Ejemplo n.º 1
0
        /// <summary>
        /// ЗАГРУЖАЕМ файл в базу
        /// </summary>
        public static void Download(FileSystemStoreObject descriptor, Stream source)
        {
            Stream destination = null;
            try
            {
                destination = File.Open(descriptor.RealFileName, FileMode.Create);
                BinaryWriter writer = new BinaryWriter(destination);

                byte[] buffer = new byte[1024 * 1024];
                int count = 0;
                while ((count = source.Read(buffer, 0, buffer.Length)) > 0)
                {
                    writer.Write(buffer, 0, count);
                }

                descriptor.Save();
            }
            catch { }
            finally
            {
                if (destination != null)
                {
                    destination.Close();
                    destination = null;
                }
            }
        }
Ejemplo n.º 2
0
 private void SaveFileSystemStoreObject(FileSystemStoreObject fileObject, System.IO.Stream stream)
 {
     if (fileObject != null && stream != null)
     {
         System.IO.MemoryStream memory = new System.IO.MemoryStream();
         stream.CopyTo(memory);
         memory.Position = 0;
         (fileObject as IFileData).LoadFromStream(fileObject.FileName, memory);
         fileObject.Save();
         stream.Close();
     }
 }
Ejemplo n.º 3
0
 private static void SaveConclusionTemplate(FileSystemStoreObject fileObject, System.IO.Stream stream)
 {
     if (fileObject != null && stream != null)
     {
         var memory = new System.IO.MemoryStream();
         stream.CopyTo(memory);
         memory.Position = 0;
         (fileObject as IFileData).LoadFromStream("Сonclusion-template.rtf", memory);
         fileObject.Save();
         stream.Close();
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Медод передает в FileSystemStoreObject ссылку на поток с исходным файлом
        /// ФАЙЛ СОХРАНЯЕТСЯ НА ДИСК ПРИ ВЫЗОВЕ ObjectSpace.CommitChanges()
        /// </summary>
        private static void CopyToStoreObject(string sourceFileName, FileSystemStoreObject destinationStoreObject)
        {
            System.IO.Stream stream = System.IO.File.Open(sourceFileName, System.IO.FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            System.IO.MemoryStream memory = new System.IO.MemoryStream();
            stream.CopyTo(memory);
            memory.Position = 0;

            (destinationStoreObject as IFileData).LoadFromStream(destinationStoreObject.FileName, memory);

            destinationStoreObject.Save();

            if (stream != null)
                stream.Close();
        }
Ejemplo n.º 5
0
        private static void CreateFromTemplate( FileSystemStoreObject template, FileSystemStoreObject target)
        {
            if (File.Exists(template.RealFileName) == true)
            {
                Stream stream = null;
                try
                {
                    stream = File.Open(template.RealFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

                    var memory = new MemoryStream();

                    stream.CopyTo(memory);
                    memory.Position = 0;

                    (target as IFileData).LoadFromStream(target.FileName, memory);

                    target.Save();
                }
                catch (Exception e)
                {
                    Tracing.Tracer.LogError(e);
                }
                finally
                {
                    if (stream != null)
                    {
                        stream.Close();
                    }
                }
            }
            else
            {
                Tracing.Tracer.LogWarning("Conclusion template file not found!");
            }
        }