Exemplo n.º 1
0
        internal void complete(PointF point, FlowChart fc)
        {
            cycleRoots.Clear();
            affectedArrows.Clear();
            completing = true;

            // someone might have deleted the item from a selection- change event
            if (currentObject == null)
            {
                return;
            }

            if (action == Action.Create)
            {
                currentObject.completeCreate(point);

                // someone might have deleted the item in itemCreated handler
                if (itemDeleted)
                {
                    return;
                }

                invalidRect = Utilities.unionRects(
                    invalidRect, currentObject.getRepaintRect(true));
                fc.Dirty = true;

                if (currentObject.getType() != ItemType.Selection)
                {
                    // add to the diagram
                    AddItemCmd cmd = new AddItemCmd(currentObject);
                    cmd.Execute();
                    fc.fireObjCreated(currentObject);

                    // select the new item if SelectAfterCreate == true;
                    // check for null because people just love to delete currObject
                    // from within its xCreated or xActivated event handlers
                    if (fc.SelectAfterCreate && currentObject != null && !itemDeleted)
                    {
                        invalidRect = Utilities.unionRects(
                            invalidRect, fc.Selection.getRepaintRect(true));
                        fc.Selection.Change(currentObject);
                        if (currentObject != null)
                        {
                            invalidRect = Utilities.unionRects(
                                invalidRect, currentObject.getRepaintRect(true));
                        }
                    }

                    if (fc.UndoManager.UndoEnabled)
                    {
                        cmd.saveSelState();
                    }
                }
            }
            else
            {
                currentObject.completeModify(point, this);
                fc.UndoManager.onCompleteModify();
                if (!itemDeleted)
                {
                    invalidRect = Utilities.unionRects(invalidRect,
                                                       currentObject.getRepaintRect(true));
                }
                fc.Dirty = true;
            }
        }
        public override int Run(string[] remainingArguments)
        {
            if (EntityType.ToLower() == "task")
            {
                SparkTask taskToAdd = new SparkTask();
                taskToAdd.Description = Description;
                int duration;
                if (int.TryParse(Duration, out duration))
                {
                    if (duration <= 0)
                    {
                        Console.WriteLine("The duration must be a number grather than 0");
                        return(0);
                    }
                    taskToAdd.Duration = duration;
                }
                else
                {
                    Console.WriteLine("The duration must be an integer");
                    return(0);
                }
                taskToAdd.Client    = Client;
                taskToAdd.StartDate = DateTime.Now;
                taskToAdd.State     = TaskState.Paused;


                AddItemCmd addItemCmd = new AddItemCmd();

                addItemCmd.ItemToWork = taskToAdd;

                var result = addItemCmd.AddItem();
                Console.WriteLine(result);
                return(0);
            }

            if (EntityType.ToLower() == "reminder")
            {
                Reminder reminderToAdd = new Reminder();
                reminderToAdd.Description = Description;
                int interval;
                if (int.TryParse(Duration, out interval))
                {
                    if (interval <= 0)
                    {
                        Console.WriteLine("The duration must be a number grather than 0");
                        return(0);
                    }
                    reminderToAdd.Interval = interval;
                }
                else
                {
                    Console.WriteLine("The duration must be an integer");
                    return(0);
                }



                String pattern = @"((?<hour>\d{2})\:(?<minutes>\d{2}))";
                var    regex = new Regex(pattern, RegexOptions.IgnoreCase);
                var    match = regex.Match(TimeOfActivation);
                int    hour, minutes;

                if (!int.TryParse(match.Groups["hour"].Value, out hour) || !int.TryParse(match.Groups["minutes"].Value, out minutes))
                {
                    Console.WriteLine("The hour has to be numbers");
                    return(0);
                }

                if (int.TryParse(match.Groups["hour"].Value, out hour))
                {
                    if (hour < 00 && hour > 23)
                    {
                        Console.WriteLine("The hours must be between 00 and 23");
                        return(0);
                    }
                }
                if (int.TryParse(match.Groups["minutes"].Value, out minutes))
                {
                    if (minutes < 00 && minutes > 59)
                    {
                        Console.WriteLine("minutes must be between 00 and 59");
                        return(0);
                    }
                }

                DateTime ActivationTime = DateTime.Now;
                TimeSpan ts             = new TimeSpan(hour, minutes, 0);
                ActivationTime = ActivationTime.Date + ts;

                reminderToAdd.TimeOfActivation = ActivationTime;
                reminderToAdd.Type             = ReminderType.Custom;
                reminderToAdd.Source           = ReminderSource.User;

                AddItemCmd addItemCmd = new AddItemCmd();

                addItemCmd.ItemToWork = reminderToAdd;


                var result = addItemCmd.AddItem();
                Console.WriteLine(result);
                return(0);
            }
            else
            {
                Console.WriteLine("The type of entity should be a task or reminder");
            }

            return(0);
        }