Exemple #1
0
            public IUserAssetEntity GetEntity(Guid guid)
            {
                return(entities.GetOrCreate(guid, () =>
                {
                    var element = elements.GetOrThrow(guid);

                    Type type = UserAssetNames.GetOrThrow(element.Name.ToString());

                    var entity = giRetrieveOrCreate.GetInvoker(type)(guid);

                    entity.FromXml(element, this);

                    previews.Add(guid, new UserAssetPreviewLineEmbedded
                    {
                        Text = entity.ToString() !,
                        Type = entity.GetType().ToTypeEntity(),
                        Guid = guid,
                        Action = entity.IsNew ? EntityAction.New :
                                 customResolutionModel.ContainsKey(entity.Guid) ? EntityAction.Different :
                                 GraphExplorer.FromRoot((Entity)entity).Any(a => a.Modified != ModifiedState.Clean) ? EntityAction.Different :
                                 EntityAction.Identical,
                        CustomResolution = customResolutionModel.TryGetCN(entity.Guid),
                    });

                    return entity;
                }));
Exemple #2
0
    static void Validate <T>(IEnumerable <T> entities) where T : Entity
    {
#if DEBUG
        var errors = new List <IntegrityCheckWithEntity>();
        foreach (var e in entities)
        {
            var ic = e.FullIntegrityCheck();

            if (ic != null)
            {
                var withEntites = ic.WithEntities(GraphExplorer.FromRoots(entities));
                errors.AddRange(withEntites);
            }
        }
        if (errors.Count > 0)
        {
            throw new IntegrityCheckException(errors);
        }
#else
        var errors = new Dictionary <Guid, IntegrityCheck>();
        foreach (var e in entities)
        {
            var ic = e.FullIntegrityCheck();

            if (ic != null)
            {
                errors.AddRange(ic);
            }
        }
        if (errors.Count > 0)
        {
            throw new IntegrityCheckException(errors);
        }
#endif
    }
        public void CreateGraphExplorerCreates()
        {
            GraphExplorer ge = GraphExplorer.CreateGraphExplorer(new byte[] { 2, 2 },
                                                                 new byte[] { 1, 2, 3, 0 }, new char[] { 'l', 'r' });

            Assert.IsNotNull(ge);
        }
Exemple #4
0
        protected override string ChildPropertyValidation(ModifiableEntity sender, PropertyInfo pi)
        {
            if (sender is PanelPartEmbedded part)
            {
                if (pi.Name == nameof(part.StartColumn))
                {
                    if (part.StartColumn + part.Columns > 12)
                    {
                        return(DashboardMessage.Part0IsTooLarge.NiceToString(part));
                    }

                    var other = Parts.TakeWhile(p => p != part)
                                .FirstOrDefault(a => a.Row == part.Row && a.ColumnInterval().Overlaps(part.ColumnInterval()));

                    if (other != null)
                    {
                        return(DashboardMessage.Part0OverlapsWith1.NiceToString(part, other));
                    }
                }

                if (entityType != null && pi.Name == nameof(part.Content) && part.Content != null)
                {
                    var idents = GraphExplorer.FromRoot((Entity)part.Content).OfType <Entity>();

                    string errorsUserQuery = idents.OfType <IHasEntitytype>()
                                             .Where(uc => uc.EntityType != null && !uc.EntityType.Is(EntityType))
                                             .ToString(uc => DashboardMessage._0Is1InstedOf2In3.NiceToString(NicePropertyName(() => EntityType), uc.EntityType, entityType, uc),
                                                       "\r\n");

                    return(errorsUserQuery.DefaultText(null));
                }
            }

            return(base.ChildPropertyValidation(sender, pi));
        }
        public static Dictionary <Guid, IntegrityCheck> GetErrors(Modifiable mod)
        {
            var graph = GraphExplorer.PreSaving(() => GraphExplorer.FromRoot(mod));
            var error = GraphExplorer.FullIntegrityCheck(graph);

            return(error);
        }
Exemple #6
0
        Dictionary <Lite <RoleEntity>, RoleAllowedCache> NewCache()
        {
            using (AuthLogic.Disable())
                using (new EntityCache(EntityCacheType.ForceNewSealed))
                {
                    List <Lite <RoleEntity> > roles = AuthLogic.RolesInOrder().ToList();

                    var rules = Database.Query <RuleTypeEntity>().ToList();

                    var errors = GraphExplorer.FullIntegrityCheck(GraphExplorer.FromRoots(rules));
                    if (errors != null)
                    {
                        throw new IntegrityCheckException(errors);
                    }

                    Dictionary <Lite <RoleEntity>, Dictionary <Type, TypeAllowedAndConditions> > realRules =
                        rules.AgGroupToDictionary(ru => ru.Role, gr => gr
                                                  .SelectCatch(ru => KeyValuePair.Create(TypeLogic.EntityToType.GetOrThrow(ru.Resource), ru.ToTypeAllowedAndConditions()))
                                                  .ToDictionaryEx());

                    Dictionary <Lite <RoleEntity>, RoleAllowedCache> newRules = new Dictionary <Lite <RoleEntity>, RoleAllowedCache>();
                    foreach (var role in roles)
                    {
                        var related = AuthLogic.RelatedTo(role);

                        newRules.Add(role, new RoleAllowedCache(role, merger, related.Select(r => newRules.GetOrThrow(r)).ToList(), realRules.TryGetC(role)));
                    }

                    return(newRules);
                }
        }
Exemple #7
0
        public static FluentInclude <T> WithVirtualMListInitializeOnly <T, L>(this FluentInclude <T> fi,
                                                                              Func <T, MList <L> > getMList,
                                                                              Expression <Func <L, Lite <T> > > getBackReference,
                                                                              Action <L, T> onSave = null)
            where T : Entity
            where L : Entity
        {
            Action <L, Lite <T> > setter = null;
            var sb = fi.SchemaBuilder;

            sb.Schema.EntityEvents <T>().Saving += (T e) =>
            {
                if (GraphExplorer.IsGraphModified(getMList(e)))
                {
                    e.SetModified();
                }
            };
            sb.Schema.EntityEvents <T>().Saved += (T e, SavedEventArgs args) =>
            {
                var mlist = getMList(e);

                if (!GraphExplorer.IsGraphModified(mlist))
                {
                    return;
                }

                if (setter == null)
                {
                    setter = CreateSetter(getBackReference);
                }

                mlist.ForEach(line => setter(line, e.ToLite()));
                if (onSave == null)
                {
                    mlist.SaveList();
                }
                else
                {
                    mlist.ForEach(line => { if (GraphExplorer.IsGraphModified(line))
                                            {
                                                onSave(line, e);
                                            }
                                  });
                }
                var priv = (IMListPrivate)mlist;
                for (int i = 0; i < mlist.Count; i++)
                {
                    if (priv.GetRowId(i) == null)
                    {
                        priv.SetRowId(i, mlist[i].Id);
                    }
                }
                mlist.SetCleanModified(false);
            };

            return(fi);
        }
        public static bool HasChanges(this FrameworkElement element)
        {
            if (element is IHasChangesHandler hch)
            {
                return(hch.HasChanges());
            }

            return(GraphExplorer.HasChanges((Modifiable)element.DataContext));
        }
        public void IsRootNodeTest_False()
        {
            GraphExplorer ge = GraphExplorer.CreateGraphExplorer(new byte[] { 2, 2 },
                                                                 new byte[] { 1, 2, 3, 4 }, new char[] { 'l', 'r' });
            INode parent = new Node(null, null, new NodeState(new byte[] { 1, 1 }, new byte[] { 0, 1 }), 0);

            Assert.IsFalse(ge.IsRootNode(new Node(parent, DownOperator.Instance, new NodeState(new byte[] { 1, 1 },
                                                                                               new byte[] { 0, 1 }), 1)));
        }
Exemple #10
0
            public void AddFullGraph(ModifiableEntity ie)
            {
                DirectedGraph <Modifiable> modifiables = GraphExplorer.FromRoot(ie);

                foreach (var ident in modifiables.OfType <Entity>().Where(ident => !ident.IsNew))
                {
                    Add(ident);
                }
            }
        public void IsRootNodeTest_True()
        {
            GraphExplorer ge = GraphExplorer.CreateGraphExplorer(new byte[] { 4, 4 },
                                                                 new byte[] { 1, 2, 3, 0 },
                                                                 new char[] { 'l', 'r' });

            Assert.IsTrue(ge.IsRootNode(new Node(null, null, new NodeState(new byte[] { 1, 1 },
                                                                           new byte[] { 0, 1 }), 0)));
        }
        private static void CleanChanges(ModelEntity rules)
        {
            var graph      = GraphExplorer.FromRoot(rules);
            var conditions = graph.OfType <TypeAllowedAndConditions>().SelectMany(a => a.Conditions).ToList();

            conditions.ForEach(con => graph.UnionWith(GraphExplorer.FromRoot(con)));
            GraphExplorer.CleanModifications(graph);
            GraphExplorer.SetDummyRowIds(graph);
        }
Exemple #13
0
        private void AssertRetrieved <T>(List <T> list) where T : Modifiable
        {
            var graph = GraphExplorer.FromRoots(list);

            var problematic = graph.Where(a =>
                                          a.IsGraphModified &&
                                          a is Entity && (((Entity)a).IdOrNull == null || ((Entity)a).IsNew));

            if (problematic.Any())
            {
                Assert.True(false, "Some non-retrived elements: {0}".FormatWith(problematic.ToString(", ")));
            }
        }
Exemple #14
0
        public void SaveManyMList()
        {
            using (var tr = new Transaction())
                using (OperationLogic.AllowSave <LabelEntity>())
                    using (OperationLogic.AllowSave <CountryEntity>())
                        using (OperationLogic.AllowSave <AlbumEntity>())
                            using (OperationLogic.AllowSave <ArtistEntity>())
                            {
                                var prev = Database.MListQuery((AlbumEntity a) => a.Songs).Count();

                                var authors =
                                    Database.Query <BandEntity>().Take(6).ToList().Concat <IAuthorEntity>(
                                        Database.Query <ArtistEntity>().Take(8).ToList()).ToList();

                                var label = new LabelEntity {
                                    Name = "Four Music", Country = new CountryEntity {
                                        Name = "Germany"
                                    }, Node = MusicLoader.NextLabelNode()
                                };

                                List <AlbumEntity> albums = 0.To(16).Select(i => new AlbumEntity()
                                {
                                    Name   = "System Greatest hits {0}".FormatWith(i),
                                    Author = i < authors.Count ? authors[i] : new ArtistEntity {
                                        Name = ".Net Framework"
                                    },
                                    Year  = 2001,
                                    Songs = { new SongEmbedded {
                                                  Name = "Compilation {0}".FormatWith(i)
                                              } },
                                    State = AlbumState.Saved,
                                    Label = label,
                                }).ToList();

                                albums.SaveList();

                                Assert.All(GraphExplorer.FromRoots(albums), a => Assert.False(a.IsGraphModified));

                                Assert.Equal(prev + 16, Database.MListQuery((AlbumEntity a) => a.Songs).Count());

                                albums.ForEach(a => a.Name += "Updated");

                                albums.SaveList();

                                albums.ForEach(a => a.Songs.ForEach(s => s.Name = "Updated"));

                                albums.SaveList();

                                //tr.Commit();
                            }
        }
Exemple #15
0
    public static ImportAction Save(Entity entity)
    {
        if (!GraphExplorer.HasChanges(entity))
        {
            return(ImportAction.NoChanges);
        }

        var result = entity.IsNew ? ImportAction.Inserted : ImportAction.Updated;

        using (OperationLogic.AllowSave(entity.GetType()))
            entity.Save();

        return(result);
    }
Exemple #16
0
        static T AssertEntity <T>(this T result, Entity entity)
            where T : IEntityOperation
        {
            if (result.Lite)
            {
                var list = GraphExplorer.FromRoot(entity).Where(a => a.Modified == ModifiedState.SelfModified);
                if (list.Any())
                {
                    throw new InvalidOperationException("Operation {0} needs a Lite or a clean entity, but the entity has changes:\r\n {1}"
                                                        .FormatWith(result.OperationSymbol, list.ToString("\r\n")));
                }
            }

            return(result);
        }
Exemple #17
0
        public void Test_AStar_NoPath()
        {
            GraphExplorer gExplorer    = null;
            IPath         searchResult = null;
            IVertex       start        = null;
            IVertex       destination  = null;

            start       = m_graph.Vertices["Shlomzion-Wizo"];
            destination = m_graph.Vertices["Khoogim"];

            gExplorer    = new GraphExplorer(m_graph);
            searchResult = gExplorer.AStar(start, destination);

            Assert.IsNull(searchResult);
        }
Exemple #18
0
        public void Test_AStar_TakeShohamToSchool()
        {
            GraphExplorer gExplorer    = null;
            IPath         searchResult = null;
            IVertex       start        = null;
            IVertex       destination  = null;

            start       = m_graph.Vertices["Hana 40"];
            destination = m_graph.Vertices["Khoogim"];

            gExplorer    = new GraphExplorer(m_graph);
            searchResult = gExplorer.AStar(start, destination);

            Assert.AreEqual("Hana 29", searchResult.NextVertex(m_graph.Vertices["Hana 40"]).Name);
        }
Exemple #19
0
        private bool HasErrors()
        {
            GraphExplorer.PreSaving(() => GraphExplorer.FromRoot(Request));

            var errors = Request.FullIntegrityCheck();

            if (errors == null)
            {
                return(false);
            }

            MessageBox.Show(Window.GetWindow(this), "There are errors in the chart settings:\r\n" + errors, "Errors in the chart", MessageBoxButton.OK, MessageBoxImage.Stop);

            return(true);
        }
Exemple #20
0
        public void AlgorithmManhattanHeuristicTest()
        {
            byte[]            puzzle            = new byte[] { 1, 2, 3, 4, 5, 11, 0, 7, 9, 6, 10, 8, 13, 14, 15, 12 };
            HeuristicProvider heuristicProvider = new Manhattan(solution);
            GraphExplorer     explorer          = GraphExplorer.CreateGraphExplorer(
                new byte[] { 4, 4 },
                puzzle,
                new char[] { 'u', 'd', 'l', 'r' }, new AStar(heuristicProvider));

            explorer.TargetState = new NodeState(new byte[] { 4, 4 },
                                                 new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0 });
            string sol = explorer.TraverseForSolution();

            Assert.IsFalse(string.IsNullOrEmpty(sol));
        }
Exemple #21
0
        public void Test_AStar_Boorekas()
        {
            GraphExplorer gExplorer    = null;
            IPath         searchResult = null;
            IVertex       start        = null;
            IVertex       destination  = null;

            start       = m_graph.Vertices["Hana 40"];
            destination = m_graph.Vertices["Z. Carmelia"];

            gExplorer    = new GraphExplorer(m_graph);
            searchResult = gExplorer.AStar(start, destination);

            Assert.AreEqual("Rachel 2", searchResult.NextVertex(m_graph.Vertices["Rachel Fork"]).Name);
        }
Exemple #22
0
        public void FindSolutionTest()
        {
            byte[]        puzzle   = new byte[] { 1, 2, 3, 4, 5, 11, 0, 7, 9, 6, 10, 8, 13, 14, 15, 12 };
            GraphExplorer explorer = GraphExplorer.CreateGraphExplorer
                                         (new byte[] { 4, 4 },
                                         puzzle,
                                         new char[] { 'u', 'd', 'l', 'r' }, new BFS());

            explorer.TargetState = new NodeState(new byte[] { 4, 4 },
                                                 new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0 });
            var sol = explorer.TraverseForSolution();

            System.Console.WriteLine(sol);
            Assert.IsNotNull(sol);
        }
Exemple #23
0
        public void FindSolutionTest()
        {
            byte[] puzzle = new byte[] { 2, 5, 3, 4, 1, 7, 11, 8, 10, 6, 14, 0, 9, 13, 15, 12 };
            // byte[] puzzle = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 10, 13, 11, 12, 9, 14, 0, 15 };
            GraphExplorer explorer = GraphExplorer.CreateGraphExplorer
                                         (new byte[] { 4, 4 },
                                         puzzle,
                                         new char[] { 'u', 'd', 'l', 'r' }, new DFS());

            explorer.TargetState = new NodeState(new byte[] { 4, 4 },
                                                 new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0 });
            string sol = explorer.TraverseForSolution();

            Assert.IsFalse(string.IsNullOrEmpty(sol));
        }
Exemple #24
0
        static void Validate <T>(IEnumerable <T> entities) where T : Entity
        {
            foreach (var e in entities)
            {
                var ic = e.FullIntegrityCheck();

                if (ic != null)
                {
#if DEBUG
                    throw new IntegrityCheckException(ic.WithEntities(GraphExplorer.FromRoots(entities)));
#else
                    throw new IntegrityCheckException(ic);
#endif
                }
            }
        }
Exemple #25
0
        public void Test_AStar_StartIsTheGoal()
        {
            GraphExplorer gExplorer    = null;
            IPath         searchResult = null;
            IVertex       start        = null;
            IVertex       destination  = null;

            start       = m_graph.Vertices["Hana 40"];
            destination = m_graph.Vertices["Hana 40"];

            gExplorer    = new GraphExplorer(m_graph);
            searchResult = gExplorer.AStar(start, destination);

            Assert.AreEqual("Hana 40", searchResult.StartVertex.Name);
            Assert.IsNull(searchResult.NextVertex(start));
        }
Exemple #26
0
        public static T SetNotModifiedGraph <T>(this T entity, PrimaryKey id)
            where T : Entity
        {
            foreach (var item in GraphExplorer.FromRoot(entity).Where(a => a.Modified != ModifiedState.Sealed))
            {
                item.SetNotModified();
                if (item is Entity e)
                {
                    e.SetId(new PrimaryKey("invalidId"));
                }
            }

            entity.SetId(id);

            return(entity);
        }
Exemple #27
0
        public async Task <List <EvalEntityError> > GetEvalErrors([Required, FromBody] QueryEntitiesRequestTS request)
        {
            var allEntities = await QueryLogic.Queries.GetEntitiesLite(request.ToQueryEntitiesRequest()).Select(a => a.Entity).ToListAsync();

            return(allEntities.Select(entity =>
            {
                GraphExplorer.PreSaving(() => GraphExplorer.FromRoot(entity));

                return new EvalEntityError
                {
                    lite = entity.ToLite(),
                    error = entity.FullIntegrityCheck().EmptyIfNull().Select(a => a.Value).SelectMany(a => a.Errors.Values).ToString("\n")
                };
            })
                   .Where(ee => ee.error.HasText())
                   .ToList());
        }
Exemple #28
0
        public void SaveMList()
        {
            using (var tr = new Transaction())
                using (OperationLogic.AllowSave <LabelEntity>())
                    using (OperationLogic.AllowSave <CountryEntity>())
                        using (OperationLogic.AllowSave <AlbumEntity>())
                            using (OperationLogic.AllowSave <ArtistEntity>())
                            {
                                var prev = Database.MListQuery((AlbumEntity a) => a.Songs).Count();

                                Type[] types = typeof(int).Assembly.GetTypes().Where(a => a.Name.Length > 3 && a.Name.StartsWith("A")).ToArray();

                                AlbumEntity album = new AlbumEntity()
                                {
                                    Name   = "System Greatest hits",
                                    Author = new ArtistEntity {
                                        Name = ".Net Framework"
                                    },
                                    Year  = 2001,
                                    Songs = types.Select(t => new SongEmbedded()
                                    {
                                        Name = t.Name
                                    }).ToMList(),
                                    State = AlbumState.Saved,
                                    Label = new LabelEntity {
                                        Name = "Four Music", Country = new CountryEntity {
                                            Name = "Germany"
                                        }, Node = MusicLoader.NextLabelNode()
                                    },
                                }.Save();

                                Assert.All(GraphExplorer.FromRoot(album), a => Assert.False(a.IsGraphModified));

                                Assert.Equal(prev + types.Length, Database.MListQuery((AlbumEntity a) => a.Songs).Count());

                                album.Name += "Updated";

                                album.Save();

                                album.Songs.ForEach(a => a.Name = "Updated");

                                album.Save();

                                //tr.Commit();
                            }
        }
Exemple #29
0
        public ActionResult <EntityPackTS> ExecuteEntity([Required, FromBody] EntityOperationRequest request)
        {
            Entity entity;

            try
            {
                entity = OperationLogic.ServiceExecute(request.entity, request.GetOperationSymbol(request.entity.GetType()), request.args);
            }
            catch (IntegrityCheckException ex)
            {
                GraphExplorer.SetValidationErrors(GraphExplorer.FromRoot(request.entity), ex);
                this.TryValidateModel(request, "request");
                return(BadRequest(this.ModelState));
            }

            return(SignumServer.GetEntityPack(entity));
        }
        public EntityPackTS ExecuteEntity(EntityOperationRequest request)
        {
            Entity entity;

            try
            {
                entity = OperationLogic.ServiceExecute(request.entity, request.GetOperationSymbol(request.entity.GetType()), request.args);
            }
            catch (IntegrityCheckException ex)
            {
                GraphExplorer.SetValidationErrors(GraphExplorer.FromRoot(request.entity), ex);
                this.Validate(request, "request");
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, this.ModelState));
            }

            return(SignumServer.GetEntityPack(entity));
        }