Esempio n. 1
0
        public static bool ReadProjectFile(string fileName)
        {
            if (!File.Exists(fileName))
            {
                return(false);
            }

            FileStream   fs = new FileStream(fileName, FileMode.Open);
            StreamReader sr = new StreamReader(fs);

            var fileData = sr.ReadToEnd();

            sr.Close();
            fs.Close();

            try
            {
                var yamlSerialzer = new SharpYaml.Serialization.Serializer();
                projectFile = yamlSerialzer.Deserialize <ProjectFile>(fileData);
            }
            catch (Exception e)
            {
                string errorMessage = string.Format("There was an error while reading the project file.\r\n\r\n{0}", e.Message);
                MessageBox.Show(errorMessage);
                return(false);
            }

            ImageHandler.initalized = false; // necessary for if the rootDir changes, a bit weird to struture the program this way. think about changing it. (update: just found a weird bug related to ImageHandler initialization, definitely needs changed)

            return(true);
        }
Esempio n. 2
0
 static int Main(string[] args)
 {
     SharpYaml.Serialization.Serializer serializer = new SharpYaml.Serialization.Serializer();
     if (args.Length < 1)
     {
         Console.Error.WriteLine("You must provide an input YAML file!");
         Console.In.Read();
         return(1);
     }
     try
     {
         GameDefinition def = serializer.Deserialize(File.ReadAllText(args[0]), typeof(GameDefinition)) as GameDefinition;
         def.ParseTypes();
         string baseDir = Directory.GetCurrentDirectory();
         if (args.Length > 1)
         {
             baseDir = args[1];
         }
         cxx.CxxHelper.GenerateFiles(Path.Combine(baseDir, "cxx"), def);
         cxx.CxxHelper.GenerateServerFiles(Path.Combine(baseDir, "server"), def);
         cs.CsHelper.GenerateFiles(Path.Combine(baseDir, "cs"), def);
         return(0);
     }
     catch (Exception e)
     {
         Console.Error.WriteLine(e);
         Console.In.Read();
         return(1);
     }
 }
Esempio n. 3
0
        private void ConfigureMicroservice(IHostingEnvironment env)
        {
            var serializer = new SharpYaml.Serialization.Serializer();

            ApplicationComposition input;

            using (var fileStream = new FileStream(Path.Combine(env.ContentRootPath, "core.yml"), FileMode.Open, FileAccess.Read))
            {
                input = (ApplicationComposition)serializer.Deserialize(fileStream);
            }

            new Bootstrapper().Startup(input);
        }
Esempio n. 4
0
        private Dictionary <object, object> LoadHybrasylMapYamlFile(string filename)
        {
            Dictionary <object, object> hybrasylMap = null;

            if (!string.IsNullOrEmpty(filename) &&
                !string.IsNullOrEmpty(Configuration.Current.HybrasylWorldDirectory))
            {
                string hybrasylMapData = File.ReadAllText(Path.Combine(Configuration.Current.HybrasylWorldDirectory, "maps", filename));

                var s = new SharpYaml.Serialization.Serializer();
                hybrasylMap = s.Deserialize(hybrasylMapData) as Dictionary <object, object>;
            }

            return(hybrasylMap);
        }
Esempio n. 5
0
        private bool LoadLastOpened()
        {
            if (!File.Exists(lastOpenedFileData))
            {
                return(false);
            }

            FileStream   fs = new FileStream(lastOpenedFileData, FileMode.Open);
            StreamReader sr = new StreamReader(fs);

            var fileData = sr.ReadToEnd();

            sr.Close();
            fs.Close();

            var yamlSerialzer = new SharpYaml.Serialization.Serializer();

            initalizationData = yamlSerialzer.Deserialize <InitalizationData>(fileData);

            return(true);
        }
Esempio n. 6
0
        public void Deserialize()
        {
            var yaml = @"
Info: Test data
Map:
  - Delay: 100
    Description: Probe endpoint
    Status: 200
    Url: /probe
    
  - Delay: 200
    Description: Swagger endpoint
    Status: 200
    Url: /swagger
    Foo: bar
    
  - Delay: 300
    Method: POST
    Description: Order endpoint
    Status: 201
    Url: /order
    Payload: '{""paymentId"":""@guid""}'
    Headers:
      Location: /probe?a=b
      Authorization: 'Bearer aaa'
";

            var serializer = new SharpYaml.Serialization.Serializer();

            serializer.Settings.IgnoreUnmatchedProperties = true;

            var result = serializer.Deserialize <ConfigurationDefinition>(yaml);

            // Assert
            result.Should().NotBeNull();
            result.Info.Should().Be("Test data");
            result.Map.Should().NotBeNullOrEmpty();
            result.Map.Should().HaveCount(3);

            var firstItem = result.Map !.ElementAt(0);

            firstItem.Delay.Should().Be(100);
            firstItem.Description.Should().Be("Probe endpoint");
            firstItem.Status.Should().Be(200);
            firstItem.Url.Should().Be("/probe");
            firstItem.Payload.Should().BeNull();
            firstItem.Headers.Should().BeNull();
            firstItem.Method.Should().BeNull();

            var secondItem = result.Map !.ElementAt(1);

            secondItem.Delay.Should().Be(200);
            secondItem.Description.Should().Be("Swagger endpoint");
            secondItem.Status.Should().Be(200);
            secondItem.Url.Should().Be("/swagger");
            secondItem.Payload.Should().BeNull();
            secondItem.Headers.Should().BeNull();
            secondItem.Method.Should().BeNull();

            var thirdItem = result.Map !.ElementAt(2);

            thirdItem.Delay.Should().Be(300);
            thirdItem.Description.Should().Be("Order endpoint");
            thirdItem.Status.Should().Be(201);
            thirdItem.Url.Should().Be("/order");
            thirdItem.Payload.Should().Be("{\"paymentId\":\"@guid\"}");
            thirdItem.Method.Should().Be("POST");
            thirdItem.Headers.Should().NotBeNull();
            thirdItem.Headers.Should().HaveCount(2);
            thirdItem.Headers !["Location"].Should().Be("/probe?a=b");
Esempio n. 7
0
        private void SaveYaml_viaYamlDotNet()
        {
            // Load the YAML from file
            string hybrasylMapFilepath = Path.Combine(Configuration.Current.HybrasylWorldDirectory, "maps", map.Name);
            string hybrasylMapData     = File.ReadAllText(hybrasylMapFilepath);

            var serializer  = new SharpYaml.Serialization.Serializer();
            var hybrasylMap = serializer.Deserialize(hybrasylMapData) as Dictionary <object, object>;

            // update the Map properties supported by the editor
            // (TODO: replace this and pass in a Map Model object that the editor has been modifying, when that Model class exists)
            dynamic spawns = null;

            if (map.SpawnsFixed.Count > 0 && map.SpawnsZone.Count > 0)
            {
                spawns = new { @fixed = new List <object>(), zone = new List <object>() };
            }
            else if (map.SpawnsFixed.Count > 0)
            {
                spawns = new { @fixed = new List <object>() };
            }
            else if (map.SpawnsZone.Count > 0)
            {
                spawns = new { zone = new List <object>() };
            }

            if (spawns != null)
            {
                foreach (var f in map.SpawnsFixed)
                {
                    dynamic s = new ExpandoObject();
                    s.name      = f.name;
                    s.checkrate = f.checkrate;

                    // optional fields
                    if (f.min > 0)
                    {
                        s.min = f.min;
                    }
                    if (f.max > 0)
                    {
                        s.max = f.max;
                    }
                    if (f.every > 0)
                    {
                        s.every = f.every;
                    }
                    if (f.percentage > 0F)
                    {
                        s.percentage = f.percentage;
                    }
                    if (f.speed != FixedSpawn.DEFAULT_SPEED)
                    {
                        s.speed = f.speed;
                    }
                    if (f.hostile != FixedSpawn.DEFAULT_HOSTILE)
                    {
                        s.hostile = f.hostile;
                    }
                    if (f.strategy != FixedSpawn.DEFAULT_STRATEGY)
                    {
                        s.strategy = f.strategy;
                    }

                    [email protected](s);
                }

                foreach (var z in map.SpawnsZone)
                {
                    dynamic s = new ExpandoObject();
                    s.name        = z.name;
                    s.checkrate   = z.checkrate;
                    s.start_point = string.Format("{0},{1}", z.start_point.X, z.start_point.Y);
                    s.end_point   = string.Format("{0},{1}", z.end_point.X, z.end_point.Y);

                    // optional fields
                    if (z.min > 0)
                    {
                        s.min = z.min;
                    }
                    if (z.max > 0)
                    {
                        s.max = z.max;
                    }
                    if (z.every > 0)
                    {
                        s.every = z.every;
                    }
                    if (z.percentage > 0F)
                    {
                        s.percentage = z.percentage;
                    }
                    if (z.speed != ZoneSpawn.DEFAULT_SPEED)
                    {
                        s.speed = z.speed;
                    }
                    if (z.hostile != ZoneSpawn.DEFAULT_HOSTILE)
                    {
                        s.hostile = z.hostile;
                    }
                    if (z.strategy != ZoneSpawn.DEFAULT_STRATEGY)
                    {
                        s.strategy = z.strategy;
                    }

                    spawns.zone.Add(s);
                }

                hybrasylMap["spawns"] = spawns;
            }
            else if (spawns == null && hybrasylMap.ContainsKey("spawns"))
            {
                hybrasylMap.Remove("spawns");
            }


            using (var sw = new StreamWriter(System.IO.File.Create(hybrasylMapFilepath)))
            {
                var s = new YamlDotNet.Serialization.Serializer(namingConvention: new YamlDotNet.Serialization.NamingConventions.CamelCaseNamingConvention());
                s.Serialize(sw, hybrasylMap);
            }
        }