private void WidgetHosts_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Add) { foreach (IWidgetHost host in e.NewItems) { WidgetDescriptor descriptor = GetDescriptor(host.Widget); ScatterViewItem viewItem = (ScatterViewItem)host; Point position = descriptor.Position; Binding binding = new Binding("Position"); binding.Source = descriptor; binding.Mode = BindingMode.OneWayToSource; viewItem.SetBinding(ScatterViewItem.CenterProperty, binding); _scatterView.Items.Add(host); viewItem.Center = position; } } if (e.Action == NotifyCollectionChangedAction.Remove) { foreach (var newItem in e.OldItems) { _scatterView.Items.Remove(newItem); } } }
private void OnWidgetDrop(object sender, DragEventArgs e) { WidgetDescriptor descriptor = (WidgetDescriptor)e.Data.GetData(WidgetDataFormat); Point mousePositionInCanvas = e.GetPosition(widgetContainer); descriptor.Position = mousePositionInCanvas; descriptor.ZIndex = 100; descriptor.IsActive = true; }
private WidgetViewContext GetWidgetViewContext(WidgetDescriptor widget, HtmlEncoder htmlEncoder) { var viewDescriptior = _widgetComponentFactory.Create(widget); return(new WidgetViewContext(viewDescriptior, null, ViewContext, htmlEncoder, ViewContext.Writer) { ComponentDescriptor = viewDescriptior, }); }
/// <summary> /// Create and add widget to collection parent page by specified widget descriptor, zone id and position. /// </summary> /// <param name="descriptor">The widget descriptor</param> /// <param name="zoneID">The widget zone id.</param> /// <param name="pos">The widget position.</param> /// <returns>A new widget instance object.</returns> public WidgetInstanceDecorator Add(WidgetDescriptor descriptor, string zoneID, int pos) { if (descriptor == null) { throw new Exception("Widget descriptor not found."); } var widget = DataContext.Widgets.AddWidget(descriptor, ParentPage.ID, zoneID, pos); DataContext.SaveChanges(); return(new WidgetInstanceDecorator(widget, DataContext.Widgets)); }
/// <summary> /// Create the Widget Instance by specified widget descriptor ,the web page visual path ,the zone element id and the position in widgets sequence. /// </summary> /// <param name="id">The new widget id.</param> ///<param name="descriptor">The WidgetDescriptor instance.</param> /// <param name="webPagePath">Specified the web page path to added</param> /// <param name="zoneID">The zone element id</param> /// <param name="position"> The position in widgets sequence</param> /// <returns>A new Widget instance.</returns> public virtual WidgetInstance AddWidget(WidgetDescriptor descriptor, int pageID, string zoneID, int position) { int pos = 0; if (position > -1) { pos = position; } if (descriptor == null) { throw new ArgumentNullException("descriptor"); } if (pageID == 0) { throw new ArgumentNullException("pageID"); } if (string.IsNullOrEmpty(zoneID)) { throw new ArgumentNullException(zoneID); } WebPage page = Context.WebPages.Find(pageID); if (page == null) { throw new WebPageNotFoundException(); } var widgetsForUpdate = DbSet.Where(w => w.PageID == page.ID && (w.ZoneID == zoneID)) .OrderBy(w => w.Pos) .ToList(); if (widgetsForUpdate != null) { for (var i = 0; i < widgetsForUpdate.Count; i++) { var _w = widgetsForUpdate[i]; _w.Pos = i; if (i >= pos) { _w.Pos = i + 1; } } if (IsOwnContext) { Context.SaveChanges(); } } WidgetInstance widget = new WidgetInstance() { //ID = id, IsExpanded = true, Pos = pos, ZoneID = zoneID }; ///TODO:We need to load the localization contents from package which descriptor refers to. //widget.IconUrl = descriptor.IconUrl; widget.Title = descriptor.Title; widget.Locale = page.Locale; widget.Data = descriptor.Defaults; widget.ViewMode = descriptor.ViewModes; widget.ShowHeader = true; widget.ShowBorder = true; widget.IsExpanded = true; widget.WidgetDescriptor = descriptor; widget.WebPage = page; widget.CssText = ""; //widget.Cached = descriptor.CacheEnabled; if (!descriptor.DefaultLocale.Equals(page.Locale)) { var locName = descriptor.LocaleName(page.Locale); if (!string.IsNullOrEmpty(locName.FullName)) { widget.Title = locName.FullName; } //var locDesc=descriptor.LocaleDesc(page.Locale); //if (!string.IsNullOrEmpty(locDesc)) // widget. } if (descriptor.Height > 0) { widget.BodyCssText = "height:" + descriptor.Height.ToString() + "px;"; } if (descriptor.ViewModes == "floating" && descriptor.Width > 0) { widget.CssText += "position:absolute;top:0px;left:0px;"; widget.BodyCssText = "width" + descriptor.Width + "px;"; } try { if (!string.IsNullOrEmpty(descriptor.Defaults)) { var serializer = new JavaScriptSerializer(); var defaults = serializer.Deserialize <List <Dictionary <string, object> > >(descriptor.Defaults); foreach (var def in defaults) { var name = def["name"].ToString(); if (name.Equals("showHeader", StringComparison.OrdinalIgnoreCase) || name.Equals("sys_header", StringComparison.OrdinalIgnoreCase)) { widget.ShowHeader = (bool)def["value"]; } if (name.Equals("showBorder", StringComparison.OrdinalIgnoreCase) || name.Equals("sys_border", StringComparison.OrdinalIgnoreCase)) { widget.ShowBorder = (bool)def["value"]; } if (name.Equals("transparent", StringComparison.OrdinalIgnoreCase) || name.Equals("sys_tran", StringComparison.OrdinalIgnoreCase)) { widget.Transparent = (bool)def["value"]; } if (name.Equals("cached", StringComparison.OrdinalIgnoreCase) || name.Equals("sys_cached", StringComparison.OrdinalIgnoreCase)) { widget.Cached = (bool)def["value"]; } if (name.Equals("showIn", StringComparison.OrdinalIgnoreCase) || name.Equals("sys_shows", StringComparison.OrdinalIgnoreCase)) { widget.ShowMode = (int)def["value"]; } //if (name.Equals("sys_height", StringComparison.OrdinalIgnoreCase)) //widget.Height = (int)def["value"]; //if (name.Equals("sys_width", StringComparison.OrdinalIgnoreCase)) //widget.Width = (int)def["value"]; } } } catch (Exception e) { throw new Exception("Deserialize " + descriptor.Title + " widget default values error.The default value definition is not correct. Please check your widget config.xml."); } Create(widget); return(widget); }
/// <summary> /// Initializes a new instance of the WidgetDescriptorDecorator class with given widget descriptor and data context object. /// </summary> /// <param name="descriptor">The widget descriptor</param> /// <param name="context">The data context.</param> public WidgetDescriptorDecorator(WidgetDescriptor descriptor, IDataContext context) { Model = descriptor; descriptor.CopyTo(this, new string[] { "Widgets", "Roles" }); Context = context; }
public static void SetDescriptor(DependencyObject obj, WidgetDescriptor value) { obj.SetValue(DescriptorProperty, value); }
private WidgetDescriptorDecorator Register(WidgetPackage package) { if (package != null) { #region For common properties var widget = package.Locale(package.Model.DefaultLocale); var descriptor = new WidgetDescriptor() { UID = widget.ID, InstalledPath = package.Category + "\\" + package.Name, Version = widget.Version, Name = widget.Name.ShortName, Title = widget.Name.FullName, Description = widget.Description, ContentType = widget.Content != null ? widget.Content.ContentType : "application/x-ms-aspnet", ContentUrl = widget.Content != null ? widget.Content.Source : "", ContentDirection = widget.Content != null ? widget.Content.Direction : "ltr", ContentText = widget.Content != null ? widget.Content.Text : "", Width = widget.Width, Height = widget.Height, ViewModes = widget.ViewModes, Author = widget.Author != null ? widget.Author.Name : "", AuthorEmail = widget.Author != null ? widget.Author.Email : "", AuthorHomePage = widget.Author != null ? widget.Author.Uri : "", Encoding = widget.Content != null ? widget.Content.Encoding : "utf-8", ConfigXml = package.ConfigXml, DefaultLocale = widget.DefaultLocale, Modified = DateTime.Now, IconUrl = (widget.Icons != null && widget.Icons.Count > 0) ? package.ResolveUri(widget.Icons.First().Source) : "" }; var langs = package.GetSupportLanguages(); if (langs != null && langs.Count() > 0) { descriptor.Locales = string.Join(",", langs); } if (widget.Preferences != null && widget.Preferences.Count > 0) { var items = new List <string>(); foreach (DNA.Xml.Widgets.PreferenceElement p in widget.Preferences) { items.Add("{name:\"" + p.Name + "\",readonly:" + p.IsReadonly.ToString().ToLower() + ",value:" + (string.IsNullOrEmpty(p.Value) ? "\"\"" : p.Value) + "}"); } var jsonStr = "[" + string.Join(",", items.ToArray()) + "]"; descriptor.Defaults = jsonStr; } #endregion //Get widget type var widgetType = WidgetTypes.W3CWidget; if (widget.Features != null && widget.Features.Count > 0) { var extFeature = widget.Features.FirstOrDefault(f => f.IsRequried && f.Name.Equals("mvc")); if (extFeature != null) { widgetType = WidgetTypes.ServerWidget; var area = extFeature.Params != null ? (extFeature.Params.FirstOrDefault(f => f.Name.Equals("area", StringComparison.OrdinalIgnoreCase))) : null; var ctrl = extFeature.Params != null ? (extFeature.Params.FirstOrDefault(f => f.Name.Equals("controller", StringComparison.OrdinalIgnoreCase))) : null; var act = extFeature.Params != null ? (extFeature.Params.FirstOrDefault(f => f.Name.Equals("action", StringComparison.OrdinalIgnoreCase))) : null; if (area != null) { descriptor.Area = area.Value; } if (ctrl != null) { descriptor.Controller = ctrl.Value; } if (act != null) { descriptor.Action = act.Value; } } widgetType = WidgetTypes.ServerWidget; } if (widget.Content != null) { if (widget.Content.ContentType == "application/x-ms-aspnet") { widgetType = WidgetTypes.ServerWidget; } } descriptor.WidgetType = (int)widgetType; DataContext.WidgetDescriptors.Create(descriptor); DataContext.SaveChanges(); return(new WidgetDescriptorDecorator(descriptor, DataContext)); } return(null); }
public Widget(WidgetDescriptor descriptor, Lazy <IWidgetRenderer> render) : base(descriptor, render) { }
protected WidgetBase(WidgetDescriptor descriptor, Lazy <IWidgetRenderer> renderer) { Descriptor = descriptor; _renderer = renderer; Settings = new Dictionary <string, string>(); }