Esempio n. 1
0
        private static void AddCustomVariableGroups()
        {
            for (int i = 1; i <= TotalNumberOfEachEntityToCreate; i++)
            {
                CustomVariableGroup group = new CustomVariableGroup();

                group.Name = "group" + i;

                // For each group, add some custom variables. The first group will have one variable,
                // the second will have two, and so on...
                for (int x = 1; x <= i; x++)
                {
                    group.CustomVariables.Add(new CustomVariable()
                    {
                        Key = "k" + x, Value = "v" + x
                    });
                }

                CustomVariableGroupLogic.Save(group);
            }

            // Add a group with the Deleted property set to true. It shouldn't affect the other tests because
            // getting all the groups should exclude the deleted group.
            Guid uniqueGroupName             = Guid.NewGuid();
            CustomVariableGroup deletedGroup = new CustomVariableGroup();

            deletedGroup.Name    = uniqueGroupName.ToString();
            deletedGroup.Deleted = true;
            CustomVariableGroupLogic.Save(deletedGroup);
        }
Esempio n. 2
0
        private static void AddAppServers()
        {
            IEnumerable <InstallationEnvironment> environments = InstallationEnvironmentLogic.GetAll();

            for (int i = 1; i <= TotalNumberOfEachEntityToCreate; i++)
            {
                ApplicationServer server = new ApplicationServer();

                server.Name = "server" + i;
                server.InstallationEnvironment = environments.Where(x => x.LogicalOrder == 1).First();        // 1st env is dev
                server.Description             = "Description " + i;
                server.EnableDebugLogging      = false;

                Application app = ApplicationLogic.GetByName("app" + i);
                server.ApplicationsWithOverrideGroup.Add(new ApplicationWithOverrideVariableGroup()
                {
                    Enabled = true, Application = app
                });

                CustomVariableGroup group = CustomVariableGroupLogic.GetByName("group" + i);
                server.CustomVariableGroups.Add(group);

                ApplicationServerLogic.Save(server);
            }
        }
        private void DeleteVariableGroup()
        {
            if (!UserConfirmsDelete(this.SelectedCustomVariableGroup.Name))
            {
                return;
            }

            if (string.IsNullOrEmpty(this.SelectedCustomVariableGroup.Id))
            {
                // Group hasn't ever been saved. Just remove it from the list.
                this.CustomVariableGroups.Remove(this.SelectedCustomVariableGroup);
                return;
            }

            try
            {
                CustomVariableGroup deletedGroup = this.CustomVariableGroups.FirstOrDefault(x => x.Id == this.SelectedCustomVariableGroup.Id);

                using (var prestoWcf = new PrestoWcf <ICustomVariableGroupService>())
                {
                    prestoWcf.Service.DeleteGroup(deletedGroup);
                }

                this.CustomVariableGroups.Remove(deletedGroup);
            }
            catch (Exception ex)
            {
                ViewModelUtility.MainWindowViewModel.AddUserMessage(ex.Message);

                ShowUserMessage(ex.Message, ViewModelResources.ItemCannotBeDeletedCaption);

                return;
            }
        }
        public void GetByNameTest()
        {
            string name = "group8";

            CustomVariableGroup group = CustomVariableGroupLogic.GetByName(name);

            Assert.AreEqual(name, group.Name);
        }
Esempio n. 5
0
        private static void TestDataCall()
        {
            var cvg = new CustomVariableGroup();

            cvg.Id = "CustomVariableGroups/197";

            var data = new SandboxData();

            data.SetAsInitialDalInstanceAndCreateSession();
            SandboxData.VerifyGroupNotUsedByInstallationSummary(cvg);
        }
        private static void VerifyGroupNotUsedByInstallationSummary(CustomVariableGroup customVariableGroup)
        {
            // Note: Tried to use Contains() here, but Raven doesn't accept that, so Any() was used.
            EntityBase installationSummary = QuerySingleResultAndSetEtag(session => session.Query <InstallationSummary>()
                                                                         .FirstOrDefault(x => x.ApplicationWithOverrideVariableGroup.CustomVariableGroupIds.Any(y => y == customVariableGroup.Id)));

            if (installationSummary != null)
            {
                // Can't delete. An installation summary references this group.
                throw new InvalidOperationException("Group could not be deleted because it is included in an installation summary.");
            }
        }
        private static void VerifyGroupNotUsedByApp(CustomVariableGroup customVariableGroup)
        {
            EntityBase app = QuerySingleResultAndSetEtag(session => session.Query <Application>()
                                                         .Where(x => x.CustomVariableGroupIds.Any(y => y == customVariableGroup.Id))
                                                         .FirstOrDefault());

            if (app != null)
            {
                // Can't delete. An app references this group.
                throw new InvalidOperationException("Group could not be deleted because it is being used by an app.");
            }
        }
Esempio n. 8
0
        internal static void VerifyGroupNotUsedByInstallationSummary(CustomVariableGroup cvg)
        {
            // Contains() not supported in RavenDB:
            //EntityBase installationSummary = QuerySingleResultAndSetEtag(session => session.Query<InstallationSummary>()
            //        .FirstOrDefault(x => x.ApplicationWithOverrideVariableGroup.CustomVariableGroupIds.Contains(customVariableGroup.Id)));

            // So here is my attempt to work around that:
            EntityBase installationSummary = QuerySingleResultAndSetEtag(session => session.Query <InstallationSummary>()
                                                                         .FirstOrDefault(x => x.ApplicationWithOverrideVariableGroup.CustomVariableGroupIds.Any(y => y == cvg.Id)));

            Console.WriteLine(installationSummary == null);
        }
        private static void VerifyGroupNotUsedByServer(CustomVariableGroup customVariableGroup)
        {
            EntityBase server = QuerySingleResultAndSetEtag(session => session.Query <ApplicationServer>()
                                                            .Where(x => x.CustomVariableGroupIds.Any(y => y == customVariableGroup.Id) ||
                                                                   x.CustomVariableGroupIdsForAllAppWithGroups.Any(y => y == customVariableGroup.Id))
                                                            .FirstOrDefault());

            if (server != null)
            {
                // Can't delete. An app server, or app with group, references this group.
                throw new InvalidOperationException("Group could not be deleted because it is being used by an app server.");
            }
        }
        public CustomVariableGroup GetById(string id)
        {
            return(ExecuteQuery <CustomVariableGroup>(() =>
            {
                CustomVariableGroup customVariableGroup =
                    QuerySingleResultAndSetEtag(session => session
                                                .Include <CustomVariableGroup>(customGroup => customGroup.Id == id)
                                                .Load <CustomVariableGroup>(id))
                    as CustomVariableGroup;

                return customVariableGroup;
            }));
        }
        public CustomVariableGroup GetByName(string name)
        {
            return(ExecuteQuery <CustomVariableGroup>(() =>
            {
                CustomVariableGroup customVariableGroup =
                    QuerySingleResultAndSetEtag(session => session.Query <CustomVariableGroup>()
                                                .Customize(x => x.WaitForNonStaleResults())
                                                .Where(customGroup => customGroup.Name == name)
                                                .FirstOrDefault())
                    as CustomVariableGroup;

                return customVariableGroup;
            }));
        }
Esempio n. 12
0
 public CustomVariableGroup SaveGroup(CustomVariableGroup customVariableGroup)
 {
     return(Invoke(() =>
     {
         CustomVariableGroup existingGroup = null;
         if (!string.IsNullOrWhiteSpace(customVariableGroup.Id))
         {
             existingGroup = CustomVariableGroupLogic.GetById(customVariableGroup.Id);
         }
         CustomVariableGroupLogic.Save(customVariableGroup);
         PossiblySendCustomVariableGroupChangedEmail(existingGroup, customVariableGroup);
         return customVariableGroup;
     }));
 }
 public void Delete(CustomVariableGroup group)
 {
     try
     {
         using (var prestoWcf = new PrestoWcf <ICustomVariableGroupService>())
         {
             prestoWcf.Service.DeleteGroup(group);
         }
     }
     catch (Exception ex)
     {
         Logger.LogException(ex);
         throw Helper.CreateHttpResponseException(ex, "Error Deleting Variable Group");
     }
 }
Esempio n. 14
0
        internal static CustomVariableGroup CreateCustomVariableGroup(string rootName)
        {
            CustomVariableGroup group = new CustomVariableGroup();

            group.Name = rootName + " group";

            group.CustomVariables.Add(new CustomVariable()
            {
                Key = rootName + " key", Value = rootName + " value"
            });

            CustomVariableGroupLogic.Save(group);

            return(group);
        }
 public CustomVariableGroup Save(CustomVariableGroup group)
 {
     try
     {
         using (var prestoWcf = new PrestoWcf <ICustomVariableGroupService>())
         {
             return(prestoWcf.Service.SaveGroup(group));
         }
     }
     catch (Exception ex)
     {
         Logger.LogException(ex);
         throw Helper.CreateHttpResponseException(ex, "Error Saving Variable Group");
     }
 }
        private void UpdateCacheWithSavedItem(CustomVariableGroup savedGroup)
        {
            int index = this._customVariableGroups.ToList().FindIndex(x => x.Id == savedGroup.Id);

            System.Windows.Application.Current.Dispatcher.Invoke(() =>
            {
                if (index >= 0)
                {
                    this._customVariableGroups[index] = savedGroup;
                }
                else
                {
                    this._customVariableGroups.Add(savedGroup);
                }
            });
        }
        private void AddVariableGroup()
        {
            string newGroupName = "New group - " + Guid.NewGuid().ToString();

            var newGroup = new CustomVariableGroup()
            {
                Name = newGroupName
            };

            this.SelectedCustomVariableGroup = newGroup;

            SaveVariableGroup(null);

            //this.CustomVariableGroups.Add(newGroup);

            //this.SelectedCustomVariableGroup = this.CustomVariableGroups.FirstOrDefault(group => @group.Name == newGroupName);
        }
Esempio n. 18
0
        public static void Save(CustomVariableGroup customVariableGroup)
        {
            if (customVariableGroup == null)
            {
                throw new ArgumentNullException("customVariableGroup");
            }

            try
            {
                DataAccessFactory.GetDataInterface <ICustomVariableGroupData>().Save(customVariableGroup);
            }
            catch (ConcurrencyException ex)
            {
                LogicBase.SetConcurrencyUserSafeMessage(ex, customVariableGroup.Name);
                throw;
            }
        }
        public void Delete(CustomVariableGroup customVariableGroup)
        {
            if (customVariableGroup == null)
            {
                throw new ArgumentNullException("customVariableGroup");
            }

            VerifyGroupNotUsedByApp(customVariableGroup);

            VerifyGroupNotUsedByServer(customVariableGroup);

            VerifyGroupNotUsedByInstallationSummary(customVariableGroup);

            // Since there is no referential integrity in RavenDB, set Deleted to true and save.
            customVariableGroup.Deleted = true;
            new GenericData().Save(customVariableGroup);
        }
Esempio n. 20
0
        private static void PossiblySendCustomVariableGroupChangedEmail(CustomVariableGroup existingGroup, CustomVariableGroup newGroup)
        {
            if (ConfigurationManager.AppSettings["emailCustomVariableGroupChanges"].ToUpperInvariant() != "TRUE")
            {
                return;
            }

            string emailSubject = string.Format(CultureInfo.CurrentCulture,
                                                "{0} saved a Presto Custom Variable Group: {1}",
                                                IdentityHelper.UserName,
                                                newGroup.Name);

            string emailBody =
                "Machine: " + Environment.MachineName + Environment.NewLine +
                "User: "******"emailToForCustomVariableGroupChanges");
        }
Esempio n. 21
0
        private static ApplicationServer CreateAppServer(string rootName, Application app, CustomVariableGroup group)
        {
            ApplicationServer server = new ApplicationServer();

            server.Name = rootName + " server";
            server.InstallationEnvironment = _defaultEnv;
            server.Description             = rootName + " server description";
            server.EnableDebugLogging      = false;

            server.ApplicationsWithOverrideGroup.Add(new ApplicationWithOverrideVariableGroup()
            {
                Enabled = true, Application = app
            });

            // Add the generic apps to the server, so we have more than just the one above.
            _genericApps.ForEach(x => server.ApplicationsWithOverrideGroup.Add(
                                     new ApplicationWithOverrideVariableGroup()
            {
                Enabled = true, Application = x
            }));

            server.CustomVariableGroups.Add(group);

            ApplicationServerLogic.Save(server);

            return(server);
        }
Esempio n. 22
0
 public void DeleteGroup(CustomVariableGroup customVariableGroup)
 {
     Invoke(() => CustomVariableGroupLogic.Delete(customVariableGroup));
 }
Esempio n. 23
0
        private void ImportApplication()
        {
            string filePathAndName = GetFilePathAndNameFromUser();

            if (string.IsNullOrWhiteSpace(filePathAndName))
            {
                return;
            }

            List <ApplicationWithOverrideVariableGroup> applicationsWithOverrideVariableGroup;

            using (FileStream fileStream = new FileStream(filePathAndName, FileMode.Open))
            {
                XmlSerializer xmlSerializer = new XmlSerializer(typeof(List <ApplicationWithOverrideVariableGroup>));
                try
                {
                    applicationsWithOverrideVariableGroup = xmlSerializer.Deserialize(fileStream) as List <ApplicationWithOverrideVariableGroup>;
                }
                catch (Exception ex)
                {
                    ViewModelUtility.MainWindowViewModel.AddUserMessage(string.Format(CultureInfo.CurrentCulture,
                                                                                      ViewModelResources.CannotImport));
                    CommonUtility.ProcessException(ex);
                    return;
                }
            }

            // When importing, get the apps and custom variable groups from the DB. We'll use those to populate the properties.
            using (var prestoWcf = new PrestoWcf <IApplicationService>())
            {
                foreach (ApplicationWithOverrideVariableGroup importedGroup in applicationsWithOverrideVariableGroup)
                {
                    importedGroup.Enabled = false;  // default

                    Application appFromDb;

                    appFromDb = prestoWcf.Service.GetByName(importedGroup.Application.Name);

                    if (appFromDb == null)
                    {
                        CannotImportGroup(importedGroup);
                        return;
                    }

                    importedGroup.Application = appFromDb;

                    if (importedGroup.CustomVariableGroups != null && importedGroup.CustomVariableGroups.Count > 0)
                    {
                        var importedGroupCustomVariableGroupNames = new List <string>();
                        importedGroup.CustomVariableGroups.ForEach(x => importedGroupCustomVariableGroupNames.Add(x.Name));
                        importedGroup.CustomVariableGroups.ClearItemsAndNotifyChangeOnlyWhenDone();

                        using (var prestoWcf2 = new PrestoWcf <ICustomVariableGroupService>())
                        {
                            foreach (string groupName in importedGroupCustomVariableGroupNames)
                            {
                                CustomVariableGroup groupFromDb = prestoWcf2.Service.GetCustomVariableGroupByName(groupName);
                                importedGroup.CustomVariableGroups.Add(groupFromDb);
                            }
                        }
                    }

                    this.SelectedApplicationServer.ApplicationsWithOverrideGroup.Add(importedGroup);
                }
            }

            SaveServer();
        }
Esempio n. 24
0
 public static void Delete(CustomVariableGroup customVariableGroup)
 {
     DataAccessFactory.GetDataInterface <ICustomVariableGroupData>().Delete(customVariableGroup);
 }
Esempio n. 25
0
        private static void TestFindingOneAppWithGroupOutOfMany()
        {
            var singleCvg = new CustomVariableGroup()
            {
                Id = "884"
            };
            var extraCvg1 = new CustomVariableGroup()
            {
                Id = "1"
            };
            var extraCvg2 = new CustomVariableGroup()
            {
                Id = "2"
            };
            var extraCvg3 = new CustomVariableGroup()
            {
                Id = "3"
            };
            var extraCvg4 = new CustomVariableGroup()
            {
                Id = "4"
            };

            var app1 = new Application()
            {
                Id = "atp"
            };
            var app2 = new Application()
            {
                Id = "fdp"
            };
            var app3 = new Application()
            {
                Id = "mrp"
            };

            var appWithGroup1 = new ApplicationWithOverrideVariableGroup()
            {
                Application = app1
            };
            var appWithGroup2 = new ApplicationWithOverrideVariableGroup()
            {
                Application = app2
            };
            var appWithGroup3 = new ApplicationWithOverrideVariableGroup()
            {
                Application = app3
            };

            var appWithGroup4 = new ApplicationWithOverrideVariableGroup()
            {
                Application = app1
            };

            appWithGroup4.CustomVariableGroups = new PrestoObservableCollection <CustomVariableGroup>();
            appWithGroup4.CustomVariableGroups.Add(extraCvg1);

            var appWithGroup5 = new ApplicationWithOverrideVariableGroup()
            {
                Application = app2
            };

            appWithGroup5.CustomVariableGroups = new PrestoObservableCollection <CustomVariableGroup>();
            appWithGroup5.CustomVariableGroups.Add(extraCvg1);
            appWithGroup5.CustomVariableGroups.Add(extraCvg2);

            var appWithGroup6 = new ApplicationWithOverrideVariableGroup()
            {
                Application = app1
            };

            appWithGroup6.CustomVariableGroups = new PrestoObservableCollection <CustomVariableGroup>();
            appWithGroup6.CustomVariableGroups.Add(extraCvg3);
            appWithGroup6.CustomVariableGroups.Add(extraCvg4);

            var appWithGroup7 = new ApplicationWithOverrideVariableGroup()
            {
                Application = app3
            };

            appWithGroup7.CustomVariableGroups = null;

            var appWithGroup8 = new ApplicationWithOverrideVariableGroup()
            {
                Application = app1
            };

            appWithGroup8.CustomVariableGroups = new PrestoObservableCollection <CustomVariableGroup>();
            appWithGroup8.CustomVariableGroups.Add(singleCvg);
            appWithGroup8.CustomVariableGroups.Add(extraCvg4);

            var appWithGroupList   = new List <ApplicationWithOverrideVariableGroup>();
            var appWithGroupToFind = appWithGroup8;

            appWithGroupList.Add(appWithGroup1);
            appWithGroupList.Add(appWithGroup2);
            appWithGroupList.Add(appWithGroup3);
            appWithGroupList.Add(appWithGroup4);
            appWithGroupList.Add(appWithGroup5);
            appWithGroupList.Add(appWithGroup6);
            appWithGroupList.Add(appWithGroup7);
            appWithGroupList.Add(appWithGroup8);

            var appWithGroupMatch = appWithGroupList.FirstOrDefault(groupFromList =>
                                                                    groupFromList.Application.Id == appWithGroupToFind.Application.Id &&
                                                                    groupFromList.CustomVariableGroups != null &&
                                                                    groupFromList.CustomVariableGroups.Count == appWithGroupToFind.CustomVariableGroups.Count &&
                                                                    groupFromList.CustomVariableGroups.Select(x => x.Id).All(appWithGroupToFind.CustomVariableGroups.Select(x => x.Id).Contains));

            // In the final line of the query above, we're selecting all of the IDs of each CVG and making sure the same IDs
            // exist in the appWithGroupToFind.

            if (appWithGroupMatch == null)
            {
                Console.WriteLine("No match found.");
                return;
            }

            Console.WriteLine(appWithGroupMatch.Application.Id);

            if (appWithGroupMatch.CustomVariableGroups != null)
            {
                appWithGroupMatch.CustomVariableGroups.ToList().ForEach(x => Console.WriteLine(x.Id));
            }
        }
 public void Save(CustomVariableGroup customVariableGroup)
 {
     new GenericData().Save(customVariableGroup);
 }
Esempio n. 27
0
        public static ResolvedVariablesContainer Resolve(ApplicationWithOverrideVariableGroup appWithGroup, ApplicationServer server)
        {
            if (appWithGroup == null)
            {
                throw new ArgumentNullException("appWithGroup");
            }
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            int    numberOfProblemsFound     = 0;
            bool   variableFoundMoreThanOnce = false;
            var    resolvedCustomVariables   = new List <CustomVariable>();
            string supplementalStatusMessage = string.Empty;

            // This is normally set when calling Install(), but since we're not doing that
            // here, set it explicitly.
            ApplicationWithOverrideVariableGroup.SetInstallationStartTimestamp(DateTime.Now);

            foreach (TaskBase task in appWithGroup.Application.MainAndPrerequisiteTasks)
            {
                if (variableFoundMoreThanOnce)
                {
                    break;
                }

                foreach (string taskProperty in task.GetTaskProperties())
                {
                    if (variableFoundMoreThanOnce)
                    {
                        break;
                    }

                    string key   = string.Empty;
                    string value = string.Empty;

                    foreach (Match match in CustomVariableGroup.GetCustomVariableStringsWithinBiggerString(taskProperty))
                    {
                        // Don't add the same key more than once.
                        if (resolvedCustomVariables.Any(x => x.Key == match.Value))
                        {
                            continue;
                        }

                        try
                        {
                            key = match.Value;
                            // Note, we pass true so that encrypted values stay encrypted. We don't want the user to see encrypted values.
                            value = CustomVariableGroup.ResolveCustomVariable(match.Value, server, appWithGroup, true);
                        }
                        catch (CustomVariableMissingException)
                        {
                            numberOfProblemsFound++;
                            value = "** NOT FOUND **";
                        }
                        catch (CustomVariableExistsMoreThanOnceException ex)
                        {
                            variableFoundMoreThanOnce = true;
                            numberOfProblemsFound++;
                            value = "** MORE THAN ONE FOUND **";
                            supplementalStatusMessage = ex.Message;
                        }

                        resolvedCustomVariables.Add(new CustomVariable()
                        {
                            Key = key, Value = value
                        });
                    }
                }
            }

            var container = new ResolvedVariablesContainer();

            container.NumberOfProblems          = numberOfProblemsFound;
            container.SupplementalStatusMessage = supplementalStatusMessage;
            container.Variables = resolvedCustomVariables;

            return(container);
        }