// confirms that it is valid to create a new activity with the given name and parent
        private string ValidateCandidateNewInheritance(Inheritance inheritance)
        {
            ActivityDescriptor childDescriptor = inheritance.ChildDescriptor;

            if (childDescriptor == null)
            {
                return("Child name is required");
            }
            Activity existingChild = this.ResolveDescriptor(childDescriptor);

            if (existingChild != null)
            {
                return("Child " + existingChild.Name + " already exists");
            }
            ActivityDescriptor parentDescriptor = inheritance.ParentDescriptor;

            if (parentDescriptor == null)
            {
                return("Parent name is required: try \"Activity\"");
            }
            Activity parent = this.ResolveDescriptor(parentDescriptor);

            if (parent == null)
            {
                return("Parent " + parentDescriptor.ActivityName + " does not exist");
            }
            if (parent is ToDo)
            {
                return("Parent " + parentDescriptor.ActivityName + " is a ToDo which cannot have child activities");
            }
            return("");
        }
        public string AddParent(Inheritance inheritance)
        {
            if (inheritance.ChildDescriptor == null)
            {
                return("Child name is required");
            }
            Activity child = this.ResolveDescriptor(inheritance.ChildDescriptor);

            if (child == null)
            {
                return("Child " + inheritance.ChildDescriptor.ActivityName + " does not exist");
            }
            if (inheritance.ParentDescriptor == null)
            {
                return("Parent name is required: try \"Activity\"");
            }
            Activity parent = this.ResolveDescriptor(inheritance.ParentDescriptor);

            if (parent == null)
            {
                return("Parent " + inheritance.ParentDescriptor.ActivityName + " does not exist");
            }
            Category parentCategory = parent as Category;

            if (parentCategory != null)
            {
                if (child is Problem && child.Parents.Count == 0 && parentCategory != this.problemCategory)
                {
                    // If the first parent added to a Problem is neither a Problem nor this.problemCategory, then add this.problemCategory as a parent
                    child.AddParent(this.problemCategory);
                }
                child.AddParent(parentCategory);
            }
            else
            {
                Problem parentProblem = parent as Problem;
                if (parentProblem != null)
                {
                    child.AddParent(parentProblem);
                    if (!(child is Problem))
                    {
                        this.hasSolution = true;
                    }
                }
                else
                {
                    return("Parent " + parent.Name + " is not of type Category or Problem");
                }
            }
            if (this.InheritanceAdded != null)
            {
                this.InheritanceAdded.Invoke(inheritance);
            }
            return("");
        }
        public void AddInheritance(Inheritance inheritance)
        {
            this.GetActivityOrCreateCategory(inheritance.ChildDescriptor);
            this.GetActivityOrCreateCategory(inheritance.ParentDescriptor);
            string message = this.AddParent(inheritance);

            if (message != "")
            {
                throw new ArgumentException(message);
            }
        }
Exemple #4
0
 public override void PostInheritance(Inheritance newInheritance)
 {
     if (this.include(newInheritance.ChildDescriptor))
     {
         base.PostInheritance(newInheritance);
     }
     else
     {
         System.Diagnostics.Debug.WriteLine("Deleting " + newInheritance);
     }
 }
        public string CreateProblem(Inheritance inheritance)
        {
            string err = this.ValidateCandidateNewInheritance(inheritance);

            if (err != "")
            {
                return(err);
            }
            Problem problem = this.CreateProblem(inheritance.ChildDescriptor);

            return(this.AddParent(inheritance));
        }
        public string CreateToDo(Inheritance inheritance)
        {
            string err = this.ValidateCandidateNewInheritance(inheritance);

            if (err != "")
            {
                return(err);
            }
            ToDo     toDo   = this.CreateToDo(inheritance.ChildDescriptor);
            Activity parent = this.ResolveDescriptor(inheritance.ParentDescriptor);

            if (parent == this.todoCategory || parent == this.rootActivity)
            {
                return(""); // don't have to add the same parent twice
            }
            return(this.AddParent(inheritance));
        }
        // returns a string other than "" in case of error
        public string CreateCategory(Inheritance inheritance)
        {
            string err = this.ValidateCandidateNewInheritance(inheritance);

            if (err != "")
            {
                return(err);
            }
            Activity parent = this.ResolveDescriptor(inheritance.ParentDescriptor);

            if (parent == this.todoCategory || parent == this.problemCategory)
            {
                return("You can't assign an Activity of type Category as a child of the Category named " + parent.Name);
            }
            ActivityDescriptor childDescriptor = inheritance.ChildDescriptor;
            Activity           child           = this.CreateCategory(inheritance.ChildDescriptor);

            return(this.AddParent(inheritance));
        }
Exemple #8
0
        private void OkButton_Clicked(object sender, EventArgs e)
        {
            ActivityDescriptor childDescriptor  = this.childNameBox.ActivityDescriptor;
            ActivityDescriptor parentDescriptor = this.parentNameBox.ActivityDescriptor;
            Inheritance        inheritance      = new Inheritance(parentDescriptor, childDescriptor);

            inheritance.DiscoveryDate = DateTime.Now;

            string error = this.activityDatabase.AddParent(inheritance);

            if (error == "")
            {
                this.childNameBox.Clear();
                this.parentNameBox.Clear();
                this.feedbackLayout.setText(childDescriptor.ActivityName + " now inherits from " + parentDescriptor.ActivityName);
            }
            else
            {
                this.feedbackLayout.setText(error);
            }
        }
Exemple #9
0
        private void OkButton_Clicked(object sender, EventArgs e)
        {
            ActivityDescriptor childDescriptor  = this.childNameBox.ActivityDescriptor;
            ActivityDescriptor parentDescriptor = this.parentNameBox.ActivityDescriptor;
            Inheritance        inheritance      = new Inheritance(parentDescriptor, childDescriptor);

            inheritance.DiscoveryDate = DateTime.Now;

            string error;

            if (this.SelectedActivityTypeIsCategory || this.SelectedActivityTypeIsSolution)
            {
                error = this.activityDatabase.CreateCategory(inheritance);
            }
            else
            {
                if (this.SelectedActivityTypeIsToDo)
                {
                    error = this.activityDatabase.CreateToDo(inheritance);
                }
                else
                {
                    error = this.activityDatabase.CreateProblem(inheritance);
                }
            }
            if (error == "")
            {
                this.childNameBox.Clear();
                this.parentNameBox.Clear();
                this.showMessage("Created " + childDescriptor.ActivityName);
                if (this.GoBackAfterCreation)
                {
                    this.layoutStack.GoBack();
                }
            }
            else
            {
                this.showError(error);
            }
        }
Exemple #10
0
        public override void PostInheritance(Inheritance newInheritance)
        {
            string text = this.textConverter.ConvertToString(newInheritance);

            this.addText(text);
        }
Exemple #11
0
 public virtual void PostInheritance(Inheritance newInheritance)
 {
 }
Exemple #12
0
 public void AddInheritance(Inheritance newInheritance)
 {
     this.engine.PutInheritanceInMemory(newInheritance);
     this.updatedAfterInheritances = false;
     this.PostInheritance(newInheritance);
 }