示例#1
0
        public WidgetBase CreateWidgetViewModel(WidgetBase widget)
        {
            if (widget == null)
            {
                throw new Exception($"Fail to create widget service. Because the widget is null.");
            }
            string key = $"{widget.AssemblyName},{widget.ViewModelTypeName}";

            if (WidgetBase.KnownWidgetModel.ContainsKey(key))
            {
                return(widget.CopyTo(_serviceProvider.GetService(WidgetBase.KnownWidgetModel[key]) as WidgetBase));
            }
            else
            {
                var template = _serviceProvider.GetService <IWidgetTemplateService>().Get(m => m.PartialView == widget.PartialView).FirstOrDefault();
                if (template != null)
                {
                    widget.AssemblyName      = template.AssemblyName;
                    widget.ServiceTypeName   = template.ServiceTypeName;
                    widget.ViewModelTypeName = template.ViewModelTypeName;
                    key = $"{widget.AssemblyName},{widget.ServiceTypeName}";
                    if (WidgetBase.KnownWidgetService.ContainsKey(key))
                    {
                        return(widget.CopyTo(_serviceProvider.GetService(WidgetBase.KnownWidgetModel[key]) as WidgetBase));
                    }
                }
            }
            throw new Exception($"Fail to create {key} instance. May be the plugin is not exists or not regist.");
        }
        public WidgetBase CreateWidgetViewModel(WidgetBase widget)
        {
            string     key       = $"{widget.AssemblyName},{widget.ViewModelTypeName}";
            WidgetBase viewModel = null;

            if (WidgetBase.KnownWidgetModel.ContainsKey(key))
            {
                viewModel = _serviceProvider.GetService(WidgetBase.KnownWidgetModel[key]) as WidgetBase;
            }
            else
            {
                var template = _serviceProvider.GetService <IWidgetTemplateService>().Get(m => m.PartialView == widget.PartialView).FirstOrDefault();
                if (template != null)
                {
                    widget.AssemblyName      = template.AssemblyName;
                    widget.ServiceTypeName   = template.ServiceTypeName;
                    widget.ViewModelTypeName = template.ViewModelTypeName;
                    key = $"{widget.AssemblyName},{widget.ServiceTypeName}";
                    if (WidgetBase.KnownWidgetService.ContainsKey(key))
                    {
                        viewModel = _serviceProvider.GetService(WidgetBase.KnownWidgetModel[key]) as WidgetBase;
                    }
                }
            }
            return(viewModel == null ? null : widget.CopyTo(viewModel));
        }
示例#3
0
        public virtual WidgetBase GetWidget(WidgetBase widget)
        {
            T result = base.Get(widget.ID);

            if (result != null)
            {
                widget.CopyTo(result);
            }
            if (result == null)
            {
                throw new Exception("Get widget error. Widget ID:" + widget.ID);
            }
            return(result);
        }
        public virtual WidgetBase GetWidget(WidgetBase widget)
        {
            T result = Get().FirstOrDefault(m => m.ID == widget.ID);

            if (result != null)
            {
                widget.CopyTo(result);
            }
            if (result == null)
            {
                throw new Exception("Get widget error. Widget ID:" + widget.ID);
            }
            return(result);
        }
示例#5
0
        public virtual WidgetBase GetWidget(WidgetBase widget)
        {
            T result = base.Get(widget.ID);

            if (result != null)
            {
                widget.CopyTo(result);
                return(result);
            }
            var basePart = widget.ToWidgetBasePart();

            DbContext.WidgetBasePart.Attach(basePart);
            DbContext.WidgetBasePart.Remove(basePart);
            DbContext.SaveChanges();
            return(null);
        }
示例#6
0
 public override WidgetBase GetWidget(WidgetBase widget)
 {
     return(widget.CopyTo(JsonConvert.DeserializeObject <T>(widget.ExtendData ?? "{}")) as T);
 }