private void LogScriptOutput(string suffix, string message)
        {
            string script = MetadataScript.GetMetadataKeyHyphen(this.scriptType, suffix);

            if (!string.IsNullOrEmpty(message))
            {
                Logger.Info("{0}: {1}", script, message);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Generate a new file name to store a metadata script.
        /// </summary>
        /// <param name="suffix">
        /// The script type indicating the appropriate file extension.
        /// </param>
        /// <returns>The filename of the file created.</returns>
        private string GetTempFileName(string suffix)
        {
            string scriptTypeString = MetadataScript.GetMetadataTypeString(this.scriptType, suffix);
            string fileName;

            do
            {
                fileName = string.Format("{0}{1}.{2}", Path.GetTempPath(), Guid.NewGuid(), suffix);
            }while (File.Exists(fileName));
            return(fileName);
        }
        public List <MetadataScript> GetAttributeScripts(AttributesJson attributesJson)
        {
            List <MetadataScript> scripts = new List <MetadataScript>();

            foreach (string suffix in MetadataScript.Suffixes)
            {
                string scriptKey = MetadataScript.GetMetadataKeyTitle(this.scriptType, suffix);
                string script    = GetPropertyValue(attributesJson, scriptKey);
                if (!string.IsNullOrEmpty(script))
                {
                    Logger.Info("Found {0} in metadata.", MetadataScript.GetMetadataKeyHyphen(this.scriptType, suffix));
                    scripts.Add(FetchScript(suffix, script));
                }
            }

            return(scripts);
        }
Exemplo n.º 4
0
        public List <MetadataScript> GetScripts(MetadataJson metadata)
        {
            AttributesJson instanceAttributesJson;
            AttributesJson projectAttributesJson;

            try
            {
                instanceAttributesJson = metadata.Instance.Attributes;
            }
            catch (NullReferenceException)
            {
                instanceAttributesJson = null;
            }

            try
            {
                projectAttributesJson = metadata.Project.Attributes;
            }
            catch (NullReferenceException)
            {
                projectAttributesJson = null;
            }

            List <MetadataScript> scripts = new List <MetadataScript>();

            foreach (string suffix in MetadataScript.Suffixes)
            {
                string scriptKey = MetadataScript.GetMetadataKeyTitle(this.scriptType, suffix);
                string script    = GetPropertyValue(instanceAttributesJson, scriptKey) ??
                                   GetPropertyValue(projectAttributesJson, scriptKey);
                if (!string.IsNullOrEmpty(script))
                {
                    Logger.Info("Found {0} in metadata.", MetadataScript.GetMetadataKeyHyphen(this.scriptType, suffix));
                    scripts.Add(FetchScript(suffix, script));
                }
            }

            return(scripts);
        }
        public async Task RunScript(MetadataScript metadataScript)
        {
            ProcessStartInfo startInfo;

            if ("ps1" == metadataScript.Suffix)
            {
                startInfo = RunPowershell(metadataScript.Script);
            }
            else
            {
                startInfo = GetProcStartInfo(metadataScript.Script);
            }

            using (Process process = Process.Start(startInfo))
            {
                Task outputFinished = LogStream(metadataScript.Suffix, process.StandardOutput);
                await LogStream(metadataScript.Suffix, process.StandardError);

                await outputFinished;
            }
            File.Delete(metadataScript.Script);
        }