Ejemplo n.º 1
0
        public Package(DirectoryInfo packageDirectory)
        {
            _directoryInfo = packageDirectory;

            var jsonFile = _directoryInfo.GetFile("metadata.json");
            var yamlFile = _directoryInfo.GetFile("metadata.yml");

            if (jsonFile.Exists)
            {
                var se = new Serializer();
                Metadata = JsonConvert.DeserializeObject<PackageMetadata>(File.ReadAllText(_directoryInfo.GetFile("metadata.json").FullName));
                using (var yamlStream = yamlFile.Open(FileMode.OpenOrCreate))
                {
                    using (var yamlWriter = new StreamWriter(yamlStream, Encoding.UTF8))
                    {
                        se.Serialize(yamlWriter, Metadata);
                    }
                }
                jsonFile.Delete();
            }

            var dse = new Deserializer();
            //Console.WriteLine("Reading YAML: {0}", yamlFile.FullName);
            using (var yamlStream = yamlFile.Open(FileMode.Open))
            {
                using (var yamlReader = new StreamReader(yamlStream, Encoding.UTF8, true))
                {
                    Metadata = dse.Deserialize<PackageMetadata>(yamlReader);
                }
            }
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            // bug in the SDK requires these even though we're posting the job to HDInsight
            Environment.SetEnvironmentVariable("HADOOP_HOME", @"c:\hadoop");
            Environment.SetEnvironmentVariable("Java_HOME", @"c:\hadoop\jvm");

            var configfile = args.Length == 1 ? args[0] : "default.yaml";

            if (!File.Exists(configfile))
            {
                Console.WriteLine("Configuration file does not exists.");
                return;
            }

            Configuration config = null;

            var serializer = new Deserializer();

            using (var reader = new StreamReader(configfile))
            {
                config = serializer.Deserialize<Configuration>(reader);
            }

            if (config == null)
            {
                Console.WriteLine("Could not read configuration");
                return;
            }

            var hadoop = Hadoop.Connect(
                new Uri(config.ClusterUrl),
                config.ClusterUserName,
                config.HadoopUserName,
                config.ClusterPassword,
                config.BlobStorageUrl,
                config.BlobStorageKey,
                config.BlobContainerName,
                config.CreateContainerIfMissing);

            try
            {
                MapReduceResult result = hadoop.MapReduceJob.ExecuteJob(
                    typeof(MapReduceXmlJob), new[] { config.InputPath, config.OutputPath });

                using (var output = new StreamWriter("output.txt", false))
                {
                    output.WriteLine("Exit code");
                    output.WriteLine(result.Info.ExitCode);
                    output.WriteLine("stdout");
                    output.WriteLine(result.Info.StandardOut);
                    output.WriteLine("stderr");
                    output.WriteLine(result.Info.StandardError);
                    output.Flush();
                }
            }
            catch (Exception x)
            {
                Console.WriteLine(x);
            }
        }
Ejemplo n.º 3
0
        public void NotSpecifyingObjectFactoryUsesDefault()
        {
            var deserializer = new Deserializer();
            deserializer.RegisterTagMapping("!foo", typeof(FooBase));
            var result = deserializer.Deserialize(new StringReader("!foo {}"));

            Assert.IsType<FooBase>(result);
        }
Ejemplo n.º 4
0
        public void ObjectFactoryIsInvoked()
        {
            var deserializer = new Deserializer(new LambdaObjectFactory(t => new FooDerived()));
            deserializer.RegisterTagMapping("!foo", typeof(FooBase));

            var result = deserializer.Deserialize(new StringReader("!foo {}"));

            Assert.IsType<FooDerived>(result);
        }
Ejemplo n.º 5
0
        public IEnumerable<ITestCaseData> GetTestCases(string file)
        {
            var text = File.ReadAllText(string.Format("../../../spec/specs/{0}.yml", file));
            var deserializer = new Deserializer();
            var doc = deserializer.Deserialize<SpecDoc>(new StringReader(text));

            return doc.tests
                .Select(test => new TestCaseData(test.name, test.data, test.template, test.partials, test.expected)
                .SetName(file + ": " + test.name));
        }
Ejemplo n.º 6
0
 public void Test_Cartridge()
 {
     string cartridgePath = Path.Combine(CartridgeRepository.CartridgeBasePath, "dotnet");
     string manifestPath = Path.Combine(cartridgePath, "metadata", "manifest.yml");
     string document = File.ReadAllText(manifestPath);
     var input = new StringReader(document);
     var deserializer = new Deserializer();
     dynamic spec = (dynamic)deserializer.Deserialize(input);
     Cartridge cart = Cartridge.FromDescriptor(spec);            
     Assert.AreEqual("dotnet", cart.OriginalName);
 }
Ejemplo n.º 7
0
 public void Test_ToDescriptor()
 {
     string cartridgePath = Path.Combine(CartridgeRepository.CartridgeBasePath, "dotnet");
     string manifestPath = Path.Combine(cartridgePath, "metadata", "manifest.yml");
     string document = File.ReadAllText(manifestPath);
     var input = new StringReader(document);
     var deserializer = new Deserializer();
     dynamic spec = (dynamic)deserializer.Deserialize(input);
     Cartridge cart = Cartridge.FromDescriptor(spec);
     dynamic desc = cart.ToDescriptor();
     Assert.IsTrue(desc.ContainsKey("Name"));
 }
Ejemplo n.º 8
0
        public static SiteConfiguration LoadSiteConfiguration(string file)
        {
            if (!File.Exists(file))
                return null;

            var deserializer = new Deserializer(null, new CamelCaseNamingConvention());

            using (var reader = new StreamReader(file))
            {
                return deserializer.Deserialize<SiteConfiguration>(reader);
            }
        }
Ejemplo n.º 9
0
 private static Config Deserialize(string configFileName)
 {
     if (!File.Exists(configFileName))
     {
         WriteSampleConfigFile(configFileName);
         throw new Exception(string.Format("Update the sample config file, {0}, before running tests.", configFileName));
     }
     using (var streamReader = File.OpenText(configFileName))
     {
         var deserializer = new Deserializer();
         return deserializer.Deserialize<Config>(streamReader);
     }
 }
Ejemplo n.º 10
0
 public void Test_CartridgeFromDescriptor()
 {
     bool testresult = false;
     Manifest sampleManifest = TestHelper.GetSampleManifest();
     var input = new StringReader(sampleManifest.ToManifestString());            
     var deserializer = new Deserializer();
     dynamic spec = (dynamic)deserializer.Deserialize(input);
     Cartridge cart = Cartridge.FromDescriptor(spec);
     if (cart != null)
     {
         testresult = true;
     }
     Assert.AreEqual(true, testresult);
 }
Ejemplo n.º 11
0
        public void Update()
        {
            Console.Write("Fetching available packages for {0}...", Uri);
            try
            {
                using (var yamlStream = _wc.OpenRead(new Uri(Uri, "packages.yml")))
                {
                    if (yamlStream != null)
                        using (var yamlStreamReader = new StreamReader(yamlStream))
                            PackageInfos = new Deserializer().Deserialize<List<PackageInfo>>(yamlStreamReader);
                    else
                        throw new Exception();
                }

                Console.WriteLine(" OK.");
            }
            catch
            {
                Console.WriteLine(" FAIL.");
            }
        }
Ejemplo n.º 12
0
        public static string GetCartridgeList(bool listDescriptors, bool porcelain, bool oo_debug)
        {
            string output = string.Empty;

            List<Cartridge> carts = new List<Cartridge>();

            foreach(Manifest cartridge in CartridgeRepository.Instance.LatestVersions())
            {
                string manifestString = cartridge.ToManifestString();
                using(StringReader sr = new StringReader(manifestString))
                {
                    var desrializer = new Deserializer();
                    dynamic manifest = desrializer.Deserialize(sr);
                    manifest["Version"] = cartridge.Version;
                    carts.Add(Cartridge.FromDescriptor(manifest));
                }                
            }

            if (porcelain)
            {
                if (listDescriptors)
                {
                    output += "CLIENT_RESULT: ";
                    List<string> descriptors = new List<string>();
                    foreach (Cartridge cart in carts)
                    {
                        dynamic desc = cart.ToDescriptor();
                        StringWriter sw = new StringWriter();
                        Serializer serializer = new Serializer();
                        serializer.Serialize(new Emitter(sw, 2, int.MaxValue, true), desc);
                        descriptors.Add(sw.ToString());
                    }
                    output += JsonConvert.SerializeObject(descriptors);
                }
                else
                {
                    output += "CLIENT_RESULT: ";
                    List<string> names = new List<string>();
                    foreach (Cartridge cart in carts)
                    {
                        names.Add(cart.Name);
                    }
                    output += JsonConvert.SerializeObject(names);
                }
            }
            else
            {
                if (listDescriptors)
                {
                    foreach (Cartridge cart in carts)
                    {
                        dynamic desc = cart.ToDescriptor();
                        StringWriter sw = new StringWriter();
                        Serializer serializer = new Serializer(SerializationOptions.JsonCompatible);
                        serializer.Serialize(new Emitter(sw, 2, int.MaxValue, true), desc);
                        output += string.Format("Cartridge name: {0}\n\nDescriptor:\n {1}\n\n\n", cart.Name, sw.ToString());
                    }
                }
                else
                {
                    output += "Cartridges:\n";
                    foreach (Cartridge cart in carts)
                    {
                        output += string.Format("\t{0}\n", cart.Name);
                    }
                }
            }

            return output;
        }
Ejemplo n.º 13
0
 private void LoadSections(TextReader yaml)
 {
     var deserializer = new Deserializer();
     sections = (IDictionary<string, object>)deserializer.Deserialize(yaml, typeof(Dictionary<string, object>));
 }
Ejemplo n.º 14
0
        public ReleaseInfo GetReleaseInfo(CloudFoundry.WindowsPrison.Prison prison)
        {
            string exe = GetExecutable(Path.Combine(this.path, "bin"), "release");

            string outputPath = Path.Combine(this.cacheDir, "release.yml");
            string script = string.Format("{0} {1} > {2} 2>&1", exe, this.appDir, outputPath);

            Process process = prison.Execute(null, script, this.appDir, false, null, null, null, null);

            process.WaitForExit(5000);

            string output = File.ReadAllText(outputPath);
            File.Delete(outputPath);
            using (var reader = new StringReader(output))
            {
                Deserializer deserializer = new Deserializer();
                return (ReleaseInfo)deserializer.Deserialize(reader, typeof(ReleaseInfo));
            }
        }
Ejemplo n.º 15
0
 public static dynamic ManifestFromYaml(string yamlStr)
 {
     var input = new StringReader(yamlStr);
     var deserializer = new Deserializer();
     dynamic spec = (dynamic)deserializer.Deserialize(input);
     return spec;
 }
Ejemplo n.º 16
0
        object IConfigurationSectionHandler.Create(object parent, object configContext, XmlNode section)
        {
            TextReader yaml;
            if (section.Attributes["file"] != null)
            {
                string fileName = section.Attributes["file"].Value;
                if (!File.Exists(fileName))
                {
                    string configPath = Path.GetDirectoryName(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).FilePath);
                    fileName = Path.Combine(configPath, fileName);
                }

                yaml = File.OpenText(fileName);
            }
            else
            {
                yaml = GetYamlContent(section);
            }

            var sectionType = typeof(object);
            if (section.Attributes["type"] != null)
            {
                sectionType = Type.GetType(section.Attributes["type"].Value, true);
            }

            var deserializer = new Deserializer();
            return deserializer.Deserialize(yaml, sectionType);
        }
Ejemplo n.º 17
0
        public ReleaseInfo GetReleaseInfo(ProcessPrison prison)
        {
            string exe = GetExecutable(Path.Combine(this.path, "bin"), "release");

            string outputPath = Path.Combine(this.cacheDir, "release.yml");
            string script = string.Format("{0} {1} > {2} 2>&1", exe, this.appDir, outputPath);

            var runInfo = new ProcessPrisonRunInfo();
            runInfo.WorkingDirectory = Path.Combine(this.appDir);
            runInfo.FileName = null;
            runInfo.Arguments = script;
            Process process = prison.RunProcess(runInfo);
            process.WaitForExit(5000);

            string output = File.ReadAllText(outputPath);
            File.Delete(outputPath);
            using (var reader = new StringReader(output))
            {
                Deserializer deserializer = new Deserializer();
                return (ReleaseInfo)deserializer.Deserialize(reader, typeof(ReleaseInfo));
            }
        }
 public static ServerSettings ReadFrom(string filePath)
 {
     var deserializer = new Deserializer(namingConvention: new CamelCaseNamingConvention());
     var reader = new StreamReader(filePath, Encoding.UTF8);
     return deserializer.Deserialize<ServerSettings>(reader);
 }