Exemplo n.º 1
0
        public StringBuilder Execute(Dictionary <string, StringBuilder> values, IWorkspace theWorkspace)
        {
            var result = new ExecuteMessage {
                HasError = false
            };

            Dev2Logger.Info("Delete Scheduled Resource Service");
            StringBuilder tmp;

            values.TryGetValue("Resource", out tmp);
            var serializer = new Dev2JsonSerializer();

            if (tmp != null)
            {
                var res = serializer.Deserialize <IScheduledResource>(tmp);
                Dev2Logger.Info("Delete Scheduled Resource Service." + res);
                using (var model = SchedulerFactory.CreateModel(GlobalConstants.SchedulerFolderId, SecurityWrapper))
                {
                    model.DeleteSchedule(res);
                }
            }
            else
            {
                Dev2Logger.Info("Delete Scheduled Resource Service. No Resource Selected");
                result.Message.Append("No Resource Selected");
                result.HasError = true;
            }
            return(serializer.SerializeToBuilder(result));
        }
Exemplo n.º 2
0
        public override StringBuilder Execute(Dictionary <string, StringBuilder> values, IWorkspace theWorkspace)
        {
            try
            {
                values.TryGetValue("Resource", out StringBuilder tmp);
                var serializer = new Dev2JsonSerializer();

                if (tmp != null)
                {
                    var res = serializer.Deserialize <IScheduledResource>(tmp);
                    Dev2Logger.Info("Get Scheduled History. " + tmp, GlobalConstants.WarewolfInfo);
                    IList <IResourceHistory> resources;
                    using (var model = SchedulerFactory.CreateModel(GlobalConstants.SchedulerFolderId, SecurityWrapper))
                    {
                        resources = model.CreateHistory(res);
                    }
                    return(serializer.SerializeToBuilder(resources));
                }
                Dev2Logger.Debug("No resource Provided", GlobalConstants.WarewolfDebug);
                return(serializer.SerializeToBuilder(new List <IResourceHistory>()));
            }
            catch (Exception e)
            {
                Dev2Logger.Error(e, GlobalConstants.WarewolfError);
                throw;
            }
        }
Exemplo n.º 3
0
        void TryExecute(Dictionary <string, StringBuilder> values, ExecuteMessage result, StringBuilder tmp, Dev2JsonSerializer serializer)
        {
            if (tmp != null)
            {
                var res = serializer.Deserialize <IScheduledResource>(tmp);
                Dev2Logger.Info("Save Scheduled Resource. Scheduled Resource:" + res, GlobalConstants.WarewolfInfo);
                using (var model = SchedulerFactory.CreateModel(GlobalConstants.SchedulerFolderId, SecurityWrapper))
                {
                    values.TryGetValue("UserName", out StringBuilder userName);
                    values.TryGetValue("Password", out StringBuilder password);
                    if (userName == null || password == null)
                    {
                        result.Message.Append(ErrorResource.NoUserNameAndPassword);
                        result.HasError = true;
                    }
                    else
                    {
                        values.TryGetValue("PreviousResource", out StringBuilder previousTask);

                        model.Save(res, userName.ToString(), password.ToString());
                        if (!string.IsNullOrEmpty(previousTask?.ToString()) && previousTask.ToString() != res.Name)
                        {
                            model.DeleteSchedule(new ScheduledResource(previousTask.ToString(), SchedulerStatus.Disabled, DateTime.MaxValue, null, null, Guid.NewGuid().ToString()));
                        }
                    }
                }
            }
            else
            {
                result.Message.Append(ErrorResource.NoResourceSelected);
                result.HasError = true;
            }
        }
Exemplo n.º 4
0
        public StringBuilder Execute(Dictionary <string, StringBuilder> values, IWorkspace theWorkspace)
        {
            var result = new ExecuteMessage {
                HasError = false
            };
            StringBuilder tmp;

            values.TryGetValue("Resource", out tmp);
            var serializer = new Dev2JsonSerializer();

            try
            {
                if (tmp != null)
                {
                    var res = serializer.Deserialize <IScheduledResource>(tmp);
                    Dev2Logger.Log.Info("Save Scheduled Resource. Scheduled Resource:" + res);
                    using (var model = SchedulerFactory.CreateModel(GlobalConstants.SchedulerFolderId, SecurityWrapper))
                    {
                        StringBuilder userName;
                        StringBuilder password;

                        values.TryGetValue("UserName", out userName);
                        values.TryGetValue("Password", out password);
                        if (userName == null || password == null)
                        {
                            result.Message.Append("No UserName or password provided");
                            result.HasError = true;
                        }
                        else
                        {
                            StringBuilder previousTask;
                            values.TryGetValue("PreviousResource", out previousTask);

                            model.Save(res, userName.ToString(), password.ToString());
                            if (previousTask != null && !String.IsNullOrEmpty(previousTask.ToString()) && (previousTask.ToString() != res.Name))
                            {
                                model.DeleteSchedule(new ScheduledResource(previousTask.ToString(), SchedulerStatus.Disabled, DateTime.MaxValue, null, null));
                            }
                        }
                    }
                }
                else
                {
                    result.Message.Append("No Resource Selected");
                    result.HasError = true;
                }
            }
            catch (Exception e)
            {
                Dev2Logger.Log.Error(e);
                result.Message.Append(string.Format("Error while saving: {0}", e.Message.Remove(e.Message.IndexOf('.'))));
                result.HasError = true;
            }
            return(serializer.SerializeToBuilder(result));
        }
Exemplo n.º 5
0
        public StringBuilder Execute(Dictionary <string, StringBuilder> values, IWorkspace theWorkspace)
        {
            try
            {
                Dev2Logger.Log.Info("Get Scheduled Resources");
                ObservableCollection <IScheduledResource> resources;
                using (var model = SchedulerFactory.CreateModel(GlobalConstants.SchedulerFolderId, SecurityWrapper))
                {
                    resources = model.GetScheduledResources();
                }

                var sb = new StringBuilder(JsonConvert.SerializeObject(resources, Formatting.Indented, new JsonSerializerSettings
                {
                    TypeNameHandling       = TypeNameHandling.Objects,
                    TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
                }));
                return(sb);
            }
            catch (Exception err)
            {
                Dev2Logger.Log.Error(err);
                throw;
            }
        }