Пример #1
0
 private void Pv3_ValidateEvent(object sender, ValidateEventArgs e)
 {
     // We didn't specify the flag that allows system properties to be updated, all value's should be different
     if (e.PropertyName.Equals("Value", StringComparison.InvariantCultureIgnoreCase))
     {
         if (!e.SourceValue.Equals(e.TargetValue))
         {
             e.IsEqual = true;
         }
     }
 }
        public virtual bool ValidateObjects <T>(T sourceElement, T targetElement, List <string> properties, TokenParser tokenParser = null, Dictionary <string, string[]> parsedProperties = null) where T : class
        {
            IEnumerable sElements = (IEnumerable)sourceElement;
            IEnumerable tElements = (IEnumerable)targetElement;

            string key         = properties[0];
            int    sourceCount = 0;
            int    targetCount = 0;

            foreach (object sElem in sElements)
            {
                sourceCount++;
                string sourceKey = sElem.GetType().GetProperty(key).GetValue(sElem).ToString();

                if (tokenParser != null && parsedProperties != null)
                {
                    if (parsedProperties.ContainsKey(key))
                    {
                        string[] parserExceptions;
                        parsedProperties.TryGetValue(key, out parserExceptions);
                        sourceKey = tokenParser.ParseString(Convert.ToString(sourceKey), parserExceptions);
                    }
                }

                foreach (object tElem in tElements)
                {
                    string targetKey = tElem.GetType().GetProperty(key).GetValue(tElem).ToString();

                    if (sourceKey.Equals(targetKey))
                    {
                        targetCount++;
                        //compare objects
                        foreach (string property in properties)
                        {
                            string sourceProperty = sElem.GetType().GetProperty(property).GetValue(sElem).ToString();
                            if (tokenParser != null && parsedProperties != null)
                            {
                                if (parsedProperties.ContainsKey(property))
                                {
                                    string[] parserExceptions;
                                    parsedProperties.TryGetValue(key, out parserExceptions);
                                    sourceProperty = tokenParser.ParseString(Convert.ToString(sourceProperty), parserExceptions);
                                }
                            }

                            string targetProperty = tElem.GetType().GetProperty(property).GetValue(tElem).ToString();

                            ValidateEventArgs e = null;
                            if (ValidateEvent != null)
                            {
                                e = new ValidateEventArgs(property, sourceProperty, targetProperty, sElem, tElem);
                                ValidateEvent(this, e);
                            }

                            if (e != null && e.IsEqual)
                            {
                                // Do nothing since we've declared equality in the event handler
                            }
                            else
                            {
                                if (!sourceProperty.Equals(targetProperty))
                                {
                                    return(false);
                                }
                            }
                        }
                        break;
                    }
                }
            }

            return(sourceCount == targetCount);
        }
Пример #3
0
 private void Pv2_ValidateEvent(object sender, ValidateEventArgs e)
 {
     // If "Overwrite" was set to false then we're not updating the property, hence we need to make an exception in our comparison logic
     if (e.PropertyName.Equals("Value", StringComparison.InvariantCultureIgnoreCase))
     {
         if ((e.SourceObject as PropertyBagEntry).Overwrite == false)
         {
             // if source and target value are the same then somehow this delta update overwrote which it shouldn't
             if (!e.SourceValue.Equals(e.TargetValue))
             {
                 e.IsEqual = true;
             }
         }
     }
 }