private string ResolveTransformName(XDocument document) { Guard.ArgumentNotNull(document, "document"); // Create a Rules Engine fact representing the message type of the item being processed. MessageTypeFact msgTypeFact = new MessageTypeFact(document); // Construct a cache key that uniquely identifies a specific cache item based on the input document type. string cacheKeyName = String.Concat(this.GetType().FullName, "_ResolveTransform_", msgTypeFact.Value); return(this.cacheProviderExtension.GetOrPut(cacheKeyName, () => { // Invoke a policy to determine the name of the map to be applied to the item being processed. StringDictionaryFact policyExecutionResult = this.rulesEngineExtension.ExecutePolicy <StringDictionaryFact>(this.configSettingsExtension.Settings.HandlingPolicyName, msgTypeFact); if (policyExecutionResult != null && policyExecutionResult.Items != null && policyExecutionResult.Items.Count > 0) { // Take a dictionary item by it's predefined name. return policyExecutionResult.Items[Resources.StringDictionaryFactValueTransformName]; } else { return null; } }) as string); }
private Type ResolveDataTransferObjectType(XDocument document) { Guard.ArgumentNotNull(document, "document"); // Create a Rules Engine fact representing the message type of the item being processed. MessageTypeFact msgTypeFact = new MessageTypeFact(document); // Construct a cache key that uniquely identifies a specific cache item based on the input document type. string cacheKeyName = String.Concat(this.GetType().FullName, "_ResolveDTOTypeName_", msgTypeFact.Value); string dtoTypeName = this.cacheProviderExtension.GetOrPut(cacheKeyName, () => { // Invoke a policy to determine the name of the map to be applied to the item being processed. StringDictionaryFact policyExecutionResult = this.rulesEngineExtension.ExecutePolicy <StringDictionaryFact>(this.configSettingsExtension.Settings.HandlingPolicyName, msgTypeFact); if (policyExecutionResult != null && policyExecutionResult.Items != null && policyExecutionResult.Items.Count > 0) { // Take a dictionary item by it's predefined name. return(policyExecutionResult.Items[Resources.StringDictionaryFactValueDataTransferObjectType]); } else { return(null); } }) as string; if (!String.IsNullOrEmpty(dtoTypeName)) { // Construct a cache key that uniquely identifies a specific cache item based on the input document type. cacheKeyName = String.Concat(this.GetType().FullName, "_ResolveDTOType_", dtoTypeName); return(this.cacheProviderExtension.GetOrPut(cacheKeyName, () => { // First, assume that we have a fully-qualified type name. Type dtoType = Type.GetType(dtoTypeName, false); if (dtoType != null) { return dtoType; } // Not a fully qualified type name, assume we have a type name with namespace, try to append the assembly name. string fullTypeName = DefaultDtoAssemblyQualifiedName.Replace(DefaultDtoTypeFullName, dtoTypeName); dtoType = Type.GetType(fullTypeName, false); if (dtoType != null) { return dtoType; } // Still not found, assume we have just a type name, append both the namespace and assembly name. fullTypeName = DefaultDtoAssemblyQualifiedName.Replace(DefaultDtoTypeFullName, String.Concat(DefaultDtoNamespace, ".", dtoTypeName)); dtoType = Type.GetType(fullTypeName, false); return dtoType; }) as Type); } else { return(null); } }
private void HandlePersistenceQueueItem(PersistenceQueueItemInfo itemInfo) { Guard.ArgumentNotNull(itemInfo, "itemInfo"); var callToken = TraceManager.WorkerRoleComponent.TraceIn(itemInfo.QueueItemId, itemInfo.QueueItemType, itemInfo.QueueItemSize); try { this.owner.Extensions.Demand <IRulesEngineServiceClientExtension>(); this.owner.Extensions.Demand <IWorkItemProcessorConfigurationExtension>(); IWorkItemProcessorConfigurationExtension configSettingsExtension = this.owner.Extensions.Find <IWorkItemProcessorConfigurationExtension>(); IRulesEngineServiceClientExtension rulesEngineExtension = this.owner.Extensions.Find <IRulesEngineServiceClientExtension>(); // Invoke a policy to determine the number of dequeue listeners required to process this volume of data. StringDictionaryFact policyExecutionResult = rulesEngineExtension.ExecutePolicy <StringDictionaryFact>(configSettingsExtension.Settings.HandlingPolicyName, itemInfo); int dequeueTaskCount = policyExecutionResult != null && !String.IsNullOrEmpty(policyExecutionResult.Items[Resources.StringDictionaryFactValueDequeueListenerCount]) ? Convert.ToInt32(policyExecutionResult.Items[Resources.StringDictionaryFactValueDequeueListenerCount]) : 0; // Check if the policy has provided us with the number of queue listeners. if (dequeueTaskCount > 0) { // Write the number of dequeue tasks into trace log. TraceManager.WorkerRoleComponent.TraceInfo(TraceLogMessages.DequeueTaskCountInfo, itemInfo.QueueItemType, itemInfo.QueueItemSize, dequeueTaskCount); // Request all queue listeners to increase the number of listeners accordingly to the given workload. foreach (var queueService in this.owner.Extensions.FindAll <ICloudQueueServiceWorkerRoleExtension>()) { // Get the queue listener state information such as queue depth, number of activity listener threads and total number of listener threads. var state = queueService.QueryState(); // If the queue listener count is less than suggested by the policy, start as many extra listener threads as needed. if (state.ActiveDequeueTasks < dequeueTaskCount) { queueService.StartListener(dequeueTaskCount - state.ActiveDequeueTasks); } } } } finally { TraceManager.WorkerRoleComponent.TraceOut(callToken); } }