protected StreamAdapter_Accessor GetStreamAccessor(StreamAdapter adapter)
        {
            PrivateObject          po       = new PrivateObject(adapter);
            StreamAdapter_Accessor accessor = new StreamAdapter_Accessor(po);

            return(accessor);
        }
Exemple #2
0
        //public ClientEntity(IRemoteHubAdapter adapter)
        //{
        //    Adapter = adapter;
        //    Stream = null;
        //    TcpClient = null;
        //    EndPoint = "DIRECT";
        //}

        public ClientEntity(TcpClient tcpClient)
        {
            try
            {
                var stream = new SslStream(tcpClient.GetStream(), false,
                                           (sender, certificate, chain, sslPolicyErrors) => true /*always return true in certificate test in this demo*/);
                try
                {
                    EndPoint = tcpClient.Client.RemoteEndPoint.ToString();
                    stream.AuthenticateAsServer(serverCertificate);

                    TcpClient = tcpClient;
                    Stream    = stream;
                    Adapter   = new StreamAdapter <byte[]>(stream, stream);
                }
                catch
                {
                    stream.Close();
                    stream.Dispose();
                    throw;
                }
            }
            catch
            {
                tcpClient.Close();
                tcpClient.Dispose();
                throw;
            }
        }
Exemple #3
0
        private async Task Extract(ZipArchiveEntry entry, string targetDirectory, CancellationToken cancellationToken)
        {
            Logger.Verbose("Extracting file: {File}", entry.FullName);

            var destinationPath = RemoveRelativeSegments(targetDirectory, entry.FullName);

            if (!VerifyPathIsSafe(targetDirectory, destinationPath))
            {
                Logger.Warning("Skipping potentially malicious file: {File}", entry.FullName);

                return;
            }

            using var source = new StreamAdapter(entry.Open());
            var file      = this.FileSystem.GetFile(destinationPath);
            var directory = file.Directory;

            if (directory?.Exists == false)
            {
                directory.Create();
            }

            using var destination = file.OpenWrite();
            await source.CopyToAsync(destination, cancellationToken);
        }
Exemple #4
0
        public void LoadSettingsFromStream(Stream stream)
        {
            if (!Initalized)
            {
                return;
            }

            StreamAdapter streamAdapter = new StreamAdapter(stream);
            HRESULT       hr            = _application.UIRibbon.LoadSettingsFromStream(streamAdapter);
        }
Exemple #5
0
        /// <summary>
        /// The SaveSettingsToStream method is useful for persisting ribbon state, such as Quick Access Toolbar (QAT) items, across application instances.
        /// </summary>
        /// <param name="stream"></param>
        public void SaveSettingsToStream(Stream stream)
        {
            if (!Initialized)
            {
                return;
            }

            StreamAdapter streamAdapter = new StreamAdapter(stream);
            HRESULT       hr            = _application.UIRibbon.SaveSettingsToStream(streamAdapter);
        }
Exemple #6
0
        public void BigEndianBinaryReaderConstructorNullStreamTest()
        {
            StreamAdapter input = null;

            try
            {
                new BigEndianBinaryReader(input);
            }
            catch (ArgumentException)
            {
                return; // test passed - ArgumentException has been thrown
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            Assert.Fail("Exception must be thrown for null stream object");
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View view = inflater.Inflate(Resource.Layout.Rounded, container, false);

            StreamAdapter adapter = new StreamAdapter(Activity);

            view.FindViewById <ListView>(Resource.Id.main_list).Adapter = adapter;

            adapter.Add(new ColorItem(Android.Resource.Color.DarkerGray, "Tufa at night", "Mono Lake, CA", ImageView.ScaleType.Center));
            adapter.Add(new ColorItem(Android.Resource.Color.HoloOrangeDark, "Starry night", "Lake Powell, AZ", ImageView.ScaleType.CenterCrop));
            adapter.Add(new ColorItem(Android.Resource.Color.HoloBlueDark, "Racetrack playa", "Death Valley, CA", ImageView.ScaleType.CenterInside));
            adapter.Add(new ColorItem(Android.Resource.Color.HoloGreenDark, "Napali coast", "Kauai, HI", ImageView.ScaleType.FitCenter));
            adapter.Add(new ColorItem(Android.Resource.Color.HoloRedDark, "Delicate Arch", "Arches, UT", ImageView.ScaleType.FitEnd));
            adapter.Add(new ColorItem(Android.Resource.Color.HoloPurple, "Sierra sunset", "Lone Pine, CA", ImageView.ScaleType.FitStart));
            adapter.Add(new ColorItem(Android.Resource.Color.White, "Majestic", "Grand Teton, WY", ImageView.ScaleType.FitXy));

            return(view);
        }
Exemple #8
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View view = inflater.Inflate(Resource.Layout.Rounded, container, false);

            StreamAdapter adapter = new StreamAdapter(Activity, exampleType);

            adapter.Add(new StreamItem(Activity, Resource.Drawable.photo1, "Tufa at night", "Mono Lake, CA", ImageView.ScaleType.Center));
            adapter.Add(new StreamItem(Activity, Resource.Drawable.photo2, "Starry night", "Lake Powell, AZ", ImageView.ScaleType.CenterCrop));
            adapter.Add(new StreamItem(Activity, Resource.Drawable.photo3, "Racetrack playa", "Death Valley, CA", ImageView.ScaleType.CenterInside));
            adapter.Add(new StreamItem(Activity, Resource.Drawable.photo4, "Napali coast", "Kauai, HI", ImageView.ScaleType.FitCenter));
            adapter.Add(new StreamItem(Activity, Resource.Drawable.photo5, "Delicate Arch", "Arches, UT", ImageView.ScaleType.FitEnd));
            adapter.Add(new StreamItem(Activity, Resource.Drawable.photo6, "Signal Hill", "Cape Town, South Africa", ImageView.ScaleType.FitStart));
            adapter.Add(new StreamItem(Activity, Resource.Drawable.photo7, "Majestic", "Grand Teton, WY", ImageView.ScaleType.FitXy));
            adapter.Add(new StreamItem(Activity, Resource.Drawable.black_white_tile, "TileMode", "REPEAT", ImageView.ScaleType.FitXy, Shader.TileMode.Repeat));
            adapter.Add(new StreamItem(Activity, Resource.Drawable.black_white_tile, "TileMode", "CLAMP", ImageView.ScaleType.FitXy, Shader.TileMode.Clamp));
            adapter.Add(new StreamItem(Activity, Resource.Drawable.black_white_tile, "TileMode", "MIRROR", ImageView.ScaleType.FitXy, Shader.TileMode.Mirror));

            view.FindViewById <ListView>(Resource.Id.main_list).Adapter = adapter;
            return(view);
        }
        public void ReadWriteInt32Test()
        {
            MemoryStream   ms      = new MemoryStream();
            IStreamAdapter adapter = new StreamAdapter(ms);
            // serialize some data
            XmlWriterMock writer = new XmlWriterMock(adapter);
            int           a      = 1234567890;

            writer.Write(a);
            ms.Position = 0;
            string actual   = Encoding.UTF8.GetString(ms.ToArray());
            string expected = "<int>" + a + "</int>";

            Assert.AreEqual(actual, expected);

            // deserialize serialized data
            XmlReaderMock reader = new XmlReaderMock(adapter);
            int           b      = reader.ReadInt32();

            Assert.AreEqual(a, b);
        }
        static void ConnectAndDisconnectSwitchTest(RemoteHubSwitch remoteHubSwitch1, StreamAdapter <byte[]> streamAdaptersOnSwitch1)
        {
            //Sending test messages
            Task sending = Task.Run(async() => await SendTestMessages());

            sending.Wait();

            //disconnect switches
            Console.WriteLine("Disconnecting...");
            remoteHubSwitch1.RemoveAdapter(streamAdaptersOnSwitch1);

            //Sending test messages
            Console.WriteLine("There should be some messages missing due to disconnection.");
            sending = Task.Run(async() => await SendTestMessages());
            sending.Wait();

            //reconnect switches
            Console.WriteLine("Reconnecting...");
            remoteHubSwitch1.AddAdapter(streamAdaptersOnSwitch1);

            //Sending test messages
            sending = Task.Run(async() => await SendTestMessages());
            sending.Wait();
        }
        static void VirtualHostTest(RemoteHubSwitch remoteHubSwitch1, StreamAdapter <byte[]> streamAdaptersOnSwitch1, IRemoteHub <string> sender)
        {
            sender.RemoteClientUpdated += Sender_RemoteClientUpdated;

            //reg
            Console.WriteLine("Please wait for several seconds and press any key to reg virtual hosts...");
            Console.ReadKey(true);

            Guid virtualHostId = Guid.NewGuid();

            foreach (var client in clients)
            {
                client.ApplyVirtualHosts(new KeyValuePair <Guid, VirtualHostSetting>(virtualHostId, new VirtualHostSetting(0, 1)));
            }
            //clients[0].ApplyVirtualHosts(new KeyValuePair<Guid, VirtualHostSetting>(virtualHostId, new VirtualHostSetting(1, 1))); //this command will add higher setting on only clients[0] which will suppress all other clients on the same virtual host.

            Console.WriteLine("Please wait for several seconds and press any key to continue sending test...");
            Console.ReadKey(true);

            //send
            for (int i = 0; i < 100; i++)
            {
                if (sender.TryResolveVirtualHost(virtualHostId, out var hostId))
                {
                    string testMessage = string.Format("<-- {0:D2}: To Virtual Host on {1} -->", i, clientNames[hostId]);
                    waitingTexts.Add(testMessage);
                    sender.SendMessage(hostId, testMessage);
                }
            }

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey(true);
            if (waitingTexts.Count > 0)
            {
                foreach (var text in waitingTexts)
                {
                    Console.WriteLine("Missing message: " + text);
                }
                waitingTexts.Clear();
            }
            else
            {
                Console.WriteLine("All message received.");
            }

            //disconnect switch
            Console.WriteLine("Disconnecting...");
            remoteHubSwitch1.RemoveAdapter(streamAdaptersOnSwitch1);

            //add switch direct link
            Console.WriteLine("Adding client...");
            RemoteHubSwitchDirect <string> clientDirect = new RemoteHubSwitchDirect <string>(Guid.NewGuid(), Received);

            adapterNamesForSwitch1[clientDirect] = "To SwitchDirect"; //name the new created adapter as To SwitchDirect
            clients.Add(clientDirect);
            clientNames.Add(clientDirect.ClientId, "SwitchDirect");   //name the client as SwitchDirect
            remoteHubSwitch1.AddAdapter(clientDirect);

            //set another virtual host
            clientDirect.ApplyVirtualHosts(new KeyValuePair <Guid, VirtualHostSetting>(virtualHostId, new VirtualHostSetting(0, 3)));
            Console.WriteLine("Please wait a while for client (SwitchDirect) discovery and press any key to continue...");

            //resume switch connection
            Console.WriteLine("Reconnecting...");
            remoteHubSwitch1.AddAdapter(streamAdaptersOnSwitch1);

            Console.ReadKey(true);
            //send
            for (int i = 0; i < 100; i++)
            {
                if (sender.TryResolveVirtualHost(virtualHostId, out var hostId))
                {
                    string testMessage = string.Format("<-- {0:D2}: To Virtual Host on {1} -->", i, clientNames[hostId]);
                    waitingTexts.Add(testMessage);
                    sender.SendMessage(hostId, testMessage);
                }
            }

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey(true);

            if (waitingTexts.Count > 0)
            {
                foreach (var text in waitingTexts)
                {
                    Console.WriteLine("Missing message: " + text);
                }
                waitingTexts.Clear();
            }
            else
            {
                Console.WriteLine("All message received.");
            }
        }
Exemple #12
0
        static void AddRemoveClientTest(RemoteHubSwitch remoteHubSwitch2)
        {
            //adding a new client to Redis
            string redisConnectionString = "localhost";                                                    //define redis connection string

            clients.Add(new RemoteHubOverRedis <string>(Guid.NewGuid(), redisConnectionString, Received)); //create one new client to redis and add it to the clients list
            clientNames.Add(clients[4].ClientId, "New Redis Client");                                      //name the client as New Redis Client
            clients[4].Start();                                                                            //start the new created client

            //adding a new client and a connected adapter in pair to Switch 2
            TcpListener tcpListener = new TcpListener(IPAddress.Any, 60005);     //open one tcp listener

            tcpListener.Start();                                                 //start tcp listener
            Task <TcpClient> acceptingTask = tcpListener.AcceptTcpClientAsync(); //waiting for connection

            TcpClient[] tcpClients = new TcpClient[]                             //prepare 2 tcp links, connected in pair
            {
                new TcpClient("localhost", 60005),
                acceptingTask.Result
            };
            tcpListener.Stop();                                                                                                         //stop listener
            NetworkStream[]        streamsOfTcpClients    = Array.ConvertAll(tcpClients, i => i.GetStream());                           //get network streams from tcp links.
            StreamAdapter <byte[]> streamAdapterOnSwitch2 = new StreamAdapter <byte[]>(streamsOfTcpClients[0], streamsOfTcpClients[0]); //create adapter from one stream

            adapterNamesForSwitch2[streamAdapterOnSwitch2] = "To New Stream Client";                                                    //name the new created adapter as To New Stream Client
            clients.Add(new RemoteHubOverStream <string>(Guid.NewGuid(), streamsOfTcpClients[1], streamsOfTcpClients[1], Received));    //create one client based on the other stream which is connected to the stream adapter.
            clientNames.Add(clients[5].ClientId, "New Stream Client");                                                                  //name the client as New Stream Client
            clients[5].Start();                                                                                                         //start the new created client
            remoteHubSwitch2.AddAdapter(streamAdapterOnSwitch2);                                                                        //add the switch adapter to Switch 2
            Console.WriteLine("Please wait a while for clients (New Stream Client & New Redis Client) discovery.");

            //Sending test messages
            Task sending = Task.Run(async() => await SendTestMessages());

            sending.Wait();

            //removing the new added clients
            remoteHubSwitch2.RemoveAdapter(streamAdapterOnSwitch2);
            streamAdapterOnSwitch2.Stop();
            streamAdapterOnSwitch2.Dispose();
            adapterNamesForSwitch2.Remove(streamAdapterOnSwitch2);
            clients[5].Stop();
            ((IDisposable)clients[5]).Dispose();
            clients.RemoveAt(5);
            clients[4].Stop();
            ((IDisposable)clients[4]).Dispose();
            clients.RemoveAt(4);
            foreach (var stream in streamsOfTcpClients)
            {
                stream.Close();
                stream.Dispose();
            }
            foreach (var tcpClient in tcpClients)
            {
                tcpClient.Close();
                tcpClient.Dispose();
            }

            Console.WriteLine("Please wait a while for clients (New Stream Client & New Redis Client) removal.");

            //Sending test messages
            sending = Task.Run(async() => await SendTestMessages());
            sending.Wait();
        }
        public void Resize(byte[] sourceBytes, Stream targetStream, uint targetMaxSize)
        {
            var factory     = (IWICComponentFactory) new WICImagingFactory();
            var inputStream = factory.CreateStream();

            inputStream.InitializeFromMemory(sourceBytes, (uint)sourceBytes.Length);
            var decoder = factory.CreateDecoderFromStream(inputStream, null, WICDecodeOptions.WICDecodeMetadataCacheOnLoad);
            var frame   = decoder.GetFrame(0);

            // Compute target size
            uint width, height, targetWidth, targetHeight;

            frame.GetSize(out width, out height);
            if (width <= targetMaxSize && height <= targetMaxSize)
            {
                targetHeight = height;
                targetWidth  = width;
            }
            else if (width > height)
            {
                targetWidth  = targetMaxSize;
                targetHeight = height * targetMaxSize / width;
            }
            else
            {
                targetWidth  = width * targetMaxSize / height;
                targetHeight = targetMaxSize;
            }

            // Prepare output stream to cache file
            var outputStreamAdapter = new StreamAdapter(targetStream);

            // Prepare JPG encoder
            var encoder = factory.CreateEncoder(Consts.GUID_ContainerFormatJpeg, null);

            encoder.Initialize(outputStreamAdapter, WICBitmapEncoderCacheOption.WICBitmapEncoderNoCache);

            // Prepare output frame
            IWICBitmapFrameEncode outputFrame;
            var argument = new IPropertyBag2[1];

            encoder.CreateNewFrame(out outputFrame, argument);
            var propBag           = argument[0];
            var propertyBagOption = new PROPBAG2[1];

            propertyBagOption[0].pstrName = ImageQualityParamName;
            propBag.Write(1, propertyBagOption, this.jpegQuality);
            outputFrame.Initialize(propBag);
            outputFrame.SetResolution(this.thumbDpi, this.thumbDpi);
            outputFrame.SetSize(targetWidth, targetHeight);

            // Prepare scaler
            var scaler = factory.CreateBitmapScaler();

            scaler.Initialize(frame, targetWidth, targetHeight, WICBitmapInterpolationMode.WICBitmapInterpolationModeLinear);

            // Write the scaled source to the output frame
            outputFrame.WriteSource(scaler, new WICRect {
                X = 0, Y = 0, Width = (int)targetWidth, Height = (int)targetHeight
            });
            outputFrame.Commit();
            encoder.Commit();
        }
Exemple #14
0
 protected override Upload CreateFromSpec(Metadata metadata, StreamAdapter streamAdapter)
 {
     return(new Upload(metadata.Id, Guid.Empty, 0U, metadata.Name, metadata.ContentType, streamAdapter));
 }
Exemple #15
0
        static void Main(string[] args)
        {
            //Redis part
            string redisConnectionString = "localhost";                                                      //define redis connection string

            clients.Add(new RemoteHubOverRedis <string>(Guid.NewGuid(), redisConnectionString, Received));   //create one client to redis and add it to the clients list
            clients.Add(new RemoteHubOverRedis <string>(Guid.NewGuid(), redisConnectionString, Received));   //create one more client to redis and add it to the clients list
            clientNames.Add(clients[0].ClientId, "Client 0");                                                //name the 1st client as Client 0
            clientNames.Add(clients[1].ClientId, "Client 1");                                                //name the 2nd client as Client 1
            clients[0].Start();                                                                              //start the 1st client
            clients[1].Start();                                                                              //start the 2nd client
            RedisAdapter <byte[]> redisAdapterOnRedisHub = new RedisAdapter <byte[]>(redisConnectionString); //create an adapter connected to redis for later using in Switch 2

            //Switch1 part
            TcpListener[] tcpListeners = new TcpListener[] //open 3 tcp listeners
            {
                new TcpListener(IPAddress.Loopback, 60002),
                new TcpListener(IPAddress.Loopback, 60003),
                new TcpListener(IPAddress.Loopback, 60004)
            };
            foreach (var tcpListener in tcpListeners) //start tcp listeners
            {
                tcpListener.Start();
            }
            Task <TcpClient>[] acceptingTasks = Array.ConvertAll(tcpListeners, i => i.AcceptTcpClientAsync()); //waiting for connection for each server
            TcpClient[]        tcpClients     = new TcpClient[]                                                //prepare 6 tcp links, connection relation: 0<->3, 1<->4, 2<->5
            {
                new TcpClient("localhost", 60002),
                new TcpClient("localhost", 60003),
                new TcpClient("localhost", 60004),
                acceptingTasks[0].Result,
                acceptingTasks[1].Result,
                acceptingTasks[2].Result
            };
            foreach (var tcpListener in tcpListeners) //stop all listeners
            {
                tcpListener.Stop();
            }
            NetworkStream[]          streamsOfTcpClients     = Array.ConvertAll(tcpClients, i => i.GetStream()); //get network streams from tcp links.
            StreamAdapter <byte[]>[] streamAdaptersOnSwitch1 = new StreamAdapter <byte[]>[]                      //create adapters from first 3 tcp links.
            {
                new StreamAdapter <byte[]>(streamsOfTcpClients[0], streamsOfTcpClients[0]),
                new StreamAdapter <byte[]>(streamsOfTcpClients[1], streamsOfTcpClients[1]),
                new StreamAdapter <byte[]>(streamsOfTcpClients[2], streamsOfTcpClients[2])
            };
            adapterNamesForSwitch1[streamAdaptersOnSwitch1[0]] = "To Client 2";                                                         //name the 1st adapter as To Client 2
            adapterNamesForSwitch1[streamAdaptersOnSwitch1[1]] = "To Client 3";                                                         //name the 2nd adapter as To Client 3
            adapterNamesForSwitch1[streamAdaptersOnSwitch1[2]] = "To Switch 2";                                                         //name the 3rd adapter as To Switch 2 for later using in Switch 2
            clients.Add(new RemoteHubOverStream <string>(Guid.NewGuid(), streamsOfTcpClients[3], streamsOfTcpClients[3], Received));    //create one client based on the 3rd stream which is connected to the 1st stream adapter.
            clients.Add(new RemoteHubOverStream <string>(Guid.NewGuid(), streamsOfTcpClients[4], streamsOfTcpClients[4], Received));    //create one more client based on the 4th stream which is connected to the 2nd stream adapter.
            clientNames.Add(clients[2].ClientId, "Client 2");                                                                           //name the new created client as Client 2
            clientNames.Add(clients[3].ClientId, "Client 3");                                                                           //name the 2nd new created client as Client 3
            clients[2].Start();                                                                                                         //start the new created client
            clients[3].Start();                                                                                                         //start the 2nd new created client
            StreamAdapter <byte[]> streamAdapterOnSwitch2 = new StreamAdapter <byte[]>(streamsOfTcpClients[5], streamsOfTcpClients[5]); //create one adapter based on the 5th stream which is connected to the 3rd stream adapter.
            RemoteHubSwitch        remoteHubSwitch1       = new RemoteHubSwitch();                                                      //create the 1st Switch

            remoteHubSwitch1.RemoteClientAdded   += RemoteHubSwitch1_RemoteClientAdded;
            remoteHubSwitch1.RemoteClientChanged += RemoteHubSwitch1_RemoteClientChanged;
            remoteHubSwitch1.RemoteClientRemoved += RemoteHubSwitch1_RemoteClientRemoved;
            //remoteHubSwitch1.MessageRouted += RemoteHubSwitch1_MessageRouted;
            //remoteHubSwitch1.MessageRoutingFailed += RemoteHubSwitch1_MessageRoutingFailed;
            remoteHubSwitch1.AddAdapters(streamAdaptersOnSwitch1); //add the new created adapter to the 1st Switch

            //Switch2 part
            adapterNamesForSwitch2[redisAdapterOnRedisHub] = "To Redis";    //name the redis adapter for switch 2 as To Redis
            adapterNamesForSwitch2[streamAdapterOnSwitch2] = "To Switch 1"; //name the stream adapter for switch 2 as To Switch 1
            RemoteHubSwitch remoteHubSwitch2 = new RemoteHubSwitch();       //create the 2nd Switch

            remoteHubSwitch2.RemoteClientAdded   += RemoteHubSwitch2_RemoteClientAdded;
            remoteHubSwitch2.RemoteClientChanged += RemoteHubSwitch2_RemoteClientChanged;
            remoteHubSwitch2.RemoteClientRemoved += RemoteHubSwitch2_RemoteClientRemoved;
            //remoteHubSwitch2.MessageRouted += RemoteHubSwitch2_MessageRouted;
            //remoteHubSwitch2.MessageRoutingFailed += RemoteHubSwitch2_MessageRoutingFailed;
            remoteHubSwitch2.AddAdapter(redisAdapterOnRedisHub); //add the redis adapter to Switch 2
            remoteHubSwitch2.AddAdapter(streamAdapterOnSwitch2); //add the switch adapter to Switch 2

            //Test

            SimpleMessageTest();
            //AddRemoveClientTest(remoteHubSwitch2);
            //ConnectAndDisconnectSwitchTest(remoteHubSwitch1, streamAdaptersOnSwitch1[2]);
            //VirtualHostTest(remoteHubSwitch1, streamAdaptersOnSwitch1[2], clients[2]);

            Console.WriteLine("Press any key to quit...");
            Console.ReadKey(true);

            //Dispose
            foreach (var client in clients) //stop all clients
            {
                client.Stop();
                ((IDisposable)client).Dispose();
            }

            remoteHubSwitch1.RemoveAllAdapters(true); //remove all adapters attached in Switch 1
            remoteHubSwitch2.RemoveAllAdapters(true); //remove all adapters attached in Switch 2

            redisAdapterOnRedisHub.Dispose();
            streamAdapterOnSwitch2.Dispose();
            foreach (var adapter in streamAdaptersOnSwitch1)
            {
                adapter.Dispose();
            }
            foreach (var stream in streamsOfTcpClients)
            {
                stream.Close();
                stream.Dispose();
            }
            foreach (var tcpClient in tcpClients)
            {
                tcpClient.Close();
                tcpClient.Dispose();
            }
        }
 public static Stream GetStreamForFileName(string filename, StreamAdapter.StreamAccess access)
 {
     var acc = access == StreamAdapter.StreamAccess.ForReading ? FileAccess.Read : FileAccess.Write;
     return File.Open(filename, FileMode.OpenOrCreate,acc,FileShare.ReadWrite);
 }