Esempio n. 1
0
        /// <summary>
        /// This method is used to set the DirtyStatus to NoChange to item and it's child items
        /// </summary>
        public void SetDirtyStatusToNoChange()
        {
            DirtyStatus = eDirtyStatus.NoChange;

            // Properties
            foreach (PropertyInfo PI in this.GetType().GetProperties())
            {
                var token = PI.GetCustomAttribute(typeof(IsSerializedForLocalRepositoryAttribute));
                if (token == null)
                {
                    continue;
                }

                if (typeof(IObservableList).IsAssignableFrom(PI.PropertyType))
                {
                    IObservableList obj = (IObservableList)PI.GetValue(this);
                    if (obj == null)
                    {
                        continue;
                    }
                    foreach (object o in obj)
                    {
                        if (o is RepositoryItemBase)
                        {
                            ((RepositoryItemBase)o).SetDirtyStatusToNoChange();
                        }
                    }
                }
            }

            // Fields
            foreach (FieldInfo FI in this.GetType().GetFields())
            {
                var token = FI.GetCustomAttribute(typeof(IsSerializedForLocalRepositoryAttribute));
                if (token == null)
                {
                    continue;
                }
                if (typeof(IObservableList).IsAssignableFrom(FI.FieldType))
                {
                    IObservableList obj = (IObservableList)FI.GetValue(this);
                    if (obj == null)
                    {
                        return;
                    }
                    foreach (object o in obj)
                    {
                        if (o is RepositoryItemBase)
                        {
                            ((RepositoryItemBase)o).SetDirtyStatusToNoChange();
                        }
                    }
                }
            }
        }
        public void CheckPropertyChangedTriggered()
        {
            // Scan all RIs for each prop marked with [IsSerializedForLocalRepositoryAttribute] try to change and verify prop changed triggered

            //Arrange

            // Get all Repository items
            IEnumerable <Type> list = GetRepoItems();

            ErrCounter = 0;

            //Act
            foreach (Type type in list)
            {
                Console.WriteLine("CheckPropertyChangedTriggered for type: " + type.FullName);
                if (type.IsAbstract)
                {
                    continue;
                }
                RepositoryItemBase RI = (RepositoryItemBase)Activator.CreateInstance(type);
                RI.PropertyChanged += RIPropertyChanged;
                RI.StartDirtyTracking();

                // Properties
                foreach (PropertyInfo PI in RI.GetType().GetProperties())
                {
                    var token = PI.GetCustomAttribute(typeof(IsSerializedForLocalRepositoryAttribute));
                    if (token == null)
                    {
                        continue;
                    }
                    Console.WriteLine("CheckPropertyChangedTriggered for property: " + PI.Name);
                    object newValue = GetNewValue(PI.PropertyType, PI.GetValue(RI));
                    if (newValue != null)
                    {
                        RI.DirtyStatus = eDirtyStatus.NoChange;
                        prop           = null;
                        PI.SetValue(RI, newValue);
                        CheckChanges(RI, PI.Name, newValue);
                    }
                }


                // Fields
                foreach (FieldInfo FI in RI.GetType().GetFields())
                {
                    var token = FI.GetCustomAttribute(typeof(IsSerializedForLocalRepositoryAttribute));
                    if (token == null)
                    {
                        continue;
                    }
                    Console.WriteLine("CheckPropertyChangedTriggered for property: " + FI.Name);
                    object newValue = GetNewValue(FI.FieldType, FI.GetValue(RI));
                    if (newValue != null)
                    {
                        RI.DirtyStatus = eDirtyStatus.NoChange;
                        prop           = null;
                        FI.SetValue(RI, newValue);
                        CheckChanges(RI, FI.Name, newValue);
                    }
                }
            }
            //Assert
            Assert.AreEqual(0, ErrCounter);
        }
        //[Ignore]
        //[TestMethod]  [Timeout(60000)]
        //public void NewRepositorySerializer_ReadOldXML()
        //{
        //    // Using new SR2 to load and write old XML but load old object, save with the style


        //    //Arrange
        //    //GingerCore.Repository.RepositorySerializerInitilizer OldSR = new GingerCore.Repository.RepositorySerializerInitilizer();


        //    //GingerCore.Repository.RepositorySerializerInitilizer.InitClassTypesDictionary();
        //    NewRepositorySerializer RS2 = new NewRepositorySerializer();

        //    string fileName = Common.getGingerUnitTesterDocumentsFolder() + @"Repository\BigFlow1.Ginger.BusinessFlow.xml";

        //    //Act
        //    string txt = System.IO.File.ReadAllText(fileName);
        //    BusinessFlow BF = (BusinessFlow)NewRepositorySerializer.DeserializeFromText(txt);

        //    //load with new
        //    // BusinessFlow BF = (BusinessFlow)RS2.DeserializeFromFile(fileName);
        //    //Serialize to new style
        //    //string s = RS2.SerializeToString(BF);
        //    // cretae from new style SR2
        //    BusinessFlow BF2 = (BusinessFlow)RS2.DeserializeFromText(typeof(BusinessFlow), txt, filePath: fileName);

        //    //to test the compare change something in b like below
        //    // BF2.Activities[5].Description = "aaa";
        //    // BF2.Activities.Remove(BF2.Activities[10]);

        //    //Assert

        //    // System.IO.File.WriteAllText(@"c:\temp\BF1.xml", s);
        //   // Assert.AreEqual(78, BF.Activities.Count);
        //    //Assert.AreEqual(78, BF2.Activities.Count);

        //    CompareRepoItem(BF, BF2);
        //}

        private void CompareRepoItem(RepositoryItemBase a, RepositoryItemBase b)
        {
            var props = a.GetType().GetProperties();

            foreach (PropertyInfo PI in props)
            {
                var token = PI.GetCustomAttribute(typeof(IsSerializedForLocalRepositoryAttribute));
                if (token != null)
                {
                    Console.WriteLine("compare: " + a.ToString() + " " + PI.Name);

                    object aProp = PI.GetValue(a);
                    object bProp = b.GetType().GetProperty(PI.Name).GetValue(b);

                    if (aProp == null && bProp == null)
                    {
                        continue;
                    }


                    if (aProp.ToString() != bProp.ToString())
                    {
                        throw new Exception("Items no match tostring: " + a.ItemName + " attr: " + PI.Name + " a=" + aProp.ToString() + " b=" + bProp.ToString());
                    }

                    //if (aProp != bProp)
                    //{
                    //    throw new Exception("Items no match: " + a.ItemName + " attr: " + PI.Name + " a=" + aProp.ToString() + " b=" + bProp.ToString());
                    //}
                }
            }

            var fields = a.GetType().GetFields();

            foreach (FieldInfo FI in fields)
            {
                var token = FI.GetCustomAttribute(typeof(IsSerializedForLocalRepositoryAttribute));
                if (token != null)
                {
                    Console.WriteLine("compare: " + a.ToString() + " " + FI.Name);

                    object aFiled = FI.GetValue(a);
                    object bField = b.GetType().GetField(FI.Name).GetValue(b);

                    if (aFiled == null && bField == null)
                    {
                        continue;
                    }

                    if (aFiled.ToString() != bField.ToString())
                    {
                        throw new Exception("Items no match tostring: " + a.ItemName + " attr: " + FI.Name + " a=" + aFiled.ToString() + " b=" + bField.ToString());
                    }

                    //if (aFiled != bField)
                    //{
                    //    throw new Exception("Items no match: " + a.ItemName + " attr: " + FI.Name + " a=" + aFiled.ToString() + " b=" + bField.ToString());
                    //}

                    if (aFiled is IObservableList)
                    {
                        if (((IObservableList)aFiled).Count != ((IObservableList)bField).Count)
                        {
                            throw new Exception("Items in list count do not match: " + a.ItemName + " attr: " + FI.Name + " a=" + aFiled.ToString() + " b=" + bField.ToString());
                        }
                        var aList = ((IObservableList)aFiled).GetEnumerator();
                        var bList = ((IObservableList)bField).GetEnumerator();



                        while (aList.MoveNext())
                        {
                            bList.MoveNext();
                            RepositoryItemBase o1 = (RepositoryItemBase)aList.Current;
                            RepositoryItemBase o2 = (RepositoryItemBase)bList.Current;
                            CompareRepoItem(o1, o2);
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        public void StartDirtyTracking()
        {
            if (DirtyStatus != eDirtyStatus.NoTracked)
            {
                // Nothing to do
                return;
            }

            DirtyTrackingFields = new List <string>();
            DirtyStatus         = eDirtyStatus.NoChange;
            //first track self item changes
            PropertyChanged += ItmePropertyChanged;

            // now track all children which are marked with isSerizalized...
            // throw err if item is serialized but dindn't impl IsDirty

            // Properties
            foreach (PropertyInfo PI in this.GetType().GetProperties())
            {
                var token = PI.GetCustomAttribute(typeof(IsSerializedForLocalRepositoryAttribute));
                if (token == null)
                {
                    continue;
                }

                DirtyTrackingFields.Add(PI.Name);

                // We track observable list which are seriazlized - drill down recursivley in obj tree
                if (typeof(IObservableList).IsAssignableFrom(PI.PropertyType))
                {
                    IObservableList obj = (IObservableList)PI.GetValue(this);
                    if (obj == null)
                    {
                        return;
                    }
                    TrackObservableList((IObservableList)obj);
                }
            }

            // Fields
            foreach (FieldInfo FI in this.GetType().GetFields())
            {
                var token = FI.GetCustomAttribute(typeof(IsSerializedForLocalRepositoryAttribute));
                if (token == null)
                {
                    continue;
                }

                DirtyTrackingFields.Add(FI.Name);

                // We track observable list which are seriazlized - drill down recursivley in obj tree
                if (typeof(IObservableList).IsAssignableFrom(FI.FieldType))
                {
                    IObservableList obj = (IObservableList)FI.GetValue(this);
                    if (obj == null)
                    {
                        return;
                    }
                    TrackObservableList((IObservableList)obj);
                }
            }
        }
Esempio n. 5
0
        public void StartDirtyTracking()
        {
            if (DirtyStatus != eDirtyStatus.NoTracked)
            {
                // Nothing to do
                return;
            }

            DirtyTrackingFields = new ConcurrentBag <string>();
            DirtyStatus         = eDirtyStatus.NoChange;
            //first track self item changes
            PropertyChanged += ItmePropertyChanged;

            // now track all children which are marked with isSerizalized...
            // throw err if item is serialized but dindn't impl IsDirty

            // Properties
            Parallel.ForEach(this.GetType().GetProperties(), PI =>
            {
                var token = PI.GetCustomAttribute(typeof(IsSerializedForLocalRepositoryAttribute));
                if (token == null)
                {
                    return;
                }

                DirtyTrackingFields.Add(PI.Name);

                // We track observable list which are seriazlized - drill down recursivley in obj tree
                if (typeof(IObservableList).IsAssignableFrom(PI.PropertyType))
                {
                    //skip list if it is LazyLoad and was not loaded yet
                    var lazyLoadtoken = PI.GetCustomAttribute(typeof(IsLazyLoadAttribute));
                    if (lazyLoadtoken != null)
                    {
                        string lazyStatusProp = PI.Name + nameof(IObservableList.LazyLoad);
                        if (this.GetType().GetProperty(lazyStatusProp) != null)
                        {
                            if (bool.Parse(this.GetType().GetProperty(PI.Name + nameof(IObservableList.LazyLoad)).GetValue(this).ToString()) == true)
                            {
                                return;//skip doing dirty tracking for observableList which is LazyLoad and not loaded yet
                            }
                        }
                        else
                        {
                            Reporter.ToLog(eLogLevel.ERROR, string.Format("Failed to check if to start DirtyTracking for Lazy Load ObservabelList called '{0}' because the property '{1}' is missing", PI.Name, lazyStatusProp));
                        }
                    }

                    IObservableList obj = (IObservableList)PI.GetValue(this);
                    if (obj == null)
                    {
                        return;
                    }
                    TrackObservableList((IObservableList)obj);
                }
            });

            // Fields
            Parallel.ForEach(this.GetType().GetFields(), FI =>
            {
                var token = FI.GetCustomAttribute(typeof(IsSerializedForLocalRepositoryAttribute));
                if (token == null)
                {
                    return;
                }

                DirtyTrackingFields.Add(FI.Name);

                // We track observable list which are seriazlized - drill down recursivley in obj tree
                if (typeof(IObservableList).IsAssignableFrom(FI.FieldType))
                {
                    IObservableList obj = (IObservableList)FI.GetValue(this);
                    if (obj == null)
                    {
                        return;
                    }
                    TrackObservableList((IObservableList)obj);
                }
            });
        }