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
Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost

Essential posted:

If you were to build your first phone app, as a fun hobby project, what would you do? Go native? Xamarin?

"Native" and "Xamarin" are redundant; Xamarin is native. You're calling the same APIs that would get called if you wrote the code in Swift or Java; instead, it's from .NET.

The first question would be "Which platforms do you want to support?" Are you doing iOS? Android? If you're doing anything Mac related, I would say go download Visual Studio for Mac and use that instead of using VS on Windows. While you can use VS, you still need a Mac set up and connected to your PC so you can build and deploy the app, and at that point, you should do your dev work on the Mac, IMO. If you're working with Android, I've seen more people use it VS on Windows, and generally, that's the more preferred IDE.

If you've done any Windows development before with XAML (WPF, UWP), you should check out Xamarin.Forms, which is cross-platform UI toolkit. It makes it quite easy to build UIs that run everywhere, and it's by far the most popular way to build an app using Xamarin. Most of the tutorials and helper libraries you'll see on the web are for Xamarin.Forms.

Of course, you can build iOS and Android apps using the standard UI kits those platforms use, and use class libraries or shared projects to share code between them all.

And personally, I'm becoming a big fan of Elmish.XamarinForms, which is an awesome way to leverage F# and Xamarin.Forms. I wouldn't build a production app with it yet, as it's going through a bunch of changes while it's being worked on, but it's cool to check out if you're into F# and functional programming.

Adbot
ADBOT LOVES YOU

Essential
Aug 14, 2003

Drastic Actions posted:

"Native" and "Xamarin" are redundant; Xamarin is native. You're calling the same APIs that would get called if you wrote the code in Swift or Java; instead, it's from .NET.

The first question would be "Which platforms do you want to support?" Are you doing iOS? Android? If you're doing anything Mac related, I would say go download Visual Studio for Mac and use that instead of using VS on Windows. While you can use VS, you still need a Mac set up and connected to your PC so you can build and deploy the app, and at that point, you should do your dev work on the Mac, IMO. If you're working with Android, I've seen more people use it VS on Windows, and generally, that's the more preferred IDE.

If you've done any Windows development before with XAML (WPF, UWP), you should check out Xamarin.Forms, which is cross-platform UI toolkit. It makes it quite easy to build UIs that run everywhere, and it's by far the most popular way to build an app using Xamarin. Most of the tutorials and helper libraries you'll see on the web are for Xamarin.Forms.

Of course, you can build iOS and Android apps using the standard UI kits those platforms use, and use class libraries or shared projects to share code between them all.

And personally, I'm becoming a big fan of Elmish.XamarinForms, which is an awesome way to leverage F# and Xamarin.Forms. I wouldn't build a production app with it yet, as it's going through a bunch of changes while it's being worked on, but it's cool to check out if you're into F# and functional programming.

Thanks for the information this is great! I'm doing some light reading on Xamarin and I think I see what you mean with Xamarin being native. I was under the impression it was something else, with limited capabilities (such as no gps) that could only be done in the native codebase.

Since I have an Android phone my thought was to start there and I'm already setup on VS for windows. I have used xaml before with Silverlight of all things. I appreciate you pointing out xamarin.Forms as well.

Essential fucked around with this message at 19:15 on Jul 7, 2018

Hughlander
May 11, 2005

Honestly. Unity no matter what you were doing.

Captain Capacitor
Jan 21, 2008

The code you say?
I have officially :yotj:'d onto the Cosmos DB team. Should be a nice change of pace from my old team.

chippy
Aug 16, 2006

OK I DON'T GET IT

Munkeymon posted:

How is Min(0) not working for you for 'greater than 0'?

Because they're not the same thing. Min(0) is 'greater than or equal to 0'. If your number is an int, then you can just use Min(1), but if you want a decimal (float, etc.) that has to be greater than 0, there's no way to do this out of the box.

LOOK I AM A TURTLE posted:

workaround suggestion

Thanks man. I'm quite comfortable writing my own annotation (or just using Fluent Validation), I was just surprised that this isn't one of the built-in ones.

chippy fucked around with this message at 10:00 on Jul 9, 2018

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

chippy posted:

Because they're not the same thing. Min(0) is 'greater than or equal to 0'. If your number is an int, then you can just use Min(1), but if you want a decimal (float, etc.) that has to be greater than 0, there's no way to do this out of the box.


Thanks man. I'm quite comfortable writing my own annotation (or just using Fluent Validation), I was just surprised that this isn't one of the built-in ones.

If there’s min on floating point types, you could just write out the smallest representable number greater than zero..

Munkeymon
Aug 14, 2003

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



chippy posted:

Because they're not the same thing. Min(0) is 'greater than or equal to 0'. If your number is an int, then you can just use Min(1), but if you want a decimal (float, etc.) that has to be greater than 0, there's no way to do this out of the box.

Yeah, my bad. I do some of my worst thinking in the morning, so I inflict it on you guys rather than my codebase :angel:

downout
Jul 6, 2009

If min(0) equates to greater than or equal to 0, then wont min(0) and != 0 equate to greater than 0?

chippy
Aug 16, 2006

OK I DON'T GET IT

downout posted:

If min(0) equates to greater than or equal to 0, then wont min(0) and != 0 equate to greater than 0?

Is there an existing annotation for != ?

fankey
Aug 31, 2001

We have some c# code that discovers our devices on the network. To do so it needs to probe some TCP ports - different firmware versions on the devices have different ports open. We accomplish this using the following code
code:
  [System.Diagnostics.DebuggerHidden]
    public static async Task TimeoutAfter( this Task actualTask, TimeSpan timeout )
    {
      using( var timeoutCancellationTokenSource = new CancellationTokenSource() )
      {
        var timeoutTask = Task.Delay( timeout, timeoutCancellationTokenSource.Token );
        var completedTask = await Task.WhenAny( actualTask, timeoutTask );
        if( completedTask == actualTask )
        {
          timeoutCancellationTokenSource.Cancel();
          await actualTask; // Very important in order to propagate exceptions
          return;
        }
        else
        {
          throw new TimeoutException( "The operation has timed out." );
        }
      }
    }

    [System.Diagnostics.DebuggerHidden]
    private async static Task<string> IsPortOpenInternal( string host, int port, TimeSpan timeout )
    {
      try
      {
        using( var client = new System.Net.Sockets.TcpClient() )
        {
          try
          {
            var task = client.ConnectAsync( host, port );
            await task.TimeoutAfter( timeout );
            return host;
          }
          catch( TimeoutException )
          {
            return null;
          }
          catch( System.Net.Sockets.SocketException )
          {
            return null;
          }
          catch( Exception )
          {
            return null;
          }
        }
      }
      catch
      {
        return null;
      }
    }
It all functions fine - the issue is that if we run our application in the debugger and have a large number of devices that will fail the port check ( which happens when the app starts ) the application is unusable for a couple of minutes as VS prints out exceptions. As you can see I've tried sprinkling the code with DebuggerHidden attributes but those don't seem to apply down in the async world. Here's an example stack from when the exception is thrown
code:
System.dll!System.Net.Sockets.Socket.DoMultipleAddressConnectCallback(object result, System.Net.Sockets.Socket.MultipleAddressConnectAsyncResult context) Line 7096	C#
System.dll!System.Net.Sockets.Socket.MultipleAddressConnectCallback(System.IAsyncResult result) Line 7053	C#
System.dll!System.Net.LazyAsyncResult.Complete(System.IntPtr userToken) Line 415	C#
System.dll!System.Net.ContextAwareResult.Complete(System.IntPtr userToken) Line 465	C#
System.dll!System.Net.LazyAsyncResult.ProtectedInvokeCallback(object result, System.IntPtr userToken) Line 368	C#
System.dll!System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(uint errorCode, uint numBytes, System.Threading.NativeOverlapped* nativeOverlapped) Line 399	C#
mscorlib.dll!System.Threading._IOCompletionCallback.PerformIOCompletionCallback(uint errorCode, uint numBytes, System.Threading.NativeOverlapped* pOVERLAP) Line 135	C#
[Native to Managed Transition]	
kernel32.dll!BaseThreadInitThunk()	Unknown
ntdll.dll!RtlUserThreadStart()	Unknown
Any idea how to disable the exception printouts in these areas? Turning on 'Enable Just My Code' in the debugger settings does fix the issue but then I don't end up seeing other exceptions that I am interested in. This is using VS 2015 if that matters.

downout
Jul 6, 2009

chippy posted:

Is there an existing annotation for != ?

I couldnt figure out what i was missing. Annotation doh. Thanks

raminasi
Jan 25, 2005

a last drink with no ice

fankey posted:

We have some c# code that discovers our devices on the network. To do so it needs to probe some TCP ports - different firmware versions on the devices have different ports open. We accomplish this using the following code
code:
  [System.Diagnostics.DebuggerHidden]
    public static async Task TimeoutAfter( this Task actualTask, TimeSpan timeout )
    {
      using( var timeoutCancellationTokenSource = new CancellationTokenSource() )
      {
        var timeoutTask = Task.Delay( timeout, timeoutCancellationTokenSource.Token );
        var completedTask = await Task.WhenAny( actualTask, timeoutTask );
        if( completedTask == actualTask )
        {
          timeoutCancellationTokenSource.Cancel();
          await actualTask; // Very important in order to propagate exceptions
          return;
        }
        else
        {
          throw new TimeoutException( "The operation has timed out." );
        }
      }
    }

    [System.Diagnostics.DebuggerHidden]
    private async static Task<string> IsPortOpenInternal( string host, int port, TimeSpan timeout )
    {
      try
      {
        using( var client = new System.Net.Sockets.TcpClient() )
        {
          try
          {
            var task = client.ConnectAsync( host, port );
            await task.TimeoutAfter( timeout );
            return host;
          }
          catch( TimeoutException )
          {
            return null;
          }
          catch( System.Net.Sockets.SocketException )
          {
            return null;
          }
          catch( Exception )
          {
            return null;
          }
        }
      }
      catch
      {
        return null;
      }
    }
It all functions fine - the issue is that if we run our application in the debugger and have a large number of devices that will fail the port check ( which happens when the app starts ) the application is unusable for a couple of minutes as VS prints out exceptions. As you can see I've tried sprinkling the code with DebuggerHidden attributes but those don't seem to apply down in the async world. Here's an example stack from when the exception is thrown
code:
System.dll!System.Net.Sockets.Socket.DoMultipleAddressConnectCallback(object result, System.Net.Sockets.Socket.MultipleAddressConnectAsyncResult context) Line 7096	C#
System.dll!System.Net.Sockets.Socket.MultipleAddressConnectCallback(System.IAsyncResult result) Line 7053	C#
System.dll!System.Net.LazyAsyncResult.Complete(System.IntPtr userToken) Line 415	C#
System.dll!System.Net.ContextAwareResult.Complete(System.IntPtr userToken) Line 465	C#
System.dll!System.Net.LazyAsyncResult.ProtectedInvokeCallback(object result, System.IntPtr userToken) Line 368	C#
System.dll!System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(uint errorCode, uint numBytes, System.Threading.NativeOverlapped* nativeOverlapped) Line 399	C#
mscorlib.dll!System.Threading._IOCompletionCallback.PerformIOCompletionCallback(uint errorCode, uint numBytes, System.Threading.NativeOverlapped* pOVERLAP) Line 135	C#
[Native to Managed Transition]	
kernel32.dll!BaseThreadInitThunk()	Unknown
ntdll.dll!RtlUserThreadStart()	Unknown
Any idea how to disable the exception printouts in these areas? Turning on 'Enable Just My Code' in the debugger settings does fix the issue but then I don't end up seeing other exceptions that I am interested in. This is using VS 2015 if that matters.

Does VS2015 not let you filter out specific exception types? I thought it did like 2017 but I might be misremembering.

(Also what sadist came up with that parentheses style?)

fankey
Aug 31, 2001

raminasi posted:

Does VS2015 not let you filter out specific exception types? I thought it did like 2017 but I might be misremembering.
You can filter out what exceptions to break on but AFAIK there isn't a way to filter out what exceptions are printed out which seems to be what's bogging down VS. Looks like you can also just turn off exception printing which would be too heavy of a hammer as well.

quote:

(Also what sadist came up with that parentheses style?)
Not me! That's what Ctrl+E, D is for...

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)
This depends on hpw many devices you're talking about, but you could not time out each connection task, and instead time out "IsPortOpen" as a whole. Run the tasks, wait some time, and then poll each socket to see if it is connected.

If you have quite a bit of things to scan, you can "do it yourself" by sending syn packets with SharpPcap and using a packet filter for syn/acks from the interesting hosts and ports. Or you can call an external tool like masscan to do it also.

Mongolian Queef
May 6, 2004

fankey posted:

You can filter out what exceptions to break on but AFAIK there isn't a way to filter out what exceptions are printed out which seems to be what's bogging down VS. Looks like you can also just turn off exception printing which would be too heavy of a hammer as well.

Not me! That's what Ctrl+E, D is for...

When the project is started inside VS, can you see if it makes any difference if you right click the Output window and deselect "Exception messages" (or similar)?
Also, you could check if you have "Enable native code debugging" checked (and in that case try unchecking it) under Debug in the project properties.

EssOEss
Oct 23, 2006
128-bit approved
VS will not print out exceptions if they are caught. Therefore, you have uncaught exceptions happening - when there is a timeout, what awaits actualTask? Nothing! So the actualTask exceptions never get caught. I do not have VS installed on this computer, so cannot verify what a solution might be, but I suggest making sure that you have no dangling tasks - you need to continue with actualTask and handle the exception even if you timeout. My first instinct would be to construct something using .ContinueWith().

Mongolian Queef
May 6, 2004

EssOEss posted:

VS will not print out exceptions if they are caught.

My VS2013 does this and it's toggled by the "Exception messages" in the output window. Maybe non ancient VS makes more sense :)

Edit: I missed the complete stack trace. So you're right, VS2013 will not print the entire exception with a stack trace like that, it will just be a one-liner per exception.

fankey
Aug 31, 2001

Thanks for all the ideas. Anything that removes the exception printouts from the Output window solves the problem - turning off Exception Messages, Enable Just My Code, etc. The issue is I still want other exceptions to show up - even including other SocketExeceptions. it's just these particular operations I want to mask.

EssOEss posted:

VS will not print out exceptions if they are caught. Therefore, you have uncaught exceptions happening - when there is a timeout, what awaits actualTask? Nothing! So the actualTask exceptions never get caught. I do not have VS installed on this computer, so cannot verify what a solution might be, but I suggest making sure that you have no dangling tasks - you need to continue with actualTask and handle the exception even if you timeout. My first instinct would be to construct something using .ContinueWith().
Here's a very simple example which just tried to connect without bypassing the built in 20 sec connection timer
code:
Console.WriteLine("testing...");
System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
sw.Start();
using (var client = new System.Net.Sockets.TcpClient())
{
  try
  {
    var task = client.ConnectAsync("1.1.1.1", 1111);
    await Task.WhenAll(task);
    Console.WriteLine("got it!");
  }
  catch (Exception ex)
  {
    System.Console.WriteLine(ex.Message);
  }
}
Console.WriteLine("testing took {0}ms", sw.ElapsedMilliseconds);
As far I a know I am fully awaiting the task and should be catching all exceptions but I still get multiple internal exceptions printed out
code:
testing...
Exception thrown: 'System.Net.Sockets.SocketException' in System.dll
Exception thrown: 'System.Net.Sockets.SocketException' in System.dll
Exception thrown: 'System.Net.Sockets.SocketException' in System.dll
Exception thrown: 'System.Net.Sockets.SocketException' in mscorlib.dll
The thread 0x3b34 has exited with code 0 (0x0).
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 1.1.1.1:1111
testing took 21276ms

Mongolian Queef
May 6, 2004


Here's what VS2013 outputs when I run the above:

quote:

testing...
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in mscorlib.dll
No connection could be made because the target machine actively refused it 127.0.0.1:23123
testing took 1064ms

How come your VS doesn't say that it's a first chance exception? I find that odd. Do you want to ignore first chance exceptions? I'm guessing yes in this case, and you can do that by right clicking the Output window and uncheck exception messages.
If you get an unhandled exception (unlike the above), you will still definitely know.

EssOEss
Oct 23, 2006
128-bit approved

fankey posted:

As far I a know I am fully awaiting the task and should be catching all exceptions but I still get multiple internal exceptions printed out

Oh, I thought you were getting stack traces in there but upon re-reading I realize that was just additional information on the exceptions. My mistake!

fankey
Aug 31, 2001

Mongolian Queef posted:

How come your VS doesn't say that it's a first chance exception? I find that odd. Do you want to ignore first chance exceptions? I'm guessing yes in this case, and you can do that by right clicking the Output window and uncheck exception messages.
If you get an unhandled exception (unlike the above), you will still definitely know.
No idea, I'm running 2015 so there might be some difference in how it reports exceptions. Once difference might be that in my example I was attempting to contact an unreachable IP so the connection timed out and in your case the IP was reachable but the connection was refused.

Looks like I was incorrect in my previous assessment. Just disabling exception printing in the Debug output doesn't fix my issue. Only enabling 'Just My Code' does.

raminasi
Jan 25, 2005

a last drink with no ice
Is there a good way to dip my toes into learning to read IL? I managed to write some F# that causes an InvalidProgramException and the issue I opened is attracting curious people posting IL and I’d like to not feel like it’s written in a foreign language.

Night Shade
Jan 13, 2013

Old School

raminasi posted:

Is there a good way to dip my toes into learning to read IL? I managed to write some F# that causes an InvalidProgramException and the issue I opened is attracting curious people posting IL and I’d like to not feel like it’s written in a foreign language.

assuming i found the issue you posted, it looks like it's managing to push 8x 32-bit values onto the stack and then reading one of them back as a 16-bit value when its passed to the DU constructor. that's not going to work very well

i have some vague familiarity with assembly from my uni days but i had to google all the IL opcodes

Munkeymon
Aug 14, 2003

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



I'm gonna sound like a broken record, but LINQPad can do that:



Some of the names are straightforward and you can look up the ones that aren't

Careful Drums
Oct 30, 2007

by FactsAreUseless
Hey y'all

I'm building an picture/asset management system with a web api backend, angular frontend, and storing all the assets as blobs in azure. I'm working on a feature where you can select a bunch of assets in the UI and download them as a zip file.

I'd like to send a request to the web api and:

- grab the blobs from blob storage
- zip them up in the web server
- provide the zipped up file to the angular app/directly to the browser/whatever.

I'm trying to figure out the most solid approach but having a hard time. I'm running .NET 4.6.1 and as I understand the System.IO.Compression namespace was greatly improved in .NET 4.5. I could be missing something but it looks like what comes for free with .NET is exclusively for working with the filesystem, which is not what I want to do - all this poo poo runs in Azure so I don't want to be reliant on any filesystem. I've come across suggestions on stack overflow of using 3rd party libraries, but most of them seem very out of date or no longer maintained (such as this one, DotNetZip, hosted on the deprecated CodePlex platform: https://archive.codeplex.com/?p=dotnetzip)

Can I build this with native .NET 4.6.1? Is there an actively maintained library (in the form of an easily installable NuGet package) for creating zip files without a file system dependency?

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost

Careful Drums posted:

I could be missing something but it looks like what comes for free with .NET is exclusively for working with the filesystem, which is not what I want to do - all this poo poo runs in Azure so I don't want to be reliant on any filesystem.

System.IO.Compression doesn't require a file system, you can use MemoryStream's to hold the created archive. Then, you could download each blob (In memory as a stream) and add it to the archive and then stream that out in the response.

For example, creating the zip, you could:

code:
	    using (var memoryStream = new MemoryStream())
            using (ZipArchive archive = new ZipArchive(memoryStream, ZipArchiveMode.Create))
            {
                ZipArchiveEntry readmeEntry = archive.CreateEntry("test.txt");
                using (StreamWriter writer = new StreamWriter(readmeEntry.Open()))
                {
                    writer.WriteLine("Test");
                }
            }

Xik
Mar 10, 2011

Dinosaur Gum

Careful Drums posted:

I'd like to send a request to the web api and:

- grab the blobs from blob storage
- zip them up in the web server
- provide the zipped up file to the angular app/directly to the browser/whatever.

We just implemented something very similar in one of our apis, we used SharpZipLib, and Nuget. It was pretty trivial to use, just open up a zip output stream and add new entries into it, it even comes with some nice utilities to copy streams over without having to handle them yourself.

Mr Shiny Pants
Nov 12, 2012

Careful Drums posted:

Hey y'all

I'm building an picture/asset management system with a web api backend, angular frontend, and storing all the assets as blobs in azure. I'm working on a feature where you can select a bunch of assets in the UI and download them as a zip file.

I'd like to send a request to the web api and:

- grab the blobs from blob storage
- zip them up in the web server
- provide the zipped up file to the angular app/directly to the browser/whatever.

I'm trying to figure out the most solid approach but having a hard time. I'm running .NET 4.6.1 and as I understand the System.IO.Compression namespace was greatly improved in .NET 4.5. I could be missing something but it looks like what comes for free with .NET is exclusively for working with the filesystem, which is not what I want to do - all this poo poo runs in Azure so I don't want to be reliant on any filesystem. I've come across suggestions on stack overflow of using 3rd party libraries, but most of them seem very out of date or no longer maintained (such as this one, DotNetZip, hosted on the deprecated CodePlex platform: https://archive.codeplex.com/?p=dotnetzip)

Can I build this with native .NET 4.6.1? Is there an actively maintained library (in the form of an easily installable NuGet package) for creating zip files without a file system dependency?

You'd have a filesystem on the webserver though? Which you can use as temp staging or something.

Careful Drums
Oct 30, 2007

by FactsAreUseless

Mr Shiny Pants posted:

You'd have a filesystem on the webserver though? Which you can use as temp staging or something.

You're right that there technically is a file system, you can ftp into it and everything, but I don't want to rely on it if i can avoid it.

Thanks for the responses, I'm going to experiment today and I'll post what approach I end up using later.

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost

Careful Drums posted:

You're right that there technically is a file system, you can ftp into it and everything, but I don't want to rely on it if i can avoid it.

I think it's more that, unless you can't write to the web server at all, you can write a zip to a temporary path (System.IO.Path.GetTempPath()), add files to it, serve that file and delete it when done. Even with Azure App Services, you can write to GetTempPath.

EssOEss
Oct 23, 2006
128-bit approved
What I would prefer to do is to zip the files on the fly to a temporary Azure blob. That is, do not write to filesystem, do not write to a MemoryStream in RAM, just append the data directly to the blob. This avoids using significant server resources besides the CPU and limits the range of things that can go wrong. Once the write is finished, give the user a SAS token enabled link to the blob and get rid of the blob after N hours.

I do not know if this processing model works well with the Zip and Azure Storage APIs, however. I am also unsure if the ZIP file format is friendly to append-only construction.

nielsm
Jun 1, 2009



EssOEss posted:

What I would prefer to do is to zip the files on the fly to a temporary Azure blob. That is, do not write to filesystem, do not write to a MemoryStream in RAM, just append the data directly to the blob. This avoids using significant server resources besides the CPU and limits the range of things that can go wrong. Once the write is finished, give the user a SAS token enabled link to the blob and get rid of the blob after N hours.

I do not know if this processing model works well with the Zip and Azure Storage APIs, however. I am also unsure if the ZIP file format is friendly to append-only construction.

The ZIP format keeps the directory at the end of the archive, and I believe it's legal to have junk between individual files' data streams, meaning you could easily make "multi-session" ZIP files where you add a bunch of files, write a new directory at the end pointing to all old files and new files contained, and then you just have an old directory index floating in the middle somewhere, taking up a bit of extra space. You can even "delete" files that way, just writing a new directory that no longer points to the files to be deleted.
Of course this accumulates garbage over time, so if you update some archives a lot you'd need to do a complete rewrite occasionally.

I don't know if any libraries exist that allow this usage pattern, but the file format itself can support it.

ljw1004
Jan 18, 2005

rum

nielsm posted:

The ZIP format keeps the directory at the end of the archive, and I believe it's legal to have junk between individual files' data streams, meaning you could easily make "multi-session" ZIP files...

I love the zip file format! For instance, what Nokia did was have a JPEG header and content (the JPEG file format allows for junk at the end), then have a .AVI file, then put the ZIP directory right at the end which points to both JPEG and AVI files.

If the file suffix is .JPG then every app in the world will correctly read the JPG part.
If the file suffix is .ZIP then every app in the world will correctly read it as a ZIP containing two files, a JPEG and an AVI.
If you write image-viewing software then you can decide to recognize it as a live photo.
Anyone who wants to copy the file has an easy time of it too - it's just a single file.

When Apple did their live photos, they seem to have done it with two separate files (at least at first) which meant it was harder to store/backup/view via third party utilities.

nielsm
Jun 1, 2009



And this is also why, if you have a service where you let untrusted users upload files of only a limited set of formats, you need to validate those files and ideally rewrite them, especially if other users are able to download the files. If you don't rewrite the file in its purported format, by parsing and re-creating the file structure, users would probably be able to stuff other data inside them e.g. via ZIP files.

Careful Drums
Oct 30, 2007

by FactsAreUseless
oh my god zips are more complicated than i thought

Mr Shiny Pants
Nov 12, 2012

Careful Drums posted:

oh my god zips are more complicated than i thought

Its software, what did you expect? :)

LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer
Let's not forget about the fact that, as a lot of people were recently made aware of, you can have relative paths inside a zip, meaning that a zip file can contain a file at ../../../../usr/bin/fart.

redleader
Aug 18, 2005

Engage according to operational parameters

LOOK I AM A TURTLE posted:

Let's not forget about the fact that, as a lot of people were recently made aware of, you can have relative paths inside a zip, meaning that a zip file can contain a file at ../../../../usr/bin/fart.

Oh for Christ's sake.

Sad Panda
Sep 22, 2004

I'm a Sad Panda.
The school that I'll be teaching at in September uses C# for the 16-18 year olds, so I've decided I need to learn some. I've installed Visual Studio Community for Mac and have been working my way through C# Fundamentals for Absolute Beginners on MVA which has mainly been super easy, but I'm fine with slow. I'd rather get the foundational knowledge.

1. In terms of next steps, what do people recommend? I've seen mention of "The Yellow Book", someone else suggested "The Bulgarian Book" and I've got access to Lynda.com for free through my university. My goal is a solid understanding of the foundations. My coding background is self-taught Python to an upper-beginner level.

2. How much of a hinderance is being on OS X going to be? I've already noticed a couple of mini things (like how in the Switch + Enum video the guy used a snippet on the enum so it filled out all the switch cases for him), but should I just resign myself to doing my coding in a Windows 10 VM?

3. In terms of cross-platform GUI creation, my friends who code in C# talk about WPF, which obviously doesn't work on OS X. What's the best alternative? A Google suggests Xamarin.Forms?

Thanks

Sad Panda fucked around with this message at 16:20 on Jul 19, 2018

Adbot
ADBOT LOVES YOU

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Sad Panda posted:

The school that I'll be teaching at in September uses C# for the 16-18 year olds, so I've decided I need to learn some. I've installed Visual Studio Community for Mac and have been working my way through C# Fundamentals for Absolute Beginners on MVA which has mainly been super easy, but I'm fine with slow. I'd rather get the foundational knowledge.

1. In terms of next steps, what do people recommend? I've seen mention of "The Yellow Book", someone else suggested "The Bulgarian Book" and I've got access to Lynda.com for free through my university. My goal is a solid understanding of the foundations. My coding background is self-taught Python to an upper-beginner level.

2. How much of a hinderance is being on OS X going to be? I've already noticed a couple of mini things (like how in the Switch + Enum video the guy used a snippet on the enum so it filled out all the switch cases for him), but should I just resign myself to doing my coding in a Windows 10 VM?

3. In terms of cross-platform GUI creation, my friends who code in C# talk about WPF, which obviously doesn't work on OS X. What's the best alternative? A Google suggests Xamarin.Forms?

Thanks

1. [edit] I can't read durr

2/3: What you need to keep in mind is that the only thing that's cross-platform from the ground up right now is .NET Core. If you're looking to do desktop GUIs, you're looking at full .NET framework. If you're looking at full .NET framework, you might as well do it on Windows and save yourself a world of pain.

https://stackoverflow.com/questions/779283/is-there-a-cross-platform-gui-framework-for-c-net

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