Esempio n. 1
0
        public override object InternalExecute(Program program, object[] arguments)
        {
            FtpWebRequest request = (FtpWebRequest)WebRequest.Create((string)arguments[0]);

            if (arguments.Length > 1)
            {
                request.Credentials = new NetworkCredential((string)arguments[1], (string)arguments[2]);
            }

            // HACK: Apparently there is a defect in the framework that results in an error under certain timing if the following line isn't here:
            request.UsePassive = false;
            // Details: The error: "The remote server returned an error: 227 Entering Passive Mode (208,186,252,59,8,103)"

            FtpWebResponse response       = (FtpWebResponse)request.GetResponse();
            Stream         responseStream = response.GetResponseStream();

            try
            {
                MemoryStream copyStream = new MemoryStream((int)response.ContentLength > 0 ? (int)response.ContentLength : 1024);
                StreamUtility.CopyStream(responseStream, copyStream);
                byte[] data = new byte[copyStream.Length];
                Buffer.BlockCopy(copyStream.GetBuffer(), 0, data, 0, data.Length);
                return(data);
            }
            finally
            {
                responseStream.Close();
            }
        }
Esempio n. 2
0
 public void SetImageAccepted(IFormInterface AForm)
 {
     FImageSource = (IImageSource)AForm;
     if (FImageSource.Stream == null)
     {
         DataField.ClearValue();
     }
     else
     {
         using (DAE.Runtime.Data.Scalar LNewValue = new DAE.Runtime.Data.Scalar(Source.DataView.Process.ValueManager, Source.DataView.Process.DataTypes.SystemGraphic))
         {
             Stream LStream = LNewValue.OpenStream();
             try
             {
                 FImageSource.Stream.Position = 0;
                 StreamUtility.CopyStream(FImageSource.Stream, LStream);
             }
             finally
             {
                 LStream.Close();
             }
             DataField.Value = LNewValue;
         }
     }
 }
Esempio n. 3
0
        public void WriteImage()
        {
            WebSession = (Web.Session)Session["WebSession"];

            Response.ClearContent();
            Response.BufferOutput = false;

            string imageID = Request.QueryString["ImageID"];

            if ((imageID != null) && (imageID != String.Empty))
            {
                using (Stream stream = WebSession.ImageCache.Read(imageID))
                {
                    Response.AppendHeader(ContentLengthHeader, stream.Length.ToString());
                    StreamUtility.CopyStream(stream, Response.OutputStream);
                }
            }
            else
            {
                imageID = Request.QueryString["HandlerID"];
                if ((imageID != null) && (imageID != String.Empty))
                {
                    LoadImageHandler handler = WebSession.ImageCache.GetImageHandler(imageID);
                    if (handler != null)
                    {
                        handler(Context, imageID, Response.OutputStream);
                    }
                }
            }
        }
Esempio n. 4
0
 private Image LoadImage(string imageExpression)
 {
     try
     {
         using (IDataValue imageData = FrontendSession.Pipe.RequestDocument(imageExpression))
         {
             var    streamCopy = new MemoryStream();
             Stream stream     = imageData.OpenStream();
             try
             {
                 StreamUtility.CopyStream(stream, streamCopy);
             }
             finally
             {
                 stream.Close();
             }
             return(Image.FromStream(streamCopy));
         }
     }
     catch (Exception exception)
     {
         Dataphoria.Warnings.AppendError(this, exception, true);
         // Don't rethrow
     }
     return(null);
 }
Esempio n. 5
0
        public void ProcessRequest(HttpContext AContext)
        {
            AContext.Response.ContentType = FrontendUtility.CXmlContentType;

            string LUri = HttpUtility.UrlDecode(AContext.Request.QueryString[DilxUtility.UriParameter]);

            if (LUri == null)
            {
                throw new ServerException(ServerException.Codes.MissingParameter, DilxUtility.UriParameter);
            }
            LUri = AContext.Request.MapPath(new Uri(LUri).LocalPath);

            // Validate that the request is for a DILX document
            if (String.Compare(Path.GetExtension(LUri), DilxUtility.CDilxExtension, true) != 0)
            {
                throw new ServerException(ServerException.Codes.UnknownExtension, Path.GetExtension(LUri));
            }

            // Read the DILX file
            using (FileStream LStream = new FileStream(LUri, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                StreamUtility.CopyStream(LStream, AContext.Response.OutputStream);
            }

            AContext.Response.End();
        }
Esempio n. 6
0
 public override object InternalExecute(Program program, object[] arguments)
 {
     using (FileStream file = File.Open((string)arguments[0], FileMode.Append, FileAccess.Write, FileShare.Read))
     {
         if (Operator.Operands[1].DataType.Is(program.DataTypes.SystemString))
         {
             using (StreamWriter writer = new StreamWriter(file))
             {
                 writer.Write((string)arguments[1]);
             }
         }
         else
         {
             if (arguments[1] is StreamID)
             {
                 using (Stream sourceStream = program.StreamManager.Open((StreamID)arguments[1], LockMode.Exclusive))
                 {
                     StreamUtility.CopyStream(sourceStream, file);
                 }
             }
             else
             {
                 byte[] tempValue = (byte[])arguments[1];
                 file.Write(tempValue, 0, tempValue.Length);
             }
         }
     }
     return(null);
 }
Esempio n. 7
0
 protected void LoadImage()
 {
     if (!ImageSource.Loading)
     {
         try
         {
             ImageSource.LoadImage();
             if (ImageSource.Stream != null)
             {
                 using (DAE.Runtime.Data.Scalar newValue = new DAE.Runtime.Data.Scalar(ImageControl.Source.DataSet.Process.ValueManager, ImageControl.Source.DataSet.Process.DataTypes.SystemGraphic))
                 {
                     using (Stream stream = newValue.OpenStream())
                     {
                         using (ImageSource.Stream)
                         {
                             ImageSource.Stream.Position = 0;
                             StreamUtility.CopyStream(ImageSource.Stream, stream);
                             ImageControl.DataField.Value = newValue;
                             ImageControl.LoadImage();
                         }
                     }
                 }
             }
         }
         finally
         {
             if (ImageSource.GetType() == typeof(ImageCaptureForm))
             {
                 ImageSource = null;
             }
         }
     }
 }
Esempio n. 8
0
 public Stream Read(string imageID)
 {
     string fileName = BuildFileName(imageID);
     if (File.Exists(fileName))
         return File.OpenRead(fileName);
     else
     {
         FileStream fileStream = new FileStream(fileName, FileMode.CreateNew, FileAccess.ReadWrite);
         try
         {
             object tempValue = _identifiers[imageID];
             if (tempValue is String)
             {
                 using (DAE.Runtime.Data.Scalar scalar = (DAE.Runtime.Data.Scalar)_session.Pipe.RequestDocument((string)tempValue))
                     StreamUtility.CopyStream(scalar.OpenStream(), fileStream);
             }
             else
                 ((GetImageHandler)tempValue)(imageID, fileStream);
             fileStream.Position = 0;
             return fileStream;
         }
         catch
         {
             fileStream.Close();
             if (File.Exists(fileName))
                 File.Delete(fileName);
             throw;
         }
     }
 }
Esempio n. 9
0
        internal void InternalSaveToFile()
        {
            if (String.IsNullOrEmpty(_fileName))
            {
                _fileName = PromptForSaveName();
            }
            // The file must be writable to overwrite
            if (File.Exists(_fileName))
            {
                FileUtility.EnsureWriteable(_fileName);
            }

            // Write/rewrite the file
            using (FileStream fileStream = new FileStream(_fileName, FileMode.Create, FileAccess.Write))
                if (((Schema.ScalarType)DataField.DataType).NativeType == typeof(byte[]))
                {
                    using (Stream stream = DataField.Value.OpenStream())
                        StreamUtility.CopyStream(stream, fileStream);
                }
                else
                {
                    using (StreamWriter streamWriter = new StreamWriter(fileStream))
                        streamWriter.Write(DataField.Value.AsString);
                }
        }
Esempio n. 10
0
 private void ImageRead(PipeRequest request, Pipe pipe)
 {
     if (Active)
     {
         _imageRequest = null;
         try
         {
             if (request.Result.IsNative)
             {
                 byte[] resultBytes = request.Result.AsByteArray;
                 SetImage(System.Drawing.Image.FromStream(new MemoryStream(resultBytes, 0, resultBytes.Length, false, true)));
             }
             else
             {
                 using (Stream stream = request.Result.OpenStream())
                 {
                     MemoryStream copyStream = new MemoryStream();
                     StreamUtility.CopyStream(stream, copyStream);
                     SetImage(System.Drawing.Image.FromStream(copyStream));
                 }
             }
         }
         catch
         {
             SetImage(ImageUtility.GetErrorImage());
         }
     }
 }
Esempio n. 11
0
 protected void ImageRead(PipeRequest request, Pipe pipe)
 {
     if (Active)
     {
         try
         {
             _imageRequest = null;
             try
             {
                 if (request.Result.IsNative)
                 {
                     byte[] resultBytes = request.Result.AsByteArray;
                     _internalImage = System.Drawing.Image.FromStream(new MemoryStream(resultBytes, 0, resultBytes.Length, false, true));
                 }
                 else
                 {
                     using (Stream stream = request.Result.OpenStream())
                     {
                         MemoryStream copyStream = new MemoryStream();
                         StreamUtility.CopyStream(stream, copyStream);
                         _internalImage = System.Drawing.Image.FromStream(copyStream);
                     }
                 }
             }
             catch
             {
                 _internalImage = ImageUtility.GetErrorImage();
             }
         }
         finally
         {
             UpdateColumn();
         }
     }
 }
Esempio n. 12
0
 protected void ImageRead(PipeRequest request, Pipe pipe)
 {
     _imageRequest = null;
     try
     {
         if (request.Result.IsNative)
         {
             byte[] resultBytes = request.Result.AsByteArray;
             _image = System.Drawing.Image.FromStream(new MemoryStream(resultBytes, 0, resultBytes.Length, false, true));
         }
         else
         {
             using (Stream stream = request.Result.OpenStream())
             {
                 MemoryStream copyStream = new MemoryStream();
                 StreamUtility.CopyStream(stream, copyStream);
                 _image = System.Drawing.Image.FromStream(copyStream);
             }
         }
     }
     catch
     {
         _image = ImageUtility.GetErrorImage();
     }
     FCallBack(this, new EventArgs());
 }
Esempio n. 13
0
        public StreamID Reference(StreamID streamID)
        {
            LocalStreamHeader targetHeader;

            if (_headers.TryGetValue(streamID, out targetHeader) && (targetHeader.Stream != null) && targetHeader.Stream.Modified)
            {
                StreamID localStreamID = Allocate();
                Stream   stream        = Open(localStreamID, LockMode.Exclusive);
                try
                {
                    Stream targetStream = new CoverStream(targetHeader.Stream);
                    try
                    {
                        StreamUtility.CopyStream(targetStream, stream);
                        return(localStreamID);
                    }
                    finally
                    {
                        targetStream.Close();
                    }
                }
                finally
                {
                    stream.Close();
                    Close(localStreamID);
                }
            }
            else
            {
                StreamID          localStreamID = _sourceStreamManager.Reference(streamID);
                LocalStreamHeader header        = new LocalStreamHeader(localStreamID);
                _headers.Add(header);
                return(localStreamID);
            }
        }
Esempio n. 14
0
 public override void LoadData(Stream data)
 {
     using (Stream stream = File.OpenRead(FileName))
     {
         data.Position = 0;
         StreamUtility.CopyStream(stream, data);
     }
 }
Esempio n. 15
0
 public override void SaveBinaryData(Stream data)
 {
     EnsureWritable(FileName);
     using (Stream stream = new FileStream(FileName, FileMode.Create, FileAccess.Write))
     {
         data.Position = 0;
         StreamUtility.CopyStream(data, stream);
     }
 }
Esempio n. 16
0
        public void Update(Stream AData, int AEntryNumber)
        {
            if (NodeType == IndexNodeType.Data)
            {
                FIndex.DisposeData(FProcess, Data(AEntryNumber));
            }

            AData.Position = 0;
            StreamUtility.CopyStream(AData, Data(AEntryNumber));
        }
Esempio n. 17
0
        // IWebPrehandler

        public override void PreprocessRequest(HttpContext AContext)
        {
            if (AContext.Request.Files.Count > 0)
            {
                FLoading = true;
                Stream LStream = new MemoryStream();
                StreamUtility.CopyStream(AContext.Request.Files[0].InputStream, LStream);
                FStream = LStream;
            }
            base.ProcessRequest(AContext);
        }
Esempio n. 18
0
 public override void Flush()
 {
     if (_modified)
     {
         SourceStream.SetLength(0);
         _stream.Position = 0;
         StreamUtility.CopyStream(_stream, SourceStream);
         _modified            = false;
         _sourcePositionReset = true;
         _stream.Position     = 0;
         _sourceLength        = _stream.Length;
     }
 }
Esempio n. 19
0
        internal void InternalDelete(int AEntryNumber)
        {
            // foreach Entry > AEntryNumber, asc, copy the existing entry to the entry below
            int LEntryCount = EntryCount;

            for (int LIndex = AEntryNumber + 1; LIndex < LEntryCount; LIndex++)
            {
                StreamUtility.CopyStream(Entry(LIndex), Entry(LIndex - 1));
            }

            // Decrement EntryCount
            EntryCount = LEntryCount - 1;
        }
Esempio n. 20
0
        private static byte[] FromStreamCore(Stream value, bool leaveStreamOpen)
        {
            MemoryStream s = value as MemoryStream;

            if (s != null)
            {
                if (leaveStreamOpen)
                {
                    return(s.ToArray());
                }
                using (s) { return(s.ToArray()); }
            }
            return(((MemoryStream)StreamUtility.CopyStream(value, leaveStreamOpen)).ToArray());
        }
Esempio n. 21
0
 private void SetModified()
 {
     if (!IsModified)
     {
         long position = _sourceStream.Position;
         _sourceStream.Position = 0;
         if (_sourceStream.Length > Int32.MaxValue)
         {
             throw new StreamsException(StreamsException.Codes.CopyOnWriteOverflow);
         }
         _modifiedStream = new MemoryStream((int)_sourceStream.Length);
         StreamUtility.CopyStream(_sourceStream, _modifiedStream);
         _modifiedStream.Position = position;
     }
 }
Esempio n. 22
0
 private void GetImage(HttpContext AContext, string AID, Stream AStream)
 {
     if (IsFieldActive() && DataField.HasValue())
     {
         Stream LStream = DataField.Value.OpenStream();
         try
         {
             StreamUtility.CopyStream(LStream, AStream);
         }
         finally
         {
             LStream.Close();
         }
     }
 }
Esempio n. 23
0
        protected void LoadClicked(object sender, EventArgs args)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = Strings.Get("DBImageAspect.OpenFileDialog.Filter");
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                using (FileStream imageFile = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.Read))
                {
                    MemoryStream copy = new MemoryStream();
                    StreamUtility.CopyStream(imageFile, copy);
                    copy.Position = 0;
                    Image         = System.Drawing.Image.FromStream(copy);
                }
            }
        }
 /// <summary>
 /// Converts the given stream to an <see cref="IXPathNavigable"/> object.
 /// </summary>
 /// <param name="value">The <see cref="Stream"/> to be converted.</param>
 /// <param name="leaveStreamOpen">if <c>true</c>, the source <see cref="Stream"/> is being left open; otherwise it is being closed and disposed.</param>
 /// <returns>An <see cref="System.Xml.XPath.IXPathNavigable"/> object.</returns>
 public static IXPathNavigable FromStream(Stream value, bool leaveStreamOpen)
 {
     Validator.ThrowIfNull(value, nameof(value));
     if (leaveStreamOpen)
     {
         Stream copyOfValue = StreamUtility.CopyStream(value, true);
         using (copyOfValue)
         {
             return(new XPathDocument(copyOfValue));
         }
     }
     using (value)
     {
         return(new XPathDocument(value));
     }
 }
Esempio n. 25
0
        private void LoadImage(HttpContext context, string iD, Stream stream)
        {
            string rowIndex = context.Request.QueryString["RowIndex"];

            if ((rowIndex != String.Empty) && (ColumnName != String.Empty))
            {
                DAE.Runtime.Data.IRow row = ParentGrid.DataLink.Buffer(Int32.Parse(rowIndex));
                if ((row != null) && row.HasValue(ColumnName))
                {
                    using (Stream source = row.GetValue(ColumnName).OpenStream())
                    {
                        StreamUtility.CopyStream(source, stream);
                    }
                }
            }
        }
Esempio n. 26
0
 public override void LoadData(Stream data)
 {
     using (DAE.Runtime.Data.IScalar scalar = Dataphoria.FrontendSession.Pipe.RequestDocument(String.Format(".Frontend.LoadBinary('{0}', '{1}')", DAE.Schema.Object.EnsureRooted(LibraryName), DAE.Schema.Object.EnsureRooted(DocumentName))))
     {
         data.Position = 0;
         Stream stream = scalar.OpenStream();
         try
         {
             StreamUtility.CopyStream(stream, data);
         }
         finally
         {
             stream.Close();
         }
     }
 }
Esempio n. 27
0
        public void ProcessRequest(HttpContext AContext)
        {
            string LUri = HttpUtility.UrlDecode(AContext.Request.QueryString[DilxUtility.UriParameter]);

            if (LUri == null)
            {
                throw new ServerException(ServerException.Codes.MissingParameter, DilxUtility.UriParameter);
            }
            string LTemp = AContext.Request.MapPath(new Uri(LUri).LocalPath);

            // TODO: Authenticate save request (security, or at least make sure we aren't overwriting a dynamic page)

            switch (Path.GetExtension(LTemp).ToLower())
            {
            case DilxUtility.CDilxExtension:
                // write to a memory stream first, then write to the file.
                using (MemoryStream LMemoryStream = new MemoryStream())
                {
                    Process(AContext.Request.InputStream, LMemoryStream, AContext);
                    using (FileStream LStream = new FileStream(LTemp, FileMode.Create, FileAccess.Write))
                    {
                        LMemoryStream.Position = 0;
                        StreamUtility.CopyStream(LMemoryStream, LStream);
                    }
                }
                break;

            case DilxUtility.CDilExtension:
                using (FileStream LStream = new FileStream(LTemp, FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    StreamUtility.CopyStream(AContext.Request.InputStream, LStream);
                }
                break;

            default:
                throw new ServerException(ServerException.Codes.UnknownExtension, Path.GetExtension(LTemp));
            }

            LTemp = AContext.Request.QueryString[CAddLinkMap];
            if ((LTemp != null) && (LTemp != String.Empty))
            {
                LTemp = new Uri(LTemp).PathAndQuery.Remove(0, AContext.Request.ApplicationPath.Length + 1);
                LUri  = new Uri(LUri).PathAndQuery.Remove(0, AContext.Request.ApplicationPath.Length + 1);
                ((ApplicationServer)AContext.ApplicationInstance).AddLinkMap(WebUtility.SortUri(HttpUtility.UrlDecode(LTemp)), LUri);
            }
        }
Esempio n. 28
0
        private void FCapture_Click(object sender, EventArgs e)
        {
            String tempFileName = Path.Combine(Application.LocalUserAppDataPath, Strings.CTempFileName);

            SendMessage(_videoHandle, WM_CAP_FILE_SAVEDIB, SendMessagenNullParameter, tempFileName);
            using (FileStream imageFile = new FileStream(tempFileName, FileMode.Open, FileAccess.Read))
            {
                if (_stream != null)
                {
                    _stream.Close();
                    _stream = null;
                }
                _stream = new MemoryStream();
                StreamUtility.CopyStream(imageFile, _stream);
                _stream.Position    = 0;
                FCaptureImage.Image = System.Drawing.Image.FromStream(_stream);
            }
        }
Esempio n. 29
0
        protected void ImageRead(PipeRequest request, Pipe pipe)
        {
            Size oldSize;

            if (Active)
            {
                if (_imageAspect.Image != null)
                {
                    oldSize = _imageAspect.Image.Size;
                }
                else
                {
                    oldSize = Size.Empty;
                }

                _imageRequest = null;
                try
                {
                    if (request.Result.IsNative)
                    {
                        byte[] resultBytes = request.Result.AsByteArray;
                        _imageAspect.Image = System.Drawing.Image.FromStream(new MemoryStream(resultBytes, 0, resultBytes.Length, false, true));
                    }
                    else
                    {
                        using (Stream stream = request.Result.OpenStream())
                        {
                            MemoryStream copyStream = new MemoryStream();
                            StreamUtility.CopyStream(stream, copyStream);
                            _imageAspect.Image = System.Drawing.Image.FromStream(copyStream);
                        }
                    }
                }
                catch
                {
                    _imageAspect.Image = ImageUtility.GetErrorImage();
                }
                if ((ImageWidth < 0) || (ImageHeight < 0) || !(_imageAspect.Image.Size != oldSize))
                {
                    UpdateLayout();
                }
            }
        }
Esempio n. 30
0
        internal void InternalInsert(Stream AKey, Stream AData, int AEntryNumber)
        {
            // foreach Entry >= AEntryNumber, desc, copy the existing entry to the next entry
            int LEntryCount = EntryCount;

            for (int LIndex = LEntryCount - 1; LIndex >= AEntryNumber; LIndex--)
            {
                StreamUtility.CopyStream(Entry(LIndex), Entry(LIndex + 1));
            }

            // Write the given Key and Data streams into the node
            AKey.Position = 0;
            StreamUtility.CopyStream(AKey, Key(AEntryNumber));
            AData.Position = 0;
            StreamUtility.CopyStream(AData, Data(AEntryNumber));

            // Increment EntryCount
            EntryCount = LEntryCount + 1;
        }