/// <summary> /// Initializes a new instance of the <see cref="MigrateEnvironmentArgument" /> class. /// </summary> /// <param name="sourceEnvironment">The source environment.</param> /// <param name="newArtifactStoreId">The new artifact store identifier.</param> /// <param name="newEnvironmentName">New name of the environment.</param> public MigrateEnvironmentArgument(CommerceEnvironment sourceEnvironment, Guid newArtifactStoreId, string newEnvironmentName) { Condition.Requires(sourceEnvironment).IsNotNull("The sourceEnvironment can not be null"); Condition.Requires(newEnvironmentName).IsNotNullOrEmpty("The newEnvironmentName can not be null or empty"); this.SourceEnvironment = sourceEnvironment; this.NewArtifactStoreId = newArtifactStoreId; this.NewEnvironmentName = newEnvironmentName; }
public override void Initialize(IServiceProvider serviceProvider, ILogger logger, MinionPolicy policy, CommerceEnvironment environment, CommerceContext globalContext) { base.Initialize(serviceProvider, logger, policy, environment, globalContext); ReconcilePointsMinionPipeline = serviceProvider.GetService <IReconcilePointsMinionPipeline>(); }
public override void Initialize(IServiceProvider serviceProvider, ILogger logger, MinionPolicy policy, CommerceEnvironment environment, CommerceContext globalContext) { base.Initialize(serviceProvider, logger, policy, environment, globalContext); this.exportOrderPipeline = serviceProvider.GetService <IExportOrderPipeline>(); }
/// <summary> /// Public constructor with DI /// </summary> /// <param name="serviceProvider"></param> /// <param name="globalEnvironment"></param> /// <param name="getEnvironmentCommand"></param> public CommandsController(IServiceProvider serviceProvider, CommerceEnvironment globalEnvironment, GetEnvironmentCommand getEnvironmentCommand, IConfiguration configuration) : base(serviceProvider, globalEnvironment) { _getEnvironmentCommand = getEnvironmentCommand; _serviceProvider = serviceProvider; _globalEnvironment = globalEnvironment; _connectionString = configuration.GetConnectionString("AppSettings:ServiceBusConnectionString"); _topicName = configuration.GetValue <string>("AppSettings:ServiceBusTopicName"); _subscriptionName = configuration.GetValue <string>("AppSettings:ServiceBusSubscriptionName"); }
/// <inheritdoc /> /// <summary> /// Initializes a new instance of the <see cref="T:Sitecore.Commerce.Plugin.Sample.CommandsController" /> class. /// </summary> /// <param name="serviceProvider">The service provider.</param> /// <param name="globalEnvironment">The global environment.</param> /// <param name="catalogImporter">Catalog Importer</param> /// <param name="categoryImporter">Category Importer</param> /// <param name="productImporter">product importer</param> /// <param name="variantImporter">variant Importer</param> public CommandsController( IServiceProvider serviceProvider, CommerceEnvironment globalEnvironment, ICatalogImporter catalogImporter, ICategoryImporter categoryImporter, IProductImporter productImporter, IVariantImporter variantImporter) : base(serviceProvider, globalEnvironment) { _catalogImporter = catalogImporter; _categoryImporter = categoryImporter; _productImporter = productImporter; _variantImporter = variantImporter; }
/// <summary> /// Configures the services. /// </summary> /// <param name="services">The services.</param> public void ConfigureServices(IServiceCollection services) { this._services = services; this.SetupDataProtection(services); this.StartupEnvironment = this.GetGlobalEnvironment(); this.NodeContext.Environment = this.StartupEnvironment; this._services.AddSingleton(this.StartupEnvironment); this._services.AddSingleton(this.NodeContext); // Add the ODataServiceBuilder to the services collection services.AddOData(); // Add MVC services to the services container. services.AddMvc(); // TODO uncomment for Application Insights services.AddApplicationInsightsTelemetry(this._configuration); TelemetryConfiguration.Active.DisableTelemetry = true; this._logger.LogInformation("BootStrapping Services..."); services.Sitecore() .Eventing() //// .Bootstrap(this._hostServices) //// .AddServicesDiagnostics() .Caching(config => config .AddMemoryStore("GlobalEnvironment") .ConfigureCaches("GlobalEnvironment.*", "GlobalEnvironment")) //// .AddCacheDiagnostics() .Rules(config => config .IgnoreNamespaces(n => n.Equals("Sitecore.Commerce.Plugin.Tax"))) .RulesSerialization(); services.Add(new ServiceDescriptor(typeof(IRuleBuilderInit), typeof(RuleBuilder), ServiceLifetime.Transient)); this._logger.LogInformation("BootStrapping application..."); services.Sitecore().Bootstrap(this._hostServices); // TODO uncomment for Application Insights services.Add(new ServiceDescriptor(typeof(TelemetryClient), typeof(TelemetryClient), ServiceLifetime.Singleton)); this.NodeContext.Objects.Add(services); services.AddSingleton <Microsoft.Extensions.Logging.ILogger>(this._logger); }
public static NodeContext CommerceNodeInitialize(this IHostingEnvironment hostEnv, string nodeInstanceId) { var logger = ApplicationLogging.CreateLogger("ConfigNode"); // temporary environment status var environment = new CommerceEnvironment { Name = "Bootstrap" }; return(new NodeContext(logger, new TelemetryClient()) { CorrelationId = nodeInstanceId, ConnectionId = "Node_Global", ContactId = "Node_Global", GlobalEnvironment = environment, Environment = environment, WebRootPath = hostEnv.WebRootPath, LoggingPath = hostEnv.WebRootPath + @"\logs\", BootStrapProviderPath = hostEnv.WebRootPath + @"\Bootstrap\", // The default BootStrapEnvironmentPath = "Global", // The default }); }
public ServiceBusConsumer( CommerceCommander commerceCommander, GetEnvironmentCommand getEnvironmentCommand, ImportSellableItemFromContentHubCommand importSellableItemFromContentHubCommand, ImportCategoryFromContentHubCommand importCategoryFromContentHubCommand, IConfiguration configuration, ILogger <ServiceBusConsumer> logger, IServiceProvider serviceProvider, CommerceEnvironment globalEnvironment) { _serviceProvider = serviceProvider; _globalEnvironment = globalEnvironment; _getEnvironmentCommand = getEnvironmentCommand; _commerceCommander = commerceCommander; _logger = logger; _connectionString = configuration.GetConnectionString("AppSettings:ServiceBusConnectionString"); _topicName = configuration.GetValue <string>("AppSettings:ServiceBusTopicName"); _queueClient = new QueueClient(_connectionString, _topicName); this._nodeContext = serviceProvider.GetService <NodeContext>(); _importSellableItemFromContentHubCommand = importSellableItemFromContentHubCommand; _importCategoryFromContentHubCommand = importCategoryFromContentHubCommand; }
public override Task <string> Run(string arg, CommercePipelineExecutionContext context) { Condition.Requires <string>(arg).IsNotNullOrEmpty(this.Name + ": the environment name cannot be null or empty."); Log.Logger.Information("Resetting Node Context for environment '" + arg + "|" + this._nodeContext.CorrelationId + "'. Triggered by " + this.Name + "."); var environmentEntityId = arg.ToEntityId <CommerceEnvironment>(); CommerceEnvironment commerceEnvironment = this._nodeContext.GetEntities <CommerceEnvironment>().FirstOrDefault(p => p.Id.Equals(arg, StringComparison.OrdinalIgnoreCase)); if (commerceEnvironment != null) { commerceEnvironment.DisposeMinions(); this._nodeContext.RemoveEntity(commerceEnvironment); } EnvironmentContext environmentContext = this._nodeContext.GetObject <EnvironmentContext>(e => e.CorrelationId.Equals(arg, StringComparison.OrdinalIgnoreCase)); if (environmentContext != null) { this._nodeContext.RemoveObject(environmentContext); } return(Task.FromResult(arg)); }
public virtual async Task <RunMinionNowCommand> Process(CommerceContext commerceContext, string minionFullName, string environmentName, IList <Policy> policies) { RunMinionNowCommand runMinionNowCommand = this; using (CommandActivity.Start(commerceContext, (CommerceCommand)runMinionNowCommand)) { if (policies == null) { policies = (IList <Policy>) new List <Policy>(); } CommerceEnvironment commerceEnvironment = await this._getEnvironment.Process(commerceContext, environmentName) ?? commerceContext.Environment; CommercePipelineExecutionContextOptions pipelineContextOptions = commerceContext.PipelineContextOptions; pipelineContextOptions.CommerceContext.Environment = commerceEnvironment; IRunMinionPipeline runMinionPipeline = this._runMinionPipeline; RunMinionArgument runMinionArgument = new RunMinionArgument(minionFullName); runMinionArgument.Policies = policies; CommercePipelineExecutionContextOptions executionContextOptions = pipelineContextOptions; int num = await runMinionPipeline.Run(runMinionArgument, (IPipelineExecutionContextOptions)executionContextOptions) ? 1 : 0; } return(runMinionNowCommand); }
/// <inheritdoc /> /// <summary> /// Initializes a new instance of the <see cref="T:Plugin.NishTech.IntegrationFramework.JobConnectionsController" /> class. /// </summary> /// <param name="serviceProvider">The service provider.</param> /// <param name="globalEnvironment">The global environment.</param> public JobConnectionsController(IServiceProvider serviceProvider, CommerceEnvironment globalEnvironment) : base(serviceProvider, globalEnvironment) { }
/// <summary> /// Public constructor with DI /// </summary> /// <param name="serviceProvider"></param> /// <param name="globalEnvironment"></param> /// <param name="getEnvironmentCommand"></param> public CommandsController(IServiceProvider serviceProvider, CommerceEnvironment globalEnvironment, GetEnvironmentCommand getEnvironmentCommand) : base(serviceProvider, globalEnvironment) { _getEnvironmentCommand = getEnvironmentCommand; }
public EntityView Process(CommerceContext commerceContext, EntityView entityView, CommerceEnvironment environment) { using (CommandActivity.Start(commerceContext, this)) { try { if (environment == null) { return(entityView); } entityView.Properties .Add(new ViewProperty { Name = "Environment", RawValue = environment.Name, UiType = "EntityLink" }); entityView.Properties .Add(new ViewProperty { Name = "Policies", RawValue = environment.Policies.Count }); entityView.Properties .Add(new ViewProperty { Name = "Components", RawValue = environment.Components.Count }); entityView.Properties .Add(new ViewProperty { Name = "ArtifactStoreId", RawValue = environment.ArtifactStoreId.ToString("N") }); entityView.Properties .Add(new ViewProperty { Name = "GlobalEnvironmentName", RawValue = this._commerceCommander.CurrentNodeContext(commerceContext).GlobalEnvironmentName }); entityView.GetPolicy <ActionsPolicy>().Actions.Add( new EntityActionView { Name = "DoAction", IsEnabled = true, Description = "Description", DisplayName = "Do Action", RequiresConfirmation = false, UiHint = "RelatedList", EntityView = "/entityView/GetListView-CompletedOrders" }); } catch (Exception ex) { commerceContext.Logger.LogError($"ChildViewEnvironments.Exception: Message={ex.Message}"); } return(entityView); } }
public override async Task <string> Run(string arg, CommercePipelineExecutionContext context) { CustomBootStrapImportJsonsBlock importJsonsBlock = this; string environmentName = this._hostingEnvironment.EnvironmentName; Condition.Requires(arg).IsNotNull(importJsonsBlock.Name + ": The argument cannot be null."); string[] otherEnvironments = Directory.GetFiles(importJsonsBlock._nodeContext.WebRootPath + "\\data\\environments", $"*.json"); for (int index = 0; index < otherEnvironments.Length; ++index) { string fileName = otherEnvironments[index]; string file = File.ReadAllText(fileName); string environmentSpecificFileName = $"{fileName.Substring(0, fileName.LastIndexOf('.'))}.{environmentName}.json"; string environmentSpecificFile; try { environmentSpecificFile = File.ReadAllText(environmentSpecificFileName); } catch (Exception) { environmentSpecificFile = null; } bool skipFile = false; foreach (string otherEnvironment in otherEnvironments) { string brokenFileNameCurrentFile = $"{fileName.Substring(0, fileName.LastIndexOf('.'))}"; brokenFileNameCurrentFile = $"{brokenFileNameCurrentFile.Substring(0, brokenFileNameCurrentFile.LastIndexOf('.'))}"; string brokenFileNameFromList = $"{otherEnvironment.Substring(0, otherEnvironment.LastIndexOf('.'))}"; if (brokenFileNameFromList.Equals(brokenFileNameCurrentFile)) { skipFile = true; } } if (skipFile) { continue; } var targetFileToUse = ReplaceWithEnvironmentSpecificFile ? environmentSpecificFile ?? file : file; JObject jobject = JObject.Parse(targetFileToUse); // Json Validation if any property is present if (!jobject.HasValues || !jobject.Properties().Any(p => p.Name.Equals("$type", StringComparison.OrdinalIgnoreCase))) { context.Logger.LogError(importJsonsBlock.Name + ".Invalid json file '" + targetFileToUse + "'.", Array.Empty <object>()); break; } JProperty jproperty = jobject.Properties().FirstOrDefault(p => p.Name.Equals("$type", StringComparison.OrdinalIgnoreCase)); // Json Validation if type property is present if (string.IsNullOrEmpty(jproperty?.Value?.ToString())) { context.Logger.LogError(importJsonsBlock.Name + ".Invalid type in json file '" + targetFileToUse + "'.", Array.Empty <object>()); break; } // In case we have an environment specific json -> overwrite the given properties in the original json if (!ReplaceWithEnvironmentSpecificFile && !string.IsNullOrEmpty(environmentSpecificFile)) { JObject environmentspecificJObject = JObject.Parse(environmentSpecificFile); JProperty specificProperty = environmentspecificJObject.Properties().FirstOrDefault(); IterateJsonProperties(ref jobject, specificProperty as JToken); targetFileToUse = jobject.ToString(); } // Determination if file is environment if (jproperty.Value.ToString().Contains(typeof(CommerceEnvironment).FullName)) { context.Logger.LogInformation(importJsonsBlock.Name + ".ImportEnvironmentFromFile: File=" + targetFileToUse, Array.Empty <object>()); try { CommerceEnvironment commerceEnvironment = await importJsonsBlock._importEnvironmentCommand.Process(context.CommerceContext, targetFileToUse); context.Logger.LogInformation(importJsonsBlock.Name + ".EnvironmentImported: EnvironmentId=" + commerceEnvironment.Id + "|File=" + targetFileToUse, Array.Empty <object>()); } catch (Exception ex) { context.CommerceContext.LogException(importJsonsBlock.Name + ".ImportEnvironmentFromFile", ex); } } // Or policy-set else if (jproperty.Value.ToString().Contains(typeof(PolicySet).FullName)) { context.Logger.LogInformation(importJsonsBlock.Name + ".ImportPolicySetFromFile: File=" + targetFileToUse, Array.Empty <object>()); try { PolicySet policySet = await importJsonsBlock._importPolicySetCommand.Process(context.CommerceContext, targetFileToUse); context.Logger.LogInformation(importJsonsBlock.Name + ".PolicySetImported: PolicySetId=" + policySet.Id + "|File=" + targetFileToUse, Array.Empty <object>()); } catch (Exception ex) { context.CommerceContext.LogException(importJsonsBlock.Name + ".ImportPolicySetFromFile", ex); } } } return(arg); }
public override void Initialize(IServiceProvider serviceProvider, ILogger logger, MinionPolicy policy, CommerceEnvironment environment, CommerceContext globalContext) { base.Initialize(serviceProvider, logger, policy, environment, globalContext); CommerceCommander = serviceProvider.GetService <CommerceCommander>(); LogInitialization(); }
public override void Initialize(IServiceProvider serviceProvider, ILogger logger, MinionPolicy policy, CommerceEnvironment environment, CommerceContext globalContext) { base.Initialize(serviceProvider, logger, policy, environment, globalContext); this.MinionPipeline = serviceProvider.GetService <IProcessCustomerPipeline>(); this.CommerceCommand = new CommerceCommand(serviceProvider); }
public NewOrderNumberController(IServiceProvider serviceProvider, CommerceEnvironment globalEnvironment) : base(serviceProvider, globalEnvironment) { }
/// <inheritdoc /> /// <summary> /// Initializes a new instance of the <see cref="T:Plugin.LoyaltyPoints.Controllers.SampleController" /> class. /// </summary> /// <param name="serviceProvider">The service provider.</param> /// <param name="globalEnvironment">The global environment.</param> public SampleController(IServiceProvider serviceProvider, CommerceEnvironment globalEnvironment, GetSellableItemCommand getSellableItemCommand) : base(serviceProvider, globalEnvironment) { _serviceProvider = serviceProvider; _globalEnvironment = globalEnvironment; _getSellableItemCommand = getSellableItemCommand; }
public AddCustomOrderController(IServiceProvider serviceProvider, CommerceEnvironment globalEnvironment) : base(serviceProvider, globalEnvironment) { }
public FindLoyaltyOrderController(IServiceProvider serviceProvider, CommerceEnvironment globalEnvironment) : base(serviceProvider, globalEnvironment) { }
private void AddEnvironmentView(EntityView entityView, CommerceContext commerceContext, CommerceEnvironment environment) { if (environment == null) { return; } var entityViewEnvironment = new EntityView { EntityId = string.Empty, ItemId = environment.Id, DisplayName = "Environment Display Name", Name = "Environment - " + environment.Name }; entityViewEnvironment.Properties .Add(new ViewProperty { Name = "Environment", RawValue = environment.Name, UiType = "EntityLink" }); entityViewEnvironment.Properties .Add(new ViewProperty { Name = "Policies", RawValue = environment.Policies.Count }); entityViewEnvironment.Properties .Add(new ViewProperty { Name = "Components", RawValue = environment.Components.Count }); entityViewEnvironment.Properties .Add(new ViewProperty { Name = "ArtifactStoreId", RawValue = environment.ArtifactStoreId.ToString("N") }); entityViewEnvironment.Properties .Add(new ViewProperty { Name = "GlobalEnvironmentName", RawValue = this._commerceCommander.CurrentNodeContext(commerceContext).GlobalEnvironmentName }); entityView.ChildViews.Add(entityViewEnvironment); }
public SellableItemPriceCardController( IServiceProvider serviceProvider, CommerceEnvironment globalEnvironment) : base(serviceProvider, globalEnvironment) { }
private static void CloneEnvironment() { using (new SampleMethodScope()) { var originalEnvironment = ExportEnvironment( EnvironmentConstants.AdventureWorksShops); // Export an Environment to use as a template var serializer = new JsonSerializer { TypeNameHandling = TypeNameHandling.All, NullValueHandling = NullValueHandling.Ignore }; var reader = new StringReader(originalEnvironment); CommerceEnvironment newEnvironment = null; using (var jsonReader = new JsonTextReader(reader) { DateParseHandling = DateParseHandling.DateTimeOffset }) { newEnvironment = serializer.Deserialize <CommerceEnvironment>(jsonReader); } // Change the Id of the environment in order to import as a new Environment var newEnvironmentId = Guid.NewGuid(); newEnvironment.ArtifactStoreId = newEnvironmentId; newEnvironment.Name = "ConsoleSample." + newEnvironmentId.ToString("N"); var sw = new StringWriter(new StringBuilder()); string newSerializedEnvironment = null; using (var writer = new JsonTextWriter(sw)) { serializer.Serialize(writer, newSerializedEnvironment); } newSerializedEnvironment = sw.ToString(); // imports the environment into Sitecore Commerce var importedEnvironment = ImportEnvironment(newSerializedEnvironment); importedEnvironment.EntityId.Should() .Be($"Entity-CommerceEnvironment-ConsoleSample.{newEnvironmentId}"); importedEnvironment.Name.Should().Be($"ConsoleSample.{newEnvironmentId}"); // Adds a policy var policyResult = Proxy.DoOpsCommand( OpsContainer.AddPolicy( importedEnvironment.EntityId, "Sitecore.Commerce.Plugin.Availability.GlobalAvailabilityPolicy, Sitecore.Commerce.Plugin.Availability", new GlobalAvailabilityPolicy { AvailabilityExpires = 0 }, "GlobalEnvironment")); policyResult.Messages.Any(m => m.Code.Equals("error", StringComparison.OrdinalIgnoreCase)) .Should() .BeFalse(); policyResult.Models.OfType <PolicyAddedModel>().Any().Should().BeTrue(); // Initialize the Environment with default artifacts Bootstrapping.InitializeEnvironment(OpsContainer, $"ConsoleSample.{newEnvironmentId}"); // Get a SellableItem from the environment to assure that we have set it up correctly var shopperInNewEnvironmentContainer = new RegisteredCustomerDana { Context = { Environment = $"ConsoleSample.{newEnvironmentId}" } }.Context.ShopsContainer(); var result = Proxy.GetValue( shopperInNewEnvironmentContainer.SellableItems.ByKey("Adventure Works Catalog,AW055 01,") .Expand( "Components($expand=ChildComponents($expand=ChildComponents($expand=ChildComponents)))")); result.Should().NotBeNull(); result.Name.Should().Be("Unisex hiking pants"); // Get the environment to validate change was made var updatedEnvironment = Proxy.GetValue(OpsContainer.Environments.ByKey(importedEnvironment.EntityUniqueId.ToString())); var globalAvailabilityPolicy = updatedEnvironment.Policies.OfType <GlobalAvailabilityPolicy>().FirstOrDefault(); globalAvailabilityPolicy.Should().NotBeNull(); globalAvailabilityPolicy.AvailabilityExpires.Should().Be(0); } }
public NearestStoreLocatorController(IServiceProvider serviceProvider, CommerceEnvironment globalEnvironment) : base(serviceProvider, globalEnvironment) { }
public GetWishlistDataController(IServiceProvider serviceProvider, CommerceEnvironment globalEnvironment) : base(serviceProvider, globalEnvironment) { }
public static void ConfigureCommerceNode(this IServiceCollection services, IConfigurationRoot configuration, string nodeInstanceId, CommerceEnvironment environment, NodeContext node) { node.Environment = environment; node.GlobalEnvironmentName = environment.Name; node.AddDataMessage("NodeStartup", $"Status='Started',GlobalEnvironmentName='{node.GlobalEnvironmentName}'"); if (!string.IsNullOrEmpty(environment.GetPolicy <DeploymentPolicy>().DeploymentId)) { node.ContactId = $"{environment.GetPolicy<DeploymentPolicy>().DeploymentId}_{nodeInstanceId}"; } else if (configuration.GetSection("AppSettings:BootStrapFile").Value != null) { node.ContactId = configuration.GetSection("AppSettings:NodeId").Value; } node.Objects.Add(services); services.AddSingleton(node); }
private void AddComponentsListView(EntityView entityView, CommerceContext commerceContext, CommerceEnvironment environment) { if (environment == null) { return; } var componentsListContainer = new EntityView { EntityId = string.Empty, ItemId = string.Empty, DisplayName = "Entity Components", Name = "Components", UiHint = "Table" }; entityView.ChildViews.Add(componentsListContainer); foreach (var component in environment.Components) { var environmentRowEntityView = new EntityView { EntityId = entityView.EntityId, ItemId = component.Id, Name = component.GetType().FullName, DisplayName = component.GetType().FullName, UiHint = "Flat" }; componentsListContainer.ChildViews.Add(environmentRowEntityView); environmentRowEntityView.Properties.Add(new ViewProperty { Name = "Name", RawValue = component.GetType().FullName }); } }
private void AddPoliciesListView(EntityView entityView, CommerceContext commerceContext, CommerceEnvironment environment) { if (environment == null) { return; } var pluginPolicy = commerceContext.GetPolicy <PluginPolicy>(); var localpolicies = new List <Policy>(); localpolicies.AddRange(environment.Policies); var policySetPolicies = localpolicies.OfType <PolicySetPolicy>().ToList(); try { var policySetsView = new EntityView { EntityId = string.Empty, ItemId = string.Empty, DisplayName = "Policy Sets", Name = "PolicySets", UiHint = "Table" }; entityView.ChildViews.Add(policySetsView); foreach (var policySetPolicy in policySetPolicies) { localpolicies.Remove(policySetPolicy); policySetsView.ChildViews.Add( new EntityView { ItemId = $"{policySetPolicy.PolicyId}", Icon = pluginPolicy.Icon, Properties = new List <ViewProperty> { new ViewProperty { Name = "ItemId", RawValue = $"{policySetPolicy.PolicyId}", UiType = "EntityLink", IsHidden = true }, new ViewProperty { Name = "PolicySetId", RawValue = policySetPolicy.PolicySetId } } }); } } catch (Exception ex) { commerceContext.Logger.LogError($"Catalog.DoActionAddList.Exception: Message={ex.Message}"); } var validationPolicies = localpolicies.OfType <ValidationPolicy>().ToList(); try { var validationsView = new EntityView { EntityId = string.Empty, ItemId = string.Empty, DisplayName = "Validation Policies", Name = "ValidationPolicies", UiHint = "Table" }; entityView.ChildViews.Add(validationsView); foreach (var policy in validationPolicies) { localpolicies.Remove(policy); var validationAttributes = policy.Models.OfType <ValidationAttributes>().FirstOrDefault();; validationsView.ChildViews.Add( new EntityView { ItemId = $"{policy.PolicyId}", Icon = pluginPolicy.Icon, Properties = new List <ViewProperty> { new ViewProperty { Name = "ItemId", RawValue = $"{policy.PolicyId}", UiType = "EntityLink", IsHidden = true }, new ViewProperty { Name = "Name", RawValue = policy.TypeFullName }, new ViewProperty { Name = "Validator", RawValue = validationAttributes.RegexValidator }, new ViewProperty { Name = "Error", RawValue = validationAttributes.RegexValidatorErrorCode }, new ViewProperty { Name = "Required", RawValue = validationAttributes.IsRequired }, new ViewProperty { Name = "Required", RawValue = validationAttributes.MinLength }, new ViewProperty { Name = "Required", RawValue = validationAttributes.MaxLength } } }); } } catch (Exception ex) { commerceContext.Logger.LogError($"DevOps.AddPoliciesListView.Exception: Message={ex.Message}"); } var memoryCachePolicies = new List <EntityMemoryCachingPolicy>(); memoryCachePolicies.AddRange(localpolicies.OfType <EntityMemoryCachingPolicy>()); var memoryCacheListContainer = new EntityView { EntityId = string.Empty, ItemId = string.Empty, DisplayName = "Entity memory Caching", Name = "Entity memory Caching", UiHint = "Table" }; entityView.ChildViews.Add(memoryCacheListContainer); foreach (var memoryCachePolicy in memoryCachePolicies) { var environmentRowEntityView = new EntityView { EntityId = entityView.EntityId, ItemId = memoryCachePolicy.PolicyId, Name = memoryCachePolicy.GetType().Name, DisplayName = memoryCachePolicy.GetType().FullName, UiHint = "Flat" }; memoryCacheListContainer.ChildViews.Add(environmentRowEntityView); environmentRowEntityView.Properties.Add(new ViewProperty { Name = "Name", RawValue = memoryCachePolicy.EntityFullName }); environmentRowEntityView.Properties.Add(new ViewProperty { Name = "AllowCaching", RawValue = memoryCachePolicy.AllowCaching }); if (memoryCachePolicy.AllowCaching) { environmentRowEntityView.Properties.Add(new ViewProperty { Name = "CacheAsEntity", RawValue = memoryCachePolicy.CacheAsEntity }); environmentRowEntityView.Properties.Add(new ViewProperty { Name = "CacheName", RawValue = memoryCachePolicy.CacheName }); environmentRowEntityView.Properties.Add(new ViewProperty { Name = "Expiration", RawValue = memoryCachePolicy.Expiration }); environmentRowEntityView.Properties.Add(new ViewProperty { Name = "HasNegativeCaching", RawValue = memoryCachePolicy.HasNegativeCaching }); environmentRowEntityView.Properties.Add(new ViewProperty { Name = "Priority", RawValue = memoryCachePolicy.Priority }); } localpolicies.Remove(memoryCachePolicy); } foreach (var policy in localpolicies) { var policyName = policy.GetType().Name; var policyEntityView = new EntityView { EntityId = entityView.EntityId, ItemId = policy.PolicyId, Name = policyName, DisplayName = policyName, UiHint = "Flat" }; entityView.ChildViews.Add(policyEntityView); if (policyName == "GlobalEnvironmentPolicy") { policyEntityView.DisplayRank = 100; } if (policyName == "SitecoreConnectionPolicy") { policyEntityView.DisplayRank = 0; } if (policyName == "CsCatalogPolicy") { policyEntityView.DisplayRank = 0; } var props = policy.GetType().GetProperties(); foreach (var prop in props) { if (prop.Name == "Models" || prop.Name == "PolicyId") { //DoNothing } else { var newProp = new ViewProperty { Name = prop.Name, RawValue = prop.GetValue(policy, null) }; var originalType = prop.PropertyType.FullName; try { if (policyName == "CsCatalogPolicy") { if (newProp.Name == "SchemaTimeout" || newProp.Name == "ItemInformationCacheTimeout" || newProp.Name == "ItemHierarchyCacheTimeout" || newProp.Name == "ItemRelationshipsCacheTimeout" || newProp.Name == "ItemAssociationsCacheTimeout" || newProp.Name == "CatalogCollectionCacheTimeout" || newProp.Name == "SupportedAuthorizationMethods") { newProp.IsHidden = true; } } if (policyName == "SitecoreConnectionPolicy" && prop.Name == "Host") { newProp.RawValue = $"<a href='http://{newProp.RawValue}' target='_blank' >(Shop){newProp.RawValue}</a><br><a href='http://{newProp.RawValue}/sitecore' target='_blank' >(Admin){newProp.RawValue}/sitecore</a>"; newProp.UiType = "Html"; newProp.OriginalType = "Html"; } if (originalType == "Sitecore.Commerce.Core.EntityReference") { commerceContext.Logger.LogInformation($"DevOps.EntityViewEnvironment.CantProcessProperty: Name={prop.Name}|OriginalType={originalType}"); if (newProp.RawValue is EntityReference reference) { newProp.RawValue = $"<a href='entityView/Master/{reference.EntityTarget}' >{reference.EntityTarget}</a>"; newProp.UiType = "Html"; newProp.OriginalType = "Html"; } else { newProp.RawValue = "[Reference (Null)]"; } } else if (newProp.RawValue is List <EntityReference> propList) { var finalValue = string.Empty; foreach (var propRow in propList) { finalValue = finalValue + $"<a href='entityView/Master/{propRow.EntityTarget}' >{propRow.EntityTarget}</a></br>"; newProp.UiType = "Html"; newProp.OriginalType = "Html"; } newProp.RawValue = finalValue; } else if (originalType.Contains("System.Collections.Generic.List")) { if (newProp.RawValue is List <string> stringList) { var finalValue = string.Empty; foreach (var value in stringList) { finalValue = finalValue + $"{value}<br>"; } newProp.RawValue = finalValue; newProp.UiType = "Html"; newProp.OriginalType = "Html"; } else { newProp.RawValue = $"(List-{originalType})"; } } else if (originalType.Contains("System.Collections.Generic.IList")) { commerceContext.Logger.LogInformation($"DevOps.EntityViewEnvironment.CantProcessProperty: Name={prop.Name}|OriginalType={originalType}"); newProp.RawValue = newProp.RawValue is List <string> list ? $"(String-{list.Count})" : $"(List-{originalType})"; } if (newProp.RawValue is bool) { newProp.OriginalType = "System.Boolean"; } } catch (Exception ex) { commerceContext.Logger.LogError($"DevOps.EntityViewEnvironment.Exception: Message={ex.Message}|Name={prop.Name}|OriginalType={originalType}"); } policyEntityView.Properties.Add(newProp); } } } }
/// <inheritdoc /> /// <summary> /// Initializes a new instance of the <see cref="T:Sitecore.HabitatHome.Feature.Orders.Engine.Controllers.CommandsController" /> class. /// </summary> /// <param name="serviceProvider">The service provider.</param> /// <param name="globalEnvironment">The global environment.</param> public CommandsController(IServiceProvider serviceProvider, CommerceEnvironment globalEnvironment) : base(serviceProvider, globalEnvironment) { }
/// <inheritdoc /> /// <summary> /// Initializes a new instance of the <see cref="T:Plugin.NishTech.IntegrationFramework.JobInstancesController" /> class. /// </summary> /// <param name="serviceProvider">The service provider.</param> /// <param name="globalEnvironment">The global environment.</param> public JobInstancesController(IServiceProvider serviceProvider, CommerceEnvironment globalEnvironment) : base(serviceProvider, globalEnvironment) { }