Hack Forums
[C#] [SOURCE] Omnicoin Value - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] [SOURCE] Omnicoin Value (/showthread.php?tid=4207121)

Pages: Pages 1 2


[SOURCE] Omnicoin Value - DeadLine - May 2, 2014

Information:

This simple program is able to get the latest OMC information from AllCrypt using their API. It uses the Blockchain API to convert BTC to USD since AllCrypt doesn't actually send the BTC value in USD with their API even though they show that value on their website.
You can minimize it to tray and it will automatically refresh the values and show a notification.

Screenshot:

[Image: 988XfRe.png]

[Image: ekgOBop.png]

Download:

https://www.mediafire.com/?d4dquf1d04dvfv0

Source:

https://www.mediafire.com/?d5ngk9u2ds4z9e8

To-Do:
  • Change OMC ammount
  • USD to OMC(/BTC)
  • BTC to OMC(/USD)
  • Refresh warning on low intervals
  • AllCrypt trade history

I'll get around to doing these things sooner or later. I have exams right now so can't tell when.


* - Gt403cyl - May 2, 2014

Very nice, I Like it! Thanks for sharing the source, I can probably learn some things from this!


* - DeadLine - May 3, 2014

(May 2, 2014 10:56 PM)Gt403cyl Wrote:  Very nice, I Like it! Thanks for sharing the source, I can probably learn some things from this!

I'm glad you like it !
I'm always open to suggestions and code improvements so feel free to let me know if there's something you'd like me to add or improve on ^^.


* - 0xDEAD10CC - May 3, 2014

1. Try statement overuse for exception catching, no proper exception handling.
2. Not disposing of IDisposable objects.


* - DeadLine - May 3, 2014

(May 3, 2014 04:59 PM)0xDEAD10CC Wrote:  1. Try statement overuse for exception catching, no proper exception handling.
2. Not disposing of IDisposable objects.

Thank you !
Will fix as soon as possible but which object needs disposing ?


* - nickchan - May 3, 2014

This looks cool, I'm going to download this as soon as you add the USD option (:


* - DeadLine - May 3, 2014

(May 3, 2014 06:55 PM)NickChan Wrote:  This looks cool, I'm going to download this as soon as you add the USD option (:

Should be done by tomorrow, have to study a bit now 😭 .


* - Cryptic™ - May 3, 2014

Keep in mind that AllCrypt's API allows 1 request per 15 seconds and upto 150 requests per day.


* - DeadLine - May 3, 2014

(May 3, 2014 06:59 PM)Cryptic™ Wrote:  Keep in mind that AllCrypt's API allows 1 request per 15 seconds and upto 150 requests per day.

Initial refresh rate is set to once every 15 minutes which means about 96 refreshes per day. Users can set it lower but I'll add a warning message if they do 👍 !


* - 0xDEAD10CC - May 3, 2014

(May 3, 2014 06:39 PM)DeadLine Wrote:  Thank you !
Will fix as soon as possible but which object needs disposing ?

I looked quickly at the source, but I know that there's a WebClient instance in there at the least that needs to be disposed. Exception handling routines documented on MSDN should help you identify how to avoid most of those try statements which are intended to just swallow the exception (bad for application performance).


* - Stay Plural - May 3, 2014

Are you able to create a sort of preev for omc?


* - DeadLine - May 3, 2014

(May 3, 2014 07:22 PM)0xDEAD10CC Wrote:  I looked quickly at the source, but I know that there's a WebClient instance in there at the least that needs to be disposed. Exception handling routines documented on MSDN should help you identify how to avoid most of those try statements which are intended to just swallow the exception (bad for application performance).
Just noticed the missing dispose of the webclient, thanks for pointing it out ;)

When the settings file has been remove from the disk, it would throw an exception when you try to get or set a setting. DownloadString method can throw an exception if there is no connection available. Process.Start("http://example.com") throws an exception if the user doesn't have a default browser.

Is it really worth checking if the settings file is there and hasn't been modified, checking if there is an active internet connection and see if there is a default browser available, etc. in terms of performance ?
Maybe I'm just being lazy :s.



(May 3, 2014 07:23 PM)Stay Plural Wrote:  Are you able to create a sort of preev for omc?

Yes, almost there. The program can already convert OMC to BTC and USD.
Now all I need to do is convert BTC to USD and OMC, USD to BTC and OMC.


* - 0xDEAD10CC - May 3, 2014

(May 3, 2014 07:37 PM)DeadLine Wrote:  When the settings file has been remove from the disk, it would throw an exception when you try to get or set a setting. DownloadString method can throw an exception if there is no connection available. Process.Start("http://example.com") throws an exception if the user doesn't have a default browser.

Is it really worth checking if the settings file is there and hasn't been modified, checking if there is an active internet connection and see if there is a default browser available, etc. in terms of performance ?
Maybe I'm just being lazy :s.

1. File.Exists()
2. There's still a few types of exceptions that can be prevented, in which a WebClient instance can throw, and you can check for a connection too
3. IE is default for a Windows install, but confident statistics by assumption would dictate that probably 90-99% of users will have a default program which handles a url.

It is worth it though, and it is good practice. Read MSDN: http://msdn.microsoft.com/en-us/library/5b2yeyab%28v=vs.110%29.aspx

If .NET programming didn't define good/proper exception handling as prevention, functions like File.Exists(), int.TryParse(), etc... Wouldn't exist.


* - DeadLine - May 3, 2014

(May 3, 2014 07:49 PM)0xDEAD10CC Wrote:  1. File.Exists()
2. There's still a few types of exceptions that can be prevented, in which a WebClient instance can throw, and you can check for a connection too
3. IE is default for a Windows install, but confident statistics by assumption would dictate that probably 90-99% of users will have a default program which handles a url.

It is worth it though, and it is good practice. Read MSDN: http://msdn.microsoft.com/en-us/library/5b2yeyab%28v=vs.110%29.aspx

If .NET programming didn't define good/proper exception handling as prevention, functions like File.Exists(), int.TryParse(), etc... Wouldn't exist.

1. Fair point, will be added.
2. Connection might be up but DNS is down, new issue because you cannot connect to the API unless you enter it's IP address but what if they change their IP.
3. True, but you can't exclude it from the list. You can prevent an application crash by catching this exception even though it's not likely to happen. School has always told me to catch exceptions that are possible.

So many things could go wrong that honestly I don't know what to do anymore and that's why I usually go with the easiest solution.
Perhaps it's because that's what they thought me at school when I started out with Visual Basic.


* - 0xDEAD10CC - May 3, 2014

Fair enough, and yes networking is and can be complex, but for the easiest solution, typically most programmers don't consider a try/catch statement as a valid solution. That's a bandaid lol.