{"id":372,"date":"2022-10-27T18:46:26","date_gmt":"2022-10-27T15:46:26","guid":{"rendered":"https:\/\/ru.robotnet.org\/blog\/?post_type=docs&#038;p=372"},"modified":"2023-01-06T19:18:56","modified_gmt":"2023-01-06T16:18:56","slug":"csharp-sample-stream","status":"publish","type":"docs","link":"https:\/\/ru.robotnet.org\/blog\/doc\/c-sharp\/csharp-sample-stream\/","title":{"rendered":"9.3.4. \u041f\u0440\u0438\u043c\u0435\u0440 Stream"},"content":{"rendered":"\n<p><strong>sdk\\c-sharp\\stream\\stream\\Program.cs<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code console-output has-small-font-size\"><code>using System;\r\nusing System.Collections.Generic;\r\nusing System.IO;\r\nusing System.Security.Cryptography;\r\nusing System.Linq;\r\nusing System.Reflection;\r\n\r\n#if (DEBUG)\r\nusing RobotNET.Factory.Debug;\r\n#else\r\nusing RobotNET.Factory.Release;\r\n#endif\r\n\r\nnamespace Stream\r\n{\r\n    class Program\r\n    {\r\n        static void Main( string&#91;] args )\r\n        {\r\n            Console.WriteLine( string.Format( \"Program started!\" ) );\r\n\r\n            try\r\n            {\r\n                string path = AppDomain.CurrentDomain.BaseDirectory;\r\n#if (DEBUG)\r\n                using( Factory factory = new Factory( args&#91;0], args&#91;1], \"sdk\\\\c-sharp\\\\stream\\\\stream-plugin\\\\bin\\\\debug\\\\stream-plugin.dll\", \"Stream.Plugin\" ) )\r\n#else\r\n                using( Factory factory = new Factory( args&#91;0], args&#91;1], \"sdk\\\\c-sharp\\\\stream\\\\stream-plugin\\\\bin\\\\release\\\\stream-plugin.dll\", \"Stream.Plugin\" ) )\r\n#endif\r\n                    try\r\n                    {\r\n                        int blockSize = 32767;\r\n                        byte&#91;] buffer = new byte&#91;blockSize];\r\n                        int read;\r\n\r\n                        FileStream orig = new FileStream( path + \"\\\\\" + args&#91;2], FileMode.Open );\r\n                        long max = orig.Length;\r\n                        int len = 0;\r\n                        while( ( read = orig.Read( buffer, 0, blockSize ) ) > 0 )\r\n                        {\r\n                            factory.WriteBytes( new byte&#91;] { 1 } );\r\n                            byte&#91;] block = new byte&#91;read];\r\n                            Buffer.BlockCopy( buffer, 0, block, 0, read );\r\n                            factory.WriteBytes( block );\r\n\r\n                            len += read;\r\n                            Console.WriteLine( \"&lt;-- {0} \/ {1}\", len, max );\r\n                        }\r\n                        factory.WriteBytes( new byte&#91;] { 0 } );\r\n                        orig.Close();\r\n                        orig.Dispose();\r\n\r\n                        FileStream test = new FileStream( path + \"\\\\test-\" + args&#91;2], FileMode.Create );\r\n                        byte&#91;] h;\r\n                        while( ( h = factory.ReadBytes() )&#91;0] == 1 )\r\n                        {\r\n                            byte&#91;] block = factory.ReadBytes();\r\n                            test.Write( block, 0, block.Length );\r\n\r\n                            len -= block.Length;\r\n                            Console.WriteLine( \"--> {0} \/ {1}\", len, max );\r\n                        }\r\n                        test.Close();\r\n                        test.Dispose();\r\n\r\n                        if( len > 0 )\r\n                        {\r\n                            Console.WriteLine( \"FAIL\" );\r\n                            Console.ReadKey();\r\n                        }\r\n\r\n                        Console.WriteLine( \"Sleep 3000...\" );\r\n                        System.Threading.Thread.Sleep( 3000 );\r\n\r\n                        byte&#91;] origMD5 = null;\r\n                        byte&#91;] testMD5 = null;\r\n                        byte&#91;] tempMD5 = null;\r\n                        using( var md5 = MD5.Create() )\r\n                        {\r\n                            using( var stream = File.OpenRead( path + \"\\\\\" + args&#91;2] ) )\r\n                            {\r\n                                origMD5 = md5.ComputeHash( stream );\r\n                            }\r\n                            using( var stream = File.OpenRead( path + \"\\\\test-\" + args&#91;2] ) )\r\n                            {\r\n                                testMD5 = md5.ComputeHash( stream );\r\n                            }\r\n#if (DEBUG)\r\n                            using( var stream = File.OpenRead( path + \"\\\\temp.dat\" ) )\r\n                            {\r\n                                tempMD5 = md5.ComputeHash( stream );\r\n                            }\r\n#else\r\n                            tempMD5 = testMD5;    \r\n#endif\r\n                        }\r\n\r\n                        if( origMD5 != null &amp;&amp; testMD5 != null )\r\n                            if( origMD5.SequenceEqual( testMD5 ) &amp;&amp; testMD5.SequenceEqual( tempMD5 ) )\r\n                                Console.WriteLine( \"MATCH\" );\r\n                    }\r\n                    catch( Exception e )\r\n                    {\r\n                        Console.WriteLine( string.Format( \"Program catch an error at Main \\\"{0}\\\"\", e ) );\r\n                    }\r\n            }\r\n            catch( Exception e )\r\n            {\r\n                Console.WriteLine( e );\r\n            }\r\n\r\n            Console.WriteLine( string.Format( \"Program finished!\" ) );\r\n        }\r\n    }\r\n}\r\n<\/code><\/pre>\n\n\n\n<p><strong>sdk\\c-sharp\\stream\\stream-plugin\\Plugin.cs<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code console-output has-small-font-size\"><code>using System;\r\nusing System.Collections.Generic;\r\nusing System.Diagnostics;\r\nusing System.IO;\r\nusing System.Reflection;\r\n\r\nusing RobotNET.Factory;\r\n\r\nnamespace Stream\r\n{\r\n    public class Plugin : MarshalByRefObject, IPlugin\r\n    {\r\n        public void Worker( object _pipe )\r\n        {\r\n            \/\/ \u041f\u043e\u0442\u043e\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c\u0441\u044f, \u0435\u0441\u043b\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u043e\u0441\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u0430 \u0438\u043b\u0438 \u0431\u044b\u043b \u0440\u0430\u0437\u0440\u0443\u0448\u0435\u043d \u043f\u0430\u0439\u043f\r\n            IPipe pipe = ( IPipe )_pipe;\r\n\r\n            Console.WriteLine( string.Format( \"Plugin started!\" ) );\r\n\r\n            string path = AppDomain.CurrentDomain.BaseDirectory;\r\n\r\n            int blockSize = 8192;\r\n            byte&#91;] buffer = new byte&#91;blockSize];\r\n            int read;\r\n\r\n            FileStream test = new FileStream( path + \"\\\\temp.dat\", FileMode.Create );\r\n            int len = 0;\r\n            while( ( pipe.ReadBytes() )&#91;0] == 1 )\r\n            {\r\n                byte&#91;] block = pipe.ReadBytes();\r\n                test.Write( block, 0, block.Length );\r\n\r\n                len += block.Length;\r\n                Console.WriteLine( \"--> {0} \/ ?\", len );\r\n            }\r\n            test.Close();\r\n            test.Dispose();\r\n\r\n            FileStream orig = new FileStream( path + \"\\\\temp.dat\", FileMode.Open );\r\n            long max = orig.Length;\r\n            while( ( read = orig.Read( buffer, 0, blockSize ) ) > 0 )\r\n            {\r\n                pipe.WriteBytes( new byte&#91;] { 1 } );\r\n                byte&#91;] block = new byte&#91;read];\r\n                Buffer.BlockCopy( buffer, 0, block, 0, read );\r\n                pipe.WriteBytes( block );\r\n\r\n                len -= read;\r\n                Console.WriteLine( \"&lt;-- {0} \/ {1}\", len, max );\r\n            }\r\n            pipe.WriteBytes( new byte&#91;] { 0 } );\r\n            orig.Close();\r\n            orig.Dispose();\r\n\r\n            Console.WriteLine( string.Format( \"Plugin finished!\" ) );\r\n        }\r\n    }\r\n}\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>sdk\\c-sharp\\stream\\stream\\Program.cs sdk\\c-sharp\\stream\\stream-plugin\\Plugin.cs<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"doc_category":[33],"doc_tag":[],"class_list":["post-372","docs","type-docs","status-publish","hentry","doc_category-c-sharp"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>9.3.4. \u041f\u0440\u0438\u043c\u0435\u0440 Stream - \u0411\u043b\u043e\u0433, \u043d\u043e\u0432\u043e\u0441\u0442\u0438 \u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f RobotNET<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ru.robotnet.org\/blog\/doc\/c-sharp\/csharp-sample-stream\/\" \/>\n<meta property=\"og:locale\" content=\"ru_RU\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"9.3.4. \u041f\u0440\u0438\u043c\u0435\u0440 Stream - \u0411\u043b\u043e\u0433, \u043d\u043e\u0432\u043e\u0441\u0442\u0438 \u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f RobotNET\" \/>\n<meta property=\"og:description\" content=\"sdkc-sharpstreamstreamProgram.cs sdkc-sharpstreamstream-pluginPlugin.cs\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ru.robotnet.org\/blog\/doc\/c-sharp\/csharp-sample-stream\/\" \/>\n<meta property=\"og:site_name\" content=\"\u0411\u043b\u043e\u0433, \u043d\u043e\u0432\u043e\u0441\u0442\u0438 \u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f RobotNET\" \/>\n<meta property=\"article:modified_time\" content=\"2023-01-06T16:18:56+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u041f\u0440\u0438\u043c\u0435\u0440\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 \u043c\u0438\u043d\u0443\u0442\u044b\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ru.robotnet.org\/blog\/doc\/c-sharp\/csharp-sample-stream\/\",\"url\":\"https:\/\/ru.robotnet.org\/blog\/doc\/c-sharp\/csharp-sample-stream\/\",\"name\":\"9.3.4. \u041f\u0440\u0438\u043c\u0435\u0440 Stream - \u0411\u043b\u043e\u0433, \u043d\u043e\u0432\u043e\u0441\u0442\u0438 \u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f RobotNET\",\"isPartOf\":{\"@id\":\"https:\/\/ru.robotnet.org\/blog\/#website\"},\"datePublished\":\"2022-10-27T15:46:26+00:00\",\"dateModified\":\"2023-01-06T16:18:56+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/ru.robotnet.org\/blog\/doc\/c-sharp\/csharp-sample-stream\/#breadcrumb\"},\"inLanguage\":\"ru-RU\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/ru.robotnet.org\/blog\/doc\/c-sharp\/csharp-sample-stream\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/ru.robotnet.org\/blog\/doc\/c-sharp\/csharp-sample-stream\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u0413\u043b\u0430\u0432\u043d\u0430\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430\",\"item\":\"https:\/\/ru.robotnet.org\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"9.3.4. \u041f\u0440\u0438\u043c\u0435\u0440 Stream\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/ru.robotnet.org\/blog\/#website\",\"url\":\"https:\/\/ru.robotnet.org\/blog\/\",\"name\":\"\u041f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0438 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f RobotNET\",\"description\":\"\u041e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0440\u0435\u0441\u0443\u0440\u0441 \u041f\u0438\u0440\u0438\u043d\u0433\u043e\u0432\u043e\u0439 \u041f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b \u041c\u0438\u043a\u0440\u043e-\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 RobotNET\",\"alternateName\":\"\u0411\u043b\u043e\u0433, \u043d\u043e\u0432\u043e\u0441\u0442\u0438 \u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f RobotNET\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/ru.robotnet.org\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ru-RU\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"9.3.4. \u041f\u0440\u0438\u043c\u0435\u0440 Stream - \u0411\u043b\u043e\u0433, \u043d\u043e\u0432\u043e\u0441\u0442\u0438 \u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f RobotNET","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ru.robotnet.org\/blog\/doc\/c-sharp\/csharp-sample-stream\/","og_locale":"ru_RU","og_type":"article","og_title":"9.3.4. \u041f\u0440\u0438\u043c\u0435\u0440 Stream - \u0411\u043b\u043e\u0433, \u043d\u043e\u0432\u043e\u0441\u0442\u0438 \u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f RobotNET","og_description":"sdkc-sharpstreamstreamProgram.cs sdkc-sharpstreamstream-pluginPlugin.cs","og_url":"https:\/\/ru.robotnet.org\/blog\/doc\/c-sharp\/csharp-sample-stream\/","og_site_name":"\u0411\u043b\u043e\u0433, \u043d\u043e\u0432\u043e\u0441\u0442\u0438 \u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f RobotNET","article_modified_time":"2023-01-06T16:18:56+00:00","twitter_card":"summary_large_image","twitter_misc":{"\u041f\u0440\u0438\u043c\u0435\u0440\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f":"2 \u043c\u0438\u043d\u0443\u0442\u044b"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/ru.robotnet.org\/blog\/doc\/c-sharp\/csharp-sample-stream\/","url":"https:\/\/ru.robotnet.org\/blog\/doc\/c-sharp\/csharp-sample-stream\/","name":"9.3.4. \u041f\u0440\u0438\u043c\u0435\u0440 Stream - \u0411\u043b\u043e\u0433, \u043d\u043e\u0432\u043e\u0441\u0442\u0438 \u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f RobotNET","isPartOf":{"@id":"https:\/\/ru.robotnet.org\/blog\/#website"},"datePublished":"2022-10-27T15:46:26+00:00","dateModified":"2023-01-06T16:18:56+00:00","breadcrumb":{"@id":"https:\/\/ru.robotnet.org\/blog\/doc\/c-sharp\/csharp-sample-stream\/#breadcrumb"},"inLanguage":"ru-RU","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ru.robotnet.org\/blog\/doc\/c-sharp\/csharp-sample-stream\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/ru.robotnet.org\/blog\/doc\/c-sharp\/csharp-sample-stream\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u0413\u043b\u0430\u0432\u043d\u0430\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430","item":"https:\/\/ru.robotnet.org\/blog\/"},{"@type":"ListItem","position":2,"name":"9.3.4. \u041f\u0440\u0438\u043c\u0435\u0440 Stream"}]},{"@type":"WebSite","@id":"https:\/\/ru.robotnet.org\/blog\/#website","url":"https:\/\/ru.robotnet.org\/blog\/","name":"\u041f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0438 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f RobotNET","description":"\u041e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0440\u0435\u0441\u0443\u0440\u0441 \u041f\u0438\u0440\u0438\u043d\u0433\u043e\u0432\u043e\u0439 \u041f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b \u041c\u0438\u043a\u0440\u043e-\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 RobotNET","alternateName":"\u0411\u043b\u043e\u0433, \u043d\u043e\u0432\u043e\u0441\u0442\u0438 \u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f RobotNET","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ru.robotnet.org\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ru-RU"}]}},"_links":{"self":[{"href":"https:\/\/ru.robotnet.org\/blog\/wp-json\/wp\/v2\/docs\/372","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ru.robotnet.org\/blog\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/ru.robotnet.org\/blog\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/ru.robotnet.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ru.robotnet.org\/blog\/wp-json\/wp\/v2\/comments?post=372"}],"version-history":[{"count":0,"href":"https:\/\/ru.robotnet.org\/blog\/wp-json\/wp\/v2\/docs\/372\/revisions"}],"wp:attachment":[{"href":"https:\/\/ru.robotnet.org\/blog\/wp-json\/wp\/v2\/media?parent=372"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/ru.robotnet.org\/blog\/wp-json\/wp\/v2\/doc_category?post=372"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/ru.robotnet.org\/blog\/wp-json\/wp\/v2\/doc_tag?post=372"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}