/// <summary> /// /// </summary> /// <returns></returns> public bool LoadKeyBindings(string filename = null) { if (filename == null) { filename = KeyBindingsFilename; } List <AppKeyBinding> keyBindings; keyBindings = JsonSerializationUtils.DeserializeFromFile(filename, typeof(List <AppKeyBinding>)) as List <AppKeyBinding>; if (keyBindings == null || keyBindings.Count < 1) { return(false); } foreach (var kb in keyBindings) { var keyBinding = KeyBindings.FirstOrDefault(binding => binding.CommandName == kb.CommandName); if (keyBinding == null) { continue; } keyBinding.Key = kb.Key; if (keyBinding.Command != null) { keyBinding.Command.KeyboardShortcut = kb.Key; } } return(true); }
/// <summary> /// /// </summary> /// <returns></returns> public bool LoadKeyBindings(string filename = null) { if (filename == null) { filename = KeyBindingsFilename; } List <AppKeyBinding> keyBindings; keyBindings = JsonSerializationUtils.DeserializeFromFile(filename, typeof(List <AppKeyBinding>)) as List <AppKeyBinding>; if (keyBindings == null || keyBindings.Count < 1) { return(false); } // TODO: Fix bug with multiple keybindings to the same Command - need Unique Identifier foreach (var kb in keyBindings) { var keyBinding = KeyBindings.FirstOrDefault(binding => binding.Id == kb.Id); if (keyBinding == null) { continue; } keyBinding.Key = kb.Key; if (keyBinding.Command != null) { keyBinding.Command.KeyboardShortcut = kb.Key; } } return(true); }
/// <summary> /// Retrieves results from various request files /// </summary> /// <returns></returns> public override List <HttpRequestData> GetResults() { if (FileCount < 1) { return(Results); } var list = new List <HttpRequestData>(); if (!EnsureFileExists(Path.Combine(TempFolderName, "WebSurgeRequests_" + FileCount + ".json"))) { return(null); } var files = Directory.GetFiles( Path.Combine(TempFolderName), "WebSurgeRequests_*.json", SearchOption.TopDirectoryOnly); foreach (var file in files) { if (!EnsureFileExists(file)) { return(null); } var reqs = JsonSerializationUtils.DeserializeFromFile(file, typeof(List <HttpRequestData>), true) as List <HttpRequestData>; if (reqs != null) { list.AddRange(reqs); } } list.AddRange(Results); return(list); }
public RequestCollection ImportFromFile(string collectionFilename) { var collection = JsonSerializationUtils.DeserializeFromFile(collectionFilename, typeof(PostmanCollection), false) as PostmanCollection; return(Import(collection)); }
/// <summary> /// Return /// </summary> /// <typeparam name="TAppConfig"></typeparam> /// <returns></returns> public override TAppConfig Read <TAppConfig>() { var result = JsonSerializationUtils.DeserializeFromFile(JsonConfigurationFile, typeof(TAppConfig)) as TAppConfig; if (result != null) { DecryptFields(result); } return(result); }
/// <summary> /// Reads configuration into the current instance of the config object passed in. /// </summary> /// <param name="config"></param> /// <returns></returns> public override bool Read(AppConfiguration config) { var newConfig = JsonSerializationUtils.DeserializeFromFile(JsonConfigurationFile, typeof(TAppConfiguration)) as TAppConfiguration; if (newConfig == null) { if (Write(config)) { return(true); } return(false); } DecryptFields(newConfig); DataUtils.CopyObjectData(newConfig, config, "Provider,ErrorMessage"); return(true); }
public bool Load(string filename = "~/LocalizationConfigurations.json") { if (filename.StartsWith("~/")) { filename = HttpContext.Current.Server.MapPath(filename); } if (!File.Exists(filename)) { return(false); } var config = JsonSerializationUtils.DeserializeFromFile(filename, typeof(ConfigurationEntry)) as List <ConfigurationEntry>; return(config != null); }
public void DeserializeFromFileTest() { string fname = "serialized.config"; var config = new AutoConfigFileConfiguration(); config.ApplicationName = "New App"; config.DebugMode = DebugModes.DeveloperErrorMessage; bool result = JsonSerializationUtils.SerializeToFile(config, fname, true, true); Assert.IsTrue(result); config = null; config = JsonSerializationUtils.DeserializeFromFile(fname, typeof(AutoConfigFileConfiguration)) as AutoConfigFileConfiguration; Assert.IsNotNull(config); Assert.IsTrue(config.ApplicationName == "New App"); Assert.IsTrue(config.DebugMode == DebugModes.DeveloperErrorMessage); }
/// <summary> /// Retrieves a list of addins from the addin repository. Note this list /// is retrieved in chunks - first the summary list is retrieved and the /// remaining data is filled in later from individual repos. /// </summary> /// <param name="addinList"></param> /// <returns></returns> public async Task <List <AddinItem> > GetAddinListAsync(List <AddinItem> addinList = null) { if (addinList == null) { addinList = await GetInitialAddinListAsync(); } if (addinList == null) { return(null); } //foreach (var ai in addinList) Parallel.ForEach(addinList, new ParallelOptions { MaxDegreeOfParallelism = 20 }, ai => { try { // not using async here so we can wait for final list result // before returning Debug.WriteLine(ai.gitVersionUrl); var dl = HttpUtils.JsonRequest <AddinItem>(new HttpRequestSettings { Url = ai.gitVersionUrl }); DataUtils.CopyObjectData(dl, ai, "id,name,gitVersionUrl,gitUrl"); string addinFolder = mmApp.Configuration.AddinsFolder; if (Directory.Exists(Path.Combine(addinFolder, ai.id)) || Directory.Exists(Path.Combine(addinFolder, "Install", ai.id))) { ai.isInstalled = true; } try { var versionFile = Path.Combine(addinFolder, ai.id, "version.json"); if (File.Exists(versionFile)) { var addinItem = JsonSerializationUtils.DeserializeFromFile( versionFile, typeof(AddinItem), false) as AddinItem; ai.installedVersion = addinItem.version; if (addinItem != null && addinItem.version.CompareTo(ai.version) < 0) { ai.updateAvailable = true; } } } catch { } if (File.Exists(".\\Addins\\Install\\" + ai.id + ".delete")) { ai.isInstalled = false; } } catch (Exception ex) { mmApp.Log($"Addin {ai.name} version failed", ex); } }); return(addinList .Where(ai => ai.updated > new DateTime(2016, 1, 1)) .OrderBy(ai => ai.isInstalled ? 0 : 1) .ThenByDescending(ai => ai.updated) .ToList()); }
public static List <UserEntry> LoadUsersFromJsonFile(string filename) { object result = JsonSerializationUtils.DeserializeFromFile(filename, typeof(List <UserEntry>), throwExceptions: true); return(result as List <UserEntry>); }
public bool ImportHbp(string inputFile, string outputFolder = null, string kavaDocsAddinFolder = null) { if (kavaDocsAddinFolder == null) { kavaDocsAddinFolder = KavaDocsConfiguration.Current.HomeFolder; } if (outputFolder == null) { outputFolder = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(inputFile)); } if (!Directory.Exists(outputFolder)) { Directory.CreateDirectory(outputFolder); } if (!Directory.Exists(Path.Combine(outputFolder, "images"))) { Directory.CreateDirectory(Path.Combine(outputFolder, "images")); } if (!string.IsNullOrEmpty(kavaDocsAddinFolder)) { FileUtils.CopyDirectory(Path.Combine(kavaDocsAddinFolder, "ProjectTemplates"), Path.Combine(outputFolder, "_kavadocs")); } else { if (!Directory.Exists(Path.Combine(outputFolder, "_kavadocs"))) { Directory.CreateDirectory(Path.Combine(outputFolder, "_kavadocs")); } } var oldTopics = JsonSerializationUtils.DeserializeFromFile(inputFile, typeof(List <HbpTopic>)) as List <HbpTopic>; var project = new DocProject(Path.Combine(outputFolder, "_toc.json")); var newTopics = new ObservableCollection <DocTopic>(); project.Topics = newTopics; foreach (var oldTopic in oldTopics) { if (oldTopic.pk == "CONFIG") { continue; } var newTopic = new DocTopic(project) { Id = oldTopic.pk, ParentId = oldTopic.parentpk, Title = oldTopic.topic, DisplayType = oldTopic.type?.ToLower(), Keywords = oldTopic.keywords, Remarks = oldTopic.remarks, Example = oldTopic.example, SeeAlso = oldTopic.seealso, SortOrder = oldTopic.sortorder, IsLink = oldTopic.external, Incomplete = oldTopic.followup, HelpId = oldTopic.helpid.ToString(), ClassInfo = new ClassInfo() { Syntax = string.IsNullOrEmpty(oldTopic.syntax) ? null : oldTopic.syntax, Classname = string.IsNullOrEmpty(oldTopic._class) ? null : oldTopic._class, MemberName = string.IsNullOrEmpty(oldTopic.method) ? null : oldTopic.method, Parameters = string.IsNullOrEmpty(oldTopic.parameters) ? null : oldTopic.parameters, Returns = string.IsNullOrEmpty(oldTopic.returns) ? null : oldTopic.returns, Scope = string.IsNullOrEmpty(oldTopic.scope) ? null : oldTopic.scope, Implements = string.IsNullOrEmpty(oldTopic.implements) ? null : oldTopic.implements, Inherits = string.IsNullOrEmpty(oldTopic.inherits) ? null : oldTopic.inherits, InheritanceTree = string.IsNullOrEmpty(oldTopic.inh_tree) ? null : oldTopic.inh_tree, Signature = string.IsNullOrEmpty(oldTopic.signature) ? null : oldTopic.signature, Assembly = oldTopic.assembly, Contract = oldTopic.contract, Namespace = oldTopic._namespace, Exceptions = oldTopic.exceptions, }, }; newTopic.Project = project; int format = oldTopic.viewmode; newTopic.Type = format == 2 ? TopicBodyFormats.Markdown : TopicBodyFormats.HelpBuilder; newTopic.SetBodyWithoutSavingTopicFile(oldTopic.body); // Properties have to be parsed out // BodyFormats project.Topics.Add(newTopic); } if (!Directory.Exists(outputFolder)) { Directory.CreateDirectory(outputFolder); } // Copy images string sourceFolder = Path.GetDirectoryName(inputFile); KavaUtils.CopyDirectory(Path.Combine(sourceFolder, "Images"), Path.Combine(outputFolder, "images")); project.Title = Title; project.Owner = Owner; project.GetTopicTreeFromFlatList(project.Topics); // fix up image links relative to hierarchy project.WalkTopicsHierarchy(project.Topics, (topic, proj) => { string find = "](images/"; if (!topic.Body.Contains(find) || topic.Parent == null) { return; } int foldersDown = 0; var parent = topic.Parent; while (parent != null) { foldersDown++; parent = parent.Parent; } if (foldersDown < 1) { return; } string replace = "](" + new StringBuilder().Insert(0, "../", foldersDown) + "images/"; topic.Body = topic.Body.Replace(find, replace); }); return(project.SaveProject(Path.Combine(outputFolder, "_toc.json"))); }