예제 #1
0
        public static DeploymentFile Read(string path, bool outputProcessedJson)
        {
            DeploymentFile deploymentFile = null;

            using (FileStream fileStream = new FileStream(path, FileMode.Open))
            {
                using (MemoryStream stream = new MemoryStream())
                {
                    // Convert to JSON
                    var serializerBuilder = new SerializerBuilder();
                    serializerBuilder.JsonCompatible();
                    serializerBuilder.DisableAliases();
                    var serializer   = serializerBuilder.Build();
                    var deserializer = new Deserializer();
                    var writer       = new StreamWriter(stream);

                    serializer.Serialize(writer, deserializer.Deserialize(new StreamReader(fileStream)));
                    writer.Flush();

                    stream.Seek(0, SeekOrigin.Begin);
                    if (outputProcessedJson)
                    {
                        using (var file = new FileStream(Path.GetFileNameWithoutExtension(path) + "_processed.json", FileMode.OpenOrCreate))
                        {
                            stream.CopyTo(file);
                        }
                        stream.Seek(0, SeekOrigin.Begin);
                    }

                    // Deserialize with the contract
                    DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(DeploymentFile));
                    deploymentFile = jsonSerializer.ReadObject(stream) as DeploymentFile;
                }
            }
            deploymentFile.FileName = path;
            return(deploymentFile);
        }
예제 #2
0
        internal Deployer(IList <string> deploymentFilePaths, string optionBinPath, string optionInstallPath, bool outputProcessedJson)
        {
            DateTime mostRecentWriteTimeStamp     = DateTime.MinValue;
            List <DeploymentFile> deploymentFiles = new List <DeploymentFile>(deploymentFilePaths.Count);

            foreach (var deploymentFilePath in deploymentFilePaths)
            {
                if (!File.Exists(deploymentFilePath))
                {
                    throw new Exception(String.Format("File '{0}' not found in current directory", deploymentFilePath));
                }
                deploymentFiles.Add(DeploymentFile.Read(deploymentFilePath, outputProcessedJson));
                DateTime currentFileTime = File.GetLastWriteTimeUtc(deploymentFilePath);
                mostRecentWriteTimeStamp = mostRecentWriteTimeStamp > currentFileTime ? mostRecentWriteTimeStamp : currentFileTime;
                Utils.Log("Using deployment file: {0}", deploymentFilePath);
            }

            if (deploymentFiles.Count == 0)
            {
                throw new Exception("You at least have to provide one deployment file");
            }

            Deployment = new Deployment(deploymentFiles, optionBinPath, optionInstallPath, mostRecentWriteTimeStamp);
        }
예제 #3
0
        private List <Tool> InitTools(string toolset, DeploymentFile.Tool[] fileTools, string packageInstallPath, DeploymentFile deploymentFile)
        {
            var tools = new List <Tool>();

            foreach (var fileTool in fileTools)
            {
                if (string.IsNullOrEmpty(fileTool.Path))
                {
                    throw new InvalidDataException(string.Format("Missing tool path in {0}", deploymentFile.FileName));
                }
                if (fileTool.Aliases.Length == 0)
                {
                    throw new InvalidDataException(string.Format("Missing tool aliases in {0} for {1}", fileTool.Path, deploymentFile.FileName));
                }

                string toolInstallPath = Environment.ExpandEnvironmentVariables(fileTool.Path);
                if (!string.IsNullOrEmpty(packageInstallPath))
                {
                    if (Path.IsPathRooted(toolInstallPath))
                    {
                        throw new InvalidDataException(string.Format("Tools with linked packages can't have rooted paths: {0}", fileTool.Path));
                    }

                    toolInstallPath = Path.GetFullPath(Path.Combine(packageInstallPath, toolInstallPath));
                }
                else
                {
                    if (!Path.IsPathRooted(fileTool.Path))
                    {
                        throw new InvalidDataException(string.Format("Tools without linked packages need rooted paths: {0}", fileTool.Path));
                    }
                }

                switch (fileTool.Type)
                {
                case "exe":
                    tools.Add(new ExeTool(toolset, fileTool.Aliases, toolInstallPath, fileTool.Blocking, InitEnvVariables(fileTool.EnvVariables)));
                    break;

                case "bash":
                    tools.Add(new BashTool(toolset, fileTool.Aliases, toolInstallPath, InitEnvVariables(fileTool.EnvVariables)));
                    break;

                default:
                    throw new InvalidDataException(string.Format("Tool type {0} not supported", fileTool.Type));
                }

                AddConfigMapping("tool-" + fileTool.Aliases[0], toolInstallPath);
            }

            return(tools);
        }