private void ValidateRanges(BLECommandSetDataModel data, Action onSuccess, OnErr onError)
        {
            ErrReport report;

            WrapErr.ToErrReport(out report, 9999, () => {
                string error = string.Empty;
                foreach (ScriptItem item in data.Items)
                {
                    this.ValidateBLECmdItem(data.DataType, item, () => { }, (err) => {
                        if (error == string.Empty)
                        {
                            error = err;
                        }
                    });
                }
                if (error == string.Empty)
                {
                    onSuccess();
                }
                else
                {
                    onError(error);
                }
            });
            if (report.Code != 0)
            {
                WrapErr.SafeAction(() => onError(report.Msg));
            }
        }
        public void T004_EditSave02_OutOfRange()
        {
            TestHelpers.CatchUnexpected(() => {
                // Create list of 3 and validate
                this.SetupData();
                List <IIndexItem <BLECmdIndexExtraInfo> > index = this.GetCommandList(4);
                IIndexItem <BLECmdIndexExtraInfo> item          = index[1];

                BLECommandSetDataModel dataModel = null;
                string error = string.Empty;
                TDI.Wrapper.RetrieveBLECmdSet(item,
                                              (dm) => { dataModel = dm; },
                                              (err) => { error = err; });

                Assert.AreEqual(string.Empty, error);
                Assert.NotNull(dataModel, "Data model");
                // Validate existing before edit
                Assert.AreEqual("6195", dataModel.CharacteristicName);
                Assert.AreEqual(BLE_DataType.UInt_8bit, dataModel.DataType);
                Assert.AreEqual(3, dataModel.Items.Count);
                Assert.AreEqual("Close door", dataModel.Items[0].Display);
                Assert.AreEqual("0", dataModel.Items[0].Command);

                // Change value to force out of range for 8 bit
                dataModel.Items[0].Command = "10000";
                error = string.Empty;
                TDI.Wrapper.SaveBLECmdSet(item, dataModel, () => { }, (err) => { error = err; });
                Assert.AreEqual("Invalid Input", error, "After save");
            });
        }
        private BLECommandSetDataModel RetrieveOriginal()
        {
            BLECommandSetDataModel tmp = null;

            DI.Wrapper.RetrieveBLECmdSet(this.index, dm => { tmp = dm; }, this.onFailure);
            return(tmp);
        }
 private void OnCmdListChanged(BLECommandSetDataModel dm)
 {
     if (dm != null)
     {
         this.lb_BLECmds.ItemsSource = dm.Items;
     }
 }
        public void CreateBLECmds(string display, BLE_DataType dataType, List <ScriptItem> items, Action onSuccess, OnErr onError)
        {
            ErrReport report;

            WrapErr.ToErrReport(out report, 9999, "Failure on CreateBLEBoolDemoCmds", () => {
                BLECommandSetDataModel dm = new BLECommandSetDataModel(items, "", dataType, display);
                this.CreateBLECmdSet(
                    dm.Display, dm, new BLECmdIndexExtraInfo(dm), idx => onSuccess(), onError);
            });
        }
 private void Init()
 {
     this.original = this.useType == UseType.Edit
         ? this.RetrieveOriginal()
         : this.CreateNewOriginal();
     this.copy = this.MakeWorkingCopy(this.original);
     if (this.copy != null)
     {
         this.txtName.Text        = this.copy.Display;
         this.lbxCmds.ItemsSource = copy.Items;
         this.lbDataType.Content  = string.Format("{0} : {1}",
                                                  DI.Wrapper.GetText(MsgCode.DataType), this.copy.DataType.ToStr());
     }
 }
        private IIndexItem <BLECmdIndexExtraInfo> CreateItem(List <ScriptItem> items, string characteristicName, BLE_DataType dataType, string display, string errExpected)
        {
            IIndexItem <BLECmdIndexExtraInfo> index = null;
            string error = string.Empty;
            BLECommandSetDataModel dm = new BLECommandSetDataModel(
                items, characteristicName, dataType, display);

            TDI.Wrapper.CreateBLECmdSet(dm.Display, dm, new BLECmdIndexExtraInfo(dm), (ndx) => {
                index = ndx;
            },
                                        (err) => {
                error = err;
            });
            Assert.AreEqual(errExpected, error);
            //Assert.NotNull(index, "Did not return index");
            return(index);
        }
 private BLECommandSetDataModel MakeWorkingCopy(BLECommandSetDataModel source)
 {
     if (source != null)
     {
         var target = new BLECommandSetDataModel()
         {
             DataType           = source.DataType,
             Display            = source.Display,
             CharacteristicName = source.CharacteristicName,
             UId = source.UId,
         };
         foreach (var item in original.Items)
         {
             target.Items.Add(new ScriptItem(item.Display, item.Command));
         }
         return(target);
     }
     return(null);
 }
示例#9
0
 public void Update(BLECommandSetDataModel dm)
 {
     this.CharacteristicName = dm.CharacteristicName;
     this.DataTypeDisplay    = dm.DataType.ToStr();
     this.DataType           = dm.DataType;
 }
示例#10
0
 public BLECmdIndexExtraInfo(BLECommandSetDataModel dm)
 {
     this.Update(dm);
 }
        public void T004_EditSave01_Success()
        {
            TestHelpers.CatchUnexpected(() => {
                // Create list of 4 and validate
                this.SetupData();
                List <IIndexItem <BLECmdIndexExtraInfo> > index = this.GetCommandList(4);
                IIndexItem <BLECmdIndexExtraInfo> item          = index[1];

                BLECommandSetDataModel dataModel = null;
                string error = string.Empty;
                TDI.Wrapper.RetrieveBLECmdSet(item,
                                              (dm) => { dataModel = dm; },
                                              (err) => { error = err; });

                Assert.AreEqual(string.Empty, error);
                Assert.NotNull(dataModel, "Data model");
                // Validate existing before edit
                Assert.AreEqual("6195", dataModel.CharacteristicName);
                Assert.AreEqual(BLE_DataType.UInt_8bit, dataModel.DataType);
                Assert.AreEqual("Demo uint 8 bit", dataModel.Display);
                Assert.AreEqual(3, dataModel.Items.Count, "Command item count in data model");
                Assert.AreEqual("Close door", dataModel.Items[0].Display);
                Assert.AreEqual("0", dataModel.Items[0].Command);

                // Change values
                dataModel.CharacteristicName = "9999";
                dataModel.DataType           = BLE_DataType.UInt_64bit;
                dataModel.Display            = "Demo uint 64 bit";
                dataModel.Items[0].Command   = "10000";

                error = string.Empty;
                TDI.Wrapper.SaveBLECmdSet(item, dataModel, () => { }, (err) => { error = err; });
                Assert.AreEqual(string.Empty, error, "After save");


                // TODO index extra info not being updated. The actual object file is OK
                // need to retrieve the proper one. Not in previous order
                index = this.GetCommandList(4);
                // Iterate to find the correct data model
                item = null;
                for (int i = 0; i < index.Count; i++)
                {
                    if (index[i].ExtraInfoObj.CharacteristicName == "9999")
                    {
                        item = index[i];
                        break;
                    }
                }
                Assert.NotNull(item, "Retrieve after save - index for 9999 not found");
                dataModel = null;
                error     = string.Empty;
                TDI.Wrapper.RetrieveBLECmdSet(item,
                                              (dm) => { dataModel = dm; },
                                              (err) => { error = err; });

                Assert.AreEqual(string.Empty, error, "Retrieve after save");
                Assert.NotNull(dataModel, "Data model");
                Assert.AreEqual("9999", dataModel.CharacteristicName, "Retrieve after edit");
                Assert.AreEqual(BLE_DataType.UInt_64bit, dataModel.DataType, "Retrieve after edit");
                Assert.AreEqual("Demo uint 64 bit", dataModel.Display, "Retrieve after edit");
                Assert.AreEqual(3, dataModel.Items.Count, "Retrieve after edit");
                Assert.AreEqual("Close door", dataModel.Items[0].Display, "Retrieve after edit");
                Assert.AreEqual("10000", dataModel.Items[0].Command, "Retrieve after edit");
            });
        }
 public void SaveBLECmdSet(IIndexItem <BLECmdIndexExtraInfo> idx, BLECommandSetDataModel data, Action onSuccess, OnErr onError)
 {
     this.ValidateRanges(data,
                         () => this.Save(this.bleCmdStorage, idx, data, (dm, index) => index.ExtraInfoObj.Update(dm), onSuccess, onError), onError);
 }
 public void CreateBLECmdSet(string display, BLECommandSetDataModel data, BLECmdIndexExtraInfo extraInfo, Action <IIndexItem <BLECmdIndexExtraInfo> > onSuccess, OnErr onError)
 {
     this.ValidateRanges(data, () => this.Create(display, data, this.bleCmdStorage, onSuccess, onError, extraInfo), onError);
 }
 public void CreateBLECmdSet(BLECommandSetDataModel data, Action <IIndexItem <BLECmdIndexExtraInfo> > onSuccess, OnErr onError)
 {
     this.ValidateRanges(data, () => this.Create(
                             data.Display, data, this.bleCmdStorage, onSuccess, onError, new BLECmdIndexExtraInfo(data)), onError);
 }