示例#1
0
        public void FilterManipulations()
        {
            Filter filter1 = new Filter();

            filter1.AddCondition("Name = Bob");
            filter1.AddCondition("Name = Lex");

            Filter filter2 = new Filter("Name = Bob and Name = Lex");

            Filter filter3 = new Filter(new Condition("Name", "Bob", ComparisonOperator.EQ));

            filter3.AddCondition(new Condition("Name", "Lex"));

            Filter filter4 = new Filter();

            filter4.AddCondition("Name = Tom");
            filter4.AddCondition("Name = Lex");
            var condition1 = filter4.ConditionLine.Where(x => x is Condition)
                             .Select(e => e as Condition)
                             .Where(c => c.Value.ToString() == "Tom")
                             .First();

            condition1.Value = "Bob";

            Assert.AreEqual(filter1.GetQueryString(), filter2.GetQueryString());
            Assert.AreEqual(filter1.GetQueryString(), filter3.GetQueryString());
            Assert.AreEqual(filter1.GetQueryString(), filter4.GetQueryString());
            Assert.AreEqual(filter1.GetQueryString(), "$filter=Name%20eq%20%27Bob%27%20and%20Name%20eq%20%27Lex%27");
        }
示例#2
0
        private void SetConditions()
        {
            if (!ValidateConditions(out string hashKey))
            {
                ArgumentException ex = new ArgumentException($"Not contains any condition of type Equals for field {hashKey}");
                throw ex;
            }

            Conditions.ForEach(f => Filter.AddCondition(f.AtributeName, f));
        }
        private static void AdjustQueryForCreatedThreshold(QueryDefinition query, DateTime notInThreshold)
        {
            //if we have a not in query then we want to ensure any records created after the not in set was generated
            //arent included in the main query as they wont have been considered for exlcusion when running the not in query
            var rootFilter = query.RootFilter;
            var newFilter  = new Filter();

            newFilter.SubFilters.Add(rootFilter);
            newFilter.AddCondition("createdon", ConditionType.LessThan, notInThreshold);
            query.RootFilter = newFilter;
        }
        public override void ExecuteExtention(ManagePluginTriggersRequest request, ManagePluginTriggersResponse response, ServiceRequestController controller)
        {
            controller.UpdateProgress(0, 4, "Processing Deletions");
            //delete any removed plugins
            var removedPlugins = request.GetSdkMessageStepsPre().Where(smsp => request.Triggers.All(pt => pt.Id != smsp.Id)).ToArray();
            var deletions      = Service.DeleteInCrm(removedPlugins);

            response.AddResponseItems(deletions.Errors.Select(e => new ManagePluginTriggersResponseItem("Event Delete", e.Key.GetStringField(Fields.sdkmessageprocessingstep_.name), e.Value)));
            response.AddResponseItems(deletions.Deleted.Select(d => new ManagePluginTriggersResponseItem("Event Delete", d.GetStringField(Fields.sdkmessageprocessingstep_.name))));

            //load the filter entities which exist for each entity type, message combination
            var filters = request.Triggers.Select(t =>
            {
                var filter = new Filter();
                filter.AddCondition(Fields.sdkmessagefilter_.primaryobjecttypecode, ConditionType.Equal, t.RecordType == null ? "none" : t.RecordType.Key);
                filter.AddCondition(Fields.sdkmessagefilter_.sdkmessageid, ConditionType.Equal, t.Message.Id);
                return(filter);
            }).ToArray();
            var pluginFilters = Service.RetrieveAllOrClauses(Entities.sdkmessagefilter, filters);

            controller.UpdateProgress(1, 4, "Unloading Triggers");
            //unload the triggers into an entity object referencing it in a dictionary
            var unloadedObjects = new Dictionary <IRecord, PluginTrigger>();

            foreach (var item in request.Triggers)
            {
                var matchingPluginFilters =
                    pluginFilters.Where(f => f.GetLookupId(Fields.sdkmessagefilter_.sdkmessageid) == item.Message.Id
                                        &&
                                        ((item.RecordType == null && f.GetStringField(Fields.sdkmessagefilter_.primaryobjecttypecode) == "none")
                                         ||
                                         (item.RecordType != null && f.GetStringField(Fields.sdkmessagefilter_.primaryobjecttypecode) == item.RecordType.Key)))
                    .ToArray();
                var record = Service.NewRecord(Entities.sdkmessageprocessingstep);
                var name   = string.Format("{0} {1} {2} {3} {4}", item.Plugin, item.RecordType?.Key ?? "none", item.Message, item.Stage, item.Mode).Left(Service.GetMaxLength(Fields.sdkmessageprocessingstep_.name, Entities.sdkmessageprocessingstep));
                try
                {
                    if (!matchingPluginFilters.Any())
                    {
                        response.AddResponseItem(new ManagePluginTriggersResponseItem("Warning", name, new NullReferenceException($"No Matching {Service.GetDisplayName(Entities.sdkmessagefilter)} Could Be Found For The Trigger Configuration")));
                    }


                    record.SetField(Fields.sdkmessageprocessingstep_.name, name, Service);
                    record.SetField(Fields.sdkmessageprocessingstep_.rank, item.Rank, Service);
                    if (item.Stage != null)
                    {
                        record.SetField(Fields.sdkmessageprocessingstep_.stage, (int)item.Stage, Service);
                    }
                    if (item.Mode != null)
                    {
                        record.SetField(Fields.sdkmessageprocessingstep_.mode, (int)item.Mode, Service);
                    }
                    record.SetField(Fields.sdkmessageprocessingstep_.plugintypeid, item.Plugin, Service);
                    record.SetField(Fields.sdkmessageprocessingstep_.sdkmessagefilterid, !matchingPluginFilters.Any() ? null : matchingPluginFilters.First().ToLookup(), Service);
                    record.SetField(Fields.sdkmessageprocessingstep_.sdkmessageid, item.Message, Service);
                    record.SetField(Fields.sdkmessageprocessingstep_.impersonatinguserid, item.SpecificUserContext == null || item.SpecificUserContext.Id == null ? null : item.SpecificUserContext, Service);
                    if (item.Id != null)
                    {
                        record.SetField(Fields.sdkmessageprocessingstep_.sdkmessageprocessingstepid, item.Id, Service);
                    }
                    record.SetField(Fields.sdkmessageprocessingstep_.asyncautodelete, item.Mode == PluginTrigger.PluginMode.Asynch, Service);
                    record.SetField(Fields.sdkmessageprocessingstep_.filteringattributes, item.FilteringFields != null && item.FilteringFields.Any() ? string.Join(",", item.FilteringFields.OrderBy(r => r.Key).Select(r => r.Key)) : null, Service);
                    unloadedObjects.Add(record, item);
                }
                catch (Exception ex)
                {
                    response.AddResponseItem(new ManagePluginTriggersResponseItem("Unload Error", name, ex));
                }
            }

            controller.UpdateProgress(2, 4, "Creating/Updating Triggers");
            //submit them to crm create/update
            var triggerLoads = Service.LoadIntoCrm(unloadedObjects.Keys,
                                                   Fields.sdkmessageprocessingstep_.sdkmessageprocessingstepid);

            foreach (var e in triggerLoads.Errors)
            {
                response.AddResponseItem(new ManagePluginTriggersResponseItem(e.Key.Id != null ? "Event Update" : "Event Create", e.Key.GetStringField(Fields.sdkmessageprocessingstep_.name), e.Value));
            }
            response.AddResponseItems(triggerLoads.Created.Select(d => new ManagePluginTriggersResponseItem("Event Create", d.GetStringField(Fields.sdkmessageprocessingstep_.name))));
            response.AddResponseItems(triggerLoads.Updated.Select(d => new ManagePluginTriggersResponseItem("Event Update", d.GetStringField(Fields.sdkmessageprocessingstep_.name))));

            controller.UpdateProgress(3, 4, "Creating/Updating Images");

            var updatesAndDeletes =
                unloadedObjects.Keys.Where(
                    r =>
                    new[] { "Update", "Delete" }.Contains(
                        r.GetLookupName(Fields.sdkmessageprocessingstep_.sdkmessageid)))
                .ToArray();

            var solutionItemsToAdd = new List <string>();
            //update/delete pre-images
            var imagesToCreateOrUpdate = new List <IRecord>();
            var imagesToDelete         = new List <IRecord>();

            foreach (var item in updatesAndDeletes
                     .Where(i => !triggerLoads.Errors.Keys.Contains(i)))
            {
                var matchingPluginTrigger = unloadedObjects[item];
                //the plugin will only have an image if all fields, or there are specific fields selected
                var hasImage = matchingPluginTrigger.PreImageAllFields || (matchingPluginTrigger.PreImageFields != null && matchingPluginTrigger.PreImageFields.Any());
                if (!hasImage)
                {
                    //delete the existing image if is has been changed to not have an image
                    if (matchingPluginTrigger.PreImageId != null)
                    {
                        try
                        {
                            imagesToDelete.Add(Service.Get(Entities.sdkmessageprocessingstepimage, matchingPluginTrigger.PreImageId));
                            solutionItemsToAdd.Add(matchingPluginTrigger.Id);
                        }
                        catch (Exception ex)
                        {
                            response.AddResponseItem(new ManagePluginTriggersResponseItem("Pre Image Delete", matchingPluginTrigger.Id, ex));
                        }
                    }
                }
                else
                {
                    try
                    {
                        //set the details to create/update in the pre-image
                        var isUpdate    = triggerLoads.Updated.Contains(item);
                        var imageRecord = Service.NewRecord(Entities.sdkmessageprocessingstepimage);
                        imageRecord.Id = matchingPluginTrigger.PreImageId;
                        if (matchingPluginTrigger.PreImageId != null)
                        {
                            imageRecord.SetField(Fields.sdkmessageprocessingstepimage_.sdkmessageprocessingstepimageid, matchingPluginTrigger.PreImageId, Service);
                        }
                        if (matchingPluginTrigger.PreImageIdUnique != null)
                        {
                            imageRecord.SetField(Fields.sdkmessageprocessingstepimage_.sdkmessageprocessingstepimageidunique, matchingPluginTrigger.PreImageIdUnique, Service);
                        }

                        imageRecord.SetField(Fields.sdkmessageprocessingstepimage_.name, matchingPluginTrigger.PreImageName, Service);
                        imageRecord.SetField(Fields.sdkmessageprocessingstepimage_.entityalias, matchingPluginTrigger.PreImageName, Service);
                        imageRecord.SetField(Fields.sdkmessageprocessingstepimage_.messagepropertyname, "Target", Service);
                        imageRecord.SetField(Fields.sdkmessageprocessingstepimage_.sdkmessageprocessingstepid, Service.ToLookup(item), Service);
                        imageRecord.SetField(Fields.sdkmessageprocessingstepimage_.imagetype, OptionSets.SdkMessageProcessingStepImage.ImageType.PreImage, Service);
                        var attributesString = matchingPluginTrigger.PreImageAllFields || matchingPluginTrigger.PreImageFields == null || !matchingPluginTrigger.PreImageFields.Any()
                            ? null
                            : string.Join(",", matchingPluginTrigger.PreImageFields.Select(f => f.Key).OrderBy(s => s).ToArray());
                        imageRecord.SetField(Fields.sdkmessageprocessingstepimage_.attributes, attributesString, Service);
                        imagesToCreateOrUpdate.Add(imageRecord);
                    }
                    catch (Exception ex)
                    {
                        response.AddResponseItem(new ManagePluginTriggersResponseItem("Image Error", item.GetStringField(Fields.sdkmessageprocessingstep_.name), ex));
                    }
                }
            }

            //submit create/update/deletion of pre-images
            var imageLoads = Service.LoadIntoCrm(imagesToCreateOrUpdate,
                                                 Fields.sdkmessageprocessingstepimage_.sdkmessageprocessingstepimageidunique);

            foreach (var e in imageLoads.Errors)
            {
                response.AddResponseItem(new ManagePluginTriggersResponseItem(e.Key.Id != null ? "Pre Image Update" : "Pre Image Create", e.Key.GetLookupName(Fields.sdkmessageprocessingstepimage_.sdkmessageprocessingstepid), e.Value));
            }
            response.AddResponseItems(imageLoads.Created.Select(d => new ManagePluginTriggersResponseItem("Pre Image Create", d.GetLookupName(Fields.sdkmessageprocessingstepimage_.sdkmessageprocessingstepid))));
            response.AddResponseItems(imageLoads.Updated.Select(d => new ManagePluginTriggersResponseItem("Pre Image Update", d.GetLookupName(Fields.sdkmessageprocessingstepimage_.sdkmessageprocessingstepid))));


            var imageDeletions = Service.DeleteInCrm(imagesToDelete);

            response.AddResponseItems(imageDeletions.Errors.Select(e => new ManagePluginTriggersResponseItem("Pre Image Delete", e.Key.GetLookupName(Fields.sdkmessageprocessingstepimage_.sdkmessageprocessingstepid), e.Value)));

            //add plugin steps to the solution
            var componentType = OptionSets.SolutionComponent.ObjectTypeCode.SDKMessageProcessingStep;

            solutionItemsToAdd.AddRange(triggerLoads.Created.Union(triggerLoads.Updated).Select(r => r.Id).ToList());
            var imagesReferences = imageLoads.Created.Union(imageLoads.Updated)
                                   .Select(i => i.GetLookupId(Fields.sdkmessageprocessingstepimage_.sdkmessageprocessingstepid))
                                   .Where(id => !string.IsNullOrWhiteSpace(id));

            solutionItemsToAdd.AddRange(imagesReferences);

            if (PackageSettings.AddToSolution)
            {
                controller.UpdateProgress(4, 4, "Adding Components To Solution");
                Service.AddSolutionComponents(PackageSettings.Solution.Id, componentType, solutionItemsToAdd);
            }

            if (response.HasResponseItemError)
            {
                response.Message = "There Were Errors Thrown Updating The Plugins";
            }
            else if (!response.HasResponseItems)
            {
                response.Message = "No Updates Were Identified";
            }
            else
            {
                response.Message = "Plugins Updated";
            }
        }
示例#5
0
        protected override void CompleteDialogExtention()
        {
            var responses = new List <PluginTriggerError>();

            //delete any removed plugins
            var removedPlugins = SdkMessageStepsPre.Where(smsp => EntryObject.Triggers.All(pt => pt.Id != smsp.Id)).ToArray();
            var deletions      = XrmRecordService.DeleteInCrm(removedPlugins);

            foreach (var trigger in deletions.Errors)
            {
                var error = new PluginTriggerError()
                {
                    Type      = "Deletion",
                    Name      = trigger.Key.GetLookupName(Fields.sdkmessageprocessingstep_.sdkmessageprocessingstepid),
                    Exception = trigger.Value
                };
                responses.Add(error);
            }

            //load the filter entities which exist for each entity type, message combination
            var filters = EntryObject.Triggers.Select(t =>
            {
                var filter = new Filter();
                filter.AddCondition(Fields.sdkmessagefilter_.primaryobjecttypecode, ConditionType.Equal, t.RecordType == null ? "none" : t.RecordType.Key);
                filter.AddCondition(Fields.sdkmessagefilter_.sdkmessageid, ConditionType.Equal, t.Message.Id);
                return(filter);
            }).ToArray();
            var pluginFilters = XrmRecordService.RetrieveAllOrClauses(Entities.sdkmessagefilter, filters);

            //unload the triggers into an entity object referencing it in a dictionary
            var unloadedObjects = new Dictionary <IRecord, PluginTrigger>();

            foreach (var item in EntryObject.Triggers)
            {
                var matchingPluginFilters =
                    pluginFilters.Where(f => f.GetLookupId(Fields.sdkmessagefilter_.sdkmessageid) == item.Message.Id
                                        &&
                                        ((item.RecordType == null && f.GetStringField(Fields.sdkmessagefilter_.primaryobjecttypecode) == "none")
                                         ||
                                         (item.RecordType != null && f.GetStringField(Fields.sdkmessagefilter_.primaryobjecttypecode) == item.RecordType.Key)))
                    .ToArray();
                var record = XrmRecordService.NewRecord(Entities.sdkmessageprocessingstep);
                var name   = string.Format("{0} {1} {2} {3} {4}", item.Plugin, item.RecordType?.Key ?? "none", item.Message, item.Stage, item.Mode).Left(XrmRecordService.GetMaxLength(Fields.sdkmessageprocessingstep_.name, Entities.sdkmessageprocessingstep));
                record.SetField(Fields.sdkmessageprocessingstep_.name, name, XrmRecordService);
                record.SetField(Fields.sdkmessageprocessingstep_.rank, item.Rank, XrmRecordService);
                if (item.Stage != null)
                {
                    record.SetField(Fields.sdkmessageprocessingstep_.stage, (int)item.Stage, XrmRecordService);
                }
                if (item.Mode != null)
                {
                    record.SetField(Fields.sdkmessageprocessingstep_.mode, (int)item.Mode, XrmRecordService);
                }
                record.SetField(Fields.sdkmessageprocessingstep_.plugintypeid, item.Plugin, XrmRecordService);
                record.SetField(Fields.sdkmessageprocessingstep_.sdkmessagefilterid, !matchingPluginFilters.Any() ? null : matchingPluginFilters.First().ToLookup(), XrmRecordService);
                record.SetField(Fields.sdkmessageprocessingstep_.sdkmessageid, item.Message, XrmRecordService);
                record.SetField(Fields.sdkmessageprocessingstep_.impersonatinguserid, item.SpecificUserContext == null || item.SpecificUserContext.Id == null ? null : item.SpecificUserContext, XrmRecordService);
                if (item.Id != null)
                {
                    record.SetField(Fields.sdkmessageprocessingstep_.sdkmessageprocessingstepid, item.Id, XrmRecordService);
                }
                record.SetField(Fields.sdkmessageprocessingstep_.asyncautodelete, item.Mode == PluginTrigger.PluginMode.Asynchronous, XrmRecordService);
                record.SetField(Fields.sdkmessageprocessingstep_.filteringattributes, item.FilteringFields != null && item.FilteringFields.Any() ? string.Join(",", item.FilteringFields.OrderBy(r => r.Key).Select(r => r.Key)) : null, XrmRecordService);
                unloadedObjects.Add(record, item);
            }

            //submit them to crm create/update
            var triggerLoads = XrmRecordService.LoadIntoCrm(unloadedObjects.Keys,
                                                            Fields.sdkmessageprocessingstep_.sdkmessageprocessingstepid);

            var updatesAndDeletes =
                unloadedObjects.Keys.Where(
                    r =>
                    new[] { "Update", "Delete" }.Contains(
                        r.GetLookupName(Fields.sdkmessageprocessingstep_.sdkmessageid)))
                .ToArray();

            var solutionItemsToAdd = new List <string>();
            //update/delete pre-images
            var imagesToCreateOrUpdate = new List <IRecord>();
            var imagesToDelete         = new List <IRecord>();

            foreach (var item in updatesAndDeletes
                     .Where(i => !triggerLoads.Errors.Keys.Contains(CompletionItem)))
            {
                var matchingPluginTrigger = unloadedObjects[item];
                //the plugin will only have an image if all fields, or there are specific fields selected
                var hasImage = matchingPluginTrigger.PreImageAllFields || (matchingPluginTrigger.PreImageFields != null && matchingPluginTrigger.PreImageFields.Any());
                if (!hasImage)
                {
                    //delete the existing image if is has been changed to not have an image
                    if (matchingPluginTrigger.PreImageId != null)
                    {
                        try
                        {
                            imagesToDelete.Add(XrmRecordService.Get(Entities.sdkmessageprocessingstepimage, matchingPluginTrigger.PreImageId));
                            solutionItemsToAdd.Add(matchingPluginTrigger.Id);
                        }
                        catch (Exception ex)
                        {
                            var error = new PluginTriggerError()
                            {
                                Type      = "Image Deletion",
                                Name      = matchingPluginTrigger.PreImageId,
                                Exception = ex
                            };
                            responses.Add(error);
                        }
                    }
                }
                else
                {
                    //set the details to create/update in the pre-image
                    var isUpdate    = triggerLoads.Updated.Contains(item);
                    var imageRecord = XrmRecordService.NewRecord(Entities.sdkmessageprocessingstepimage);
                    imageRecord.Id = matchingPluginTrigger.PreImageId;
                    if (matchingPluginTrigger.PreImageId != null)
                    {
                        imageRecord.SetField(Fields.sdkmessageprocessingstepimage_.sdkmessageprocessingstepimageid, matchingPluginTrigger.PreImageId, XrmRecordService);
                    }
                    imageRecord.SetField(Fields.sdkmessageprocessingstepimage_.name, matchingPluginTrigger.PreImageName, XrmRecordService);
                    imageRecord.SetField(Fields.sdkmessageprocessingstepimage_.entityalias, matchingPluginTrigger.PreImageName, XrmRecordService);
                    imageRecord.SetField(Fields.sdkmessageprocessingstepimage_.messagepropertyname, "Target", XrmRecordService);
                    imageRecord.SetField(Fields.sdkmessageprocessingstepimage_.sdkmessageprocessingstepid, XrmRecordService.ToLookup(item), XrmRecordService);
                    imageRecord.SetField(Fields.sdkmessageprocessingstepimage_.imagetype, OptionSets.SdkMessageProcessingStepImage.ImageType.PreImage, XrmRecordService);
                    var attributesString = matchingPluginTrigger.PreImageAllFields || matchingPluginTrigger.PreImageFields == null || !matchingPluginTrigger.PreImageFields.Any()
                        ? null
                        : string.Join(",", matchingPluginTrigger.PreImageFields.Select(f => f.Key).OrderBy(s => s).ToArray());
                    imageRecord.SetField(Fields.sdkmessageprocessingstepimage_.attributes, attributesString, XrmRecordService);
                    imagesToCreateOrUpdate.Add(imageRecord);
                }
            }

            //submit create/update/deletion of pre-images
            var imageLoads = XrmRecordService.LoadIntoCrm(imagesToCreateOrUpdate,
                                                          Fields.sdkmessageprocessingstepimage_.sdkmessageprocessingstepimageid);
            var imageDeletions = XrmRecordService.DeleteInCrm(imagesToDelete);

            //add any errors to the response object
            foreach (var trigger in imageDeletions.Errors)
            {
                var error = new PluginTriggerError()
                {
                    Type      = "Image Deletion",
                    Name      = trigger.Key.GetLookupName(Fields.sdkmessageprocessingstepimage_.sdkmessageprocessingstepid),
                    Exception = trigger.Value
                };
                responses.Add(error);
            }

            foreach (var trigger in triggerLoads.Errors)
            {
                var error = new PluginTriggerError()
                {
                    Type      = "Plugin Step",
                    Name      = trigger.Key.GetStringField(Fields.sdkmessageprocessingstep_.name),
                    Exception = trigger.Value
                };
                responses.Add(error);
            }
            foreach (var trigger in imageLoads.Errors)
            {
                var error = new PluginTriggerError()
                {
                    Type      = "Image",
                    Name      = trigger.Key.GetLookupName(Fields.sdkmessageprocessingstepimage_.sdkmessageprocessingstepid),
                    Exception = trigger.Value
                };
                responses.Add(error);
            }

            //add plugin steps to the solution
            var componentType = OptionSets.SolutionComponent.ObjectTypeCode.SDKMessageProcessingStep;

            solutionItemsToAdd.AddRange(triggerLoads.Created.Union(triggerLoads.Updated).Select(r => r.Id).ToList());
            var imagesReferences = imageLoads.Created.Union(imageLoads.Updated)
                                   .Select(i => i.GetLookupId(Fields.sdkmessageprocessingstepimage_.sdkmessageprocessingstepid))
                                   .Where(id => !string.IsNullOrWhiteSpace(id));

            solutionItemsToAdd.AddRange(imagesReferences);

            if (PackageSettings.AddToSolution)
            {
                XrmRecordService.AddSolutionComponents(PackageSettings.Solution.Id, componentType, solutionItemsToAdd);
            }

            CompletionItem = new Completionresponse {
                Errors = responses
            };

            if (responses.Any())
            {
                CompletionMessage = "There Were Errors Thrown Updating The Plugins";
            }
            else
            {
                CompletionMessage = "Plugins Updated";
            }
        }
示例#6
0
文件: Form1.cs 项目: Aegisub/SSATool
        private void LoadEffectsFile(string filename)
        {
            if (File.Exists(filename)) {
                try {
                    XmlDocument xDocM = new XmlDocument();
                    xDocM.Load(filename);
                    XmlNode xDoc = xDocM.SelectSingleNode("ESSA");

                    XmlNodeList effects = xDoc.SelectNodes("Effect");
                    Filter thisFilter;
                    int index = 0;

                    foreach (XmlNode enode in effects) {
                        if (enode.Attributes["Name"] == null) {
                            MessageBox.Show("Encountered unnamed effect. Skipping.");
                            continue;
                        }

                        thisFilter = new Filter(enode.Attributes["Name"].Value);

                        if (enode.Attributes["Code"] != null)
                            thisFilter.Code = enode.Attributes["Code"].Value;

                        //add default options
                        XmlNodeList options = enode.SelectNodes("Option");
                        foreach (XmlNode onode in options) {
                            if (onode.Attributes["Name"] == null) continue;
                            thisFilter.AddOption(onode.Attributes["Name"].Value, onode.InnerText);
                        }

                        //add default conditions
                        XmlNodeList econditions = enode.SelectNodes("Condition");
                        foreach (XmlNode ecnode in econditions) {
                            if ((ecnode.Attributes["ConditionOne"] == null) || (ecnode.Attributes["ConditionTwo"] == null) ||
                                (ecnode.Attributes["ConditionOperation"] == null)) { continue; }
                            Condition thisCondition = new Condition();
                            thisCondition.ConditionOne = ecnode.Attributes["ConditionOne"].Value;
                            thisCondition.ConditionTwo = ecnode.Attributes["ConditionTwo"].Value;
                            thisCondition.ConditionOp = ecnode.Attributes["ConditionOperation"].Value;
                            thisCondition.ConditionEnabled = (ecnode.Attributes["Enabled"] != null) ?
                                (String.Equals(ecnode.Attributes["Enabled"].Value, "true", StringComparison.OrdinalIgnoreCase)) : true;
                            thisFilter.AddCondition(thisCondition);
                        }

                        templateFilterColl.Add(thisFilter);
                        menuItem15.MenuItems.Add(thisFilter.ToString(), new EventHandler(this.menuFilter_Click));
                        index+=1;
                    }
                    //templateFilterColl.Sort();
                    EventContext();
                } catch (XmlException xmle) {
                    MessageBox.Show(xmle.Message);
                } catch (Exception e) {
                    MessageBox.Show(e.Message);
                }
            }
        }