{"id":1271,"date":"2014-02-25T09:35:22","date_gmt":"2014-02-25T06:35:22","guid":{"rendered":"http:\/\/www.water-simulation.com\/wsp\/?p=1271"},"modified":"2014-02-25T09:35:22","modified_gmt":"2014-02-25T06:35:22","slug":"epanet-class-for-c-sharp","status":"publish","type":"post","link":"http:\/\/www.water-simulation.com\/wsp\/2014\/02\/25\/epanet-class-for-c-sharp\/","title":{"rendered":"EPANET class for C#"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1275 alignleft\" alt=\"C_Sharp_wordmark.svg\" src=\"http:\/\/www.water-simulation.com\/wsp\/wp-content\/uploads\/2014\/02\/C_Sharp_wordmark.svg_.png\" width=\"94\" height=\"64\" \/>The <a href=\"http:\/\/www.water-simulation.com\/wsp\/2013\/04\/21\/using-epanet-toolkit-in-csharp\/\">previous C# class<\/a> I posted about a year ago had some issues and bugs.\u00a0Vyacheslav Shevelyov, who <a href=\"http:\/\/www.water-simulation.com\/wsp\/2013\/04\/21\/using-epanet-toolkit-in-csharp\/comment-page-1\/#comment-155864\">reported<\/a> a few of these issues, took upon himself to write a new C# class for the EPANET Toolkit. From the class readme file:<\/p>\n<blockquote><p>This archive contains C# source code to interact with unmanaged EPANET 2\u00a0hydraulics library and example files to demonstrate\/test core functionality.\u00a0Sources written for epanet2.dll codeversion 20012. There are no CLI classes,\u00a0that wrap EPANET object, just plain function imports and constants.<\/p>\n<p>Only UnsafeNativeMethods.cs, Enumerations.cs and optionally EpanetException.cs\u00a0should be used to call epanet2.dll from C# code:<\/p>\n<ul>\n<li>UnsafeNativeMethods.cs contains UnsafeNativeMethods class with EPANET function declarations as well as some important constants.<\/li>\n<li><span style=\"font-size: 14px; line-height: 1.5em;\">Enumerations.cs file contains EPANET constant end defines, grouped in\u00a0<\/span><span style=\"font-size: 14px; line-height: 1.5em;\">several enums.<\/span><\/li>\n<li><span style=\"font-size: 14px; line-height: 1.5em;\">EpanetException.cs is mapper of error codes, returned by Epanet to CLI\u00a0<\/span><span style=\"font-size: 14px; line-height: 1.5em;\">exceptions. It is not required to call EPANET functions, but may be\u00a0<\/span><span style=\"font-size: 14px; line-height: 1.5em;\">useful due to all EPANET functions return error codes to indicate errors.<\/span><\/li>\n<\/ul>\n<p>Other files are examples, to demonstrate code functionality and make some<br \/>\ntesting.<\/p><\/blockquote>\n<p>The code is distributed under the <a href=\"http:\/\/unlicense.org\/\">unlicense<\/a> license.<\/p>\n<p>Here are a few code snippets just to show the function calls and Enums:<\/p>\n<p>[code language=&#8221;csharp&#8221; collapse=&#8221;false&#8221;]<br \/>\nUnsafeNativeMethods.ENgetcount(CountType.Node, out nodeCount);<br \/>\nUnsafeNativeMethods.ENgetnodevalue(i, NodeValue.Head, out value);<br \/>\nUnsafeNativeMethods.ENgetlinkvalue(i, LinkValue.Flow, out value);<br \/>\n[\/code]<\/p>\n<p>Download <a href=\"http:\/\/www.water-simulation.com\/wsp\/wp-content\/uploads\/2014\/02\/Epanet-c-sharp.zip\">Epanet-c-sharp<\/a>\u00a0(zip).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The previous C# class I posted about a year ago had some issues and bugs.\u00a0Vyacheslav Shevelyov, who reported a few of these issues, took upon himself to write a new C# class for the EPANET Toolkit. From the class readme &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/www.water-simulation.com\/wsp\/2014\/02\/25\/epanet-class-for-c-sharp\/\"> <span class=\"screen-reader-text\">EPANET class for C#<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,4,7],"tags":[202,158,203],"class_list":["post-1271","post","type-post","status-publish","format-standard","hentry","category-epanet-related","category-free-software","category-programming","tag-c-sharp","tag-c","tag-epanet-toolkit"],"_links":{"self":[{"href":"http:\/\/www.water-simulation.com\/wsp\/wp-json\/wp\/v2\/posts\/1271","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.water-simulation.com\/wsp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.water-simulation.com\/wsp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.water-simulation.com\/wsp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.water-simulation.com\/wsp\/wp-json\/wp\/v2\/comments?post=1271"}],"version-history":[{"count":2,"href":"http:\/\/www.water-simulation.com\/wsp\/wp-json\/wp\/v2\/posts\/1271\/revisions"}],"predecessor-version":[{"id":1286,"href":"http:\/\/www.water-simulation.com\/wsp\/wp-json\/wp\/v2\/posts\/1271\/revisions\/1286"}],"wp:attachment":[{"href":"http:\/\/www.water-simulation.com\/wsp\/wp-json\/wp\/v2\/media?parent=1271"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.water-simulation.com\/wsp\/wp-json\/wp\/v2\/categories?post=1271"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.water-simulation.com\/wsp\/wp-json\/wp\/v2\/tags?post=1271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}