Exemple #1
0
        public void TestActivityVariablesSyncWithRepo_v2()
        {
            string variableName = "ACTVAR2";
            string initialValue = "123";
            string updatedValue = "abc123";

            mBF = new BusinessFlow()
            {
                Name = "TestActvVarSyncV2", Active = true
            };
            mBF.Activities = new ObservableList <Activity>();

            VariableString V1 = new VariableString()
            {
                Name = variableName, InitialStringValue = initialValue
            };

            // add variable to the activity
            Activity activity = new Activity()
            {
                ActivityName = "Activity1"
            };

            activity.AddVariable(V1);
            mBF.Activities.Add(activity);

            // add business flow to the solution repository
            mSolutionRepository.AddRepositoryItem(mBF);

            // prepare to add the variable to the shared repository
            UploadItemSelection uploadItemSelection = new UploadItemSelection()
            {
                UsageItem = V1, ItemUploadType = UploadItemSelection.eItemUploadType.New
            };

            (new SharedRepositoryOperations()).UploadItemToRepository(new Context()
            {
                BusinessFlow = mBF
            }, uploadItemSelection);

            // find the newly added variable in the shared repo
            VariableBase   sharedVariableBase = (from x in mSolutionRepository.GetAllRepositoryItems <VariableBase>() where x.Name == variableName select x).SingleOrDefault();
            VariableString sharedV1           = (VariableString)sharedVariableBase;

            //update the new value in the shared repo variable
            sharedV1.InitialStringValue = updatedValue;

            //sync the updated instance with the business flow instance
            sharedV1.UpdateInstance(V1, "All", mBF.Activities[0]);

            // get the updated value from the business flow
            VariableString V2 = (VariableString)mBF.Activities[0].Variables[0];

            //Assert
            Assert.AreEqual(1, mBF.Activities.Count);
            Assert.AreEqual(1, mBF.Activities[0].Variables.Count);
            Assert.AreNotSame(V1, V2);
            Assert.AreEqual(updatedValue, V2.InitialStringValue);
        }
        public Boolean UploadItemToRepository(Context context, UploadItemSelection itemToUpload)
        {
            try
            {
                RepositoryItemBase item         = itemToUpload.UsageItem;
                string             itemFileName = string.Empty;
                RepositoryItemBase itemCopy     = null;
                bool isOverwrite = false;
                if (itemToUpload.ItemUploadType == UploadItemSelection.eItemUploadType.Overwrite)
                {
                    isOverwrite = true;
                    itemCopy    = GetItemToOverrite(itemToUpload);
                }
                else
                {
                    itemCopy = (RepositoryItemBase)item.CreateCopy(false);
                }

                itemCopy.UpdateItemFieldForReposiotryUse();



                bool blockingIssuesHandled = HandleItemValidationIssues(context, itemToUpload, itemCopy, ref isOverwrite);

                if (blockingIssuesHandled == false)
                {
                    itemToUpload.ItemUploadStatus = UploadItemSelection.eItemUploadStatus.FailedToUpload;
                    return(false);
                }

                if (isOverwrite)
                {
                    WorkSpace.Instance.SolutionRepository.MoveSharedRepositoryItemToPrevVersion(itemToUpload.ExistingItem);

                    RepositoryFolderBase repositoryFolder = WorkSpace.Instance.SolutionRepository.GetRepositoryFolderByPath(itemToUpload.ExistingItem.ContainingFolderFullPath);
                    repositoryFolder.AddRepositoryItem(itemCopy);
                }
                else
                {
                    WorkSpace.Instance.SolutionRepository.AddRepositoryItem(itemCopy);
                }

                itemToUpload.UsageItem.IsSharedRepositoryInstance = true;

                if (itemToUpload.ExistingItemType == UploadItemSelection.eExistingItemType.ExistingItemIsParent && itemToUpload.ItemUploadType == UploadItemSelection.eItemUploadType.New)
                {
                    itemToUpload.UsageItem.ParentGuid = Guid.Empty;
                }

                itemToUpload.ItemUploadStatus = UploadItemSelection.eItemUploadStatus.Uploaded;
                return(true);
            }
            catch (Exception e)
            {
                Reporter.ToLog(eLogLevel.ERROR, "failed to upload the repository item", e);
                itemToUpload.ItemUploadStatus = UploadItemSelection.eItemUploadStatus.FailedToUpload;
                return(false);
            }
        }
        private bool HandleItemValidationIssues(Context context, UploadItemSelection selectedItem, RepositoryItemBase itemCopy, ref bool isOverwrite)
        {
            bool blockingIssuesHandled           = true;
            List <ItemValidationBase> itemIssues = ItemValidationBase.GetAllIssuesForItem(selectedItem);

            if (itemIssues != null && itemIssues.Count > 0)
            {
                foreach (ItemValidationBase issue in itemIssues)
                {
                    switch (issue.mIssueType)
                    {
                    case ItemValidationBase.eIssueType.MissingVariables:
                        if (issue.Selected)
                        {
                            foreach (string missingVariableName in issue.missingVariablesList)
                            {
                                VariableBase missingVariable = context.BusinessFlow.GetHierarchyVariableByName(missingVariableName);

                                if (missingVariable != null)
                                {
                                    ((Activity)itemCopy).Variables.Add(missingVariable);
                                }
                            }

                            selectedItem.Comment = "Missing " + GingerDicser.GetTermResValue(eTermResKey.Variable) + " added to " + GingerDicser.GetTermResValue(eTermResKey.Activity);
                        }
                        else
                        {
                            selectedItem.Comment = "Uploaded without adding missing " + GingerDicser.GetTermResValue(eTermResKey.Variables);
                        }
                        break;

                    case ItemValidationBase.eIssueType.DuplicateName:
                        if (issue.Selected)
                        {
                            isOverwrite          = false;
                            itemCopy.ItemName    = issue.ItemNewName;
                            selectedItem.Comment = "Uploaded with new newm" + issue.ItemNewName;
                        }
                        else
                        {
                            selectedItem.Comment  = "Can not upload the item with same name";
                            blockingIssuesHandled = false;    // if user do not accept new name, upload can not proceed for the item
                        }
                        break;
                    }
                }
            }
            return(blockingIssuesHandled);
        }
        private UploadItemSelection CreateUploadItem(RepositoryItemBase item)
        {
            string strComment = "";
            UploadItemSelection uploadItem = new UploadItemSelection();

            uploadItem.Selected = true;

            UploadItemSelection.eExistingItemType existingItemType = UploadItemSelection.eExistingItemType.NA;
            RepositoryItemBase existingItem = ExistingItemCheck(item, ref strComment, ref existingItemType);

            if (existingItem != null)
            {
                uploadItem.ItemUploadType   = UploadItemSelection.eItemUploadType.Overwrite;
                uploadItem.ExistingItem     = existingItem;
                uploadItem.ExistingItemType = existingItemType;
                uploadItem.Comment          = strComment;
            }
            else
            {
                uploadItem.ItemUploadType = UploadItemSelection.eItemUploadType.New;
            }

            if (item is Activity)
            {
                Activity activity = (Activity)item;

                if (activity.ActivitiesGroupID != null && activity.ActivitiesGroupID != string.Empty)
                {
                    ActivitiesGroup group = (ActivitiesGroup)Context.BusinessFlow.ActivitiesGroups.Where(x => x.Name == activity.ActivitiesGroupID).FirstOrDefault();
                    if (group != null)
                    {
                        ObservableList <ActivitiesGroup> repoGroups = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems <ActivitiesGroup>();
                        ActivitiesGroup repoGroup = repoGroups.Where(x => (x.Guid == group.Guid) || (x.Guid == group.ParentGuid) || (group.ExternalID != null &&
                                                                                                                                     group.ExternalID != string.Empty && x.ExternalID == group.ExternalID)).FirstOrDefault();
                        if (repoGroup == null)
                        {
                            uploadItem.Comment = "It is recommended to also add parent activity group: " + group.ItemName + " to repository";
                        }
                    }
                }
            }

            uploadItem.ItemName = item.ItemName;
            uploadItem.ItemGUID = item.Guid;
            uploadItem.SetItemPartesFromEnum(GetTypeOfItemParts(item));
            uploadItem.UsageItem = item;

            return(uploadItem);
        }
Exemple #5
0
        public void TestBusinessFlowVariableSyncWithRepo()
        {
            string variableName = "BFV1";
            string initialValue = "123";
            string updatedValue = "abc123";

            mBF = new BusinessFlow()
            {
                Name = "TestBFVarSync", Active = true
            };

            VariableString V1 = new VariableString()
            {
                Name = variableName, InitialStringValue = initialValue
            };

            mBF.AddVariable(V1);

            // add business flow to the solution repository
            mSolutionRepository.AddRepositoryItem(mBF);

            // prepare to add the variable to the shared repository
            UploadItemSelection uploadItemSelection = new UploadItemSelection()
            {
                UsageItem = V1, ItemUploadType = UploadItemSelection.eItemUploadType.New
            };

            SharedRepositoryOperations.UploadItemToRepository(uploadItemSelection);

            // find the newly added variable from the shared repo
            VariableBase   sharedVariableBase = (from x in mSolutionRepository.GetAllRepositoryItems <VariableBase>() where x.Name == variableName select x).SingleOrDefault();
            VariableString sharedV1           = (VariableString)sharedVariableBase;

            //update the new value in the shared repo variable
            sharedV1.InitialStringValue = updatedValue;

            //sync the updated instance with the business flow instance
            sharedV1.UpdateInstance(V1, "All", mBF);

            // get the updated value from the business flow
            VariableString V2 = (VariableString)mBF.Variables[0];

            //Assert
            Assert.AreEqual(1, mBF.Variables.Count);
            Assert.AreNotSame(V1, V2);
            Assert.AreEqual(updatedValue, V2.InitialStringValue);
        }
Exemple #6
0
        public static void Validate(UploadItemSelection selectedItem)
        {
            bool isDuplicateFound = CheckForItemWithDuplicateName(selectedItem);

            if (isDuplicateFound)
            {
                ItemValidationBase VA = ItemValidationBase.CreateNewIssue((RepositoryItemBase)selectedItem.UsageItem);
                VA.IssueDescription = "Item with same name already exists";
                VA.mIssueType       = ItemValidationBase.eIssueType.DuplicateName;
                VA.ItemNewName      = GetUniqueItemName(selectedItem);
                VA.IssueResolution  = "Item will be uploaded with new name: " + VA.ItemNewName;
                VA.Selected         = true;
                ItemValidationBase.mIssuesList.Add(VA);
            }
            switch (selectedItem.UsageItem.GetType().Name)
            {
            case "Activity":
                ValidateActivity.Validate((Activity)selectedItem.UsageItem);
                break;
            }
        }
Exemple #7
0
        public static string GetUniqueItemName(UploadItemSelection duplicateItem)
        {
            List <string>                 existingRepoItems = new List <string>();
            ObservableList <Activity>     activities        = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems <Activity>();
            ObservableList <Act>          actions           = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems <Act>();
            ObservableList <VariableBase> variables         = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems <VariableBase>();

            ObservableList <ActivitiesGroup> activitiesGroup = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems <ActivitiesGroup>();

            if (duplicateItem.UsageItem is ActivitiesGroup)
            {
                existingRepoItems = activitiesGroup.Select(x => x.ItemName).ToList();
            }
            else if (duplicateItem.UsageItem is Activity)
            {
                existingRepoItems = activities.Select(x => x.ItemName).ToList();
            }
            else if (duplicateItem.UsageItem is Act)
            {
                existingRepoItems = actions.Select(x => x.ItemName).ToList();
            }
            else if (duplicateItem.UsageItem is VariableBase)
            {
                existingRepoItems = variables.Select(x => x.ItemName).ToList();
            }

            string newItemName = duplicateItem.ItemName;

            while (true)
            {
                newItemName += "_copy";

                if (!existingRepoItems.Contains(newItemName))
                {
                    return(newItemName);
                }
            }
            //TODO - find better way to get unique name
        }
Exemple #8
0
        public static bool CheckForItemWithDuplicateName(UploadItemSelection selectedItem)
        {
            List <RepositoryItemBase>        existingRepoItems = new List <RepositoryItemBase>();
            ObservableList <Activity>        activities        = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems <Activity>();
            ObservableList <Act>             SharedActions     = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems <Act>();
            ObservableList <VariableBase>    variables         = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems <VariableBase>();
            ObservableList <ActivitiesGroup> activitiesGroup   = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems <ActivitiesGroup>();

            if (selectedItem.UsageItem is ActivitiesGroup)
            {
                existingRepoItems = activitiesGroup.Cast <RepositoryItemBase>().ToList();
            }
            else if (selectedItem.UsageItem is Activity)
            {
                existingRepoItems = activities.Cast <RepositoryItemBase>().ToList();
            }
            else if (selectedItem.UsageItem is Act)
            {
                existingRepoItems = SharedActions.Cast <RepositoryItemBase>().ToList();
            }
            else if (selectedItem.UsageItem is VariableBase)
            {
                existingRepoItems = variables.Cast <RepositoryItemBase>().ToList();
            }

            if (selectedItem.ItemUploadType == UploadItemSelection.eItemUploadType.Overwrite)
            {
                existingRepoItems.Remove(selectedItem.ExistingItem);
            }

            foreach (object o in existingRepoItems)
            {
                if (((RepositoryItemBase)o).GetNameForFileName() == selectedItem.ItemName)
                {
                    return(true);
                }
            }
            return(false);
        }
        private static RepositoryItemBase GetItemToOverrite(UploadItemSelection itemToUpload)
        {
            RepositoryItemBase itemCopy = itemToUpload.UsageItem.GetUpdatedRepoItem(itemToUpload.UsageItem, itemToUpload.ExistingItem, itemToUpload.SelectedItemPart);

            switch (itemToUpload.ExistingItemType)
            {
            case UploadItemSelection.eExistingItemType.ExistingItemIsParent:
                itemCopy.Guid       = itemToUpload.ExistingItem.Guid;
                itemCopy.ParentGuid = itemToUpload.ExistingItem.ParentGuid;
                itemCopy.ExternalID = itemToUpload.ExistingItem.ExternalID;

                break;

            case UploadItemSelection.eExistingItemType.ExistingItemIsExternalID:

                break;

            case UploadItemSelection.eExistingItemType.ExistingItemIsDuplicate:

                break;
            }

            return(itemCopy);
        }
Exemple #10
0
 public new static void Validate(UploadItemSelection selectedItem)
 {
 }
Exemple #11
0
        public static Boolean UploadItemToRepository(UploadItemSelection itemToUpload)
        {
            try
            {
                RepositoryItem item         = itemToUpload.UsageItem;
                string         itemFileName = string.Empty;
                RepositoryItem itemCopy     = null;
                bool           isOverwrite  = false;
                if (itemToUpload.ItemUploadType == UploadItemSelection.eItemUploadType.Overwrite)
                {
                    isOverwrite = true;
                    itemCopy    = GetItemToOverrite(itemToUpload);
                }
                else
                {
                    itemCopy = (RepositoryItem)item.CreateCopy(false);
                }

                itemCopy.UpdateItemFieldForReposiotryUse();

                bool blockingIssuesHandled = HandleItemValidationIssues(itemToUpload, itemCopy, ref isOverwrite);

                if (blockingIssuesHandled == false)
                {
                    itemToUpload.ItemUploadStatus = UploadItemSelection.eItemUploadStatus.FailedToUpload;
                    return(false);
                }

                if (isOverwrite)
                {
                    App.LocalRepository.MovePrevVersion(itemToUpload.ExistingItem, itemToUpload.ExistingItem.FileName);
                    App.LocalRepository.RemoveItemFromCache(itemToUpload.ExistingItem);
                    itemFileName = itemToUpload.ExistingItem.FileName;
                }
                else
                {
                    itemFileName = LocalRepository.GetRepoItemFileName(itemCopy, Path.Combine(App.UserProfile.Solution.Folder, LocalRepository.GetSharedRepoItemTypeFolder(itemCopy.GetType())));
                }

                itemCopy.SaveToFile(itemFileName);

                App.LocalRepository.AddRepoItemToCache(itemCopy);


                itemToUpload.UsageItem.IsSharedRepositoryInstance = true;

                if (itemToUpload.ExistingItemType == UploadItemSelection.eExistingItemType.ExistingItemIsParent && itemToUpload.ItemUploadType == UploadItemSelection.eItemUploadType.New)
                {
                    itemToUpload.UsageItem.ParentGuid = Guid.Empty;
                }

                itemToUpload.ItemUploadStatus = UploadItemSelection.eItemUploadStatus.Uploaded;
                return(true);
            }
            catch (Exception e)
            {
                Reporter.ToLog(eLogLevel.ERROR, "failed to upload the repository item", e);
                itemToUpload.ItemUploadStatus = UploadItemSelection.eItemUploadStatus.FailedToUpload;
                return(false);
            }
        }