Ejemplo n.º 1
0
        void ICommunicationService.UploadData(DataInfo request)
        {
            if (owner != null)
                owner.RouteFileData(request.Context, request.FileName, request.ByteStream, request.Length);

            //TestUploadData(request);
        }
Ejemplo n.º 2
0
        void ICommunicationService.UploadData(DataInfo request)
        {
            try
            {
                if (owner != null)
                    owner.RouteFileData(request.Context, request.FileName, request.ByteStream, request.Length);
            }
            catch
            {
            }

            //int chunkSize = 2048;
            //byte[] buffer = new byte[chunkSize];
            //int count = 0;

            //using (MemoryStream ms = new MemoryStream())
            //{
            //    while ((count = request.ByteStream.Read(buffer, 0, chunkSize)) > 0)
            //    {
            //        ms.Write(buffer, 0, count);
            //    }

            //    ms.Seek(0, SeekOrigin.Begin);
            //    try
            //    {
            //        if (owner != null)
            //            owner.RouteData(request.Context, request.FileName, ms);
            //    }
            //    catch
            //    {
            //    }

            //    ms.Close();
            //}
        }
Ejemplo n.º 3
0
 public static void UploadData(DataInfo request)
 {
     EndpointAddress ep = new EndpointAddress(uri);
     NetNamedPipeBinding binding = new NetNamedPipeBinding();
     binding.MaxReceivedMessageSize = int.MaxValue;
     binding.SendTimeout = TimeSpan.MaxValue;
     binding.TransferMode = TransferMode.Streamed;
     binding.MaxBufferSize = int.MaxValue;
     ICommunicationService proxy = ChannelFactory<ICommunicationService>.CreateChannel(binding, ep);
     proxy.UploadData(request);
 }
Ejemplo n.º 4
0
        public void TestUploadData(DataInfo request)
        {
            bool abort = false;

            string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "TestWCF");

            if (Directory.Exists(path) == false)
                Directory.CreateDirectory(path);

            string file = Path.Combine(path, Guid.NewGuid().ToString()/*request.FileName*/);

            Stream stream = null;
            BinaryWriter writer = null;
            try
            {
                Console.WriteLine(String.Format("UploadData..."));

                stream = File.Open(file, FileMode.Create);
                writer = new BinaryWriter(stream);

                int bufferSize = 0x100000;
                byte[] buffer = new byte[bufferSize];

                int bytesRead = 0;
                while ((bytesRead = request.ByteStream.Read(buffer, 0, bufferSize)) > 0)
                {
                    writer.Write(buffer, 0, bytesRead);
                }
            }
            catch (Exception ex)
            {
                abort = true;
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                    stream = null;
                }

                if (File.Exists(file) == true && abort == true)
                    File.Delete(file);
            }
        }