Ejemplo n.º 1
0
        public static InformationSourceCollection GetInformationSources(string targetLocation)
        {
            string blobPath = InformationSourceCollection.GetRelativeLocationAsMetadataTo(targetLocation);
            var    result   = StorageSupport.RetrieveInformation(blobPath, typeof(InformationSourceCollection));

            return((InformationSourceCollection)result);
        }
Ejemplo n.º 2
0
        public static void RefreshPHTMLContent(CloudBlob webPageBlob, bool skipIfSourcesIntact = false)
        {
            // Refresh only PHTML blobs
            if (webPageBlob.Name.EndsWith(".phtml") == false)
            {
                return;
            }
            InformationSourceCollection sources = webPageBlob.GetBlobInformationSources();

            if (sources == null)
            {
                throw new InvalidDataException("Web page to refresh is missing information sources: " + webPageBlob.Name);
            }
            if (skipIfSourcesIntact)
            {
                bool sourcesIntact = sources.HasAnySourceChanged() == false;
                if (sourcesIntact)
                {
                    return;
                }
            }
            InformationSource templateSource = sources.CollectionContent.First(src => src.IsWebTemplateSource);

            if (templateSource == null)
            {
                throw new InvalidDataException("Web page to refresh is missing template source: " + webPageBlob.Name);
            }
            CloudBlob templateBlob =
                StorageSupport.CurrActiveContainer.GetBlockBlobReference(templateSource.SourceLocation);

            RenderTemplateWithContentToBlob(templateBlob, webPageBlob);
        }
Ejemplo n.º 3
0
 private static List <ContentItem> GetExistingRoots(InformationSourceCollection sources)
 {
     return
         (sources.CollectionContent.Where(
              source => source.SourceType == StorageSupport.InformationType_InformationObjectValue).Select(
              GetRootFromSource).ToList());
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Updates mismatched (new and removed) roots to sources
        /// </summary>
        /// <param name="sources">Information sources</param>
        /// <param name="existingRoots">Current roots</param>
        /// <param name="renderTarget">Render target</param>
        /// <returns>True, if existing sources were spotted and re-rendering is required</returns>
        private static bool UpdateMismatchedRootsToSources(InformationSourceCollection sources, List <ContentItem> existingRoots, CloudBlob renderTarget)
        {
            var newSources =
                existingRoots.Where(root => root.WasMissing).Select(root =>
            {
                bool foundExistingSource;
                var source = GetMissingRootAsNewSource(
                    root, renderTarget.Name,
                    out foundExistingSource);
                // If error, returns null
                if (source == null)
                {
                    return(null);
                }
                return(new
                {
                    Source = source,
                    FoundExistingSource =
                        foundExistingSource
                });
            }
                                                                    ).Where(res => res != null).ToArray();

            sources.CollectionContent.AddRange(newSources.Select(item => item.Source));
            foreach (var item in existingRoots.Where(root => root.WasNeeded == false))
            {
                sources.CollectionContent.Remove(item.Source);
            }
            // Don't delete the missing blobs just now
            return(newSources.Any(source => source.FoundExistingSource));
        }
Ejemplo n.º 5
0
        public static void RenderTemplateWithContentToBlob(CloudBlob template, CloudBlob renderTarget, InformationSource setAsDefaultSource = null)
        {
            InformationSourceCollection sources = renderTarget.GetBlobInformationSources();

            if (sources == null)
            {
                sources = CreateDefaultSources(template);
            }
            if (setAsDefaultSource != null)
            {
                sources.SetDefaultSource(setAsDefaultSource);
            }
            string             templateContent = template.DownloadText();
            List <ContentItem> existingRoots   = GetExistingRoots(sources);
            string             renderResult    = RenderTemplateWithContentRoots(templateContent, existingRoots);
            bool rerenderRequired = UpdateMismatchedRootsToSources(sources, existingRoots, renderTarget);

            renderTarget.SetBlobInformationSources(sources);
            renderTarget.UploadBlobText(renderResult, StorageSupport.InformationType_RenderedWebPage);
            if (rerenderRequired)
            {
                RenderTemplateWithContentToBlob(template, renderTarget);
            }
            else
            {
                sources.SubscribeTargetToSourceChanges(renderTarget);
            }
        }
Ejemplo n.º 6
0
        private static InformationSourceCollection CreateDefaultSources(CloudBlob template)
        {
            InformationSourceCollection sources = InformationSourceCollection.CreateDefault();
            InformationSource           source  = InformationSource.CreateDefault();

            source.SetBlobValuesToSource(template);
            sources.CollectionContent.Add(source);
            return(sources);
        }
Ejemplo n.º 7
0
 public static void SetInformationSources(string targetLocation, InformationSourceCollection sourceCollection)
 {
     if (sourceCollection == null)
     {
         // Delete existing
         string    blobPath = InformationSourceCollection.GetRelativeLocationAsMetadataTo(targetLocation);
         CloudBlob blob     = StorageSupport.CurrActiveContainer.GetBlobReference(blobPath);
         blob.DeleteWithoutFiringSubscriptions();
         return;
     }
     sourceCollection.SetRelativeLocationAsMetadataTo(targetLocation);
     StorageSupport.StoreInformation(sourceCollection);
 }
Ejemplo n.º 8
0
        public static void DeleteInformationSources(string targetLocation)
        {
            string blobPath = InformationSourceCollection.GetRelativeLocationAsMetadataTo(targetLocation);

            StorageSupport.DeleteBlob(blobPath);
        }
Ejemplo n.º 9
0
        private void HandleOwnerPostRequest(IContainerOwner containerOwner, HttpContext context, string contentPath)
        {
            InformationContext.Current.Owner = containerOwner;
            HttpRequest request = context.Request;
            var         form    = request.Unvalidated().Form;

            bool isAjaxDataRequest = request.ContentType.StartsWith("application/json"); // form.Get("AjaxObjectInfo") != null;

            if (isAjaxDataRequest)
            {
                // Various data deserialization tests - options need to be properly set
                // strong type radically faster 151ms over 25sec with flexible type - something ill
                throw new NotSupportedException("Not supported as-is, implementation for serialization available, not finished");
                var    stream       = request.GetBufferedInputStream();
                var    dataX        = JSONSupport.GetObjectFromStream <NodeSummaryContainer>(stream);
                var    streamReader = new StreamReader(request.GetBufferedInputStream());
                string data         = streamReader.ReadToEnd();
                var    jsonData     = JSONSupport.GetJsonFromStream(data);
                HandlerOwnerAjaxDataPOST(containerOwner, form);
                return;
            }

            bool isClientTemplateRequest = form.Get("ContentSourceInfo") != null ||
                                           form.Get("ExecuteOperation") != null;

            if (isClientTemplateRequest)
            {
                HandleOwnerClientTemplatePOST(containerOwner, request);
                return;
            }

            string sourceNamesCommaSeparated = form["RootSourceName"];
            bool   isCancelButton            = form["btnCancel"] != null;

            if (isCancelButton)
            {
                return;
            }
            string actionName    = form["RootSourceAction"];
            string objectFieldID = form["ObjectFieldID"];

            CloudBlob webPageBlob = StorageSupport.CurrActiveContainer.GetBlob(contentPath, containerOwner);
            InformationSourceCollection sources = webPageBlob.GetBlobInformationSources();

            if (sources == null)
            {
                throw new InvalidDataException("Postback to page with no information sources defined - where there should be");
            }
            if (sourceNamesCommaSeparated == null)
            {
                sourceNamesCommaSeparated = "";
            }
            sourceNamesCommaSeparated += ",";
            string[] sourceNames = sourceNamesCommaSeparated.Split(',').Distinct().ToArray();

            if (objectFieldID != null && actionName.StartsWith("cmd") == false && actionName != "Save" && actionName.Contains(",") == false)
            {
                var result = PerformWebAction.Execute(new PerformWebActionParameters
                {
                    CommandName        = actionName,
                    FormSourceNames    = sourceNames,
                    FormSubmitContent  = form,
                    InformationSources = sources,
                    Owner          = containerOwner,
                    TargetObjectID = objectFieldID
                });
                if (result.RenderPageAfterOperation)
                {
                    RenderWebSupport.RefreshPHTMLContent(webPageBlob);
                }
                return;
            }

            string inContextEditFieldID = form["InContextEditFieldID"];

            if (inContextEditFieldID != null)
            {
                string objectFieldValue = form["Text_Short"];
                if (objectFieldValue == null)
                {
                    objectFieldValue = form["Text_Long"];
                }
                form = new NameValueCollection();
                form.Set(inContextEditFieldID, objectFieldValue);
            }

            InformationSource[] sourceArray =
                sources.CollectionContent.Where(
                    src => src.IsDynamic || (src.IsInformationObjectSource && sourceNames.Contains(src.SourceName))).ToArray();
            foreach (InformationSource source in sourceArray)
            {
                string             oldETag    = source.SourceETag;
                IInformationObject rootObject = source.RetrieveInformationObject();

                /* Temporarily removed all the version checks - last save wins!
                 * if (oldETag != rootObject.ETag)
                 * {
                 *  RenderWebSupport.RefreshPHTMLContent(webPageBlob);
                 *  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)
                rootObject.SetValuesToObjects(form);
                IAddOperationProvider addOperationProvider = rootObject as IAddOperationProvider;
                bool skipNormalStoreAfterAdd = false;
                if (addOperationProvider != null)
                {
                    skipNormalStoreAfterAdd = addOperationProvider.PerformAddOperation(actionName, sources, contentPath, request.Files);
                }
                if (skipNormalStoreAfterAdd == false)
                {
                    // If not add operation, set media content to stored object
                    foreach (string contentID in request.Files.AllKeys)
                    {
                        HttpPostedFile postedFile = request.Files[contentID];
                        if (String.IsNullOrWhiteSpace(postedFile.FileName))
                        {
                            continue;
                        }
                        rootObject.SetMediaContent(containerOwner, contentID, postedFile);
                    }
                    rootObject.StoreInformationMasterFirst(containerOwner, false);
                }
            }
            RenderWebSupport.RefreshPHTMLContent(webPageBlob);
            // Temporary live to pub sync below, to be removed
            //SyncTemplatesToSite(StorageSupport.CurrActiveContainer.Name,
            //    String.Format("grp/f8e1d8c6-0000-467e-b487-74be4ad099cd/{0}/", "livesite"),
            //    StorageSupport.CurrAnonPublicContainer.Name,
            //                    String.Format("grp/default/{0}/", "livepubsite"), true);
        }
Ejemplo n.º 10
0
        private void HandleOwnerPostRequest(IContainerOwner containerOwner, HttpContext context, string contentPath)
        {
            HttpRequest request = context.Request;
            var         form    = request.Unvalidated().Form;

            string sourceNamesCommaSeparated = form["RootSourceName"];
            bool   isCancelButton            = form["btnCancel"] != null;

            if (isCancelButton)
            {
                return;
            }
            string actionName       = form["RootSourceAction"];
            string objectFieldID    = form["ObjectFieldID"];
            string objectFieldValue = form["Text_Short"];

            if (objectFieldValue == null)
            {
                objectFieldValue = form["Text_Long"];
            }

            CloudBlob webPageBlob = StorageSupport.CurrActiveContainer.GetBlob(contentPath, containerOwner);
            InformationSourceCollection sources = webPageBlob.GetBlobInformationSources();

            if (sources == null)
            {
                throw new InvalidDataException("Postback to page with no information sources defined - where there should be");
            }
            if (sourceNamesCommaSeparated == null)
            {
                sourceNamesCommaSeparated = "";
            }
            sourceNamesCommaSeparated += ",";
            string[] sourceNames = sourceNamesCommaSeparated.Split(',').Distinct().ToArray();

            return;

            if (objectFieldID != null)
            {
                var result = PerformWebAction.Execute(new PerformWebActionParameters
                {
                    CommandName        = actionName,
                    FormSourceNames    = sourceNames,
                    InformationSources = sources,
                    Owner          = containerOwner,
                    TargetObjectID = objectFieldID
                });
                if (result.RenderPageAfterOperation)
                {
                    RenderWebSupport.RefreshPHTMLContent(webPageBlob);
                }
                return;
            }

            InformationSource[] sourceArray =
                sources.CollectionContent.Where(
                    src => src.IsDynamic || (src.IsInformationObjectSource && sourceNames.Contains(src.SourceName))).ToArray();
            foreach (InformationSource source in sourceArray)
            {
                string             oldETag    = source.SourceETag;
                IInformationObject rootObject = source.RetrieveInformationObject();
                if (oldETag != rootObject.ETag)
                {
                    RenderWebSupport.RefreshPHTMLContent(webPageBlob);
                    throw new InvalidDataException("Information under editing was modified during display and save");
                }
                rootObject.SetValuesToObjects(form);
                IAddOperationProvider addOperationProvider = rootObject as IAddOperationProvider;
                bool skipNormalStoreAfterAdd = false;
                if (addOperationProvider != null)
                {
                    skipNormalStoreAfterAdd = addOperationProvider.PerformAddOperation(actionName, sources, contentPath, request.Files);
                }
                if (skipNormalStoreAfterAdd == false)
                {
                    // If not add operation, set media content to stored object
                    foreach (string contentID in request.Files.AllKeys)
                    {
                        HttpPostedFile postedFile = request.Files[contentID];
                        if (String.IsNullOrWhiteSpace(postedFile.FileName))
                        {
                            continue;
                        }
                        rootObject.SetMediaContent(containerOwner, contentID, postedFile);
                    }
                    rootObject.StoreInformationMasterFirst(containerOwner, false);
                }
            }
            RenderWebSupport.RefreshPHTMLContent(webPageBlob);
            // Temporary live to pub sync below, to be removed
            //SyncTemplatesToSite(StorageSupport.CurrActiveContainer.Name,
            //    String.Format("grp/f8e1d8c6-0000-467e-b487-74be4ad099cd/{0}/", "livesite"),
            //    StorageSupport.CurrAnonPublicContainer.Name,
            //                    String.Format("grp/default/{0}/", "livepubsite"), true);
        }