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
Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

Milotic posted:

Is the only easy-ish solution for a machine global 'mutex' which protects access to async code by using database transactions for acquiring exclusivity?

You could use a system semaphore since it's not thread-affine. Also, you can hook AppDomain.ProcessExit to make sure all your handles are released.

Adbot
ADBOT LOVES YOU

RICHUNCLEPENNYBAGS
Dec 21, 2010

Faldoncow posted:

I'm doing this right now, where I have my database-first EF model in a class library and am using it as a reference in a couple of other projects. There may be a better way, but so far all I've had to do is copy the connection string to the app/web.config of my other projects. I haven't run into any major problems so far.

IIRC DbContext has a constructor where you can pass in the connection string so you can use one class with the settings somewhere. However, I'd put it in the app.config/Web.config in at least one place so you can use the Server Explorer in VS.

Milotic posted:

Is the only easy-ish solution for a machine global 'mutex' which protects access to async code by using database transactions for acquiring exclusivity? Since async code isn't guaranteed to be re-entrant on the same thread, you'll blow up when you release the Mutex after the async code. The only alternative that springs to mind is a class which pins a mutex to a thread, and uses message passing to marshal calls to acquire/release the mutex onto that thread. That just seems like :effort:.

Use case is extracting a zip of binaries to a local directory (a bit like NuGet), and multiple builds for a given user. I can probably live without it for now. And if needs be use a database to register locks, and handle unexpected termination of the process.

You can use SemaphoreSlim without regard for threads... would that work? Why use a database?

Milotic
Mar 4, 2009

9CL apologist
Slippery Tilde

Bognar posted:

You could use a system semaphore since it's not thread-affine. Also, you can hook AppDomain.ProcessExit to make sure all your handles are released.

Ah neat. I'd browsed the docs for Semaphores, but I misconstrued the bit mentioning it being OK for app domains as being only OK for App domains.

Milotic
Mar 4, 2009

9CL apologist
Slippery Tilde

RICHUNCLEPENNYBAGS posted:

IIRC DbContext has a constructor where you can pass in the connection string so you can use one class with the settings somewhere. However, I'd put it in the app.config/Web.config in at least one place so you can use the Server Explorer in VS.


You can use SemaphoreSlim without regard for threads... would that work? Why use a database?

SemaphoreSlim doesn't support named system semaphores, so you can't use it for IPC - several build processes for a given user might be trying to unpack the same zip at once. The reason to use a database is via transactions, you can protect access to a resource - I've done this in the past when I've needed to control access to a folder containing a list of files greedily polled by services across multiple machines (yes I'm aware I could use a co-ordinator service, but it wasn't practical to set up a new service due to infosec constraints, and also then you've got a single point of failure).

ljw1004
Jan 18, 2005

rum

Milotic posted:

Use case is extracting a zip of binaries to a local directory (a bit like NuGet), and multiple builds for a given user. I can probably live without it for now. And if needs be use a database to register locks, and handle unexpected termination of the process.

Then I'd be inclined to do it with a .lock file ...

Milotic
Mar 4, 2009

9CL apologist
Slippery Tilde

ljw1004 posted:

Then I'd be inclined to do it with a .lock file ...

Yeah, I have used files to control parallelism in the past, but files aren't great when you expect heavy contention. I've left it for now, there's nothing worse than premature synchronization.

Actually, there probably is, and that's premature use of async/await. The headaches they introduce mean they're not really great for many long running server apps (my chief complaint is no more being able to log different requests to different files unless you thread through a logger object through every method call)

async/await has it's place, but I think it needs to be used with caution for server stuff

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

Milotic posted:

my chief complaint is no more being able to log different requests to different files unless you thread through a logger object through every method call

I'm not sure I understand what you mean here.

Milotic posted:

async/await has it's place, but I think it needs to be used with caution for server stuff

I don't disagree that async/await should be used with caution (see deadlocks and ConfigureAwait), but I don't think it's worse in servers than on desktops. One of the big benefits of it in the server is that it generally increases your throughput (since requests are suspended on an await rather than blocking a thread).

Bognar fucked around with this message at 21:56 on May 18, 2015

RICHUNCLEPENNYBAGS
Dec 21, 2010

Milotic posted:

Yeah, I have used files to control parallelism in the past, but files aren't great when you expect heavy contention. I've left it for now, there's nothing worse than premature synchronization.

Actually, there probably is, and that's premature use of async/await. The headaches they introduce mean they're not really great for many long running server apps (my chief complaint is no more being able to log different requests to different files unless you thread through a logger object through every method call)

async/await has it's place, but I think it needs to be used with caution for server stuff

Except that if you wait you're going to have to change all of your code.

Blasphemeral
Jul 26, 2012

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

Bognar posted:

I'm not sure I understand what you mean here.

Milotic posted:

...(my chief complaint is no more being able to log different requests to different files unless you thread through a logger object through every method call)...

I am also slightly curious what you mean here. Could you expand on it, at all? I might have a suggestion for you. I wrote a class a while ago for this purpose that might come in handy for you, but I'd need to know more.

Milotic
Mar 4, 2009

9CL apologist
Slippery Tilde

I am also slightly curious what you mean here. Could you expand on it, at all? I might have a suggestion for you. I wrote a class a while ago for this purpose that might come in handy for you, but I'd need to know more.
[/quote]

Sure, easy enough. You have a service running on a server which listens in for requests and performs work (in this case builds). Ideally you want to run multiple of these on a machine. Let's say we go for running multiple in a single process, with long lived threads, each grabbing work when it's finished its last build. You want to create build logs for individual requests so you can send them to the requesting user upon build failure (and also for diagnostics). You want different requests to go to different log files - in log4net this would normally be a case of using NDC or similar and setting it up so that log4net calls on that thread go to a specific file. But that doesn't work as soon as you're using async/await and/or running multiple async tasks at once.

So instead, you manually create a wrapper around a StreamWriter/FileStream with suitable InfoFormat methods etc, and pass that around through your method calls. e.g. Checkout(ILogger, ...), Build(ILogger, ...) etc.. It's a little tedious, but it works and is non-flaky and doesn't involve having to think too hard about what the heck the CLR is doing under the covers. That's the chief issue with async/await (or indeed the TPL in general) - you have to care about stuff it would be nice not to have to care about.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

Milotic posted:

So instead, you manually create a wrapper around a StreamWriter/FileStream with suitable InfoFormat methods etc, and pass that around through your method calls. e.g. Checkout(ILogger, ...), Build(ILogger, ...) etc.. It's a little tedious, but it works and is non-flaky and doesn't involve having to think too hard about what the heck the CLR is doing under the covers. That's the chief issue with async/await (or indeed the TPL in general) - you have to care about stuff it would be nice not to have to care about.

Fair enough, async/await requires a departure from thinking about your code as being attached to a single thread. This is obviously a problem for libraries that assume that (e.g. log4net), but in your own code you can switch to using something like CallContext.LogicalSetData and LogicalGetData to store information on a CallContext (which is maintained through async methods). At the top level of a request, you could do something like:

C# code:
CallContext.LogicalSetData("RequestId", Guid.NewGuid().ToString());
Then in your logger method:

C# code:
public static void MyLog(string message, var otherParams)
{
    var requestId = CallContext.LogicalGetData("RequestId");
    SomeOtherLogger.Log(requestId + ": " + message);
}

Inverness
Feb 4, 2009

Fully configurable personal assistant.
Well, at least with log4net you can create custom-named logs, configure them as necessary, and pass them around with a task's context. I'm not sure if it keeps references to loggers alive somewhere so that might not be a good idea if you're having a custom name for each request.

Milotic
Mar 4, 2009

9CL apologist
Slippery Tilde

Bognar posted:

Fair enough, async/await requires a departure from thinking about your code as being attached to a single thread. This is obviously a problem for libraries that assume that (e.g. log4net), but in your own code you can switch to using something like CallContext.LogicalSetData and LogicalGetData to store information on a CallContext (which is maintained through async methods). At the top level of a request, you could do something like:

C# code:
CallContext.LogicalSetData("RequestId", Guid.NewGuid().ToString());
Then in your logger method:

C# code:
public static void MyLog(string message, var otherParams)
{
    var requestId = CallContext.LogicalGetData("RequestId");
    SomeOtherLogger.Log(requestId + ": " + message);
}

Thanks, I know about CallContext, but it's kind of a wash with injecting in a logger. I guess you could call to a static logging class, and when you invoke log4net, set a property on the log message which is based on this and results in it being routed to the correct file. I guess I'm mostly kvetching!

Blasphemeral
Jul 26, 2012

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

Milotic posted:

Sure, easy enough. You have a service running on a server which listens in for requests and performs work ...
So instead, you manually create a wrapper around a StreamWriter/FileStream with suitable InfoFormat methods etc, and pass that around through your method calls. e.g. Checkout(ILogger, ...), Build(ILogger, ...) etc...

Ah, I see. That's not what I had in mind. Thanks for expanding on it, and sorry I don't have a ready-made solution for you.

Bognar posted:

C# code:
CallContext.LogicalSetData("RequestId", Guid.NewGuid().ToString());
...
C# code:
public static void MyLog(string message, var otherParams)
{
    var requestId = CallContext.LogicalGetData("RequestId");
    SomeOtherLogger.Log(requestId + ": " + message);
}

Woah, cool. I hadn't heard of this before. Thanks for the cool new toy.

chippy
Aug 16, 2006

OK I DON'T GET IT
Goons, help (Winforms). I have a textbox that needs to be able to accept a tab character. I can do this by making it MultiLine=True and AcceptsTab=False. However, I also need it to NOT accept/type a carriage return when Enter is pressed, as I need this to trigger an event. However, according to MSDN, AcceptsReturn=False only works if the form has a default Accept button, otherwise the Textbox will get a carriage return in it anyway. The form doesn't have a default OK button so what is happening currently is that the Enter key is triggering the event, but is also inserting a carriage return into the Textbox, which is only 1 line high so the 1st line is then disappearing. I need to trigger the event on the Enter key, and NOT have it insert a carriage return.

I'm considering a hidden default Accept button but this seems hackish. Can anyone suggest a proper way of doing this?

If anyone's wondering, these weird requirements are because the form is driven by a barcode scanner that emulates a keyboard. Operators need to be able to drive the whole thing with just the scanner, without using keyboard and mouse. Some of the barcodes use a tab character as a delimiter (I have no control over this), and the scanner automatically sends an 'Enter' keypress at the end of the scan (I have no control over this either). This was all working before but the tabs in barcodes are a new thing that's thrown a bit of a spanner into the works.

Probably also worth mentioning that the handler for the Enter being pressed is a KeyDown event at the form level. I'm not sure why this was done rather than handling the keydown event for each textbox individually. I thought it might help to handle them at the textbox level but when I created a test form to try this out it didn't actually make any difference.

Calidus
Oct 31, 2011

Stand back I'm going to try science!
Can't you just do a basic event handler to check if enter is keydown and textbox has focus? Couldn't you also just do text.TrimEnd(new char[] { '\r', '\n' }) on textbox change event if you want something simple and kinda hackish?

RICHUNCLEPENNYBAGS
Dec 21, 2010
Baseless speculation here but can you intercept each key press and only forward it if it's not enter?

SirViver
Oct 22, 2008

chippy posted:

Goons, help (Winforms).
Just checked it and this should do it:
C# code:
// Set via designer...
textBox1.AcceptsTab = true;
textBox1.Multiline = true;
textBox1.KeyPress += textBox1_KeyPress;

// In code behind
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
	if (e.KeyChar == (char)13) // Return
	{
		e.Handled = true; // Prevent newline being added to textbox
		HandleBarcodeEntry(textBox1.Text); // Move this from your form handler to here
	}
}
Not exactly watertight or pretty to look at, but it should get you going. Note that it has to be the KeyPress event and not KeyDown/Up, as the Handled property on their event object does exactly gently caress all (for preventing key input). If you don't like the (char)13 comparison, you can also create a bool returnKeyPressed or similar and set that in the KeyDown event by comparing e.KeyCode against the nicer Keys.Return enumeration value (and also maybe move the barcode handling code there and only use the KeyPress event to prevent the newline from being added).

Fastbreak
Jul 4, 2002
Don't worry, I had ten bucks.
I did a search but I couldn't find anything related, so forgive me if I am asking a old and tired question.

Short Version: I need a good CMS that gets out of my way. All of my sites have a lot of custom services and DB work, and I don't want to have everyone on my team change that.

Long Version:
For the longest time I just did everything custom, and had a set of admin tools I wrote and reused. Mostly all it did was update content blocks using tinymce, and users. I just called the content blocks in via rest, or put them in the model and it worked well. users were okay with it, but was never ideal. I was never busy learning a new CMS platform, I could just have all the control I needed and did it all by hand. I am now hitting the wall where I am spending more of my time updating and maintaining my ghetto CMS solution when I should be building something around it; basically I am at the point where CMS's have a market. I have been looking around and nothing I find is as simple as I wish it would be. Umbraco is going to make most of my services go through their controller class, or I have to start overriding a lot of their settings, which has other side affects. I have not yet given up on Umbraco, as it is the most promising at this point, but hopeful there is something better. PiranhaCMS looked promising, but I could not get it to load and install. DNN was obviously something popular but that was definitely more platform focused than complementing a custom project.

So does anyone have a good recommendation for a small, lightweight CMS, that will really just manage my content for me? Or at least have the ability to avoid all the other heavy lifting with a CMS?

Requirements:
.Net
>= MVC 4 compliant
Easily integrates into existing projects
Won't enforce style or code practices that are CMS specific.

Any help would be hot, thanks in advance.

wwb
Aug 17, 2004

Unfortunately there just aren't a lot of great .NET CMS options out there. I gave up and let the web hippies use wordpress or whatever they wanted to smoke and provide http services for the front end to consume.

gariig
Dec 31, 2004
Beaten into submission by my fiance
Pillbug
Orchard? I've never used

Fastbreak
Jul 4, 2002
Don't worry, I had ten bucks.

gariig posted:

Orchard? I've never used

Ah I should have mentioned Orchard. I did install it but I put it in the same camp as Umbraco: a really great (especially in potential) CMS for .Net. It's structure and extensability is pretty awesome considering it's size. But as wwb has said

wwb posted:

Unfortunately there just aren't a lot of great .NET CMS options out there.

So relatively speaking, a great .Net CMS is still a mediocre CMS from what I have found.

Maybe I do have to stick with my own lovely CMS build that I don't have time to maintain, but still praying someone has something in mind that could handle it.

Fastbreak fucked around with this message at 01:07 on May 21, 2015

RICHUNCLEPENNYBAGS
Dec 21, 2010

wwb posted:

Unfortunately there just aren't a lot of great .NET CMS options out there. I gave up and let the web hippies use wordpress or whatever they wanted to smoke and provide http services for the front end to consume.

Umbraco seems to be popular and uses MVC.

chippy
Aug 16, 2006

OK I DON'T GET IT

SirViver posted:

Just checked it and this should do it:
C# code:
// Set via designer...
textBox1.AcceptsTab = true;
textBox1.Multiline = true;
textBox1.KeyPress += textBox1_KeyPress;

// In code behind
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
	if (e.KeyChar == (char)13) // Return
	{
		e.Handled = true; // Prevent newline being added to textbox
		HandleBarcodeEntry(textBox1.Text); // Move this from your form handler to here
	}
}
Not exactly watertight or pretty to look at, but it should get you going. Note that it has to be the KeyPress event and not KeyDown/Up, as the Handled property on their event object does exactly gently caress all (for preventing key input). If you don't like the (char)13 comparison, you can also create a bool returnKeyPressed or similar and set that in the KeyDown event by comparing e.KeyCode against the nicer Keys.Return enumeration value (and also maybe move the barcode handling code there and only use the KeyPress event to prevent the newline from being added).

Ahhh, thanks, I'll give this a go. I actually already tried pretty much exactly this, but I was using KeyDown, so taht explains why that wasn't working.

Mr Shiny Pants
Nov 12, 2012
Is it possible to use a datatemplateselector design time in WinRT?

I can't find anything about this.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

chippy posted:

Ahhh, thanks, I'll give this a go. I actually already tried pretty much exactly this, but I was using KeyDown, so taht explains why that wasn't working.

For another option, I wouldn't bother dealing with input at all, instead I would handle the TextChanged event directly and get rid of any carriage returns.

wwb
Aug 17, 2004

RICHUNCLEPENNYBAGS posted:

Umbraco seems to be popular and uses MVC.

Popular != great.

Basically the economics of .NET with expensive developers, expensive hosting and barriers to entry killed it in this area. lovely PHP-based apps that could run on $1/mo web hosting plans won the war there for better or worse.

epswing
Nov 4, 2003

Soiled Meat

wwb posted:

Popular != great.

Basically the economics of .NET with expensive developers, expensive hosting and barriers to entry killed it in this area. lovely PHP-based apps that could run on $1/mo web hosting plans won the war there for better or worse.

Sounds like an opportunity.. ;)

wwb
Aug 17, 2004

I'm not so sure about that -- the content types don't give a poo poo about running on a good stack vs a bad stack and they also are loath to pay for decent hosting. On the other hand they have a hard-on for the massive plugin markets you see for wordpress or drupal because they can drag and drop them in and get the widget they want and such. Add on top of this that you'd really start thinking twice about building a site for a pure content play in 2014 -- why not just publish to medium and instantly get airtime without investing in building sites?

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison
Anyone have experience using the VS code coverage tools? I'm instrumenting a bunch of binaries and libraries on our build server, copying the coverage tool over (vsperf or something) to a test server, starting it and running my install + tests, then stopping everything. I get a .coverage file out at the end of the day but I cannot get anything to actually read it.

If I try to use something like visualcoverage either remotely or locally on that file, it complains about not being able to find the images. If I copy all of my instrumented assemblies over to the same directory that the coverage file is in, it complains that it can't find the symbols. If I copy the PDBs over, it still complains that it can't find the symbols.

The only thing I can think is that it's looking for the path where the PDBs were on the build server - dropping into the debugger seems to indicate that there's a path to them stored in that .coverage file - but it also seems to be searching in the directory that the .coverage file lives. I'm pretty much out of ideas at this point and Google isn't being much help.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

uncurable mlady posted:

Anyone have experience using the VS code coverage tools? I'm instrumenting a bunch of binaries and libraries on our build server, copying the coverage tool over (vsperf or something) to a test server, starting it and running my install + tests, then stopping everything. I get a .coverage file out at the end of the day but I cannot get anything to actually read it.

If I try to use something like visualcoverage either remotely or locally on that file, it complains about not being able to find the images. If I copy all of my instrumented assemblies over to the same directory that the coverage file is in, it complains that it can't find the symbols. If I copy the PDBs over, it still complains that it can't find the symbols.

The only thing I can think is that it's looking for the path where the PDBs were on the build server - dropping into the debugger seems to indicate that there's a path to them stored in that .coverage file - but it also seems to be searching in the directory that the .coverage file lives. I'm pretty much out of ideas at this point and Google isn't being much help.

What are you using for build?

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison
Welp, looks like I was onto something. When you instrument the assemblies there's a hard-coded path embedded in them somehow and if it's not accessible then everything just loving dies.

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison

Ithaqua posted:

What are you using for build?

msbuild by way of innumerable powershell scripts by way of teamcity

epswing
Nov 4, 2003

Soiled Meat

wwb posted:

I'm not so sure about that -- the content types don't give a poo poo about running on a good stack vs a bad stack and they also are loath to pay for decent hosting. On the other hand they have a hard-on for the massive plugin markets you see for wordpress or drupal because they can drag and drop them in and get the widget they want and such. Add on top of this that you'd really start thinking twice about building a site for a pure content play in 2014 -- why not just publish to medium and instantly get airtime without investing in building sites?

I'm going to look into Dozuki, Confluence , FrameMaker, but if they don't do what I need, or are prohibitively expensive, I might have to buckle down and do this myself: http://forums.somethingawful.com/showthread.php?threadid=3696351

ASP.NET MVC 5's Identity framework will suffice for user authentication/authorization, there are existing tools I can use to convert Markdown to html, and diffs of saved wiki markdown, and the rest is pretty much just shuffling text back and forth to SQL Server, and storing images on the filesystem.

HOW HARD COULD IT BE!? :v:

wwb
Aug 17, 2004

Looking at your request in that thread I would start with redmine -- it is a bit focused on being an issue tracker but they grew a pretty badassed wiki in the process. The main advantages is they do have an API that can be useful and it features built-in "dump this wiki as a PDF" features. The platform has pretty good extensibility so you can probably bolt on what you'd need.

As for how hard could it be -- the basics are generally easy but things get real squirrelly real fast. Especially if you factor in non-technical content managers doing things, needing the thing to function across dev, QA and production. And then if you want to get loopy and batshit you need to start thinking about custom components (aka plugins). Server-side is tricky but doable with IoC. The real fun is client-side -- how do you have a page with 42 individual components that don't know about each other and all wanting their own custom javascript? How does that come together? Who owns the html head section? Etc, etc. We got pretty close to solving most of this on the last CMS we built but we still couldn't keep up with the Wordpresses and Drupals of the world.

That said, if you are doing a site that is really about one thing that needs some limited CMS functions -- IE edit pages and maybe provide editable text blocks and anything more complex is custom programming -- the baseline toolkit you get with ASP.NET is pretty solid and goes a long way towards providing the functions you'd need.

RICHUNCLEPENNYBAGS
Dec 21, 2010
End users love TinyMCE. I mean that's no good if you can't trust the input but if you can then use that.

Iverron
May 13, 2012

I've used Orchard and came to the conclusion that if I wanted to write code that wasn't MVC, I'd not have searched for "MVC CMS" in the first place. I don't want to learn an entire framework and philosophy to use a CMS.

Umbraco is closer to MVC, but the several features (document types) are too close to a "who needs developers anyway?" mindset. Plus a few other quirks, like the split of front end users with back end users and the severe limitations of features with one vs the other. It's also kind of a Frankenstein of Web Forms and MVC when you lift the veil. But it is closer.

I'm not going to give DNN the time it would take to write about.

In the end, I rolled my own CMS (yes yes, boo hiss) with some help from our PHP Lead who rolled his own. My goal was "just please for the love of Xenu let me write MVC code" and still have those controllers and actions be accessible for user changes to page titles, metas, dynamic nav, etc. I'm still ironing out the kinks, but I'm fairly happy with how it turned out. I get to write MVC code, not another framework that sits on top of MVC code.

Fastbreak
Jul 4, 2002
Don't worry, I had ten bucks.

Iverron posted:

I'm not going to give DNN the time it would take to write about.

In the end, I rolled my own CMS (yes yes, boo hiss)

I think you will find that the consensus right now is that if you want a CMS that will get out of your way and let you write your own code, yeah you are rolling your own.

I might build some dll distributable that does nothing but save and serve content... but I really hate that we are building another product to do something that has a flooded market.

crashdome
Jun 28, 2011

Fastbreak posted:

but I really hate that we are building another product to do something that has a flooded market.

Web development since 1995

Adbot
ADBOT LOVES YOU

EssOEss
Oct 23, 2006
128-bit approved

Fastbreak posted:

Short Version: I need a good CMS that gets out of my way.

I work for a company that used to specialize in CMS building and I can confirm that there is nothing good available. You are much better off rolling your own if you really need .NET or going with WordPress if you do not need that much custom stuff.

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