public static WidgetInstance Load(Database db, System.Data.DataRow row) { var rowid = row.GetLong("rowid"); var fullName = row.GetString("name"); var type = WidgetManager.GetTypeFromFullName(fullName); if (type == null) { throw new WidgetLoadException(string.Format("A widget with the name '{0}' cannot be found.", fullName)); } var bounds = new Rectangle(row.GetInt("bounds_left"), row.GetInt("bounds_top"), row.GetInt("bounds_width"), row.GetInt("bounds_height")); var settings = new WidgetConfig(); foreach (System.Data.DataRow settingRow in db.SelectDataTable("select name, value from widget_config where widget_id = @id", "@id", rowid).Rows) { var name = settingRow.GetString("name"); if (string.IsNullOrEmpty(name)) { continue; } settings.Add(new WidgetConfigItem(name, settingRow.GetString("value"))); } return(new WidgetInstance(type, bounds, settings)); }
public static WidgetInstance Load(XmlElement element) { if (element.Name != XmlElementName) { throw new WidgetLoadException(string.Format("Element name is not '{0}'.", XmlElementName)); } var fullName = element.GetAttribute("Name"); if (fullName == null) { throw new WidgetLoadException("'Name' attribute does not exist."); } var type = WidgetManager.GetTypeFromFullName(fullName); if (type == null) { throw new WidgetLoadException(string.Format("A widget with the name '{0}' cannot be found.", fullName)); } var boundsElement = element.SelectSingleNode("Bounds") as XmlElement; if (boundsElement == null) { throw new WidgetLoadException("'Bounds' element does not exist."); } var bounds = new Rectangle(int.Parse(boundsElement.GetAttribute("Left")), int.Parse(boundsElement.GetAttribute("Top")), int.Parse(boundsElement.GetAttribute("Width")), int.Parse(boundsElement.GetAttribute("Height"))); var settings = new WidgetConfig(); foreach (var xmlSetting in element.SelectNodes("Config").Cast <XmlElement>()) { var name = xmlSetting.GetAttribute("Name"); if (string.IsNullOrEmpty(name)) { throw new WidgetLoadException("Widget config has no 'Name' attribute."); } settings.Add(new WidgetConfigItem(name, xmlSetting.GetAttribute("Value"))); } return(new WidgetInstance(type, bounds, settings)); }
static void Main(string[] args) { try { var winStart = false; foreach (var arg in args) { if (arg.Equals("-winstart", StringComparison.InvariantCultureIgnoreCase)) { winStart = true; } } bool createdNew; var mutex = new Mutex(true, k_guid, out createdNew); if (createdNew) { Log.Initialize(); try { #if DEBUG Log.Level = LogLevel.Debug; #else Log.Level = LogLevel.Info; #endif Settings.Initialize(); WidgetManager.SearchForWidgets(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); _mainWindow = new MainWindow(winStart); Application.Run(_mainWindow); } finally { Log.Debug("Main thread is terminating."); // Terminal the switch thread try { Log.Debug("Shutting down switch thread."); if (_switchThread != null && _switchThread.IsAlive) { _switchThread.Kill(); _switchThread = null; } } catch (Exception ex) { Log.Write(ex); } // Close the log file try { Log.Close(); } catch (Exception ex) { Log.Write(ex); // Probably futile } } } else if (!winStart) { NativeMethods.PostMessage((IntPtr)NativeMethods.HWND_BROADCAST, NativeMethods.WM_SHOWME, IntPtr.Zero, IntPtr.Zero); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error when starting WallSwitch", MessageBoxButtons.OK, MessageBoxIcon.Error); } }