public static string Encrypt(string value) { Verify.ArgumentNotNullOrEmpty(value, nameof(value)); // Create a RijndaelManaged object // with the specified key and IV. using (var rima = new RijndaelManaged()) { rima.Key = _encryptionKey; rima.IV = RijndaelIV; // Create a decrytor to perform the stream transform. ICryptoTransform encryptor = rima.CreateEncryptor(); // Create the streams used for encryption. using (var msEncrypt = new MemoryStream()) { using (var csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)) using (var swEncrypt = new C1StreamWriter(csEncrypt)) { //Write all data to the stream. swEncrypt.Write(value); } // Return the encrypted bytes from the memory stream. return(ByteToHexString(msEncrypt.ToArray())); } } }
/// <summary> /// Replaces the all files content with some new content /// </summary> /// <param name="file"></param> /// <param name="newContent"></param> public static void SetNewContent(this IFile file, string newContent) { using (C1StreamWriter sw = new C1StreamWriter(GetNewWriteStream(file))) { sw.Write(newContent); } }
public List <T> AddNew <T>(IEnumerable <T> datas) where T : class, IData { List <T> result = new List <T>(); foreach (IData data in datas) { CheckInterface(data.GetType()); IFile file = (IFile)data; string filename = CreateSystemPath(Path.Combine(file.FolderPath, file.FileName)); FileSystemFile fileSystemFile = Activator.CreateInstance(_fileSystemFileTypeWithInterface) as FileSystemFile; fileSystemFile.SetDataSourceId(_context.CreateDataSourceId(new FileSystemFileDataId(filename), _fileInterfaceType)); fileSystemFile.FolderPath = file.FolderPath; fileSystemFile.FileName = file.FileName; fileSystemFile.SystemPath = filename; using (C1StreamReader streamReader = new C1StreamReader(file.GetReadStream())) { using (C1StreamWriter streamWriter = new C1StreamWriter(fileSystemFile.GetNewWriteStream())) { streamWriter.Write(streamReader.ReadToEnd()); } } FileSystemFileStreamManager.WriteFileToDisk(fileSystemFile); result.Add(fileSystemFile as T); } return(result); }
public static string Encrypt(string value) { Verify.ArgumentNotNullOrEmpty(value, "value"); // Declare the streams used // to encrypt to an in memory // array of bytes. MemoryStream msEncrypt = null; CryptoStream csEncrypt = null; C1StreamWriter swEncrypt = null; // Declare the RijndaelManaged object // used to encrypt the data. RijndaelManaged rima = null; try { // Create a RijndaelManaged object // with the specified key and IV. rima = new RijndaelManaged(); rima.Key = _encryptionKey; rima.IV = RijndaelIV; // Create a decrytor to perform the stream transform. ICryptoTransform encryptor = rima.CreateEncryptor(); // Create the streams used for encryption. msEncrypt = new MemoryStream(); csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write); swEncrypt = new C1StreamWriter(csEncrypt); //Write all data to the stream. swEncrypt.Write(value); } finally { if (swEncrypt != null) { swEncrypt.Close(); } if (csEncrypt != null) { csEncrypt.Close(); } if (msEncrypt != null) { msEncrypt.Close(); } if (rima != null) { rima.Clear(); } } // Return the encrypted bytes from the memory stream. return(ByteToHexString(msEncrypt.ToArray())); }
/// <exclude /> public static string GetDocumentAsString(this XDocument document) { Verify.ArgumentNotNull(document, "document"); using (var ms = new MemoryStream()) { using (var sw = new C1StreamWriter(ms)) { document.Save(sw); ms.Seek(0, SeekOrigin.Begin); using (var sr = new C1StreamReader(ms)) { return(sr.ReadToEnd()); } } } }
/// <exclude/> public override IEnumerable <XElement> Install() { Verify.IsNotNull(_contentToAdd, "FileModifyPackageFragmentInstaller has not been validated"); foreach (ContentToAdd content in _contentToAdd) { if (C1File.Exists(content.Path)) { using (C1StreamWriter sw = C1File.AppendText(content.Path)) { sw.Write(content.Content); sw.Close(); } } else { C1File.WriteAllText(content.Path, content.Content); } } return(new[] { this.Configuration.FirstOrDefault() }); }
public static void Initialize(Resources resources) { LoggingSettings section = null; if (ConfigurationServices.ConfigurationSource != null) { section = ConfigurationServices.ConfigurationSource.GetSection(LoggingSettings.SectionName) as LoggingSettings;; } if (section != null) { resources.Factory = new LogWriterFactory(ConfigurationServices.ConfigurationSource); resources.Writer = resources.Factory.Create(); } else { string path = Path.Combine(PathUtil.BaseDirectory, $"logging{Guid.NewGuid()}.config"); using (C1StreamWriter writer = new C1StreamWriter(path)) { Type type = typeof(LoggingService).Assembly .GetType("Composite.Plugins.Logging.LogTraceListeners.TcpLogTraceListener.TcpLogTraceListener", false); if ((type != null) && (RuntimeInformation.IsUnittest == false)) { #region config file writer.WriteLine(@"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <configSections> <section name=""loggingConfiguration"" type=""Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0"" /> </configSections> <loggingConfiguration name=""Logging Application Block"" tracingEnabled=""true"" defaultCategory=""General"" logWarningsWhenNoCategoriesMatch=""true""> <listeners> <add listenerDataType=""Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0"" traceOutputOptions=""None"" type=""Composite.Plugins.Logging.LogTraceListeners.TcpLogTraceListener.TcpLogTraceListener, Composite, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"" name=""Tcp Custom Trace Listener"" initializeData="""" formatter=""Text Formatter"" /> </listeners> <formatters> <add template=""Timestamp: {timestamp}
Message: {message}
Category: {category}
Priority: {priority}
EventId: {eventid}
Severity: {severity}
Title: {title}
Machine: {machine}
Application Domain: {appDomain}
Process Id: {processId}
Process Name: {processName}
Win32 Thread Id: {win32ThreadId}
Thread Name: {threadName}
Extended Properties: {dictionary({key} - {value}
)}"" type=""Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0"" name=""Text Formatter"" /> </formatters> <categorySources> <add switchValue=""All"" name=""General"" /> </categorySources> <specialSources> <allEvents switchValue=""All"" name=""All Events""> <listeners> <add name=""Tcp Custom Trace Listener"" /> </listeners> </allEvents> <notProcessed switchValue=""All"" name=""Unprocessed Category"" /> <errors switchValue=""All"" name=""Logging Errors & Warnings"" /> </specialSources> </loggingConfiguration> </configuration>"); #endregion } else { #region config file writer.WriteLine(@"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <configSections> <section name=""loggingConfiguration"" type=""Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0"" /> </configSections>s <loggingConfiguration name=""Logging Application Block"" tracingEnabled=""true"" defaultCategory=""General"" logWarningsWhenNoCategoriesMatch=""true""> <listeners> <add listenerDataType=""Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0"" traceOutputOptions=""None"" type=""Composite.Core.Logging.NullLogTraceListener, Composite, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"" name=""NullLogTraceListener"" initializeData="""" formatter=""Text Formatter"" /> </listeners> <formatters> <add template=""Timestamp: {timestamp}
Message: {message}
Category: {category}
Priority: {priority}
EventId: {eventid}
Severity: {severity}
Title:{title}
Machine: {machine}
Application Domain: {appDomain}
Process Id: {processId}
Process Name: {processName}
Win32 Thread Id: {win32ThreadId}
Thread Name: {threadName}
Extended Properties: {dictionary({key} - {value}
)}"" type=""Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0"" name=""Text Formatter"" /> </formatters> <categorySources> <add switchValue=""All"" name=""General"" /> </categorySources> <specialSources> <allEvents switchValue=""All"" name=""All Events""> <listeners> <add name=""NullLogTraceListener"" /> </listeners> </allEvents> <notProcessed switchValue=""All"" name=""Unprocessed Category"" /> <errors switchValue=""All"" name=""Logging Errors & Warnings"" /> </specialSources> </loggingConfiguration> </configuration>"); #endregion } } resources.Factory = new LogWriterFactory(new FileConfigurationSource(path)); resources.Writer = resources.Factory.Create(); } }