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
Mr Shiny Pants
Nov 12, 2012
Get the Git Extensions and download the sourcecode provider for VS.

Works pretty much as it should.

Adbot
ADBOT LOVES YOU

Mr Shiny Pants
Nov 12, 2012

hirvox posted:

If you are certain that your code will output valid XML, you should just write each line to the file as soon as you have generated each snippet. That way you'll only need to have one copy of the data (the DataTable) in memory at any time. The way you're doing it now you'll have at least four copies: The DataTable, the StringBuilder, the String itself and finally the XmlDocument.

Yep, a stringbuilder with a textwriter and append each line to a new file.

Read the file afterwards if you need it again.

^^ Nevermind :)

Mr Shiny Pants
Nov 12, 2012
Have you tried a bufferedstream?

Something like:

code:

using(var instream = new bufferedstream(new FileStream())
{

}

Mr Shiny Pants
Nov 12, 2012
I've used the MemoryCache before. It works as advertised.

See: http://msdn.microsoft.com/library/system.runtime.caching.memorycache.aspx

You create a cache, put items in it and in your application that loads the resources you create the logic to check the cache first.

Please be aware that you can't depend on your files always being in the cache, if your machine gets low on memory it will purge some of the items in the cache.

Mr Shiny Pants
Nov 12, 2012

Begby posted:

I have an issue that is driving me absolutely bonkers.

I have a C# app that is running as a service on a windows server. It polls a bunch of different shopping cart web services on a fixed schedule.

For one particular client, it fails with a SSL/TLS error that the certificate is not trusted. This is only for that client, we can query that same exact service for other clients on their servers. The error only appears though after the service has been running for a couple of hours. If I shutdown the service and restart it, it starts working again for awhile.

- I have explicitly trusted their cert and the intermediary cert on the windows server where we run the C# service.
- When running the plugin using a unit test I setup and using the client credentials for their service, it works fine
- I have no SSL errors or anything when browsing to the client's website, it looks fine
- Rackspace looked at our server and claim it is all setup right

I am about to lose my mind since it works for an hour or so, then stops, and it is working fine for all of our 100+ other integrations that the service polls.

Can the server download a CRL? Does it have access to the CRL? Sounds like it does a check after awhile and can't validate the chain or something.

One thing you can test is to download the certificate and use the windows Certutil utility to check if you can build the certificate chain.

It uses the exact same apis as .Net does so any error should also turn up in there.

Another thing: Is the service running as a user and does it have the rootcerts in its own cert store?

Mr Shiny Pants
Nov 12, 2012

TheEffect posted:

I think this is the correct thread... Total newbie at VB.

Anyway, I'm creating a GUI in order to launch a batch file which then kicks off a PowerShell script. The GUI compiles fine and everything works great, however when I go to deploy the file it doesn't actually include any of the supporting files like the batch scrips or PowerShell scripts and their directories.

Stupid question but... how do I make sure these are included with the project when a user goes to install it? Using Visual Studio Express 2013.

Edit- Does it make it more complicated if there are directories that the PS script replies on in order to write out logs to? All my real coding is in the scripts. The form is just a user-friendly GUI.

You should create the folders within VS solution and tell it to copy the solution files "always". The copy option is within the file properties of the file you want it to copy.

Mr Shiny Pants
Nov 12, 2012

RICHUNCLEPENNYBAGS posted:

No, not until it produces results that are close to what I intended. :)

This.

Mr Shiny Pants
Nov 12, 2012
The new Identity stuff in MVC 5 is complex.

Been trying all day to wrap my head around it and finally got it working.
Owin and all the other stuff is totally new and the documentation doesn't make it any better.

Now to write my own userstore and the like pffff.

Mr Shiny Pants
Nov 12, 2012

Bognar posted:

We attempted to use it for a recent project, but ultimately we threw it out and rolled our own like we have done for years. I wish MS would get away from trying to provide the "one identity solution to rule them all" and instead just provide sane defaults for password hashing, password requirements, and default functionality for email validation, password resets, and the like.

Yeah I get what you mean, they are always trying to be all things to all men. See WPF, you can do almost anything with it but there are no "slick" standard controls a la OSX.

Mr Shiny Pants
Nov 12, 2012
What I found really annoying when first reading about it is that a lot of it is intertwined with Entity Framework without making it really clear what does what and why you'd need it.

I have it working with Redis now :D Yay me!

Mr Shiny Pants
Nov 12, 2012
So after getting the Identity stuff to work I am looking for some advice for building it out for my own webapplication.

My users have some extra attributes like street, country etc.

What would be my best option:

1. Extending the existing application user class with my own attributes. In effect having one user class in the whole of my application.

2. Create another table and link the application user (entity) to the username?

I like option 1 but 2 is also doable.

Mr Shiny Pants fucked around with this message at 17:09 on Aug 4, 2014

Mr Shiny Pants
Nov 12, 2012

wwb posted:

In general my experience has been one is best left leaving the authentication bits as a functional black box and then keeping your app's data (like demographic / address info) in data stores tied to my app. We typically go so far as to keep that asp.net databases as a physically separate DB as we don't like schlepping user logins back to developers.

That said, the new extensibility points in the Identity bits should make extending stuff to use a custom user with this info is much easier than what one had to do with the old membership providers. But I still don't like mixing the two myself.

Yeah this is exactly why I asked it, the new stuff seems built for extending and it keeps everything nice and tidy.

I am just not sold on it, on the other hand it is exactly how something like AD is structured.

Mr Shiny Pants
Nov 12, 2012

RICHUNCLEPENNYBAGS posted:

There's no reason at all to avoid adding fields to your ApplicationUser class/subclassing it/whatever. Especially if you're using the EF Code First Identity and EF Code First in your application. Nothing to it.

If it were me I'd make Address a class and give ApplicationUser an Address field.

I'll give it shot, I swore off EF though.

Mr Shiny Pants
Nov 12, 2012

epalm posted:

Any WPF gurus want to take a crack at this? http://stackoverflow.com/questions/25165505/how-can-i-show-the-user-what-they-are-typing-into-an-iseditable-combobox



The gist of it is: when the user types into an editable combobox, and a match is found, if the match is too long, the user can't see what they're typing. In this example gif above, typing "ABC" is fine, because it fits. Typing "PQR" selects the right item, but the user can't see what they're typing until they get further along in the string ("PQR-CONST...").

Dropdown list with all the possibilities? Getting shorter while they are typing?

The Google homepage does this, I think it is pretty elegant.

Mr Shiny Pants
Nov 12, 2012

epalm posted:

When I type into the google homepage, it bumps me up to the omnibar. I can still see what I'm typing even though there are longer options than the field is wide.



Anyways I'm not looking to build my own omnibar from scratch.

It does not do that for me, maybe only in Chrome?



I would show the dropdown and make it as wide as the widest option.

Tab completion and the possibility to select an item is what I would do.

How to build it in WPF? No clue, sorry.

Mr Shiny Pants
Nov 12, 2012
What do you guys use for session handling?

Session handling is not really the right word I guess, what do you use to keep models in memory if you know you need them again later?

It seems a bit of a waste the retrieve the same classes over the course of multiple controllers from the DB, instantiate them, use them and discard them again only to re-instantiate them a bit later.

Just retrieve them again or use some form of caching?

Mr Shiny Pants
Nov 12, 2012

Bognar posted:

Note that if you're dealing with multiple web servers, caching and cache invalidation becomes a harder problem. However, with just one web server you can either use something as simple as static variables (with thread-safe access), or possibly use the built-in ASP.NET caching.

See:
http://msdn.microsoft.com/en-us/library/vstudio/ms178597%28v=vs.100%29.aspx
http://msdn.microsoft.com/en-us/library/vstudio/18c1wd61%28v=vs.100%29.aspx


wwb posted:

Measure what the cost is -- you'd be shocked at how efficent modern stuff is. 99% of the time you can make zero real-world performance gains on the back end of your website that are measurable compared to things you can do on the front end like edge caching and compression. My 2c is the best going in proposition is to leave caching for anything longer than a single request until you have measurable performance gains you can get by caching it.

That said the key thing to think about is how long is the object life cycle? And how mutable are things? IE we have configuration objects that get hydrated on start and don't mutate and you can cache the living poo poo out of them. But anything violate is a bitch to cache, or really requires a cache invalidation strategy.

If you are really depending on the object to be there don't use ASP.NET's cache. At least the .NET 2.0 implementation would start ejecting things at the first sign of memory trouble. If you did something really retarded like have a cache callback to re-cache an object on ejection you got nasty loops. It really was written to be an output cache for the pages not a memcached equivalent.

Thanks I'll take a look and think about it some more. The cache problems you mention are something I would like to avoid.
Some Redis Pub Sub is something that I was thinking about. Publish the update on one server and have the caching server subscribe to that. Bit overkill for now but something that could work in theory.
It just feels wasteful :) I'll benchmark it first.

Another question: I am using Bcrypt.net for my password hashing and it really takes quite awhile to validate the password. I know this is the point of the whole bcrypt library but I was wondering if any of you have used this before and what some sane defaults are.

Mr Shiny Pants fucked around with this message at 20:55 on Aug 6, 2014

Mr Shiny Pants
Nov 12, 2012
I have to admit the whole DataAnnotation stuff is pretty awesome in MVC5.

All the validation rules you don't need to write by hand, phew.

Mr Shiny Pants
Nov 12, 2012

Bognar posted:

Sounds very similar to Event Sourcing to me. Changes to the model are described as events, and those events are applied in order. Events can be written to a database or queue extremely quickly and then processed separately. The end result is high scalability at the expense of immediate updates.

You probably won't find too many libraries for this since the events are highly specific to your domain model. Also, for the vast majority of the time you can get away with simple CRUD anyway.

To be honest I find CRUD to be not simple at all most of the times. I mean, looking at something like MVC with Entity Framework to do some CRUD operations is pretty complex stuff.

For my own project I first went with Nhibernate, switched to EF and later decided to go with PetaPoco for my DB operations because saving an object graph is hard I guess. It is, don't get me wrong, but that is what your ORM should be doing for you and in my, admittedly limited, experience they don't do a good job. Something as simple as order -> order item makes EF want to reinsert stuff again that it should not be doing. Looking at some blogs I am not the only who has this problem. (Attach object, set model state etc. etc.)

This requires you to jump through hoops with FK keys as strings in your model for one - to many relations. Nhibernate worked better, especially with fluent Nhibernate but all the mapping and lazy loading stuff makes it a complex beast to get going, let alone trying to figure out what broke if it decides to stop working.

With PetaPoco I just insert an order, retrieve the sequencenumber it generated and update the orderitem FK with this number and insert all the items in two stages. It is more work, but it is much simpler to reason about what your data access is doing.

Event Sourcing is pretty awesome, something like Akka persistence makes the whole object - relational impedance mismatch go away. CQRS is also neat.

Mr Shiny Pants
Nov 12, 2012

Sagacity posted:

It gives you a different set of problems, though. It's good to have immutable events, but you will never escape the fact that sometimes you designed your events in the wrong way.

True. There is no silver bullet, but if you design something wrong no pattern or architecture is going to help you.

Mr Shiny Pants
Nov 12, 2012

kingcrimbud posted:

I'm in the middle of creating a service that consumes something like 100 other services. My service will have its own model. Let's say my model has a Pet entity. And 15 of these other services have their own representations of what a pet is.

If I search these other systems and then try to represent these pets in my system, how can I model that correctly when each system has their own representation of a pet?

We've explored inheritance and creating a type per system. This gets really ugly fast and will be awful to maintain.
We've also explored decorating and compositing but again, this gets really complicated very quickly. In some cases, a Pet entity may have to have 20 new properties tacked on.

I'm currently looking at using the DynamicObject class and having my Pet inherit from it. I'm losing out on some safety and probably performance, but I can just set whatever properties I want on my Pet whenever I want.

Anyone experience a situation like this and come up with a good answer?

The easiest is probably the dynamic object. Otherwise you'll have to do something like writing connectors for each service that will transform the incoming pet to your representation.

How will you query the properties? I mean some pet could have the property "Name" others the property "name" etc. etc. You'll never have an exact representation of your entity.

This is something XSDs were invented for.

Mr Shiny Pants fucked around with this message at 20:22 on Aug 8, 2014

Mr Shiny Pants
Nov 12, 2012
I am not sure what you mean but:
code:

Console.WriteLine("The number of turns is:  " + turnsarray.Length + ".");
Console.WriteLine("The number of years is:  " + yearsarray.Length + ".");
Console.WriteLine("The number of months is:  " + monthsarray.Length + ".");


Use .Length or .Count on your arrays to print the total number?

Mr Shiny Pants
Nov 12, 2012

A Tartan Tory posted:

This wasn't it, but it did point me to what I was actually doing wrong. Nothing wrong with the arrays themselves, just how I was displaying them. Thanks for your help (I shouldn't learn to code at 5am in the morning).

Changed to the following.

code:
Console.WriteLine(string.Join(",", turnsarray));

It wasn't clear what you were trying to do, but printing just the array will display the type: System.Int32 instead of the number of items it contains. Which is what you usually want.

Mr Shiny Pants
Nov 12, 2012

Eggnogium posted:

Ah thanks, I have not worked much with JSON and didn't realize it wasn't even valid. Couldn't retrieve it as a string for the same reason but was able to retrieve it as a Stream and grab the raw bytes.

Use something like Json.net to serialize and deserialize you object to and from Json, it will save you a lot of trouble.

Mr Shiny Pants
Nov 12, 2012

candy for breakfast posted:

I inadvertently clicked on "Enable .NET framework source stepping" in the debug/general menu and now although It's unclicked it still steps through everything :( I even exported the config file and verified that the option is set to 0, but still no dice.

Using VS 2013.3, any suggestions?

Does this mean you get that annoying thing that says: Need source file for yadda yadda.cs?

No help, I got the same error. Now I get to remember each time make a call to an external library. Really, really annoying.

Mr Shiny Pants
Nov 12, 2012

Ithaqua posted:

It's an event handler, so it can't return a Task.

Let's say I have this pseudo-pseudocode:

code:
public class MyHub : Hub 
{
    public MyHub() 
    { 
        var eventyThing = new EventyThing();
        eventyThing.SomeEvent += ThingyHandler;
    }

    public async void ThingyHandler(object sender, EventArgs args) 
    {
    }
}
ThingyHandler will never be invoked. In fact, I'm pretty sure it's failing catastrophically behind the scenes -- everything after the event invocation doesn't occur.

[edit]
Basically, I'm writing a multiplayer, multi-instance turn-based game. I want the game instances to fire events when certain actions occur internally (for example, "round timeout expired, anyone who hasn't played this round yet can get hosed") so the clients can be notified. I don't want to pass an instance of the HubContext into the game objects, because that would violate the poo poo out of separation of concerns -- the game should be responsible for maintaining its internal state, and the hub should be responsible for figuring out what data to push to connected clients based on how the game's internal state is changing.

Why not logically make the game a client of the hub, the same as regular clients? Maybe a special client or something. That way logically everything is the same and the hub is only responsible for routing messages to its subscribers and you can reuse the message passing infrastructure that you already use for the clients.

Mr Shiny Pants
Nov 12, 2012

mortarr posted:

I was treating c# like javascript and it turns out if I do a Post instead of a Get I can JSON.stringify() my object and send it up as post data, and then it's all sweet from there. Can't believe I wasted like four hours on this poo poo.

Json.net is an awesome library when working with objects that you need to serialize to json. You serialize it, load into to the requeststream and off you go.

Mr Shiny Pants
Nov 12, 2012

epalm posted:

I've run into this before. My request should definitely be a GET, but the data I'm sending is complex (an array of objects with properties) and just doesn't work with GET, but does work with POST. When I say "doesn't work" I mean the IEnumerable arg is null.

So at the time I just called it a day and used POST.

But...what up with that?

Uhm GET is for retrieving data? Post is for sending? Maybe I am missing something?

EDIT: Or do you need send a query or something? What I usually do is use the URL to create the query.

Mr Shiny Pants fucked around with this message at 11:24 on Sep 4, 2014

Mr Shiny Pants
Nov 12, 2012

Bognar posted:


snipped the beginning out.
The big benefit of all this is when you add an entity to the model that should have its changes tracked. All you have to do is write one expression saying how to get from that item to the Company/Team/whatever and the changes are tracked automatically.

I was worried when building this, as I constantly am, about the performance implications of using a solution like this that does a significant amount of magically loading in extra entities. However, we have benchmarked it in multiple situations and only seen a 5-15% decrease in performance. I'm sure it could get significantly worse if you are joining on the entirety of your object model, but in the ways we use it I've seen no reason to expect that it will cripple the system.

Been on holidays, I just got back and saw this post sorry if it's a bit late. If I got it right it almost seems like you've build an ORM ( the defining relationships and change tracking ) over another ORM (EF). Why still use EF and not SQL directly if you do the change tracking yourself?

As for the item change tracking: Maybe something like event sourcing would have been a more natural fit? You write out all the events that happen to a model and store them in some list or table for later use.

Mr Shiny Pants fucked around with this message at 13:40 on Sep 29, 2014

Mr Shiny Pants
Nov 12, 2012
Cool, thanks for the explanation. I was just wondering :)

Mr Shiny Pants fucked around with this message at 16:59 on Sep 29, 2014

Mr Shiny Pants
Nov 12, 2012
Or use something like Redis and tell it to save after every update.

Mr Shiny Pants
Nov 12, 2012
If you are using F#, why not use a Type Provider instead of EF? Honest question.

Mr Shiny Pants
Nov 12, 2012
Is this F# code ok?

code:
let rec Process() =
    printfn "Listening"
    let context = listener.GetContext()
    Async.Start(ProcessRequest context)
    Process()
It is for a HttpListener that services requests. Usually it is done using a while loop, but I thought what the hell, F# is supposed to handle recursion fine.
Will this get me in trouble with stack overflows? Or will this be properly handled? Tail recursion is the word for this right?

Total F# noob here. :)

Mr Shiny Pants
Nov 12, 2012
Any ideas why this code gives me an AccessVilolation?

code:
let DecodeUrl (request:TogetherRequest) =
    request.Url.Segments
    |> Array.map(fun x -> x.Trim('/'))
    //|> Array.choose(fun x -> if (String.IsNullOrEmpty(x)) then None else Some(x))
    |> Array.choose(fun (x) -> match x with
                                | null -> None
                                | "" -> None
                                | x -> Some(x)) 
    |> (fun x -> {Method=request.HttpMethod;Url=x})
It should strip empty strings from an url after the split, but it errors out. In my limited knowledge it should build new arrays between the pipes so it is not trying to alter immutable arrays.
It only gives the error when stepping trough the code though, the result when running the program is fine and works as I expect it to do. :confused:

Both the commented array.choose as the other one give me this error.

Mr Shiny Pants
Nov 12, 2012

GrumpyDoctor posted:

Have you tried breaking up the pipeline to see exactly what the problem is?

Not yet, that was going to be my next step. I was scratching my head because I think it is quite reasonable code and everything I found on Stack overflow and the like said it should work.


Destroyenator posted:

You're right, they do create new arrays. If it's only when you're debugging it sounds like the "Locals" window or something in VS is trying to read something it shouldn't?

Side note: you can collapse your choose to a filter if you want:
Array.filter (not << System.String.IsNullOrEmpty)

Hmmm, I think you might be onto something. Pretty weird if it does. Access Violations during normal execution would stop my program right? I mean, I am not ignoring some exception silently?

Love your method, I am not that well versed in F# to work with it though. Not yet anyway. :)

Thanks

Edit: Thinking about your rewrite: Am I correct in assuming that the Not operator is a function that takes a value or a function? So you pipe the value coming out of the Array into the String.IsNullOrEmpty function and piping that into the Not operator? This results in a bool for the filter function? Sometimes F# code cooks my noodle.

Mr Shiny Pants fucked around with this message at 07:16 on Oct 20, 2014

Mr Shiny Pants
Nov 12, 2012

GrumpyDoctor posted:

You might want to double-check your exceptions list (Debug > Exceptions, I think) and make sure that "Thrown" is checked for that particular exception type. Do you see the problem any time you have a debugger attached, or just when you're actually stepping through?

Only when actually stepping through this particular piece of code.

Mr Shiny Pants
Nov 12, 2012
Rewrote it like this:
code:
let DecodeUrl (request:TogetherRequest) =
    let list1 = Array.map(fun (x:string) -> x.Trim('/'))request.Url.Segments
    let list2 = Array.choose(fun x -> if (String.IsNullOrEmpty(x)) then None else Some(x))list1
    let request = {Method=request.HttpMethod;Url=list2}
    request
Still getting the error.

Error message:

code:
System.AccessViolationException was unhandled
Message: An unhandled exception of type 'System.AccessViolationException' occurred in FSharp.Core.dll
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Edit:

Rewrote as pointed out:
code:
let DecodeUrl (request:TogetherRequest) =
    let list1 = Array.map(fun (x:string) -> x.Trim('/'))request.Url.Segments
    let list2 = Array.filter(not << String.IsNullOrEmpty)list1
    let request = {Method=request.HttpMethod;Url=list2}
    request
Still getting the accessviolation. Weird huh?

Mr Shiny Pants fucked around with this message at 18:43 on Oct 20, 2014

Mr Shiny Pants
Nov 12, 2012
Anyone have clue how to get SQLite working in F# using the Nuget drivers?

I downloaded the SQLite core drivers and referenced them, but no luck. During compilation it craps out and in the interactive window I am getting a cannot load DLL error SQLite.Interop.DLL.

Pretty frustrating, any pointers would be appreciated.

Edit: Found it. Don't know what is wrong with the Nuget package but the one from the site works great:

http://system.data.sqlite.org/downloads/1.0.94.0/sqlite-netFx451-setup-bundle-x64-2013-1.0.94.0.exe

It even works in the FSI and no mucking about with the interop DLL.

Edit 2: Wow, the X64 DLL does not work with the TypeProvider because Visual Studio is a 32Bit application that can't load X64 binaries.

So the X86 binary is still required for VS to work. Bummer.

Mr Shiny Pants fucked around with this message at 21:13 on Oct 20, 2014

Mr Shiny Pants
Nov 12, 2012

GrumpyDoctor posted:

Which line is the exception on? (And why did you eliminate that whitespace? That's a super weird style.)

What whitespace? I'll take a look and let you know.

Adbot
ADBOT LOVES YOU

Mr Shiny Pants
Nov 12, 2012
Wow pattern matching is nice.

Matching on a string and the contents of an array just blew my mind. :)

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