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 (var stream = new C1FileStream(filename, FileMode.OpenOrCreate)) { try { rootActivity.Save(stream, formatter); stream.Close(); } catch (SerializationException ex) { Log.LogError(LogTitle, ex); } } // Log.LogVerbose(LogTitle, $"Workflow persisted. Id = {id}, Type = {rootActivity.GetType()}"); }
/// <summary> /// This should be a part of the I/O layer /// </summary> public static void Save(XDocument document, string filename) { using (C1FileStream stream = new C1FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.Read)) { document.Save(stream); } }
public static void Load(XmlDocument document, string filename) { using (Stream stream = new C1FileStream(filename, FileMode.Open)) { document.Load(stream); } }
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); } } }
/// <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); } }
/// <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)); }
private void Initialize() { using (C1FileStream fileStream = C1File.Open(this.ZipFilename, FileMode.Open, FileAccess.Read)) { using (var zipInputStream = new ZipInputStream(fileStream)) { ZipEntry zipEntry; while ((zipEntry = zipInputStream.GetNextEntry()) != null) { _existingFilenamesInZip.Add(zipEntry.Name, zipEntry); } } } }
/// <summary> /// /// </summary> /// <param name="filename"> /// Format: /// ~\Filename.txt /// ~\Directory1\Directory2\Filename.txt /// ~/Filename.txt /// ~/Directory1/Directory2/Filename.txt /// </param> /// <param name="targetFilename"> /// </param> /// <returns></returns> public void WriteFileToDisk(string filename, string targetFilename) { using (Stream stream = GetFileStream(filename)) { using (var fileStream = new C1FileStream(targetFilename, FileMode.Create, FileAccess.Write)) { byte[] buffer = new byte[CopyBufferSize]; int readBytes; while ((readBytes = stream.Read(buffer, 0, CopyBufferSize)) > 0) { fileStream.Write(buffer, 0, readBytes); } } } }
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 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); }
private void finalizeCodeActivity_ExecuteCode(object sender, EventArgs e) { string currentPath = GetCurrentPath(); string newFileName = this.GetBinding <string>("NewFileName"); string fullPath = Path.Combine(currentPath, newFileName); using (C1FileStream fs = C1File.Create(fullPath)) { } SpecificTreeRefresher specificTreeRefresher = this.CreateSpecificTreeRefresher(); specificTreeRefresher.PostRefreshMesseges(this.EntityToken); if (this.EntityToken is WebsiteFileElementProviderEntityToken) { WebsiteFileElementProviderEntityToken folderToken = (WebsiteFileElementProviderEntityToken)this.EntityToken; var newFileToken = new WebsiteFileElementProviderEntityToken(folderToken.ProviderName, fullPath, folderToken.RootPath); SelectElement(newFileToken); } }
/// <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 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())); }
/// <summary> /// /// </summary> /// <param name="filename"> /// Format: /// ~\Filename.txt /// ~\Directory1\Directory2\Filename.txt /// ~/Filename.txt /// ~/Directory1/Directory2/Filename.txt /// </param> /// <param name="targetFilename"> /// </param> /// <returns></returns> public void WriteFileToDisk(string filename, string targetFilename) { using (var stream = GetFileStream(filename)) { using (var fileStream = new C1FileStream(targetFilename, FileMode.Create, FileAccess.Write)) { var buffer = new byte[CopyBufferSize]; int readBytes; while ((readBytes = stream.Read(buffer, 0, CopyBufferSize)) > 0) { fileStream.Write(buffer, 0, readBytes); } } } }