Esempio n. 1
0
        void ICommunicationService.UploadContent(UploadStreamMessage content)
        {
            Stream source = content.DataStream;
            MemoryTributary ms = new MemoryTributary();

            const int bufferLen = 65536;
            byte[] buffer = new byte[bufferLen];
            int count = 0;
            while ((count = source.Read(buffer, 0, bufferLen)) > 0)
            {
                ms.Write(buffer, 0, count);
            }

            ms.Seek(0, SeekOrigin.Begin);
            try
            {
                if (owner != null)
                    owner.RouteData(content.Context, content.ContentType, ms);
            }
            catch
            {
            }
            //MessageBox.Show(content.ContentType + " " + content.Context + " " + ms.Length);
            ms.Close();
        }
Esempio n. 2
0
            private void Pack(bool enableNewCode = true)
            {
                MemoryTributary DeflateBufferStream = new MemoryTributary();
                MemoryTributary DataBufferStream = new MemoryTributary();

                foreach (CV8Elem elem in Elems)
                {
                    UInt32 elemNum = (UInt32)Elems.IndexOf(elem);

                    if (!elem.IsV8File)
                    {
                        DataBufferStream = new MemoryTributary();
                        bool success = Deflate(elem.GetDataLikeMemStream(), out DataBufferStream);
                        if (!success)
                            throw new Exception("Ошибка сжатия данных. Некорректный формат данных!");

                        elem.SetDataFromMemStream(DataBufferStream);
                        elem.DataSize = (UInt32)DataBufferStream.Length;
                    }
                    else
                    {
                        DataBufferStream = new MemoryTributary();
                        MemoryTributary outBufSteram = new MemoryTributary();
                        elem.UnpackedData.GetData(out DataBufferStream);
                        bool success = Deflate(DataBufferStream, out outBufSteram);
                        if (!success)
                            throw new Exception("Ошибка сжатия данных. Некорректный формат данных!");

                        elem.UnpackedData = new V8File(this);
                        elem.IsV8File = false;

                        elem.SetDataFromMemStream(outBufSteram);
                        elem.DataSize = (UInt32)outBufSteram.Length;
                    }
                }

                DeflateBufferStream.Close();
                DataBufferStream.Close();
            }
Esempio n. 3
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            if (sendContext == Stub.context.textData)
            {
                String logMessage = String.Empty;
                try
                {
                    MemoryTributary stream = new MemoryTributary();
                    //MemoryStream stream = new MemoryStream();
                    reg_editor.Document.SaveDocument(stream, DocumentFormat.Rtf);
                    stream.Position = 0;

                    Communicator.UploadContent(context, "application/rtf", stream);

                    stream.Close();

                    logMessage = "Сообщение отправлено!";
                    reg_editor.Text = String.Empty;
                }
                catch (Exception ex)
                {
                    logMessage = "В процессе отправки произошла ошибка: " + ex.Message;
                }
                WriteLog(logMessage);
            }

            if (sendContext == Stub.context.fileData)
            {
                using (OpenFileDialog dlg = new OpenFileDialog())
                {
                    dlg.CheckPathExists = true;
                    dlg.CheckFileExists = true;
                    dlg.Multiselect = true;
                    if (dlg.ShowDialog(this) == DialogResult.OK)
                    {
                        foreach (String fName in dlg.FileNames)
                        {
                            UploadFile(fName);
                        }
                    }
                }
            }
        }