Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }