/// <summary> /// Load information of gateway for Local Storage /// </summary> public void LoadGatewayInfo() { var localSetting = GetStorageSetting(); try { if (localSetting.Values.ContainsKey(GatewayHttpInterface.GatewayCollectionKey)) { var buf = localSetting.Values[GatewayHttpInterface.GatewayCollectionKey] as byte[]; var gatewayCollection = GatewayHttpInterface.DecodeFromBytes <OneServerInfo[]>(buf); foreach (var info in gatewayCollection) { GatewayCollection.GetOrAdd(info.HostName, info.HostInfo); } } } catch (Exception e) { Debug.WriteLine("LoadGatewayInfo fails with exception {0}", e); // Swallow exception if the store can not be used. } if (localSetting.Values.ContainsKey(GatewayHttpInterface.GatewayKey)) { CurrentGateway = localSetting.Values[GatewayHttpInterface.GatewayKey].ToString(); } else { CurrentGateway = App.DefaultGateway; } GatewayCollection.GetOrAdd(this.CurrentGateway, "Default"); VMHub.CurrentGateway = this.CurrentGateway; }
/// <summary> /// Save information of gateway to local storage /// </summary> /// <param name="gateway"></param> /// <param name="gatewayCollection"></param> public void SaveGatewayInfo(String gateway, List <OneServerInfo> gatewayCollection) { var localSetting = GetStorageSetting(); localSetting.Values[GatewayHttpInterface.GatewayKey] = gateway; var arr = gatewayCollection.ToArray(); localSetting.Values[GatewayHttpInterface.GatewayCollectionKey] = GatewayHttpInterface.EncodeToBytes <OneServerInfo[]>(arr); CurrentGateway = gateway; VMHub.CurrentGateway = gateway; GatewayCollection.Clear(); foreach (var info in gatewayCollection) { GatewayCollection.GetOrAdd(info.HostName, info.HostInfo); } GatewayCollection.GetOrAdd(this.CurrentGateway, "Default"); }