Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
ljw1004
Jan 18, 2005

rum

Gul Banana posted:

I'm looking forward to using it in a wizard system I've got which inverts flow of control by having external code orchestrate and rerun the async method. The orchestrated method suspends itself and returns control to the orchestrator by awaiting; right now that code has to use tons of TaskCompletionSources and keep track of them using faux continuations. I can make the whole thing simpler when custom awaitables are returnable.

I wrote a blog post about how to "hibernate an async method" -- basically, serialize the state of an async callstack to disk, and deserialize it afterwards. I wonder if this might be useful?
https://blogs.msdn.microsoft.com/lucian/2016/04/20/async-workflow-2/

Adbot
ADBOT LOVES YOU

Night Shade
Jan 13, 2013

Old School

Gul Banana posted:

i didn't think finally blocks were automatically CERs, though. you need to inherit from criticalhandle or something? and use attributes also, i think

Yeah I think you might be right actually, and ThreadAbortExceptions get delayed until after finally blocks and finalisers by the runtime anyway. I haven't spent a lot of time in this area of the framework.

Gul Banana
Nov 28, 2003

i don't want to make assumptions, but it's possible that part of ConcurrentDictionary.cs is just a cargo cult technique.. :laugh:

Gul Banana
Nov 28, 2003

ljw1004 posted:

I wrote a blog post about how to "hibernate an async method" -- basically, serialize the state of an async callstack to disk, and deserialize it afterwards. I wonder if this might be useful?
https://blogs.msdn.microsoft.com/lucian/2016/04/20/async-workflow-2/

oh man, i have to read through this. your lambda-based approach to accessing the state machine is much nicer than a prototype i ended up discarding for that same wizard system:
https://gist.github.com/gulbanana/5d2e2291a42e717ce73d12d2f19c8306

what i ended up doing instead was running the munged method repeatedly, 'jumping' around parts of it by re-executing with a host function which was sometimes a dummy. that works almost all the time and it lets me feel smart by writing continuation combinators, but it does have the huge drawback that wizard implementations have to be strictly deterministic or it breaks in weird ways! your checkpoint approach seems like it could avoid that problem entirely, though i'm not 200% comfortable with "_type_AsyncMethodBuilderCore.GetMethod("TryGetStateMachineForDebugger", BindingFlags.NonPublic | BindingFlags.Static);".

EssOEss
Oct 23, 2006
128-bit approved

ljw1004 posted:

but it's back-compat for what in retrospect was a bad original design and if we could go back in time to remove it then we would.

What do you mean by this? That is, what was the bad aspect of the design?

ljw1004
Jan 18, 2005

rum

EssOEss posted:

What do you mean by this? That is, what was the bad aspect of the design?

code:
void f<T>(Func<T> lambda)

f(async () => {await Task.Delay(1); return 3; });
This compiles, and infers T=Task<int>. We wish it didn't...

If you wrote the function "f" like this, then you likely never considered what would happen when someone gave you an async lambda. You likely just execute the lambda and expect a synchronous result.

If you invoke the function "f" like this, then you likely assume that the function "f" will behave "properly" when given an async lambda, and you'll be disappointed.

Night Shade
Jan 13, 2013

Old School

Gul Banana posted:

i don't want to make assumptions, but it's possible that part of ConcurrentDictionary.cs is just a cargo cult technique.. :laugh:

Heh. Maybe. There is some stuff about it on the documentation for Thread.Abort https://msdn.microsoft.com/en-us/library/5b50fdsz(v=vs.110).aspx but I clearly made the leap to constrained execution based on some badly remembered stuff I read a while ago :pseudo:

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

ljw1004 posted:

We discussed in LDM that we honestly don't expect more than three or so people to realistically write custom tasklike types, and the three were all in the meeting. (Stephen Toub who writes ValueTask, and Oren Novotny who owns IObservable, and Stephen Toub who'd be on point to write IAsyncAction).

The reason for making it work for any task-like object, articulated by Anders Hejlsberg, is because it's bad when the compiler has a language-level dependency on certain types in the framework. With this change we have almost entirely removed Task's privileged status in the compiler. The only remaining place is in type inference, which we needed to preserve back-compat, but it's back-compat for what in retrospect was a bad original design and if we could go back in time to remove it then we would.

There are two forward-looking reasons why we also wanted to do it this way. The first is a feature that we haven't yet implemented. We'd let you return a Task, but using your own custom logic to produce the Task. You might do this if you want to have some kind of weaving, or make the method always ConfigureAwait(false), or ...
code:
[AsyncMethodBuilder(typeof(MyTaskBuilder))]
async Task Fred() { ... }
The other is a feature we also haven't implemented yet, async streams. In C#8 we hope to let you write a async iterator method, one that has both yield and await inside it. Often you'd want to return IAsyncEnumerable<T>. But you'll also want to return other things -- custom stream-likes will be more common than custom task-likes. We wanted a uniform treatment in the language for async methods as for async iterator methods.

yesss monad transformers

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION
This is kind of a general question which I think will boil down to personal preference for some people, but anyway...

I'm finding a fairly common pattern arising in my MVC projects. Whenever I have a form that needs to be filled out, I'll frequently need to load in some other information for the page as well. As an example, we'll take this ViewModel for a form to allow a student to enrol into a course:

code:
public class EnrolIntoCourseViewModel
{
    #region Course details

    public string CourseName { get; set; }
    public DateTime StartDate { get; set; }
    public DateTime EndDate { get; set; }

    #endregion

    #region Input fields
    
    public string GivenName { get; set; }
    public string Surname { get; set; }
    public DateTime DateOfBirth { get; set; }

    #endregion

}
So the first three properties are just information; display only. The next three are the details that the student will be entering to enrol into the course.

Now if there's an error, in order to correctly reload the form with the error messages present I'm going to need to either include those three information properties in the form as hidden fields, or I'm going to need to make sure I populate them in the event of an error so the page can be rendered again without error.

I find this really clunky and awkward, and it seems to violate the DRY principle as I end up with two separate pieces of code responsible for populating those properties on the ViewModel. How do you guys tend to handle these "extra baggage" fields when handling forms?

chippy
Aug 16, 2006

OK I DON'T GET IT

The Wizard of Poz posted:

This is kind of a general question which I think will boil down to personal preference for some people, but anyway...

I'm finding a fairly common pattern arising in my MVC projects. Whenever I have a form that needs to be filled out, I'll frequently need to load in some other information for the page as well. As an example, we'll take this ViewModel for a form to allow a student to enrol into a course:

code:
public class EnrolIntoCourseViewModel
{
    #region Course details

    public string CourseName { get; set; }
    public DateTime StartDate { get; set; }
    public DateTime EndDate { get; set; }

    #endregion

    #region Input fields
    
    public string GivenName { get; set; }
    public string Surname { get; set; }
    public DateTime DateOfBirth { get; set; }

    #endregion

}
So the first three properties are just information; display only. The next three are the details that the student will be entering to enrol into the course.

Now if there's an error, in order to correctly reload the form with the error messages present I'm going to need to either include those three information properties in the form as hidden fields, or I'm going to need to make sure I populate them in the event of an error so the page can be rendered again without error.

I find this really clunky and awkward, and it seems to violate the DRY principle as I end up with two separate pieces of code responsible for populating those properties on the ViewModel. How do you guys tend to handle these "extra baggage" fields when handling forms?

If it's just the simple stuff like CourseName and the Dates in your example, then I tend to just use a hidden field in the form, for the sake of simplicity. I don't know if that's the 'right' thing to do or not (I suspect it's not and you should be restricting the client to POSTing back only the fields that are required). For more involved stuff like drop-down menu options or things like that, I will create private methods in the controller and call them from the actions that need them - either one that takes the ViewModel as a parameter and populates it with everything it needs, or just methods that return IEnumerable<SelectListItem> (or whatever other things are required) that you can call to get the various bits the ViewModel needs. This second pattern is more flexible as you can use it with different ViewModels that happen to rely on the same sources of information (i.e. lists of suppliers, customers, whatever).

chippy fucked around with this message at 12:32 on Oct 3, 2016

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION
Hmm yeah I will tend toward private methods in the controllers as well. I don't know, it just feels clunky having that information mixed in among the input fields. It feels like I'm working against MVC somehow, and that there must be a more accepted way.

Cuntpunch
Oct 3, 2003

A monkey in a long line of kings
Ok, what am I missing here, is this intended or is this known or do I need to report this?

code:
[TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod_Void()
        {
            Assert.Inconclusive("foo");
        }              

        [TestMethod]
        public async Task TestMethod_AsyncTask()
        {
            Assert.Inconclusive("foo");
        }
    }
Here are two TestMethods - that are stubbed out with Inconclusive to indicate they aren't implemented, etc.

If you run these tests in a generic Unit Test project, both will flag as Skipped/Inconclusive/'yellow'

But if you run these tests in a UWP Unit Test project, the async version will flag as a hard *Fail*/'red' - no other changes.

Gul Banana
Nov 28, 2003

with what error message? does it fail also when using mstest v2, the one which is mostly the same between environments?

Cuntpunch
Oct 3, 2003

A monkey in a long line of kings

Gul Banana posted:

with what error message? does it fail also when using mstest v2, the one which is mostly the same between environments?

What do you mean, error message? It's the same thing, it's just that in UWP it counts as a hard 'Fail', the same as Assert.Fail() - whereas in standard projects it's counted as a skip - like flagging a test [Ignore]

mortarr
Apr 28, 2005

frozen meat at high speed

The Wizard of Poz posted:

Hmm yeah I will tend toward private methods in the controllers as well. I don't know, it just feels clunky having that information mixed in among the input fields. It feels like I'm working against MVC somehow, and that there must be a more accepted way.

Same here, hidden input fields for simple objects. Sometimes I need to edit lists of child records on the same page, so in that case they go down in their own property like:

code:
  public class ParentViewModel {
    public int ParentId { get; set; }
    ... various props
    public List<ChildViewModel> Children { get; set; }
  }

  public class ChildViewModel {
    public DateTime? DateAdded { get; set; }
    public string Notes { get; set; }
  }  
In the view I use a kendo ui grid to hold the Children (initialised via javascript, not via the asp.net bindings), and I might bind to a custom popup window for row editing or use inline editing if the requirements are more simple. On post, I re-serialise the underlying datasource for the grid via json stringify into a hidden field, then I override DefaultModelBinder and read it back in to its correct property before the controller gets it:

code:
public class ParentViewModelModelBinder : DefaultModelBinder<ParentViewModel>
  {
    protected override void BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor)
    {
      if (propertyDescriptor.Name == "Children")
      {
        // Set the property ourselves when we're overriding default behaviour
        var serialisedValue = controllerContext.HttpContext.Request.Params[propertyDescriptor.Name] ?? string.Empty;
        var data = serialisedValue.FromJson<List<ChildViewModel>>() ?? new List<ChildViewModel>();

        this.SetProperty(controllerContext, bindingContext, propertyDescriptor, data);
      }
      else
      {
        // If it's not a property of interest, fall back to the default behaviour.
        base.BindProperty(controllerContext, bindingContext, propertyDescriptor);
      }
    }
  }
This way, I ensure I don't need to requery my EF objects each postback if validation fails.

Someone please tell me there's an easier way for setting up parent/child editable pages in asp.net mvc?!

chippy
Aug 16, 2006

OK I DON'T GET IT

mortarr posted:

Someone please tell me there's an easier way for setting up parent/child editable pages in asp.net mvc?!

Quite an old post but this is the approach I prefer personally:

http://blog.stevensanderson.com/2010/01/28/editing-a-variable-length-list-aspnet-mvc-2-style/

This only covers a list but you can use it with a viewmodel with top-level fields and a collection of child viewmodels to edit a parent record and child records in one page.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

The Wizard of Poz posted:

Hmm yeah I will tend toward private methods in the controllers as well. I don't know, it just feels clunky having that information mixed in among the input fields. It feels like I'm working against MVC somehow, and that there must be a more accepted way.

Hopping on the private method train. I usually have properties in my ViewModels organized into display-only data and user-editable data. The display-only data is then populated by a private method in the controller while the user-editable data is posted. This is the most flexible configuration, since there are cases where you might have a lot of display-only data that you don't want to be posting back and forth from the server.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION
I'm trying to figure out a neat way to hold onto a collection of Entity Framework Include() expressions and retrieve them generically. Let's say I have the following Entities:
code:
public class Student
{
 
    public string GivenName { get; set; }
    public string Surname { get; set; }
    public int EmployerId { get; set; }
    public Employer Employer { get; set; }
}

public class Employer
{
    public int Id { get; set; }
    public string Name { get; set; }
}
And the following ViewModels:

code:
public class StudentBasicViewModel
{
    public string GivenName { get; set; }
    public string Surname { get; set; }
}

public class StudentDetailViewModel : StudentBasicViewModel
{
    public string EmployerName { get; set; }
}
Now if I'm going to be able to map to StudentDetailViewModel correctly, I'm going to need to make sure I call .Include(st => st.Employer) when querying Entity Framework. The problem is, how will I know what relationships to include if I am working generically? I want to write a method something like the following:

code:
public class StudentManager
{
    public List<TViewModel> GetStudentsAs<TViewModel>()
    {
        return _studentDbSet.IncludeAll([somehow get include list here]).ToList().Map<TViewModel>();
    }
}
At this stage it's worth mentioning that I've written an IQueryable<T> extension method called IncludeAll() that takes an array of Expression<Func<T, object>> and calls Include() for each.

How can I get that list of includes? I've considered putting it on the ViewModel as a static property, but then there's no way to enforce the presence of the static property using a type constraint, so there's no way to access that static property generically. Ideas?

mortarr
Apr 28, 2005

frozen meat at high speed

The Wizard of Poz posted:

I'm trying to figure out a neat way to hold onto a collection of Entity Framework Include() expressions and retrieve them generically. Let's say I have the following Entities:

(snip)

How can I get that list of includes? I've considered putting it on the ViewModel as a static property, but then there's no way to enforce the presence of the static property using a type constraint, so there's no way to access that static property generically. Ideas?

Not sure if it's helpdul, but Automapper has ProjectTo() which (I think) you use in a similar way to what you are proposing, although you may need to map things beforehand. Maybe digging in to its source would give you some pointers?

If you use its MapTo() method, automapper will project the IQueryable to a list (or similar) and then hit EF once for each of the items in the list (I think this is called the select n+1 problem). Instead, you can use ProjectTo, and it will build a smarter EF query and get all the props at once. It sounds like it's using includes the same way you mention, but I don't know what magic is going on under the hood.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

mortarr posted:

Not sure if it's helpdul, but Automapper has ProjectTo() which (I think) you use in a similar way to what you are proposing, although you may need to map things beforehand. Maybe digging in to its source would give you some pointers?

If you use its MapTo() method, automapper will project the IQueryable to a list (or similar) and then hit EF once for each of the items in the list (I think this is called the select n+1 problem). Instead, you can use ProjectTo, and it will build a smarter EF query and get all the props at once. It sounds like it's using includes the same way you mention, but I don't know what magic is going on under the hood.

Yeah I've approached it from the projection angle as well, but the problem is I have calculated fields on the Entity that need to be mapped to the ViewModel. This is because the Entity is part of a code library that is shared across projects and I want the business logic for the Entity to remain consistent.

In my example I've actually explicitly turned it into a List<> myself so that it forces EF to run the query once to get the entire collection, with the Includes. THEN once I have the list of Entities, I map them using AutoMapper.

Edit for clarification:
code:
return _studentDbSet
           .IncludeAll([somehow get include list here]) // Still an IQueryable, no query run yet.
           .ToList() // This executes the query, now we're operating in memory.
           .Map<TViewModel>(); // Mapping performed entirely in memory.

putin is a cunt fucked around with this message at 06:52 on Oct 5, 2016

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

The Wizard of Poz posted:

At this stage it's worth mentioning that I've written an IQueryable<T> extension method called IncludeAll() that takes an array of Expression<Func<T, object>> and calls Include() for each.

How can I get that list of includes? I've considered putting it on the ViewModel as a static property, but then there's no way to enforce the presence of the static property using a type constraint, so there's no way to access that static property generically. Ideas?

So, it's pretty goofy but you could do something like this:

C# code:
public interface IIncludable<T>
{
    List<Expression<Func<T, object>>> Inclusions { get; }
}

public static List<TViewModel> Map<T, TViewModel>(this IQueryable<T> query)
    where TViewModel : IIncludable<T>, new()
{
    var obj = new TViewModel();
    foreach(var inclusion in obj.Inclusions)
        query = query.Include(inclusion)
    var list = query.ToList();
    var mapped = // do your mapping here
    return mapped;
}

// usage
public class StudentViewModel : IIncludable<Student>
{
    public List<Expression<Func<Student, object>>> Inclusions
        => new List<Expression<Func<Student, object>>> { s => s.Employer };
}

var list = db.Students.Map<Student, StudentViewModel>();
I just typed this out without checking anything, so it might not compile. However, the idea is simple - use the new() generic constraint for TViewModel so you can instantiate it in your Map method, then rely on the IIncludable<T> generic constraint to get the inclusions list.

edit: this is yet another place where I wish C# had typeclasses (or static interfaces, or whatever they're called on the Roslyn GH issue nowadays).

Bognar fucked around with this message at 16:16 on Oct 5, 2016

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Bognar posted:

So, it's pretty goofy but you could do something like this:

C# code:
public interface IIncludable<T>
{
    List<Expression<Func<T, object>>> Inclusions { get; }
}

public static List<TViewModel> Map<T, TViewModel>(this IQueryable<T> query)
    where TViewModel : IIncludable<T>, new()
{
    var obj = new TViewModel();
    foreach(var inclusion in obj.Inclusions)
        query = query.Include(inclusion)
    var list = query.ToList();
    var mapped = // do your mapping here
    return mapped;
}

// usage
public class StudentViewModel : IIncludable<Student>
{
    public List<Expression<Func<Student, object>>> Inclusions
        => new List<Expression<Func<Student, object>>> { s => s.Employer };
}

var list = db.Students.Map<Student, StudentViewModel>();
I just typed this out without checking anything, so it might not compile. However, the idea is simple - use the new() generic constraint for TViewModel so you can instantiate it in your Map method, then rely on the IIncludable<T> generic constraint to get the inclusions list.

edit: this is yet another place where I wish C# had typeclasses (or static interfaces, or whatever they're called on the Roslyn GH issue nowadays).

This is somewhat similar to what I wound up doing, happy to see that it's not an easy thing to solve elegantly. For the record I did this:

First I made an interface similar to yours:

code:
public interface IMapFrom<T>
{
    Expression<Func<T, object>>[] RequiredProperties { get; }
}
Then created a "factory" class:

code:
public class IncludeResolver<TEntity, TViewModel>
        where TViewModel : IMapFrom<TEntity>, new()
    {
        public static Expression<Func<TEntity, object>>[] Resolve()
        {
            return new TViewModel().RequiredProperties;
        }
    }
Now when I'm building up the Entity Framework query I can just call .Include(IncludeResolver<Student, StudentViewModel>.Resolve()). I feel dirty.

Polio Vax Scene
Apr 5, 2009



Is there a way to make an XML serializer print like this:
pre:
<Contact>
  <FirstName>Bob</FirstName>
  <MiddleName></MiddleName>
  <LastName>Smith</LastName>
</Contact>
Instead of like this?:
pre:
<Contact>
  <FirstName>Bob</FirstName>
  <MiddleName />
  <LastName>Smith</LastName>
</Contact>
That doesn't involve painfully manually writing out the XML?

v That is (un)fortunately beyond the scope of my responsibility.

Polio Vax Scene fucked around with this message at 17:43 on Oct 7, 2016

EssOEss
Oct 23, 2006
128-bit approved
I suggest you fix whatever is consuming that XML, as the two snippets are completely equivalent. Bad XML parsers must die by starvation!

GreenDragon42
Apr 29, 2009

Polio Vax Scene posted:

Is there a way to make an XML serializer print like this:
pre:
<Contact>
  <FirstName>Bob</FirstName>
  <MiddleName></MiddleName>
  <LastName>Smith</LastName>
</Contact>
Instead of like this?:
pre:
<Contact>
  <FirstName>Bob</FirstName>
  <MiddleName />
  <LastName>Smith</LastName>
</Contact>
That doesn't involve painfully manually writing out the XML?

v That is (un)fortunately beyond the scope of my responsibility.

From what I've seen googling, there isn't an option out of the box, but I did find a solution that seems simple enough to implement here https://www.experts-exchange.com/questions/28413488/Manipulating-the-output-of-empty-XML-elements-for-NET-serialization.html

bomblol
Jul 17, 2009

my first crapatar
very dumb question incoming, I hope Xamarin questions are kosher in this thread. Although I'm pretty experienced with C# due to extensive use of very old versions of mono in unity, I have 0 experience with .NET related stuff in most other formats. I'm a bit in over my head as I try to set up a Xamarin.Forms solution. Most guides have really nice step-by-step instructions, but inevitably what I see doesn't match what the guide shows. Right now, I'm using Xamarin Studio and I'm creating a PCL iOS / Android App. I disabled the "Use XAML for user interface" button during setup because when I left it checked it seemed to create a different project setup than al the tutorials I was looking at. My only point of confusion now, I guess, is why there seems to be a LaunchScreen.storyboard in my MyApp.ios project? I can't seem to find any other references to why this would be here. No tutorials show it in the pictures.

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost

bomblol posted:

very dumb question incoming, I hope Xamarin questions are kosher in this thread. Although I'm pretty experienced with C# due to extensive use of very old versions of mono in unity, I have 0 experience with .NET related stuff in most other formats. I'm a bit in over my head as I try to set up a Xamarin.Forms solution. Most guides have really nice step-by-step instructions, but inevitably what I see doesn't match what the guide shows. Right now, I'm using Xamarin Studio and I'm creating a PCL iOS / Android App. I disabled the "Use XAML for user interface" button during setup because when I left it checked it seemed to create a different project setup than al the tutorials I was looking at. My only point of confusion now, I guess, is why there seems to be a LaunchScreen.storyboard in my MyApp.ios project? I can't seem to find any other references to why this would be here. No tutorials show it in the pictures.

So first, I highly encourage you to go to our developer docs site. They get updated frequently and might be a better place to start.

This is what's created when you turn off the "Use XAML for user interface" button when making a new project.



and this is with using XAML



The only difference should be the use of XAML in the PCL project.

There is a LaunchScreen storyboard in the iOS project because there needs to be one (It's used to show your apps logo and then start from AppDelegate. You can see it being used in the info.plist). Basically it's following the standard iOS startup for an app to initialize the Xamarin.Forms stuff, so then it goes to what you have in the PCL.

I'm not sure what you're confused by though, could you post what tutorials you're trying to follow and what you're trying to do?

EDIT: Oh yeah, I should say, IMO, you should start with XAML instead of doing it programmatically. Most tutorials are going to follow that because way more people like using XAML.

Drastic Actions fucked around with this message at 23:16 on Oct 8, 2016

bomblol
Jul 17, 2009

my first crapatar
I've been looking at 3 resources, one of which is on the official site:
Tutsplus Sitepoint Xamarin
Normally I don't struggle with something as simple as getting a development environment set up and creating Hello World-esque technologies, but my lack of familiarity with .NET or the history of Xamarin has kind of left me reeling.
They're all at least slightly outdated, so none of them even mentioned the XAML option, although I certainly have no personal reason not to use it other than it seems that the resources I was using did not. I've been mostly using the one on the Xamarin website

e: is the only difference that checking "Use XAML for user interface" does is making the initital App.cs a xaml and xaml.cs like all the other ones the tutorial had me add, instead of just giving it to you as a single .cs file? That would clear up 90% of my confusion. I used React without JSX so I understand the terror of trying to create layouts in code and the preference for using markup for that.

bomblol fucked around with this message at 23:40 on Oct 8, 2016

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost

bomblol posted:

I've been looking at 3 resources, one of which is on the official site:
Tutsplus Sitepoint Xamarin
Normally I don't struggle with something as simple as getting a development environment set up and creating Hello World-esque technologies, but my lack of familiarity with .NET or the history of Xamarin has kind of left me reeling.
They're all at least slightly outdated, so none of them even mentioned the XAML option, although I certainly have no personal reason not to use it other than it seems that the resources I was using did not.

e: is the only difference that checking "Use XAML for user interface" does is making the initital App.cs a xaml and xaml.cs like all the other ones the tutorial had me add, instead of just giving it to you as a single .cs file? That would clear up 90% of my confusion

First, I would ignore the tutsplus tutorial. It's pretty old and it's for VS anyway.

The XAML option was introduced, to the best of my knowledge, in Cycle 7 which was early this summer. So yeah, our tutorial is slightly little out of date in terms of what the template contains when you make it (like how the LaunchScreen storyboard is created now for iOS, before it was programmatic), but you should still be able to follow it.

Originally, when a forms project was created, it would not generate XAML at all, only the app.cs with the mainpage created programmatically. The option was introduced because the first thing most users did was remove the app.cs code and make App.xaml and a MainPage.xaml.

The tutorials also assume you have some passing knowledge of .NET and C#. Like, the first HelloWorld doc has basic dependency injection in it. You may want to start with more basic C# stuff first. You can try using Xamarin Workbooks as a REPL to play around with it.

Drastic Actions fucked around with this message at 23:49 on Oct 8, 2016

bomblol
Jul 17, 2009

my first crapatar

Drastic Actions posted:

First, I would ignore the tutsplus tutorial. It's pretty old and it's for VS anyway.

The XAML option was introduced, to the best of my knowledge, in Cycle 7 which was early this summer. So yeah, our tutorial is slightly little out of date in terms of what the template contains when you make it (like how the LaunchScreen storyboard is created now for iOS, before it was programmatic), but you should still be able to follow it.

Originally, when a forms project was created, it would not generate XAML at all, only the app.cs with the mainpage created programmatically. The option was introduced because the first thing most users did was remove the app.cs code and make App.xaml and a MainPage.xaml.

The tutorials also assume you have some passing knowledge of .NET and C#. Like, the first HelloWorld doc has basic dependency injection in it. You may want to start with more basic C# stuff first. You can try using Xamarin Workbooks as a REPL to play around with it.
Alright, that makes perfect sense! That entirely clears up the stupid, minor thing I was getting tripped up over. I understood pretty much everything else, but I had trouble moving on with the next steps until I was sure I was not misunderstanding something. Thanks for your advice, I'll check out that xamarin workbooks link.

Mr Shiny Pants
Nov 12, 2012
What are you getting stuck at? I am going through the same thing myself.

Sab669
Sep 24, 2009

(sorry for formatting, posting from my phone)

Hey goons, I have an asp mvc-4 application that uses jquery to send an ajax request that passes a string back to the server which then is supposed to write that string to a file.

Problem is under certain conditions, the string is pretty long. 4 million characters or more. Once the request is sent, the server throws this error:

quote:

Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the steering exceeds the value set on the maxJsonLength property

This gets thrown by System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)

The breakpoint I've set in my controller's method I'm trying to invoke over ajax doesn't get triggered, the server is throwing this exception before MyController.SaveToFile() gets called.

I've Googled around and found a handful threads on StackOverflow citing this error, but the suggestions did not work for me.

I've tried adding <jsonSerialization maxJsonLength="2147483644" /> to my <system.web.extensions> node in the web.config, and I've also tried <add key="aspnet:MaxJsonSerializationMembers" value="2147483644" /> to the <appSettings> node.

I've tried with just one, then the other, they both.

Our application was recently just rewritten by some Indian company. Used to be a lovely VB ASP.net application which only used plain old vanilla JS and had only a vague sense of any sort of architectural foresight. Now it's a mediocre C# app that uses jquery, C#, and MVC. I say this because I noticed in the web.config there was this key: <add key="JSONMAXJSONLENGTH" value="2147483644" />. I tried removing this but it made no difference. I also googled for simply "asp.net key JSONMAXJSONLENGTH" and got a whopping 10 results -- 1 of which is a question I posted on SO the other day.

But yea. So I'm absolutely clueless as to why the internal serializer class isn't respecting my web.config value.

Anyone have any ideas? :(

Sab669 fucked around with this message at 13:45 on Oct 13, 2016

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

Sab669 posted:

I've tried adding <jsonSerialization maxJsonLength="2147483644" /> to my <system.web.extensions> node in the web.config, and I've also tried <add key="aspnet:MaxJsonSerializationMembers" value="2147483644" /> to the <appSettings> node.

Just to make sure, did you have it in this exact format?

code:
   <system.web.extensions>
       <scripting>
           <webServices>
               <jsonSerialization maxJsonLength="2147483644"/>
           </webServices>
       </scripting>
   </system.web.extensions>
If it's still not working, then you could cheat and just accept the json as a string parameter. Then you can deserialize it yourself instead of having MVC do it.

Sab669
Sep 24, 2009

Bognar posted:

Just to make sure, did you have it in this exact format?


Yea that's the format I used. Just a pain to type it all out on my phone :v:

quote:


If it's still not working, then you could cheat and just accept the json as a string parameter. Then you can deserialize it yourself instead of having MVC do it.


This might be a dumb question but how would I do that? I'm still pretty new to ajax, we just call $.ajax({ async, cache, data, dataType, type, url, contentType, traditional, headers, beforeSend, success, error, complete})

Where data is my multimillion character string, url is myController/SaveToFile, then beforeSend, success, error and complete are just a few functions that do the following: validate a token, perform some validation on the results, log the error, and do whatever is needed to the UI respectively.

data is initially just a single dimension array with 4 strings: "FileName", "FileNameValue.rtf", "RtfErrorList", "The four million character string to be written to the file"

We call JSON.stringify and pass this array. What we get back is sent as the data object in the ajax request.

Is this what you're saying I should change?

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
Continue stringifying your data, but when you AJAX it give it to JQuery like { json: serializedData } then either don't specify a contentType or use "application/x-www-form-urlencoded; charset=UTF-8" which is the default.

This will send it to your server as a form-encoded POST with one parameter json that has all of your info. Then you can use it in your Action method like this:

code:
public ActionResult SaveToFile(string json) {
    var data = JsonConvert.DeserializeObject<MyObject>(data);
    .... do stuff
}
I should note, this is definitely a hack and there's probably a better way to get MVC to accept large JSON input. However, this should at least work.

Sab669
Sep 24, 2009

Thanks for the explanation, I'll at least give it a shot.

SaveToFile actually returns void, it creates the file from the object passed it an argument and stores it in a session variable. The function defined by the success parameter just shows a pop-up for them to then save it.

So that should be fine, right? I guess I'd just need to change the type of the parameter and handle the parsing of the data myself.

Sab669 fucked around with this message at 17:05 on Oct 13, 2016

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
Yeah that should work - return type doesn't have any effect on the parameter binding.

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


Is there any way to get LINQ to SQL type functionality with an Oracle database?

Horn
Jun 18, 2004

Penetration is the key to success
College Slice
You can use Entity Framework against an oracle DB. I believe they even ship a fully managed driver via nuget.

Adbot
ADBOT LOVES YOU

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


Thanks, I'll have to read up on EF, I haven't any real clue how it differs (or how data interactions in C#/.net work at all yet, really)

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply