Example #1
0
 public static void Load(XmlDocument document, string filename)
 {
     using (Stream stream = new C1FileStream(filename, FileMode.Open))
     {
         document.Load(stream);
     }
 }
Example #2
0
 public static void Save(XmlDocument document, string filename)
 {
     using (Stream stream = new C1FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.Read))
     {
         document.Save(stream);
     }
 }
Example #3
0
 /// <summary>
 /// This should be a part of the I/O layer
 /// </summary>
 public static void SaveToPath(this XElement element, string fileName)
 {
     using (var stream = new C1FileStream(fileName, FileMode.Create, FileAccess.Write))
     {                
         element.Save(stream);
     }
 }
Example #4
0
        /// <summary>
        /// Creates a new XmlWriter
        /// </summary>
        /// <param name="path">Path to file</param>
        /// <param name="settings">An instance to XmlWriterSettings</param>
        /// <returns>Returns the newly created XmlWriter</returns>
        public static XmlWriter Create(string path, XmlWriterSettings settings)
        {
            Stream stream = new C1FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read);

            settings.CloseOutput = true;

            return XmlWriter.Create(stream, settings);
        }        
Example #5
0
        /// <summary>
        /// This should be a part of the I/O layer
        /// </summary>
        public static XmlReader Create(string path, XmlReaderSettings settings)
        {
            MemoryStream memoryStream = new MemoryStream();

            using (Stream stream = new C1FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                StreamUtils.CopyStream(stream, memoryStream);
            }

            memoryStream.Seek(0, SeekOrigin.Begin);

            if (settings == null)
            {
                return XmlReader.Create(memoryStream);
            }
            else
            {
                return XmlReader.Create(memoryStream, settings);
            }
        }
        private void finalizeCodeActivity_SaveFile_ExecuteCode(object sender, EventArgs e)
        {
            UploadedFile uploadedFile = this.GetBinding<UploadedFile>("UploadedFile");

            if (uploadedFile.HasFile)
            {
                string currentPath = GetCurrentPath();
                string filename = uploadedFile.FileName;

                string fullFilename = System.IO.Path.Combine(currentPath, filename);

                if (C1File.Exists(fullFilename))
                {
                    FileUtils.Delete(fullFilename);
                }

                using (C1FileStream fs = new C1FileStream(fullFilename, FileMode.CreateNew))
                {
                    uploadedFile.FileStream.CopyTo(fs);
                }

                SpecificTreeRefresher specificTreeRefresher = this.CreateSpecificTreeRefresher();
                specificTreeRefresher.PostRefreshMesseges(this.EntityToken);

                if (this.EntityToken is WebsiteFileElementProviderEntityToken)
                {
                    WebsiteFileElementProviderEntityToken folderToken = (WebsiteFileElementProviderEntityToken)this.EntityToken;
                    var newFileToken = new WebsiteFileElementProviderEntityToken(folderToken.ProviderName, fullFilename, folderToken.RootPath);
                    SelectElement(newFileToken);
                }
            }
        }
        private object DeserializeActivity(Activity rootActivity, Guid id)
        {
            string filename = GetFileName(id);
            object result;

            IFormatter formatter = new BinaryFormatter();
            formatter.SurrogateSelector = ActivitySurrogateSelector.Default;

            using (C1FileStream stream = new C1FileStream(filename, FileMode.Open))
            {
                result = Activity.Load(stream, rootActivity, formatter);
                stream.Close();
            }

            // Log.LogVerbose(LogTitle, $"Workflow loaded. Id = {id}, Type = {result.GetType()}");

            return result;
        }
        private void SerializeActivity(Activity rootActivity, Guid id)
        {
            if (!ActivityIsSerializable(rootActivity))
            {
                Log.LogVerbose(LogTitle,
                    $"The workflow does not support persiting. Id = {id}, Type = {rootActivity.GetType()}");
                return;
            }

            string filename = GetFileName(id);

            IFormatter formatter = new BinaryFormatter();
            formatter.SurrogateSelector = ActivitySurrogateSelector.Default;

            using (C1FileStream stream = new C1FileStream(filename, FileMode.OpenOrCreate))
            {
                rootActivity.Save(stream, formatter);
                stream.Close();
            }

            // Log.LogVerbose(LogTitle, $"Workflow persisted. Id = {id}, Type = {rootActivity.GetType()}");
        }
Example #9
0
        private static PackageFragmentValidationResult SaveZipFile(Stream zipFileStream, out string zipFilename)
        {
            zipFilename = null;

            try
            {
                zipFilename = Path.Combine(PathUtil.Resolve(GlobalSettingsFacade.PackageDirectory), PackageSystemSettings.ZipFilename);

                if (C1File.Exists(zipFilename))
                {
                    C1File.Delete(zipFilename);
                }

                if (C1Directory.Exists(Path.GetDirectoryName(zipFilename)) == false)
                {
                    C1Directory.CreateDirectory(Path.GetDirectoryName(zipFilename));
                }

                using (Stream readStream = zipFileStream)
                {
                    using (C1FileStream fileStream = new C1FileStream(zipFilename, FileMode.Create))
                    {
                        byte[] buffer = new byte[4096];

                        int readBytes;
                        while ((readBytes = readStream.Read(buffer, 0, 4096)) > 0)
                        {
                            fileStream.Write(buffer, 0, readBytes);
                        }
                    }
                }

                return null;
            }
            catch (Exception ex)
            {
                return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, ex);
            }
        }
        private void SerializeActivity(Activity rootActivity, Guid id)
        {
            if (!ActivityIsSerializable(rootActivity))
            {
                LoggingService.LogVerbose("FileWorkFlowPersisetenceService", string.Format("The workflow does not support persiting. Id = {0}, Type = {1}", id, rootActivity.GetType()));
                return;
            }

            string filename = GetFileName(id);

            IFormatter formatter = new BinaryFormatter();
            formatter.SurrogateSelector = ActivitySurrogateSelector.Default;

            using (C1FileStream stream = new C1FileStream(filename, FileMode.OpenOrCreate))
            {
                rootActivity.Save(stream, formatter);
                stream.Close();
            }

            // LoggingService.LogVerbose("FileWorkFlowPersisetenceService", string.Format("Workflow persisted. Id = {0}, Type = {1}", id, rootActivity.GetType()));
        }
        private object DeserializeActivity(Activity rootActivity, Guid id)
        {
            string filename = GetFileName(id);
            object result;

            IFormatter formatter = new BinaryFormatter();
            formatter.SurrogateSelector = ActivitySurrogateSelector.Default;

            using (C1FileStream stream = new C1FileStream(filename, FileMode.Open))
            {
                result = Activity.Load(stream, rootActivity, formatter);
                stream.Close();
            }

            // LoggingService.LogVerbose("FileWorkFlowPersisetenceService", string.Format("Workflow loaded. Id = {0}, Type = {1}", id, result.GetType()));

            return result;
        }