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
Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

Ithaqua posted:

If you're doing true CI, I strongly recommend hooking up an on-prem CI solution. Team Build will of course work just peachy with VSO, as will Jenkins and TeamCity.
Not that it's noticeably better or worse than than those but Bamboo is fine for CI too if you're into Atlassian products.

Adbot
ADBOT LOVES YOU

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer
You might want to look into cache control headers so repeated page views from the same client won't need to hit your server. Check out the OutputCacheAttribute.

Also look at what EF is running to grab the content. SQL Express Profiler is free and can tell you what SQL is being executed. If the database is what's slowing everything down you might need to address what EF is generating or whether you need indexes in the database.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

Geisladisk posted:

Does anyone have any tips for streamlining Windows Service development?

I started working on a large, mature system two months ago, which runs on a fairly baffling ecosystem of virtual machines. Most of these VMs are running windows services, which I need to develop.

I've got batch scripts that, whenever I recompile a particular service, automatically uninstalls it, copies the new files to the VM, reinstalls the service, and then starts it. I then attach the debugger to the process running on the VM if I need to debug. This is all fairly nice, but the process still feels very unweildy, and compiling and running the code takes up to a minute, which is frustrating me more than it should.

Are there any ways to streamline this process that I haven't noticed? I'm running visual studio 2012 pro, but I can get a upgrade to 2013 pro if needed.

Depending how much scope you've got to mess with them I've used http://docs.topshelf-project.com/en/latest/overview/faq.html before and it's pretty good. You write your service as a console app with this wrapping it up. Lets you run from the command line for testing and adds install/uninstall command line flags which do that junk for you.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer
Re: ELMAH alternatives:

I've used StackExchange.Exceptional and it's pretty good. Stacks repeated exceptions so it's easy to read but will throw away some info in that case (only keeps the http context data for the first one etc.). Less configurable than ELMAH but it's easy to throw custom data into it along with the exceptions.

I haven't used it but I've heard good things about Serilog.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

Ithaqua posted:

Something I was thinking about earlier:

Let's say you have an event. When you fire the event, you want to provide some event args, but the contents of the event args don't really match up with any strongly-typed models you have, and it's a bit too specific to warrant any sort of reuse, and also you're a lazy jerk.

Is it wrong to do public event EventHandler<dynamic> FooEvent;?

The invocation (in my mind) would be to handle a case like this:

code:
FooEvent(this, new { Stuff=whatever, OtherStuff=butts });
It feels wrong, but I can't express what's so wrong about it.
It feels wrong because you won't catch a typo there and it's a public interface. It's pretty borderline IMO, a class definition for that event args would be what, four lines? On the other hand it's a call in one place and not gonna be reused so who cares?

I'd consider who's on my team and who's gonna be supporting it because I wouldn't mind either way but there are people that would care *really hard* about it, and you could be setting a precedent.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

Ithaqua posted:

If you want to stay in the Microsoft stack and keep it simple (and can afford licensing costs), MS Release Management fits the bill. It can kick off a custom workflow-based deployment sequence, a DSC script, or Chef.

DSC, Chef, or Puppet are all attractive and reasonable options here.
If you're doing web stuff Octopus Deploy is also pretty good. It can handle setting up IIS correctly and doing web config transforms / connection strings etc.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

Ithaqua posted:

RM...
I don't have any Octopus Deploy experience, but it looks solid.
Yeah, I've used Octopus on a couple of projects and been happy with it. Looks like I need to look at the MS stack again though.

Green_Machine posted:

There's a framework ideal for writing scenario-based BDD-style unit test that ties into MSTest. It's called Given.
This looks a lot like BDDfy. I haven't used it myself, NUnit is usually enough for me.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

Scaramouche posted:

I think this is possible, but I was wondering if you guys could give me a direction to get started. I've got a large number of images provided by a third party. Some of them are either contrasty, adjusted poorly, or what have you. This means that backgrounds that should be white, are instead kind of an off-white. Here's an example image:


So what I'd like to be able to do, programmatically, is 'fix' these images so the white is actually RGB 255 white. Do you guys have any suggestions or libraries that you think are up to this?

Note: I don't have to be able to >find< them, I have another service that does this. I'd be inputting a big list of file names with weird backgrounds into whatever solution I develop.
If this is a one-off batch conversion I'd probably go Python or similar if you're comfortable with it because there tends to be simpler libraries for this sort of thing.

If you are going .Net, I'd just fire up nuget, search for image processing, filter by popularity and start googling library names until I found one that looked right.

The other thing to consider is whether the "blended" bits where the background meets the item are going to look okay. Try paint bucket fill on a few with the more "off" backgrounds and see if it's noticeable. If you need those bits converted properly I think you might be heading into script photoshop/gimp territory unless a there's a library that explicitly does this.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

Ochowie posted:

So I have an f# question. Has anyone done pattern matching on .NET types using the :? operator? I'm using f# to do some financial calculations on a list of various types derived from a base class and calculations need to be performed based on the derived type. I could give each of them a calculate method and use polymorphism but I was intrigued by the ability in f# to pattern match on type.
It works pretty much like you'd expect but stylistically it sounds like this is when you should use polymorphism.
code:
match item with
| :? DerivedTypeA as d -> d.i + 2
| :? DerivedTypeB as d -> d.m + d.n
| _ -> 14
Without the catch-all case you'll get a compiler warning because it can't guarantee that another sub-type won't be written and you'd get a run-time exception if you do pass it one. With the catch-all case you won't get any warnings and it's not obvious to someone adding a new sub-type where in the codebase they have to add those sort of operations.

Destroyenator fucked around with this message at 13:25 on Oct 14, 2014

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

Ochowie posted:

I know I should, but these are POCO EF entities and I feel dirty putting what is essentially business logic right on the entity class. Transferring them to DTOs would essentially require the same kind of type checking since i would get a list of base objects and want map them to a list of DTOs.
Well you know the codebase better than any of us and it's partly a personal preference thing, try it out and see how it feels? Think about how often a new sub-type will be written, how many different places you'll need to put switching logic and whether you're setting a precedent (either way).

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer
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)

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer
Yeah, sorry I could've been clearer, the << operator is function chaining, it's just a terser way of writing:
Array.filter (fun x -> not (System.String.INOE(x)))

Where "not" is just the boolean not like "!" in c#.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

chmods please posted:

Aren't those array functions evaluated lazily? I wonder if stepping through in the debugger forces an evaluation and you wouldn't otherwise see it in normal execution for a while.
No, the array ones are eager. You can always poke around in the internals here: https://github.com/fsharp/fsharp/blob/master/src/fsharp/FSharp.Core/array.fs#L144 if you need to check. The Seq ones are lazy IEnumerables though.

Bognar posted:

I wish C# has this kind of composition. I love that you can do .Where(string.IsNullOrEmpty) but I hate that you have to do .Where(x => !string.IsNullOrEmpty(x)).
Yeah, and I find myself wanting to do it with single arg constructors more often than you'd expect.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

ljw1004 posted:

NameOf operator - https://roslyn.codeplex.com/discussions/570551
This aims to be used in places like ArgumentNullException, or PropertyChangedEventArgs, or DependencyProperty.Register, where you need to pass the string name of a programmatic element but if your code is full of string literals then it's too easy to make mistakes.
code:
// Changed to allow certain expressions in its argument
Console.WriteLine(nameof(this.p)); // returns "p"

// Changed to disallow certain types
var s = nameof(List<>.Length); // now an error

// Changed to allow only a sequence of dot-qualified identifiers
var s = nameof(StrongBox<string>.Value.Length); // returns "Length"
var s = nameof(((StrongBox<string>)(null).Value); // error not allowed casts
This looks cool and it seems like you've though out all the main use cases. I'm not clear though if you're able to do chained member access on types?
eg. nameof(SomeClass.Property.InnerPropertyName)

I'd probably use them when constructing web forms that post back different view models.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

Che Delilas posted:

I'll keep AutoMapper in mind - this project is pretty simple, so I'm happy just manually creating all my viewmodels, but I've seen it mentioned before a number of times as a real energy saver.
I'm not convinced by it. I've seen it in projects before and you either don't get any information when you rename/delete fields on either side, or you use it's validator which involves writing out either all the mappings or all the differences for each pair of classes at which point why not just write the mapping yourself? Unless I'm missing something major I don't see the value there?

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

Funking Giblet posted:

I think you're missing something major! You can validate the configuration at runtime which will find unmapped fields, or write a unit test to do as much. Not to mention injectable value and type resolvers which can be reused across types.
Yeah I've seen the validation as unit tests thing, but the places I've seen it usually involve writing a bunch of exceptions for the missing/extra/renamed fields. That's when I get to: why bother, you're effectively writing the maps anyway at this point?
I guess I haven't seen it work out simpler in the long run (though I've only really seen it used extensively twice), but if it works for you great.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer
Try to get the responsibility for reviews to be shared by the whole team. You don't want to end up as a "gatekeeper" or seen as a blocker to code getting to production. The team should be responsible for code quality.

In reviews just make sure you aren't too hard (especially early on). You're looking for acceptable not perfect. Even if no code is changed as a result of reviews you'll be getting benefits from better visibility of the code base and what your colleagues are doing day-to-day.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

chmods please posted:

I'm using Autofac with an MVC project. I need to provide a value from HttpApplication.Request to the container - it needs to be used elsewhere in the hierarchy, possibly from components which don't know anything about ASP.NET. Something like:

code:
protected void Application_Start()
{
    // register a bunch of things including ButtModule
    builder.RegisterInstance(Request.UserHostAddress).Named<string>("RequestAddress");
    container = builder.Build();
}

// in a module far, far away
public class ButtModule : Module
{
    protected override void Load(ContainerBuilder builder)
    {
        builder.Register(c => new Butt(c.ResolveNamed<string>("RequestAddress")).As<IButt>().InstancePerDependency();
    }
}
Unfortunately, the request object is not available in Application_Start - it throws an exception "Request is not available in this context". I tried to be sneaky and register it with a lambda instead, but run into the same problem. It seems like it would be bad to build the container in BeginRequest but I can't think of anywhere else where I could access the request data and provide it to the container before it is needed to resolve dependencies. Ideas?
I think this does what you're looking for? http://stackoverflow.com/a/15542425/291137
You may have to add the Autofac.Mvc package if you haven't already.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

Dromio posted:

We’ve had an issue where we changed our deployment to support testing an upcoming release in development and QA, but then had to re-deploy the older Production build and couldn’t without a good deal of work.
I think Octo will keep track of the config and steps for a deployment so if you have a previous actual deployment to prod you should be able to find it and repeat it with the the same process. Creating a new release will use the new settings though.

If you run into similar again one way of mitigating a bit is to just add new tags to your servers and target the new steps to them. If there's no servers matching those tags in production those steps can be skipped. You might be able to target config transforms to tags as well but I'm not 100% on that.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer
You may also run into the browser/webserver/load balancer/cache/whatever limiting your max URL length.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

aBagorn posted:

Follow up, so if I'm reading these correctly, EF does NOT by default lock DB rows?

This is something that he's hung up on and the more ammo I can take in the better.
I think the answer is to just write some code and use a profiler to see what gets sent to the SQL server. You can show each other the actual SQL and decide if it'll be acceptable. Usually with EF I would create a new context per request (so entity caching happens per request), and use transactions (with using blocks) where you need them.

What migration strategy will you be using, and how does the DBA feel about that?

edit: that's a context per web request, not DB request.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer
Does anyone know of a simple web monitoring/reporting tool I can plug into an MVC site? I just want basic stuff like request times and maybe SQL timings, what MiniProfiler does essentially but rolled up over all users and with a simple admin screen for monitoring hosted within the same app.

I could build my own, either timing begin request to end request or just reading IIS logs, but it seems like this should be a simple thing someone's built?

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

Mr Shiny Pants posted:

This has stumped me for awhile:

Does anybody know how in F# I can start parallel async tasks and select one that returns a certain value?

I want to download something in parallel from a couple of webservers and need the one that returns 200. The others may not respond that is why I would like it to run in parallel.

I really have no clue, I've looked at joinads and observables but have no idea how to glue it all together.
I feel like there should be a more idiomatic way of doing it, but it works.
code:
open System
open System.Threading.Tasks
open System.Net
open Microsoft.FSharp.Control.WebExtensions

let getWinner urls =
    let result = new TaskCompletionSource<Uri * string>()
    let fetch url = async { let uri, client = new Uri(url), new WebClient()
                            try let! response = client.AsyncDownloadString(uri)
                                result.TrySetResult (uri, response) |> ignore
                            with _ -> () }

    async { do! List.map fetch urls |> Async.Parallel |> Async.Ignore
            result.TrySetException (Exception "all failed") |> ignore } |> Async.Start

    Async.AwaitTask result.Task |> Async.RunSynchronously

let urls = ["http://broken"
           ;"http://google.com"
           ;"http://dnsjkadnksja.dsnakldsaoni.net"
           ;"http://dsadsdsa"]

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer
Yep.

https://github.com/dotnet/coreclr/blob/02084af832c2900cf6eac2a168c41f261409be97/src/mscorlib/src/System/Globalization/DateTimeParse.cs#L2484 posted:

code:
#if FEATURE_CORECLR // on CoreCLR DateTime is also restricted to +- 14:00, just like DateTimeOffset

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer
What is your ideal/required process for versioning and QA?

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

xgalaxy posted:

What does everyone suggest for good code coverage tool?
Right now I'm looking at NCover, OpenCover, and dotCover

It looks like NCover and OpenCover provide better code coverage reporting vs dotCover. If I could actually use Visual Studio instead of Xamarin Studio (barf) it might swing things in dotCover's favor but as it is that isn't a possibility for me currently.

Any comments about NCover vs OpenCover? Or some other code coverage tool?
What's your end goal here? Is it going to be a metric you track or do you just want some confidence?

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer
It's also useful for moving data between your objects and generated classes for messaging/remote services/etc. Never bothered looking into performance though.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer
Yeah, I definitely agree with that sentiment. Closing streams they didn't open isn't a great pattern and I've hit it a couple of times.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer
With Reshaper you can use Alt-End for go to derived class which works on interfaces.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer
I've used a similar pattern of query/command on a few projects, it's worked really well and how big you make the infrastructure is up to your needs.

I got fairly far with a really simple implementation in one case, along the lines of:
C# code:
public interface ICommand
{
    Task Execute(IDbConnection connection, IDbTransaction transaction);
}

public class CreateThingCommand : ICommand
{
    public Guid Id { get; private set; }
    public string Something { get; private set; }

    public CreateThingCommand(Guid id, string something)
    {
        // throw validation errors here
        Id = id;
        Something = something;
    }

    public async Task Execute(IDbConnection connection, IDbTransaction transaction)
    {
       // dapper goes here
    }
}
With this on the BaseController:
C# code:
public async Task ExecuteCommandAsync(ICommand command)
{
    using (var conn = GetConnection()) // some ioc magic here
    using (var trans = conn.BeginTransaction())
    {
        await command.Execute(conn, trans);
        trans.Commit();
    }
}
There's a separation of concerns thing there about the command being it's own handler and once you start scaling up you'll want to inject something with the "Execute" method for testing purposes but those are simple to solve when you start hitting pain points.
The controllers end up being fairly declarative and readable too:
C# code:
[HttpPost]
public async Task<ActionResult> CreateMeAThing(string something)
{
    var id = Guid.New(); 
    var command = new CreateThingCommand(id, something);
            
    await ExecuteCommandAsync(command);
            
    return RedirectToAction("View", new { id });
}

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer
I tend to avoid property injection too. I would only use a base class with injection for a base Controller in MVC/WebAPI where you know you're always going to want a RoleService or UserRepo or something in almost every action, and they all have a common base class anyway. In that case I'd go with property injection on the base class (to save passing them through all the time) and ctor injection for everything else.

One solution for your problem could be an interface that defined the services as properties. Then you could allow property injection only for that interface, your view models that take that standard set could implement the interface to get them and any additional services would be injected the standard way. You do end up with some property injection but it's limited and you avoid the base class concerns. (Disclaimer: haven't tried this, not sure which IoC containers will let you wire up injection method based on interface rather than implementation.)

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer
Not sure about Mercurial but I've seen setups that the CI server will create a git tag on the commit it used to achieve the same effect.

edit: for background tasks on a web app I've heard good things about http://hangfire.io

Destroyenator fucked around with this message at 02:28 on Jun 2, 2015

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer
I didn't realise how far the Roslyn stuff has come but yeah the three types of search and go to implementations for interfaces, refactor tools (especially introduce var/param and inline), snippet stuff for all the common operations (use var, invert if to reduce nesting, remove dead code, simplify conditionals, foreach-linq conversions, remove braces).

I find in a solution with DI/IoC I'm using this pattern all the time: type "_userService", alt-enter -> introduce field, the type is highlighted so type "IUS" press enter, alt-enter -> initialise from ctor param (which jumps to the ctor), jump up to issue and alt-enter -> make readonly, jump down issue which is usually my unfinished line. It looks like with the Roslyn stuff I'd be able to make that a thing I can do in one step?

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

Uziel posted:

We would actually be running it on the same machine (dedicated to our app) since its an intranet application. Guessing private queues would work then!
I've seen Hangfire (free version) used for this before too, it uses an SQL backend to manage it's queues so if you've already got one up there's not much added infrastructure. Pretty easy to configure, not sure how well it does under massive load but for intranet stuff you should be fine.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer
Write tests for what's going to break and for odd cases that will be forgotten so that when people fix your code they don't break the functionality.

Good tests should explain the code, but always consider [value delivered/time spent] for everything your write.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

GrumpyDoctor posted:

I'm having a weird AutoMapper problem. Mapper.AssertConfigurationIsValid() succeeds, but all my actual mappings are failing with "Missing type map configuration or unsupported mapping." As an example: I'm mapping a Source.GlazingMaterial to a Destination.GlazingMaterial, but the mapper, in a child mapping, then tries to map the source object itself to an Int32 field, which obviously fails. I don't know which one, because neither type even has any Int32 fields. Something like this is happening with every type - the mapper tries to map the source object itself to a field on the destination object (which may not even exist). Calling Mapper.Reset() before establishing my mappings doesn't fix the problem. Is there any way to ask AutoMapper wtf it thinks it's doing?

e: When the exception is thrown, AutoMapperMappingException.Context.MemberName is empty. That seems...wrong.
Wild guess, is the Mapper.AssertConfigurationIsValid in the same build mode (debug/release)? Anything funky with the models being in assemblies targeting different runtime versions from the call site/tests?

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer
Weird. Any chance it's generating a parent class mapping that's getting selected so the child specific fields aren't recognised?

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer
xUnit and Shouldly, sometimes Moq or Autofixture. The NCrunch test runner is pretty amazing but it's quite pricey, I usually use it in conjunction with the ReSharper one. Most build servers will make it easy to use the xUnit standalone runner.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer
Untested, but I think this would do it?
C# code:
public Task LogMessageAsync(string message)
{
    Console.WriteLine( ... );   // nothing to await and no Console.WriteLineAsync call
    return Task.FromResult(0);
}

Adbot
ADBOT LOVES YOU

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

rarbatrol posted:

Yeah, switching from C# to F# at work feels like going back to working with notepad sometimes.
I would be pushing more F# at work if the tooling was better.

Gul Banana posted:

talking the language maintainers into using a multipass compiler and allowing unordered files would be nice :-(
I think this is explicitly not a goal, and type providers make it harder than it should be even if they wanted to. The fact you end up with so much more actual functionality in each file (single line data type declarations etc.) is meant to make it less of a problem than in a C# codebase.

edit: Also more guidance on coding style. We rely heavily (with R# help) on the MS style guide in C#. In F# there isn't really anything in the community or from MS about a consistent approach to naming, scoping, project layout etc.

Destroyenator fucked around with this message at 13:32 on Aug 28, 2016

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