Search Amazon.com:
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 $3,400 per month for bandwidth bills alone, and since we don't believe in shoving popup ads to our registered users, we try to make the money back through forum registrations.
«368 »
  • Post
  • Reply
fankey
Aug 31, 2001


Ithaqua posted:

Well, what happened was the async CTP installed a bunch of new stuff that targeted .NET 4.0. When you installed VS2012, it installed a new version of the framework, where all of that cool stuff is targeting .NET 4.5.

I know you already know this, but it bears repeating for future generations: Never use CTPs in production code, it will end up loving you.
On the plus side, my code compiled with minor editing in VS2012.

On the minus side, installing .NET 4.5 on any machine will break my installed application.

On the slightly plus side, uninstalling .NET 4.5 and reinstalling 4.0 fixes things.

Adbot
ADBOT LOVES YOU

fankey
Aug 31, 2001


I was seeing if I could use a <app>.exe.config to make my app use a specific version of .NET. In HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP I see the entries I expect - v2.0.50727, v3.0, v3.5, v4 and v4.0 ( how is this different than v4? ). The odd thing is that I don't see a 4.5 entry - the Version of the v4 has been updated to 4.5 instead of adding a new 4.5 entry. It was also installed in the v4.0.30319 directory and not a 4.5 directory. As far as I can tell 4.5 overwrites 4.0. Anyone have an idea as to why this would be the case? This seems like it could cause other issues due to changes in the Framework unrelated to the mess I'm in.

Ithaqua
Jul 18, 2003

Only in Kenya.

fankey posted:

As far as I can tell 4.5 overwrites 4.0.

Yup. It's something weird Microsoft did for some unfathomable reason. It's still 4.0.

ljw1004
Jan 18, 2005

rum


fankey posted:

So I've made 2 bad choices that I'm trying to figure out how to extract myself from. First, I used the Async CTP w/ VS2010. Then I decided to install VS2012 to see what porting to the new async stuff will look like. Not only did that break my ability to compile my code in VS2010 but it also broke my ability to run already compiled versions that use the Async CTP.

I hadn't expected it to be that rough. (I was one of the team who did the async ctp). I had expected that:

(0) Your code that you built with the asyncCTP (targeting mscore40 and AsyncCTPLibrary.dll) should still run even on a machine that replaces mscore40 with mscore45. That's because your compiled binary will be explicitly referencing types like AsyncCTPLibrary.dll::IAsyncStateMachine, rather than mscorlib::IAsyncStateMachine.

(1) You should continue to be able to use VS2010+AsyncCTP since VS2012 can exist happily SxS with VS2010 and shouldn't touch it.

(2) You would be able to load your projects into VS2012 but still targetting .NET4. You'd have to add the AsyncTargettingPack to make this work. (The AsyncTargettingPack is a replacement for the "AsyncCTPLibrary.dlll" that shipped with the CTP). This would require some changes to the async APIs that you invoke, but not too many.

(3) You should be able to uptarget your projects to target .NET45. This would again require some changes to the APIs you invoke, but not many.


I'd be happy to spend more time figuring out your situation to see what could be done, either on this thread or by email to me at lwischik@microsoft.com

I'm sorry it's so difficult! Installer stuff was a nightmare. We the async-ctp team were a small group, and working with the installer (and VS2010's update cycle) took months of our time that we didn't want to spend, and ultimately there was no good way to ship an "OutOfBand" product like AsyncCTP have have it keep working reliably despite mainline updates to VS2010. And there were SxS scenarios we just didn't imagine.

epalm
Nov 4, 2003



I want to share some code with y'all, so I can be told how terrible I am at C# and hopefully improve a bit.

Here's a (thread-safe?) ActionQueue. You can queue up actions from multiple threads and run them. I use it to write messages to a log file, broadcast messages to a list of clients, etc.

https://bitbucket.org/epalm/csharp/.../ActionQueue.cs

Usage:

code:
static void Main(string[] args)
{
    ActionQueue queue = new ActionQueue();
    queue.Start();

    Task.Factory.StartNew(() => // thread A
    {
        queue.Enqueue(() => Console.WriteLine("a0"));
        queue.Enqueue(() => Console.WriteLine("a1"));
        queue.Enqueue(() => Console.WriteLine("a2"));
        queue.Enqueue(() => Console.WriteLine("a3"));
        queue.Enqueue(() => Console.WriteLine("a4"));

        queue.Run();
    });

    Task.Factory.StartNew(() => // thread B
    {
        queue.Enqueue(() => Console.WriteLine("b0"));
        queue.Enqueue(() => Console.WriteLine("b1"));
        queue.Enqueue(() => Console.WriteLine("b2"));
        queue.Enqueue(() => Console.WriteLine("b3"));
        queue.Enqueue(() => Console.WriteLine("b4"));

        queue.Run();
    });

    Console.ReadLine();
    queue.Stop();
}
Output:

code:
a0
b0
b1
a1
a2
a3
a4
b2
b3
b4
Question(s):

In EnqueueAndRun and Run, Does newEvent.Set(); need to be in the lock?

Ithaqua
Jul 18, 2003

Only in Kenya.

epalm posted:

I want to share some code with y'all, so I can be told how terrible I am at C# and hopefully improve a bit.

Here's a (thread-safe?) ActionQueue. You can queue up actions from multiple threads and run them. I use it to write messages to a log file, broadcast messages to a list of clients, etc.


Wouldn't this do basically the same thing?

code:
            var actionQueue = new ConcurrentQueue<Action>();
            
            actionQueue.Enqueue(()=>
            { 
                Console.WriteLine("start foo");
                Thread.Sleep(5000);
                Console.WriteLine("end foo");
            });
            actionQueue.Enqueue(() => 
            { 
                Console.WriteLine("start bar");
                Thread.Sleep(1000);
                Console.WriteLine("end bar");
            });

            
            var actionTimer = new Timer(x=>
                {
                    Action dequeuedAction;
                    if (actionQueue.TryDequeue(out dequeuedAction))
                    {
                        dequeuedAction();
                    }
                });
            actionTimer.Change(0, 100);
I didn't analyze your code in too much depth, but it seems like it should serve essentially the same purpose.

Even if my code is missing the point and sucks, use a ConcurrentQueue.

fankey
Aug 31, 2001


ljw1004 posted:

I hadn't expected it to be that rough. (I was one of the team who did the async ctp). I had expected that:
That's the sort of issues I was expecting when I used the CTP. I'll contact you via email - I appreciate any help I can get with this.

dalin
Nov 6, 2005



ljw1004 posted:

First step: install Jared Parson's PInvoke Assistant!
http://clrinterop.codeplex.com/releases/view/14120

Sweet!

Gilg
Oct 10, 2002



I've been looking at some posts on the repository pattern when used with Entity Framework and encountered something I haven't been able to figure out. Some examples, e.g. http://www.tugberkugurlu.com/archiv...esting-triangle, include an Update or Edit function and some do not. Why is that?

I gather that the ones with an Update function let you work better "detached", but I guess I don't fully understand what that means or when you would work attached or detached. Is it that working attached means you always query the repository for entities and therefore the entities are always tracked and you would just SaveChanges() to make updates anyway? And Update just means starting to track a detached but already existing entity?

PhonyMcRingRing
Jun 6, 2002


fankey posted:

I was seeing if I could use a <app>.exe.config to make my app use a specific version of .NET. In HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP I see the entries I expect - v2.0.50727, v3.0, v3.5, v4 and v4.0 ( how is this different than v4? ). The odd thing is that I don't see a 4.5 entry - the Version of the v4 has been updated to 4.5 instead of adding a new 4.5 entry. It was also installed in the v4.0.30319 directory and not a 4.5 directory. As far as I can tell 4.5 overwrites 4.0. Anyone have an idea as to why this would be the case? This seems like it could cause other issues due to changes in the Framework unrelated to the mess I'm in.

For some dumb rear end reason, and ignoring every single criticism, Microsoft decided to make .NET 4.5 an "in place" installation. Meaning, 4.5 overwrites 4.0 and then doesn't leave you with any way at all of knowing whether or not you're running in 4.0 or 4.5. While they claim they made sure to run all sorts of tests to ensure no one's programs get hosed up by this, I'm sure that lots of things will start cropping up soon enough. DO NOT install 4.5 unless you're ready to start testing that all your things compiled for 4.0 are still functional.

Tres Burritos
Sep 3, 2009


Ithaqua posted:

use a ConcurrentQueue.

The concurrent classes are so loving badass. I drat near poo poo myself when I found them. They are way, way, way faster (and sometimes cleaner looking) than locking around queues/dictionaries/whatever.

Zhentar
Sep 28, 2003

Brilliant Master Genius


One word of caution with the Concurrent classes - ConcurrentDictionary and ConcurrentBag both incur an object allocation. If you're adding & removing at a high enough rate, they can actually hurt your Concurrency through heavy garbage collection.


Edit: regarding the in-place 4.5 upgrade, I'd bet money they did it to shave one or two hundred megabytes off the Windows 8 install footprint, to help cram it in to 16/32GB flash devices.

Hot Yellow KoolAid
Aug 17, 2012


I've hit a snag in a project I'm working on. I am using the following method to get a directory name from a user and then load all the filenames of picture files (bmp, etc) into an array. I use this to cast the filenames into Images, and it's working fine so far:
code:
        private void button2_Click(object sender, EventArgs e)
        {
            Stream myStream = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            openFileDialog1.FilterIndex = 2;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            //end start
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }       
        }
The aim is to put the Images into a circualr linked list that will play on a slideshow. I haven't run into any problems so far with this method.

What I'm stuck on now is figuring out a method to do the same opperation on a user-specified web address i.e. collecting the Images inside it into a circular linked list. Is there an object like OpenFileDialog for webpages, or should I do this another way? Thanks

Ithaqua
Jul 18, 2003

Only in Kenya.

Hot Yellow KoolAid posted:

The aim is to put the Images into a circualr linked list that will play on a slideshow. I haven't run into any problems so far with this method.

What I'm stuck on now is figuring out a method to do the same opperation on a user-specified web address i.e. collecting the Images inside it into a circular linked list. Is there an object like OpenFileDialog for webpages, or should I do this another way? Thanks

Here's what you're going to want to do:
1) Use a WebClient to download the page.
2) Parse the HTML with something like the HTML Agility Pack
3) Get all the images from the page.
4) Download the images to a temporary location (this is a perfect opportunity to use .NET 4.5's async/await!)
5) Use a normal dialog to select the images to display.

Also, in the code sample you provided, you should be declaring myStream in the scope you're going to use it! I hate it when I see a null object created at the top of the method and it's not actually instantiated until halfway through the method.

I decided to do it for some practice async/awaiting. Here it is!

C# code:
private async void button1_Click(object sender, EventArgs e)
{
    await GetPage("http://www.macrumors.com");
}

public async Task GetPage(string pageUri)
{
    byte[] result;
    using (var wc = new WebClient())
    {
        result = await wc.DownloadDataTaskAsync(pageUri);
    }
    var html = Encoding.UTF8.GetString(result);

    var doc = new HtmlAgilityPack.HtmlDocument();
    doc.LoadHtml(html);

    var images = doc.DocumentNode.Descendants("img").Select(e => e.GetAttributeValue("src", null))
	.Where(s => !string.IsNullOrWhiteSpace(s) && (s.EndsWith("gif") || 	s.EndsWith("png") || s.EndsWith("jpg")))
	.Distinct();
    await DownloadImages(images, pageUri);

}

public async Task DownloadImages(IEnumerable<string> images, string pageUri)
{
    foreach (var image in images)
    {
        string urlToGrab;
        if (!image.StartsWith("http"))
        {
            urlToGrab = pageUri + image;
        }
        else
        {
            urlToGrab = image;
        }

        var dotIndex = image.LastIndexOf('.') + 1;
        var extension = image.Substring(dotIndex, image.Length - dotIndex);

        using (var wc = new WebClient())
        {
            await wc.DownloadFileTaskAsync(urlToGrab, string.Format(@"C:\temp\{0}.{1}", Guid.NewGuid(), extension));
        }
    }
}

Ithaqua fucked around with this message at Aug 17, 2012 around 14:52

Factor Mystic
Mar 19, 2006

Baby's First Post-Apocalyptic Fiction

Zhentar posted:

Edit: regarding the in-place 4.5 upgrade, I'd bet money they did it to shave one or two hundred megabytes off the Windows 8 install footprint, to help cram it in to 16/32GB flash devices.

That doesn't really make sense as a justification. I actually have not heard a clear justification for why it was an in place upgrade, if anyone can find a link to a team member blog (or, any team member would like to respond here) I'd love to hear it.

Frozen-Solid
Aug 25, 2004

Behind you, Cobb! Stay alert!


I have a really crappy COM object I'm trying to code against. I've added the COM as a reference, but when I try to use it I keep getting this error:

Unable to cast COM object of type '<blah>' to interface type '<blah>'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{E1496B92-4BD6-11D2-95B9-0000C0BE33E7}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

The only way I've gotten it to work is using Type.GetTypeFromProgID() which returns a System.__ComObject type, and then I can use Activator.CreatInstance() and InvokeMember. It's a huge pain in the butt, but I can't figure out how to actually make the objects usable in C# the way they should be.

ljw1004
Jan 18, 2005

rum


Frozen-Solid posted:

I have a really crappy COM object I'm trying to code against. I've added the COM as a reference, but when I try to use it I keep getting this error:

Unable to cast COM object of type '<blah>' to interface type '<blah>'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{E1496B92-4BD6-11D2-95B9-0000C0BE33E7}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

The only way I've gotten it to work is using Type.GetTypeFromProgID() which returns a System.__ComObject type, and then I can use Activator.CreatInstance() and InvokeMember. It's a huge pain in the butt, but I can't figure out how to actually make the objects usable in C# the way they should be.

You've most likely got the wrong IID number there!

InvokeMember never uses the IID. It instead goes via IDispatch or IDispatchEx. The fact that InvokeMember works, reinforces my suspicion that you've got the wrong IID number.

It's impossible to answer your question without seeing more code. I'd STRONGLY recommend coding up a C++ example that works (using QueryInterface). Then show us the C++ code, the C++ header file that describes the COM object, your C# class+interface definitions for the COM object, and the C# code you're using to work with it.

Sedro
Dec 31, 2008


Or just cast it to dynamic and call it a day.

Frozen-Solid
Aug 25, 2004

Behind you, Cobb! Stay alert!


ljw1004 posted:

You've most likely got the wrong IID number there!

I'm never calling the IID anywhere. I'm just using straight objects from the referenced COM.

LabelVision.Application app = new LabelVision.Application(); //Works!
LabelVision.Label label = app.OpenLabel(Application.StartupPath + Path.DirectorySeparatorChar + "Label.lbx"); //Fails!

Full error:

Unable to cast COM object of type 'LabelVision.ApplicationClass' to interface type 'LabelVision.IApplication'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{E1496B92-4BD6-11D2-95B9-0000C0BE33E7}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

Code that works:

Type lvAppType = Type.GetTypeFromProgID("LabelVision.Application");
object lvApp = Activator.CreateInstance(lvAppType);
object lvLabel = lvAppType.InvokeMember("OpenLabel", BindingFlags.InvokeMethod, null, lvApp, new object[] {Application.StartupPath + Path.DirectorySeparatorChar + "Label.lbx"});

GetTypeFromProgID returns a System.__ComObject. I can't figure out how to cast that into anything useful besides just using generic objects. The code that works is okay, because I can just wrap it in a C# class object, but i don't think I should really have to do that. Of course the company that made the COM is useless, and just wants money for "Custom Application Design" support. All their documentation is for VB and looks like it should "Just Work" using VB's GetObject and CreateObject functions, but I'd rather not resort to VB if I don't have to.

Frozen-Solid fucked around with this message at Aug 17, 2012 around 17:02

Essential
Aug 14, 2003


Are there any unique identifiable file properties? For instance, c:\mydocument.doc vs. c:\documents\mydocument.doc. Would there be an attribute or something that I could use to distinguish between the 2?

I know I can look at file date, file size etc. but rightfully assuming those attributes can change and/or be the same I need something else.

We have assembly version, file version and assembly guid for assemblies so I'm looking for something similiar on files.

wither
Jun 23, 2004

I have a turn both for observation and for deduction.

Essential posted:

Are there any unique identifiable file properties? For instance, c:\mydocument.doc vs. c:\documents\mydocument.doc. Would there be an attribute or something that I could use to distinguish between the 2?

I know I can look at file date, file size etc. but rightfully assuming those attributes can change and/or be the same I need something else.

We have assembly version, file version and assembly guid for assemblies so I'm looking for something similiar on files.

If you're looking for bit-for-bit comparison between the two documents, System.Security.Cryptography has an SHA1 class.

uXs
May 3, 2005

Mark it zero!

Ithaqua posted:

Well, what happened was the async CTP installed a bunch of new stuff that targeted .NET 4.0. When you installed VS2012, it installed a new version of the framework, where all of that cool stuff is targeting .NET 4.5.

I know you already know this, but it bears repeating for future generations: Never use CTPs in production code, it will end up loving you.

Meh, I did and I'm not regretting it. It even has a license that you're allowed to use it in production code, so.

The only problem was when I tried the VS2012 preview, because that was really incompatible with the async CTP.

I guess I'll have the same problem when I install the real 2012 in a few months, but at that point I'll just throw 2010 in the bin and upgrade everything.

fankey
Aug 31, 2001


uXs posted:

Meh, I did and I'm not regretting it. It even has a license that you're allowed to use it in production code, so.

The only problem was when I tried the VS2012 preview, because that was really incompatible with the async CTP.

I guess I'll have the same problem when I install the real 2012 in a few months, but at that point I'll just throw 2010 in the bin and upgrade everything.
I don't know if it's particular to my app but I'm also not able to run my app that uses the Async CTP on Windows 8.

I have determined that I can use VS2012 with the Async Targeting Pack to compile my app targeting 4.0 and it will run with either 4.0 or 4.5 installed.

Sab669
Sep 24, 2009


So this is baffling me. I'm playing around with this little portable bar code scanner and the SDK it came with only supports C++ and VB

I found some open source third-party library in C# that interfaces with the device and I was able to rip apart the code and get some real bare-bone functionality that we need.

My problem is that their code, which I don't understand at all, gets the barcodes with the date and time it was scanned from the device and returns that.

If I just use their method to get the information, it's good. But we don't want the time and date attached to it.

so I have

code:
private void button1_Click(object sender, EventArgs e)
{
string barcodes = "";
GKGBarcode.Barcode bc = new GKGBarcode.Barcode();
            
barcodes = bc.getBarcodes();
//barcodes = stripDates(barcodes);

Clipboard.SetDataObject(barcodes);
}



private string stripDates(string barcodeSet)
{
int comma = barcodeSet.LastIndexOf(",");
int newLine = barcodeSet.LastIndexOf(Environment.NewLine);
int difference = newLine - comma;

if (comma > -1 && newLine > -1)

     barcodeSet = barcodeSet.Remove(comma, difference - 1);

if (barcodeSet.LastIndexOf(",") > -1)
{
  do
  {
    comma = barcodeSet.LastIndexOf(",");
    newLine = barcodeSet.LastIndexOf(Environment.NewLine);
    difference = newLine - comma;

    barcodeSet = barcodeSet.Remove(comma, difference - 1);

   } while (barcodeSet.LastIndexOf(",") > -1);
}
return barcodeSet;
}
That works fine. If I uncomment my stripDates call, the clipboard has the text "The operation has timed out". Where the gently caress does that come from?

Ithaqua
Jul 18, 2003

Only in Kenya.

Sab669 posted:

So this is baffling me. I'm playing around with this little portable bar code scanner and the SDK it came with only supports C++ and VB

I found some open source third-party library in C# that interfaces with the device and I was able to rip apart the code and get some real bare-bone functionality that we need.

My problem is that their code, which I don't understand at all, gets the barcodes with the date and time it was scanned from the device and returns that.

If I just use their method to get the information, it's good. But we don't want the time and date attached to it.


That works fine. If I uncomment my stripDates call, the clipboard has the text "The operation has timed out". Where the gently caress does that come from?

What format is the data in? That algorithm looks atrocious and there's probably a better way to strip the dates. I'm not saying your algorithm is the problem, but I can almost guarantee you there's a more elegant solution to the problem.

Super anal style nitpicking:
C# method names should be UpperCamelCase.

Sab669
Sep 24, 2009


I know it's pretty ugly
I had something recursive before but it kept causing stack overflows when there were a large number of barcodes stored on the device.

A sample of the output without any modification from me:

quote:

609465149776, 8/17/2012 3:22:58 PM
884726694077, 8/17/2012 3:23:04 PM
72-96027-0008, 8/17/2012 3:23:17 PM
MX, 8/17/2012 3:23:33 PM

I just scanned a bunch of things on my desk, so now that you mention it maybe the end product would have more... expected style of information. I'll have to go check with my boss next time he's in the office.

Che Delilas
Nov 23, 2009

Prolonged exposure can cause tooth rot, diabetes and involuntary manic grins.

Ithaqua posted:

Super anal style nitpicking:
C# method names should be UpperCamelCase.

Ooh ooh can we have the "my style guide is the only style guide" discussion again?

Ithaqua
Jul 18, 2003

Only in Kenya.

Che Delilas posted:

Ooh ooh can we have the "my style guide is the only style guide" discussion again?

Nope. My style guide is Microsoft's, so that's a pretty good starting point.

Ithaqua
Jul 18, 2003

Only in Kenya.

Sab669 posted:

I know it's pretty ugly
I had something recursive before but it kept causing stack overflows when there were a large number of barcodes stored on the device.

A sample of the output without any modification from me:


I just scanned a bunch of things on my desk, so now that you mention it maybe the end product would have more... expected style of information. I'll have to go check with my boss next time he's in the office.

Try this:
C# code:
            string barcodeSource = @"609465149776, 8/17/2012 3:22:58 PM
884726694077, 8/17/2012 3:23:04 PM
72-96027-0008, 8/17/2012 3:23:17 PM
MX, 8/17/2012 3:23:33 PM";

            var barcodeLines = barcodeSource.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
            
            var barcodesOnly = string.Join(Environment.NewLine, barcodeLines.Select(s => s.Split(',')[0]));

Che Delilas
Nov 23, 2009

Prolonged exposure can cause tooth rot, diabetes and involuntary manic grins.

Ithaqua posted:

Nope. My style guide is Microsoft's, so that's a pretty good starting point.

Right, which is the style guide Microsoft uses for MSDN examples (and I assume internally?), which has nothing to do with anybody else's code base. Its guidelines do not supercede being consistent with your own code base. His method names are internally consistent (all 2 of them that we see, heh), so it's perfectly valid.

For the record, I happen to use Microsoft's guidelines in my own work. Mostly because they're all written out and easily referenced, and there's nothing really wrong with them.

ljw1004
Jan 18, 2005

rum


Essential posted:

Are there any unique identifiable file properties? For instance, c:\mydocument.doc vs. c:\documents\mydocument.doc. Would there be an attribute or something that I could use to distinguish between the 2?

http://blogs.msdn.com/b/vbteam/arch...an-wischik.aspx

but read the comments for caveats

wwb
Aug 17, 2004


Che Delilas posted:

Right, which is the style guide Microsoft uses for MSDN examples (and I assume internally?), which has nothing to do with anybody else's code base. Its guidelines do not supercede being consistent with your own code base. His method names are internally consistent (all 2 of them that we see, heh), so it's perfectly valid.

For the record, I happen to use Microsoft's guidelines in my own work. Mostly because they're all written out and easily referenced, and there's nothing really wrong with them.

Exactly -- internal consistency is the only thing that matters at the end of the day.

Personally I prefer the lowerCamelCase for all private members -- easier to tell what things are at a glance without ruining the semantics. Does anyone know why the UpperCamelCase fatwa came down?

Che Delilas
Nov 23, 2009

Prolonged exposure can cause tooth rot, diabetes and involuntary manic grins.

wwb posted:

Exactly -- internal consistency is the only thing that matters at the end of the day.

Personally I prefer the lowerCamelCase for all private members -- easier to tell what things are at a glance without ruining the semantics. Does anyone know why the UpperCamelCase fatwa came down?

My guess is that because that's how the .Net Framework names its own stuff. Which is in fact a good argument for doing it Microsoft's way, since non-trivial programs generally make extensive use of the Framework libraries. Code autocomplete tools like Intellisense are also so good now that a lot of the older naming conventions (some of which shall remain nameless) are unnecessary. And good riddance.

The only names that are in camel case that I know of in Microsoft's style guide are fields, function params and locally scoped variables. That's enough, in my opinion, since if I'm calling a class's function from within another function of the same class, I don't really care if the function I'm calling is public or private.

Safe and Secure!
Jun 14, 2008
"Those who are more likely to do evil are conveniently cursed with an evil appearance. It even helps the rest of us good people avoid them, so that we can stay safe."


What should I know if I'm going to be applying for junior C#/.NET developer jobs? I want to work toward getting up to that level, but I don't really know what that level is. I've done a couple of small projects in C#, but nothing that really took advantage of more than basic language features, and I didn't really use any of the framework besides some simple WPF and a couple collections classes.

I'm guessing that being very familiar with everything in System.Collections is a must, but what else?

I ask because I'm currently an intern doing test automation, but one of the people leading the team have said they're thinking of moving me to development if it looks like we don't really need much to maintain our UI test suite, while another said that they only intended for the intern to work in testing for a couple months to get familiar with the product before moving to development.

I want to be productive ASAP if that happens, but all I really know is that they use C# and WCF for the back-end of their product.

Ithaqua
Jul 18, 2003

Only in Kenya.

Safe and Secure! posted:

What should I know if I'm going to be applying for junior C#/.NET developer jobs? I want to work toward getting up to that level, but I don't really know what that level is. I've done a couple of small projects in C#, but nothing that really took advantage of more than basic language features, and I didn't really use any of the framework besides some simple WPF and a couple collections classes.

I'm guessing that being very familiar with everything in System.Collections is a must, but what else?

I ask because I'm currently an intern doing test automation, but one of the people leading the team have said they're thinking of moving me to development if it looks like we don't really need much to maintain our UI test suite, while another said that they only intended for the intern to work in testing for a couple months to get familiar with the product before moving to development.

I want to be productive ASAP if that happens, but all I really know is that they use C# and WCF for the back-end of their product.

Make sure you're familiar with this stuff:
- Fundamental understanding of OO principles (abstract classes, interfaces, how and why you'd use them)
- SOLID design principles
- Unit testing / IOC
- LINQ and why it's awesome
- Generics and why they're awesome
- In general, know how to write clean code (small classes, small methods, sanely named classes/methods/variables)

A few jobs ago I was responsible for technical evaluations for interviewees, and I've done a bunch of mock interviews with folks from COC. If you want to set one up, shoot me a PM or give me an email address where I can contact you.

Essential
Aug 14, 2003


wither posted:

If you're looking for bit-for-bit comparison between the two documents, System.Security.Cryptography has an SHA1 class.

Thank you for the suggestions guys. I'll look into them both and see if that accomplishes what I need.

I should have added to the original post that I need to track 1 file as the 'working' file. I don't know if the above solutions will work because of that but both are a step in the right direction at least.

Vintersorg
Mar 3, 2004

Three lives you shall have of me. No more, no less. Three and we are done.


Would the File.Exists class work on something that is online? I am sometimes getting server errors when the XML file im using is getting created. So I want to put a safeguard checking that it's there before rendering.

The address is http://*.*.*.*/status.xml and putting that into the arguments results in it always being false.

Vintersorg fucked around with this message at Aug 20, 2012 around 18:47

Ithaqua
Jul 18, 2003

Only in Kenya.

Vintersorg posted:

Would the File.Exists class work on something that is online? I am sometimes getting server errors when the XML file im using is getting created. So I want to put a safeguard checking that it's there before rendering.

The address is [url]http://*.*.*.*/status.xml[/url] and putting that into the arguments results in it always being false.

No, all of the File methods are for the local filesystem.

You can do something like this to see if it exists on a web server:

C# code:
        public static bool RemoteFileExists(string url)
        {
            var request = WebRequest.Create(new Uri(url));
            request.Method = "HEAD";
            try
            {
                WebResponse response = request.GetResponse();
                return true;
            }
            catch (WebException ex)
            {
                if (ex.Message.Contains("404"))
                {
                    return false;
                }
                throw;
            }
        }
What that does is opens up a web connection to the URL you provide and tries to get the header. It throws an exception if it's not found, so you catch the exception and check if it's a 404. If it's a 404, it doesn't exist. If it's any other kind of error, it rethrows the exception.

Ithaqua fucked around with this message at Aug 20, 2012 around 18:57

Vintersorg
Mar 3, 2004

Three lives you shall have of me. No more, no less. Three and we are done.


I'll add that top stuff re: 404's, that will be more precise. After I posted the above I just threw everything into a try/catch and get the user to try again momentarily as a refresh will usually work right away.

Adbot
ADBOT LOVES YOU

wwb
Aug 17, 2004


Ithaqua posted:

No, all of the File methods are for the local filesystem.

You can do something like this to see if it exists on a web server:

C# code:
        public static bool RemoteFileExists(string url)
        {
            var request = WebRequest.Create(new Uri(url));
            request.Method = "HEAD";
            try
            {
                WebResponse response = request.GetResponse();
                return true;
            }
            catch (WebException ex)
            {
                if (ex.Message.Contains("404"))
                {
                    return false;
                }
                throw;
            }
        }
What that does is opens up a web connection to the URL you provide and tries to get the header. It throws an exception if it's not found, so you catch the exception and check if it's a 404. If it's a 404, it doesn't exist. If it's any other kind of error, it rethrows the exception.

Shouldn't you be looking into the WebException's Status rather than digging into the error message. Loads cleaner . . .

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply
«368 »