static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //Prompt User for Plugin to load SelectPluginForm selectForm = new SelectPluginForm(); if (selectForm.ShowDialog() == DialogResult.Cancel) { return; } //Create the Framework Simulator PluginFactory.PluginRelativePath = ConfigurationManager.AppSettings["PluginRelativeLocation"]; PluginAssembly pluginAssembly = PluginFactory.GetPluginByAssemblyName(selectForm.PluginAssemblyName); InternalFrameworkSimulator simulator = new InternalFrameworkSimulator(ConfigurationManager.AppSettings["GlobalDatabase"], pluginAssembly); // Paperless mode simulator.PaperlessMode = JobMediaMode.Paperless; // Common environment values simulator.SessionId = ConfigurationManager.AppSettings["SessionId"]; simulator.UserName = ConfigurationManager.AppSettings["UserName"]; simulator.UserPassword = ConfigurationManager.AppSettings["UserPassword"]; simulator.UserDomain = ConfigurationManager.AppSettings["UserDomain"]; simulator.UserDnsDomain = ConfigurationManager.AppSettings["UserDnsDomain"]; simulator.FileRepository.DocumentShare = ConfigurationManager.AppSettings["DocumentShareLocation"]; // Less common values used by some plugins simulator.PluginSettings["sampleKey"] = "sampleValue"; simulator.EnvironmentConfiguration.OutputMonitorDestinations.Add("dss100"); simulator.EnvironmentConfiguration.ServerServices.Add("spooler"); simulator.SessionRuntime.OfficeWorkerEmailAddresses.Add("*****@*****.**"); Application.Run(new PluginFrameworkSimulatorForm(simulator)); }
/// <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); }