Example #1
0
        /// <summary>
        /// Loads all data from the database required to build the manifests for this Scenario so that
        /// properties like Resources and Quantities can be evaluated before the actual building of the manifests.
        /// </summary>
        private void Initialize()
        {
            using (EnterpriseTestContext context = new EnterpriseTestContext())
            {
                TraceFactory.Logger.Debug($"Loading all resources for scenarioId: {ScenarioId}");

                // Get the enabled VirtualResources but filter out any disabled items from the VirtualResourceMetadataSet
                var resources = EnterpriseScenario.SelectWithAllChildren(context, ScenarioId)?.VirtualResources.Where(e => e.Enabled);
                if (resources == null || !resources.Any())
                {
                    //No reason to continue if there are no resources
                    return;
                }

                foreach (var resource in resources)
                {
                    var temp = resource.VirtualResourceMetadataSet.Where(x => x.Enabled).ToList();
                    resource.VirtualResourceMetadataSet.Clear();
                    temp.ForEach(resource.VirtualResourceMetadataSet.Add);
                }
                Resources = resources;

                ManifestSet.ScenarioId   = ScenarioId;
                ManifestSet.ScenarioName = EnterpriseScenario.Select(context, ScenarioId).Name;

                Quantities = new SessionResourceQuantity(Resources);
            }
        }
Example #2
0
        /// <summary>
        /// Creates a new instance of the <see cref="ManifestServerAgent"/> class.
        /// </summary>
        /// <param name="scenarioId"></param>
        public ManifestServerAgent(Guid scenarioId)
        {
            using (EnterpriseTestContext context = new EnterpriseTestContext())
            {
                // Retrieve server usage data for all enabled activities in the specified session
                var activities = (from serverusage in context.VirtualResourceMetadataServerUsages
                                  let data = serverusage.ServerSelectionData
                                             let metadata = serverusage.VirtualResourceMetadata
                                                            let resource = metadata.VirtualResource
                                                                           where resource.EnterpriseScenarioId == scenarioId &&
                                                                           resource.Enabled == true &&
                                                                           metadata.Enabled == true &&
                                                                           data != null
                                                                           select new { Id = metadata.VirtualResourceMetadataId, Servers = data }).ToList();

                foreach (var activity in activities)
                {
                    ServerSelectionData serverSelectionData = GetSelectionData(activity.Servers);
                    _activityServers.Add(activity.Id, GetServerIds(serverSelectionData));
                }
            }

            var serverIds = _activityServers.Values.SelectMany(n => n).Distinct().ToList();

            using (AssetInventoryContext assetContext = DbConnect.AssetInventoryContext())
            {
                _servers.AddRange(assetContext.FrameworkServers.Where(n => serverIds.Contains(n.FrameworkServerId)).ToServerInfoCollection());
            }
        }
        public GlobalSettingsManagementDialog()
        {
            InitializeComponent();
            UserInterfaceStyler.Configure(this, FormStyle.SizeableDialogWithHelp);

            _context = new EnterpriseTestContext();
        }
 private void refreshVMs_LinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     using (EnterpriseTestContext context = new EnterpriseTestContext())
     {
         LoadComboBoxes(context);
     }
 }
Example #5
0
        private void Initialize()
        {
            // Fetch plugin icons from the database
            using (EnterpriseTestContext context = DbConnect.EnterpriseTestContext())
            {
                foreach (MetadataType metadataType in context.MetadataTypes.Where(n => n.Icon != null))
                {
                    Image icon = ImageUtil.ReadImage(metadataType.Icon);
                    pluginImageList.Images.Add(metadataType.Name, icon);
                }
            }

            // Add icons with "disabled" overlay for resources and plugins
            ImageComposer.Append(virtualResourceImageList, disabledImageOverlay, "Disabled");
            ImageComposer.Append(pluginImageList, disabledImageOverlay, "Disabled");

            // For each image list, add the appropriate images and overlays.
            configurationImageList.Images.Add(commonImageList);
            configurationImageList.Images.Add(virtualResourceImageList);
            configurationImageList.Images.Add(pluginImageList);

            executionImageList.Images.Add(commonImageList);
            executionImageList.Images.Add(virtualResourceImageList);
            executionImageList.Images.Add(pluginImageList);
            executionImageList.Images.Add(assetImageList);
        }
        private void GetMetaData()
        {
            using (EnterpriseTestContext context = new EnterpriseTestContext())
            {
                var temp = context.AssociatedProducts.Where(y => y.AssociatedProductId == _selectedProductId);
                if (temp.Count() == 0)
                {
                    MessageBox.Show("Name and Vendor don't exist in the database to edit", "Product Add Error", MessageBoxButtons.OK);
                    return;
                }
                else
                {
                    var item = temp.First();

                    //if (item.MetadataTypes.Count > 0)
                    //{
                    metadata_DatagridView.DataSource = item.MetadataTypes;
                    if (item.MetadataTypes.Count > 0)
                    {
                        removeAssociation_Button.Enabled = true;
                    }
                    metadata_DatagridView.ClearSelection();

                    //}
                }
            }
        }
        private void addAssociation_Button_Click(object sender, EventArgs e)
        {
            using (EnterpriseTestContext context = new EnterpriseTestContext())
            {
                var meta = metaData_ComboBox.SelectedItem as MetadataType;
                var temp = context.AssociatedProducts.Where(y => y.AssociatedProductId == _selectedProductId && y.MetadataTypes.Any(x => x.Name == meta.Name));
                //var otherTemp = temp.First().Value.Where(x => x.AssociatedProductId == _selectedProductId).First();

                if (temp.Count() > 0)
                {
                    MessageBox.Show("Plugin Association already exists for this metadata", "Product Association Error", MessageBoxButtons.OK);
                    return;
                }
                else
                {
                    var metadata = context.MetadataTypes.Where(y => y.Name == meta.Name).First();

                    var prod = context.AssociatedProducts.Where(y => y.AssociatedProductId == _selectedProductId).First();

                    prod.MetadataTypes.Add(metadata);
                    context.SaveChanges();
                }
            }
            LoadPage();
        }
Example #8
0
        /// <summary>
        /// Creates a <see cref="SessionTicket"/> using the specififed scenario name.
        /// </summary>
        /// <param name="scenarioNames">List of the scenarios to execute.</param>
        /// <param name="sessionName">Name of the session to execute scenarios</param>
        /// <param name="durationHours">The session duration in hours.</param>
        /// <returns></returns>
        /// <exception cref="System.InvalidOperationException">Scenario with specified name is not found in the database.</exception>
        public static SessionTicket Create(IEnumerable <string> scenarioNames, string sessionName, int durationHours = 2)
        {
            SessionTicket ticket = new SessionTicket()
            {
                ExpirationDate = DateTime.Now.AddHours(durationHours),
                DurationHours  = durationHours,
                SessionName    = sessionName
            };

            using (EnterpriseTestContext context = new EnterpriseTestContext())
            {
                foreach (string scenarioName in scenarioNames)
                {
                    if (!string.IsNullOrEmpty(scenarioName))
                    {
                        var scenario = EnterpriseScenario.Select(context, scenarioName);
                        if (scenario == null)
                        {
                            throw new InvalidOperationException($"'{scenarioName}' is not found in the database.");
                        }
                        ((List <Guid>)ticket.ScenarioIds).Add(scenario.EnterpriseScenarioId);
                    }
                }
            }
            return(ticket);
        }
Example #9
0
        private ConfigurationObjectChangeSet LoadConfigurationMap(Func <EnterpriseTestContext, IQueryable <EnterpriseScenario> > scenarioSelector)
        {
            _configMap.Clear();

            using (EnterpriseTestContext context = new EnterpriseTestContext(_connectionString))
            {
                // Set up queries for scenarios, resources, and metadata
                IQueryable <EnterpriseScenario>      scenarios = scenarioSelector(context);
                IQueryable <VirtualResource>         resources = scenarios.SelectMany(n => n.VirtualResources);
                IQueryable <VirtualResourceMetadata> metadata  = resources.SelectMany(n => n.VirtualResourceMetadataSet);

                // Create configuration objects from the above queries
                List <ConfigurationObjectTag> scenarioTags = scenarios.ToConfigurationObjectTags().ToList();
                List <ConfigurationObjectTag> resourceTags = resources.ToConfigurationObjectTags().ToList();
                List <ConfigurationObjectTag> metadataTags = metadata.ToConfigurationObjectTags().ToList();

                // The configuration tags need to be added in order, such that every tag comes *after* its parent and folder.
                // We can take advantage of the strict object hierarchy to minimize the amount of sorting required.
                // Scenarios, resources, and metadata require no particular order, since they are independent of each other.
                // Folders must be sorted to ensure that subfolders are added after their parent folder.
                LoadSortedConfigFolders(context, ConfigurationObjectType.ScenarioFolder, Enumerable.Empty <ConfigurationObjectTag>());
                _configMap.AddRange(scenarioTags);
                LoadSortedConfigFolders(context, ConfigurationObjectType.ResourceFolder, scenarioTags);
                _configMap.AddRange(resourceTags);
                LoadSortedConfigFolders(context, ConfigurationObjectType.MetadataFolder, resourceTags);
                _configMap.AddRange(metadataTags);
            }

            ConfigurationObjectChangeSet changeSet = new ConfigurationObjectChangeSet();

            changeSet.AddedObjects.Add(_configMap.AllObjects);
            return(changeSet);
        }
Example #10
0
 private static bool IsUserRegistered(string userName)
 {
     using (EnterpriseTestContext context = new EnterpriseTestContext())
     {
         return(context.Users.Any(n => n.UserName.Equals(userName, StringComparison.OrdinalIgnoreCase)));
     }
 }
 private User GetUser(string userName, string domain)
 {
     using (EnterpriseTestContext context = new EnterpriseTestContext())
     {
         return(context.Users.FirstOrDefault(u => u.UserName.Equals(userName, StringComparison.OrdinalIgnoreCase) && u.Domain.ToLower().StartsWith(domain.ToLower())));
     }
 }
Example #12
0
        /// <summary>
        /// Creates resource detail and inserts it into the manifest.
        /// </summary>
        /// <param name="resources">The resources.</param>
        /// <param name="manifest">The manifest.</param>
        internal override void AddToManifest(Collection <VirtualResource> resources, SystemManifest manifest)
        {
            var resource = resources.First();

            MachineReservationDetail detail = manifest.Resources.GetResource <MachineReservationDetail>(resource.VirtualResourceId);

            if (detail == null)
            {
                detail = CreateDetail(resource);
                manifest.Resources.Add(detail);
            }

            // Add installers to the manifest that are specific to this instance of the Machine Reservation
            MachineReservationMetadata metadata = LegacySerializer.DeserializeXml <MachineReservationMetadata>(resource.VirtualResourceMetadataSet.First().Metadata);

            if (metadata.PackageId != Guid.Empty)
            {
                using (EnterpriseTestContext context = new EnterpriseTestContext())
                {
                    int i = 1;
                    foreach (var installer in SelectSoftwareInstallers(context, metadata.PackageId))
                    {
                        TraceFactory.Logger.Debug("Adding {0}".FormatWith(installer.Description));
                        manifest.SoftwareInstallers.Add(CreateSoftwareInstallerDetail(installer, i++));
                    }
                }
            }
        }
        public ManifestDocumentAgent(Guid scenarioId)
        {
            using (EnterpriseTestContext context = new EnterpriseTestContext())
            {
                // Retrieve document usage data for all enabled activities in the specified session
                var activities = (from documentUsage in context.VirtualResourceMetadataDocumentUsages
                                  let data = documentUsage.DocumentSelectionData
                                             let metadata = documentUsage.VirtualResourceMetadata
                                                            let resource = metadata.VirtualResource
                                                                           where resource.EnterpriseScenarioId == scenarioId &&
                                                                           resource.Enabled == true &&
                                                                           metadata.Enabled == true &&
                                                                           data != null
                                                                           select new { Id = metadata.VirtualResourceMetadataId, Documents = data }).ToList();

                foreach (var activity in activities)
                {
                    DocumentSelectionData documentSelectionData = GetSelectionData(activity.Documents);
                    _activityDocuments.Add(activity.Id, GetDocuments(documentSelectionData));
                }
            }

            var documentIds = _activityDocuments.Values.SelectMany(n => n).Distinct().ToList();

            using (DocumentLibraryContext context = DbConnect.DocumentLibraryContext())
            {
                var documents = context.TestDocuments.Where(n => documentIds.Contains(n.TestDocumentId)).ToDocumentCollection();
                _documents.AddRange(documents);
            }
        }
Example #14
0
        public void LoadGroups(EnterpriseScenarioContract contract)
        {
            _groups = contract.UserGroups;

            using (EnterpriseTestContext context = new EnterpriseTestContext())
            {
                editorGroups_CheckedListBox.Items.Clear();
                foreach (UserGroup group in context.UserGroups.OrderBy(x => x.GroupName))
                {
                    editorGroups_CheckedListBox.Items.Add(group);
                }
            }

            var listBoxItems  = editorGroups_CheckedListBox.Items.Cast <UserGroup>().Select(x => x.GroupName).ToList();
            var missingGroups = _groups.Where(x => !listBoxItems.Contains(x)).ToList();

            foreach (var group in missingGroups)
            {
                _groups.Remove(group);
            }

            foreach (var groupName in listBoxItems)
            {
                if (_groups.Contains(groupName))
                {
                    int index = listBoxItems.IndexOf(groupName);
                    editorGroups_CheckedListBox.SetItemCheckState(index, CheckState.Checked);
                }
            }
        }
        public void LoadFolders()
        {
            saveToRadTreeView.Nodes.Clear();

            using (EnterpriseTestContext context = new EnterpriseTestContext())
            {
                var folders = ConfigurationTreeFolder.Select(context, "ScenarioFolder");
                foreach (ConfigurationTreeFolder folder in ConfigurationTreeFolder.SortHierarchical(folders))
                {
                    RadTreeNode node = new RadTreeNode(folder.Name);
                    node.Tag      = folder.ConfigurationTreeFolderId;
                    node.ImageKey = "Folder";

                    if (folder.ParentId == null)
                    {
                        saveToRadTreeView.Nodes.Add(node);
                    }
                    else
                    {
                        var temp = FindNode(folder.ParentId);
                        if (temp != null)
                        {
                            temp.Nodes.Add(node);
                        }
                        else
                        {
                            saveToRadTreeView.Nodes.Add(node);
                        }

                        //FindNode(folder.ParentId).Nodes.Add(node);
                    }
                }
            }
            FindSelectedNode();
        }
Example #16
0
 /// <summary>
 /// Retrieves the specified system setting.
 /// </summary>
 /// <param name="setting">The name of the setting to retrieve.</param>
 /// <returns>The setting value, or null if no such setting is found.</returns>
 public static string RetrieveSetting(string setting)
 {
     using (EnterpriseTestContext context = DbConnect.EnterpriseTestContext())
     {
         return(context.SystemSettings.FirstOrDefault(n => n.Type == "SystemSetting" && n.Name == setting)?.Value);
     }
 }
        private void editProduct_Button_Click(object sender, EventArgs e)
        {
            string vendor = vendor_TextBox.Text;
            string name   = name_TextBox.Text;

            if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(vendor))
            {
                MessageBox.Show("Name and Vendor Fields can not be blank", "Edit Product Error", MessageBoxButtons.OK);
                return;
            }

            using (EnterpriseTestContext context = new EnterpriseTestContext())
            {
                var temp = context.AssociatedProducts.Where(y => y.AssociatedProductId == _selectedProductId);
                if (temp.Count() == 0)
                {
                    MessageBox.Show("Name and Vendor don't exist in the database to edit", "Product Add Error", MessageBoxButtons.OK);
                    return;
                }
                else
                {
                    AssociatedProduct edit = temp.First();
                    edit.Name   = name;
                    edit.Vendor = vendor;

                    context.SaveChanges();


                    LoadPage();
                }
            }
        }
Example #18
0
        private void LoadPrintQueues(string serverName)
        {
            List <RemotePrintQueue> queues = null;

            using (EnterpriseTestContext context = new EnterpriseTestContext())
            {
                queues = RemotePrintQueue.SelectByPrintServerName(context, serverName).ToList();
            }

            _printQueueNode.Nodes.Clear();
            foreach (RemotePrintQueue queue in queues)
            {
                TreeNode queueNode = _printQueueNode.Nodes.Add(queue.Name);
                foreach (ResourceWindowsCategory counter in _printQueueCounterNames)
                {
                    BuildTree(counter, queueNode);
                }
            }

            // Only display the Print Queue Node if the selected server has queues.
            if (_printQueueNode.Nodes.Count > 0)
            {
                available_TreeView.Nodes.Add(_printQueueNode);
            }
        }
        private void deleteProduct_Button_Click(object sender, EventArgs e)
        {
            string vendor = vendor_TextBox.Text;
            string name   = name_TextBox.Text;


            using (EnterpriseTestContext context = new EnterpriseTestContext())
            {
                var temp = context.AssociatedProducts.Where(y => y.AssociatedProductId == _selectedProductId);
                if (temp.Count() == 0)
                {
                    MessageBox.Show("Name and Vendor don't exist in the database to delete", "Product Delete Error", MessageBoxButtons.OK);
                    return;
                }
                else
                {
                    AssociatedProduct del = temp.First();
                    context.DeleteObject(del);

                    context.SaveChanges();

                    LoadPage();
                }

                if (context.AssociatedProducts.Count() == 0)
                {
                    editProduct_Button.Enabled = false;
                }
            }
            deleteProduct_Button.Enabled = false;
        }
        /// <summary>
        /// Gets the AssociatedProducts for the given scenario.
        /// </summary>
        /// <param name="context">The EnterpriseTest data context.</param>
        /// <param name="scenario">The scenario.</param>
        /// <returns>The AssociatedProducts for the given scenario.</returns>
        public static IEnumerable <ScenarioProduct> GetAssociatedProducts(EnterpriseTestContext context, EnterpriseScenario scenario)
        {
            List <string> metadataTypes = new List <string>();

            foreach (VirtualResource vr in scenario.VirtualResources)
            {
                foreach (var vrms in vr.VirtualResourceMetadataSet)
                {
                    metadataTypes.Add(vrms.MetadataType);
                }
            }

            List <AssociatedProduct>        associatedProducts = context.AssociatedProducts.Where(n => n.MetadataTypes.Any(m => metadataTypes.Contains(m.Name))).ToList();
            IEnumerable <Guid>              productIds         = associatedProducts.Select(x => x.AssociatedProductId);
            List <AssociatedProductVersion> productVersions    = AssociatedProductVersion.SelectVersions(context, productIds, scenario.EnterpriseScenarioId).ToList();

            return(from productInfo in associatedProducts
                   join versionInfo in productVersions
                   on productInfo.AssociatedProductId equals versionInfo.AssociatedProductId
                   select new ScenarioProduct
            {
                ProductId = productInfo.AssociatedProductId,
                Version = versionInfo.Version,
                ScenarioId = versionInfo.EnterpriseScenarioId,
                Name = productInfo.Name,
                Vendor = productInfo.Vendor,
                Active = versionInfo.Active
            });
        }
Example #21
0
        private static void AddActivityUsageDataToContract(EnterpriseScenarioContract contract, Guid scenarioId)
        {
            using (var context = new EnterpriseTestContext())
            {
                contract.ActivityAssetUsage.Clear();
                var assetUsage = context.VirtualResourceMetadataAssetUsages.Where(n => n.VirtualResourceMetadata.VirtualResource.EnterpriseScenarioId == scenarioId).ToList();
                assetUsage.ForEach(x => contract.ActivityAssetUsage.Add(new ResourceUsageContract(x.VirtualResourceMetadataId, x.AssetSelectionData)));

                contract.ActivityDocumentUsage.Clear();
                var docUsage = context.VirtualResourceMetadataDocumentUsages.Where(n => n.VirtualResourceMetadata.VirtualResource.EnterpriseScenarioId == scenarioId).ToList();
                docUsage.ForEach(x => contract.ActivityDocumentUsage.Add(new ResourceUsageContract(x.VirtualResourceMetadataId, x.DocumentSelectionData)));

                contract.ActivityPrintQueueUsage.Clear();
                var printQueueUsage = context.VirtualResourceMetadataPrintQueueUsages.Where(n => n.VirtualResourceMetadata.VirtualResource.EnterpriseScenarioId == scenarioId).ToList();
                printQueueUsage.ForEach(x => contract.ActivityPrintQueueUsage.Add(new ResourceUsageContract(x.VirtualResourceMetadataId, x.PrintQueueSelectionData)));

                contract.ActivityServerUsage.Clear();
                var serverUsage = context.VirtualResourceMetadataServerUsages.Where(n => n.VirtualResourceMetadata.VirtualResource.EnterpriseScenarioId == scenarioId).ToList();
                serverUsage.ForEach(x => contract.ActivityServerUsage.Add(new ResourceUsageContract(x.VirtualResourceMetadataId, x.ServerSelectionData)));

                contract.ActivityRetrySettings.Clear();
                var retrySettings = context.VirtualResourceMetadataRetrySettings.Where(n => n.VirtualResourceMetadata.VirtualResource.EnterpriseScenarioId == scenarioId).ToList();
                retrySettings.ForEach(x => contract.ActivityRetrySettings.Add(new RetrySettingContract(x.VirtualResourceMetadataId)
                {
                    State  = x.State,
                    Action = x.Action,
                    LimitExceededAction = x.LimitExceededAction,
                    RetryDelay          = x.RetryDelay,
                    RetryLimit          = x.RetryLimit,
                }
                                                                              ));
            }
        }
        /// <summary>
        /// Constructs a new instance of SoftwareInstallersForm.
        /// Creates and uses a new data context.
        /// </summary>
        public SoftwareInstallersForm()
        {
            InitializeForm();

            _dataContext = new EnterpriseTestContext();
            LoadInstallers();
        }
Example #23
0
        protected override void StartService(CommandLineArguments args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            FrameworkServiceHelper.LoadSettings(args, autoRefresh: true);
            using (EnterpriseTestContext dataContext = new EnterpriseTestContext())
            {
                GlobalSettings.IsDistributedSystem = dataContext.VirtualResources.Any(r => r.ResourceType == "OfficeWorker");
            }
            string dispatcherHostName = "localhost";

            if (GlobalSettings.IsDistributedSystem)
            {
                using (AssetInventoryContext context = DbConnect.AssetInventoryContext())
                {
                    var dispatcher = context.FrameworkServers.FirstOrDefault(x => x.Active && x.ServerTypes.Any(n => n.Name == "BTF"));
                    if (dispatcher == null)
                    {
                        TraceFactory.Logger.Error("Could not find any dispatchers reserved for BTF Execution.");
                        return;
                    }
                }
            }

            SessionClient.Instance.Initialize(dispatcherHostName);
            SessionClient.Instance.SessionStartupTransitionReceived += Instance_SessionStartupTransitionReceived;
            SessionClient.Instance.SessionStateReceived             += Instance_SessionStateReceived;
            _server = WebApp.Start <Startup>(url: _baseAddress);
            _executionTimer.Start();
        }
Example #24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VirtualMachinePlatformConfigForm"/> class.
 /// </summary>
 public VirtualMachinePlatformConfigForm()
 {
     InitializeComponent();
     UserInterfaceStyler.Configure(this, FormStyle.SizeableDialog);
     _assetInventoryContext = DbConnect.AssetInventoryContext();
     _enterpriseTestContext = DbConnect.EnterpriseTestContext();
 }
Example #25
0
        private void ScenarioSelectionForm_Load(object sender, EventArgs e)
        {
            bool noOrphans = true;

            using (EnterpriseTestContext context = new EnterpriseTestContext())
            {
                var folders = ConfigurationTreeFolder.Select(context, "ScenarioFolder");
                foreach (ConfigurationTreeFolder folder in ConfigurationTreeFolder.SortHierarchical(folders))
                {
                    RadTreeNode node = new RadTreeNode(folder.Name);
                    node.Tag      = folder.ConfigurationTreeFolderId;
                    node.ImageKey = "Folder";

                    noOrphans &= AddNode(node, folder.ParentId);
                }

                foreach (EnterpriseScenario scenario in context.EnterpriseScenarios)
                {
                    RadTreeNode node = new RadTreeNode(scenario.Name);
                    node.Tag      = scenario.EnterpriseScenarioId;
                    node.ImageKey = "Scenario";

                    noOrphans &= AddNode(node, scenario.FolderId);
                }
            }

            if (!noOrphans)
            {
                MessageBox.Show("One or more scenarios or folders did not load into the tree successfully.\n" +
                                "Please contact an administrator to determine which database items have incorrect configuration.",
                                "Load Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Example #26
0
        private void PackResources(string platform, Collection <VirtualResource> resourceCollection)
        {
            // Iterate over each collection of resources grouped by the resource type.
            foreach (var resources in resourceCollection.GroupBy(x => x.ResourceType))
            {
                // Some of the resources may not have ResourcesPerVM specified.
                // Fill those in with the default from the database so they all have good values for the sort.
                List <VirtualResource> resourcesWithNulls = resources.Where(n => n.ResourcesPerVM == null).ToList();
                if (resourcesWithNulls.Count() > 0)
                {
                    using (EnterpriseTestContext context = new EnterpriseTestContext())
                    {
                        int defaultResourcesPerVM = context.ResourceTypes.First(n => n.Name == resourcesWithNulls[0].ResourceType).MaxResourcesPerHost;
                        resourcesWithNulls.ForEach(n => n.ResourcesPerVM = defaultResourcesPerVM);
                    }
                }

                // Sort the resources by the maximum number of resources per VM
                // This is required for the greedy packing algorithm to work
                List <VirtualResource> orderedSet = resources.OrderBy(n => (int)n.ResourcesPerVM).ToList();

                // This algorithm will pack the resources into sets while mandating that no resource is packed
                // with more siblings than specified by its ResourcesPerVM property.
                // The algorithm starts with the most claustrophobic resources (lowest ResourcesPerVM) and
                // packs as many sets as necessary.  The last set packed this way may have some space left over,
                // so fill that with the next-most claustrophobic resource instance.  Continue this process
                // until all the VMs have been packed into sets.
                VirtualResourcePackedSet packingSet = null;
                foreach (VirtualResource resource in orderedSet.SelectMany(x => x.ExpandedDefinitions))
                {
                    // Each iteration through this block represents packing 1 instance of this resource
                    {
                        // If packingSet is null, this means we need to create a new packed set
                        // based on the resource that is currently being packed
                        if (packingSet == null)
                        {
                            packingSet = new VirtualResourcePackedSet(resource, platform);
                        }

                        // Add one instance of this resource to our current set
                        packingSet.Add(resource);

                        // Check to see if this set is fully packed
                        if (packingSet.IsFullyPacked)
                        {
                            // Save off this set into our listed of packed sets and null out our list
                            // Don't generate a new list yet - it might not be based on this resource
                            _packedSets.Add(packingSet);
                            packingSet = null;
                        }
                    }
                }

                // When we get to the end, we may have a partially packed set - if so, save it to our list
                if (packingSet != null && packingSet.Count > 0)
                {
                    _packedSets.Add(packingSet);
                }
            }
        }
        private void InitializePluginControl(IPluginConfigurationControl configurationControl)
        {
            Dictionary <string, string> settings = new Dictionary <string, string>();

            using (EnterpriseTestContext context = new EnterpriseTestContext())
            {
                foreach (SystemSetting pluginSetting in context.SystemSettings.Where(n => n.Type.Equals("PluginSetting") && n.SubType.Equals(_metadata.MetadataType)))
                {
                    settings.Add(pluginSetting.Name, pluginSetting.Value);
                }
            }

            PluginEnvironment environment = new PluginEnvironment
                                            (
                new SettingsDictionary(settings),
                GlobalSettings.Items[Setting.Domain],
                GlobalSettings.Items[Setting.DnsDomain]
                                            );

            if (string.IsNullOrEmpty(_metadata.Metadata))
            {
                configurationControl.Initialize(environment);
            }
            else
            {
                PluginConfigurationData configurationData = _metadata.BuildConfigurationData();
                configurationControl.Initialize(configurationData, environment);
            }
            _editorType = _metadata.MetadataType;
            _editor     = configurationControl;
        }
        public ManifestRetrySettingsAgent(Guid scenarioId)
        {
            using (EnterpriseTestContext context = new EnterpriseTestContext())
            {
                // Retrieve retry settings data for all enabled activities in the specified session
                var activities = (from retrySetting in context.VirtualResourceMetadataRetrySettings
                                  let metadata = retrySetting.VirtualResourceMetadata
                                                 let resource = metadata.VirtualResource
                                                                where resource.EnterpriseScenarioId == scenarioId &&
                                                                resource.Enabled == true &&
                                                                metadata.Enabled == true
                                                                group retrySetting by retrySetting.VirtualResourceMetadataId into g
                                                                select new { Id = g.Key, RetrySettings = g });

                foreach (var activity in activities)
                {
                    var list = new List <PluginRetrySetting>();
                    foreach (var setting in activity.RetrySettings)
                    {
                        var retrySetting = new PluginRetrySetting(
                            state: EnumUtil.Parse <PluginResult>(setting.State),
                            retryAction: EnumUtil.Parse <PluginRetryAction>(setting.Action),
                            retryLimit: setting.RetryLimit,
                            delayBeforeRetry: new TimeSpan(0, 0, setting.RetryDelay),
                            limitExceededAction: EnumUtil.Parse <PluginRetryAction>(setting.LimitExceededAction)
                            );
                        list.Add(retrySetting);
                    }
                    _activityRetrySettings.Add(activity.Id, new PluginRetrySettingDictionary(list));
                }
            }
        }
Example #29
0
        public void Update(EnterpriseTestContext context)
        {
            var temp = context.AssociatedProductVersions.Where(x => x.AssociatedProductId == ProductId && x.EnterpriseScenarioId == ScenarioId);

            if (temp == null || temp.Count() == 0)
            {
                AssociatedProductVersion version = new AssociatedProductVersion();
                version.AssociatedProductId  = ProductId;
                version.EnterpriseScenarioId = ScenarioId;
                version.Active  = Active;
                version.Version = Version;

                context.AssociatedProductVersions.AddObject(version);
                context.SaveChanges();
            }
            else
            {
                AssociatedProductVersion version = context.AssociatedProductVersions.Where(x => x.AssociatedProductId == ProductId && x.EnterpriseScenarioId == ScenarioId).First();
                version.AssociatedProductId  = ProductId;
                version.EnterpriseScenarioId = ScenarioId;
                version.Active  = Active;
                version.Version = Version;

                context.SaveChanges();
            }
        }
 private void Update_GridView(int selectedId)
 {
     using (EnterpriseTestContext context = new EnterpriseTestContext())
     {
         children_GridView.DataSource = ResourceWindowsCategory.SelectByParent(context, selectedId);
     }
 }