Esempio n. 1
0
        protected override void Process([NotNull] ProcessorArgs args)
        {
            Install9Args   arguments      = (Install9Args)args;
            Task           task           = arguments.Tasker.Tasks.FirstOrDefault(t => t.Name == this.taskName);
            PowerShellTask powershellTask = task as PowerShellTask;

            if (powershellTask != null)
            {
                string result = powershellTask.GetScript();
                if (task.State == TaskState.Failed)
                {
                    throw new AggregateException(string.Format("Failed to execute {0} task. \n{1}", task.Name, result));
                }

                string path = Path.Combine(arguments.Tasker.GlobalParams.First(p => p.Name == "FilesRoot").Value,
                                           string.Format("generated_scripts/{0}", task.UnInstall ? "Uninstall" : "Install"));
                Directory.CreateDirectory(path);

                using (StreamWriter writer = new StreamWriter(Path.Combine(path, string.Format("{0}.ps1", task.Name))))
                {
                    writer.Write(powershellTask.GetScript());
                }
            }
            else
            {
                this.Skip();
            }
        }
Esempio n. 2
0
        public Tasker(string unInstallParamsPath) : this()
        {
            UnInstall           = true;
            UnInstallParamsPath = unInstallParamsPath;
            string unInstallTasksPath = Path.Combine(unInstallParamsPath, uninstallTasksFolderName);
            List <InstallParam> deserializedGlobalParams;

            using (StreamReader reader = new StreamReader(Path.Combine(unInstallParamsPath, "globals.json")))
            {
                string filePath = Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(), "GlobalParamsConfig"),
                                                     reader.ReadLine(), SearchOption.AllDirectories).Single();
                globalParamsFile = filePath;
                string data = reader.ReadToEnd();
                deserializedGlobalParams = JsonConvert.DeserializeObject <List <InstallParam> >(data);
            }

            FilesRoot = deserializedGlobalParams.Single(p => p.Name == "FilesRoot").Value;
            doc       = JObject.Parse(File.ReadAllText(globalParamsFile));
            this.LoadValidators();
            mapping      = GetPackageMapping();
            GlobalParams = GetGlobalParams();
            string deployRoot = deserializedGlobalParams.Single(p => p.Name == "DeployRoot")?.Value;

            if (deployRoot != null)
            {
                this.InjectGlobalDeploymentRoot(deployRoot);
            }

            for (int i = 0; i < GlobalParams.Count; ++i)
            {
                InstallParam param = deserializedGlobalParams.FirstOrDefault(p => p.Name == GlobalParams[i].Name);
                if (param != null)
                {
                    param.ParamValueUpdated += GlobalParamValueUpdated;
                    GlobalParams[i]          = param;
                }
            }

            List <string> uninstallTasksNames = Directory.GetFiles(unInstallParamsPath, "*.json")
                                                .Where(name => !Path.GetFileName(name).Equals("globals.json", StringComparison.InvariantCultureIgnoreCase))
                                                .ToList();

            foreach (string paramsFile in uninstallTasksNames)
            {
                string taskNameAdnOrder = Path.GetFileNameWithoutExtension(paramsFile);
                int    index            = taskNameAdnOrder.LastIndexOf('_');
                string taskName         = taskNameAdnOrder.Substring(0, index);
                int    order            = int.Parse(taskNameAdnOrder.Substring(index + 1));
                using (StreamReader reader = new StreamReader(paramsFile))
                {
                    JProperty param      = doc["ExecSequense"].Children().Cast <JProperty>().Single(p => p.Name == taskName);
                    string    taskType   = param.Value["Type"]?.ToString() ?? typeof(SitecoreTask).FullName;
                    JToken    overridden = param.Value["Parameters"];
                    string    realName   = param.Name;
                    if (overridden != null && overridden["RealName"] != null)
                    {
                        realName = overridden["RealName"]?.ToString();
                    }
                    List <InstallParam>         localParams = GetTaskParameters(unInstallTasksPath, realName);
                    Dictionary <string, string> taskOptions = GetTaskOptions(param);

                    //Each task should have the same ctor (TaskName(string),Order(int),Tasker,LocalParams(List<InstallParams>),TaskOptions(Dictionary<string,string>))
                    Task   t    = (Task)Activator.CreateInstance(Type.GetType(taskType), param.Name, order, this, localParams, taskOptions);
                    string data = reader.ReadToEnd();
                    if (!string.IsNullOrWhiteSpace(data))
                    {
                        List <InstallParam> deserializedLocalParams = JsonConvert.DeserializeObject <List <InstallParam> >(data);
                        for (int i = 0; i < t.LocalParams.Count; ++i)
                        {
                            InstallParam lParam = deserializedLocalParams.FirstOrDefault(p => p.Name == t.LocalParams[i].Name);
                            if (lParam != null)
                            {
                                t.LocalParams[i] = lParam;
                            }
                        }
                    }

                    t.UnInstall = true;
                    Tasks.Add(t);
                }
            }

            Tasks = Tasks.OrderBy(t => t.ExecutionOrder).ToList();
            foreach (InstallParam p in GlobalParams)
            {
                p.ParamValueUpdated += GlobalParamValueUpdated;
            }
        }