/// <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 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())); } } }
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 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() }); }