public void Undo_Template_SubScope_Points()
        {
            //Arrange
            var Template = ModelCreation.TestTemplates(rand);
            var subScope = Template.Templates.SubScopeTemplates[0];
            ObservableCollection <TECPoint> expected = new ObservableCollection <TECPoint>();

            foreach (TECPoint item in subScope.Points)
            {
                expected.Add(item);
            }
            TECPoint edit = new TECPoint();

            edit.Type = IOType.AI;

            //Act
            ChangeWatcher watcher = new ChangeWatcher(Template); DoStacker testStack = new DoStacker(watcher);

            subScope.Points.Add(edit);
            Assert.AreEqual(1, testStack.UndoCount(), "Not added to undo stack");
            testStack.Undo();

            //assert
            var actual = subScope.Points;

            Assert.AreEqual(expected.Count, actual.Count, "Not Undone");
        }
예제 #2
0
 public TECEstimator(TECBid Bid, ChangeWatcher watcher) : this(Bid, Bid.Parameters, Bid.ExtraLabor, Bid.Duration, watcher)
 {
     Bid.PropertyChanged += (sender, e) =>
     {
         if (e.PropertyName == "Duration")
         {
             this.duration = (sender as TECBid).Duration;
             raiseAll();
         }
         else if (e.PropertyName == "Parameters")
         {
             parameters.PropertyChanged -= memberObjectChanged;
             this.parameters             = Bid.Parameters;
             raiseAll();
             parameters.PropertyChanged += memberObjectChanged;
         }
         else if (e.PropertyName == "ExtraLabor")
         {
             extraLabor.PropertyChanged -= memberObjectChanged;
             this.extraLabor             = Bid.ExtraLabor;
             raiseAll();
             extraLabor.PropertyChanged += memberObjectChanged;
         }
     };
 }
        public void Undo_Template_System_Equipment()
        {
            //Arrange
            var Template = ModelCreation.TestTemplates(rand);
            var system   = Template.Templates.SystemTemplates[0];
            ObservableCollection <TECEquipment> expected = new ObservableCollection <TECEquipment>();

            foreach (TECEquipment item in system.Equipment)
            {
                expected.Add(item);
            }
            TECEquipment edit = new TECEquipment();

            //Act
            ChangeWatcher watcher = new ChangeWatcher(Template); DoStacker testStack = new DoStacker(watcher);

            system.Equipment.Add(edit);
            Assert.AreEqual(1, testStack.UndoCount(), "Not added to undo stack");
            testStack.Undo();

            //assert
            var actual = system.Equipment;

            Assert.AreEqual(expected.Count, actual.Count, "Not Undone");
        }
예제 #4
0
 public SystemSummaryVM(TECBid bid, ChangeWatcher watcher)
 {
     this.bid = bid;
     setupExtraLaborEstimate(bid);
     populateAll(bid);
     watcher.Changed += changed;
 }
예제 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="root"></param>
        /// <param name="watcher"></param>
        /// <param name="includeFilter">Predicate for "where" clause of direct children of root.</param>
        public ConnectionsVM(IRelatable root, ChangeWatcher watcher, TECCatalogs catalogs, IEnumerable <TECLocation> locations = null,
                             Func <ITECObject, bool> filterPredicate = null)
        {
            if (filterPredicate == null)
            {
                filterPredicate = item => true;
            }
            this.filterPredicate = filterPredicate;

            ConnectableFilter.basePredicate = connectable =>
            {
                if (!connectable.IsConnected() && connectable.AvailableProtocols.Count == 0)
                {
                    return(false);
                }
                if (connectable == SelectedController)
                {
                    return(false);
                }
                return(true);
            };

            this.InterlocksVM = new InterlocksVM(root, watcher, catalogs, filterPredicate);

            this.root      = root;
            this.Catalogs  = catalogs;
            this.Locations = locations != null ? new ObservableCollection <TECLocation>(locations) : new ObservableCollection <TECLocation>();
            if (this.Catalogs.ConduitTypes.Count > 0)
            {
                this.DefaultConduitType = this.Catalogs.ConduitTypes[0];
            }

            watcher.Changed += parentChanged;
            new DirectRelationshipChangedFilter(watcher).DirectRelationshipChanged += parentScopeChanged;

            this.rootConnectableGroup = new FilteredConnectablesGroup("root", this.ConnectableFilter);
            this.rootControllerGroup  = new FilteredConnectablesGroup("root", this.ControllerFilter);

            repopulateGroups(null, root, addConnectable);

            SelectProtocolCommand          = new RelayCommand(selectProtocolExecute, selectProtocolCanExecute);
            CancelProtocolSelectionCommand = new RelayCommand(cancelProtocolSelectionExecute);

            ConnectionDropHandler = new NetworkConnectionDropTarget(this);

            this.ControllerFilter.FilterChanged += () =>
            { if (SelectedControllerGroup?.PassesFilter == false)
              {
                  SelectedControllerGroup = null;
              }
            };
            this.ConnectableFilter.FilterChanged += () =>
            { if (SelectedConnectableGroup?.PassesFilter == false)
              {
                  SelectedConnectableGroup = null;
              }
            };

            DeleteCommand = new RelayCommand <IControllerConnection>(deleteConnectionExecute, canDeleteConnection);
        }
        public void Undo_Template_Equipment_SubScope()
        {
            //Arrange
            var Template  = ModelCreation.TestTemplates(rand);
            var equipment = Template.Templates.EquipmentTemplates[0];
            ObservableCollection <TECSubScope> expected = new ObservableCollection <TECSubScope>();

            foreach (TECSubScope item in equipment.SubScope)
            {
                expected.Add(item);
            }
            TECSubScope edit = new TECSubScope();

            //Act
            ChangeWatcher watcher = new ChangeWatcher(Template); DoStacker testStack = new DoStacker(watcher);

            equipment.SubScope.Add(edit);
            Assert.AreEqual(1, testStack.UndoCount(), "Not added to undo stack");
            testStack.Undo();

            //assert
            var actual = equipment.SubScope;

            Assert.AreEqual(expected.Count, actual.Count, "Not Undone");
        }
        public void Undo_Template_MiscCost()
        {
            //Arrange
            var Template = ModelCreation.TestTemplates(rand);
            ObservableCollection <TECMisc> expected = new ObservableCollection <TECMisc>();

            foreach (TECMisc item in Template.Templates.MiscCostTemplates)
            {
                expected.Add(item);
            }
            TECMisc edit = new TECMisc(CostType.TEC);

            //Act
            ChangeWatcher watcher = new ChangeWatcher(Template); DoStacker testStack = new DoStacker(watcher);
            int           beforeCount = testStack.UndoCount();

            Template.Templates.MiscCostTemplates.Add(edit);
            Assert.AreEqual((beforeCount + 1), testStack.UndoCount(), "Not added to undo stack");
            testStack.Undo();

            //assert
            var actual = Template.Templates.MiscCostTemplates;

            Assert.AreEqual(expected.Count, actual.Count, "Not Undone");
        }
        public void Redo_Template_SubScope_Device()
        {
            //Arrange
            var Template = ModelCreation.TestTemplates(rand);
            ObservableCollection <TECConnectionType> types = new ObservableCollection <TECConnectionType>();

            types.Add(Template.Catalogs.ConnectionTypes[0]);
            TECDevice edit = new TECDevice(types, new List <TECProtocol>(),
                                           Template.Catalogs.Manufacturers[0]);

            //Act
            ChangeWatcher watcher = new ChangeWatcher(Template); DoStacker testStack = new DoStacker(watcher);

            Template.Templates.SystemTemplates[0].Equipment[0].SubScope[0].Devices.Add(edit);
            var expected = new ObservableCollection <IEndDevice>();

            foreach (IEndDevice item in Template.Templates.SystemTemplates[0].Equipment[0].SubScope[0].Devices)
            {
                expected.Add(item);
            }
            testStack.Undo();
            testStack.Redo();

            //assert
            var actual = Template.Templates.SystemTemplates[0].Equipment[0].SubScope[0].Devices;

            Assert.AreEqual(expected.Count, actual.Count, "Not Redone");
        }
예제 #9
0
        public void DoAnything_EventMustBeFired()
        {
            var root = CreateRoot();
            var cw   = new ChangeWatcher(root);
            IConfigurationChangeInfo info = null;

            cw.ChangePushed += (o, e) =>
            {
                info = e;
            };
            root["a"] = "b";
            Assert.IsNotNull(info);
            EventArgs changeMgrArg = null;

            cw.ChangeMerged += (o, e) =>
            {
                changeMgrArg = e;
            };
            cw.Merge();
            Assert.IsNotNull(changeMgrArg);
            EventArgs changeClearedArg = null;

            cw.ChangeCleared += (o, e) =>
            {
                changeClearedArg = e;
            };
            cw.Clear();
            Assert.IsNotNull(changeClearedArg);
        }
        public void Redo_Template_SubScope_Points()
        {
            //Arrange
            var      Template = ModelCreation.TestTemplates(rand);
            TECPoint edit     = new TECPoint();

            edit.Type = IOType.AI;

            //Act
            ChangeWatcher watcher = new ChangeWatcher(Template); DoStacker testStack = new DoStacker(watcher);

            Template.Templates.SystemTemplates[0].Equipment[0].SubScope[0].Points.Add(edit);
            var expected = new ObservableCollection <TECPoint>();

            foreach (TECPoint item in Template.Templates.SystemTemplates[0].Equipment[0].SubScope[0].Points)
            {
                expected.Add(item);
            }
            testStack.Undo();
            testStack.Redo();

            //assert
            var actual = Template.Templates.SystemTemplates[0].Equipment[0].SubScope[0].Points;

            Assert.AreEqual(expected.Count, actual.Count, "Not Redone");
        }
        public void Redo_Template_Panel()
        {
            //Arrange
            var Template = ModelCreation.TestTemplates(rand);
            ObservableCollection <TECPanel> expected = new ObservableCollection <TECPanel>();

            foreach (TECPanel item in Template.Templates.PanelTemplates)
            {
                expected.Add(item);
            }
            TECPanel edit = new TECPanel(Template.Catalogs.PanelTypes[0]);

            //Act
            ChangeWatcher watcher = new ChangeWatcher(Template); DoStacker testStack = new DoStacker(watcher);
            int           beforeCount = testStack.UndoCount();

            Template.Templates.PanelTemplates.Add(edit);
            Assert.AreEqual((beforeCount + 1), testStack.UndoCount(), "Not added to undo stack");
            testStack.Undo();
            testStack.Redo();

            //assert
            var actual = Template.Templates.PanelTemplates;

            Assert.AreEqual(expected.Count + 1, actual.Count, "Not Redone");
        }
예제 #12
0
        public void SaveAs_Bid_Estimate()
        {
            TECBid       saveBid           = ModelCreation.TestBid(rand);
            var          watcher           = new ChangeWatcher(saveBid);
            TECEstimator estimate          = new TECEstimator(saveBid, watcher);
            var          expectedTotalCost = estimate.TotalCost;
            double       delta             = 0.0001;

            Dictionary <Guid, INotifyCostChanged> saveCostDictionary = new Dictionary <Guid, INotifyCostChanged>();

            addToCost(saveCostDictionary, saveBid, saveBid);

            //Act
            path = Path.GetTempFileName();
            DatabaseManager <TECBid> manager = new DatabaseManager <TECBid>(path);

            manager.New(saveBid);
            TECBid       loadedBid      = manager.Load() as TECBid;
            var          loadedWatcher  = new ChangeWatcher(loadedBid);
            TECEstimator loadedEstimate = new TECEstimator(loadedBid, loadedWatcher);

            Dictionary <Guid, INotifyCostChanged> loadCostDictionary = new Dictionary <Guid, INotifyCostChanged>();

            addToCost(loadCostDictionary, loadedBid, loadedBid);

            compareCosts(saveCostDictionary, loadCostDictionary);
            compareEstimators(estimate, loadedEstimate);
            Assert.AreEqual(expectedTotalCost, loadedEstimate.TotalCost, delta);
        }
예제 #13
0
        protected override void handleLoaded(TECBid loadedBid)
        {
            if (loadedBid != null)
            {
                bid        = loadedBid;
                watcher    = new ChangeWatcher(bid);
                doStack    = new DoStacker(watcher);
                deltaStack = new DeltaStacker(watcher, bid);

                if (databaseManager == null && currentTemplatesPath != "")
                {
                    DatabaseManager <TECTemplates> templatesDatabaseManager = new DatabaseManager <TECTemplates>(currentTemplatesPath);
                    templatesDatabaseManager.LoadComplete += handleLoadedTemplates;
                    ViewEnabled = false;
                    templatesDatabaseManager.AsyncLoad();
                }
                else
                {
                    estimate    = new TECEstimator(bid, watcher);
                    EditorVM    = new EstimateEditorVM(bid, watcher, estimate);
                    CurrentVM   = EditorVM;
                    ViewEnabled = true;
                }
            }
            else
            {
                this.splashVM.LoadingText = "";
                ViewEnabled = true;
            }
        }
예제 #14
0
        public void RemoveValve()
        {
            //Arrange
            bid.Catalogs.Add(ModelCreation.TestValve(bid.Catalogs, rand));
            ChangeWatcher cw = new ChangeWatcher(bid);

            TECTypical typical = new TECTypical();

            bid.Systems.Add(typical);

            TECEquipment typEquip = new TECEquipment();

            typical.Equipment.Add(typEquip);

            TECSubScope typSS = new TECSubScope();

            typEquip.SubScope.Add(typSS);

            TECValve valve = bid.Catalogs.Valves[0];

            valve.AssignRandomScopeProperties(bid.Catalogs, rand);
            typSS.Devices.Add(valve);

            typical.AddInstance();

            MaterialSummaryVM matVM = new MaterialSummaryVM(bid, cw);

            CostBatch initial = MatVMToCostBatch(matVM);

            //Act
            typSS.Devices.Remove(valve);

            //Assert
            AssertMaterialVMMatchesCostBatch(matVM, initial - valve.CostBatch);
        }
예제 #15
0
 public ScheduleVM(TECBid bid, ChangeWatcher watcher)
 {
     this.Schedule        = bid.Schedule;
     this.AddTableCommand = new RelayCommand(addTableExecute, canAddTable);
     watcher.Changed     += changed;
     this.ScopeCollection = populateScopeCollection(bid);
     this.Locations       = bid.Locations;
 }
예제 #16
0
        public void TestInitialize()
        {
            rand = new Random(0);
            TECCatalogs catalogs = ModelCreation.TestCatalogs(rand);

            bid          = new TECBid();
            bid.Catalogs = catalogs;
            cw           = new ChangeWatcher(bid);
        }
예제 #17
0
 public NetworkContext(NewFileModule module, NetworkModel model, MainStoragePath mainPath)
 {
     _fileModule = module;
     _mainPath = mainPath;
     _netModel = model;
     _mainFileIndex = new MainFileIndex(this);
     _changeWatcher = new ChangeWatcher(this);
     _dispatcher = new ChangeMaster(this);
 }
예제 #18
0
        public void AddChanged_ClearIt_MustClean()
        {
            var root = CreateRoot();
            var cw   = new ChangeWatcher(root);

            root["hello"] = "world";
            cw.Clear();
            Assert.AreEqual(0, cw.ChangeInfos.Count);
        }
        public BaseWatcherFilter(ChangeWatcher watcher)
        {
            watcher.Changed         += watcherChanged;
            watcher.CostChanged     += watcherCostChanged;
            watcher.PointChanged    += watcherPointChanged;
            watcher.PropertyChanged += watcherPropertyChanged;

            this.propertyExceptions = watcher.propertyExceptions;
        }
예제 #20
0
        public void AddChanged_MustStored()
        {
            var root = CreateRoot();
            var cw   = new ChangeWatcher(root);

            Assert.AreEqual(root, cw.Configuration);
            root["hello"] = "world";
            Assert.AreEqual(1, cw.ChangeInfos.Count);
        }
예제 #21
0
 public DeltaStacker(ChangeWatcher changeWatcher, TECScopeManager manager)
 {
     dbType = DBType.Bid;
     if (manager is TECTemplates)
     {
         dbType = DBType.Templates;
     }
     changeWatcher.Changed += handleChange;
     stack = new List <UpdateItem>();
 }
예제 #22
0
        public void DisposeIt_AddChange_MustDoNothing()
        {
            var root = CreateRoot();
            var cw   = new ChangeWatcher(root);

            Assert.AreEqual(root, cw.Configuration);
            cw.Dispose();
            root["hello"] = "world";
            Assert.AreEqual(0, cw.ChangeInfos.Count);
        }
예제 #23
0
        public void HidenConfigurationMustEqualPublicProperty()
        {
            var root = CreateRoot();
            var cw   = new ChangeWatcher(root);
            var a    = cw.Configuration;
            var b    = ((IChangeWatcher)cw).Configuration;

            var equal = a == b;

            Assert.IsTrue(equal);
        }
예제 #24
0
 public RiserVM(TECBid bid, ChangeWatcher watcher)
 {
     this.bid     = bid;
     this.watcher = new ScopeWatcherFilter(watcher);
     this.watcher.ScopeChanged += changed;
     populateBidLocations(bid);
     AddLocationCommand = new RelayCommand(addLocationExecute, canAddLocation);
     AddPatternCommand  = new RelayCommand(addPatternExecute, canAddPattern);
     PropertiesVM       = new PropertiesVM(bid.Catalogs, bid);
     DeleteCommand      = new RelayCommand <LocationContainer>(deleteLocationExecute, canDeleteLocation);
 }
예제 #25
0
        public void IgnoreSameTrue_AddChange_TwiceMustIgnored()
        {
            var root = CreateRoot();
            var cw   = new ChangeWatcher(root);

            cw.IgnoreSame = true;
            root["hello"] = "world";
            root["hello"] = "world";
            Assert.AreEqual("world", cw.ChangeInfos[0].New);
            Assert.AreEqual(1, cw.ChangeCount);
        }
예제 #26
0
        public void AddSameChanged_MustMerged()
        {
            var root = CreateRoot();
            var cw   = new ChangeWatcher(root);

            Assert.AreEqual(root, cw.Configuration);
            root["hello"] = "world";
            root["hello"] = "world1";
            Assert.AreEqual(1, cw.ChangeInfos.Count);
            Assert.AreEqual(1, cw.ChangeCount);
            Assert.AreEqual("world1", cw.ChangeInfos[0].New);
        }
        public void MyTestInitialize()
        {
            bid                     = new TECBid();
            manufacturer            = new TECManufacturer();
            manufacturer.Multiplier = 1;
            ChangeWatcher watcher = new ChangeWatcher(bid);

            costs = new CostBatch();
            watcher.CostChanged += (e) =>
            {
                costs += e;
            };
        }
예제 #28
0
        public Changes()
        {
            var builder = new SavableConfiurationBuilder();

            builder.AddJsonFile("appsettings.json", true, false);
            root          = builder.Build();
            changeWatcher = new ChangeWatcher(root);

            var msbuilder = new ConfigurationBuilder();

            msbuilder.AddJsonFile("appsettings.json", true, false);
            msroot = msbuilder.Build();
        }
예제 #29
0
        private static void StartWatching(CompilerOptions opt)
        {
            Console.WriteLine("watching:" + opt.Path);
            var watcher = new ChangeWatcher(opt.Path, opt,
                                            (path, options) =>
            {
                Console.WriteLine(DateTime.Now + ":" + path + " has changed.");
                CompileMany(new[] { path }, options);
                Console.WriteLine(DateTime.Now + ":" + path + " recompiled");
            });

            watcher.Start();
        }
예제 #30
0
        public void TestCase()
        {
            var fileWatch = new ChangeWatcher();
            var settings  = new WatchSettings {
                Pattern   = "*.cs",
                Path      = "../../",
                Recursive = false
            };

            fileWatch.Watch(settings, (changed) => {
                changed.ToList().ForEach(x => Console.WriteLine(x.FullPath));
            });
        }
예제 #31
0
        public QuotesVM(TECBid bid, ChangeWatcher watcher)
        {
            watcher.Changed  += bidChanged;
            NeedQuoteHardware = new ObservableCollection <TECHardware>(bid
                                                                       .GetAll <TECSubScope>()
                                                                       .SelectMany(ss => ss.Devices
                                                                                   .Where(x => x is TECHardware ware && ware.RequireQuote && ware.QuotedPrice == -1))
                                                                       .Distinct()
                                                                       .OfType <TECHardware>());
            QuotedHardware = new ObservableCollection <TECHardware>(bid.Catalogs.GetAll <TECHardware>().Where(x => x.QuotedPrice != -1).Distinct());
            QuotedHardware.CollectionChanged += quotedHardware_CollectionChanged;
            var dropHandler = new EmptyDropTarget();

            dropHandler.DragOverAction = info =>
            {
                DragDropHelpers.DragOver(info, (item, sourceType, targetType) =>
                {
                    var hardware = item as TECHardware;
                    return(hardware != null && hardware.QuotedPrice == -1);
                });
            };
            dropHandler.DropAction = info =>
            {
                DragDropHelpers.Drop(info, item =>
                {
                    var hardware         = item as TECHardware;
                    hardware.QuotedPrice = hardware.Cost;
                    return(hardware);
                });
            };
            QuoteDropHandler = dropHandler;
            CollectionsVM    = new ScopeCollectionsTabVM(bid);
            CollectionsVM.OmitCollections(new List <AllSearchableObjects>()
            {
                AllSearchableObjects.System,
                AllSearchableObjects.Equipment,
                AllSearchableObjects.SubScope,
                AllSearchableObjects.Controllers,
                AllSearchableObjects.Panels,
                AllSearchableObjects.MiscCosts,
                AllSearchableObjects.MiscWiring,
                AllSearchableObjects.Tags,
                AllSearchableObjects.AssociatedCosts,
                AllSearchableObjects.Wires,
                AllSearchableObjects.Conduits,
                AllSearchableObjects.Protocols
            });
        }