Example #1
0
        public void DequeueTest()
        {
            dynamic record = DllFileLoader.CreateAnInstance();

            record.waterLevel = 12;
            record.PossibleCauseOfDisaster = new ObservableCollection <string>()
            {
                "123"
            };
            record.currentLongitude = "121.23";
            record.currentLatitude  = "23.5";
            record.currentTimeStamp = "2017/1/23";
            CancellationToken cancellationToken = new CancellationToken();

            WorkItem workItem
                = new WorkItem(FunctionGroupName.DataManagementFunction,
                               AsyncCallName.SaveRecord,
                               (Object)record,
                               null,
                               null);

            Utilities.PriorityWorkQueue <WorkItem> target = new Utilities.PriorityWorkQueue <WorkItem>((int)WorkPriority.NumberOfPriorities);
            int expected = (int)WorkPriority.Normal;

            target.Enqueue(workItem, expected, cancellationToken);
            WorkItem workItem2;
            int      actual = target.Dequeue(out workItem2);

            Assert.AreEqual(expected, actual);
        }
Example #2
0
        public void GetRecordFromBufferTest()
        {
            DiReCTCore target = new DiReCTCore();

            dynamic record1 = DllFileLoader.CreateAnInstance();

            record1.waterLevel = 12;
            record1.PossibleCauseOfDisaster = new ObservableCollection <string>()
            {
                "123"
            };
            record1.currentLongitude = "121.23";
            record1.currentLatitude  = "23.5";
            record1.currentTimeStamp = "2017/1/23";
            target.SaveRecordToBuffer(record1);

            dynamic record2 = DllFileLoader.CreateAnInstance();

            record2.waterLevel = 12;
            record2.PossibleCauseOfDisaster = new ObservableCollection <string>()
            {
                "123"
            };
            record2.currentLongitude = "123.23";
            record2.currentLatitude  = "23.5";
            record2.currentTimeStamp = "2017/1/23";
            target.SaveRecordToBuffer(record2);

            dynamic record;

            bool actual   = DiReCTCore.GetRecordFromBuffer(0, out record);
            bool expected = true;

            Assert.AreEqual(expected, actual);
            Assert.AreEqual(record1, record);

            actual = DiReCTCore.GetRecordFromBuffer(1, out record);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual(record2, record);

            actual = DiReCTCore.GetRecordFromBuffer(2, out record);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual(null, record);
            try
            {
                DiReCTCore.GetRecordFromBuffer(140, out record);
                Assert.Fail("An exception should have been thrown");
            }
            catch (ArgumentOutOfRangeException ae)
            {
                Assert.AreEqual("The index should be in the range of the size of the buffer.", ae.ParamName);
            }
            catch (Exception e)
            {
                Assert.Fail(string.Format("Unexpected exception of type {0} caught: {1}",
                                          e.GetType(), e.Message));
            }
        }
Example #3
0
        private void DoSaveRecord(object obj)
        {
            ObservableCollection <string> causes = new ObservableCollection <string>();

            for (int i = 0; i < availablePresentationObjects.Count(); i++)
            {
                if (availablePresentationObjects[i].IsChecked == true)
                {
                    availablePresentationObjects[i].IsChecked = false;
                    Debug.WriteLine(availablePresentationObjects[i].Name);
                    causes.Add(availablePresentationObjects[i].Name);
                }
            }

            //FloodRecord record = new FloodRecord();
            //record.Latitude = currentLatitude;
            //record.Longitude = currentLongitude;
            //record.Time = currentTimeStamp;
            //record.WaterLevel = _waterLevel.ToString();
            //record.causes = causes;
            if (_waterLevel.ToString() != "" && causes.Count() != 0)
            {
                _waterLevel = 230 / 2;
                RaisePropertyChanged("waterLevel");
            }
            othersIsChecked = false;
            others          = "";
            RaisePropertyChanged("AvailablePresentationObjects");
            RaisePropertyChanged("others");
            RaisePropertyChanged("othersIsChecked");
            MenuViewBase recordView = HomeScreenViewModel.GetInstance().ShowRecordView();
            //recordView.RaiseUserInputReadyEvent(new SaveButtonClickedEventArgs(record));

            // Initialize the record object
            dynamic record = DllFileLoader.CreateAnInstance();

            record.waterLevel = waterLevel;
            record.PossibleCauseOfDisaster = causes;
            record.currentLongitude        = currentLongitude;
            record.currentLatitude         = currentLatitude;
            record.currentTimeStamp        = currentTimeStamp;
            // Signal Core for record
            recordView.OnSavingFloodRecord(record);
        }
Example #4
0
        private void InitCoreDM()
        {
            // DM buffer initialization
            RecordBuffer         = new dynamic[Constant.BUFFER_NUMBER];
            bufferLock           = new object[Constant.BUFFER_NUMBER];
            bufferSpaceAvailable = new BitArray(Constant.BUFFER_NUMBER);
            for (int i = 0; i < Constant.BUFFER_NUMBER; i++)
            {
                bufferLock[i]           = new object();
                bufferSpaceAvailable[i] = true; // Set every space to available
            }

            // Dll variable initialization
            DllFileLoader = new DllFileLoader();

            // Subscribe to UI Saving Record Event
            MenuViewBase.UIRecordSavingTriggerd +=
                new MenuViewBase.SaveRecordEventHanlder(PassSaveRecordToCore);
        }
Example #5
0
        public void SaveRecordToBufferTest()
        {
            DiReCTCore target = new DiReCTCore();

            // Test1
            dynamic record = DllFileLoader.CreateAnInstance();

            record.waterLevel = 12;
            record.PossibleCauseOfDisaster = new ObservableCollection <string>()
            {
                "123"
            };
            record.currentLongitude = "121.23";
            record.currentLatitude  = "23.5";
            record.currentTimeStamp = "2017/1/23";
            int actual   = target.SaveRecordToBuffer(record);
            int expected = 0;

            Assert.AreEqual(expected, actual);

            // Test2
            dynamic record2 = null;

            try
            {
                target.SaveRecordToBuffer(record2);
                Assert.Fail("An exception should have been thrown");
            }
            catch (System.ArgumentNullException ae)
            {
                Assert.AreEqual("The record passed to SaveRecordToBuffer cannot be null.", ae.ParamName);
            }
            catch (Exception e)
            {
                Assert.Fail(string.Format("Unexpected exception of type {0} caught: {1}",
                                          e.GetType(), e.Message));
            }
        }
Example #6
0
        public void CoreSaveRecordTest()
        {
            // Initialize DiReCTCore first in order to initialize CoreWorkQueue as well
            DiReCTCore target = new DiReCTCore();

            dynamic record = DllFileLoader.CreateAnInstance();

            record.waterLevel = 12;
            record.PossibleCauseOfDisaster = new ObservableCollection <string>()
            {
                "123"
            };
            record.currentLongitude = "121.23";
            record.currentLatitude  = "23.5";
            record.currentTimeStamp = "2017/1/23";

            bool actual   = DiReCTCore.CoreSaveRecord(record, null, null);
            bool expected = true;

            Assert.AreEqual(expected, actual);

            try
            {
                DiReCTCore.CoreSaveRecord(null, null, null);
                Assert.Fail("An exception should have been thrown");
            }
            catch (ArgumentNullException ae)
            {
                Assert.AreEqual("The recordData passed to CoreSaveRecord cannot be null.", ae.ParamName);
            }
            catch (Exception e)
            {
                Assert.Fail(string.Format("Unexpected exception of type {0} caught: {1}",
                                          e.GetType(), e.Message));
            }
        }