Exemplo n.º 1
0
        private void TrimDataModel(IModelContainer container)
        {
            foreach (IModelInstance instance in container.Instances)
            {
                var deletedValues = instance.Values.Where(it => it.ObjectState == ObjectState.Deleted).ToList();

                while (deletedValues.Any())
                {
                    instance.Values.Remove(deletedValues.First());
                    deletedValues.Remove(deletedValues.First());
                }

                if (instance.ObjectState != ObjectState.Deleted)
                {
                    instance.MarkUnmodified();
                }
            }

            foreach (IModelContainer childContainer in container.ChildContainers)
            {
                TrimDataModel(childContainer);
            }

            var deletedInstances = container.Instances.GroupJoin(container.ChildContainers.SelectMany(it => it.Instances), left => left.InstanceID, right => right.ParentInstanceID, (left, right) => new { Parent = left, Children = right }).Where(it => !it.Children.Any()).Select(it => it.Parent).Where(it => it.ObjectState == ObjectState.Deleted).ToList();

            while (deletedInstances.Any())
            {
                container.Instances.Remove(deletedInstances.First());
                deletedInstances.Remove(deletedInstances.First());
            }

            container.MarkUnmodified();
        }
Exemplo n.º 2
0
        public ActionResult UpdateAttribute(AttributeViewModel postedModel)
        {
            MetadataModel metadata = TempData["Metadata"] as MetadataModel;

            IModelContainer eavContainer = FindContainer(metadata.CurrentContext.Containers, postedModel.ContainerID);
            IModelAttribute eavAttribute = eavContainer.Attributes.Single(it => it.AttributeID == postedModel.ID);

            if (UpdateRequested)
            {
                eavAttribute.Name        = postedModel.Name;
                eavAttribute.DataName    = postedModel.DataName;
                eavAttribute.DisplayText = postedModel.DisplayText;
                eavAttribute.DataType    = postedModel.DataType;
                eavAttribute.IsKey       = postedModel.IsKey;
            }
            else if (eavAttribute.ObjectState == ObjectState.New && (String.IsNullOrWhiteSpace(eavAttribute.Name) || (String.IsNullOrWhiteSpace(eavAttribute.DataName))))
            {
                eavContainer.Attributes.Remove(eavAttribute);
            }

            TempData["Metadata"] = metadata;

            if (eavContainer is IModelRootContainer)
            {
                return(BuildResult("Container Editor", Url.Content("~/Metadata/ContainerEditorDialog"), Url.Content("~/Metadata/UpdateRootContainer"), null));
            }
            else
            {
                return(BuildResult("Container Editor", Url.Content("~/Metadata/ContainerEditorDialog"), Url.Content("~/Metadata/UpdateChildContainer"), null));
            }
        }
Exemplo n.º 3
0
        public ActionResult DeleteAttribute(ContainerViewModel postedModel)
        {
            MetadataModel metadata = TempData["Metadata"] as MetadataModel;

            metadata.DialogStack.Push(postedModel);

            IModelContainer eavContainer = FindContainer(metadata.CurrentContext.Containers, postedModel.ID);
            IModelAttribute eavAttribute = eavContainer.Attributes.Single(it => it.AttributeID == ID);

            if (eavAttribute.ObjectState != ObjectState.New)
            {
                eavAttribute.MarkDeleted();
            }
            else
            {
                eavContainer.Attributes.Remove(eavAttribute);
            }

            TempData["Metadata"] = metadata;

            if (eavContainer is IModelRootContainer)
            {
                return(BuildResult("Container Editor", Url.Content("~/Metadata/ContainerEditorDialog"), Url.Content("~/Metadata/UpdateRootContainer"), null));
            }
            else
            {
                return(BuildResult("Container Editor", Url.Content("~/Metadata/ContainerEditorDialog"), Url.Content("~/Metadata/UpdateChildContainer"), null));
            }
        }
Exemplo n.º 4
0
 public ExpressionFactory(IModelContainer <TEntity> modelContainer)
 {
     this.modelContainer    = modelContainer;
     this.PrimaryKeyFilters = this.modelContainer.PrimaryKey.Properties
                              .Select(SelectPrimaryKeyBuilder)
                              .ToImmutableList();
     this.FilterExpressions = this.modelContainer.Properties
                              .ToDictionary(p => p.Name, SelectFilterBuilder);
     this.OrderByExpressions = this.modelContainer.Properties
                               .Select(SelectOrderByBuilder)
                               .ToImmutableList();
     this.DeclaredProperties = this.modelContainer.Properties
                               .Where(p => !p.IsShadowProperty && !p.IsForeignKey())
                               .ToImmutableList();
 }
Exemplo n.º 5
0
        public ContainerViewModel(IModelContainer container)
        {
            ID          = container.ContainerID.GetValueOrDefault();
            ParentID    = container.ParentContainerID.GetValueOrDefault();
            Name        = container.Name;
            DataName    = container.DataName;
            DisplayText = container.DisplayText;
            IsRepeating = container.IsRepeating;
            Sequence    = container.Sequence;

            childContainers = new List <ContainerViewModel>();
            InitializeContainers(container.ChildContainers);

            attributes = new List <AttributeViewModel>();
            InitializeAttributes(container.Attributes);
        }
Exemplo n.º 6
0
        public ActionResult EditAttribute(ContainerViewModel postedModel)
        {
            MetadataModel metadata = TempData["Metadata"] as MetadataModel;

            metadata.DialogStack.Push(postedModel);

            IModelContainer eavContainer = FindContainer(metadata.CurrentContext.Containers, postedModel.ID);
            IModelAttribute eavAttribute = eavContainer.Attributes.Single(it => it.AttributeID == ID);

            metadata.DialogStack.Push(new AttributeViewModel(eavAttribute)
            {
                Existing = true
            });

            TempData["Metadata"] = metadata;

            return(BuildResult("Attribute Editor", Url.Content("~/Metadata/AttributeEditorDialog"), Url.Content("~/Metadata/UpdateAttribute"), null));
        }
Exemplo n.º 7
0
        public static ViewModelInstance Create(IModelContainer container, IModelSubject subject, IModelInstance instance, ViewModelInstance parentInstance, ref int nextInstanceID)
        {
            ViewModelInstance viewInstance = new ViewModelInstance()
            {
                ObjectState = instance != null ? instance.ObjectState : ObjectState.New, ContainerID = container.ContainerID, SubjectID = subject != null ? subject.SubjectID : 0, InstanceID = instance != null ? instance.InstanceID : nextInstanceID--, ParentInstanceID = parentInstance != null ? parentInstance.InstanceID : null
            };

            foreach (EAV.Model.IModelAttribute attribute in container.Attributes.OrderBy(it => it.Sequence))
            {
                viewInstance.Values.Add(ViewModelAttributeValue.Create(attribute, instance != null ? instance.Values.SingleOrDefault(it => it.AttributeID == attribute.AttributeID) : null));
            }

            foreach (IModelChildContainer childContainer in container.ChildContainers.OrderBy(it => it.Sequence))
            {
                viewInstance.ChildContainers.Add(ViewModelContainer.Create(childContainer, subject, viewInstance, ref nextInstanceID));
            }

            return(viewInstance);
        }
Exemplo n.º 8
0
        public ActionResult EditChildContainer(ContainerViewModel postedModel)
        {
            MetadataModel metadata = TempData["Metadata"] as MetadataModel;

            postedModel.FixupContainerOrder();
            postedModel.FixupAttributeOrder();
            metadata.DialogStack.Push(postedModel);

            IModelContainer eavContainer = FindContainer(metadata.CurrentContext.Containers, ID);

            metadata.DialogStack.Push(new ContainerViewModel(eavContainer)
            {
                Existing = true
            });

            TempData["Metadata"] = metadata;

            return(BuildResult("Container Editor", Url.Content("~/Metadata/ContainerEditorDialog"), Url.Content("~/Metadata/UpdateChildContainer"), null));
        }
Exemplo n.º 9
0
        public ActionResult AddAttribute(ContainerViewModel postedModel)
        {
            MetadataModel metadata = TempData["Metadata"] as MetadataModel;

            metadata.DialogStack.Push(postedModel);

            IModelContainer eavContainer = FindContainer(metadata.CurrentContext.Containers, postedModel.ID);
            IModelAttribute eavAttribute = objectFactory.Create <EAV.Model.IModelAttribute>();

            eavAttribute.AttributeID = metadata.NextAttributeID;
            eavAttribute.Container   = eavContainer;
            eavAttribute.Sequence    = eavContainer.Attributes.Max(it => it.Sequence) + 1;

            metadata.DialogStack.Push(new AttributeViewModel(eavAttribute));

            TempData["Metadata"] = metadata;

            return(BuildResult("Attribute Editor", Url.Content("~/Metadata/AttributeEditorDialog"), Url.Content("~/Metadata/UpdateAttribute"), null));
        }
Exemplo n.º 10
0
        static async Task ProcessModelsAsync(ModelOptions options, IModelContainer container)
        {
            string dir = options.InputFile + ".models";

            Directory.CreateDirectory(dir);

            for (int i = 0; i < container.ModelCount; i++)
            {
                var model = await container.GetModelAsync(i);

                WriteLine($"Found model #{i}; Extracting to OBJ...");

                string filePath = Path.Combine(dir, $"model_{i}.obj");
                using (var writer = File.CreateText(filePath))
                {
                    await model.WriteToOBJAsync(writer);
                }

                WriteLine($"Conversion successful! Wrote output to file: {filePath}", OutputImportance.Verbose);
            }
        }
Exemplo n.º 11
0
        public ActionResult AddChildContainer(ContainerViewModel postedModel)
        {
            MetadataModel metadata = TempData["Metadata"] as MetadataModel;

            postedModel.FixupContainerOrder();
            postedModel.FixupAttributeOrder();
            metadata.DialogStack.Push(postedModel);

            IModelContainer      eavParentContainer = FindContainer(metadata.CurrentContext.Containers, postedModel.ID);
            IModelChildContainer eavChildContainer  = objectFactory.Create <EAV.Model.IModelChildContainer>();

            eavChildContainer.ContainerID     = metadata.NextContainerID;
            eavChildContainer.ParentContainer = eavParentContainer;
            eavChildContainer.Sequence        = eavParentContainer.ChildContainers.Max(it => it.Sequence) + 1;

            metadata.DialogStack.Push(new ContainerViewModel(eavChildContainer));

            TempData["Metadata"] = metadata;

            return(BuildResult("Container Editor", Url.Content("~/Metadata/ContainerEditorDialog"), Url.Content("~/Metadata/UpdateChildContainer"), null));
        }
Exemplo n.º 12
0
 public AccountController(IModelContainer ModelContainer)
 {
     repo = new Repository(ModelContainer);
 }
 public CustomNavigationService(IModelContainer <CelestialObjectTypeModel> page)
     : base((Page)page)
 {
 }
Exemplo n.º 14
0
 public ModelContainer(IModelContainer container)
 {
     this.container = container;
 }
Exemplo n.º 15
0
        /// <summary>
        /// Mapping generic interface I to generic destination type D and returns <see cref="IActionResult"/> acording <see cref="ModelContainer&lt;T&gt;.ResponseStatusCode"/>
        /// </summary>
        /// <typeparam name="I"></typeparam>
        /// <typeparam name="D"></typeparam>
        /// <param name="modelContainer"></param>
        /// <returns></returns>
        public ActionResult ApiActionResult <I, D>(IModelContainer <I> modelContainer) where D : I
        {
            var mappedResponseModel = modelContainer.Model.Map <I, D>();

            return(ApiActionResult(mappedResponseModel, modelContainer.ResponseStatusCode, modelContainer.ErrorMessage));
        }
Exemplo n.º 16
0
 public Repository(IModelContainer ModelContainer)
 {
     modelContainer = ModelContainer;
 }
Exemplo n.º 17
0
 public BookController(IModelContainer ModelContainer)
 {
     repo = new Repository(ModelContainer);
 }
Exemplo n.º 18
0
        /// <summary>
        /// Mapps generic interface IEnumerable&lt;I&gt; to generic destination type List&lt;D&gt; and returns appropriate <see cref="IActionResult"/> acording <see cref="ModelContainer&lt;T&gt;.ResponseStatusCode"/>
        /// </summary>
        /// <typeparam name="SourceInterface"></typeparam>
        /// <typeparam name="DestinationType"></typeparam>
        /// <param name="modelContainer"></param>
        /// <returns></returns>
        public ActionResult ApiActionResult <SourceInterface, DestinationType>(IModelContainer <IEnumerable <SourceInterface> > modelContainer) where DestinationType : SourceInterface
        {
            var mappedResponseModel = modelContainer.Model.Map <SourceInterface, DestinationType>();

            return(ApiActionResult <IEnumerable <DestinationType> >(mappedResponseModel, modelContainer.ResponseStatusCode, modelContainer.ErrorMessage));
        }
Exemplo n.º 19
0
 public ServicesProvider(IModelContainer model)
 {
     _model = model;
 }
Exemplo n.º 20
0
        public virtual void AfterPropertiesSet(IBeanContextFactory beanContextFactory)
        {
            ParamChecker.AssertNotNull(RevertChangesHelper, "RevertChangesHelper");
            ParamChecker.AssertNotNull(SharedData, "SharedData");
            ParamChecker.AssertNotNull(SharedDataHandOnExtendable, "SharedDataHandOnExtendable");

            //TODO: inject Uri as bean
#if SILVERLIGHT
            Uri uri = HtmlPage.Document.DocumentUri;
#else
            Uri uri = null;
            if (uri == null)
            {
                throw new NotSupportedException("This code has to be compatible with .NET first");
            }
#endif

            ISet <String> allBeanNames = new HashSet <String>();
            if (BeansToConsume != null)
            {
                allBeanNames.UnionWith(BeansToConsume.Keys);
            }

            IDictionary <String, IModelContainer> data = null;
            if (Token != null)
            {
                data = SharedData.Read(Token);
            }
            if (data == null)
            {
                // Clear token to suppress handsOn in afterStarted()
                Token = null;
                data  = new Dictionary <String, IModelContainer>();
            }
            IModelMultiContainer <Uri> uriList = (IModelMultiContainer <Uri>)DictionaryExtension.ValueOrDefault(data, SourceUriBeanName);
            if (uriList != null)
            {
                //Url-list is avaliable
                uriList.Values.Add(uri);
            }
            allBeanNames.UnionWith(data.Keys);

            if (!allBeanNames.Contains(SourceUriBeanName))
            {
                //Url-list is not avaliable
                beanContextFactory.RegisterBean <ModelMultiContainer <Uri> >(SourceUriBeanName).PropertyValue("Value", uri);
            }

            IdentityHashSet <Object> allProvidedBusinessObjects = new IdentityHashSet <Object>();
            foreach (String nameInOwnContext in allBeanNames)
            {
                //Proecess the input
                IModelContainer dataContainer = DictionaryExtension.ValueOrDefault(data, nameInOwnContext);
                if (dataContainer != null)
                {
                    if (dataContainer is IModelMultiContainer)
                    {
                        IEnumerable businessObjects = ((IModelMultiContainer)dataContainer).ValuesData;
                        if (businessObjects != null)
                        {
                            allProvidedBusinessObjects.AddAll(businessObjects.Cast <object>());
                        }
                    }
                    else if (dataContainer is IModelSingleContainer)
                    {
                        Object businessObject = ((IModelSingleContainer)dataContainer).ValueData;
                        if (businessObject != null)
                        {
                            allProvidedBusinessObjects.Add(businessObject);
                        }
                    }
                    //By copying only the data, listeners are unregistered
                    //beanContextFactory.registerBean(name, dataContainer.GetType()).propertyValue("Data", dataContainer.Data);
                    beanContextFactory.RegisterExternalBean(nameInOwnContext, dataContainer);
                    continue;
                }
                if (!BeansToConsume.ContainsKey(nameInOwnContext))
                {
                    continue;
                }
                //Process default-beans
                String aliasToDefaultBean = BeansToConsume[nameInOwnContext];
                if (aliasToDefaultBean == null)
                {
                    //Mandatory parameter was not present in data
                    throw new Exception("The new Screen has not all mandatory information: \"" + nameInOwnContext + "\" is missing.");
                }
                if (!nameInOwnContext.Equals(aliasToDefaultBean))
                {
                    beanContextFactory.RegisterAlias(nameInOwnContext, aliasToDefaultBean);
                }
            }
            if (allProvidedBusinessObjects.Count > 0)
            {
                IRevertChangesSavepoint savepoint = RevertChangesHelper.CreateSavepoint(allProvidedBusinessObjects);
                beanContextFactory.RegisterExternalBean(savepoint).Autowireable <IRevertChangesSavepoint>();
            }
        }