private void _UpdateSessionModel(SmartConfigDataModel model) { if (null == model) { return; } lock (_updateModelSyncObj) { for (int i = 0; i < 3; ++i) { try { try { Session.Remove(Definitions.SMART_CONFIG_SESSION_KEY); } catch { } Session[Definitions.SMART_CONFIG_SESSION_KEY] = model; } catch (Exception ex) { model.LastErrorMessage = ex.Message; MvcApplication.Logger.Error(ex.Message); } } } }
public ActionResult Index() { var model = Session[Definitions.SMART_CONFIG_SESSION_KEY] as SmartConfigDataModel; if (null == model) { using (model = new SmartConfigDataModel()) { this._UpdateSessionModel(model); } } return(View(model)); }
public ActionResult LoadJsonConfig(HttpPostedFileBase jsonConfig) { if (null != jsonConfig && jsonConfig.ContentLength > 0) { SmartConfigDataModel model = new SmartConfigDataModel(); try { const string uploadFolder = @"~/App_Data/Upload"; var fileInfo = new FileInfo(jsonConfig.FileName); var jsonFile = Path.Combine(Server.MapPath(uploadFolder), string.Format(@"{0}_{1}" + fileInfo.Extension, fileInfo.Name.Replace(fileInfo.Extension, string.Empty), System.Web.HttpContext.Current.Session.SessionID)); jsonConfig.SaveAs(jsonFile); using (StreamReader file = System.IO.File.OpenText(jsonFile)) { var serializer = new JsonSerializer(); model = (SmartConfigDataModel)serializer.Deserialize(file, typeof(SmartConfigDataModel)); if (model.Root.Count == 0) { model.LastErrorMessage = string.Format(@"-- There is no node been loaded, please verify the json file [{0}] is valid. ---", fileInfo.FullName); this._UpdateSessionModel(model); return(RedirectToAction("Index")); } model.BuildTree(); model.ConfigLoaded = true; model.JsonConfig = jsonFile; this._UpdateSessionModel(model); } } catch (Exception ex) { var errorMsg = string.Format(@"SmartConfig - Excepton caught at LoadJsonConfig", ex.Message); model.LastErrorMessage = errorMsg; MvcApplication.Logger.Error(errorMsg); } } return(RedirectToAction("Index")); }
public void SmartConfigJsonTest() { var model = new SmartConfigDataModel { Root = { new ConfigTreeNode { Key = @"Edk2Manu", Annotation = @"EDKII Menu", SubMenu = { new ConfigTreeNode { Key = @"Socket", Annotation = @"Socket Configuration", Properties = { pType = @"Hex", Options = { "0xe0","0xe1", "0xe2", "0xe3" }, Default = "0xe0", CurrentValue = "0xe0" }, UpdateDictionary = new UpdateMatrix { UpdateData = { new KeyValuePair <string, UpdateMatrixData>(@"DisableTPH", new UpdateMatrixData("0")), new KeyValuePair <string, UpdateMatrixData>(@"DisableTPH", new UpdateMatrixData("1") { Properties = new Props{ pType = "Hex", Options = { "0xe0","0xe1", "0xe2", "0xe3"}, Default = "0xe3", CurrentValue = "0xe3" }, RawDataMap = new RawData{ Offset = "0x200", Size = "0x02", Value = "0x02" } }), new KeyValuePair <string, UpdateMatrixData>(@"DisableTPH", new UpdateMatrixData("2")), } }, RawDataMap = { Offset = "0x100", Size = "0x01", Value = "0x01" }, SubMenu = { new ConfigTreeNode { Key = @"AdvancedPowerManagementConfiguration", Annotation = @"Advanced Power Management Configuration", Properties = { pType = "Int", Options = { "270","300" }, Default = "270", CurrentValue = "270" }, RawDataMap = { Offset = "0x100", Size = "0x01", Value = "0x01" }, SubMenu = { new ConfigTreeNode { Key = "IIOConfiguration", Annotation = "IIOConfiguration", RawDataMap = { Offset = "0x300", Size = "0x03", Value = "0x03" }, SubMenu = { new ConfigTreeNode { Key = "IOATConfiguration", Annotation = "IOAT Configuration", RawDataMap = { Offset = "0x300", Size = "0x03", Value = "0x03" }, SubMenu = { { new ConfigTreeNode { Key = "DisableTPH", Annotation = "Disable TPH", RawDataMap = { Offset = "0x300", Size = "0x03", Value = "0x03" }, Observer = { "Root.Edk2Manu.Socket", "Root.BootManagerMenu", "Root.Edk2Manu.Socket.AdvancedPowerManagementConfiguration" } } } } } } } } } } } } }, new ConfigTreeNode { Key = @"BootManagerMenu", Annotation = @"Boot Manage rMenu" }, new ConfigTreeNode { Key = @"BootMaintenanceManager", Annotation = @"Boot Maintenance Manager" }, new ConfigTreeNode { Key = @"Continue", Annotation = @"Continue" }, new ConfigTreeNode { Key = @"Reset", Annotation = @"Reset" }, } }; var json = new JsonFormatter(JsonConvert.SerializeObject(model)).Format(); var jsonFile = @"C:\mcu-release-automation\DcPaeWebService\IntelDCGSpsWebService\App_Data\EdkIIConfig.json"; //File.WriteAllText(jsonFile, json); SmartConfigDataModel root = null; using (StreamReader file = File.OpenText(jsonFile)) { var serializer = new JsonSerializer(); try { root = (SmartConfigDataModel)serializer.Deserialize(file, typeof(SmartConfigDataModel)); root.BuildTree(); string[] keys = { "Edk2Manu", "Socket", "AdvancedPowerManagementConfiguration", "IIOConfiguration", "IOATConfiguration", "DisableTPH" }; var jpath = "Root"; foreach (var key in keys) { jpath = string.Format("{0}.{1}", jpath, key); var x = root.GetConfigNodeByJPath(jpath); } var updateDictFile = @"C:/mcu-release-automation/ReleaseAutomation/buildingblocks/SmartJsonConfig/unittest_smart_json_config/UpdateDictionary.json"; } catch (Exception ex) { } } var updateMatrix = new UpdateMatrix { UpdateData = { new KeyValuePair <string, UpdateMatrixData>(@"DisableTPH", new UpdateMatrixData("0")), new KeyValuePair <string, UpdateMatrixData>(@"DisableTPH", new UpdateMatrixData("1") { Properties = new Props { pType = "Hex", Options = { "0xe0", "0xe1", "0xe2", "0xe3"}, Default = "0xe3", CurrentValue = "0xe3" }, RawDataMap = new RawData { Offset = "0x200", Size = "0x02", Value = "0x02" } }), new KeyValuePair <string, UpdateMatrixData>(@"DisableTPH", new UpdateMatrixData("2")), } }; json = new JsonFormatter(JsonConvert.SerializeObject(updateMatrix)).Format(); jsonFile = @"C:\mcu-release-automation\DcPaeWebService\IntelDCGSpsWebService\App_Data\UpdateDictionary.json"; //File.WriteAllText(jsonFile, json); var jp = "Root.Edk2Manu.Socket.AdvancedPowerManagementConfiguration.IIOConfiguration.IOATConfiguration.DisableTPH"; var instance = root.GetConfigNodeByJPath(jp); instance.SyncUpdate(instance); }