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
New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Drastic Actions posted:

So Xamarin switched to Slack from Hipchat. There's no official Windows Phone client yet (They are actually making one though, which shocked me) nor a Windows 8 version, so I figured I would start making one. If only as an excuse to play around with WebSockets.

I have the connection set up with MessageWebSocket and it's sending and receiving messages successfully. I have a timer set up so it can ping the server so it can maintain a connection, and close it when the view pages, or if there is a network issue. But I'm having an issue trying to figure out how to handle the messages I'm receiving. If you look at their API, it returns messages as JSON. That's great, but I like to deserialize json as objects with JSON.NET, and the objects it brings back can be different. For example

JavaScript code:
{
    "type": "message",
    "ts": "1358878749.000002",
    "user": "U023BECGF",
    "text": "Hello"
}
or

JavaScript code:
{
    "type":"user_typing",
    "channel":"C03C6CWAM",
     "user":"U03C6CW9T"
}
When I make API calls directly, I know exactly what I'm going to get back; The object I requested, or an error object. I don't think I can deserialize this directly though, so I can only parse it as a JObject, check the type field and go from there. Is there a good way to handle this, or am I just missing something obvious?

I dealt with something along those lines while I was playing with writing an IRC client a while back. Same basic problem: Messages of certain types come in and need to be converted to POCOs, but you don't know what POCO it is. I ended up hacking something together with attributes and reflection that would map the message type to the object type, then fire an appropriate event so the object could be consumed.

Adbot
ADBOT LOVES YOU

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

Drastic Actions posted:

When I make API calls directly, I know exactly what I'm going to get back; The object I requested, or an error object. I don't think I can deserialize this directly though, so I can only parse it as a JObject, check the type field and go from there. Is there a good way to handle this, or am I just missing something obvious?

Unfortunately, no, if the API is going to return multiple types you'll have to do some inspection. You can make this somewhat easy on yourself with a static Dictionary<string, Type>, with the key being the type string and the value being your C# type. Once you get your type, then you can just use the non-generic JsonConvert.DeserializeObject(string, Type). You won't know the output type at compile time unless you do some more magic, but that may not be important if the number of types of messages is small.

Bognar fucked around with this message at 23:19 on Jan 24, 2015

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Comedy option: one object with every possible key represented as a property that you do different things with based on which properties serialize out to null :v:

and by "comedy option" I mean "what you might just end up doing when you come across an API made by someone who's never used a language less dynamic than JavaScript"

Munkeymon fucked around with this message at 16:59 on Jan 26, 2015

Inverness
Feb 4, 2009

Fully configurable personal assistant.
I see GC.AddMemoryPressure() exists to inform the system about unmanaged memory. Is it also valid to do this when that unmanaged memory is in the GPU?

Mr. Crow
May 22, 2008

Snap City mayor for life
Probably let your unmanaged code manage the memory?

Blasphemeral
Jul 26, 2012

Three mongrel men in exchange for a party member? I found that one in the Faustian Bargain Bin.

Hey, Lucian! After you posted that link, I naturally went and watched your whole Essential Async series. While I've been doing a bunch of the things you suggested for a long time, I did catch a couple new pointers that I enjoyed. Something I also found was pretty awesome was your suggestions about when not to use some of those patterns. This particular discussion about where and when to use Task.Run has been helpful, so thanks to everyone here for bringing it up. I'll be adjusting my network framing library API the next time I refactor it to clear that up.

Additionally, I had a question a while back which your last video reminded me to ask here, regarding awaitable.ConfigureAwait(false) :
I realized after implementing the ConfigureAwait changes into my library, that my code became absolutely saturated with ConfigureAwait(false) calls in some places and I wanted to clean it up somehow. Since, on a library level I (basically) never want to ConfigureAwait(true), is there a way or place where I can set the default ConfigureAwait setting on, say, a project- or assembly-level to false? If so, where/how?

ljw1004
Jan 18, 2005

rum

Blasphemeral posted:

Since, on a library level I (basically) never want to ConfigureAwait(true), is there a way or place where I can set the default ConfigureAwait setting on, say, a project- or assembly-level to false? If so, where/how?

Sorry no! That's been a common request from library-authors but we don't have any good answers.


What my team does is we use VS2015, currently in CTP5, and we wrote an "analyzer" which detects every await statement and gives you a warning if it lacks .ConfigureAwait(false). That at least catches the places where you need it.

bpower
Feb 19, 2011
I'm building a .net mvc website, and we've decided to use angular to create two "mini spas" within our app. Im super confused about routing between .net and angular.

Lets say one of the spas allows you to manage "offices". An office is a complex entity with staff, resources, budgets etc. A user can have many offices to manage. We have other areas of the system already built with just .Net.

I have a .net controller OfficeController. The Index method takes an OfficeId. I want this view to be an Angular spa.

My route to the view is https://www.blah.com/Office/?officeid=52

My angular stuff is in a folder called 'app' at the root of the website. Within the spa I have links to other views of the spa. I want it to have routes lke

https://www.blah.com/Office/?officeid=52/staff
https://www.blah.com/Office/?officeid=52/budgets

So (I think) I want .Net to ignore these two, but not ignore "www.blah.com/Office/?officeid=52". I cant figure out how to do it with MapRoute in my config.

I also want Angular to use "www.blah.com/Office/?officeid=52/" as its root. I can use <base href="/app/"/> to set a fixed one, but that seems to mess with my links back to ".net land".

I know I haven't ask a specific question yet, and thats a good indication of how lost I am. Can I get some general advise please, even if that advice is "go away and read the following....".

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
If you're doing a SPA, you don't use ASP .NET routing; the front end handles the routing, using hash routes.

bpower
Feb 19, 2011

Ithaqua posted:

If you're doing a SPA, you don't use ASP .NET routing; the front end handles the routing, using hash routes.

Can I not have a spa within a larger asp.net site? The other nonangular stuff will still need their routes wont they?

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

bpower posted:

Can I not have a spa within a larger asp.net site? The other nonangular stuff will still need their routes wont they?

You use ASP .NET routing to get you to the right view. If the view is an SPA, the SPA handles its own routing.

https://docs.angularjs.org/tutorial/step_07

bpower
Feb 19, 2011

Ithaqua posted:

You use ASP .NET routing to get you to the right view. If the view is an SPA, the SPA handles its own routing.

https://docs.angularjs.org/tutorial/step_07

When I create demo apps in just angular the routing is simple. Same with .net. Its combining them thats really confusing me.

How do I map, say, http://www.blah.com/Office/?officeid=52/staff to
app/office/staff.html

Can I have a dynamic root like /Office/?officeid=52 to an angular spa? I think I might have painted myself into a corner.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
You'll want to turn hash routing on in Angular, and your URL would look something like:

http://blah.com/Office#!officeid=52/staff

This would load the Index method on the OfficeController in MVC, then Angular would use officeid=52/staff to do its front-end routing.

bpower
Feb 19, 2011
Thanks guys. I'll read up on hash routing and come back if I'm stuck.

wwb
Aug 17, 2004

bpower posted:

Can I not have a spa within a larger asp.net site? The other nonangular stuff will still need their routes wont they?

We do this but more like http://www.example.com/offices/#hashRoute or http://www.example.com/furniture/#hashRoute than routing off query strings and such.

Even with angular you still need to build routes for the services. I'd check out attribute based routing at this point rather than handle it all in the routing config file.

bpower
Feb 19, 2011
Ok I'm getting closer.

I can go directly to

http://www.blah.com/Office/?officeid=52#!/staff
http://www.blah.com/Office/?officeid=52#!/budget

So how do I create the dynamic links within the Angular views. I need to somehow have

<a href="Office/?officeid=52#!/staff"> Staff</a>

Is that right?

edit: Thanks wwb, I'll look into that.

ljw1004
Jan 18, 2005

rum

Inverness posted:

I see GC.AddMemoryPressure() exists to inform the system about unmanaged memory. Is it also valid to do this when that unmanaged memory is in the GPU?

Background:

The AddMemoryPressure API has no idea where the native memory came from or how it’s used at all. This API assumes that you are holding onto some relatively large amounts of native memory with your relatively small managed objects and when the managed objects die it cleans up the native memory in its finalizer. But because there’s just not enough managed memory pressure for GC to think it needs to do any collections, they are not seeing GCs getting triggered so they use the AddMemoryPressure API so GCs will get triggered which will clean up those managed objects and in turn clean up the native memory.


Given this limited goal of the API, it seems valid to do it when unmanaged memory is in the GPU...

wwb
Aug 17, 2004

bpower posted:

Ok I'm getting closer.

I can go directly to

http://www.blah.com/Office/?officeid=52#!/staff
http://www.blah.com/Office/?officeid=52#!/budget

So how do I create the dynamic links within the Angular views. I need to somehow have

<a href="Office/?officeid=52#!/staff"> Staff</a>

Is that right?

edit: Thanks wwb, I'll look into that.

Side note from a URL nazi: It would make me feel alot obetter if you got to http://www.example.com/office/52 -- that is easy to do, if you are using default MVC routing just change your officeId parameter to be ID. If not setup the parameter in your routes.

For angular -- presuming you are linking in the container it is pretty easy. You don't need to change the page -- ie https://www.example.com/office/52, just what happens after the hash. So you'd change to the staff view from the budget view. Now, you will need to track the ID number (52) but you'd already have to have that handled since the view is tied to a single office and you'd need to expose that number to angular to render the default view.

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost
I've been making some updates to Awful Forums Reader, and I got around to doing something I've wanted to do for awhile. Since the core of those projects is a PCL, I've been using it to screw around with some other side projects. Well, it was annoying bundling the core dll with each project, or referencing the entire project. So I decided to split it out of the Awful Forums Reader solution and turn it into a true PCL Library and threw it on Nuget.

It should work in any .NET 4+ project, including Xamarin (and excluding Windows Phone 8 and 8.1 Silverlight :v:), as long as it works with PCLStorage (which is used to store the forums cookie on the users machine). I can make docs if anyone is interested in using it for themselves. I'm also going to port over some old unit tests Ithaqua wrote for me awhile back, and the command line test project I wrote for showing off how it works and throw it all on Github soon.

Dromio
Oct 16, 2002
Sleeper
I need to do some complex model binding to an action in MVC using HTTP GET instead of POST.

We built these complex, nexted objects in javascript and we POSTed them to an MVC endpoint that accepted a parameter that looked very similar to the json object being posted and it worked great. But now I really need that data in the querystring of the request (for caching purposes), and while MVC says it got the request and hydrated the object, I can see the more complicated bits are still missing.

So I have an action like this:

code:
public class PricingController
{
        public JsonResult ProductPrice(PricingContext context)
        {
             //Do something and generate output
        }
}

public class PricingContext
{
       public long ProductID{get;set;}
       public List<ChoicePricingContext> Choices{get;set;}
}
public class ChoicePricingContext
{
    public long ChoiceID{get;set;}
}


And javascript used to be:
code:
$.ajax({
   url: actionEndpoint,
   type: "POST",
   data: ko.toJSON(pricingContext)
});
but is now:
code:
$.ajax({
   url: actionEndpoint,
   type: "GET",
   data: $.param(pricingContext)
});
I can see that the ProductID is being bound appropriately in MVC with the GET, and the model gets the correct number of ChoiceContexts, but all the ChoiceContexts are empty.

What should I do to fix the modelbinding here? Am I going to have to write a whole lot of custom modelbinder code to make this work?

raminasi
Jan 25, 2005

a last drink with no ice
I'm calling into a third-party library for which I don't have access to the code. As part of its operation, this library spawns a thread to do some work on. Recently, though, this other-thread work is throwing an unhandled exception. Is there any way to keep the entire application from being brought down?

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

GrumpyDoctor posted:

I'm calling into a third-party library for which I don't have access to the code. As part of its operation, this library spawns a thread to do some work on. Recently, though, this other-thread work is throwing an unhandled exception. Is there any way to keep the entire application from being brought down?

My first suggestion is to drop that third party library like a rock. If that really isn't an option, then you have some options depending on what kind of application it is. If it's WinForms, then you can use SetUnhandledExceptionMode. If you're in WPF, you can use DispatcherUnhandledException. This is very hackish, however, and I would urge you to look for a better library.


Dromio posted:

I need to do some complex model binding to an action in MVC using HTTP GET instead of POST.

My XY spidey sense is going off. What are you caching and where are you caching it? Are you sure it's necessary?

Binding to GET requests in MVC is a hassle and should generally just be avoided. There's probably a better way of doing what you're trying to do.

raminasi
Jan 25, 2005

a last drink with no ice

Bognar posted:

My first suggestion is to drop that third party library like a rock. If that really isn't an option, then you have some options depending on what kind of application it is. If it's WinForms, then you can use SetUnhandledExceptionMode. If you're in WPF, you can use DispatcherUnhandledException. This is very hackish, however, and I would urge you to look for a better library.

Oh, I am all over switching, don't worry, but I'm looking for some very-short-term stopgaps. Unfortunately, this is a WinForms app, and according to that documentation, that handler can't actually prevent termination from non-UI-thread exceptions, so it doesn't really help us.

ljw1004
Jan 18, 2005

rum

GrumpyDoctor posted:

Oh, I am all over switching, don't worry, but I'm looking for some very-short-term stopgaps. Unfortunately, this is a WinForms app, and according to that documentation, that handler can't actually prevent termination from non-UI-thread exceptions, so it doesn't really help us.

I'd be scared enough to run the separate library from a separate process, one I'm happy restarting as needed

Newf
Feb 14, 2006
I appreciate hacky sack on a much deeper level than you.
Can anyone here tell me about discount options for hosting an extremely low traffic MVC site with a very small database? I'm looking to make a quick and dirty attendance/merit tracking webapp for someone managing the homework room of a Boys and Girls Club, but the local network isn't accessible for me to host the thing due to national Boys and Girls club bureaucracy which I'd rather sidestep.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Newf posted:

Can anyone here tell me about discount options for hosting an extremely low traffic MVC site with a very small database? I'm looking to make a quick and dirty attendance/merit tracking webapp for someone managing the homework room of a Boys and Girls Club, but the local network isn't accessible for me to host the thing due to national Boys and Girls club bureaucracy which I'd rather sidestep.

Do you have an MSDN subscription? If you do, Microsoft gives you up to $150 per month of free Azure hosting, depending on subscription level (Pro/Premium/Ultimate). It goes a long way for a low-traffic site.

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost

Ithaqua posted:

Do you have an MSDN subscription? If you do, Microsoft gives you up to $150 per month of free Azure hosting, depending on subscription level (Pro/Premium/Ultimate). It goes a long way for a low-traffic site.

I have "Visual Studio Professional with MSDN" and get $50 in credits and I usually end up using $15 or so of that with the few sites I have up there.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Drastic Actions posted:

I have "Visual Studio Professional with MSDN" and get $50 in credits and I usually end up using $15 or so of that with the few sites I have up there.

Yeah, I think it's Pro = 50, Premium = 100, Ultimate = 150

I have $150 and I'm hosting like 6 low-traffic sites and some VMs (that I turn on on-demand), and I never even come close to using all $150.

Newf
Feb 14, 2006
I appreciate hacky sack on a much deeper level than you.

Ithaqua posted:

Do you have an MSDN subscription? If you do, Microsoft gives you up to $150 per month of free Azure hosting, depending on subscription level (Pro/Premium/Ultimate). It goes a long way for a low-traffic site.

Nope, I'm afraid not. At home I'm actually still using a copy of VS that I installed (legitimately) with the student license. (I guess I should move over to the new Community edition).

Drastic Actions posted:

I have "Visual Studio Professional with MSDN" and get $50 in credits and I usually end up using $15 or so of that with the few sites I have up there.

How much does that run you?

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Newf posted:

Nope, I'm afraid not. At home I'm actually still using a copy of VS that I installed (legitimately) with the student license. (I guess I should move over to the new Community edition).


How much does that run you?

VS MSDN licenses aren't cheap. Pro is $1,200 per year, and Ultimate is around $14k. It's mainly for enterprise users, although the MSDN benefits are pretty great.

RICHUNCLEPENNYBAGS
Dec 21, 2010

Ithaqua posted:

VS MSDN licenses aren't cheap. Pro is $1,200 per year, and Ultimate is around $14k. It's mainly for enterprise users, although the MSDN benefits are pretty great.

The discounts for nonprofits are insane.

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost

Ithaqua posted:

VS MSDN licenses aren't cheap. Pro is $1,200 per year, and Ultimate is around $14k. It's mainly for enterprise users, although the MSDN benefits are pretty great.

Yeah, I got it through work. I need VS for ASP.NET work (No chance in hell I'm going to use Xamarin Studio for that :v:).

gariig
Dec 31, 2004
Beaten into submission by my fiance
Pillbug

Newf posted:

Can anyone here tell me about discount options for hosting an extremely low traffic MVC site with a very small database? I'm looking to make a quick and dirty attendance/merit tracking webapp for someone managing the homework room of a Boys and Girls Club, but the local network isn't accessible for me to host the thing due to national Boys and Girls club bureaucracy which I'd rather sidestep.

If you are in school you can do Dreamspark (or Githubs pack which includes Dreamspark) or BizSpark. I'm pretty sure BizSpark has very little requirements to join, I think you just need to sign up.

chippy
Aug 16, 2006

OK I DON'T GET IT
DreamSpark is pretty great. You don't get quite as much stuff as is available with an MSDN subscription but there is plenty of stuff, including all versions of VS.

I signed up for the Github student developer pack thing recently and was told they would email me about it in "a few weeks". Anyone know why there's such a long delay setting it up?

Polio Vax Scene
Apr 5, 2009



Why the gently caress did .NET MVC work perfectly fine yesterday then absolutely poo poo the bed when I rebuilt and published this morning? I fixed it by readding the references and setting copy local to true but it is not the first time this has happened.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Newf posted:

Can anyone here tell me about discount options for hosting an extremely low traffic MVC site with a very small database? I'm looking to make a quick and dirty attendance/merit tracking webapp for someone managing the homework room of a Boys and Girls Club, but the local network isn't accessible for me to host the thing due to national Boys and Girls club bureaucracy which I'd rather sidestep.

AppHarbor starts at free https://appharbor.com/pricing

Newf
Feb 14, 2006
I appreciate hacky sack on a much deeper level than you.

This looks like it might be the ticket. Thanks all for the input.

epswing
Nov 4, 2003

Soiled Meat

This is awesome, thanks for sharing.

EssOEss
Oct 23, 2006
128-bit approved

Manslaughter posted:

Why the gently caress did .NET MVC work perfectly fine yesterday then absolutely poo poo the bed when I rebuilt and published this morning? I fixed it by readding the references and setting copy local to true but it is not the first time this has happened.

There is probably something wrong with your project setup. I have never seen a case where "Setting copy local to true" is a meaningful step for a well-formed project, only cases where it can be sort of used to hide some deeper underlying issue.

Adbot
ADBOT LOVES YOU

Inverness
Feb 4, 2009

Fully configurable personal assistant.
There's an update to the .NET Framework blog about the status of open source.

I'm surprised that they've only moved 25% of things to GitHub so far.

I'm curious about what exactly is involved in moving those libraries and the CLR repository to GitHub that is consuming their time.

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