Beispiel #1
0
        public static void ProcessMessage(QueueEnvelope envelope, bool reportEnvelopeError = true)
        {
            try
            {
                InformationContext.Current.InitializeCloudStorageAccess(envelope.ActiveContainerName);
                if (envelope.SingleOperation != null)
                {
                    ProcessSingleOperation(envelope.SingleOperation);
                }
                if (envelope.OrderDependentOperationSequence != null)
                {
                    Exception firstException = null;
                    //envelope.OrderDependentOperationSequence.CollectionContent.ForEach(ProcessSingleOperation);
                    foreach (var singleOperation in envelope.OrderDependentOperationSequence.CollectionContent)
                    {
                        try
                        {
                            ProcessSingleOperation(singleOperation);
                        } catch (Exception ex)
                        {
                            firstException = ex;
                            ErrorSupport.ReportException(ex);
                        }
                    }
                    if (firstException != null)
                    {
                        throw firstException;
                    }
                }
            }
            catch (Exception ex)
            {
                if (reportEnvelopeError)
                {
                    ErrorSupport.ReportEnvelopeWithException(envelope, ex);
                }
                throw;
            } finally
            {
                InformationContext.ProcessAndClearCurrent();
            }

            counter++;
            if (counter >= 1000)
            {
                QueueSupport.ReportStatistics("Processed " + counter + " messages...");
                counter = 0;
            }
        }
Beispiel #2
0
 public static bool ProcessOwnerSubscriptionChains(IContainerOwner lockedOwner, string acquiredEtag, string containerName)
 {
     try
     {
         if (containerName != null)
         {
             InformationContext.Current.InitializeCloudStorageAccess(containerName: containerName);
         }
         string[]     blobs        = SubscribeSupport.GetChainRequestList(lockedOwner);
         var          chainContent = blobs.Select(blob => StorageSupport.RetrieveInformation(blob, typeof(SubscriptionChainRequestContent))).Cast <SubscriptionChainRequestContent>().ToArray();
         const double invalidSubscriptionSubmissionTimeInSeconds = 600;
         if (chainContent.Any(item => item.SubmitTime < DateTime.UtcNow.AddSeconds(-invalidSubscriptionSubmissionTimeInSeconds)))
         {
             return(false);
         }
         WorkerSupport.ExecuteSubscriptionChains(chainContent);
         foreach (string blob in blobs)
         {
             StorageSupport.DeleteBlob(blob);
         }
     }
     catch (Exception ex)
     {
         ErrorSupport.ReportException(ex);
         throw;
     }
     finally
     {
         SubscribeSupport.ReleaseChainLock(lockedOwner, acquiredEtag);
         if (containerName != null)
         {
             InformationContext.ProcessAndClearCurrent();
         }
     }
     counter++;
     if (counter >= 1000)
     {
         QueueSupport.ReportStatistics("Processed " + counter + " messages...");
         counter = 0;
     }
     return(true);
 }
Beispiel #3
0
 public static void ExecuteSubscription(Subscription subscription)
 {
     if (String.IsNullOrEmpty(subscription.SubscriptionType))
     {
         return;
     }
     if (subscription.TargetRelativeLocation == subscription.SubscriberRelativeLocation)
     {
         throw new InvalidDataException("Self-circular subscription for target: " + subscription.TargetRelativeLocation);
     }
     if (subscription.SubscriptionType == SubscribeSupport.SubscribeType_WebPageToSource)
     {
         try
         {
             CloudBlob cloudBlob =
                 StorageSupport.CurrActiveContainer.GetBlockBlobReference(subscription.SubscriberRelativeLocation);
             RenderWebSupport.RefreshPHTMLContent(cloudBlob, true);
         } catch (Exception ex)
         {
             StorageClientException storageClientException = ex as StorageClientException;
             if (storageClientException != null)
             {
                 if (storageClientException.ErrorCode == StorageErrorCode.BlobNotFound)
                 {
                     return;
                 }
             }
             // TODO: Detect and remove the missing subscribers
             ErrorSupport.ReportException(ex);
         }
     }
     else if (subscription.SubscriptionType == SubscribeSupport.SubscribeType_MasterToReferenceUpdate)
     {
         try
         {
             string containerLocation = subscription.SubscriberRelativeLocation;
             string containerType     = subscription.SubscriberInformationObjectType;
             string masterLocation    = subscription.TargetRelativeLocation;
             string masterType        = subscription.TargetInformationObjectType;
             UpdateContainerFromMaster(containerLocation, containerType, masterLocation, masterType);
         } catch (Exception ex)
         {
             StorageClientException storageClientException = ex as StorageClientException;
             if (storageClientException != null)
             {
                 if (storageClientException.ErrorCode == StorageErrorCode.BlobNotFound)
                 {
                     return;
                 }
             }
             ErrorSupport.ReportException(ex);
         }
     }
     else if (subscription.SubscriptionType == SubscribeSupport.SubscribeType_DirectoryToCollection)
     {
         string directoryLocation  = subscription.TargetRelativeLocation;
         string collectionType     = subscription.SubscriberInformationObjectType;
         string collectionLocation = subscription.SubscriberRelativeLocation;
         UpdateCollectionFromDirectory(collectionType, collectionLocation, directoryLocation);
     }
     else if (subscription.SubscriptionType == SubscribeSupport.SubscribeType_CollectionToCollectionUpdate)
     {
         string masterCollectionLocation    = subscription.TargetRelativeLocation;
         string masterCollectionType        = subscription.TargetInformationObjectType;
         string referenceCollectionLocation = subscription.SubscriberRelativeLocation;
         string referenceCollectionType     = subscription.SubscriberInformationObjectType;
         UpdateCollectionFromMasterCollection(referenceCollectionType, referenceCollectionLocation,
                                              masterCollectionType, masterCollectionLocation);
     }
     else if (subscription.SubscriptionType == SubscribeSupport.SubscribeType_MasterCollectionToContainerUpdate)
     {
         string masterCollectionLocation = subscription.TargetRelativeLocation;
         string masterCollectionType     = subscription.TargetInformationObjectType;
         string containerLocation        = subscription.SubscriberRelativeLocation;
         string containerType            = subscription.SubscriberInformationObjectType;
         UpdateContainerFromMasterCollection(containerType, containerLocation,
                                             masterCollectionType, masterCollectionLocation);
     }
     else
     {
         throw new InvalidDataException(String.Format(
                                            "Unsupported subscription type {0} for object: {1} by {2}", subscription.SubscriptionType,
                                            subscription.TargetRelativeLocation, subscription.SubscriberRelativeLocation));
     }
 }