Example #1
0
        public JObject ConvertWcfPropertyData(CswNbtWcfProperty Prop)
        {
            JObject ret = new JObject();

            ret["id"]      = Prop.PropId;
            ret["name"]    = Prop.PropName;
            ret["ocpname"] = Prop.OriginalPropName;
            JObject values = new JObject();

            foreach (string subFieldStr in Prop.values.Keys)
            {
                string  subFieldStrOrig = subFieldStr.Replace('_', ' ');
                object  subFieldVal     = Prop.values[subFieldStr];
                JObject subFieldObj     = CswConvert.ToJObject(subFieldVal.ToString());
                if (subFieldObj.HasValues)
                {
                    //Some out our subfield values are actually JObjects and must be added as such.
                    values.Add(subFieldStrOrig, subFieldObj);
                }
                else
                {
                    values.Add(subFieldStrOrig, subFieldVal.ToString());
                }
            }
            ret["values"] = values;

            return(ret);
        }
Example #2
0
        public void ReadPropertyData(CswNbtNode Node, CswNbtWcfProperty WcfProp)
        {
            CswNbtMetaDataNodeType NodeType    = Node.getNodeType();
            CswNbtNodePropWrapper  propWrapper = null;

            if (false == String.IsNullOrEmpty(WcfProp.OriginalPropName))
            {
                propWrapper = Node.Properties[WcfProp.OriginalPropName];
            }
            else
            {
                CswNbtMetaDataNodeTypeProp ntp = NodeType.getNodeTypeProp(WcfProp.PropName);
                propWrapper = Node.Properties[ntp];
            }

            JObject propData = ConvertWcfPropertyData(WcfProp);

            propWrapper.ReadJSON(propData, null, null);
        }
        public void Edit(CswNbtAPIReturn Return, CswNbtAPIGenericRequest GenericRequest)
        {
            if (hasPermission(GenericRequest, Return))
            {
                try
                {
                    CswNbtNode Node = _CswNbtResources.Nodes.GetNode(GenericRequest.NodeId);
                    if (null != Node && GenericRequest.MetaDataName == Node.getNodeType().NodeTypeName)
                    {
                        if (null != GenericRequest.ResourceToUpdate)
                        {
                            foreach (string propKey in GenericRequest.ResourceToUpdate.PropertyData.properties.Keys)
                            {
                                CswNbtWcfProperty wcfProp = GenericRequest.ResourceToUpdate.PropertyData.properties[propKey];
                                ReadPropertyData(Node, wcfProp);
                            }
                        }

                        if (Node.IsTemp)
                        {
                            Node.PromoteTempToReal();
                        }
                        else
                        {
                            Node.postChanges(false);
                        }
                    }
                    else
                    {
                        Return.Status = HttpStatusCode.NotFound;
                    }
                }
                catch (Exception)
                {
                    Return.Status = HttpStatusCode.InternalServerError;
                }
            }
            else
            {
                Return.Status = HttpStatusCode.Forbidden;
            }
        }
Example #4
0
        /// <summary>
        /// Gets property data for a given Node and returns it in our WCF object format
        /// <returns>All visible non-UI-specific properties on the Node's Edit layout for which the current user has view permissions</returns>
        /// </summary>
        public CswNbtWcfPropCollection GetPropertyData(CswNbtNode Node)
        {
            CswNbtWcfPropCollection PropCollection = new CswNbtWcfPropCollection();
            List <Int32>            PropIdsAdded   = new List <Int32>();
            CswNbtMetaDataNodeType  NodeType       = Node.getNodeType();

            foreach (CswNbtMetaDataNodeTypeTab Tab in NodeType.getNodeTypeTabs())
            {
                if (_CswNbtResources.Permit.canTab(CswEnumNbtNodeTypePermission.View, NodeType, Tab))
                {
                    IEnumerable <CswNbtMetaDataNodeTypeProp> Props = _CswNbtResources.MetaData.NodeTypeLayout.getPropsInLayout(Node.NodeTypeId, Tab.TabId, CswEnumNbtLayoutType.Edit);
                    foreach (CswNbtMetaDataNodeTypeProp Prop in Props)
                    {
                        if (false == PropIdsAdded.Contains(Prop.PropId) &&            //Don't grab the same prop more than once
                            Prop.getFieldTypeValue() != CswEnumNbtFieldType.Button && //Exclude these prop types
                            Prop.getFieldTypeValue() != CswEnumNbtFieldType.Password &&
                            false == Prop.Hidden)                                     //Don't grab hidden props
                        {
                            CswNbtWcfProperty WCFProp = new CswNbtWcfProperty
                            {
                                PropId           = Prop.PropId.ToString(),
                                PropName         = Prop.PropName,
                                OriginalPropName = Prop.getObjectClassPropName()
                            };
                            JObject PropVals = new JObject();
                            Node.Properties[Prop].ToJSON(PropVals);
                            foreach (JProperty OldPropValue in PropVals["values"].Children())
                            {
                                WCFProp.values[OldPropValue.Name] = OldPropValue.Value.ToString();
                            }
                            PropCollection.addProperty(WCFProp);
                            PropIdsAdded.Add(Prop.PropId);
                        }
                    }
                }
            }
            return(PropCollection);
        }