Ejemplo n.º 1
0
        /// <summary>
        /// Notifies this extension component that it has been registered in the owner's collection of extensions.
        /// </summary>
        /// <param name="owner">The extensible owner object that aggregates this extension.</param>
        public void Attach(IExtensibleCloudServiceComponent owner)
        {
            owner.Extensions.Demand <ICloudStorageProviderExtension>();
            owner.Extensions.Demand <ICloudStorageLoadBalancingExtension>();
            owner.Extensions.Demand <IXslTransformProviderExtension>();

            this.cloudStorageProvider     = owner.Extensions.Find <ICloudStorageProviderExtension>();
            this.cloudStorageLoadBalancer = owner.Extensions.Find <ICloudStorageLoadBalancingExtension>();
            this.transformProvider        = owner.Extensions.Find <IXslTransformProviderExtension>();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Notifies this extension component that it has been registered in the owner's collection of extensions.
        /// </summary>
        /// <param name="owner">The extensible owner object that aggregates this extension.</param>
        public void Attach(IExtensibleCloudServiceComponent owner)
        {
            owner.Extensions.Demand <IScalableTransformServiceClientExtension>();
            owner.Extensions.Demand <ICloudStorageProviderExtension>();
            owner.Extensions.Demand <IWorkItemProcessorConfigurationExtension>();
            owner.Extensions.Demand <IRulesEngineServiceClientExtension>();
            owner.Extensions.Demand <ICloudCacheProviderExtension>();

            this.transformService         = owner.Extensions.Find <IScalableTransformServiceClientExtension>();
            this.storageProviderExtension = owner.Extensions.Find <ICloudStorageProviderExtension>();
            this.configSettingsExtension  = owner.Extensions.Find <IWorkItemProcessorConfigurationExtension>();
            this.rulesEngineExtension     = owner.Extensions.Find <IRulesEngineServiceClientExtension>();
            this.cacheProviderExtension   = owner.Extensions.Find <ICloudCacheProviderExtension>();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Notifies this extension component that it has been registered in the owner's collection of extensions.
        /// </summary>
        /// <param name="owner">The extensible owner object that aggregates this extension.</param>
        public void Attach(IExtensibleCloudServiceComponent owner)
        {
            var callToken = TraceManager.WorkerRoleComponent.TraceIn(this.queueLocation.StorageAccount, this.queueLocation.QueueName);

            try
            {
                owner.Extensions.Demand <ICloudStorageProviderExtension>();

                if (!this.queueLocation.IsDiscoverable)
                {
                    var queueLocationResolvers = owner.Extensions.FindAll <ICloudQueueLocationResolverExtension>();

                    foreach (ICloudQueueLocationResolverExtension locationResolver in queueLocationResolvers)
                    {
                        this.queueLocation = locationResolver.GetQueueLocation(this.queueLocation.QueueName);

                        if (this.queueLocation.IsDiscoverable)
                        {
                            break;
                        }
                    }
                }

                if (this.queueLocation.IsDiscoverable)
                {
                    ICloudStorageProviderExtension storageProvider = owner.Extensions.Find <ICloudStorageProviderExtension>();

                    this.queueStorage = storageProvider.GetQueueStorage(this.queueLocation.StorageAccount);

                    // Ensure that the queue is available, create a new queue if one doesn't exist.
                    this.queueStorage.CreateQueue(this.queueLocation.QueueName);
                }
                else
                {
                    throw new CloudApplicationException(String.Format(CultureInfo.CurrentCulture, ExceptionMessages.CloudQueueNotDiscoverable, this.queueLocation.QueueName));
                }
            }
            finally
            {
                TraceManager.WorkerRoleComponent.TraceOut(callToken);
            }
        }
Ejemplo n.º 4
0
        private void HandlePersistenceQueueItem(PersistenceQueueItemInfo itemInfo)
        {
            Guard.ArgumentNotNull(itemInfo, "itemInfo");

            this.owner.Extensions.Demand <IRulesEngineServiceClientExtension>();
            this.owner.Extensions.Demand <IWorkItemSchedulerConfigurationExtension>();
            this.owner.Extensions.Demand <IRoleConfigurationSettingsExtension>();
            this.owner.Extensions.Demand <ICloudStorageProviderExtension>();
            this.owner.Extensions.Demand <IInterRoleCommunicationExtension>();

            IRulesEngineServiceClientExtension       rulesEngineExtension         = this.owner.Extensions.Find <IRulesEngineServiceClientExtension>();
            IWorkItemSchedulerConfigurationExtension configSettingsExtension      = this.owner.Extensions.Find <IWorkItemSchedulerConfigurationExtension>();
            IRoleConfigurationSettingsExtension      roleConfigExtension          = this.owner.Extensions.Find <IRoleConfigurationSettingsExtension>();
            ICloudStorageProviderExtension           storageProviderExtension     = this.owner.Extensions.Find <ICloudStorageProviderExtension>();
            IActivityTrackingEventStreamExtension    trackingEventStreamExtension = this.owner.Extensions.Find <IActivityTrackingEventStreamExtension>();
            IInterRoleCommunicationExtension         interCommExtension           = this.owner.Extensions.Find <IInterRoleCommunicationExtension>();

            // Update BAM activity to indicate when we started the dequeue operation.
            if (trackingEventStreamExtension != null)
            {
                InventoryDataTrackingActivity activity = new InventoryDataTrackingActivity(itemInfo.QueueItemId.ToString())
                {
                    DequeueOperationStarted = DateTime.UtcNow
                };
                trackingEventStreamExtension.UpdateActivity(activity);
            }

            var xPathLib  = roleConfigExtension.GetSection <XPathQueryLibrary>(XPathQueryLibrary.SectionName);
            var batchInfo = rulesEngineExtension.ExecutePolicy <PersistenceQueueItemBatchInfo>(configSettingsExtension.Settings.HandlingPolicyName, itemInfo, new MessageTypeFact(itemInfo.QueueItemType));

            // Verify the batch metadata to ensure we have everything we need to be able to perform de-batching.
            ValidateBatchMetadata(itemInfo, batchInfo);

            // Replace the XPath query references with actual expressions taken from the XPath Library.
            batchInfo.BodyItemXPath      = xPathLib.Queries.Contains(batchInfo.BodyItemXPath) ? xPathLib.GetXPathQuery(batchInfo.BodyItemXPath) : batchInfo.BodyItemXPath;
            batchInfo.BodyItemCountXPath = xPathLib.Queries.Contains(batchInfo.BodyItemCountXPath) ? xPathLib.GetXPathQuery(batchInfo.BodyItemCountXPath) : batchInfo.BodyItemCountXPath;

            var headerXPathList = from item in batchInfo.HeaderSegments where xPathLib.Queries.Contains(item) select new { Segment = item, XPath = xPathLib.GetXPathQuery(item) };
            var bodyXPathList   = from item in batchInfo.BodySegments where xPathLib.Queries.Contains(item) select new { Segment = item, XPath = xPathLib.GetXPathQuery(item) };
            var footerXPathList = from item in batchInfo.FooterSegments where xPathLib.Queries.Contains(item) select new { Segment = item, XPath = xPathLib.GetXPathQuery(item) };

            foreach (var item in headerXPathList.ToList())
            {
                batchInfo.HeaderSegments.Remove(item.Segment);
                batchInfo.HeaderSegments.Add(item.XPath);
            }

            foreach (var item in bodyXPathList.ToList())
            {
                batchInfo.BodySegments.Remove(item.Segment);
                batchInfo.BodySegments.Add(item.XPath);
            }

            foreach (var item in footerXPathList.ToList())
            {
                batchInfo.FooterSegments.Remove(item.Segment);
                batchInfo.FooterSegments.Add(item.XPath);
            }

            int fromItem = 1, toItem = fromItem, maxItems = configSettingsExtension.Settings.XmlBatchSize;
            var taskParameters = new List <DequeueXmlDataTaskState>();

            using (SqlAzurePersistenceQueue persistenceQueue = new SqlAzurePersistenceQueue())
            {
                persistenceQueue.Open(WellKnownDatabaseName.PersistenceQueue);

                using (XmlReader resultReader = persistenceQueue.QueryXmlData(itemInfo.QueueItemId, new string[] { batchInfo.BodyItemCountXPath }, xPathLib.Namespaces.NamespaceManager))
                {
                    maxItems = resultReader.ReadContentAsInt();
                }
            }

            do
            {
                toItem = fromItem + configSettingsExtension.Settings.XmlBatchSize - 1;

                taskParameters.Add(new DequeueXmlDataTaskState()
                {
                    QueueItemInfo      = itemInfo,
                    HeaderSegments     = new List <string>(batchInfo.HeaderSegments),
                    BodySegments       = new List <string>(from query in batchInfo.BodySegments select String.Format(query, fromItem, toItem)),
                    FooterSegments     = new List <string>(batchInfo.FooterSegments),
                    StartItemIndex     = fromItem,
                    EndItemIndex       = toItem,
                    ItemDetectionXPath = batchInfo.BodyItemXPath,
                    Settings           = configSettingsExtension.Settings,
                    StorageProvider    = storageProviderExtension,
                    NamespaceManager   = xPathLib.Namespaces.NamespaceManager
                });

                fromItem += configSettingsExtension.Settings.XmlBatchSize;
            }while (toItem < maxItems);

            // Before we start putting work items on queue, notify the respective queue listeners that they should expect work to arrive.
            CloudQueueWorkDetectedTriggerEvent trigger = new CloudQueueWorkDetectedTriggerEvent(configSettingsExtension.Settings.CloudStorageAccount, configSettingsExtension.Settings.DestinationQueue, maxItems, PayloadSizeKind.MessageCount);

            // Package the trigger into an inter-role communication event.
            var interRoleEvent = new InterRoleCommunicationEvent(trigger);

            // Publish inter-role communication event via the Service Bus one-way multicast.
            interCommExtension.Publish(interRoleEvent);

            var stateCollection = from x in taskParameters.AsParallel <DequeueXmlDataTaskState>()
                                  orderby x.StartItemIndex
                                  select x;

            foreach (var state in stateCollection)
            {
                try
                {
                    DequeueXmlDataTaskMain(state);
                }
                catch (Exception ex)
                {
                    TraceManager.WorkerRoleComponent.TraceError(ex);
                }
            }

            // Update BAM activity to indicate when we completed the dequeue operation.
            if (trackingEventStreamExtension != null)
            {
                InventoryDataTrackingActivity activity = new InventoryDataTrackingActivity(itemInfo.QueueItemId.ToString())
                {
                    DequeueOperationCompleted = DateTime.UtcNow
                };
                trackingEventStreamExtension.UpdateActivity(activity);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Notifies this extension component that it has been registered in the owner's collection of extensions.
        /// </summary>
        /// <param name="owner">The extensible owner object that aggregates this extension.</param>
        public void Attach(IExtensibleCloudServiceComponent owner)
        {
            owner.Extensions.Demand <ICloudStorageProviderExtension>();

            this.cloudStorageProvider = owner.Extensions.Find <ICloudStorageProviderExtension>();
        }