Exemple #1
0
        /// <summary>
        /// Reads the 'OnChange' replacement templates variables from the EditorTrackFields.xml file.
        /// </summary>
        private void ReadOnChangeReplacementTemplates()
        {
            XmlNodeList        nodelist  = this.GetElementsByTagName("OnChange");
            TemplateDictionary templates = new TemplateDictionary(StringComparer.CurrentCultureIgnoreCase);

            foreach (XmlNode node in nodelist[0].ChildNodes)
            {
                using (XmlReader reader = new XmlNodeReader(node))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(ReplacementTemplate));

                    if (serializer.CanDeserialize(reader))
                    {
                        ReplacementTemplate replacementTemplate = serializer.Deserialize(reader) as ReplacementTemplate;

                        templates.Add(replacementTemplate.FeatureclassName, replacementTemplate);
                    }
                    else
                    {
                        // do something to handle
                        throw new XmlException();
                    }
                }
            }

            this.TemplateOnChangeFields = templates;
        }
        /// <summary>
        /// Method called when a feature is modified.
        /// </summary>
        /// <param name="obj">The object that was created</param>
        public void Events_OnChangeFeature(IObject obj)
        {
            if (EditorTrackHelper.extensionEnabled && trackingFields != null && obj != null)
            {
                ReplacementTemplate globaltemplates    = trackingFields.TemplateOnChangeFields[Constants.GlobalName];
                ReplacementTemplate featclasstemplates = null;

                if (trackingFields.TemplateOnCreateFields.ContainsKey((obj.Class as IDataset).Name))
                {
                    featclasstemplates = trackingFields.TemplateOnChangeFields[(obj.Class as IDataset).Name];
                }

                if (globaltemplates != null && globaltemplates.FieldReplacements != null)
                {
                    foreach (KeyValuePair <string, string> item in globaltemplates.FieldReplacements)
                    {
                        int i = obj.Fields.FindField(item.Key);

                        if (i > -1)
                        {
                            object val = this.EvaluateValue(obj, item, trackingFields.ReplacementFieldDictionary);

                            if (val != null)
                            {
                                if (val is byte[])
                                {
                                    IMemoryBlobStreamVariant memoryBlobStream = new MemoryBlobStreamClass();
                                    memoryBlobStream.ImportFromVariant(val);

                                    obj.set_Value(i, memoryBlobStream);
                                }
                                else
                                {
                                    obj.set_Value(i, val);
                                }
                            }
                        }
                    }
                }

                if (featclasstemplates != null && featclasstemplates.FieldReplacements != null)
                {
                    foreach (KeyValuePair <string, string> item in featclasstemplates.FieldReplacements)
                    {
                        int i = obj.Fields.FindField(item.Key);

                        if (i > -1)
                        {
                            object val = this.EvaluateValue(obj, item, trackingFields.ReplacementFieldDictionary);

                            if (val != null)
                            {
                                if (val is byte[])
                                {
                                    IMemoryBlobStreamVariant memoryBlobStream = new MemoryBlobStreamClass();
                                    memoryBlobStream.ImportFromVariant(val);

                                    obj.set_Value(i, memoryBlobStream);
                                }
                                else
                                {
                                    obj.set_Value(i, val);
                                }
                            }
                        }
                    }
                }
            }
        }