Example #1
0
        public static SubscriptionCollection GetSubscriptions(string targetLocation)
        {
            string blobPath = SubscriptionCollection.GetRelativeLocationAsMetadataTo(targetLocation);
            var    result   = StorageSupport.RetrieveInformation(blobPath, typeof(SubscriptionCollection));

            return((SubscriptionCollection)result);
        }
Example #2
0
        public static InformationSourceCollection GetInformationSources(string targetLocation)
        {
            string blobPath = InformationSourceCollection.GetRelativeLocationAsMetadataTo(targetLocation);
            var    result   = StorageSupport.RetrieveInformation(blobPath, typeof(InformationSourceCollection));

            return((InformationSourceCollection)result);
        }
Example #3
0
        public static void UpdateContainerFromMaster(string containerLocation, string containerType, string masterLocation, string masterType)
        {
            bool masterEtagUpdated = false;

            //do
            //{
            masterEtagUpdated = false;
            IInformationObject container         = StorageSupport.RetrieveInformation(containerLocation, containerType);
            IInformationObject referenceToMaster = StorageSupport.RetrieveInformation(masterLocation, masterType);
            string             masterEtag        = referenceToMaster.ETag;
            string             masterID          = referenceToMaster.ID;
            Dictionary <string, List <IInformationObject> > result = new Dictionary <string, List <IInformationObject> >();

            container.CollectMasterObjectsFromTree(result, candidate => candidate.ID == masterID);
            bool foundOutdatedMaster =
                result.Values.SelectMany(item => item).Count(candidate => candidate.MasterETag != masterEtag) > 0;

            if (foundOutdatedMaster)
            {
                referenceToMaster.MasterETag = referenceToMaster.ETag;
                container.ReplaceObjectInTree(referenceToMaster);
                container.StoreInformation();
                referenceToMaster = StorageSupport.RetrieveInformation(masterLocation, masterType);
                masterEtagUpdated = referenceToMaster.ETag != masterEtag;
            }
            //} while (masterEtagUpdated);
        }
Example #4
0
        private static void UpdateCollectionFromDirectory(string collectionType, string collectionLocation, string directoryLocation)
        {
            IInformationObject collectionObject = StorageSupport.RetrieveInformation(collectionLocation, collectionType);

            if (collectionObject is IInformationCollection)
            {
                IInformationCollection collection = (IInformationCollection)collectionObject;
                collection.RefreshContent();
                StorageSupport.StoreInformation(collectionObject);
            }
        }
Example #5
0
        static TBSystem()
        {
            TBSystem system = (TBSystem)StorageSupport.RetrieveInformation(SingletonRelativeLocation, typeof(TBSystem));

            if (system == null)
            {
                system    = CreateDefault();
                system.ID = "AAA";
                system.RelativeLocation = SingletonRelativeLocation;
                StorageSupport.StoreInformation(system);
            }
            currSystem = system;
        }
Example #6
0
        private static void UpdateCollectionFromMasterCollection(string referenceCollectionType, string referenceCollectionLocation, string masterCollectionType, string masterCollectionLocation)
        {
            IInformationObject referenceCollectionObject = StorageSupport.RetrieveInformation(referenceCollectionLocation,
                                                                                              referenceCollectionType);
            IInformationCollection referenceCollection = (IInformationCollection)referenceCollectionObject;

            // TODO: Revisit why this can be null
            if (referenceCollection == null)
            {
                return;
            }
            referenceCollection.RefreshContent();
            StorageSupport.StoreInformation(referenceCollectionObject);
        }
Example #7
0
        private static void UpdateContainerFromMasterCollection(string containerType, string containerLocation, string masterCollectionType, string masterCollectionLocation)
        {
            IInformationObject containerObject        = StorageSupport.RetrieveInformation(containerLocation, containerType);
            IInformationObject masterCollectionObject = StorageSupport.RetrieveInformation(masterCollectionLocation,
                                                                                           masterCollectionType);
            IInformationCollection masterCollection = (IInformationCollection)masterCollectionObject;

            // TODO: Revisit why this can be null
            if (containerObject == null || masterCollection == null)
            {
                return;
            }
            containerObject.UpdateCollections(masterCollection);
            StorageSupport.StoreInformation(containerObject);
        }
Example #8
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);
 }
        public static void ExecuteOwnerWebPOST(IContainerOwner containerOwner, NameValueCollection form, HttpFileCollection fileContent)
        {
            bool isCancelButton = form["btnCancel"] != null;

            if (isCancelButton)
            {
                return;
            }

            string operationName = form["ExecuteOperation"];

            if (operationName != null)
            {
                executeOperationWithFormValues(containerOwner, operationName, form, fileContent);
                return;
            }

            string contentSourceInfo = form["ContentSourceInfo"];

            string[]            contentSourceInfos = contentSourceInfo.Split(',');
            NameValueCollection fileEntries        = new NameValueCollection();
            NameValueCollection fieldEntries       = new NameValueCollection();
            NameValueCollection objectEntries      = new NameValueCollection();

            foreach (var key in form.AllKeys)
            {
                var value = form[key];
                if (key.StartsWith("File_"))
                {
                    fileEntries.Add(key, value);
                }
                else if (key.StartsWith("Object_"))
                {
                    objectEntries.Add(key, value);
                }
                else
                {
                    fieldEntries.Add(key, value);
                }
            }
            foreach (var key in fileContent.AllKeys)
            {
                if (key.StartsWith("File_") && fileEntries.AllKeys.Contains(key) == false)
                {
                    fileEntries.Add(key, "");
                }
            }
            foreach (string sourceInfo in contentSourceInfos)
            {
                string relativeLocation;
                string oldETag;
                retrieveDataSourceInfo(sourceInfo, out relativeLocation, out oldETag);
                VirtualOwner verifyOwner = VirtualOwner.FigureOwner(relativeLocation);
                if (verifyOwner.IsSameOwner(containerOwner) == false)
                {
                    throw new SecurityException("Mismatch in ownership of data submission");
                }
                IInformationObject rootObject = StorageSupport.RetrieveInformation(relativeLocation, oldETag,
                                                                                   containerOwner);
                if (oldETag != rootObject.ETag)
                {
                    throw new InvalidDataException("Information under editing was modified during display and save");
                }
                // TODO: Proprely validate against only the object under the editing was changed (or its tree below)
                SetFieldValues(rootObject, fieldEntries);
                SetBinaryContent(rootObject, fileEntries, fileContent, containerOwner);
                SetObjectLinks(rootObject, objectEntries);

                /* Operation bridge model below - not used/needed with field assignment solution */

                /*
                 * var removeMediaList = form["cmdRemoveMedia"];
                 * if (String.IsNullOrWhiteSpace(removeMediaList) == false)
                 * {
                 *  string[] removeList = removeMediaList.Split(',');
                 *  foreach (string contentInfo in removeList)
                 *  {
                 *      SetBinaryContent(containerOwner, contentInfo, rootObject, null);
                 *  }
                 * }
                 * */
                rootObject.StoreInformationMasterFirst(containerOwner, false);
            }
        }