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); }
public static void SetFieldValues(IInformationObject rootObject, NameValueCollection fieldEntries) { rootObject.SetValuesToObjects(fieldEntries); }
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); }
public static void SetFieldValues(IInformationObject rootObject, NameValueCollection fieldEntries) { NameValueCollection internalObjectFixedEntries = new NameValueCollection(); foreach (string key in fieldEntries.AllKeys) { string fieldValue = fieldEntries[key]; if (key.Contains("___")) { int underscoreIndex = key.IndexOf('_'); string containingObjectID = key.Substring(0, underscoreIndex); List<IInformationObject> foundObjects= new List<IInformationObject>(); rootObject.FindObjectsFromTree(foundObjects, iObj => iObj.ID == containingObjectID, false); if(foundObjects.Count == 0) throw new InvalidDataException("Containing object with ID not found: " + containingObjectID); var containingRootObject = foundObjects[0]; string chainedPropertyName = key.Substring(underscoreIndex + 1); object actualContainingObject; string actualPropertyName; InitializeChainAndReturnPropertyOwningObject(containingRootObject, chainedPropertyName, out actualContainingObject, out actualPropertyName); IInformationObject actualIObj = (IInformationObject) actualContainingObject; string actualKey = actualIObj.ID + "_" + actualPropertyName; internalObjectFixedEntries.Add(actualKey, fieldValue); } else { internalObjectFixedEntries.Add(key, fieldValue); } } rootObject.SetValuesToObjects(internalObjectFixedEntries); }