/// <summary> /// Set/Insert Consumable Data Contract object into Database /// </summary> /// <param name="rootObject">JSON RootObject</param> private void SaveMatrixToRepository(ConsumableDataContract rootObject) { var serializedJson = Serializer.Serialize <ConsumableDataContract>(rootObject); ConsumableCompatibility json = new ConsumableCompatibility() { FileSignature = rootObject.FileSignature, JSON = serializedJson }; BarcodeRepository?.SetConsumableCompatibilityJson(json); BarcodeModel.LaborieCompanyCode = GetLaborieCompanyCode(); BarcodeModel.SupportedCompanyCodes = GetSupportedCompanyCodes(); }
/// <summary> /// Load Consumable Data Contract object from the JSON file/stream, check the signature, then save to database. /// </summary> /// <param name="path">File Location or the path of stream, null means default file path</param> public void LoadStreamToDb(string path = null) { ConsumableDataContract consumableDataContract = LoadMatrixFromFile(path); if (consumableDataContract == null) { throw new InvalidFileException(Translations.Language.Missing_ConsumableJSON_File); } if (IsFileSignatureValid(consumableDataContract)) { SaveMatrixToRepository(consumableDataContract); } else { throw new InvalidFileException(Translations.Language.Invalid_ConsumableJSON_FileSignature); } }
/// <summary> /// Check the file signature of the consumable compatibility string contents. /// </summary> /// <returns>true indicate valid signature</returns> public bool CheckFileSignature() { ConsumableDataContract consumableDataContract = LoadMatrixFromRepository(); if (consumableDataContract == null) { throw new InvalidFileException(Translations.Language.Missing_ConsumableJSON_File); } if (IsFileSignatureValid(consumableDataContract)) { BarcodeModel.LaborieCompanyCode = GetLaborieCompanyCode(); BarcodeModel.SupportedCompanyCodes = GetSupportedCompanyCodes(); return(true); } else { throw new InvalidFileException(Translations.Language.Invalid_ConsumableJSON_FileSignature); } }