예제 #1
0
 internal static void ReadFilterObjectsConfig(string nodeName, Dictionary <string, FilterObject> filterObjects)
 {
     try
     {
         string      configFile  = string.Format(FilterEngine.GetApplicationPath() + @"Configurations\FilterEngine.config");
         XmlDocument xmlDocument = new XmlDocument();
         xmlDocument.Load(configFile);
         XmlNodeList filterObjectNodes = xmlDocument.SelectNodes("//filterEngine/" + nodeName + "/object");
         foreach (XmlNode filterObjectNode in filterObjectNodes)
         {
             if (filterObjectNode.Attributes["type"] != null)
             {
                 FilterObject filterObject = new FilterObject(filterObjectNode.Attributes["type"].Value);
                 if (filterObjectNode.Attributes["objectTypeId"] != null)
                 {
                     filterObject.ObjectTypeId = int.Parse(filterObjectNode.Attributes["objectTypeId"].Value);
                 }
                 XmlNodeList filterObjectProperties = filterObjectNode.SelectNodes("property");
                 foreach (XmlNode filterObjectProperty in filterObjectProperties)
                 {
                     if (filterObjectProperty.Attributes["name"] != null)
                     {
                         string propertyCopyToName = "";
                         if (filterObjectProperty.Attributes["linkedName"] != null)
                         {
                             propertyCopyToName = filterObjectProperty.Attributes["linkedName"].Value;
                         }
                         filterObject.Properties.Add(new FilterObjectProperty(filterObjectProperty.Attributes["name"].Value, propertyCopyToName));
                     }
                 }
                 filterObjects.Add(filterObjectNode.Attributes["type"].Value, filterObject);
             }
         }
     }
     catch
     {
     }
 }
예제 #2
0
        private static bool FilterObjectProperties(Business.DataObject item, List <IWordFilter> wordFilters, Dictionary <string, FilterObject> wordFilterObjects)
        {
            bool         hasItemChanged   = false;
            Type         filterObjectType = item.GetType();
            FilterObject filterObject     = wordFilterObjects[item.GetType().ToString()];

            foreach (FilterObjectProperty filterObjectProperty in filterObject.Properties)
            {
                // Get value for filtering
                PropertyInfo filterObjectPropertyName = filterObjectType.GetProperty(filterObjectProperty.Name, typeof(string));
                string       propertyValue            = (string)filterObjectPropertyName.GetValue(item, null);

                // Apply the filters
                string processedPropertyValue = propertyValue;
                if (userWantsFiltering) // Don't apply filter, if the user disabled them
                {
                    foreach (IWordFilter wordFilter in wordFilters)
                    {
                        processedPropertyValue = wordFilter.Process(processedPropertyValue, item.GetType(), FilterObjectTypes.DataObject, item.ObjectID.Value, item.UserID.Value);
                    }
                }

                // If the filter had some matches, store filtered value
                if (processedPropertyValue != propertyValue && userWantsFiltering)
                // Don't store value, if the user disabled the filter
                {
                    hasItemChanged = true;
                    if (filterObjectProperty.LinkedName != "")
                    {
                        PropertyInfo filterObjectPropertyLinkedName = filterObjectType.GetProperty(filterObjectProperty.LinkedName, typeof(string));
                        filterObjectPropertyLinkedName.SetValue(item, processedPropertyValue, null);
                    }
                    else
                    {
                        filterObjectPropertyName.SetValue(item, processedPropertyValue, null);
                    }
                }
                else // If the filter didn't had any matches
                {
                    if (filterObjectProperty.LinkedName != "")
                    {
                        PropertyInfo filterObjectPropertyLinkedName = filterObjectType.GetProperty(filterObjectProperty.LinkedName, typeof(string));
                        string       propertyLinkedValue            = (string)filterObjectPropertyLinkedName.GetValue(item, null);

                        // If the linked property has been set before, clear it
                        if (propertyLinkedValue != processedPropertyValue)
                        {
                            hasItemChanged = true;
                            filterObjectPropertyLinkedName.SetValue(item, "", null);
                        }
                        else if (propertyLinkedValue != processedPropertyValue && !userWantsFiltering)
                        // Reset value, if the user disabled the filter
                        {
                            hasItemChanged = true;
                            filterObjectPropertyLinkedName.SetValue(item, "", null);
                        }
                    }
                }
            }
            return(hasItemChanged);
        }