Ejemplo n.º 1
0
        public bool StoreActivity(ActivityObj acObj)
        {
            try
            {
                var ac =
                    (from a in Activities
                     where a.Name == acObj.Name && a.Version == ConvertVersion(acObj.Version)
                     select a).SingleOrDefault();

                if (ac == null)
                {
                    ac = new Activity
                    {
                        Name        = acObj.Name,
                        Version     = ConvertVersion(acObj.Version),
                        Description = acObj.Description,
                        Json        = JsonConvert.SerializeObject(acObj)
                    };
                    Activities.InsertOnSubmit(ac);
                }

                ac.Json = JsonConvert.SerializeObject(acObj);
                SubmitChanges(ConflictMode.FailOnFirstConflict);
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create a task, its symbol data and shape when a Palette symbol is dropped on the diagram
        /// </summary>
        /// <param name="symbolType"></param>
        /// <param name="datum"></param>
        public TaskObj CreateTask(PaletteObj symbolType, Point datum)
        {
            var symbolTask = symbolType.Task;

            if (symbolTask.ActivityName == "cleanup" && Model.Workflow.Tasks.Any(t => t.ActivityName == "cleanup"))
            {
                MessageBox.Show("No more than one Cleanup Start symbol permitted");
                return(null);
            }
            ActivityObj activity = null;

            if (symbolTask.HasActivity())
            {
                var json = RestClient.Get($"/activities/{symbolTask.ActivityName}/versions/{symbolTask.ActivityVersion}");
                activity = JsonConvert.DeserializeObject <ActivityObj>(json);

                if (activity == null)
                {
                    MessageBox.Show($"Missing activity - {symbolTask.ActivityName} {symbolTask.ActivityVersion}", "Database error");
                    return(null);
                }
            }

            var task = new TaskObj
            {
                TaskId          = Guid.NewGuid().ToString().Substring(0, 8),
                ActivityName    = symbolTask.ActivityName,
                ActivityVersion = symbolTask.ActivityVersion,
                Outflows        = (from f in symbolTask.Outflows
                                   select new FlowObj {
                    Name = f.Name
                }).ToArray(),
                Symbol      = CloneSymbol(symbolTask.Symbol),
                FailOutflow = new FlowObj {
                    Name = "Err"
                },
                HiddenProperties = symbolTask.HiddenProperties
            };

            if (activity != null)
            {
                task.Inputs = new InputCollection(activity.Inputs);
                if (task.Outflows.Length != 0)
                {
                    task.Outputs = new OutputCollection(activity.Outputs);
                }
            }

            // Override or add inputs with data from palette symbol
            if (symbolTask.Inputs != null)
            {
                foreach (var input in symbolTask.Inputs)
                {
                    task.Inputs[input.Key] = input.Value;
                }
            }

            // Override or add outputs with data from palette symbol
            if (symbolTask.Outputs != null)
            {
                foreach (var output in symbolTask.Outputs)
                {
                    task.Outputs[output.Key] = output.Value;
                }
            }

            task.Symbol.Shape = Shape.Create(task.Symbol.Style, task, datum);

            if (symbolTask.HasFailOutflow())
            {
                task.FailOutflow = new FlowObj {
                    Name = "Err"
                };
            }

            Model.Workflow.Tasks.Add(task);
            task.TaskChanged += UpdateGraphics;

            return(task);
        }