Exemple #1
0
        protected static Item ParseYamlMarkdown(string yamlmd)
        {
            var builder = new DeserializerBuilder();

            foreach (var mapping in ClassMapping)
            {
                builder = builder.WithTagMapping($"!{mapping.Key}", mapping.Value);
            }
            var yamlDeserializer = builder
                                   .WithNamingConvention(PascalCaseNamingConvention.Instance)
                                   .Build();

            var parser = new Parser(new System.IO.StringReader(yamlmd));

            parser.Consume <StreamStart>();
            parser.Consume <DocumentStart>();
            var post = yamlDeserializer.Deserialize(parser);

            parser.Consume <DocumentEnd>();
            //parser.MoveNext();
            var item = post as Item;

            item.Markdown = yamlmd.Substring(parser.Current.End.Index + 1);
            return(post as Item);
        }
        public ScenarioManager(IMockContext context, IScenarioResolver scenarioResolver)
        {
            _logProvider = context.LogProvider;

            _scenarioResolver = scenarioResolver;

            _scenarioResolver.RegisterChangeHandler(OnChangeHandler);

            _scenerioCache = new ConcurrentDictionary <string, MockScenario>();

            var deserializerBuilder = new DeserializerBuilder();

            _deserializer = deserializerBuilder
                            .WithNamingConvention(new CamelCaseNamingConvention())
                            .Build();

            var serialierBuilder = new SerializerBuilder();

            _serializer = serialierBuilder
                          .WithNamingConvention(new CamelCaseNamingConvention())
                          .Build();

            _routes = new SortedList <RouteKey, Route>(RouteKeyComparer.Instance);

            PreloadAllScenarios();
        }
Exemple #3
0
        private ToOptions LoadSetting(bool showAlert = true)
        {
            if (SettingPath == null || SettingPath.Length == 0)
            {
                if (showAlert)
                {
                    MessageBox.Show("設定ファイルを指定して下さい", "エラー");
                }
                return(null);
            }
            if (!File.Exists(SettingPath))
            {
                if (showAlert)
                {
                    MessageBox.Show("指定された設定ファイルがありません", "エラー");
                }
                return(null);
            }
            var yaml    = File.ReadAllText(SettingPath);
            var builder = new DeserializerBuilder();

            builder.WithNamingConvention(new HyphenatedNamingConvention());
            var deserializer = builder.Build();
            var options      = deserializer.Deserialize <ToOptions>(yaml);

            return(options ?? new ToOptions());
        }
Exemple #4
0
        static UpgradeGuides()
        {
            var builder = new DeserializerBuilder();

            builder.IgnoreUnmatchedProperties();
            builder.WithNamingConvention(CamelCaseNamingConvention.Instance);
            deserializer = builder.Build();
        }
Exemple #5
0
        public static Deserializer CreateDeserializer()
        {
            var builder = new DeserializerBuilder();

            builder.IgnoreUnmatchedProperties();
            builder.WithNamingConvention(namingConvention);

            return(builder.Build());
        }
Exemple #6
0
 static IDeserializer Build(DeserializerBuilder builder)
 {
     return(builder
            .WithNamingConvention(CamelCaseNamingConvention.Instance)
            .IgnoreUnmatchedProperties()
            .WithTypeConverter(new SemanticVersionYamlTypeConverter())
            .WithTypeConverter(new UriYamlTypeConverter())
            .WithTypeConverter(new OsPlatformYamlTypeConverter())
            .WithTypeConverter(new DateTimeConverter(DateTimeKind.Utc))
            .Build());
 }
        public static BasicOptions Load(string filepath)
        {
            var yaml    = File.ReadAllText(filepath);
            var builder = new DeserializerBuilder();

            builder.WithNamingConvention(new HyphenatedNamingConvention());
            builder.IgnoreUnmatchedProperties();
            var deserializer = builder.Build();
            var options      = deserializer.Deserialize <BasicOptions>(yaml);

            return(options ?? new BasicOptions());
        }
Exemple #8
0
        private static IDeserializer BuildDeserializer(DeserializeYamlSettings settings)
        {
            var deserializerBuilder = new DeserializerBuilder();

            if (!(settings.NamingConvention is null))
            {
                deserializerBuilder = deserializerBuilder.WithNamingConvention(settings.NamingConvention);
            }

            var deserializer = deserializerBuilder.Build();

            return(deserializer);
        }
        public static void Parse(string config, Dictionary <Vector2, MapBlock> mapBlocks)
        {
            var stream = new StringReader(config);

            var DeserializeBuilderObject = new DeserializerBuilder();

            DeserializeBuilderObject.WithNamingConvention(new CamelCaseNamingConvention());
            var Deserializer = DeserializeBuilderObject.Build();

            Configuration = Deserializer.Deserialize <Config.Config>(stream);

            assignConfiguration(Configuration, mapBlocks);
        }
Exemple #10
0
        public void DeserializationUtilizeNamingConventions()
        {
            var convention = A.Fake <INamingConvention>();

            A.CallTo(() => convention.Apply(A <string> ._)).ReturnsLazily((string x) => x);
            var text = Lines(
                "FirstTest: 1",
                "SecondTest: 2");

            DeserializerBuilder.WithNamingConvention(convention);
            Deserializer.Deserialize <NameConvention>(UsingReaderFor(text));

            A.CallTo(() => convention.Apply("FirstTest")).MustHaveHappened();
            A.CallTo(() => convention.Apply("SecondTest")).MustHaveHappened();
        }
Exemple #11
0
        static YamlExtensions()
        {
            var deserializerBuilder = new DeserializerBuilder();

            _deserializer = deserializerBuilder
                            .WithNamingConvention(new CamelCaseNamingConvention())
                            .Build();

            var serializerBuilder = new SerializerBuilder();

            _serializer = serializerBuilder
                          .WithNamingConvention(new CamelCaseNamingConvention())
                          .WithTypeInspector <DynamicXmlTypeInspector>((typeInspector) => { return(new DynamicXmlTypeInspector(typeInspector)); })
                          .Build();
        }
 public static Services ReadFile(string configurationFile)
 {
     try
     {
         var                 projectFolder      = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
         string              document           = System.IO.File.ReadAllText(@"" + projectFolder + "/src/orchestrator/YAML/" + configurationFile + ".yml");
         StringReader        input              = new StringReader(document);
         DeserializerBuilder deserializeBuilder = new DeserializerBuilder();
         deserializeBuilder.WithNamingConvention(new CamelCaseNamingConvention());
         Deserializer deserializer = deserializeBuilder.Build();
         return(deserializer.Deserialize <Services>(input));
     }
     catch (FileNotFoundException)
     {
         return(null);
     }
 }
    public ConfigReader()
    {
        StreamReader sr           = new StreamReader(Application.dataPath + "/../../config/unity_config.yaml");
        string       fileContents = sr.ReadToEnd();

        sr.Close();

        inputEnvironment = new StringReader(fileContents);

        sr           = new StreamReader(Application.dataPath + "/../../config/reward_system_config.yaml");
        fileContents = sr.ReadToEnd();
        sr.Close();

        inputRewardSystem = new StringReader(fileContents);

        DeserializerBuilder deserializerBuilder = new DeserializerBuilder();

        deserializerBuilder.WithNamingConvention(new CamelCaseNamingConvention());
        deserializer = deserializerBuilder.Build();
    }
Exemple #14
0
        public static T Load <T>(string path)
        {
            StreamReader reader = new StreamReader("Content/Scenes/" + path + ".yaml");

            DeserializerBuilder data = new DeserializerBuilder();

            data.WithNamingConvention(new PascalCaseNamingConvention());

            Deserializer res = data.Build();
            T            obj = res.Deserialize <T>(reader);

            if (obj != null)
            {
                return(obj);
            }
            else
            {
                throw new InvalidDataException("Path " + path + " does not return a valid " + typeof(T));
            }
        }
Exemple #15
0
        public static MetaFile FromFile(string path)
        {
            if (!File.Exists(path))
            {
                return(null);
            }

            DeserializerBuilder builder = new DeserializerBuilder();

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

            using (StreamReader sr = File.OpenText(path))
            {
                return(deserializer.Deserialize <MetaFile>(sr));
            }
        }
Exemple #16
0
        public void IgnoreExtraPropertiesIfWantedNamingScheme()
        {
            var text = Lines(
                "scratch: 'scratcher'",
                "deleteScratch: false",
                "notScratch: 9443",
                "notScratch: 192.168.1.30",
                "mappedScratch:",
                "- '/work/'"
                );

            DeserializerBuilder
            .WithNamingConvention(new CamelCaseNamingConvention())
            .IgnoreUnmatchedProperties();

            var actual = Deserializer.Deserialize <SimpleScratch>(UsingReaderFor(text));

            actual.Scratch.Should().Be("scratcher");
            actual.DeleteScratch.Should().Be(false);
            actual.MappedScratch.Should().ContainInOrder(new[] { "/work/" });
        }
Exemple #17
0
        internal static T Read <T>(string yamlFileName, params IYamlTypeConverter[] converters)
        {
            T   locale;
            var executingAssembly = Assembly.GetExecutingAssembly();

            using (var resourceStream = executingAssembly.GetManifestResourceStream(yamlFileName))
            {
                using (var textReader = new StreamReader(resourceStream))
                {
                    DeserializerBuilder deserializerBuilder = new DeserializerBuilder();
                    foreach (var converter in converters)
                    {
                        deserializerBuilder = deserializerBuilder.WithTypeConverter(converter);
                    }
                    var deserializer = deserializerBuilder
                                       .WithNamingConvention(CamelCaseNamingConvention.Instance)
                                       .Build()
                    ;
                    locale = deserializer.Deserialize <T>(textReader.ReadToEnd());
                }
            }
            return(locale);
        }
Exemple #18
0
        public void CreateClausesForSection(int sectionId, byte[] file, LoggedInUserDetails user)
        {
            // Check whether user is not admin
            if (!user.IsSysAdmin)
            {
                throw new BaseException("Access denied.");
            }

            // Check whether section does not exist
            var clauseSection = _sections.FirstOrDefault(i => i.ID == sectionId);

            if (clauseSection == null)
            {
                throw new BaseException($"Section not found {sectionId}");
            }

            // Process file
            var fileContent        = _encoding.GetString(file);
            var stringReader       = new StringReader(fileContent);
            var deserializeBuilder = new DeserializerBuilder();

            deserializeBuilder.WithNamingConvention(new CamelCaseNamingConvention());
            var deserializer = deserializeBuilder.Build();
            var sections     = deserializer.Deserialize <List <ClauseFileModel> >(stringReader);

            if (sections != null)
            {
                foreach (var section in sections)
                {
                    foreach (var clause in section.clauses)
                    {
                        // Create clause template
                        CreateClauseTemplate(sectionId, clause, user.ID.Value);
                    }
                }
            }
        }
Exemple #19
0
        // Do things when session info updates (seems to be whenever a car crosses the line)
        private void OnSessionInfoUpdated(object sender, iRacingSdkWrapper.SdkWrapper.SessionInfoUpdatedEventArgs sessionArgs)
        {
            if (isClosing)
            {
                return;             // if program is closing, just return so we don't waste time doing this stuff
            }
            if (!sessionArgs.SessionInfo.IsValidYaml)
            {
                return;                                        // if the yaml isn't valid, no reason to bother with the rest
            }
            try
            {
                DeserializerBuilder deserializerBuilder = new DeserializerBuilder();
                deserializerBuilder.WithNamingConvention(new PascalCaseNamingConvention());
                Deserializer deserializer = deserializerBuilder.Build();

                var input       = new StringReader(sessionArgs.SessionInfo.Yaml); // read the yaml
                var sessionInfo = deserializer.Deserialize <SDKReturn>(input);    // deserialize the yaml

                #region Radios
                lblIsAdmin.Text = $"User is Admin: {isAdmin}"; // update label

                foreach (Frequencies r in sessionInfo.RadioInfo.Radios[0].Frequencies)
                {
                    if (r.FrequencyName == "@ADMIN")
                    {
                        isAdmin = true;  // if user has the ADMIN radio channel, we can safely assume they're an admin in the session
                    }
                }
                #endregion

                #region Drivers Info
                if ((driversInSession == null) || (driversInSession.Count != sessionInfo.DriverInfo.Drivers.Count)) // if driver list is empty, or one of the lists is longer than the other
                {
                    driversInSession = sessionInfo.DriverInfo.Drivers;                                              // set local driver list equal to drivers in the server
                }
                #endregion

                #region Race Session Info
                foreach (var session in sessionInfo.SessionInfo.Sessions)                                       // look through all the sessions (normally they're Practice, Qualifying, and Race)
                {
                    if (session.SessionType == "Race")                                                          // find the race part session (ignore qual and practice parts of the active server, if they exist)
                    {
                        var raceSession = session;                                                              // the session we're dealing with is the race session, just using this to shorten the variable to less than 50 characters

                        currentLapRace = raceSession.ResultsLapsComplete;                                       // get the laps complete, this is helpful for when someone in top 10 is not on lead lap

                        lblCurrentLap.Text = $"Current Lap: {currentLapRace + 1} of {raceSession.SessionLaps}"; // update current lap label

                        #region close pits
                        if (!isPitsClosed && !isYellowOut)                                          // make sure pits are open
                        {
                            if (!IsSegmentEnded(1))                                                 // check if segment 1 is ended
                            {                                                                       // if not, we're in segment 1
                                if (currentLapRace >= (segment1EndLap - userSettings.ClosePitsLap)) // if it's 5 laps or less away from segment 1
                                {
                                    ClosePits();                                                    // close pits
                                }
                            }
                            else
                            {                                                                     // otherwise we're in segment 2
                                if (currentLapRace >= segment2EndLap - userSettings.ClosePitsLap) // 5 laps or less
                                {
                                    ClosePits();                                                  // close pits
                                }
                            }
                        }
                        #endregion

                        currentPositions = raceSession.ResultsPositions; // update positions to equal live results

                        if (currentPositions != null)                    // make sure currentPositions list is not null, otherwise program will crash
                        {
                            IEnumerable <Positions> carsOnLeadLapQuery = // get cars on lead lap
                                                                         from position in currentPositions
                                                                         where position.Lap == 0
                                                                         select position;

                            lblCarsOnLead.Text = $"Cars on Lead Lap: {carsOnLeadLap.Count()} of {currentPositions.Count}"; // update label

                            carsOnLeadLap = carsOnLeadLapQuery.ToList();                                                   // convert cars on lead query lap to list

                            if (!IsSegmentEnded(1) || (IsSegmentEnded(1) && !IsSegmentEnded(2)))                           // if segment 1 is not ended
                            {
                                if (currentLapRace >= segment1EndLap + 1 && segment1Top10[9].CarIdx == -1 || currentLapRace >= segment2EndLap + 1 && segment2Top10[9].CarIdx == -1)
                                {                     // if we're on the lap of a segment end, start checking if we should throw caution
                                    if (!isYellowOut) // make sure yellow hasn't come out
                                    {
                                        GetSegmentResults(false);
                                    }
                                    else // if it has
                                    {
                                        GetSegmentResults(true);
                                    }
                                }
                            }
                        }
                    }
                }
                #endregion
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message.ToString());
            }
        }
Exemple #20
0
        public static DeserializerBuilder WithNamingConvention(this DeserializerBuilder deserializerBuilder, NamingConvention namingConvention)
        {
            var target = GetNamingConvention(namingConvention);

            return(deserializerBuilder.WithNamingConvention(target));
        }