protected static object GetInstanceOf(Type modelType, object key, ModelDescriptor descriptor)
 {
     var context = ModelAssemblies.GetContext(modelType);
     var set = context.Set(modelType);
     var instance = set.Find(Convert.ChangeType(key, descriptor.KeyProperty.PropertyType));
     return instance;
 }
 public ActionResult Edit(Type modelType, object key)
 {
     var mapping = ModelMappingManager.FindByType(modelType);
     var descriptor = new ModelDescriptor(mapping);
     var instance = GetInstanceOf(modelType, key, descriptor);
     if (instance == null)
         return HttpNotFound();
     return View(new Model(modelType, descriptor, instance));
 }
 public virtual ActionResult View(Type modelType, object key)
 {
     var mapping = ModelMappingManager.FindByType(modelType);
     var descriptor = new ModelDescriptor(mapping);
     var instance = GetInstanceOf(modelType, key, descriptor);
     if (instance == null)
         return HttpNotFound();
     return Json(instance, JsonRequestBehavior.AllowGet);
 }
 public ActionResult Edit(Type modelType, object key)
 {
     var mapping = ModelMappingManager.MappingFor(modelType);
     var descriptor = new ModelDescriptor(mapping);
     var instance = GetInstanceOf(modelType, key, descriptor);
     if (instance == null)
         return HttpNotFound();
     var model = new Model(modelType, descriptor, instance);
     return !ControllerContext.IsChildAction ? (ActionResult)View(model) : PartialView(model);
 }
Example #5
0
        private static Select ParseSelect(Type modelType, QueryAttribute spec)
        {
            var select = new Select();
            var descriptor = new ModelDescriptor(ModelMappingManager.FindByType(modelType));
            var properties = descriptor.GetProperties().OfType<PropertyDescriptor>();

            select.Properties.AddRange(properties);
            if (!string.IsNullOrEmpty(spec.Select))
            {
                select.Properties.Clear();
                var propertyNames = spec.Select.Split(Select.Separator);
                foreach (var propertyName in propertyNames)
                {
                    var property = properties.FirstOrDefault(p => p.Name == propertyName);
                    if (property != null)
                        select.Properties.Add(property);
                }
            }
            return select;
        }
 protected override Task OnInitialize(ModelDescriptor modelDescriptor, Properties status)
 {
     this.modelDescriptor = modelDescriptor;
     return(base.OnInitialize(modelDescriptor, status));
 }
 public override Task <DocumentController> CreateController(ModelDescriptor modelDescriptor, DocumentControllerDescription controllerDescription)
 {
     return(Task.FromResult <DocumentController> (new ReusableController()));
 }
Example #8
0
 public QueryDescriptor(string queryName, Type queryModel, QueryModelAttribute attribute, ModelDescriptor modelDescriptor)
 {
     if (string.IsNullOrEmpty(queryName))
     {
         throw new ArgumentException($"{nameof(queryName)} is required", nameof(queryName));
     }
     QueryModel = queryModel ?? throw new ArgumentNullException(nameof(queryModel));
     if (attribute == null)
     {
         throw new ArgumentNullException(nameof(attribute));
     }
     ModelDescriptor = modelDescriptor ?? throw new ArgumentNullException(nameof(modelDescriptor));
     QueryName       = queryName.Trim().ToLower();
     SubNames        = attribute.SubNames?.Split(Separators, StringSplitOptions.RemoveEmptyEntries).Select(p => p.ToLower().Trim()).ToArray() ?? new string[0];
     Init(attribute);
 }
Example #9
0
 /// <summary>
 /// Tries to reuse this controler to display the content identified by the provide descriptor.
 /// </summary>
 /// <returns><c>true</c>, if the controller could be used to display the content, <c>false</c> otherwise.</returns>
 /// <param name="modelDescriptor">Model descriptor.</param>
 protected virtual bool OnTryReuseDocument(ModelDescriptor modelDescriptor)
 {
     return(false);
 }
Example #10
0
 public DataSourceModelDescriptorFactory(ModelDescriptor model)
 {
     this.model = model;
 }
        protected ActionResult DeleteInstanceOf(Type modelType, object key, Func<ActionResult> onSuccess, Func<Exception, ActionResult> onException, Func<ActionResult> onNotFound)
        {
            using (var context = ModelAssemblies.GetContext(modelType))
            {
                try
                {
                    var set = context.Set(modelType);
                    var descriptor = new ModelDescriptor(ModelMappingManager.FindByType(modelType));
                    var instance = set.Find(Convert.ChangeType(key, descriptor.KeyProperty.PropertyType));

                    if (instance == null)
                        return onNotFound();

                    set.Remove(instance);
                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                    return onException(ex);
                }
                return onSuccess();
            }
        }
 public SignalRHierarchicalDataSourceModelDescriptorFactory(ModelDescriptor model)
     : base(model)
 {
 }
        protected ActionResult ExecuteMethodOf(Type modelType, Method model, Func<ActionResult> onSuccess, Func<object, ActionResult> onSuccessWithReturn, Func<Exception, ActionResult> onException, Func<ActionResult> onNotFound, string key = null)
        {
            using (var context = ModelAssemblies.GetContext(modelType))
            {
                try
                {
                    object @return;
                    if (!model.Descriptor.Method.IsStatic)
                    {
                        var descriptor = new ModelDescriptor(ModelMappingManager.FindByType(modelType));
                        var set = context.Set(modelType);
                        var instance = set.Find(Convert.ChangeType(key, descriptor.KeyProperty.PropertyType));

                        if (instance == null)
                            return onNotFound();

                        @return = model.Invoke(instance);
                        context.SaveChanges();

                        if (@return == instance)
                            @return = null;
                    }
                    else
                        @return = model.Invoke(null);

                    if (@return != null)
                        return onSuccessWithReturn(@return);
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                    return onException(ex);
                }

                return onSuccess();
            }
        }
 public override Task <DocumentController> CreateController(ModelDescriptor modelDescriptor, DocumentControllerDescription controllerDescription)
 {
     return(CreateController((FileDescriptor)modelDescriptor, controllerDescription));
 }
Example #15
0
 protected override Task OnInitialize(ModelDescriptor modelDescriptor, Properties status)
 {
     TabPageLabel = GettextCatalog.GetString("Desktop Entry");
     return(base.OnInitialize(modelDescriptor, status));
 }
Example #16
0
        protected override async Task OnInitialize(ModelDescriptor modelDescriptor, Properties status)
        {
            await _inner.Initialize(modelDescriptor, status);

            await base.OnInitialize(modelDescriptor, status);
        }
Example #17
0
 protected override bool OnTryReuseDocument(ModelDescriptor modelDescriptor)
 {
     return(_inner.TryReuseDocument(modelDescriptor));
 }
Example #18
0
 public static string ToXml(this ModelDescriptor descriptor)
 {
     return(ToXml(descriptor.ToXml));
 }
Example #19
0
 public ReadOnlyCustomDataSourceModelDescriptorFactory(ModelDescriptor model)
     : base(model)
 {
 }
Example #20
0
        protected ActionResult DeleteInstanceOf(Type modelType, object key, Func<ActionResult> onSuccess, Func<Exception, ActionResult> onException, Func<ActionResult> onNotFound)
        {
            var mapping = ModelMappingManager.MappingFor(modelType);
            using (var repository = mapping.Configuration.Repository())
            {
                try
                {
                    var descriptor = new ModelDescriptor(ModelMappingManager.MappingFor(modelType));
                    var instance = repository.Find(GetKeyValues(key, descriptor));

                    if (instance == null)
                        return onNotFound();

                    repository.Remove(instance);
                    repository.SaveChanges();
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                    return onException(ex);
                }
                return onSuccess();
            }
        }
Example #21
0
        private IQueryable GetAppliedQuery()
        {
            if (Where != null)
                Source = (Parameters != null && Parameters.Count() > 0)
                    ? Source.Where(Where.Expression, Parameters)
                    : Source.Where(Where.Expression);

            if (OrderBy != null && OrderBy.Elements.Any())
            {
                var orderBy = string.Empty;
                foreach (var element in OrderBy.Elements)
                    orderBy += element.Key + " " + element.Value + ",";
                Source = Source.OrderBy(orderBy.Substring(0, orderBy.Length - 1));
            }
            else
            {
                var mapping = ModelMappingManager.FindByType(ModelType);
                var descriptor = new ModelDescriptor(mapping);
                Source = Source.OrderBy(descriptor.KeyProperty.Name + " Asc");
            }

            if (Skip != null)
                Source = Source.Skip(Skip.Value);

            if (Take != null)
                Source = Source.Take(Take.Value);

            if (!string.IsNullOrEmpty(Include))
                Source = Source.Include(Include);

            var data = (Select != null && Select.Properties.Any())
                           ? Source.Select(string.Format("new({0})", Select))
                           : Source;
            return data;
        }
 public CustomHierarchicalDataSourceModelDescriptorFactory(ModelDescriptor model, ViewContext viewContext, IUrlGenerator urlGenerator)
     : base(model)
 {
     this.viewContext  = viewContext;
     this.urlGenerator = urlGenerator;
 }
Example #23
0
 protected override IEnumerable <DocumentControllerDescription> GetSupportedControllers(ModelDescriptor modelDescriptor)
 {
     if (modelDescriptor is AssemblyBrowserDescriptor || (modelDescriptor is FileDescriptor file && (file.FilePath.HasExtension(".dll") || file.FilePath.HasExtension(".exe"))))
     {
         yield return(new DocumentControllerDescription(GettextCatalog.GetString("Assembly Browser"), true, DocumentControllerRole.Tool));
     }
 }
Example #24
0
 protected AbstractDatabase(ModelDescriptor <T> descriptor, DatabaseConfiguration config)
 {
     Descriptor = descriptor;
     Config     = config;
 }
Example #25
0
 public override Task <DocumentController> CreateController(ModelDescriptor modelDescriptor, DocumentControllerDescription controllerDescription)
 {
     return(Task.FromResult <DocumentController> (new AssemblyBrowserViewContent()));
 }
Example #26
0
 /// <summary>
 /// Initializes the controller
 /// </summary>
 /// <returns>The initialize.</returns>
 /// <param name="status">Status of the controller/view, returned by a GetDocumentStatus() call from a previous session. It can be null if status was not available.</param>
 protected virtual Task OnInitialize(ModelDescriptor modelDescriptor, Properties status)
 {
     return(Task.CompletedTask);
 }
Example #27
0
 internal bool TryReuseDocument(ModelDescriptor modelDescriptor)
 {
     return(controller.TryReuseDocument(modelDescriptor));
 }
Example #28
0
 /// <summary>
 /// Tries to reuse this controler to display the content identified by the provide descriptor.
 /// </summary>
 /// <returns><c>true</c>, if the controller could be used to display the content, <c>false</c> otherwise.</returns>
 /// <param name="modelDescriptor">Model descriptor.</param>
 public bool TryReuseDocument(ModelDescriptor modelDescriptor)
 {
     CheckInitialized();
     return(OnTryReuseDocument(modelDescriptor));
 }
Example #29
0
 public ModelDescriptor MergeToLhs(ModelDescriptor lhs, ModelDescriptor rhs)
 {
     TypeSystemWalker.Walk(rhs.RootNamespace, new ModelMergeTypeSystemEventHandler(lhs.RootNamespace, _logger));
     return(lhs);
 }
Example #30
0
 public DataSourceModelDescriptorFactory(ModelDescriptor model)
     : base(model)
 {
 }
Example #31
0
        protected ActionResult ExecuteMethodOf(Type modelType, Method model, Func<ActionResult> onSuccess, Func<object, ActionResult> onSuccessWithReturn, Func<Exception, ActionResult> onException, Func<ActionResult> onNotFound, string key = null)
        {
            var mapping = ModelMappingManager.MappingFor(modelType);
            using (var repository = mapping.Configuration.Repository())
            {
                try
                {
                    object @return;
                    if (!model.Descriptor.Method.IsStatic)
                    {
                        var descriptor = new ModelDescriptor(ModelMappingManager.MappingFor(modelType));
                        var instance = repository.Find(GetKeyValues(key, descriptor));

                        if (instance == null)
                            return onNotFound();

                        @return = model.Invoke(instance);
                        instance = repository.Update(instance);
                        repository.SaveChanges();

                        if (@return == instance)
                            @return = null;
                    }
                    else
                        @return = model.Invoke(null);

                    foreach (var parameter in model.Parameters.Where(p => (p.IsModel || p.IsModelCollection) && p.Value != null))
                    {
                        var paramRepository = parameter.UnderliningModel.Descriptor.ModelMapping.Configuration.Repository();
                        if (parameter.IsModelCollection)
                        {

                            //TODO:Update parameters from collection
                            //foreach (var paramItem in parameter.ToModelCollection().Items)
                            //{
                            //    paramRepository.Update(paramItem.Instance);
                            //}
                        }
                        else
                            paramRepository.Update(parameter.Value);
                        paramRepository.SaveChanges();
                    }

                    if (@return != null)
                        return onSuccessWithReturn(@return);
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                    return onException(ex);
                }

                return onSuccess();
            }
        }
 protected override IEnumerable <DocumentControllerDescription> GetSupportedControllers(ModelDescriptor modelDescriptor)
 {
     if (modelDescriptor is ReusableDescriptor)
     {
         yield return(new DocumentControllerDescription("Reusable", true, DocumentControllerRole.Tool));
     }
 }
Example #33
0
 private static object GetKeyValues(object key, ModelDescriptor descriptor)
 {
     var keyProperty = descriptor.KeyProperty;
     var keyValues = keyProperty.PropertyType == typeof(Guid)
                         ? Guid.Parse(key.ToString())
                         : Convert.ChangeType(key, keyProperty.PropertyType);
     return keyValues;
 }
Example #34
0
 public HierarchicalModelDescriptorBuilder(ModelDescriptor model, ViewContext viewContext, IUrlGenerator urlGenerator)
     : base(model)
 {
     this.urlGenerator = urlGenerator;
     this.viewContext  = viewContext;
 }
 public override Task <IEnumerable <DocumentControllerDescription> > GetSupportedControllersAsync(ModelDescriptor modelDescriptor)
 {
     if (modelDescriptor is FileDescriptor file)
     {
         return(GetSupportedControllersAsync(file));
     }
     else
     {
         return(Task.FromResult <IEnumerable <DocumentControllerDescription> > (Array.Empty <DocumentControllerDescription> ()));
     }
 }
Example #36
0
        private IQueryable GetAppliedQuery()
        {
            if (Source != null)
            {
                if (Filter != null)
                    Source = Filter.Apply(Source);

                if (Where != null)
                {
                    RunningObjectsSetup.Configuration.Query.ParseKeywords(this);
                    Source = (Parameters != null && Parameters.Any())
                                 ? Source.Where(Where.Expression, Parameters)
                                 : Source.Where(Where.Expression);
                }

                if (OrderBy != null && OrderBy.Elements.Any())
                {
                    var orderBy = OrderBy.Elements.Aggregate(string.Empty, (current, element) => current + (element.Key + " " + element.Value + ","));
                    Source = Source.OrderBy(orderBy.Substring(0, orderBy.Length - 1));
                }
                else
                {
                    var mapping = ModelMappingManager.MappingFor(ModelType);
                    var descriptor = new ModelDescriptor(mapping);

                    if (descriptor.Properties.Any())
                    {
                        var orderedProperty = descriptor.KeyProperty ??
                                              (descriptor.TextProperty ?? descriptor.Properties.FirstOrDefault());
                        if (orderedProperty != null)
                            Source = Source.OrderBy(orderedProperty.Name + " Asc");
                    }
                }

                if (Skip.HasValue)
                    Source = Source.Skip(Skip.Value);

                if (Take.HasValue)
                    Source = Source.Take(Take.Value);

                if(Select != null && Select.Properties.Any())
                    Source = Source.Select(string.Format("new({0})", Select));
            }
            return Source;
        }
 /// <summary>
 /// Checks if this factory can create a controller for the provided file, and returns the kind of
 /// controller it can create.
 /// </summary>
 protected virtual IEnumerable <DocumentControllerDescription> GetSupportedControllers(ModelDescriptor modelDescriptor)
 {
     throw new NotImplementedException();
 }
Example #38
0
        protected object ParseResult(Method model, object @return)
        {
            if (@return != null)
            {
                var method = model.Descriptor.Method as MethodInfo;
                if (method != null && method.ReturnType != typeof(void))
                {
                    var collectionType = method.ReturnType.GetInterface("IEnumerable`1");
                    if (collectionType != null)
                    {
                        var returnType = collectionType.GetGenericArguments()[0];
                        if (returnType != null && ModelMappingManager.Exists(returnType))
                        {
                            var mapping = ModelMappingManager.MappingFor(returnType);
                            var descriptor = new ModelDescriptor(mapping);
                            return new ModelCollection(returnType, descriptor, (IEnumerable)@return);
                        }
                    }

                    if (method.ReturnType == typeof(Redirect))
                        return @return;
                }
            }
            return null;
        }
 /// <summary>
 /// Checks if this factory can create a controller for the provided file, and returns the kind of
 /// controller it can create.
 /// </summary>
 public virtual Task <IEnumerable <DocumentControllerDescription> > GetSupportedControllersAsync(ModelDescriptor modelDescriptor)
 {
     return(Task.FromResult(GetSupportedControllers(modelDescriptor)));
 }
Example #40
0
 protected static object GetInstanceOf(Type modelType, object key, ModelDescriptor descriptor)
 {
     return ModelMappingManager.MappingFor(modelType).Configuration.Repository().Find(GetKeyValues(key, descriptor));
 }
 /// <summary>
 /// Creates a controller for editing the provided file
 /// </summary>
 public abstract Task <DocumentController> CreateController(ModelDescriptor modelDescriptor, DocumentControllerDescription controllerDescription);
        public ActionResult Index(Type modelType, int page = 1, int? size = null)
        {
            ViewBag.Exceptions = Exceptions;

            var query = GetQueryById(modelType) ?? GetDefaultQueryOf(modelType);
            return CacheableView("Index", query, () =>
            {
                var items = query.Execute(true);
                var count = items.Count();
                var quantity = size.HasValue ? size.Value : query.Paging ? query.PageSize : count;
                var fetched = items.Skip((page - 1) * quantity).Take(quantity);

                var mapping = ModelMappingManager.MappingFor(fetched.ElementType);
                var descriptor = new ModelDescriptor(mapping);

                return new ModelCollection(modelType, descriptor, fetched)
                {
                    PageCount = quantity > 0 ? (int)Math.Ceiling((decimal)count / quantity) : count,
                    PageNumber = page,
                    PageSize = quantity
                };
            },
            settings => settings.VaryByParam = "page;size");
        }
Example #43
0
 public Task <Document> OpenDocument(ModelDescriptor modelDescriptor, DocumentControllerRole?role = null, bool bringToFront = true)
 {
     return(documentManager.OpenDocument(modelDescriptor, role, bringToFront));
 }
Example #44
0
 protected override async Task OnInitialize(ModelDescriptor modelDescriptor, Properties status)
 {
     fileDescriptor = modelDescriptor as FileDescriptor;
     await base.OnInitialize(modelDescriptor, status);
 }
Example #45
0
 public ModelException(ModelDescriptor <T> m, string message = "") : base(message)
 {
     Model     = m;
     InnerType = typeof(T);
 }