public void AllTest() { IFile textFile = FactoryProvider.getFactory(PersitenseTypes.FILE).Create(FileTypes.txt); Student newStudent = textFile.Create(student); Student newStudent2 = textFile.Create(student2); Assert.AreEqual(newStudent.Name, textFile.All()[0].Name); Assert.AreEqual(newStudent2.Name, textFile.All()[1].Name); }
protected IEnumerator UpdateAssetFromUrl(UpdateFile needUpdateLst, string downloadUrl) { updateNum = 0; needUpdateNum = needUpdateLst.Count; string savePath, downloadPath, saveDir; base.Event.Trigger(AutoUpdateEvents.ON_UPDATE_FILE_START); foreach (UpdateFileField field in needUpdateLst) { downloadPath = downloadUrl + field.Path; savePath = Env.AssetPath + field.Path; saveDir = savePath.Substring(0, savePath.LastIndexOf(Path.AltDirectorySeparatorChar)); updateNum++; base.Event.Trigger(AutoUpdateEvents.ON_UPDATE_FILE_ACTION); using (UnityWebRequest request = UnityWebRequest.Get(downloadPath)) { yield return(request.Send()); if (request.isError || request.responseCode != 200) { base.Event.Trigger(AutoUpdateEvents.ON_UPDATE_FILE_FAILD); yield break; } Disk.Directory(saveDir, PathTypes.Absolute).Create(); IFile saveFile = Disk.File(savePath, PathTypes.Absolute); saveFile.Create(request.downloadHandler.data); } } base.Event.Trigger(AutoUpdateEvents.ON_UPDATE_FILE_END); }
public async Task <bool> LoadGroupFile(GroupModel model, string email) { int userId = _userRepo.GetElementByEmail(email).Id; string path = null; string error_message = null; if (model.File != null) { string expansion = model.File.FileName.Substring(model.File.FileName.LastIndexOf(".")); path = "/files/" + Guid.NewGuid() + expansion; using (var fileStream = new FileStream(_appEnviron.WebRootPath + path, FileMode.Create)) { await model.File.CopyToAsync(fileStream); } DateTime thisDay = DateTime.Today; _filesRepo.Create(new Files { Name = model.File.FileName, Path = path, DateOfLoad = thisDay, Owner = userId, GroupId = model.Id }); _filesRepo.Save(); return(true); } else { return(false); } }
public void CreateTest() { IFile XmlFile = FactoryProvider.getFactory(PersitenseTypes.FILE).Create(FileTypes.xml); Student addedStudent = XmlFile.Create(student); Assert.AreEqual(student, addedStudent); }
public void Save(string path, UpdateFile updateFile) { IFile file = Disk.File(path + Path.AltDirectorySeparatorChar + UpdateFileStore.FILE_NAME); file.Delete(); file.Create(updateFile.Data.ToByte()); }
public void DeleteTest() { IFile textFile = FactoryProvider.getFactory(PersitenseTypes.FILE).Create(FileTypes.txt); Student newStudent = textFile.Create(student); Assert.IsTrue(textFile.Delete(newStudent)); }
/// <summary> /// Write the given value (<paramref name="a_value"/>) as an INI setting in the given section /// (<paramref name="a_section"/>) with the given key (<paramref name="a_key"/>) to this file. /// </summary> /// <param name="a_section">Setting section.</param> /// <param name="a_key">Setting key.</param> /// <param name="a_value">New value of setting.</param> private void WriteIniSetting(string a_section, string a_key, string a_value) { if (!_source.Exists) { _source.Create(""); } WritePrivateProfileString(a_section, a_key, a_value, _source.Path); }
public void CreatesTest() { IFile textFile = FactoryProvider.getFactory(PersitenseTypes.FILE).Create(FileTypes.txt); Student newStudent = textFile.Create(student); Assert.AreEqual(student, newStudent); }
/// <inheritdoc cref="File.WriteAllBytes" /> public static void WriteAllBytes([NotNull] this IFile file, [NotNull] string path, [NotNull] byte[] bytes) { Guard.NotNull(file, nameof(file)); Guard.NotNull(path, nameof(path)); Guard.NotNull(bytes, nameof(bytes)); using (IFileStream stream = file.Create(path)) { stream.Write(bytes, 0, bytes.Length); } }
public async Task <IActionResult> Create([Bind("Id,Name,Path,DateOfLoad,Owner,GroupId")] Files files) { if (ModelState.IsValid) { _db.Create(files); _db.Save(); return(RedirectToAction(nameof(Index))); } ViewData["GroupId"] = new SelectList(_db.GetGroupDescriptions(), "Id", "Name", files.GroupId); ViewData["Owner"] = new SelectList(_db.GetUserDescriptions(), "Id", "Email", files.Owner); return(View(files)); }
public void Execute() { var dir = App.BaseMigrationsDirectory + @"\" + _args.Name + @"\"; if (_ds.Exists(dir)) { throw new GatorException("Warning -- A migration with that name already exists - exiting"); } _ds.Create(dir); var cfg = new MigrationConfig { created = DateTime.Now, versionNumber = "0.0.0" }; _fs.CreateWithContent(dir + "version.json", JsonConvert.SerializeObject(cfg, Formatting.Indented, new IsoDateTimeConverter())); _fs.Create(dir + "up.sql"); _fs.Create(dir + "down.sql"); }
/// <inheritdoc cref="File.WriteAllText(string,string,Encoding)" /> public static void WriteAllText([NotNull] this IFile file, [NotNull] string path, [NotNull] string contents, [CanBeNull] Encoding encoding = null) { Guard.NotNull(file, nameof(file)); Guard.NotNull(path, nameof(path)); Guard.NotNull(contents, nameof(contents)); using (IFileStream stream = file.Create(path)) { using (StreamWriter writer = CreateWriter(stream, encoding)) { writer.Write(contents); } } }
/// <summary> /// 保存ini文件 /// </summary> /// <returns></returns> public void Save() { StringBuilder data = new StringBuilder(); foreach (var dict in iniDict) { data.AppendLine("[" + dict.Key + "]"); foreach (var kv in dict.Value) { data.AppendLine(kv.Key + "=" + kv.Value); } } file.Delete(); file.Create(data.ToString().ToByte()); }
protected override Stream DoGetOutputStream(string encoding, FileMode mode, FileShare sharing) { IFile file; file = this.tempFileSystem.ResolveFile(GenerateName()); switch (mode) { case FileMode.Truncate: file.Create(); break; } return(new ShadowOutputStream(file.GetContent().GetOutputStream(encoding, sharing), this.shadowFile.ShadowedFile, file)); }
protected IEnumerator UpdateAssetFromUrl(UpdateFile needUpdateLst, string downloadUrl) { string savePath, downloadPath, saveDir; int i = 0; string[] updatePath = new string[needUpdateLst.Count]; foreach (UpdateFileField field in needUpdateLst) { updatePath[i++] = field.Path; } App.Trigger(this).SetEventName(AutoUpdateEvents.ON_UPDATE_FILE_START) .SetEventLevel(EventLevel.Global) .Trigger(new UpdateFileStartEventArgs(updatePath)); for (i = 0; i < updatePath.Length; i++) { downloadPath = downloadUrl + Path.AltDirectorySeparatorChar + updatePath[i]; savePath = Env.AssetPath + Path.AltDirectorySeparatorChar + updatePath[i]; saveDir = savePath.Substring(0, savePath.LastIndexOf(Path.AltDirectorySeparatorChar)); using (UnityWebRequest request = UnityWebRequest.Get(downloadPath)) { App.Trigger(this).SetEventName(AutoUpdateEvents.ON_UPDATE_FILE_ACTION) .SetEventLevel(EventLevel.Global) .Trigger(new UpdateFileActionEventArgs(updatePath[i], request)); yield return(request.Send()); if (request.isError || request.responseCode != 200) { App.Trigger(this).SetEventName(AutoUpdateEvents.ON_UPDATE_FILE_FAILD) .SetEventLevel(EventLevel.Global) .Trigger(); yield break; } Disk.Directory(saveDir, PathTypes.Absolute).Create(); IFile saveFile = Disk.File(savePath, PathTypes.Absolute); saveFile.Create(request.downloadHandler.data); } } App.Trigger(this).SetEventName(AutoUpdateEvents.ON_UPDATE_FILE_END) .SetEventLevel(EventLevel.Global) .Trigger(); }
/// <inheritdoc cref="File.WriteAllLines(string,IEnumerable{string},Encoding)" /> public static void WriteAllLines([NotNull] this IFile file, [NotNull] string path, [NotNull][ItemNotNull] IEnumerable <string> contents, [CanBeNull] Encoding encoding = null) { Guard.NotNull(file, nameof(file)); Guard.NotNull(path, nameof(path)); Guard.NotNull(contents, nameof(contents)); using (IFileStream stream = file.Create(path)) { using (StreamWriter writer = CreateWriter(stream, encoding)) { foreach (string line in contents) { writer.WriteLine(line); } } } }
public RootModelFactoryTest() { root = new MockDirectory("c:\\projdirr"); projFile = root.File("proj.csproj"); projFile.Create(ProjText); var prop = root.SubDirectory("Properties"); prop.Create(); pubProfiles = prop.SubDirectory("PublishProfiles"); pubProfiles.Create(); pubXmlFile = pubProfiles.File("Publish.pubxml"); pubXmlFile.Create(PubXmlText); expander.Setup(i => i.Expand(It.IsAny <String>())) .Returns((string s) => s.Replace("%APPDATA%", "C:\\Profile")); secretFile = MockSecretFile("5e7f3d51-4b7a-41f8-a32a-8f6c11c29274", SecretText); pubSecretFile = MockSecretFile("thisisthesecretkey", PubSecretText); sut = new RootModelFactory(expander.Object); }
/// <summary> /// 加载一个ini文件 /// </summary> /// <param name="file">文件</param> /// <returns>ini结果集</returns> public IIniResult Load(IFile file) { if (!file.Exists) { throw new IOException("file is not exists:" + file.FullName); } if (file.Extension != ".ini") { throw new ArgumentException("ini file path is invalid", "file"); } var result = new IniResult(file.Read()); result.OnSave += (data) => { file.Delete(); file.Create(Encoding.UTF8.GetBytes(data)); }; return(result); }
/// <summary> /// 加载一个INI文件 /// </summary> /// <param name="file">文件</param> /// <returns></returns> public IINIResult Load(IFile file) { if (!file.Exists) { throw new IOException("file is not exists:" + file.FullName); } if (file.Extension != ".ini") { throw new ArgumentException("ini file path is invalid", "path"); } var result = new INIResult(file.Read()); result.SetSaveCallback((data) => { file.Delete(); file.Create(data.ToByte()); }); return(result); }
internal static void Install(string path) { if (File.Exists(path)) { string tempFolder = Path.Combine(Path.GetTempPath(), "wox\\plugins"); if (Directory.Exists(tempFolder)) { Directory.Delete(tempFolder, true); } UnZip(path, tempFolder, true); string iniPath = Path.Combine(tempFolder, "plugin.json"); if (!File.Exists(iniPath)) { MessageBox.Show("Install failed: plugin config is missing"); return; } PluginMetadata plugin = GetMetadataFromJson(tempFolder); if (plugin?.Name == null) { MessageBox.Show("Install failed: plugin config is invalid"); return; } string pluginFolderPath = Constant.PluginsDirectory; // Using Ordinal since this is part of a path string newPluginName = plugin.Name .Replace("/", "_", StringComparison.Ordinal) .Replace("\\", "_", StringComparison.Ordinal) .Replace(":", "_", StringComparison.Ordinal) .Replace("<", "_", StringComparison.Ordinal) .Replace(">", "_", StringComparison.Ordinal) .Replace("?", "_", StringComparison.Ordinal) .Replace("*", "_", StringComparison.Ordinal) .Replace("|", "_", StringComparison.Ordinal) + "-" + Guid.NewGuid(); string newPluginPath = Path.Combine(pluginFolderPath, newPluginName); string content = $"Do you want to install following plugin?{Environment.NewLine}{Environment.NewLine}" + $"Name: {plugin.Name}{Environment.NewLine}" + $"Version: {plugin.Version}{Environment.NewLine}" + $"Author: {plugin.Author}"; PluginPair existingPlugin = PluginManager.GetPluginForId(plugin.ID); if (existingPlugin != null) { content = $"Do you want to update following plugin?{Environment.NewLine}{Environment.NewLine}" + $"Name: {plugin.Name}{Environment.NewLine}" + $"Old Version: {existingPlugin.Metadata.Version}" + $"{Environment.NewLine}New Version: {plugin.Version}" + $"{Environment.NewLine}Author: {plugin.Author}"; } var result = MessageBox.Show(content, "Install plugin", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { if (existingPlugin != null && Directory.Exists(existingPlugin.Metadata.PluginDirectory)) { // when plugin is in use, we can't delete them. That's why we need to make plugin folder a random name File.Create(Path.Combine(existingPlugin.Metadata.PluginDirectory, "NeedDelete.txt")).Close(); } UnZip(path, newPluginPath, true); Directory.Delete(tempFolder, true); // existing plugins could be loaded by the application, // if we try to delete those kind of plugins, we will get a error that indicate the // file is been used now. // current solution is to restart wox. Ugly. // if (MainWindow.Initialized) // { // Plugins.Initialize(); // } if (MessageBox.Show($"You have installed plugin {plugin.Name} successfully.{Environment.NewLine} Restart Wox to take effect?", "Install plugin", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { PluginManager.API.RestartApp(); } } } }
public static void WriteAllBytes(this IFile file, byte[] bytes) { using var write = file.Create(); write.Write(bytes, 0, bytes.Length); }
protected override Stream DoGetOutputStream(string encoding, FileMode mode, FileShare sharing) { IFile file; file = this.tempFileSystem.ResolveFile(GenerateName()); switch (mode) { case FileMode.Truncate: file.Create(); break; } return new ShadowOutputStream(file.GetContent().GetOutputStream(encoding, sharing), this.shadowFile.ShadowedFile, file); }