public FloorSet StartConnection() { FloorSet allFloorSet = new FloorSet(_Settings); string errorSetting = ""; List <string> errorList = new List <string>(); if (_Settings == null) { _Settings.NewSubSettings("Connection"); return(allFloorSet); } // Create connection for each connection subSettings foreach (string s in _Settings.SubSettings.Keys) { SettingsBase connectionSetting = _Settings.SubSettings[s]; try { ConnectionBase newConnection = CreateConnection(allFloorSet, connectionSetting); _Connections.Add(s, newConnection); if ((Convert.ToBoolean(connectionSetting["IsRunning", false]) == true) && (!newConnection.IsRunning)) { // Try to connect it try { newConnection.Connect(); } catch { } } } catch { errorList.Add(s); errorSetting += s; } } if (!string.IsNullOrEmpty(errorSetting)) { // Remove Error Connection for (int i = 0; i < errorList.Count; i++) { Trace.WriteLine(string.Format("Removing {0} connection", errorList[i]), "Connection"); _Settings.SubSettings.Remove((string)errorList[i]); } Trace.WriteLine(errorSetting + " Connection error, unable to create"); //_Log.WriteLog(errorSetting + "设置错误,无法被创建"); } OnHaveStartConnection(EventArgs.Empty); return(allFloorSet); }
public void CreateConnection(FloorSet floorSet, SettingsBase settings, ConnectionType type) { if (settings == null) { return; } // Get the FloorSet Information to Settings string floorInfo = string.Empty; foreach (int floorNumber in floorSet.FloorNumbers) { // Save each floor number floorInfo += ("F" + floorNumber); // Save each room number foreach (Room room in floorSet[floorNumber].GetRooms()) { floorInfo += ("R" + room.Number); } } settings["Type"] = type.ClassInfo.Name; ConnectionBase newConnection = type.CreateConnection(floorSet, settings); if (newConnection == null) { _Log.WriteLog("没有此类的连接方式"); //如果没有以上种,就报错 return; } else { //has created the new connection , add informations settings["FloorSet"] = floorInfo; this._Connections.Add(settings["Name"].ToString(), newConnection); if ((Convert.ToBoolean(settings["IsRunning", false]) == true) && (!newConnection.IsRunning)) { // Try to connect it try { newConnection.Connect(); } catch { } } OnHaveCreatConnection(EventArgs.Empty); } }