static void Main(string[] args) { var sourceList = new Item[10000]; for (int i = 0; i < sourceList.Length; i++) { sourceList[i] = new Item { IntValue = i, StringValue = i.ToString() }; } var mySerializer = new YamlSerializer(); var myDeserializer = new YamlDeserializer(); var defaultSerializer = new Serializer(); var defaultDeserializer = new Deserializer(); var watch = new Stopwatch(); while (true) { var sw = new StringWriter(); watch.Restart(); mySerializer.Serialize(sw, sourceList); var stime = watch.ElapsedMilliseconds; watch.Restart(); var list = myDeserializer.Deserialize<List<Item>>(new StringReader(sw.ToString())); var dtime = watch.ElapsedMilliseconds; Console.WriteLine("My - Serialize time: {0}ms, Deserialize time: {1}ms", stime, dtime); sw = new StringWriter(); watch.Restart(); defaultSerializer.Serialize(sw, sourceList); stime = watch.ElapsedMilliseconds; watch.Restart(); list = defaultDeserializer.Deserialize<List<Item>>(new StringReader(sw.ToString())); dtime = watch.ElapsedMilliseconds; Console.WriteLine("Default - Serialize time: {0}ms, Deserialize time: {1}ms", stime, dtime); } }
private static List <RepoTable> LoadRepositoryTables() { using (var reader = File.OpenText(REPOSITORY_TABLES_FILE)) { IDeserializer deserializer = YamlDeserializer.Create(); return(deserializer.Deserialize <List <RepoTable> >(reader)); } }
public static RepositoryConfiguration Get(string configurationFilePath) { var rawConfigurationYaml = File.ReadAllText(configurationFilePath); var repositoryConfiguration = YamlDeserializer.ToObject <RepositoryConfiguration>(rawConfigurationYaml); return(repositoryConfiguration); }
public void TestDeleteBranch() { var obj = YamlDeserializer.KDTObjects(GetFilePath.GetPath(KDTFilePathDelete)); foreach (var item in obj.Action) { KeywordDrivenTesting.PerformAction(item.name, Client, item.value, StatusCode.NoContent, _newBranch); } }
public void TestAddFile() { var obj = YamlDeserializer.DDTObjects(GetFilePath.GetPath(DDTFilePath)); foreach (var item in obj.Items) { UploadFileToRepo(item.FileName, item.Branch, item.Content, item.CommitMessage, Method.POST, StatusCode.Created.ToString()); } }
public void TestDeleteFileFromRepository() { var obj = YamlDeserializer.DDTObjects(GetFilePath.GetPath(DDTFilePath)); foreach (var item in obj.Items) { UploadFileToRepo(item.FileName, item.Branch, item.Content, item.CommitMessage, Method.DELETE, StatusCode.NoContent.ToString()); } }
public Validator(MarkdownFileHandler fileHandler, YamlDeserializer deserializer) { MarkdownFileHandler = fileHandler; Deserializer = deserializer; PivotIdsNotInPivotGroupDefinition = new HashSet <string>(); PivotIdsNotInMarkdownFile = new HashSet <string>(); PassesValidation = true; DefinitionForUsedPivotGroup = true; }
/// <summary> /// Tries to load the default process names from the process names yaml file. /// Since failing to load these disables parsing any processs, this /// method throws its errors /// </summary> /// <returns></returns> internal static List <ProcessData> LoadProcessData() { // since PaletteInsightAgent always sets the current directory to its location, // we should always be in the correct folder for this to work using (var reader = File.OpenText(PROCESSES_DEFAULT_FILE)) { IDeserializer deserializer = YamlDeserializer.Create(); return(deserializer.Deserialize <List <ProcessData> >(reader)); } }
/// <summary> /// Tries to load the default log folders from the log folders yaml file. /// Since failing to load these disables parsing any logs, this /// method throws its errors /// </summary> /// <returns></returns> internal static List <LogFolder> LoadDefaultLogFolders() { // load the defaults from the application // since PaletteInsightAgent always sets the current directory to its location, // we should always be in the correct folder for this to work using (var reader = File.OpenText(LOGFOLDER_DEFAULTS_FILE)) { IDeserializer deserializer = YamlDeserializer.Create(); return(deserializer.Deserialize <List <LogFolder> >(reader)); } }
public static ICollection <ICounter> Load(string pathToConfig) { // load the defaults from the application // since PaletteInsightAgent always sets the current directory to its location, // we should always be in the correct folder for this to work using (var reader = File.OpenText(pathToConfig)) { IDeserializer deserializer = YamlDeserializer.Create(); var counterConfig = deserializer.Deserialize <List <Counters.Config> >(reader); return(Counters.Config.ToICounterList(counterConfig)); } }
public void check_it_converts_sensibly() { var serializer = new YamlSerializer(_mappingRegistry); var deserializer = new YamlDeserializer(_mappingRegistry, _typeCreator); var expectedModel = SerializationTestHelper.GeneratePopulatedModel(); var data = serializer.Serialize(expectedModel); _testOutputHelper.WriteLine("Outputted Yaml: "); _testOutputHelper.WriteLine(data.AsString); var actualModel = deserializer.Deserialize <ComplexModel>(data); SerializationTestHelper.AssertPopulatedData(expectedModel, actualModel); }
private void Awake() { if (inputManager == null) { throw new ANE(nameof(inputManager)); } if (gameView == null) { throw new ANE(nameof(gameView)); } var contentPath = Path.Combine(Application.dataPath, "Content"); var gameContent = YamlDeserializer.Deserialize(contentPath); game = new Game(gameContent); inputManager.Game = game; }
public static PaletteInsightConfiguration LoadConfigFile(string filename) { try { // deserialize the config using (var reader = File.OpenText(filename)) { IDeserializer deserializer = YamlDeserializer.Create(); var config = deserializer.Deserialize <PaletteInsightConfiguration>(reader); return(config); } } catch (Exception e) { Log.Fatal("Error during cofiguration loading: {0} -- {1}", filename, e); return(null); } }
public void Test_Basic_4() { var s = new YamlSerializer(); var sw = new StringWriter(); s.Serialize(sw, new Entity { IntValue = 1, StringValue = "1.23", BoolValue = true }); Assert.Equal(@"IntValue: 1 StringValue: ""1.23"" BoolValue: true ", sw.ToString()); var d = new YamlDeserializer(); var obj = d.Deserialize<Entity>(new StringReader(sw.ToString())); Assert.Equal(1, obj.IntValue); Assert.Equal("1.23", obj.StringValue); Assert.Equal(true, obj.BoolValue); var dict = d.Deserialize<Dictionary<string, object>>(new StringReader(sw.ToString())); Assert.Equal(1, dict["IntValue"]); Assert.Equal("1.23", dict["StringValue"]); Assert.Equal(true, dict["BoolValue"]); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddMvc(); var deserializer = new YamlDeserializer(); var settings = deserializer.DeserializeConfiguration <Settings>(); settings.DynamicObjects.AddDefaultFields(); var objectGenerator = new ObjectGenerator(); objectGenerator.CreateObjects(settings.DynamicObjects); services.AddAllServices(settings); var entityTypes = CustomTypeBuilder.GetAllCustomTypes(); var schemaTypes = new List <Type>(); foreach (var type in entityTypes) { IServiceProvider serviceProvider = services.BuildServiceProvider(); var service = serviceProvider.GetRequiredService <DynamicObjectService>(); var schemaType = Activator.CreateInstance(typeof(DynamicObjectType <>).MakeGenericType(type), new object[] { service }).GetType(); schemaTypes.Add(schemaType); services.AddSingleton(schemaType); } IServiceProvider schemaServiceProvider = services.BuildServiceProvider(); var schemaGenerator = new SchemaGenerator(schemaServiceProvider); var schema = schemaGenerator.CreateSchema(schemaTypes.ToArray()); SchemaPrinter printer = new SchemaPrinter(schema); string wat = printer.Print(); services.AddSingleton <IDocumentExecuter, DocumentExecuter>(); services.AddSingleton <ISchema>(schema); }
private static T ResolveContent <T>(T item, Func <T, T> itemBuilder) where T : IOverwriteDocumentViewModel { if (itemBuilder != null) { item = itemBuilder(item); } using (var sw = new StringWriter()) { YamlUtility.Serialize(sw, item); using (var sr = new StringReader(sw.ToString())) { var serializer = new YamlDeserializer(ignoreUnmatched: true); var placeholderValueDeserializer = new PlaceholderValueDeserializer(serializer.ValueDeserializer, item.Conceptual); item = serializer.Deserialize <T>(sr, placeholderValueDeserializer); if (placeholderValueDeserializer.ContainPlaceholder) { item.Conceptual = null; } } } return(item); }
public PrValidator(string pathToMasterFile, string pathToTreeFile) { MasterFile = YamlDeserializer.DeserializeYamlToSearchable(pathToMasterFile); TreeFile = YamlDeserializer.DeserializeYamlToSearchable(pathToTreeFile); }
public void RecursiveCrawlFiles(YamlDeserializer deserializer) { foreach (string path in Directory.EnumerateFiles(this._startDir, "*.md", SearchOption.AllDirectories)) { var fileHandler = new MarkdownFileHandler(path); fileHandler.ReadMarkdownLines(); if (fileHandler.HasZonePivots) { // do validation var validator = new Validator(fileHandler, deserializer); validator.RunBasicMembershipValidation(); if (validator.PassesValidation) { Console.Write($"{fileHandler.FilePath}: "); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Green; Console.Write("PASS"); Console.ResetColor(); Console.WriteLine(); } else { Console.Write($"{fileHandler.FilePath}: "); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Red; Console.Write("FAIL"); Console.ResetColor(); Console.WriteLine(); Console.WriteLine(); if (!validator.DefinitionForUsedPivotGroup) { Console.Write(" The pivot group "); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write($"{validator.MarkdownFileHandler.ZonePivotGroupId}"); Console.ResetColor(); Console.Write(" is not defined in the zone definitions .yml file."); Console.WriteLine(); Console.WriteLine(); } else { if (validator.PivotIdsNotInPivotGroupDefinition.Count > 0) { foreach (string id in validator.PivotIdsNotInPivotGroupDefinition) { Console.Write(" The zone-pivot id "); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Cyan; Console.Write($"{id}"); Console.ResetColor(); Console.Write(" is not defined in the pivot-group "); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write($"{validator.MarkdownFileHandler.ZonePivotGroupId}."); Console.ResetColor(); Console.WriteLine(); } Console.WriteLine(); } if (validator.PivotIdsNotInMarkdownFile.Count > 0) { foreach (string id in validator.PivotIdsNotInMarkdownFile) { Console.Write(" The zone-pivot id "); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Cyan; Console.Write($"{id}"); Console.ResetColor(); Console.Write(" is defined in the pivot-group "); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write($"{validator.MarkdownFileHandler.ZonePivotGroupId}"); Console.ResetColor(); Console.Write(", but not used in "); string pathStr = validator.MarkdownFileHandler.FilePath; pathStr = pathStr.Substring(pathStr.LastIndexOf("\\") + 1); Console.Write($"{pathStr}."); Console.WriteLine(); } Console.WriteLine(); } } } } } }
/// <summary> /// Deserializes the YAML to the specified .NET type. /// </summary> /// <typeparam name="T">The type of the object to deserialize to.</typeparam> /// <param name="value">The YAML to deserialize.</param> /// <returns>The deserialized object from the YAML string.</returns> public static T[] DeserializeObject <T>(string value) where T : class, new() { var yamlDeserializer = new YamlDeserializer(); return(yamlDeserializer.Parse <T>(value)); }
public Task RunAsync(BuildContext context) { var config = context.GetSharedObject(Constants.Config) as ConfigModel; if (config == null) { throw new ApplicationException(string.Format("Key: {0} doesn't exist in build context", Constants.Config)); } var mappingConfig = config.ServiceMappingConfig; if (mappingConfig == null) { return(Task.FromResult(0)); } string outputPath = mappingConfig.OutputPath; var articlesDict = context.GetSharedObject(Constants.ArticleItemYamlDict) as ConcurrentDictionary <string, ArticleItemYaml>; var newservices = (from article in articlesDict.Values where article.Type == MemberType.Namespace let serviceCategory = Find(mappingConfig.Mappings, FormatPath(article.Source.Path)) where serviceCategory != null group article.Uid by serviceCategory into g select g ).ToDictionary(g => g.Key, g => g.ToList()); ServiceMappingItem other = new ServiceMappingItem { name = "Other", landingPageType = LandingPageTypeService, uid = "azure.java.sdk.landingpage.services.other", children = new List <string> { "*" }, }; Dictionary <string, string> hrefMapping = new Dictionary <string, string>(); if (File.Exists(outputPath)) { using (var reader = new StreamReader(outputPath)) { var oldMapping = new YamlDeserializer(ignoreUnmatched: true).Deserialize <ServiceMapping>(reader); foreach (var m in oldMapping[0].items) { if (m.name == "Other") { other = m; continue; } hrefMapping[m.name] = m.href; foreach (var c in m.items ?? Enumerable.Empty <ServiceMappingItem>()) { var sc = new ServiceCategory { Service = m.name, Category = c.name }; Merge(newservices, sc, c.children?.ToList() ?? new List <string>()); hrefMapping[GetKey(m.name, c.name)] = c.href; } } } } var services = (from item in newservices group item by item.Key.Service into g select new { Service = g.Key, Items = (from v in g group v.Value by v.Key.Category into g0 select new { Category = g0.Key, Uids = g0.SelectMany(i => i).OrderBy(i => i).Distinct().ToList() }).ToList(), }).ToDictionary(p => p.Service, p => p.Items); var mapping = new ServiceMapping() { new ServiceMappingItem() { uid = "azure.java.sdk.landingpage.reference", name = "Reference", landingPageType = "Root", items = new ServiceMapping((from pair in services let service = pair.Key let hrefAndType = GetHrefAndType(hrefMapping, service) select new ServiceMappingItem() { name = service, href = hrefAndType.Item1, landingPageType = hrefAndType.Item2, uid = "azure.java.sdk.landingpage.services." + FormatUid(service), items = new ServiceMapping(from item in pair.Value let category = item.Category let chrefAndType = GetHrefAndType(hrefMapping, GetKey(service, category)) select new ServiceMappingItem() { name = item.Category, href = chrefAndType.Item1, landingPageType = chrefAndType.Item2, uid = "azure.java.sdk.landingpage.services." + FormatUid(service) + "." + category, children = item.Uids.ToList() }) }).OrderBy(s => s.name)) } }; mapping[0].items.Add(other); using (var writer = new StreamWriter(outputPath)) { new YamlSerializer().Serialize(writer, mapping); } return(Task.FromResult(0)); }
public static Workgroup GetRepoFromWorkgroupYaml(string workgroupYmlPath, bool preferPassiveRepo) { if (workgroupYmlPath == null) { Log.Error("Path for workgroup.yml must not be null while reading configs!"); return(null); } try { // Get basic info from workgroup yml. Everything else from connections.yml IDeserializer deserializer = YamlDeserializer.Create(); Workgroup workgroup = null; using (var workgroupFile = File.OpenText(workgroupYmlPath)) { workgroup = deserializer.Deserialize <Workgroup>(workgroupFile); using (var connectionsFile = File.OpenText(workgroup.ConnectionsFile)) { workgroup.Connection = deserializer.Deserialize <TableauConnectionInfo>(connectionsFile); // workgroup.Connection.Host always contains the active repo if (preferPassiveRepo) { if (workgroup.PgHost0 != null && workgroup.PgHost1 != null) { // Use passive repo if possible/exists if (workgroup.Connection.Host != workgroup.PgHost0) { workgroup.Connection.Host = workgroup.PgHost0; workgroup.Connection.Port = workgroup.PgPort0; } else { workgroup.Connection.Host = workgroup.PgHost1; workgroup.Connection.Port = workgroup.PgPort1; } Log.Info("Based on workgroup.yml, passive repository host is: '{0}' with port: '{1}'", workgroup.Connection.Host, workgroup.Connection.Port); } else { Log.Info("Passive repo is preferred as target Tableau repo, but '{0}' does not contain passive repo node information", workgroupYmlPath); } } else { Log.Info("Active Tableau repo is configured to be the target repo"); } } if (!IsValidRepoData(workgroup)) { return(null); } } return(workgroup); } catch (Exception e) { Log.Error(e, "Error while trying to load and parse YAML config from '{0}' Exception: ", workgroupYmlPath); } return(null); }