|
I would have done, but you've got a couple of good answers on there now.
|
# ? May 16, 2016 20:20 |
|
|
# ? Jun 8, 2024 07:47 |
|
LOOK I AM A TURTLE posted:Looks like you want something like this: Thank you so much! One more question: suppose I want to call "WeatherConnection.GetWeather(43.0620960f, 141.3543760f);" from something that isn't async, like in a screen's "OnStart()" method or something similar. For example: code:
Mezzanine fucked around with this message at 01:29 on May 17, 2016 |
# ? May 17, 2016 01:23 |
|
Mezzanine posted:Thank you so much! One more question: suppose I want to call "WeatherConnection.GetWeather(43.0620960f, 141.3543760f);" from something that isn't async, like in a screen's "OnStart()" method or something similar. For example: I'm about 99% sure you're using Xamarin.Forms. You can just add async to OnStart and then call that method. Although you probably don't want to, since that, if I recall correctly without looking at the docs, is called when the app starts using their native methods, and if that task hangs or takes too long to load, your program will crash. You might want to invest some time looking to the many MVVM libraries that work with Forms, like Prism.
|
# ? May 17, 2016 01:34 |
|
Actually, I'm not using forms. I can't remember why, but I think it had something to do with trying to stay closer to the native implementation since I have enough experience with Android and iOS. I will definitely look at Prism, though! Just going over the Xamarin Android documentation, it says something about using "ThreadPool.QueueUserWorkItem (o => SlowMethod ());" and "RunOnUiThread (() => DoThingWithTheUI());", so I'm gonna try that.
|
# ? May 17, 2016 01:52 |
|
Okay, this is baffling and if Google is any indication, has happened to literally nobody ever, so who wants a brainteaser? I've got a WPF application that needs to read card swipes, which come in as keystrokes from the reader so it's pretty easy. In the application's constructor, I have this line: code:
code:
However, if you click anything on a page that takes any sort of interaction (buttons and textboxes are the two things I've found so far), the code stops working -- but only for the space bar. Every other keystroke still gets caught just fine, but space bar presses simply do not trigger tcphandler at all. I know they're going through because they trigger OnKeyDown just fine (and show up in the text box, because tcphandler isn't stopping them). There is absolutely zero code anywhere in the project regarding space bars being pressed. Once you click away from the button or textbox, space bars still are not caught. However, loading a new page causes spaces to be properly handled again, until and unless you click a button or textbox, at which point they start failing to be caught again and can only be fixed by loading a new page. CapnAndy fucked around with this message at 01:33 on May 18, 2016 |
# ? May 18, 2016 00:57 |
|
I'm trying to implement an IAuthenticationFilter (the Web Api 2 flavour, NOT the MVC flavour) and I'm struggling with the order the code is executed. I would have expected the Authentication filter to be run before any controller-based stuff, so that I could set the appropriate principal and then load the relevant user data from my DbContext in some kind of base ApiController. This is the flow I'm after: AuthenticationFilter ==> BaseController ==> Controller/Action ----------------------------------------==>----------------------------------------------------==>---------------------------------------------- Test Authorization header and set the ==> Use the principal to find the full User record in ==> Complete action as normal, has access to the principal if all is well. ==> database and assign it to protected property. ==> user record as set in the BaseController I'm not sure where to put the code in a BaseController in order to have it execute AFTER the authentication filter, but BEFORE the routed controller/action. Generally I find when I'm hitting a brick wall like this, it's because I'm trying to go the wrong way about something, so if any of the above sounds wrong let me know. putin is a cunt fucked around with this message at 03:11 on May 18, 2016 |
# ? May 18, 2016 03:09 |
|
Is there an easy way to modify exif data on photos using C#? I don't know if I'm missing something obvious, but I'm completely coming up with a blank. I'm trying to edit the GPS information located in .jpeg files.
|
# ? May 18, 2016 04:30 |
|
Does anyone have a link to a good article about how events propagate from a timer? I have this timercode:
code:
IcedPee fucked around with this message at 05:00 on May 18, 2016 |
# ? May 18, 2016 04:38 |
|
Captain Melo posted:Is there an easy way to modify exif data on photos using C#? I don't know if I'm missing something obvious, but I'm completely coming up with a blank. I'm trying to edit the GPS information located in .jpeg files. https://github.com/mwijnands/JpegMetadata Not sure if this deals with gps metadata, but it might be a starting point?
|
# ? May 18, 2016 07:42 |
|
IcedPee posted:Does anyone have a link to a good article about how events propagate from a timer? I have this timer What happens if you declare _stoptimer volatile?
|
# ? May 18, 2016 08:37 |
|
The Wizard of Poz posted:I'm trying to implement an IAuthenticationFilter (the Web Api 2 flavour, NOT the MVC flavour) and I'm struggling with the order the code is executed. I would have expected the Authentication filter to be run before any controller-based stuff, so that I could set the appropriate principal and then load the relevant user data from my DbContext in some kind of base ApiController. Honestly I'd just do something like: code:
|
# ? May 18, 2016 12:18 |
|
mortarr posted:https://github.com/mwijnands/JpegMetadata That code uses the .NET Framework class "System.Windows.Media.Imaging.JpegBitmapDecoder" to do its work, stored in "System.Windows.Media.Imaging.BitmapMetadata", which is certainly an easy route as requested There seems to be useful advice on how to use it to work with GPS tags here: http://www.codeproject.com/Questions/815338/Inserting-GPS-tags-into-jpeg-EXIF-metadata-using-n Personally, I wrote some C# code which parses the JPEG/EXIF file format manually, and locates where exactly the timestamp and GPS coordinates are stored within the file. I use it to overwrite the timestamp with my own value. (It'd be straightforward to make it also overwrite the GPS coordinates in the same way). However, my approach is no good if you need to add GPS coordinates to an EXIF which doesn't already have them. https://github.com/ljw1004/fix-camera-date/blob/master/FixCrossPlat/Program.cs
|
# ? May 18, 2016 15:33 |
|
IcedPee posted:Does anyone have a link to a good article about how events propagate from a timer? I have this timer code:
CapnAndy fucked around with this message at 17:28 on May 18, 2016 |
# ? May 18, 2016 17:25 |
|
raminasi posted:What happens if you declare _stoptimer volatile? Functionally no different, sadly. CapnAndy posted:I don't have an answer for you, but I have a way to get what you want. First off, you're doing Timer_Elapsed when you've got the definition of a ticking timer. Change it to: Yeah, there's a reason I wasn't doing _timer.Tick - System.Timers.Timer doesn't have a Tick event. I actually create my own tick event and handle it elsewhere for UI stuff. Oddly enough, I have tried calling _timer.Stop() within OnThingEvent, but it doesn't stop the timer when I call it there just like _stopTimer is always reads false in the Timer_Elapsed handler even though I have set it to true in OnThingEvent. I was really hoping that marking _stopTimer as volatile was the solution. I could try using a winforms timer, but this is a xamarin android application and I think there was a reason that would be bad. I don't recall what it is at the moment, so I'll give it a try.
|
# ? May 18, 2016 18:30 |
|
IcedPee posted:Yeah, there's a reason I wasn't doing _timer.Tick - System.Timers.Timer doesn't have a Tick event. I actually create my own tick event and handle it elsewhere for UI stuff. Oddly enough, I have tried calling _timer.Stop() within OnThingEvent, but it doesn't stop the timer when I call it there just like _stopTimer is always reads false in the Timer_Elapsed handler even though I have set it to true in OnThingEvent. I was really hoping that marking _stopTimer as volatile was the solution. If that's still impossible and the problem has to be solved, where do you declare _stopTimer to be false? You've got to be resetting it to false when the timer starts, but you didn't include that bit, or the bit where Timer_Elapsed actually restarts the timer. Without seeing them, I'm going to guess that what's happening is your timer restart method sets _stopTimer to false, and thus even though OnThingEvent sets it true, it gets overriden on the next "tick". Can you just not call _timer.Stop() from OnThingEvent? I'm not sure if stopping counts as being elapsed, but I don't think it would. And if all of that stuff doesn't work, what about just setting _timeLeft to 0 and letting the regular logic stop itself?
|
# ? May 18, 2016 18:38 |
|
CapnAndy posted:Does Xamarin have System.Windows.Threading? Threading timers can tick. Currently, I don't think I do set _stopTimer to false anywhere but when it's declared. My focus has been on getting the ThingEvent to successfully stop the timer before I worry about reset logic. StartTimer is called from a button press in the UI and is not used anywhere else in the application. If setting _stopTimer to true in OnThingEvent handler doesn't change the value that's seen for _stopTimer in Timer_Elapsed, I have serious doubts that changing _timeLeft in the OnThingEvent handler will change the value that's seen for _timeLeft in Timer_Elapsed. I have definitely tried calling _timer.Stop() in OnThingEvent to no avail. This is what leads me to believe this is a threading problem.
|
# ? May 18, 2016 18:53 |
|
IcedPee posted:Currently, I don't think I do set _stopTimer to false anywhere but when it's declared. My focus has been on getting the ThingEvent to successfully stop the timer before I worry about reset logic. StartTimer is called from a button press in the UI and is not used anywhere else in the application.
|
# ? May 18, 2016 19:11 |
|
Not surprisingly, setting _timeLeft to 0 in OnThingEvent does nothing to stop the timer. The timer runs for 10 seconds and then stops, but no amount of outside influence (so far) seems to be able to stop it earlier than that. It definitely seems like the timer runs on a separate thread and that thread gets its own copies of _stopTimer and _timeLeft even though both are declared volatile. System.Timers.Timer has a Disposed event where I can attach a handler, so maybe I can try forcing the issue from OnThingEvent that way. Edit: assuming I can, you know, actually force the timer to dispose reliably. IcedPee fucked around with this message at 19:45 on May 18, 2016 |
# ? May 18, 2016 19:33 |
|
My last idea is to declare them static instead of volatile.
|
# ? May 18, 2016 19:39 |
|
Well, poo poo. From what I read on MSDN and Stack Overflow, the recommended fix is declare it volatile, but declaring it static volatile (not sure volatile is necessary) actually worked. Thanks, dude.
|
# ? May 18, 2016 20:54 |
|
How long does it typically take for a .NET version to go from Preview to Final? I'm running into a bug in 4.6.1 on my main development PC, and wondering whether to uninstall and drop back to 4.6, or install 4.6.2 preview from March 30th. I'm not doing anything remotely bleeding edge - I can go back to Visual Studio 2013 for a month or so if I need to.
|
# ? May 18, 2016 22:45 |
|
Baby Proof posted:How long does it typically take for a .NET version to go from Preview to Final? I'm running into a bug in 4.6.1 on my main development PC, and wondering whether to uninstall and drop back to 4.6, or install 4.6.2 preview from March 30th. I'm not doing anything remotely bleeding edge - I can go back to Visual Studio 2013 for a month or so if I need to. Change the target framework to something else?
|
# ? May 19, 2016 01:15 |
|
IcedPee posted:Well, poo poo. From what I read on MSDN and Stack Overflow, the recommended fix is declare it volatile, but declaring it static volatile (not sure volatile is necessary) actually worked. Thanks, dude. This really sounds like there's a deeper lifetime management problem in code you didn't post. (Or maybe it's just some dumb Xamarin thing, I don't know.)
|
# ? May 19, 2016 06:52 |
|
Baby Proof posted:How long does it typically take for a .NET version to go from Preview to Final? I'm running into a bug in 4.6.1 on my main development PC, and wondering whether to uninstall and drop back to 4.6, or install 4.6.2 preview from March 30th. I'm not doing anything remotely bleeding edge - I can go back to Visual Studio 2013 for a month or so if I need to. The version of visual studio you are using is unrelated to the version of the .NET runtime your code will be compiled against. You can choose to compile your project against any version of the runtime that you like.
|
# ? May 19, 2016 13:01 |
|
john donne posted:The version of visual studio you are using is unrelated to the version of the .NET runtime your code will be compiled against. You can choose to compile your project against any version of the runtime that you like. I wish it was that simple. The 4.6.1 install broke the compile for an old RIA Services / Silverlight (.NET 4.0) project. If I convert it to Open RIA Services or code a workaround, I'll have to track down old versions of 3rd party libraries and modify them too, so my only real options are to uninstall 4.6.1 or jump ahead to 4.6.2.
|
# ? May 19, 2016 14:33 |
|
I just basically copy-pasted the setup from https://github.com/nlog/NLog/wiki/Database-target into my NLog config but, when it tries to load it, it just throws with the error NLog.NLogConfigurationException: Required parameter 'CommandText' on 'Database Target[azure-sql]' was not specified CommandText is definitely there... and also definitely flagged as invalid in VS with the message "This element cannot contain text. Content model is empty.", so I'm not sure what's right at this point. Any NLog users have any idea what the deal is?
|
# ? May 19, 2016 15:25 |
|
I'm trying to troubleshoot a spike of InternalServerErrorExceptions that happened over an hour a few days ago to our API. The frustrating bit is that when you delve into the logs and the stack traces, ultimately all you get is "An unexpected error occurred", which is the most useless error message I can see, for the vast majority of cases. A few towards the end of the spike were caching related: "ERRCA0009" but none of the more senior devs here think that means anything at all. All I know is that they came from the same referrer, they were related to the same thing, and if you look closely it just curves up like a standard bell curve then back down over the course of an hour. Our logs have both the full requestURI and all of the headers in the request; POSTman hitting our production API returns valid results, so I can't recreate it. Stepping through a local version everything works fine, including "nothing found." The DB behind all of this is Mongo, and yes the API correctly handles "not found" from mongo. Do vague reasons for "lol something is wrong" clustered in time like this indicate an error with connections, connection pools, hardware, the db - or is this just "poo poo happens!" I've considered putting in some better error handling code but the response I get is "we could wrap everything in try/catch, what's your point?" and "just "timebox it" ". Not sure what to do except punt. EDIT: A caching server took a poo poo at the same time and everything lines up. Whee. Space Whale fucked around with this message at 20:01 on May 19, 2016 |
# ? May 19, 2016 17:04 |
|
IcedPee posted:Does anyone have a link to a good article about how events propagate from a timer? I have this timer The way to fix it is async/await. That will make your code simpler and, since you're only using the UI thread, all the threading issues will disappear. This is an instance of a general-purpose coding pattern "using async+await is easier than spaghetti events" and I made a short training video for it here. Here's how I'd write your code: code:
EDIT: I'd also dispense with "OnTimerEnded". You could instead just have someone await until StartTimerAsync() has ended.
|
# ? May 19, 2016 17:28 |
|
Low-level fun stuff of the month: The standard's rules for variant interface calls are incomplete, have errors, are insane, and don't match .NET's behavior (which is even more insane). Figure this one out: code:
|
# ? May 20, 2016 21:38 |
|
That is definitely screwy. Intuitively, I would expect it to print B twice, but I wouldn't be surprised if it printed A twice. However printing two different values is throwing me for a loop. I'd be interested to hear ljw1004's take on this.
|
# ? May 20, 2016 22:53 |
|
Reordering the interfaces in S4 or the methods in S1 actually has no effect either. I think the problem is that it has a fun piece of non-standard undocumented behavior: When matching the interface methods for a class, it only matches them if the interface is implementing the method for the first time, either because the class supplied a new implementation since the last time it implemented the interface (if ever). In other words, S4 has an implementation of IVar<A>.P(A), but doesn't have an implementation of IVar<B>.P(B) because that interface method was recycled. Since S4 is searched for matches before S3, it prefers the hit in S4. This also means that 2 methods called from the same variant interface type could be implemented by 2 different interfaces on the class. OneEightHundred fucked around with this message at 02:07 on May 21, 2016 |
# ? May 20, 2016 23:27 |
|
Any of you guys done charts in C#? Got tasked to make a program that takes a CSV file as input and outputs scrollable/zoomable/pretty charts. Started off with 4 points of data every second over a 3 hour period and is now turning into 4 points of data every 1/10th of a second for 8 hours and I'm not real sure the current free library I'm using is going to be able to handle it.
|
# ? May 21, 2016 04:40 |
|
invision posted:Any of you guys done charts in C#? Got tasked to make a program that takes a CSV file as input and outputs scrollable/zoomable/pretty charts. Started off with 4 points of data every second over a 3 hour period and is now turning into 4 points of data every 1/10th of a second for 8 hours and I'm not real sure the current free library I'm using is going to be able to handle it. I haven't seen any charting libraries in the .NET world that don't suck or cost money. It's pretty easy to do charts and the like on the front-end using something like http://nvd3.org/. Worst-case (e.g. static CSV file), you can write it as a self-hosted WebAPI app that just exposes the data as JSON for the front-end to consume. If you can get the data from an API somewhere, even better, you can do the whole thing in HTML/JS without involving C#.
|
# ? May 21, 2016 06:10 |
|
OxyPlot is alright, the docs suck though. They do have an interactive sample browser with loads of samples, but it was down last time I checked.
|
# ? May 21, 2016 08:40 |
|
invision posted:Any of you guys done charts in C#? Got tasked to make a program that takes a CSV file as input and outputs scrollable/zoomable/pretty charts. Started off with 4 points of data every second over a 3 hour period and is now turning into 4 points of data every 1/10th of a second for 8 hours and I'm not real sure the current free library I'm using is going to be able to handle it. XPlot is a F# wrapper around Google Charts and Plotly. You can use it from C# and embed it in WPF, or just output HTML/JS. I would naively hope Google Charts to be able to handle a million data points - a very lazy googling suggests "[m]odern browsers can render up to 100.000 (or even a million) datapoints without problems. However, to keep rendering smooth on older browsers too, it is better to keep the number of datapoints below 10.000." If you have an actual budget, I've used Infragistics in production and I was pretty happy with it, but I was doing network graphs rather than charts. You can get the trial version and see if it handles your data.
|
# ? May 21, 2016 10:39 |
|
OneEightHundred posted:Low-level fun stuff of the month: The standard's rules for variant interface calls are incomplete, have errors, are insane, and don't match .NET's behavior (which is even more insane). Very strange. I can't wrap my head around what it ought to print, but clearly it ought to be the same for both cases. Try to bring this one to Eric Lippert's attention, if he isn't too busy with OCaml these days. As a sidenote, this is why friends don't let friends design languages with both subtyping and parametric polymorphism.
|
# ? May 21, 2016 14:28 |
|
OneEightHundred posted:Low-level fun stuff of the month: The standard's rules for variant interface calls are incomplete, have errors, are insane, and don't match .NET's behavior (which is even more insane). Short story: I suspect this is a known bug relating to generic variance. As you say, the CLR's algorithm for finding a match is it just walks through the interfaces in order until it finds the first match. That's why runtime behavior is sensitive to the exact order that interfaces are declared on a class. Long story: I was a junior dev on the VB compiler team, just given "generic variance" as the first actual feature I'd own myself. It was a gnarly area so I tried to write a mathematical proof of my code's correctness -- but discovered the proof was impossible because of a defect in the ECMA spec. I presented it to the C# Language Design Meeting. We ruled out changing the ECMA spec (too hard) and CLR implementation (too costly). C# compiler decided to ignore the issue for being so minor, but I added some warnings into the VB compiler to alert you if you might run into it. Punch line 1: I got invited to join the VB/C# language design team on the strength of this! Punch line 2: It turned out that my VB warnings never delivered much value to users, but they had a bug in them that warned even on some legitimate real-world code that was fine. Eric Lippert was the one who implemented variance for C#, and he made the correct assessment that the warnings were too risky for too little value. That's the difference between a senior dev like him and a then junior one like me PS. I'm not entirely sure it's the same bug because it takes a long time to walk through the exact behavior, and your example doesn't have a direct VB equivalent. Here's some more code to illustrate the issue: code:
ljw1004 fucked around with this message at 17:43 on May 21, 2016 |
# ? May 21, 2016 16:06 |
|
ljw1004 posted:As you say, the CLR's algorithm for finding a match is it just walks through the interfaces in order until it finds the first match. That's why runtime behavior is sensitive to the exact order that interfaces are declared on a class. I did some more tests and it reinforces that it considers the implementation of a method on an interface to be "no match" if the interface is a duplicate, but doesn't have a new implementation since the last time it was implemented. It's still a "new implementation" if the method is further up the class hierarchy, i.e.: code:
ljw1004 posted:And ultimately, what can it really do? If there are two possible methods that can be invoked, should the CLR throw an "AmbiguousMethodException" at runtime at the moment of invocation? (that'd be a shame if the two methods end up behaving the same as is likely the case...) It's also slow. There's no way to optimize interfaces to something like a static vtable where the variant types just map to those because there's no way to statically determine which interface will service a call to those "no match" slots. OneEightHundred fucked around with this message at 21:14 on May 21, 2016 |
# ? May 21, 2016 19:23 |
|
I'm trying to manipulate XPS files in C# like this but I'm having a really weird problem. The original VS project works fine for me, but I've tried to modify it so I can either run it from powershell or so I can run it as a console application and in both cases on the output from the file I'm testing it on, only the first page of the output file works in the XPS viewer, but I don't get any error messages. Here is my last attempt to make it into a console application while modifying it as little as possible to try to figure out where the problem is (note the hardcoded paths partway down): http://pastebin.com/qmDik1b5 I've tried targeting different .net versions but even with .net 4.5 / x86 like in the demo program I can't get it to work. Am I missing something really obvious here? Also it's really lame that there seems to be no sane way to modify XPS files. You can open them and read them using the not-quite-so-lovely WPF interface, but there isn't any way to copy content from them without messing around with XML (you can't just copy the child elements on each fixedpage because they reference other resources like fonts in the original archive). It seems like you should be able to be able to open XPS files and just change some stuff before saving it again, but it seems like you aren't actually able to do that. It's frustrating because I was able to extract the text from an xps file in a few lines of powershell code, and it seemed like it would be just as easy to make some changes, but boy was I wrong. Edit: Rather than modifying the XPS file, is there any other easy way to manipulate the content and then display it? I tried modifying the fixeddocument in memory and then passing it to a DocumentViewer control but that didn't really work either (it sort of worked sporadically, but I think that's unintended behavior); is there some way I can render a single fixedpage to a window at a time and then be able to modify it? mystes fucked around with this message at 23:43 on May 21, 2016 |
# ? May 21, 2016 23:33 |
|
|
# ? Jun 8, 2024 07:47 |
|
mystes posted:I'm trying to manipulate XPS files in C# All that said, I realized that while the approach of modifying the document as xml is unavoidable, it could be much simpler than the c# example I was looking at if rather than building a new package file, I simply *copied* the original XPS file and modified it in place. This avoids the need to copy the parts from one package to another. Here is a simple example of turning all the text red in powershell: code:
It would be so much easier if it was actually possible to render a fixedpage to a visual and then use the normal api for generating an XPS file again. Edit: It turns out the font name is actually preserved in the obfuscated file (although you have to deobfuscate it, write out to the filesystem as a ttf file, and examine it to get at it). This makes me think that I might be able to switch back to the approach of adding the existing fixedpage to a visual, and then just cleaning it up a little bit. mystes fucked around with this message at 17:09 on May 22, 2016 |
# ? May 22, 2016 15:24 |