Ejemplo n.º 1
0
        internal FixedList <Activity> GetContainedModelDependencies(Activity activityModel)
        {
            if (activityModel.IsEmptyInstance)
            {
                return(new FixedList <Activity>());
            }

            var templateProject = activityModel.Project;

            try {
                List <Activity> dependencies = templateProject.GetItems()
                                               .Select(x => (Activity)x)
                                               .ToList();

                return(dependencies.FindAll(x => x.Template.DueOnControllerId == activityModel.Id &&
                                            this.StateChanges.Exists(y => y.Template.Id == x.Id))
                       .ToFixedList());
            } catch (Exception e) {
                var ex = new Exception($"GetContainedModelDependencies issue for {activityModel.Id}.", e);

                EmpiriaLog.Error(ex);

                throw ex;
            }
        }
Ejemplo n.º 2
0
        public SingleObjectModel RunMessagingService()
        {
            string a = $"Running messaging services using Azure web jobs at {DateTime.Now.ToShortTimeString()}.";

            EmpiriaLog.Debug(a);

            return(new SingleObjectModel(this.Request, a));
        }
        public PagedCollectionModel GetMyLastESignEvents([FromUri] string keywords = "")
        {
            try {
                FixedList <SignEventDTO> events = ESignUseCases.GetMyLastESignEvents(keywords);

                return(new PagedCollectionModel(this.Request, events, typeof(SignEventDTO).FullName));
            } catch (Exception e) {
                EmpiriaLog.Error(e);

                throw base.CreateHttpException(e);
            }
        }
Ejemplo n.º 4
0
 static public void Preload()
 {
     try {
         EmpiriaLog.Info($"Application preloading starts at {DateTime.Now}.");
         StandardAccount.Preload();
         AccountsChart.Preload();
         SubsidiaryLedger.Preload();
         SubsidiaryAccount.Preload();
         EmpiriaLog.Info($"Application preloading ends at {DateTime.Now}.");
     } catch (Exception e) {
         EmpiriaLog.Error(e);
     }
 }
Ejemplo n.º 5
0
        static public void RemindActivity(Activity activity, JsonObject sendTo)
        {
            EmpiriaLog.Critical(sendTo.ToString());

            if (activity.Deadline == ExecutionServer.DateMaxValue)
            {
                return;
            }

            var content = EMailContentBuilder.RemindActivityContent(activity.Project, activity);

            FixedList <Person> contacts = GetContacts(sendTo, "sendAlertsTo");

            SendEmail(content, contacts);


            string[] additional = GetAddresses(sendTo, "sendAlertsToEMails");
            SendEmail(content, additional);
        }
Ejemplo n.º 6
0
        internal ProjectItem ChangeParentAndPosition(ProjectItem item, ProjectItem newParent, int newPosition)
        {
            EmpiriaLog.Debug($"ChangeParent of {item.Name} to new parent {newParent.Name}");

            if (item.Equals(newParent))
            {
                EmpiriaLog.Info($"Trying to change the parent of a tree item to itself {item.Name} ({item.UID}).");

                return(item);
            }

            var branchToMove = this.GetBranch(item);

            Assertion.Require(!branchToMove.Contains(newParent),
                              $"Can't change the parent of '{item.Name}' because it is a branch " +
                              $"and '{newParent.Name}' is one of its children.");

            // Then remove the whole branch an reinsert it in the new position
            foreach (var branchItem in branchToMove)
            {
                ItemsList.Remove(branchItem);
            }

            item.SetParentAndPosition(newParent, newPosition);

            int insertionIndex = newPosition - 1; // insertionIndex is zero-based

            foreach (var branchItem in branchToMove)
            {
                ItemsList.Insert(insertionIndex, branchItem);

                insertionIndex++;
            }

            this.RefreshPositions();

            EmpiriaLog.Info($"ChangeParentAndPosition of {item.Name} to {newParent.Name} at position {newParent.Position + 1}.");

            return(item);
        }
Ejemplo n.º 7
0
        internal ProjectItem ChangePosition(ProjectItem item, int newPosition)
        {
            EmpiriaLog.Debug($"ChangePosition of {item.Name} in position {item.Position} to new position {newPosition}");

            var branchToMove = this.GetBranch(item);

            Assertion.Require(newPosition <branchToMove[0].Position ||
                                           newPosition> branchToMove[branchToMove.Count - 1].Position,
                              "Can't move item because it's a branch and the requested new position is inside it.");

            int insertionIndex = Math.Min(newPosition - 1, this.ItemsList.Count);

            // Get the insertion point before item position
            ProjectItem insertBeforeItem = insertionIndex < this.ItemsList.Count ? this.ItemsList[insertionIndex] : null;

            // Then remove the whole branch an reinsert it in the new position
            foreach (var branchItem in branchToMove)
            {
                ItemsList.Remove(branchItem);
            }

            // Recalculate the new insertion index
            insertionIndex = insertBeforeItem != null?this.ItemsList.IndexOf(insertBeforeItem) : this.ItemsList.Count;

            var newParent = insertBeforeItem != null ? insertBeforeItem.Parent : ProjectItem.Empty;

            item.SetParentAndPosition(newParent, insertionIndex);

            foreach (var branchItem in branchToMove)
            {
                ItemsList.Insert(insertionIndex, branchItem);

                insertionIndex++;
            }

            this.RefreshPositions();

            return(item);
        }
Ejemplo n.º 8
0
        internal ProjectItem ChangeParentKeepingPosition(ProjectItem item, ProjectItem newParent)
        {
            EmpiriaLog.Debug($"ChangeParent of {item.Name} to new parent {newParent.Name} keeping current position.");

            if (item.Equals(newParent))
            {
                EmpiriaLog.Info($"Trying to change the parent of a tree item to itself {item.Name} ({item.UID}).");

                return(item);
            }

            var branchToMove = this.GetBranch(item);

            Assertion.Require(!branchToMove.Contains(newParent),
                              $"Can't change the parent of '{item.Name}' because it is a branch " +
                              $"and '{newParent.Name}' is one of its children.");

            item.SetParent(newParent);
            item.Save();

            return(item);
        }
Ejemplo n.º 9
0
        internal ProjectItem MoveToInsertionPoint(ProjectItem itemToMove, TreeItemInsertionRule insertionRule,
                                                  ProjectItem insertionPoint = null, int relativePosition = -1)
        {
            switch (insertionRule)
            {
            case TreeItemInsertionRule.AsSiblingBeforeInsertionPoint:
                this.ChangeParentAndPosition(itemToMove, newParent: insertionPoint.Parent,
                                             newPosition: insertionPoint.Position);
                return(itemToMove);

            case TreeItemInsertionRule.AsSiblingAfterInsertionPoint:
                int branchLastItemPosition = GetBranchLastItem(insertionPoint).Position;

                this.ChangeParentAndPosition(itemToMove, newParent: insertionPoint.Parent,
                                             newPosition: branchLastItemPosition + 1);
                return(itemToMove);

            case TreeItemInsertionRule.AsChildAsFirstNode:
                this.ChangeParentAndPosition(itemToMove, newParent: insertionPoint,
                                             newPosition: insertionPoint.Position + 1);

                return(itemToMove);

            case TreeItemInsertionRule.AsChildAsLastNode:
                branchLastItemPosition = GetBranchLastItem(insertionPoint).Position;

                this.ChangeParentAndPosition(itemToMove, newParent: insertionPoint,
                                             newPosition: branchLastItemPosition + 1);

                return(itemToMove);

            case TreeItemInsertionRule.AsChildAtPosition:
                Assertion.Require(relativePosition > 0, "Relative position must be greater than zero.");

                this.ChangeParentAndPosition(itemToMove, newParent: insertionPoint,
                                             newPosition: insertionPoint.Position + 1 + relativePosition);
                return(itemToMove);

            case TreeItemInsertionRule.AsTreeRootAtStart:
                this.ChangePosition(itemToMove, 1);

                return(itemToMove);

            case TreeItemInsertionRule.AsTreeRootAtEnd:
                return(itemToMove);

            case TreeItemInsertionRule.AtRelativePosition:
                Assertion.Require(relativePosition > 0, "Relative position must be greater than zero.");

                int indexOfInsertionPoint = this.itemsList.IndexOf(insertionPoint);

                this.itemsList.Remove(itemToMove);

                itemToMove.SetPosition(indexOfInsertionPoint + relativePosition + 1);

                this.itemsList.Insert(indexOfInsertionPoint + relativePosition, itemToMove);

                EmpiriaLog.Trace($"Item {itemToMove.Name} inserted at position {indexOfInsertionPoint}/{relativePosition}: [{itemToMove.Position}] // {insertionPoint.Name}.");


                this.RefreshPositions();

                return(itemToMove);

            default:
                throw Assertion.EnsureNoReachThisCode($"Unrecognized insertion rule '{insertionRule.ToString()}'.");
            }
        }
Ejemplo n.º 10
0
        static private int SetNewActivityInsertionRule(ProjectItemStateChange toInsertActivity,
                                                       WhatIfResult current, WhatIfResult newModelResult)
        {
            int position = -1;

            var parent = current.StateChanges.Find(x => !x.ProjectItem.IsEmptyInstance &&
                                                   x.Template.UID == toInsertActivity.Template.Parent.UID);

            if (parent != null)
            {
                var newSiblings = current.StateChanges.FindAll(x => x.ProjectItem.IsEmptyInstance &&
                                                               x.ParentStateChange.UID == parent.UID);

                var parentIndex = current.StateChanges.IndexOf(parent);

                var currentSiblings = current.StateChanges.FindAll(x => !x.ProjectItem.IsEmptyInstance &&
                                                                   x.ProjectItem.Parent.UID == parent.ProjectItem.UID);

                if (currentSiblings.Count != 0)
                {
                    toInsertActivity.InsertionPoint = parent.ProjectItem;
                    toInsertActivity.InsertionRule  = TreeItemInsertionRule.AsChildAsLastNode;

                    position = parentIndex + currentSiblings.Count + newSiblings.Count + 1;

                    EmpiriaLog.Trace($"Rule 0: {toInsertActivity.Template.Name} at position {position}.");
                }
                else
                {
                    toInsertActivity.ParentStateChange = parent;

                    toInsertActivity.InsertionPoint = parent.ProjectItem;
                    toInsertActivity.InsertionRule  = TreeItemInsertionRule.AsChildAsLastNode;

                    position = parentIndex + newSiblings.Count + 1;

                    EmpiriaLog.Trace($"Rule 1: {toInsertActivity.Template.Name} at position {position}.");
                }
            }
            else
            {
                Assertion.Require(toInsertActivity.ParentStateChange, nameof(toInsertActivity.ParentStateChange));

                var newParent = current.StateChanges.Find(x => x.UID == toInsertActivity.ParentStateChange.UID);

                var newParentIdx = current.StateChanges.IndexOf(newParent);

                var currentSiblings = current.StateChanges.FindAll(x => x.ParentStateChange != null &&
                                                                   x.ParentStateChange.UID == toInsertActivity.ParentStateChange.UID);

                toInsertActivity.ParentStateChange = newParent;

                toInsertActivity.InsertionPoint = ProjectItem.Empty;
                toInsertActivity.InsertionRule  = TreeItemInsertionRule.AsChildAsLastNode;

                position = newParentIdx + currentSiblings.Count + 1;

                EmpiriaLog.Trace($"Rule 2: {toInsertActivity.Template.Name} at position {position}.");
            }

            return(position);
        }