Beispiel #1
0
        public MetaContext(XmlDocument xml, ICacheFile cache, IIndexItem indexItem, Stream dataSource)
        {
            if (xml == null)
            {
                throw new ArgumentNullException(nameof(xml));
            }

            if (cache == null)
            {
                throw new ArgumentNullException(nameof(cache));
            }

            if (indexItem == null)
            {
                throw new ArgumentNullException(nameof(indexItem));
            }

            if (dataSource == null)
            {
                throw new ArgumentNullException(nameof(dataSource));
            }

            Document   = xml;
            Cache      = cache;
            IndexItem  = indexItem;
            DataSource = dataSource;
        }
Beispiel #2
0
        public InMemoryMetadataStream(IIndexItem item, XmlDocument doc)
        {
            var gen3Cache = item.CacheFile as IGen3CacheFile;

            if (gen3Cache == null)
            {
                throw new ArgumentException("Cache must implement IGen3CacheFile.");
            }

            segmenter = new CacheSegmenter(gen3Cache);

            SourceItem = item;
            AllBlocks  = new List <InMemoryBlockCollection>();

            using (var reader = item.CacheFile.CreateReader(item.CacheFile.DefaultAddressTranslator))
            {
                var expander = (item.CacheFile as IMccCacheFile)?.PointerExpander;
                if (expander != null)
                {
                    reader.RegisterInstance(expander);
                }

                reader.Seek(item.MetaPointer.Address, SeekOrigin.Begin);
                RootBlock = ReadBlocks(reader, doc.DocumentElement, null, 0);
            }

            currentBlock = AllBlocks.FirstOrDefault(b => b.ContainsVirtualAddress(position));

            isInitialised = true;
        }
Beispiel #3
0
        public MetaContext(XmlDocument xml, ICacheFile cache, IIndexItem indexItem)
        {
            if (xml == null)
            {
                throw new ArgumentNullException(nameof(xml));
            }

            if (cache == null)
            {
                throw new ArgumentNullException(nameof(cache));
            }

            if (indexItem == null)
            {
                throw new ArgumentNullException(nameof(indexItem));
            }

            Document  = xml;
            Cache     = cache;
            IndexItem = indexItem;

            var fs = new FileStream(cache.FileName, FileMode.Open, FileAccess.Read);

            DataSource = new TransactionStream(fs);
        }
Beispiel #4
0
        private void btnDelete_Clicked(object sender, EventArgs e)
        {
            this.log.InfoEntry("btnDelete_Clicked");
            IIndexItem <DefaultFileExtraInfo> item = this.lstTerminators.SelectedItem as IIndexItem <DefaultFileExtraInfo>;

            App.Wrapper.DeleteTerminatorData(item, this.ReloadList, (err) => App.ShowError(this, err));
        }
 public void T02_CreateNewWithIndex()
 {
     TestHelpers.CatchUnexpected(() => {
         try {
             this.SubscribeToChange();
             EthernetParams data = new EthernetParams()
             {
                 Display             = "Extra param",
                 EthernetAddress     = "192.168.1.33",
                 EthernetServiceName = "10000",
             };
             IIndexItem <EthernetExtraInfo> idx = null;
             TDI.Wrapper.CreateNewEthernetData(data,
                                               (x) => {
                 idx = x;
             }, AssertErr);
             Assert.NotNull(idx, "Bad index item");
             this.AssertIndexChangeFired();
             this.SetupData(3);
             EthernetParams retrieved = this.RetrieveData(idx);
             Assert.NotNull(retrieved, "Bad retrieved params");
             Assert.AreEqual(data.UId, retrieved.UId);
             Assert.AreEqual(data.Display, retrieved.Display, "retrieved");
             Assert.AreEqual(data.EthernetAddress, retrieved.EthernetAddress, "retrieved");
             Assert.AreEqual(data.EthernetServiceName, retrieved.EthernetServiceName, "retrieved");
             Assert.AreEqual(data.Display, idx.Display, "idx");
             Assert.AreEqual(data.EthernetAddress, idx.ExtraInfoObj.Address, "idx");
             Assert.AreEqual(data.EthernetServiceName, idx.ExtraInfoObj.Port, "idx");
         }
         finally {
             this.UnsubscribeToChange();
         }
     });
 }
        public static ModelConfig FromIndexItem(IIndexItem item)
        {
            ModelConfig result;

            switch (item.CacheFile.CacheType)
            {
            case CacheType.Halo3Retail:
            case CacheType.MccHalo3:
            case CacheType.MccHalo3U4:
            case CacheType.Halo3ODST:
            case CacheType.MccHalo3ODST:
                result = item.ReadMetadata <Blam.Halo3.model>().ToModelConfig();
                break;

            case CacheType.HaloReachRetail:
            case CacheType.MccHaloReach:
            case CacheType.MccHaloReachU3:
                result = item.ReadMetadata <Blam.HaloReach.model>().ToModelConfig();
                break;

            case CacheType.Halo4Retail:
            case CacheType.MccHalo4:
            case CacheType.MccHalo2X:
                result = item.ReadMetadata <Blam.Halo4.model>().ToModelConfig();
                break;

            default: return(null);
            }

            result.ModelTag = item;
            return(result);
        }
        public static bool TryGetSoundContent(IIndexItem item, out ISoundContainer content)
        {
            content = null;

            if (item == null)
            {
                return(false);
            }

            if (item.ClassCode != sound)
            {
                return(false);
            }

            switch (item.CacheFile.CacheType)
            {
            case CacheType.Halo2Xbox:
                content = item.ReadMetadata <Halo2.sound>();
                break;

            //case CacheType.Halo3Beta:
            case CacheType.Halo3Retail:
            case CacheType.Halo3ODST:
                content = item.ReadMetadata <Halo3.sound>();
                break;

            case CacheType.HaloReachBeta:
            case CacheType.HaloReachRetail:
                content = item.ReadMetadata <HaloReach.sound>();
                break;
            }

            return(content != null);
        }
Beispiel #8
0
        public static bool CanOpenTag(IIndexItem tag)
        {
            if (tag.ClassCode.ToLower() != "scnr")
            {
                return(false);
            }

            switch (tag.CacheFile.CacheType)
            {
            case CacheType.Halo3Retail:
            case CacheType.MccHalo3:
            case CacheType.MccHalo3U4:
            case CacheType.Halo3ODST:
            case CacheType.MccHalo3ODST:
            case CacheType.HaloReachRetail:
            case CacheType.MccHaloReach:
            case CacheType.MccHaloReachU3:
            case CacheType.Halo4Retail:
            case CacheType.MccHalo4:
            case CacheType.MccHalo2X:
                return(true);

            default: return(false);
            }
        }
 public void DeleteTerminatorData(IIndexItem <DefaultFileExtraInfo> index, Action <bool> onComplete, OnErr onError)
 {
     WrapErr.ToErrReport(9999, () => {
         ErrReport report;
         WrapErr.ToErrReport(out report, 9999, () => {
             this.DeleteFromStorageNotLast(this.terminatorStorage, index,
                                           (tf) => {
                 this.GetCurrentTerminator(
                     (data) => {
                     if (data.UId == index.UId_Object)
                     {
                         this.RetrieveTerminatorData(
                             this.terminatorStorage.IndexedItems[0],
                             (newData) => {
                             // TODO error handling if we fail to set current
                             // TODO what if it is current for the BT,WIFI,USB,Ethernet
                             this.SetCurrentTerminators(newData, (err) => { });
                         },
                             // TODO error handling if we fail to retrieve current terminator
                             (err) => { });
                     }
                 },
                     (err) => { });
                 onComplete(tf);
             }, onError);
         });
         if (report.Code != 0)
         {
             onError.Invoke(this.GetText(MsgCode.LoadFailed));
         }
     });
 }
 public void DeleteScriptData(IIndexItem <DefaultFileExtraInfo> index, string name, Func <string, bool> areYouSure, Action <bool> onComplete, OnErr onError)
 {
     this.DeleteFromStorageNotLast(
         this.scriptStorage, index, name, areYouSure,
         (ok) => this.CheckAndSetCurrentScript(index, () => onComplete(ok)),
         onError);
 }
Beispiel #11
0
 /// <summary>Navigate to the CommandSetPage and set the IndexAsString property</summary>
 /// <param name="data">The index to set</param>
 private async void OnEdit(IIndexItem <DefaultFileExtraInfo> data)
 {
     if (data != null)
     {
         await Shell.Current.GoToAsync($"{nameof(TerminatorSetPage)}?TerminatorSetPage.IndexAsString={JsonConvert.SerializeObject(data)}");
     }
 }
Beispiel #12
0
        public void DisplayModel(ITabContentHost targetWindow, IIndexItem modelTag, string fileName)
        {
            var container = targetWindow.DocumentPanel;

            LogOutput($"Loading model: {fileName}");

            try
            {
                var viewer = new Controls.DXViewer
                {
                    LogOutput   = LogOutput,
                    LogError    = LogError,
                    SetStatus   = SetWorkingStatus,
                    ClearStatus = ClearWorkingStatus
                };

                viewer.LoadGeometry(modelTag, $"{fileName}");

                container.AddItem(viewer.TabModel);

                LogOutput($"Loaded model: {fileName}");
            }
            catch (Exception e)
            {
                LogError($"Error loading model: {fileName}", e);
            }
        }
Beispiel #13
0
        public void SaveSerialCfg(IIndexItem <SerialIndexExtraInfo> idx, SerialDeviceInfo data, Action onSuccess, OnErr onError)
        {
            this.Save(this.serialStorage, idx, data, this.PreSaveOps, onSuccess, onError);

            //WrapErr.ToErrReport(9999, () => {
            //    ErrReport report;
            //    WrapErr.ToErrReport(out report, 9999, () => {
            //        this.Validate5msReadWrite(data, data);
            //        this.Save(this.serialStorage, idx, data,
            //            (dm, index)=> index.ExtraInfoObj.Update(dm), onSuccess, onError);
            //    });
            //    if (report.Code != 0) {
            //        onError.Invoke(this.GetText(MsgCode.SaveFailed));
            //    }
            //});

            //WrapErr.ToErrReport(9999, () => {
            //    ErrReport report;
            //    WrapErr.ToErrReport(out report, 9999, () => {
            //        if (idx.Display.Length == 0) {
            //            onError.Invoke(this.GetText(MsgCode.EmptyName));
            //        }
            //        else {
            //            this.Validate5msReadWrite(data, data);
            //            this.serialStorage.Store(data, idx);
            //            onSuccess.Invoke();
            //        }
            //    });
            //    if (report.Code != 0) {
            //        onError.Invoke(this.GetText(MsgCode.SaveFailed));
            //    }
            //});
        }
Beispiel #14
0
 private void Create <TSToreObject, TExtraInfo>(
     IIndexedStorageManager <TSToreObject, TExtraInfo> manager,
     string display,
     TSToreObject data,
     Action <IIndexItem <TExtraInfo> > onSuccess,
     Action <TSToreObject> onChange,
     OnErr onError, TExtraInfo extraInfo = null)
     where TSToreObject : class, IDisplayable, IIndexible where TExtraInfo : class
 {
     WrapErr.ToErrReport(9999, () => {
         ErrReport report;
         WrapErr.ToErrReport(out report, 9999, () => {
             if (display.Length == 0)
             {
                 onError.Invoke(this.GetText(MsgCode.EmptyName));
             }
             else
             {
                 IIndexItem <TExtraInfo> idx = (extraInfo == null)
                     ? new IndexItem <TExtraInfo>(data.UId)
                     : new IndexItem <TExtraInfo>(data.UId, extraInfo);
                 idx.Display = display;
                 this.Save(manager, idx, data, (obj, idx) => { }, () => onSuccess(idx), onChange, onError);
             }
         });
         if (report.Code != 0)
         {
             onError.Invoke(this.GetText(MsgCode.UnknownError));
         }
     });
 }
Beispiel #15
0
        public void RetrieveSerialCfg(IIndexItem <SerialIndexExtraInfo> index, Action <SerialDeviceInfo> onSuccess, OnErr onError)
        {
            this.RetrieveItem(this.serialStorage, index,
                              (obj) => {
                this.Validate5msReadWrite(obj, obj);
                onSuccess.Invoke(obj);
            }, onError);

            //WrapErr.ToErrReport(9999, () => {
            //    ErrReport report;
            //    WrapErr.ToErrReport(out report, 9999, () => {
            //        var info = this.serialStorage.Retrieve(index);
            //        if (info == null) {
            //            onError.Invoke(this.GetText(MsgCode.NotFound));
            //        }
            //        else {
            //            this.Validate5msReadWrite(info, info);
            //            onSuccess.Invoke(info);
            //        }
            //    });
            //    if (report.Code != 0) {
            //        onError.Invoke(this.GetText(MsgCode.LoadFailed));
            //    }
            //});
        }
Beispiel #16
0
 private void Delete <TSToreObject, TExtraInfo>(
     IIndexedStorageManager <TSToreObject, TExtraInfo> manager,
     IIndexItem <TExtraInfo> indexItem,
     Action onSuccess,
     OnErr onError)
     where TSToreObject : class where TExtraInfo : class
 {
     WrapErr.ToErrReport(9999, () => {
         ErrReport report;
         WrapErr.ToErrReport(out report, 9999, () => {
             if (indexItem == null)
             {
                 onError(this.GetText(MsgCode.NothingSelected));
             }
             else
             {
                 if (manager.DeleteFile(indexItem))
                 {
                     onSuccess();
                 }
                 else
                 {
                     onError(this.GetText(MsgCode.DeleteFailure));
                 }
             }
         });
         if (report.Code != 0)
         {
             onError.Invoke(this.GetText(MsgCode.DeleteFailure));
         }
     });
 }
Beispiel #17
0
 private void Delete <TSToreObject, TExtraInfo>(
     IIndexedStorageManager <TSToreObject, TExtraInfo> manager,
     IIndexItem <TExtraInfo> indexItem,
     string title,
     string msg,
     Func <string, string, bool> areYouSure,
     Action onComplete,
     OnErr onError)
     where TSToreObject : class where TExtraInfo : class
 {
     WrapErr.ToErrReport(9999, () => {
         ErrReport report;
         WrapErr.ToErrReport(out report, 9999, () => {
             if (indexItem == null)
             {
                 onError(this.GetText(MsgCode.NothingSelected));
             }
             else
             {
                 if (areYouSure(title, msg))
                 {
                     this.Delete(manager, indexItem, onComplete, onError);
                 }
             }
         });
         if (report.Code != 0)
         {
             onError.Invoke(this.GetText(MsgCode.DeleteFailure));
         }
     });
 }
Beispiel #18
0
 private void DeleteFromStorageNotLast <TSToreObject, TExtraInfo>(
     IIndexedStorageManager <TSToreObject, TExtraInfo> manager,
     IIndexItem <TExtraInfo> indexItem,
     string msg,
     Func <string, bool> areYouSure,
     Action <bool> onComplete,
     OnErr onError)
     where TSToreObject : class where TExtraInfo : class
 {
     WrapErr.ToErrReport(9999, () => {
         ErrReport report;
         WrapErr.ToErrReport(out report, 9999, () => {
             if (indexItem == null)
             {
                 onError(this.GetText(MsgCode.NothingSelected));
             }
             else if (manager.IndexedItems.Count < 2)
             {
                 onError(this.GetText(MsgCode.CannotDeleteLast));
             }
             else
             {
                 if (areYouSure(msg))
                 {
                     bool ok = manager.DeleteFile(indexItem);
                     onComplete(ok);
                 }
             }
         });
         if (report.Code != 0)
         {
             onError.Invoke(this.GetText(MsgCode.DeleteFailure));
         }
     });
 }
        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");
            });
        }
 public void T01_Create03_CreateOrSave_Save()
 {
     TestHelpers.CatchUnexpected(() => {
         this.SetupData(2);
         IIndexItem <SerialIndexExtraInfo> ndx = this.RetrieveList(2)[0];
         var cfg                 = this.RetrieveData(ndx);
         cfg.Display             = "BLAH BLAH BLAH";
         cfg.Baud                = 55000;
         cfg.DataBits            = 1;
         cfg.USB_VendorId        = 44;
         cfg.USB_VendorIdDisplay = "blah";
         TDI.Wrapper.CreateOrSaveSerialCfg(cfg.Display, cfg, this.OnSuccessDummy, this.AssertErr);
         this.AssertCompleteFired();
         var list   = this.RetrieveList(2);
         bool found = false;
         for (int i = 0; i < 2; i++)
         {
             if (list[i].UId_Object == ndx.UId_Object)
             {
                 found = true;
                 this.RetrieveAndValidate(list[i], "BLAH BLAH BLAH", 55000, 1, cfg.StopBits, cfg.Parity, cfg.FlowHandshake);
             }
         }
         Assert.True(found, "Did not find original index");
     });
 }
 private async void OnCredEdit(IIndexItem <DefaultFileExtraInfo> index)
 {
     if (index != null)
     {
         await Shell.Current.GoToAsync($"{ROUTE_NAME}?WifiCredentialsModalEditPage.IndexAsString={JsonConvert.SerializeObject(index)}");
     }
 }
        public static bool IsTagSupported(IIndexItem tag)
        {
            if (!directContentTags.Union(compositeTags).Any(s => tag?.ClassCode.ToLower() == s))
            {
                return(false);
            }

            switch (tag.CacheFile.CacheType)
            {
            case CacheType.Halo3Retail:
            case CacheType.MccHalo3:
            case CacheType.MccHalo3U4:
            case CacheType.Halo3ODST:
            case CacheType.MccHalo3ODST:
            case CacheType.HaloReachRetail:
            case CacheType.MccHaloReach:
            case CacheType.MccHaloReachU3:
            case CacheType.Halo4Retail:
            case CacheType.MccHalo4:
            case CacheType.MccHalo2X:
                return(true);

            default: return(false);
            }
        }
        public void T11_EditAndSave()
        {
            try {
                TestHelpers.CatchUnexpected(() => {
                    this.SubscribeToChange();
                    List <IIndexItem <EthernetExtraInfo> > list = this.SetupAndRetrieveList(2);
                    IIndexItem <EthernetExtraInfo> idx          = list[0];
                    EthernetParams p      = this.RetrieveData(idx);
                    string display        = "BLAH PHUT";
                    string address        = "221.221.221.1";
                    string port           = "99";
                    p.Display             = display;
                    p.EthernetAddress     = address;
                    p.EthernetServiceName = port;
                    TDI.Wrapper.SaveEthernetData(idx, p, this.OnSuccessDummy, AssertErr);
                    this.AssertCompleteFired();
                    this.AssertIndexChangeFired();

                    this.RetrieveAndValidate(idx, display, address, port);
                });
            }
            finally {
                this.UnsubscribeToChange();
            }
        }
Beispiel #24
0
        /// <summary>Retrieve data from storage to edit and save</summary>
        /// <param name="parent">The parent window</param>
        /// <param name="index">The data item index object</param>
        public static bool ShowBox(Window parent, IIndexItem <DefaultFileExtraInfo> index)
        {
            MsgBoxWifiCred box = new MsgBoxWifiCred(parent, index);

            box.processType = ProcessType.Edit;
            box.ShowDialog();
            return(box.Result.IsChanged);
        }
        public StructureBspModel(IIndexItem item)
        {
            IsBusy = true;

            StructureBspTag = item;

            IsBusy = false;
        }
Beispiel #26
0
 public void DeleteEthernetData(IIndexItem <EthernetExtraInfo> index, string name, Func <string, bool> areYouSure, Action <bool> onComplete, OnErr onError)
 {
     this.DeleteFromStorage(
         this.ethernetStorage, index, name, areYouSure,
         (ok) => {
         this.RaiseEthernetListChange(() => onComplete(ok), onError);
     }, onError);
 }
Beispiel #27
0
 public void DeleteSerialCfg(IIndexItem <SerialIndexExtraInfo> index, Action <bool> onComplete, OnErr onError)
 {
     //ErrReport report;
     //WrapErr.ToErrReport(out report, 2003011, "Failure on DeleteSerialCfg", () => {
     this.DeleteFromStorage(this.serialStorage, index, onComplete, onError);
     //});
     //this.RaiseIfException(report);
 }
        private TerminatorDataModel RetrieveData(IIndexItem <DefaultFileExtraInfo> index)
        {
            TerminatorDataModel data = null;

            TDI.Wrapper.RetrieveTerminatorData(index, d => { data = d; }, this.AssertErr);
            Assert.NotNull(data, "Failed to retrieve data");
            return(data);
        }
        private SerialDeviceInfo RetrieveData(IIndexItem <SerialIndexExtraInfo> index)
        {
            SerialDeviceInfo data = null;

            TDI.Wrapper.RetrieveSerialCfg(index, p => { data = p; }, this.AssertErr);
            Assert.NotNull(data, "Failed to retrieve");
            return(data);
        }
        private ScriptDataModel RetrieveData(IIndexItem <DefaultFileExtraInfo> index)
        {
            ScriptDataModel data = null;

            TDI.Wrapper.RetrieveScriptData(index, (d) => { data = d; }, this.AssertErr);
            Assert.NotNull(data);
            return(data);
        }