Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            FieldLink fl    = treeView1.SelectedNode.Tag as FieldLink;
            Type      T     = fl.GetElementType();
            object    Value = null;

            try
            {
                if (T == typeof(String))
                {
                    Value = textBox1.Text;
                }
                else if (T == typeof(int))
                {
                    Value = int.Parse(textBox1.Text);
                }
                else if (T == typeof(double))
                {
                    Value = double.Parse(textBox1.Text, CultureInfo.InvariantCulture);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            SetValue(fl, Value);
            UpdateNode(treeView1.SelectedNode);
        }
Пример #2
0
        private void UpdateNode(TreeNode tn)
        {
            FieldLink fl    = tn.Tag as FieldLink;
            object    Value = GetValue(fl);
            string    Name  = "";

            if (fl.ArrayIndex < 0)
            {
                Name = fl.F.Name;
            }
            else
            {
                Name = "[" + fl.ArrayIndex.ToString() + "]";
            }

            if (Value == null)
            {
                tn.Text = Name + ": null";
            }
            else if (Value.GetType() == typeof(Boolean))
            {
                tn.Text = Name + ": " + Value.ToString();
            }
            else if (Value.GetType() == typeof(double))
            {
                tn.Text = Name + ": \"" + ((double)Value).ToString("F8", CultureInfo.InvariantCulture) + "\"";
            }
            else
            {
                tn.Text = Name + ": \"" + Value.ToString() + "\"";
            }
        }
Пример #3
0
        private void button2_Click(object sender, EventArgs e)
        {
            FieldLink fl = treeView1.SelectedNode.Tag as FieldLink;
            Type      T  = fl.GetElementType();

            SetValue(fl, null);
            UpdateNode(treeView1.SelectedNode);
        }
Пример #4
0
        private void CreateSiteClassificationList(ClientContext ctx)
        {
            var _newList = new ListCreationInformation()
            {
                Title             = SiteClassificationList.SiteClassificationListTitle,
                Description       = SiteClassificationList.SiteClassificationDesc,
                TemplateType      = (int)ListTemplateType.GenericList,
                Url               = SiteClassificationList.SiteClassificationUrl,
                QuickLaunchOption = QuickLaunchOptions.Off
            };

            if (!ctx.Web.ContentTypeExistsById(SiteClassificationContentType.SITEINFORMATION_CT_ID))
            {
                //ct
                ContentType _contentType = ctx.Web.CreateContentType(SiteClassificationContentType.SITEINFORMATION_CT_NAME,
                                                                     SiteClassificationContentType.SITEINFORMATION_CT_DESC,
                                                                     SiteClassificationContentType.SITEINFORMATION_CT_ID,
                                                                     SiteClassificationContentType.SITEINFORMATION_CT_GROUP);

                FieldLink _titleFieldLink = _contentType.FieldLinks.GetById(new Guid("fa564e0f-0c70-4ab9-b863-0177e6ddd247"));
                _titleFieldLink.Required = false;
                _contentType.Update(false);



                //Key Field
                ctx.Web.CreateField(SiteClassificationFields.FLD_KEY_ID,
                                    SiteClassificationFields.FLD_KEY_INTERNAL_NAME,
                                    FieldType.Text,
                                    SiteClassificationFields.FLD_KEY_DISPLAY_NAME,
                                    SiteClassificationFields.FIELDS_GROUPNAME);
                //value field
                ctx.Web.CreateField(SiteClassificationFields.FLD_VALUE_ID,
                                    SiteClassificationFields.FLD_VALUE_INTERNAL_NAME,
                                    FieldType.Text,
                                    SiteClassificationFields.FLD_VALUE_DISPLAY_NAME,
                                    SiteClassificationFields.FIELDS_GROUPNAME);

                //Add Key Field to content type
                ctx.Web.AddFieldToContentTypeById(SiteClassificationContentType.SITEINFORMATION_CT_ID,
                                                  SiteClassificationFields.FLD_KEY_ID.ToString(),
                                                  true);
                //Add Value Field to content type
                ctx.Web.AddFieldToContentTypeById(SiteClassificationContentType.SITEINFORMATION_CT_ID,
                                                  SiteClassificationFields.FLD_VALUE_ID.ToString(),
                                                  true);
            }
            var _list = ctx.Web.Lists.Add(_newList);

            _list.Hidden = true;
            _list.ContentTypesEnabled = true;
            _list.Update();
            ctx.Web.AddContentTypeToListById(SiteClassificationList.SiteClassificationListTitle, SiteClassificationContentType.SITEINFORMATION_CT_ID, true);
            this.CreateCustomPropertiesInList(_list);
            ctx.ExecuteQuery();
            this.RemoveFromQuickLaunch(ctx, SiteClassificationList.SiteClassificationListTitle);
        }
Пример #5
0
        /// <summary>
        /// This event is fired AFTER the fieldLink is parsed.
        /// </summary>
        /// <param name="xmlNode"></param>
        /// <param name="fieldLink"></param>
        /// <returns>True if cancelled else false if not.</returns>
        public bool Parsed(XmlNode xmlNode, ref FieldLink fieldLink)
        {
            // initial value
            bool cancel = false;

            // Add any post processing code here. Set cancel to true to abort adding this object.

            // return value
            return(cancel);
        }
Пример #6
0
 private object GetValue(FieldLink fl)
 {
     if (fl.ArrayIndex < 0)
     {
         return(fl.F.GetValue(fl.obj));
     }
     else
     {
         Array ArrayValue = (Array)fl.F.GetValue(fl.obj);
         return(ArrayValue.GetValue(fl.ArrayIndex));
     }
 }
Пример #7
0
        private void DeployHideContentTypeLinks(object modelHost, ContentType contentType, HideContentTypeFieldLinksDefinition hideFieldLinksModel)
        {
            var context = contentType.Context;

            context.Load(contentType, c => c.FieldLinks);
            context.ExecuteQueryWithTrace();

            var fieldLinks = contentType.FieldLinks.ToList();

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = contentType,
                ObjectType       = typeof(ContentType),
                ObjectDefinition = hideFieldLinksModel,
                ModelHost        = modelHost
            });

            // re-order
            foreach (var srcFieldLink in hideFieldLinksModel.Fields)
            {
                FieldLink currentFieldLink = null;

                if (!string.IsNullOrEmpty(srcFieldLink.InternalName))
                {
                    currentFieldLink = fieldLinks.FirstOrDefault(c => c.Name == srcFieldLink.InternalName);
                }

                if (currentFieldLink == null && srcFieldLink.Id.HasValue)
                {
                    currentFieldLink = fieldLinks.FirstOrDefault(c => c.Id == srcFieldLink.Id.Value);
                }

                if (currentFieldLink != null)
                {
                    currentFieldLink.Required = false;
                    currentFieldLink.Hidden   = true;
                }
            }

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = contentType,
                ObjectType       = typeof(ContentType),
                ObjectDefinition = hideFieldLinksModel,
                ModelHost        = modelHost
            });
        }
Пример #8
0
 private void SetValue(FieldLink fl, object val)
 {
     if (fl.ArrayIndex < 0)
     {
         fl.F.SetValue(fl.obj, val);
     }
     else
     {
         Array ArrayValue = (Array)fl.F.GetValue(fl.obj);
         ArrayValue.SetValue(val, fl.ArrayIndex);
         fl.F.SetValue(fl.obj, ArrayValue);
     }
 }
Пример #9
0
        /// <summary>
        /// Create a new instance of a FieldLinkTextBox
        /// </summary>
        /// <param name="sourceNode"></param>
        /// <param name="fieldLink"></param>
        public FieldLinkTreeNode(XmlNode sourceNode, FieldLink fieldLink)
        {
            // store the values
            this.SourceNode = sourceNode;
            this.FieldLink  = fieldLink;

            // if both objects exist
            if ((this.HasSourceNode) && (this.HasFieldLink))
            {
                // change the text
                this.Text = this.FieldLink.TargetFieldName + " :: " + this.FieldLink.SourceFieldName;
            }
        }
Пример #10
0
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            textBox1.Text    = "";
            textBox1.Enabled = false;
            button1.Enabled  = false;
            button2.Enabled  = false;
            button3.Enabled  = false;

            if (e.Node.Tag != null)
            {
                FieldLink fl = e.Node.Tag as FieldLink;
                if (fl.F.FieldType.IsArray && fl.ArrayIndex < 0)
                {
                    return;
                }

                Type T = fl.GetElementType();
                if (T == typeof(String) || T == typeof(int) || T == typeof(double))
                {
                    textBox1.Enabled = true;
                    button1.Enabled  = true;
                    button2.Enabled  = true;

                    object Val = GetValue(fl);
                    if (Val != null)
                    {
                        if (fl.F.FieldType == typeof(double))
                        {
                            textBox1.Text = ((double)Val).ToString("F8", CultureInfo.InvariantCulture);
                        }
                        else
                        {
                            textBox1.Text = Val.ToString();
                        }
                    }
                }
                else
                {
                    textBox1.Text    = "";
                    textBox1.Enabled = false;

                    if (fl.F.FieldType == typeof(Boolean))
                    {
                        button3.Enabled = true;
                    }
                }
            }
        }
Пример #11
0
        private void treeView1_DoubleClick(object sender, EventArgs e)
        {
            if (treeView1.SelectedNode != null && treeView1.SelectedNode.Tag != null)
            {
                FieldLink fl = treeView1.SelectedNode.Tag as FieldLink;

                if (fl.F.FieldType.IsArray && fl.ArrayIndex < 0)
                {
                    return;
                }

                Type T = fl.GetElementType();
                if (T != typeof(String) && T != typeof(int) && T != typeof(double))
                {
                    button3_Click(null, null);
                }
            }
        }
Пример #12
0
        private static void AddFieldToContentType(ContentType contentType, Field field, bool required, bool hidden)
        {
            if (!contentType.IsPropertyAvailable("Id"))
            {
                web.Context.Load(contentType, ct => ct.Id);
                web.Context.ExecuteQuery();
            }

            if (!field.IsPropertyAvailable("Id"))
            {
                web.Context.Load(field, f => f.Id);
                web.Context.ExecuteQuery();
            }

            // Get the field if already exists in content type, else add field to content type
            // This will help to customize (required or hidden) any pre-existing field, also to handle existing field of Parent Content type

            web.Context.Load(contentType.FieldLinks);
            web.Context.ExecuteQuery();

            FieldLink flink = contentType.FieldLinks.FirstOrDefault(fld => fld.Id == field.Id);

            if (flink == null)
            {
                FieldLinkCreationInformation fldInfo = new FieldLinkCreationInformation();
                fldInfo.Field = field;
                contentType.FieldLinks.Add(fldInfo);
                contentType.Update(true);
                web.Context.ExecuteQuery();

                flink = contentType.FieldLinks.GetById(field.Id);
            }

            if (required || hidden)
            {
                // Update FieldLink
                flink.Required = required;
                flink.Hidden   = hidden;
                contentType.Update(true);
                web.Context.ExecuteQuery();
            }
        }
Пример #13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="web"></param>
        /// <param name="contentType"></param>
        /// <param name="field"></param>
        /// <param name="required"></param>
        /// <param name="hidden"></param>
        public static void AddFieldToContentType(this Web web, ContentType contentType, Field field, bool required = false, bool hidden = false)
        {
            FieldLinkCreationInformation fldInfo = new FieldLinkCreationInformation();

            fldInfo.Field = field;
            contentType.FieldLinks.Add(fldInfo);
            contentType.Update(true);
            web.Context.ExecuteQuery();

            web.Context.Load(field);
            web.Context.ExecuteQuery();

            if (required || hidden)
            {
                //Update FieldLink
                FieldLink flink = contentType.FieldLinks.GetById(field.Id);
                flink.Required = required;
                flink.Hidden   = hidden;
                contentType.Update(true);
                web.Context.ExecuteQuery();
            }
        }
Пример #14
0
        private ContentType CreateDocumentSetContentType(ClientContext clientContext, string contentTypeName, List <Field> fields)
        {
            ContentType ret = null;
            Web         web = clientContext.Web;

            clientContext.Load(web, w => w.ContentTypes, w => w.Fields);
            clientContext.ExecuteQuery();

            //Get default document set content type.
            ContentType ctDocumentSet = web.ContentTypes.FirstOrDefault(ct => ct.Name.IndexOf("document set", StringComparison.CurrentCultureIgnoreCase) != -1);

            ret = web.ContentTypes.FirstOrDefault(ct => ct.Name == contentTypeName);
            if (ret == null)
            {
                ContentTypeCreationInformation ctNewInfo = new ContentTypeCreationInformation();
                ctNewInfo.Name              = CONTENTTYPENAME;
                ctNewInfo.Description       = CONTENTTYPENAME;
                ctNewInfo.Group             = CONTENTTYPEGROUP;
                ctNewInfo.ParentContentType = ctDocumentSet;
                ret = web.ContentTypes.Add(ctNewInfo);
            }
            clientContext.Load(ret, ct => ct.FieldLinks, ct => ct.Id);
            clientContext.ExecuteQuery();
            foreach (Field field in fields)
            {
                FieldLink flAuthor = ret.FieldLinks.FirstOrDefault(link => link.Name == field.InternalName);
                if (flAuthor == null)
                {
                    FieldLinkCreationInformation fNewInfo = new FieldLinkCreationInformation();
                    fNewInfo.Field = field;
                    ret.FieldLinks.Add(fNewInfo);
                    ret.Update(true);
                    clientContext.Load(ret, ct => ct.FieldLinks);
                    clientContext.ExecuteQuery();
                }
            }
            return(ret);
        }
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var modelHostWrapper          = modelHost.WithAssertAndCast <ModelHostContext>("modelHost", value => value.RequireNotNull());
            var contentTypeFieldLinkModel = model.WithAssertAndCast <ContentTypeFieldLinkDefinition>("model", value => value.RequireNotNull());

            //var site = modelHostWrapper.Site;
            var web         = modelHostWrapper.Web;
            var contentType = modelHostWrapper.ContentType;

            var context = contentType.Context;

            TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Getting content type field link by ID: [{0}]", contentTypeFieldLinkModel.FieldId);

            var tmp = contentType.FieldLinks.GetById(contentTypeFieldLinkModel.FieldId);

            context.ExecuteQueryWithTrace();

            FieldLink fieldLink = null;

            if (tmp != null && tmp.ServerObjectIsNull.HasValue && !tmp.ServerObjectIsNull.Value)
            {
                TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Found existing field link");

                fieldLink = tmp;
            }

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = fieldLink,
                ObjectType       = typeof(FieldLink),
                ObjectDefinition = model,
                ModelHost        = modelHost
            });

            if (fieldLink == null)
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new content type field link");

                var targetField = FindExistingField(web, contentTypeFieldLinkModel.FieldId);

                fieldLink = contentType.FieldLinks.Add(new FieldLinkCreationInformation
                {
                    Field = targetField
                });
            }
            else
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing content type field link");
            }

            if (contentTypeFieldLinkModel.Required.HasValue)
            {
                fieldLink.Required = contentTypeFieldLinkModel.Required.Value;
            }

            if (contentTypeFieldLinkModel.Hidden.HasValue)
            {
                fieldLink.Hidden = contentTypeFieldLinkModel.Hidden.Value;
            }

            if (!string.IsNullOrEmpty(contentTypeFieldLinkModel.DisplayName))
            {
                // CSOM limitation - DisplayName is not available yet.
                // https://officespdev.uservoice.com/forums/224641-general/suggestions/7024931-enhance-fieldlink-class-with-additional-properties

                //   fieldLink.DisplayName = contentTypeFieldLinkModel.DisplayName;
            }

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = fieldLink,
                ObjectType       = typeof(FieldLink),
                ObjectDefinition = model,
                ModelHost        = modelHost
            });

            contentType.Update(true);
            context.ExecuteQueryWithTrace();
        }
Пример #16
0
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var modelHostWrapper          = modelHost.WithAssertAndCast <ModelHostContext>("modelHost", value => value.RequireNotNull());
            var contentTypeFieldLinkModel = model.WithAssertAndCast <ContentTypeFieldLinkDefinition>("model", value => value.RequireNotNull());

            var site        = modelHostWrapper.Site;
            var rootWeb     = site.RootWeb;
            var contentType = modelHostWrapper.ContentType;

            var context = contentType.Context;

            TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Getting content type field link by ID: [{0}]", contentTypeFieldLinkModel.FieldId);

            var tmp = contentType.FieldLinks.GetById(contentTypeFieldLinkModel.FieldId);

            context.ExecuteQueryWithTrace();

            FieldLink fieldLink = null;

            if (tmp != null && tmp.ServerObjectIsNull.HasValue && !tmp.ServerObjectIsNull.Value)
            {
                TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Found existing field link");

                fieldLink = tmp;
            }

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = fieldLink,
                ObjectType       = typeof(FieldLink),
                ObjectDefinition = model,
                ModelHost        = modelHost
            });

            if (fieldLink == null)
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new content type field link");

                var targetField = FindExistingSiteField(rootWeb, contentTypeFieldLinkModel.FieldId);

                fieldLink = contentType.FieldLinks.Add(new FieldLinkCreationInformation
                {
                    Field = targetField
                });
            }
            else
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing content type field link");
            }

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = fieldLink,
                ObjectType       = typeof(FieldLink),
                ObjectDefinition = model,
                ModelHost        = modelHost
            });

            contentType.Update(true);
            context.ExecuteQueryWithTrace();
        }
Пример #17
0
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var modelHostWrapper          = modelHost.WithAssertAndCast <ContentTypeModelHost>("modelHost", value => value.RequireNotNull());
            var contentTypeFieldLinkModel = model.WithAssertAndCast <ContentTypeFieldLinkDefinition>("model", value => value.RequireNotNull());

            //var site = modelHostWrapper.Site;
            var web         = modelHostWrapper.HostWeb;
            var contentType = modelHostWrapper.HostContentType;

            var context = contentType.Context;

            TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Getting content type field link by ID: [{0}]", contentTypeFieldLinkModel.FieldId);

            FieldLink fieldLink = FindExistingFieldLink(contentType, contentTypeFieldLinkModel);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = fieldLink,
                ObjectType       = typeof(FieldLink),
                ObjectDefinition = model,
                ModelHost        = modelHost
            });

            if (fieldLink == null)
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new content type field link");

                var targetField = FindAvailableField(web, contentTypeFieldLinkModel);

                fieldLink = contentType.FieldLinks.Add(new FieldLinkCreationInformation
                {
                    Field = targetField
                });
            }
            else
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing content type field link");
            }

            if (contentTypeFieldLinkModel.Required.HasValue)
            {
                fieldLink.Required = contentTypeFieldLinkModel.Required.Value;
            }

            if (contentTypeFieldLinkModel.Hidden.HasValue)
            {
                fieldLink.Hidden = contentTypeFieldLinkModel.Hidden.Value;
            }

            if (!string.IsNullOrEmpty(contentTypeFieldLinkModel.DisplayName))
            {
                // CSOM limitation - DisplayName is not available yet.
                // https://officespdev.uservoice.com/forums/224641-general/suggestions/7024931-enhance-fieldlink-class-with-additional-properties

                //   fieldLink.DisplayName = contentTypeFieldLinkModel.DisplayName;

                // Enhance FieldLinkDefinition - DisplayName, ReadOnly, ShowInDisplayForm #892
                // https://github.com/SubPointSolutions/spmeta2/issues/892
                if (ReflectionUtils.HasProperty(fieldLink, "DisplayName"))
                {
                    if (!string.IsNullOrEmpty(contentTypeFieldLinkModel.DisplayName))
                    {
                        ClientRuntimeQueryService.SetProperty(fieldLink, "DisplayName", contentTypeFieldLinkModel.DisplayName);
                    }
                }
                else
                {
                    TraceService.Critical((int)LogEventId.ModelProvisionCoreCall,
                                          "CSOM runtime doesn't have FieldLink.DisplayName. Update CSOM runtime to a new version. Provision is skipped");
                }
            }

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = fieldLink,
                ObjectType       = typeof(FieldLink),
                ObjectDefinition = model,
                ModelHost        = modelHost
            });

            contentType.Update(true);
            context.ExecuteQueryWithTrace();
        }
Пример #18
0
 private void SetValue(FieldLink fl, object val)
 {
     if (fl.ArrayIndex < 0)
     {
         fl.F.SetValue(fl.obj, val);
     }
     else
     {
         Array ArrayValue = (Array)fl.F.GetValue(fl.obj);
         ArrayValue.SetValue(val, fl.ArrayIndex);
         fl.F.SetValue(fl.obj, ArrayValue);
     }
 }
Пример #19
0
        // <Summary>
        // This method is used to export a FieldLink object to xml.
        // </Summary>
        public string ExportFieldLink(FieldLink fieldLink, int indent = 0)
        {
            // initial value
            string fieldLinkXml = "";

            // locals
            string indentString  = TextHelper.Indent(indent);
            string indentString2 = TextHelper.Indent(indent + 2);

            // If the fieldLink object exists
            if (NullHelper.Exists(fieldLink))
            {
                // Create a StringBuilder
                StringBuilder sb = new StringBuilder();

                // Append the indentString
                sb.Append(indentString);

                // Write the open fieldLink node
                sb.Append("<FieldLink>" + Environment.NewLine);

                // Write out each property

                // Write out the value for FieldValuePair

                sb.Append(indentString2);
                sb.Append("<FieldValuePair>" + fieldLink.FieldValuePair + "</FieldValuePair>" + Environment.NewLine);

                // Write out the value for ID

                sb.Append(indentString2);
                sb.Append("<ID>" + fieldLink.ID + "</ID>" + Environment.NewLine);

                // Write out the value for MapType

                sb.Append(indentString2);
                sb.Append("<MapType>" + fieldLink.MapType + "</MapType>" + Environment.NewLine);

                // Write out the value for RelationshipType

                sb.Append(indentString2);
                sb.Append("<RelationshipType>" + fieldLink.RelationshipType + "</RelationshipType>" + Environment.NewLine);

                // Write out the value for SourceFieldName

                sb.Append(indentString2);
                sb.Append("<SourceFieldName>" + fieldLink.SourceFieldName + "</SourceFieldName>" + Environment.NewLine);

                // Write out the value for TargetDataType

                sb.Append(indentString2);
                sb.Append("<TargetDataType>" + fieldLink.TargetDataType + "</TargetDataType>" + Environment.NewLine);

                // Write out the value for TargetFieldName

                sb.Append(indentString2);
                sb.Append("<TargetFieldName>" + fieldLink.TargetFieldName + "</TargetFieldName>" + Environment.NewLine);

                // Append the indentString
                sb.Append(indentString);

                // Write out the close fieldLink node
                sb.Append("</FieldLink>" + Environment.NewLine);

                // set the return value
                fieldLinkXml = sb.ToString();
            }
            // return value
            return(fieldLinkXml);
        }
Пример #20
0
        /// <summary>
        /// This method is used to parse FieldLink objects.
        /// </summary>
        public FieldLink ParseFieldLink(ref FieldLink fieldLink, XmlNode xmlNode)
        {
            // if the fieldLink object exists and the xmlNode exists
            if ((fieldLink != null) && (xmlNode != null))
            {
                // get the full name of this node
                string fullName = xmlNode.GetFullName();

                // Check the name of this node to see if it is mapped to a property
                switch (fullName)
                {
                case "Mirror.FieldLinks.FieldLink.FieldValuePair":

                    // Set the value for fieldLink.FieldValuePair
                    // fieldLink.FieldValuePair = // this field must be parsed manually.

                    // required
                    break;

                case "Mirror.FieldLinks.FieldLink.ID":

                    // if the FormattedNodeValue exists
                    if (TextHelper.Exists(xmlNode.FormattedNodeValue))
                    {
                        // Create a tempGuid
                        Guid tempGuid = Guid.Empty;

                        // attempt to parse the Guid
                        if (Guid.TryParse(xmlNode.FormattedNodeValue, out tempGuid))
                        {
                            // Set the value for fieldLink.ID
                            fieldLink.ID = tempGuid;
                        }
                    }

                    // required
                    break;

                case "Mirror.FieldLinks.FieldLink.MapType":

                    // Set the value for fieldLink.MapType
                    fieldLink.MapType = EnumHelper.GetEnumValue <XmlMirror.Runtime.Enumerations.MapTypeEnum>(xmlNode.FormattedNodeValue, XmlMirror.Runtime.Enumerations.MapTypeEnum.Unknown);

                    // required
                    break;

                case "Mirror.FieldLinks.FieldLink.RelationshipType":

                    // Set the value for fieldLink.RelationshipType
                    fieldLink.RelationshipType = EnumHelper.GetEnumValue <XmlMirror.Runtime.Enumerations.InstanceTypeEnum>(xmlNode.FormattedNodeValue, XmlMirror.Runtime.Enumerations.InstanceTypeEnum.Unknown);

                    // required
                    break;

                case "Mirror.FieldLinks.FieldLink.SourceFieldName":

                    // Set the value for fieldLink.SourceFieldName
                    fieldLink.SourceFieldName = xmlNode.FormattedNodeValue;

                    // required
                    break;

                case "Mirror.FieldLinks.FieldLink.TargetDataType":

                    // Set the value for fieldLink.TargetDataType
                    fieldLink.TargetDataType = EnumHelper.GetEnumValue <XmlMirror.Runtime.Enumerations.DataTypeEnum>(xmlNode.FormattedNodeValue, XmlMirror.Runtime.Enumerations.DataTypeEnum.NotSupported);

                    // required
                    break;

                case "Mirror.FieldLinks.FieldLink.TargetFieldName":

                    // Set the value for fieldLink.TargetFieldName
                    fieldLink.TargetFieldName = xmlNode.FormattedNodeValue;

                    // required
                    break;
                }

                // if there are ChildNodes
                if (xmlNode.HasChildNodes)
                {
                    // iterate the child nodes
                    foreach (XmlNode childNode in xmlNode.ChildNodes)
                    {
                        // append to this FieldLink
                        fieldLink = ParseFieldLink(ref fieldLink, childNode);
                    }
                }
            }

            // return value
            return(fieldLink);
        }
Пример #21
0
        /// <summary>
        /// This method is used to parse a list of 'FieldLink' objects.
        /// </summary>
        /// <param name="XmlNode">The XmlNode to be parsed.</param>
        /// <returns>A list of 'FieldLink' objects.</returns>
        public List <FieldLink> ParseFieldLinks(XmlNode xmlNode, List <FieldLink> fieldLinks = null)
        {
            // locals
            FieldLink fieldLink = null;
            bool      cancel    = false;

            // if the xmlNode exists
            if (xmlNode != null)
            {
                // get the full name for this node
                string fullName = xmlNode.GetFullName();

                // if this is the new collection line
                if (fullName == "Mirror.FieldLinks")
                {
                    // Raise event Parsing is starting.
                    cancel = Parsing(xmlNode);

                    // If not cancelled
                    if (!cancel)
                    {
                        // create the return collection
                        fieldLinks = new List <FieldLink>();
                    }
                }
                // if this is the new object line and the return collection exists
                else if ((fullName == "Mirror.FieldLinks.FieldLink") && (fieldLinks != null))
                {
                    // Create a new object
                    fieldLink = new FieldLink();

                    // Perform pre parse operations
                    cancel = Parsing(xmlNode, ref fieldLink);

                    // If not cancelled
                    if (!cancel)
                    {
                        // parse this object
                        fieldLink = ParseFieldLink(ref fieldLink, xmlNode);
                    }

                    // Perform post parse operations
                    cancel = Parsed(xmlNode, ref fieldLink);

                    // If not cancelled
                    if (!cancel)
                    {
                        // Add this object to the return value
                        fieldLinks.Add(fieldLink);
                    }
                }

                // if there are ChildNodes
                if (xmlNode.HasChildNodes)
                {
                    // iterate the child nodes
                    foreach (XmlNode childNode in xmlNode.ChildNodes)
                    {
                        // self call this method for each childNode
                        fieldLinks = ParseFieldLinks(childNode, fieldLinks);
                    }
                }
            }

            // return value
            return(fieldLinks);
        }
Пример #22
0
 private object GetValue(FieldLink fl)
 {
     if (fl.ArrayIndex < 0)
     {
         return fl.F.GetValue(fl.obj);
     }
     else
     {
         Array ArrayValue = (Array)fl.F.GetValue(fl.obj);
         return ArrayValue.GetValue(fl.ArrayIndex);
     }
 }