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)); }
protected override void DoGUI() { Invitation inv = InvitationManager.Instance.Invitation; if (inv == null) { gameObject.GetComponent<MainMenuGui>().MakeActive(); return; } string inviterName = null; inviterName = (inv.Inviter == null || inv.Inviter.DisplayName == null) ? "Someone" : inv.Inviter.DisplayName; WidgetConfig msgConfig = new WidgetConfig(0.0f, -0.2f, 1.0f, 0.2f, 35, inviterName + " is challenging you to a quiz race!"); GuiLabel(msgConfig); if (GuiButton(AcceptButtonCfg)) { InvitationManager.Instance.Clear(); RaceManager.AcceptInvitation(inv.InvitationId); gameObject.GetComponent<RaceGui>().MakeActive(); } else if (GuiButton(DeclineButtonCfg)) { InvitationManager.Instance.DeclineInvitation(); gameObject.GetComponent<MainMenuGui>().MakeActive(); } }
public static WidgetBuilder <IWidgetModel> RegisterWidget(this PluginBuilder pluginBuilder, Action <WidgetConfig> widgetBuilder) { var widget = new WidgetConfig(); widgetBuilder.Invoke(widget); widget.ServiceType = null; widget.ModelType = null; widget.GetDefaultSettings = (serviceProvider) => { return(null); }; widget.GetSettings = (serviceProvider, id) => { return(null); }; widget.SaveSettings = (serviceProvider, settings) => { /* no-op */ }; widget.CloneSettings = (serviceProvider, id) => { return(new EmptyWidgetModel()); }; pluginBuilder.PluginContext.AddData(widget); return(new WidgetBuilder <IWidgetModel>(widget)); }
public void Save(XmlWriter xml) { xml.WriteStartElement(XmlElementName); xml.WriteAttributeString("Name", _wtype.FullName); xml.WriteStartElement("Bounds"); xml.WriteAttributeString("Left", _bounds.Left.ToString()); xml.WriteAttributeString("Top", _bounds.Top.ToString()); xml.WriteAttributeString("Width", _bounds.Width.ToString()); xml.WriteAttributeString("Height", _bounds.Height.ToString()); xml.WriteEndElement(); // Bounds var settings = new WidgetConfig(); _widget.Save(settings); foreach (var setting in settings) { xml.WriteStartElement("Config"); xml.WriteAttributeString("Name", setting.Name); if (setting.Value != null) { xml.WriteAttributeString("Value", setting.Value); } xml.WriteEndElement(); // Setting } xml.WriteEndElement(); // Widget }
private void GuiLabel_internal(WidgetConfig config, string overrideText) { GUI.skin.label.alignment = config.ContentAnchor; GUI.skin.label.fontSize = ScreenFontSize(config.FontSize); GUI.Label(GetWidgetRect(config), overrideText == null ? config.Text : overrideText); }
protected void GuiLabel(WidgetConfig config, string overrideText) { if (!mStandBy) { GuiLabel_internal(config, overrideText); } }
protected override void DoGUI() { Invitation inv = InvitationManager.Instance.Invitation; if (inv == null) { gameObject.GetComponent <MainMenuGui>().MakeActive(); return; } string inviterName = null; inviterName = (inv.Inviter == null || inv.Inviter.DisplayName == null) ? "Someone" : inv.Inviter.DisplayName; WidgetConfig msgConfig = new WidgetConfig(0.0f, -0.2f, 1.0f, 0.2f, 35, inviterName + " is challenging you to a quiz race!"); GuiLabel(msgConfig); if (GuiButton(AcceptButtonCfg)) { InvitationManager.Instance.Clear(); RaceManager.AcceptInvitation(inv.InvitationId); gameObject.GetComponent <RaceGui>().MakeActive(); } else if (GuiButton(DeclineButtonCfg)) { InvitationManager.Instance.DeclineInvitation(); gameObject.GetComponent <MainMenuGui>().MakeActive(); } }
private void LoadAndRenderControl() { WidgetConfig config = WidgetFactory.Instance.GetWidget(_controlId); if (null != config) { Control control = null; if (_hostFilterPopUp) { if (null != config.FilterWidget) { control = this.LoadControl(config.FilterWidget.Path); IFilterControl filterControl = control as IFilterControl; if (null != filterControl) { filterControl.ApplyConfig(config.FilterWidget.FilterConfig); } } else { RenderNotFoundControl(); } } else { control = this.LoadControl(config.Path); } if (null != control) { // check if the control is a query broker consumer IQueryableControl qryControl = control as IQueryableControl; if (null != qryControl) { IQueryBroker broker = config.GetQueryBroker(); // check if we are in filter post back if (_isFilterPostback) { FilterInfo info = FilterInfo.ExtractFrom(Request.Form); broker.ApplyFilter(info); } ITable tableQuery = broker.TableSelect; qryControl.SetTableSelect(tableQuery); } RenderHostedControl(control); } else { RenderNotFoundControl(); } } else { RenderNotFoundControl(); } }
protected void GuiProgressBar(WidgetConfig cfg, Texture fgTexture, Texture bgTexture, float percent) { Rect r = GetWidgetRect(cfg); GUI.DrawTexture(r, bgTexture); r.width = r.width * percent * 0.01f; GUI.DrawTexture(r, fgTexture); }
private Rect GetWidgetRect(WidgetConfig cfg) { float centerY = cfg.Anchor == WidgetConfig.WidgetAnchor.Top ? GetScreenTop() + cfg.CenterY : cfg.Anchor == WidgetConfig.WidgetAnchor.Bottom ? GetScreenBottom() + cfg.CenterY : cfg.CenterY; return(CenteredRect(cfg.CenterX, centerY, cfg.Width, cfg.Height)); }
/// <summary> /// Sets widget properties if config object exists for node /// </summary> /// <param name="widget"></param> public static void SetWidgetByConfig(BaseWidgetControl widget) { WidgetConfig config = WidgetConfig.GetByName(widget.Name); if (config != null) { SetWidgetByConfig(widget, config); } }
public WidgetInstance(WidgetType wtype, Rectangle bounds, WidgetConfig config) { _wtype = wtype; _bounds = bounds; _config = config; _widget = (IWidget)Activator.CreateInstance(wtype.Type); _widget.Load(config); }
protected bool GuiButton(WidgetConfig config, string overrideText) { if (!mStandBy) { GUI.skin.button.alignment = config.ContentAnchor; GUI.skin.button.fontSize = ScreenFontSize(config.FontSize); return GUI.Button(GetWidgetRect(config), overrideText == null ? config.Text : overrideText); } else { return false; } }
/// <summary> /// Sets widget properties via config object /// </summary> /// <param name="widget"></param> /// <param name="config"></param> public static void SetWidgetByConfig(BaseWidgetControl widget, WidgetConfig config) { widget.Title = config.Title; widget.Description = config.Description; widget.HelpText = config.HelpText; widget.Modules = config.Modules.ToArray(); // set default widget state (if applicable) if (!string.IsNullOrEmpty(config.DefaultState)) { widget.SetWidgetState(config.DefaultState); } }
protected bool GuiButton(WidgetConfig config, string overrideText) { if (!mStandBy) { GUI.skin.button.alignment = config.ContentAnchor; GUI.skin.button.fontSize = ScreenFontSize(config.FontSize); return(GUI.Button(GetWidgetRect(config), overrideText == null ? config.Text : overrideText)); } else { return(false); } }
public void Regist(string path, string folder, WidgetConfig config) { var widget = GetByPath(path); if (widget == null) { widget = new Port_Widget(); widget.InitializeId(); widget.DCreate = DateTime.Now; widget.Name = config.Name; widget.Folder = folder; widget.Path = path; widget.Version = config.Version; widget.Remark = config.Remark; Session.Insert(widget); } else { widget.DUpdate = DateTime.Now; widget.Name = config.Name; widget.Version = config.Version; widget.Remark = config.Remark; Session.Update(widget); } foreach (var tempConfig in config.Templates) { var temp = GetTemplateByPath(widget.Id, tempConfig.Path); if (temp == null) { temp = new Port_WidgetTemplate(); temp.InitializeId(); temp.Widget_id = widget.Id; temp.Name = tempConfig.Name; temp.Path = tempConfig.Path; temp.Remark = tempConfig.Remark; Session.Insert(temp); } else { temp.Name = tempConfig.Name; temp.Remark = tempConfig.Remark; Session.Update(temp); } } Session.FlushCache("sys.widget"); }
private void WidgetXAP_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) { WidgetConfig config = (WidgetConfig)e.UserState; string[] asmClass = config.ClassName.Split(';'); if (asmClass.Length < 2) { return; } List <AssemblyPart> currentParts = Deployment.Current.Parts.ToList(); StreamResourceInfo xapStreamInfo = new StreamResourceInfo(e.Result, "application/binary"); string appManifest = new StreamReader(Application.GetResourceStream(xapStreamInfo, new Uri("AppManifest.xaml", UriKind.Relative)).Stream).ReadToEnd(); XElement deploymentRoot = XDocument.Parse(appManifest).Root; List <XElement> deploymentParts = (from assemblyParts in deploymentRoot.Elements().Elements() select assemblyParts).ToList(); Assembly widgetAssembly = null; foreach (XElement deployPart in deploymentParts) { string source = deployPart.Attribute("Source").Value; // Assembly Name StreamResourceInfo asmStreamInfo = Application.GetResourceStream(xapStreamInfo, new Uri(source, UriKind.Relative)); if (currentParts.FirstOrDefault(part => part.Source.Equals(source, StringComparison.CurrentCulture)) == null) { AssemblyPart assemblyPart = new AssemblyPart(); if (source.Equals(asmClass[0], StringComparison.CurrentCultureIgnoreCase)) { widgetAssembly = assemblyPart.Load(asmStreamInfo.Stream); } else { assemblyPart.Load(asmStreamInfo.Stream); } Deployment.Current.Parts.Add(assemblyPart); } } if (widgetAssembly != null) { WidgetBase widget = widgetAssembly.CreateInstance(asmClass[1]) as WidgetBase; SetWidgetProperties(widget, config); } }
public void Save(WidgetConfig config) { config["HostName"] = HostName.ToString(); config["LogonDomain"] = LogonDomain.ToString(); config["IpAddress"] = IpAddress.ToString(); config["MachineDomain"] = MachineDomain.ToString(); config["MacAddress"] = MacAddress.ToString(); config["BootTime"] = BootTime.ToString(); config["Cpu"] = Cpu.ToString(); config["DefaultGateway"] = DefaultGateway.ToString(); config["DhcpServer"] = DhcpServer.ToString(); config["DnsServer"] = DnsServer.ToString(); config["FreeSpace"] = FreeSpace.ToString(); config["LabelColor"] = ColorTranslator.ToHtml(LabelColor); config["ValueColor"] = ColorTranslator.ToHtml(ValueColor); }
private void SetWidgetProperties(WidgetBase widget, WidgetConfig config) { if (widget != null) { widget.Title = config.Title; widget.IsOpen = config.OpenInitial; widget.MapControl = myMap; widget.IconSource = new BitmapImage(new Uri(config.IconSource, UriKind.Relative)); widget.InitialTop = config.InitialTop; widget.InitialLeft = config.InitialLeft; widget.HasGraphics = config.HasGraphics; widget.ConfigFile = config.ConfigFile; widget.Style = this.CurrentApp.Resources["WidgetStyle"] as Style; WidgetManager.Widgets.Add(widget); WidgetsCanvas.Children.Add(widget); } }
public void Load(WidgetConfig config) { HostName = GetConfigBool(config, "HostName", true); LogonDomain = GetConfigBool(config, "LogonDomain", true); IpAddress = GetConfigBool(config, "IpAddress", true); MachineDomain = GetConfigBool(config, "MachineDomain", true); MacAddress = GetConfigBool(config, "MacAddress", true); BootTime = GetConfigBool(config, "BootTime", true); Cpu = GetConfigBool(config, "Cpu", true); DefaultGateway = GetConfigBool(config, "DefaultGateway", true); DhcpServer = GetConfigBool(config, "DhcpServer", true); DnsServer = GetConfigBool(config, "DnsServer", true); FreeSpace = GetConfigBool(config, "FreeSpace", true); LabelColor = GetConfigColor(config, "LabelColor", Color.Silver); ValueColor = GetConfigColor(config, "ValueColor", Color.White); }
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)); }
private void WidgetDLL_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) { WidgetConfig config = (WidgetConfig)e.UserState; string[] asmClass = config.ClassName.Split(';'); if (asmClass.Length < 2) { return; } AssemblyPart assemblyPart = new AssemblyPart(); Deployment.Current.Parts.Add(assemblyPart); Assembly assembly = assemblyPart.Load(e.Result); WidgetBase widget = assembly.CreateInstance(asmClass[1]) as WidgetBase; SetWidgetProperties(widget, config); }
void ShowError(string error) { EndStandBy(); WidgetConfig msgConfig = new WidgetConfig( 0.0f, -0.2f, 1.0f, 0.2f, 35, error); GuiLabel(msgConfig); if (GuiButton(OkButtonCfg)) { RaceManager.Instance.CleanUp(); gameObject.GetComponent <MainMenuGui>().MakeActive(); } }
private bool GetConfigBool(WidgetConfig config, string name, bool defVal) { var item = config.TryGetItem(name); if (item == null) { return(defVal); } bool value; if (!bool.TryParse(item.Value, out value)) { return(defVal); } return(value); }
private Color GetConfigColor(WidgetConfig config, string name, Color defVal) { var item = config.TryGetItem(name); if (item == null) { return(defVal); } try { return(ColorTranslator.FromHtml(item.Value)); } catch (Exception) { return(defVal); } }
public void Load(WidgetConfig config) { WidgetConfigItem item; int monitor; if ((item = config.TryGetItem("SourceMonitor")) != null) { if (int.TryParse(item.Value, out monitor) && monitor > 0) { _props.SourceMonitor = monitor; } } if ((item = config.TryGetItem("DestinationMonitor")) != null) { if (int.TryParse(item.Value, out monitor) && monitor > 0) { _props.DestinationMonitor = monitor; } } }
public void Load(WidgetConfig config) { bool value; WidgetConfigItem item; if ((item = config.TryGetItem("Horizontal")) != null) { if (bool.TryParse(item.Value, out value)) { _props.Horizontal = value; } } if ((item = config.TryGetItem("Vertical")) != null) { if (bool.TryParse(item.Value, out value)) { _props.Vertical = value; } } }
public ContextualWidget(WidgetConfig widgetConfig, TWidgetContext context = null) : base(widgetConfig) { m_Context = context; }
public void Save(WidgetConfig config) { _props.Save(config); }
public void Load(WidgetConfig config) { _props.Load(config); }
void ShowError(string error) { EndStandBy(); WidgetConfig msgConfig = new WidgetConfig( 0.0f, -0.2f, 1.0f, 0.2f, 35, error); GuiLabel(msgConfig); if (GuiButton(OkButtonCfg)) { RaceManager.Instance.CleanUp(); gameObject.GetComponent<MainMenuGui>().MakeActive(); } }
public Widget(WidgetConfig widgetConfig) { m_WidgetConfig = widgetConfig; UpdateFromConfig(); }
protected void GuiLabel(WidgetConfig config) { GuiLabel(config, null); }
protected bool GuiButton(WidgetConfig config) { return GuiButton(config, null); }
private Rect GetWidgetRect(WidgetConfig cfg) { float centerY = cfg.Anchor == WidgetConfig.WidgetAnchor.Top ? GetScreenTop() + cfg.CenterY : cfg.Anchor == WidgetConfig.WidgetAnchor.Bottom ? GetScreenBottom () + cfg.CenterY : cfg.CenterY; return CenteredRect(cfg.CenterX, centerY, cfg.Width, cfg.Height); }
protected bool GuiButton(WidgetConfig config) { return(GuiButton(config, null)); }