WP8: Setting up SampleData - windows-phone-8

i want to create sample data in form of a List for my LongListSelector in wp8 but cannot get it to work. Can you help?
ListEntryModel.cs:
[...]
namespace LongListSelectorStudies.ViewModels
{
public class ListEntryModel
{
public string Text { get; set;}
public List<string> Liste { get; set; }
}
}
SampleData.xaml:
<vm:ListEntryModel
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:LongListSelectorStudies.ViewModels"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Text="Test">
<vm:ListEntryModel.Liste>
<sys:String>One</sys:String>
<sys:String>Two</sys:String>
</vm:ListEntryModel.Liste>
</vm:ListEntryModel>
Error: The element "Liste" could not be identified or the element is not accessible.
I am not using the english version of Visual Studio thus the error message may not be accurate. Thank you for your help!

Related

ASP.NET Identity 2 Simple User Login Example using EF 6 + MySQL

I'm building a fairly small ASP.NET MVC 5 app using EF 6 and MySQL, and I thought it'd be nice to use Identity instead of rolling-my-own security. I've been at it for days, trying everything I can Google up, but I feel the .NET universe expanding around me. I'm no further ahead.
I simply need login accounts and security for a section of the site I'm building. Some pages are private to subscribers and others are public. I'd like for the Identity tables to be in the same MySQL db that the app utilizes.
The last time I attempted anything like this was the FormsAuth/Membership stuff in ASP.NET 2.0 - and I haven't built anything substantial w/ .NET since then - so very much a beginner w/ Identity.
Here's now this experiment has progressed. I got MySQL working with EF 6 through a series of guides and hacks, and arrived at this for the Code First approach, and worked. Tables were getting generated and data was flowing:
[DbConfigurationType(typeof(MySqlEFConfiguration))]
public class RwcDataModel : DbContext
{
public RwcDataModel()
: base("name=RwcDataModel")
{
}
public virtual DbSet<User> Users { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
}
[Table("user")]
public class User
{
[Key, Column("id")]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public virtual int Id { get; set; }
[Column("fullname"), StringLength(45, MinimumLength = 1)]
public virtual string FullName { get; set; }
[Column("email"), StringLength(45, MinimumLength = 1)]
public virtual string Email { get; set; }
[Column("username"), StringLength(45, MinimumLength = 1)]
public virtual string Username { get; set; }
[Column("password"), StringLength(45, MinimumLength = 1)]
public virtual string Password { get; set; }
[Column("created"), DataType(DataType.Date)]
public virtual DateTime Created { get; set; }
[Column("active")]
public virtual bool Active { get; set; }
}
//...etc - other tables
public class RwcDbInitializer : DropCreateDatabaseAlways<RwcDataModel>
{
protected override void Seed(RwcDataModel context)
{
context.Users.Add(new User { FullName = "Administrator", Email = "me#gmail.com", Username = "Administrator", Password = "password", Created = DateTime.Now });
context.Users.Add(new User { FullName = "Some Guy", Email = "someguy#gmail.com", Username = "someguy", Password = "password", Created = DateTime.Now });
context.SaveChanges();
}
}
...with this in Application_Start() of the Global class:
DbConfiguration.SetConfiguration(new MySqlEFConfiguration());
Database.SetInitializer<RwcDataModel>(new RwcDbInitializer());
I first tried this:
http://www.codeproject.com/Tips/788357/How-to-set-up-application-using-ASP-NET-Identity-w
...but this just caused my db to be dropped, but not re-created and seeded. Strange, can't explain that.
Thanks to trailmax below, I followed these (similar) instructions:
http://www.asp.net/identity/overview/getting-started/aspnet-identity-using-mysql-storage-with-an-entityframework-mysql-provider
...but upon running this iteration of my app, no Identity tables are created. Also, the RwcDataModel above does nothing. The db isn't dropped - it's as if the Initializer is being ignored completely.
Any ideas how to proceed? Thanks!
Check out this blog ASP.NET Identity 2.1 with ASP.NET Web API 2.2 ASP.NET Identity 2.1 with ASP.NET Web API 2.2. Mr. Taiseer Joudeh does a great job of explaining how to use ASP.net Identity 2.1 with the Entity Framework. There is sample code included with the tutorial. While MySQL is not used in the tutorial, the Entity Framework makes it easy to switch to MySQL. Hope this helps. Cheers.

View page generates RuntimeBinderException, works anyway

I am trying to use ServiceStack Razor in my project. I set up a very simple DTO:
namespace ModelsWeb.Diagnostics
{
[Route("/echo")]
[Route("/echo/{Text}")]
public class Echo
{
public string Text { get; set; }
}
public class EchoResponse
{
public ResponseStatus ResponseStatus { get; set; }
public string Result { get; set; }
}
}
And a service to go with it:
namespace Rest.Services
{
public class EchoService : Service
{
public object Any(Echo request)
{
return new EchoResponse {Result = request.Text};
}
}
}
Note that the DTO and the service are in different namespaces. This is because I'm building two applications at once -- the server and the thick client -- and I put all the DTOs in a separate class library that they both depend on. This way, the client can reference just that class library, and no other server-side code. I am using Razor to provide a Web interface to some of the server functionality.
Anyway, I also wrote a simple view for my Echo service:
#using ServiceStack.Razor
#using ModelsWeb.Diagnostics
#inherits ViewPage<EchoResponse>
#{
ViewBag.Title = "Echo Response";
Layout = "BasePage";
}
<h1>You typed: #Model.Result</h1>
When I type "http://localhost:62061/echo/hello2" into the browser, I get an error on my log:
Cannot implicitly convert type 'ServiceStack.Razor.Compilation.RazorDynamicObject'
to 'ModelsWeb.Diagnostics.EchoResponse'
However, the template still works, and I see the expected result in the browser. What's going on here ? Am I doing anything wrong ? If not, how can I suppress this exception ?

JSON property with hyphen in it in ServiceStack

I have some JSON formed like this:
{
"snippet-format":"raw",
"total":1,"start":1,
"page-length":200, ...
}
I have a C# DTO with members called Total, Start etc. These are successfully having the values from the above placed in to them. I don't know how to name properties for the snippet-format and page-length JSON items above though.
I've tried SnippetFormat and Snippet_Format to no avail.
Could someone please point me in the right direction.
Also, if a value happens to be a W3C xs:dateTime string, is there a type I can use that ServiceStack will automatically populate for me?
Thanks in advance.
Checked into the next version of ServiceStack.Text v3.9.43+, the Lenient property convention now supports hyphened properties, so you will be able to do:
public class Hyphens
{
public string SnippetFormat { get; set; }
public int Total { get; set; }
public int Start { get; set; }
public int PageLength { get; set; }
}
JsConfig.PropertyConvention = JsonPropertyConvention.Lenient;
var json = #"{
""snippet-format"":""raw"",
""total"":1,
""start"":1,
""page-length"":200
}";
var dto = json.FromJson<Hyphens>();
Assert.That(dto.SnippetFormat, Is.EqualTo("raw"));
Assert.That(dto.Total, Is.EqualTo(1));
Assert.That(dto.Start, Is.EqualTo(1));
Assert.That(dto.PageLength, Is.EqualTo(200));
In the meantime you will have to parse it dynamically, e.g:
var map = JsonObject.Parse(json);
Assert.That(map["snippet-format"], Is.EqualTo("raw"));
Assert.That(map["total"], Is.EqualTo("1"));
Assert.That(map["start"], Is.EqualTo("1"));
Assert.That(map["page-length"], Is.EqualTo("200"));

MassTransit 2.6.1 Request/Response pattern - Response times out

I'm looking at MassTransit as a ServiceBus implementation to use in a web project.
I am playing with the Request/Response pattern and am seeing a long delay between the consumer receiving the message and responding, and the request publisher handling the response; sometimes, it seems like the response is never going to come through (having left it running for 10 minutes, the response has still not come through). the only times that I have seen the handle delegate get called with the response is after a 30 second timeout period and the timeout exception being thrown; in this situation, the breakpoint set on the handler delegate is hit.
The setup is a standard affair - I have a web app that is publishing requests, a console app that is consuming requests and sending responses, for the web app to handle the responses in the callback.
I'm using Castle Windsor, and the container is initialized in the web project using WebActivator:
[assembly: WebActivator.PreApplicationStartMethod(typeof(BootStrapper), "PreStart")]
[assembly: WebActivator.PostApplicationStartMethod(typeof(BootStrapper), "PostStart")]
[assembly: WebActivator.ApplicationShutdownMethodAttribute(typeof(BootStrapper), "Stop")]
namespace Web.App_Start
{
public static class BootStrapper
{
internal static IWindsorContainer Container { get; private set; }
public static void PreStart()
{
Container = new WindsorContainer().Install(FromAssembly.This());
}
public static void PostStart()
{
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
ApiConfig.Configure(Container);
MvcConfig.Configure(Container);
}
public static void Stop()
{
if (Container != null)
Container.Dispose();
}
}
}
In the web app project (an ASP.NET Web API project), the WindsorInstaller for MassTransit looks like
public class MassTransitInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(AllTypes.FromThisAssembly().BasedOn<IConsumer>());
var bus = ServiceBusFactory.New(configurator =>
{
configurator.UseMsmq();
configurator.VerifyMsmqConfiguration();
configurator.UseMulticastSubscriptionClient();
configurator.ReceiveFrom("msmq://localhost/web");
configurator.EnableMessageTracing();
configurator.Subscribe(x => x.LoadFrom(container));
});
container.Register(Component.For<IServiceBus>().Instance(bus));
}
}
In the console app project, the WindsorInstaller looks like
public class MassTransitInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(AllTypes.FromAssemblyContaining<BasicRequestCommandHandler>().BasedOn<IConsumer>());
var bus = ServiceBusFactory.New(configurator =>
{
configurator.UseMsmq();
configurator.VerifyMsmqConfiguration();
configurator.UseMulticastSubscriptionClient();
configurator.ReceiveFrom("msmq://localhost/console");
configurator.Subscribe(x => x.LoadFrom(container));
});
container.Register(Component.For<IServiceBus>().Instance(bus));
}
}
I have an ApiController with the following GET action method
public class ExampleController : ApiController
{
private readonly IServiceBus _bus;
public HelloController(IServiceBus bus)
{
_bus = bus;
}
// GET api/hello?text={some text}
public Task<IBasicResponseCommand> Get(string text)
{
var command = new BasicRequestCommand {Text = text};
var tcs = new TaskCompletionSource<IBasicResponseCommand>();
_bus.PublishRequest(command, c =>
{
c.Handle<IBasicResponseCommand>(r =>
{
tcs.SetResult(r);
});
});
return tcs.Task;
}
}
BasicRequestCommand and BasicResponseCommand look like so
public interface IBasicRequestCommand
{
Guid CorrelationId { get; set; }
string Text { get; set; }
}
public class BasicRequestCommand :
CorrelatedBy<Guid>, IBasicRequestCommand
{
public Guid CorrelationId { get; set; }
public string Text { get; set; }
public BasicRequestCommand()
{
CorrelationId = Guid.NewGuid();
}
}
public interface IBasicResponseCommand
{
Guid CorrelationId { get; set; }
string Text { get; set; }
}
public class BasicResponseCommand :
CorrelatedBy<Guid>, IBasicResponseCommand
{
public Guid CorrelationId { get; set; }
public string Text { get; set; }
}
And the handler responding to the BasicRequestCommand in the console app:
public class BasicRequestCommandHandler : Consumes<IBasicRequestCommand>.Context
{
public void Consume(IConsumeContext<IBasicRequestCommand> context)
{
Console.Out.WriteLine("received message text " + context.Message.Text);
context.Respond(new BasicResponseCommand { Text = "Hello " + context.Message.Text, CorrelationId = context.Message.CorrelationId });
}
}
I was anticipating with all of this running locally that the request/response would be in the order of a few seconds at most. Am I missing something in configuration?
In addition, I wanted to hook MassTransit up to log4net. I am using Windsor's log4net logging facility and have a log4net section in web.config. This is all working fine for ILogger implementations provided by Windsor (and also for NHibernate logging), but it's not clear from the documentation how to configure MassTransit to use this for logging. Any ideas?
Just as Andrei Volkov and Chris Patterson were discussing on MassTransit google group, it seems that this issue stems from switching MassTransit to using SynchronizationContext, which for some reason does not work as expected.
For the time being one workaround seems to be transitioning to async MassTransit requests, or going back to v2.1.1 that does not use the offending SynchronizationContext.
(Will posts updates on this issue here for posterity if noone else does that first.)
The response timeout issue for Request/Response in ASP.NET is fixed in version 2.6.2.
https://groups.google.com/d/topic/masstransit-discuss/oC1FOe6KsAU/discussion
As you're using the MultiCastSubscriptionClient, you must call SetNetwork(NETWORK_KEY) on each machine (using the same value for NETWORK_KEY). Also, all participating machines need to be on the same subnet - see the documentation at http://masstransit.readthedocs.org/en/latest/overview/subscriptions.html#msmq-multicast
For hooking up log4net, it depends what version you're using, but in the latest versions you include the MassTransit.Log4NetIntegration assembly and then call cfg.UseLog4Net(); in your service bus configuration.
If you're still stuck, you could ask the MT mailing list at https://groups.google.com/forum/?fromgroups#!forum/masstransit-discuss

How do I map a dictionary using Fluent NHibernate automapping?

I have an entity like so:
public class Land
{
public virtual IDictionary<string, int> Damages { get; set; }
// and other properties
}
Every time I try to use automapping with the following code:
var sessionFactory = Fluently.Configure()
.Database(SQLiteConfiguration.Standard.InMemory)
.Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<Land>))
.BuildSessionFactory();
I get the following error:
{"The type or method has 2 generic parameter(s), but 1 generic argument(s) were
provided. A generic argument must be provided for each generic parameter."}
Can someone tell me what I'm doing wrong? Also, this is just a simple example. I have much more dictionaries than just this one.
It is impossible with NHibernate.
Found some traces that this isn't possible. Some traces, that it's recently implemented.
Still investigating. :)
This looks quite promising (didn't test yet).
So, in your case it should look like=>
public class LandMap : ClassMap<Land>
{
public LandMap()
{
(...)
HasMany(x => x.Damages)
.WithTableName("Damages")
.KeyColumnNames.Add("LandId")
.Cascade.All()
.AsMap<string>(
index => index.WithColumn("DamageType").WithType<string>(),
element => element.WithColumn("Amount").WithType<int>()
);
}
}
Keep in mind - it should. I didn't test it.
A possible workaround that should in theory work with automapping:
public class DamagesDictionary : Dictionary<string, int>
{
}
Land.cs
public class Land
{
public virtual DamagesDictionary Damages { get; set; }
// and other properties
}
or a more generic approach...
public class StringKeyedDictionary<T> : Dictionary<string, T>
{
}
Land.cs
public class Land
{
public virtual StringKeyedDictionary<int> Damages { get; set; }
// and other properties
}