예제 #1
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,
                }
                                                                              ));
            }
        }
예제 #2
0
 private static void AddAssetInfoToContract(Guid scenarioId, EnterpriseScenarioContract contract, SystemManifest manifest)
 {
     contract.AllAssets.Clear();
     foreach (var asset in manifest.AllAssets)
     {
         contract.AllAssets.Add(asset);
         UpdateStatus("Exporting {0}".FormatWith(asset.AssetId));
     }
 }
예제 #3
0
 private static void AddTestDocumentInfoToContract(Guid scenarioId, EnterpriseScenarioContract contract, SystemManifest manifest)
 {
     // Add any test documents referenced in the resource metadata to a collection that will
     // be resolved against the target system during import.
     contract.TestDocuments.Clear();
     foreach (Document doc in manifest.Documents)
     {
         string relativeFilePath = doc.Group + @"\" + doc.FileName;
         contract.TestDocuments.Add(new TestDocumentContract(relativeFilePath));
         UpdateStatus("Exporting {0}".FormatWith(relativeFilePath));
     }
 }
예제 #4
0
        /// <summary>
        /// Adds the folder data to the specified scenario contract.
        /// </summary>
        /// <param name="contract">The scenario contract.</param>
        /// <param name="scenario">The scenario object.</param>
        private static void AddFolderDataToContract(EnterpriseScenarioContract contract, EnterpriseScenario scenario)
        {
            try
            {
                using (EnterpriseTestContext context = new EnterpriseTestContext())
                {
                    // get resource and metadata objects
                    IEnumerable <VirtualResource>         resources = scenario.VirtualResources.Where(v => v.FolderId.HasValue && v.FolderId.Value != Guid.Empty);
                    IEnumerable <VirtualResourceMetadata> metadatas = resources.SelectMany(v => v.VirtualResourceMetadataSet).Where(m => m.FolderId.HasValue && m.FolderId.Value != Guid.Empty);

                    // group each by the folder id
                    var groupResources = (from r in resources
                                          group r by r.FolderId into g
                                          select new { FolderId = g.Key.Value, ChildIds = g.Select(x => x.VirtualResourceId) });

                    var groupMetadata = (from m in metadatas
                                         group m by m.FolderId into g
                                         select new { FolderId = g.Key.Value, ChildIds = g.Select(z => z.VirtualResourceMetadataId) });

                    // get referenced folders
                    var allGroups = groupResources.Concat(groupMetadata);
                    var folderIds = allGroups.Select(x => x.FolderId);
                    IQueryable <ConfigurationTreeFolder> folders = ConfigurationTreeFolder.Select(context, folderIds);

                    // add contract data for each referenced folder
                    foreach (var group in allGroups)
                    {
                        ConfigurationTreeFolder folder = folders.FirstOrDefault(x => x.ConfigurationTreeFolderId.Equals(group.FolderId));
                        if (folder != null)
                        {
                            FolderContract folderContract = new FolderContract()
                            {
                                Name = folder.Name, FolderType = folder.FolderType, ChildIds = new Collection <Guid>(group.ChildIds.ToList())
                            };
                            contract.Folders.Add(folderContract);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                TraceFactory.Logger.Error("Error adding folder data.", ex);
            }
        }
예제 #5
0
        /// <summary>
        /// Creates contract data for the specified scenario.
        /// </summary>
        /// <param name="scenario"></param>
        /// <returns></returns>
        public static EnterpriseScenarioContract Create(EnterpriseScenario scenario)
        {
            EnterpriseScenarioContract contract = new EnterpriseScenarioContract(scenario, "1.0");
            Guid           scenarioId           = scenario.EnterpriseScenarioId;
            SystemManifest manifest             = CreateReferenceManifest(scenarioId);

            AddTestDocumentInfoToContract(scenario.EnterpriseScenarioId, contract, manifest);
            AddAssetInfoToContract(scenario.EnterpriseScenarioId, contract, manifest);

            AddActivityUsageDataToContract(contract, scenarioId);
            AddFolderDataToContract(contract, scenario);

            foreach (var resource in scenario.VirtualResources)
            {
                var resourceDetail = VirtualResourceDetailBuilder.CreateBaseDetail(resource);
                contract.ResourceDetails.Add(resourceDetail);
                UpdateStatus("Exporting {0}".FormatWith(resourceDetail.Name));
            }

            return(contract);
        }
예제 #6
0
        /// <summary>
        /// Creates a scenario object from the specified scenario contract, building the specified import maps.
        /// </summary>
        /// <param name="contract">The scenario contract.</param>
        /// <param name="importMaps">The collection of ImportMaps</param>
        /// <returns></returns>
        public static EnterpriseScenario Create(EnterpriseScenarioContract contract, out List <ImportMap> importMaps)
        {
            EnterpriseScenario scenario = new EnterpriseScenario()
            {
                EnterpriseScenarioId = SequentialGuid.NewGuid(),
                Company     = contract.Company,
                Description = contract.Description,
                Name        = contract.Name,
                Owner       = contract.Owner,
                Vertical    = contract.Vertical,
            };

            importMaps = new List <ImportMap>();

            using (EnterpriseTestContext context = new EnterpriseTestContext())
            {
                foreach (var resourceDetail in contract.ResourceDetails)
                {
                    Guid oldResourceId = resourceDetail.ResourceId;

                    // This is a translator to target an OfficeWorker or SolutionTester
                    // for the right delivery platform.
                    VirtualResourceType finalResourceType = resourceDetail.ResourceType;
                    if (GlobalSettings.IsDistributedSystem)
                    {
                        if (finalResourceType == VirtualResourceType.SolutionTester)
                        {
                            finalResourceType = VirtualResourceType.OfficeWorker;
                            TraceFactory.Logger.Debug("Changed resource type to Office Worker");
                        }
                    }
                    else
                    {
                        if (finalResourceType == VirtualResourceType.OfficeWorker)
                        {
                            finalResourceType = VirtualResourceType.SolutionTester;
                            TraceFactory.Logger.Debug("Changed resource type to Solution Tester");
                        }
                    }

                    string type = finalResourceType.ToString();
                    if (!context.ResourceTypes.Any(x => x.Name.Equals(type)))
                    {
                        // Skip any invalid resource types for this system.
                        continue;
                    }

                    // Create the entity, load it from the provided detail, then add it to the scenario resource collection
                    VirtualResource resourceEntity = ObjectFactory.Create <VirtualResource>(finalResourceType, finalResourceType.ToString());

                    foreach (ResourceMetadataDetail metadataDetail in resourceDetail.MetadataDetails)
                    {
                        XElement       configElement  = XElement.Parse(metadataDetail.Data);
                        PluginAssembly pluginAssembly = PluginFactory.GetPluginByAssemblyName("Plugin." + metadataDetail.MetadataType + ".dll");

                        StringBuilder msg = null;
                        if (pluginAssembly.Implements <IPluginValidation>())
                        {
                            IPluginValidation       validationEngine = pluginAssembly.Create <IPluginValidation>();
                            PluginConfigurationData pcd = new PluginConfigurationData(configElement, metadataDetail.MetadataVersion);
                            if (validationEngine.ValidateMetadata(ref pcd))
                            {
                                // Save the converted metadata into the database
                                metadataDetail.Data            = pcd.GetMetadata().ToString();
                                metadataDetail.MetadataVersion = pcd.MetadataVersion;
                            }
                            else
                            {
                                msg = new StringBuilder("\n\rMetadata for activity type '");
                                msg.Append(metadataDetail.MetadataType);
                                msg.Append("', version ");
                                msg.Append(metadataDetail.MetadataVersion);
                                msg.Append(", Activity Name: ");
                                msg.Append(metadataDetail.Name);
                                msg.Append(" appears out of date. Using the current default settings.");

                                UpdateStatus(msg.ToString());
                            }
                        }
                        else //No validation engine
                        {
                            //We don't want to pop a message that the user won't understand.  Log this condition for now.
                            msg = new StringBuilder($"A plugin validation engine was not found for MetadataType: ");
                            msg.Append(metadataDetail.MetadataType);
                            msg.Append(".  The Metadata was imported 'as-is'.");
                            TraceFactory.Logger.Warn(msg.ToString());
                        }
                    }

                    resourceEntity.LoadDetail(scenario, resourceDetail);

                    if (finalResourceType == VirtualResourceType.SolutionTester)
                    {
                        var workersPerHost = context.ResourceTypes.Where(x => x.Name == "SolutionTester").Select(x => x.MaxResourcesPerHost).FirstOrDefault();
                        resourceEntity.ResourcesPerVM = workersPerHost;
                    }

                    scenario.VirtualResources.Add(resourceEntity);
                    TraceFactory.Logger.Debug("Added {0} to Scenario".FormatWith(resourceEntity.Name));

                    if (finalResourceType != resourceDetail.ResourceType)
                    {
                        // If the final resource type was changed above because are migrating an OfficeWorker to STB
                        // or a SolutionTester to STF, then set the resource type in the loaded entity to the
                        // final value since it was most likely set to the value of the initial detail.
                        resourceEntity.ResourceType = finalResourceType.ToString();
                        TraceFactory.Logger.Debug("Changing ResourceType to {0}".FormatWith(finalResourceType.ToString()));
                    }

                    importMaps.Add(new ImportMap()
                    {
                        OldId       = oldResourceId,
                        NewId       = resourceEntity.VirtualResourceId,
                        OldParentId = null,
                        NewParentId = resourceEntity.EnterpriseScenarioId,
                    });

                    // Prep each activity for insertion into the database
                    foreach (var metadataEntity in resourceEntity.VirtualResourceMetadataSet)
                    {
                        // Change the metadata id to avoid any duplicate key issues when saving to the database
                        var oldMetadataId = metadataEntity.VirtualResourceMetadataId;
                        var newMetadataId = SequentialGuid.NewGuid();
                        metadataEntity.VirtualResourceMetadataId = newMetadataId;

                        // add the usage data as needed - asset, document, etc.
                        contract.ActivityAssetUsage.Where(x => x.VirtualResourceMetadataId == oldMetadataId).ToList().ForEach(x => metadataEntity.AssetUsage =
                                                                                                                                  new VirtualResourceMetadataAssetUsage()
                        {
                            VirtualResourceMetadataId = newMetadataId, AssetSelectionData = x.XmlSelectionData
                        });

                        contract.ActivityDocumentUsage.Where(x => x.VirtualResourceMetadataId == oldMetadataId).ToList().ForEach(x => metadataEntity.DocumentUsage =
                                                                                                                                     new VirtualResourceMetadataDocumentUsage()
                        {
                            VirtualResourceMetadataId = newMetadataId, DocumentSelectionData = x.XmlSelectionData
                        });

                        contract.ActivityPrintQueueUsage.Where(x => x.VirtualResourceMetadataId == oldMetadataId).ToList().ForEach(x => metadataEntity.PrintQueueUsage =
                                                                                                                                       new VirtualResourceMetadataPrintQueueUsage()
                        {
                            VirtualResourceMetadataId = newMetadataId, PrintQueueSelectionData = x.XmlSelectionData
                        });

                        contract.ActivityServerUsage.Where(x => x.VirtualResourceMetadataId == oldMetadataId).ToList().ForEach(x => metadataEntity.ServerUsage =
                                                                                                                                   new VirtualResourceMetadataServerUsage()
                        {
                            VirtualResourceMetadataId = newMetadataId, ServerSelectionData = x.XmlSelectionData
                        });

                        contract.ActivityRetrySettings.Where(x => x.VirtualResourceMetadataId == oldMetadataId).ToList().ForEach(x => metadataEntity.VirtualResourceMetadataRetrySettings.Add(
                                                                                                                                     new VirtualResourceMetadataRetrySetting()
                        {
                            VirtualResourceMetadataId = newMetadataId,
                            SettingId           = SequentialGuid.NewGuid(),
                            State               = x.State,
                            Action              = x.Action,
                            RetryLimit          = x.RetryLimit,
                            RetryDelay          = x.RetryDelay,
                            LimitExceededAction = x.LimitExceededAction
                        }));


                        importMaps.Add(new ImportMap()
                        {
                            OldId       = oldMetadataId,
                            NewId       = newMetadataId,
                            OldParentId = oldResourceId,
                            NewParentId = resourceEntity.VirtualResourceId,
                        });
                    }
                }
            }
            return(scenario);
        }
예제 #7
0
        /// <summary>
        /// Creates a scenario object from the specified scenario contract.
        /// </summary>
        /// <param name="contract">The scenario contract.</param>
        /// <returns></returns>
        public static EnterpriseScenario Create(EnterpriseScenarioContract contract)
        {
            var temp = new List <ImportMap>();

            return(Create(contract, out temp));
        }
예제 #8
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="scenario"></param>
 public EnterpriseScenarioCompositeContract(EnterpriseScenarioContract scenario)
 {
     Scenario  = scenario;
     Documents = new DocumentContractCollection();
     Printers  = new AssetContractCollection <PrinterContract>();
 }