Exemple #1
0
 public static string SerialiseEntityQueryExpression(EntityQueryExpression item)
 {
     if (item != null)
     {
         string xml =
             @"<b:value i:type='c:EntityQueryExpression' xmlns:c='http://schemas.microsoft.com/xrm/2011/Metadata/Query'>"
             + MetadataSerialiser.SerialiseMetadataQueryExpression(item);
         if (item.AttributeQuery != null)
         {
             xml += @"<c:AttributeQuery>"
                    + MetadataSerialiser.SerialiseAttributeQueryExpression(item.AttributeQuery)
                    + @"</c:AttributeQuery>";
         }
         xml += @"<c:LabelQuery>"
                + MetadataSerialiser.SerialiseLabelQueryExpression(item.LabelQuery)
                + @"</c:LabelQuery>
         <c:RelationshipQuery i:nil='true' />
         </b:value>";
         return(xml);
     }
     else
     {
         return("<b:value i:nil='true'/>");
     }
 }
        public static PicklistAttributeMetadata DeSerialisePicklistAttributeMetadata(PicklistAttributeMetadata item, XmlNode metaData)
        {
            XmlNode options = XmlHelper.SelectSingleNode(metaData, "OptionSet");

            if (options != null)
            {
                item.OptionSet = MetadataSerialiser.DeSerialiseOptionSetMetadata(new OptionSetMetadata(), options);
            }
            return(item);
        }
        public static OptionSetMetadata DeSerialiseOptionSetMetadata(OptionSetMetadata item, XmlNode metaData)
        {
            XmlNode options = XmlHelper.SelectSingleNode(metaData, "Options");

            if (options != null)
            {
                item.Options = new List <OptionMetadata>();
                foreach (XmlNode option in options.ChildNodes)
                {
                    item.Options.Add(MetadataSerialiser.DeSerialiseOptionMetadata(new OptionMetadata(), option));
                }
            }
            return(item);
        }
 public static string SerialiseMetadataQueryExpression(MetadataQueryExpression item)
 {
     if (item != null)
     {
         string xml =
             @"<c:Criteria>"
             + MetadataSerialiser.SerialiseMetadataFilterExpression(item.Criteria) +
             @"</c:Criteria>
             <c:Properties>"
             + MetadataSerialiser.SerialiseMetadataPropertiesExpression(item.Properties)
             + @" </c:Properties>";
         return(xml);
     }
     return("");
 }
Exemple #5
0
        public static Label DeSerialiseLabel(Label item, XmlNode metaData)
        {
            item.LocalizedLabels = new List <LocalizedLabel>();
            XmlNode labels = XmlHelper.SelectSingleNode(metaData, "LocalizedLabels");

            if (labels != null && labels.ChildNodes != null)
            {
                foreach (XmlNode label in labels.ChildNodes)
                {
                    item.LocalizedLabels.Add(MetadataSerialiser.DeSerialiseLocalizedLabel(new LocalizedLabel(), label));
                }
                item.UserLocalizedLabel = MetadataSerialiser.DeSerialiseLocalizedLabel(new LocalizedLabel(), XmlHelper.SelectSingleNode(metaData, "UserLocalizedLabel"));
            }

            return(item);
        }
Exemple #6
0
        public static string SerialiseMetadataFilterExpression(MetadataFilterExpression item)
        {
            if (item != null)
            {
                string xml = @"<c:Conditions>";


                foreach (MetadataConditionExpression ex in item.Conditions)
                {
                    xml += MetadataSerialiser.SerialiseMetadataConditionExpression(ex);
                }

                xml = xml + @"</c:Conditions>
                        <c:FilterOperator>" + item.FilterOperator.ToString() + @"</c:FilterOperator>
                        <c:Filters />";
                return(xml);
            }
            return("");
        }
Exemple #7
0
        public static AttributeMetadata DeSerialiseAttributeMetadata(AttributeMetadata item, XmlNode attribute)
        {
            // Get the attributemetadata

            foreach (XmlNode node in attribute.ChildNodes)
            {
                Dictionary <string, object> itemValues = (Dictionary <string, object>)(object) item;
                string localName = XmlHelper.GetLocalName(node);
                string fieldName = localName.Substr(0, 1).ToLowerCase() + localName.Substr(1);

                // Check nil and don't set the value to save time/space
                if (node.Attributes.Count == 1 && node.Attributes[0].Name == "i:nil")
                {
                    continue;
                }

                // Non Type Specific properties
                switch (localName)
                {
                // String values
                case "AttributeOf":
                case "DeprecatedVersion":
                case "EntityLogicalName":
                case "LogicalName":
                case "SchemaName":
                case "CalculationOf":
                    itemValues[fieldName] = XmlHelper.GetNodeTextValue(node);
                    break;

                // Bool values
                case "CanBeSecuredForCreate":
                case "CanBeSecuredForRead":
                case "CanBeSecuredForUpdate":
                case "CanModifyAdditionalSettings":
                case "IsAuditEnabled":
                case "IsCustomAttribute":
                case "IsCustomizable":
                case "IsManaged":
                case "IsPrimaryId":
                case "IsPrimaryName":
                case "IsRenameable":
                case "IsSecured":
                case "IsValidForAdvancedFind":
                case "IsValidForCreate":
                case "IsValidForRead":
                case "IsValidForUpdate":
                case "DefaultValue":
                    itemValues[fieldName] = Attribute.DeSerialise(node, AttributeTypes.Boolean_);
                    break;

                // Int Values
                case "ColumnNumber":
                case "Precision":
                case "DefaultFormValue":
                case "MaxLength":
                case "PrecisionSource":
                    itemValues[fieldName] = Attribute.DeSerialise(node, AttributeTypes.Int_);
                    break;

                // Label
                case "Description":
                case "DisplayName":
                    Label label = new Label();
                    itemValues[fieldName] = MetadataSerialiser.DeSerialiseLabel(label, node);
                    break;

                //OptionSet
                case "OptionSet":
                    OptionSetMetadata options = new OptionSetMetadata();
                    itemValues[fieldName] = MetadataSerialiser.DeSerialiseOptionSetMetadata(options, node);
                    break;

                case "AttributeType":
                    item.AttributeType = (AttributeTypeCode)(object)XmlHelper.GetNodeTextValue(node);
                    break;
                    //Guid
                    // LinkedAttributeId

                    //AttributeRequiredLevel
                    //RequiredLevel

                    //DateTime
                    //MaxSupportedValue (DateTimeAttributeMetadata)
                    //MinSupportedValue (DateTimeAttributeMetadata)

                    //decimal
                    //MaxValue (DecimalAttributeMetadata)

                    //IntegerFormat
                    //Format

                    //string[]
                    //Targets
                }

                // Type sepcific attributes

                //Boolean
                //DefaultValue (OptionSetMetadata)

                //int
                // MaxValue (IntegerAttributeMetadata)
                // MinValue (IntegerAttributeMetadata)

                // StringFormat
                //Format (MemoAttributeMetadata,StringAttributeMetadata)

                //double
                //MaxValue (DoubleAttributeMetadata, MoneyAttributeMetadata)
                //MinValue (DoubleAttributeMetadata, MoneyAttributeMetadata)

                //DateTimeFormat
                //Format (DateTimeAttributeMetadata)

                //long
                //MaxValue (BigIntAttributeMetadata)
                //MinValue (BigIntAttributeMetadata)
            }
            return(item);
        }
 public static OptionMetadata DeSerialiseOptionMetadata(OptionMetadata item, XmlNode metaData)
 {
     item.Value = int.Parse(XmlHelper.SelectSingleNodeValue(metaData, "Value"));
     item.Label = MetadataSerialiser.DeSerialiseLabel(new Label(), XmlHelper.SelectSingleNode(metaData, "Label"));
     return(item);
 }
 public static string SerialiseAttributeQueryExpression(AttributeQueryExpression item)
 {
     return(MetadataSerialiser.SerialiseMetadataQueryExpression(item));
 }
        public static EntityMetadata DeSerialiseEntityMetadata(EntityMetadata item, XmlNode entity)
        {
            foreach (XmlNode node in entity.ChildNodes)
            {
                Dictionary <string, object> itemValues = (Dictionary <string, object>)(object) item;
                string localName = XmlHelper.GetLocalName(node);
                string fieldName = localName.Substr(0, 1).ToLowerCase() + localName.Substr(1); // This converts to camel case so we can use the import types from script#

                // Check nil and don't set the value to save time/space
                if (node.Attributes.Count == 1 && node.Attributes[0].Name == "i:nil")
                {
                    continue;
                }
                switch (localName)
                {
                // String values
                case "IconLargeName":
                case "IconMediumName":
                case "IconSmallName":
                case "LogicalName":
                case "PrimaryIdAttribute":
                case "PrimaryNameAttribute":
                case "RecurrenceBaseEntityLogicalName":
                case "ReportViewName":
                case "SchemaName":
                case "PrimaryImageAttribute":
                    itemValues[fieldName] = XmlHelper.GetNodeTextValue(node);
                    break;

                // Bool values
                case "AutoRouteToOwnerQueue":
                case "CanBeInManyToMany":
                case "CanBePrimaryEntityInRelationship":
                case "CanBeRelatedEntityInRelationship":
                case "CanCreateAttributes":
                case "CanCreateCharts":
                case "CanCreateForms":
                case "CanCreateViews":
                case "CanModifyAdditionalSettings":
                case "CanTriggerWorkflow":
                case "IsActivity":
                case "IsActivityParty":
                case "IsAuditEnabled":
                case "IsAvailableOffline":
                case "IsChildEntity":
                case "IsConnectionsEnabled":
                case "IsCustomEntity":
                case "IsCustomizable":
                case "IsDocumentManagementEnabled":
                case "IsDuplicateDetectionEnabled":
                case "IsEnabledForCharts":
                case "IsImportable":
                case "IsIntersect":
                case "IsMailMergeEnabled":
                case "IsManaged":
                case "IsReadingPaneEnabled":
                case "IsRenameable":
                case "IsValidForAdvancedFind":
                case "IsValidForQueue":
                case "IsVisibleInMobile":
                    itemValues[fieldName] = Attribute.DeSerialise(node, AttributeTypes.Boolean_);
                    break;

                // Int Values
                case "ActivityTypeMask":
                case "ObjectTypeCode":
                    itemValues[fieldName] = Attribute.DeSerialise(node, AttributeTypes.Int_);
                    break;

                case "Attributes":
                    item.Attributes = new List <AttributeMetadata>();
                    foreach (XmlNode childNode in node.ChildNodes)
                    {
                        AttributeMetadata a = new AttributeMetadata();
                        item.Attributes.Add(MetadataSerialiser.DeSerialiseAttributeMetadata(a, childNode));
                    }
                    break;

                ////Label
                case "Description":
                case "DisplayCollectionName":
                case "DisplayName":
                    Label label = new Label();
                    itemValues[fieldName] = MetadataSerialiser.DeSerialiseLabel(label, node);
                    break;
                }
            }
            return(item);
        }