コード例 #1
0
        private static void GenerateChangeGroupCommand(ICommandDispatcher dispatcher, EntityResource original, EntityResource updated)
        {
            if (original.DefinitionGroup != null && Equals(original.DefinitionGroup.Id, updated.DefinitionGroup.Id))
                return;

            dispatcher.Dispatch(new EntityChangedGroupCommand(updated.Identity, updated.DefinitionGroup.Id));
        }
コード例 #2
0
ファイル: EntityResource.cs プロジェクト: brucewu16899/lacjam
        public bool DiscriptionMatches(EntityResource other)
        {
            if (other == null)
                return false;

            return Equals(Name, other.Name);
        }
コード例 #3
0
ファイル: EntityController.cs プロジェクト: vikavisoft/lacjam
        public HttpResponseMessage Create(EntityResource resource)
        {
            _logWriter.Info(String.Format("Beginning of processing creation of Entity : {0}", resource.Name));

            if (resource == null)
            {
                throw new ArgumentEmptyException("resource");
            }

            _logWriter.Debug(resource.ToString());

            if (_readService.FindByIdentity(resource.Identity).Exists)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Identity already exists. Identities must be unique"));
            }

            return(_readService.FindByName(resource.Name).Fold(x =>
                                                               Request.CreateErrorResponse(HttpStatusCode.BadRequest, resource.Name + " already exists. Names must be unique"),
                                                               () =>
            {
                var command = resource.ToCreateCommand();
                _dispatcher.Dispatch(command);

                _logWriter.Info(String.Format("Completion of processing creation of Entity : {0}", resource.Name));

                return Request.CreateResponse(HttpStatusCode.Created);
            }));
        }
コード例 #4
0
        private static void GenerateReLabelCommand(ICommandDispatcher dispatcher, EntityResource original, EntityResource updated)
        {
            if (original.DiscriptionMatches(updated))
                return;

            dispatcher.Dispatch(new ReLabelEntityCommand(updated.Identity, new EntityName(updated.Name.Trim())));
        }
コード例 #5
0
        public bool DiscriptionMatches(EntityResource other)
        {
            if (other == null)
            {
                return(false);
            }

            return(Equals(Name, other.Name));
        }
コード例 #6
0
        private static void GenerateReLabelCommand(ICommandDispatcher dispatcher, EntityResource original, EntityResource updated)
        {
            if (original.DiscriptionMatches(updated))
            {
                return;
            }

            dispatcher.Dispatch(new ReLabelEntityCommand(updated.Identity, new EntityName(updated.Name.Trim())));
        }
コード例 #7
0
        public static void GenerateCommands(this ICommandDispatcher dispatcher, IEntityReadService readService, EntityResource resource)
        {
            var current = readService.FindByIdentity(resource.Identity);

            current.Foreach(original =>
            {
                GenerateReLabelCommand(dispatcher, original, resource);
                GenerateChangeGroupCommand(dispatcher, original, resource);
                GenerateValues(dispatcher, original, resource);
            });
        }
コード例 #8
0
ファイル: EntityResource.cs プロジェクト: brucewu16899/lacjam
        public bool ValuesMatch(EntityResource other)
        {
            if (other == null)
                return false;

            if (DefinitionValues == null)
                return other.DefinitionValues == null || !other.DefinitionValues.Any();

            if (other.DefinitionValues == null)
                return DefinitionValues == null || !DefinitionValues.Any();

            return DefinitionValues.Count == other.DefinitionValues.Count && DefinitionValues.Intersect(other.DefinitionValues).Count() == DefinitionValues.Count;
        }
コード例 #9
0
        private static void GenerateValues(ICommandDispatcher dispatcher, EntityResource original, EntityResource updated)
        {
            if (original.ValuesMatch(updated))
                return;

            if (updated.DefinitionValues == null || !updated.DefinitionValues.Any())
            {
                dispatcher.Dispatch(new RemoveAllEntityValuesCommand(updated.Identity));
                return;
            }

            dispatcher.Dispatch(new UpdateEntityValuesCommand(updated.Identity, BuildEntityValues(updated.Identity, updated.DefinitionValues)));
        }
コード例 #10
0
        private static IEnumerable<ValueSet> GetValues(EntityResource resource)
        {
            if (resource.DefinitionValues == null || !resource.DefinitionValues.Any())
                return Enumerable.Empty<ValueSet>();

            return resource.DefinitionValues.Select(x => new ValueSet
            {
                MetadataDefinitionIdentity = x.MetadataDefinitionIdentity,
                Name = x.Name,
                DataType = x.DataType,
                Regex = x.Regex,
                Values = new List<string>(x.Values)
            });
        }
コード例 #11
0
        private static void GenerateValues(ICommandDispatcher dispatcher, EntityResource original, EntityResource updated)
        {
            if (original.ValuesMatch(updated))
            {
                return;
            }

            if (updated.DefinitionValues == null || !updated.DefinitionValues.Any())
            {
                dispatcher.Dispatch(new RemoveAllEntityValuesCommand(updated.Identity));
                return;
            }

            dispatcher.Dispatch(new UpdateEntityValuesCommand(updated.Identity, BuildEntityValues(updated.Identity, updated.DefinitionValues)));
        }
コード例 #12
0
        private static IEnumerable <ValueSet> GetValues(EntityResource resource)
        {
            if (resource.DefinitionValues == null || !resource.DefinitionValues.Any())
            {
                return(Enumerable.Empty <ValueSet>());
            }

            return(resource.DefinitionValues.Select(x => new ValueSet
            {
                MetadataDefinitionIdentity = x.MetadataDefinitionIdentity,
                Name = x.Name,
                DataType = x.DataType,
                Regex = x.Regex,
                Values = new List <string>(x.Values)
            }));
        }
コード例 #13
0
ファイル: EntityController.cs プロジェクト: vikavisoft/lacjam
        public HttpResponseMessage UpdateEntity([FromUri] Guid identity, [FromBody] EntityResource resource)
        {
            _logWriter.Info(String.Format("Update request for Entity: {0}", identity));
            resource.Identity = identity;

            var current        = _readService.FindByIdentity(resource.Identity);
            var matchingByName = _readService.FindByName(resource.Name);

            return(matchingByName.Filter(x => x.Identity != resource.Identity)
                   .Fold(x => Request.CreateErrorResponse(HttpStatusCode.BadRequest, resource.Name + " already exists. Names must be unique"),
                         () => current.Fold(z =>
            {
                _dispatcher.GenerateCommands(_readService, resource);
                return Request.CreateResponse(HttpStatusCode.OK);
            },
                                            () => Request.CreateErrorResponse(HttpStatusCode.NotFound, "Entity Resource Not Found"))
                         ));
        }
コード例 #14
0
        public bool ValuesMatch(EntityResource other)
        {
            if (other == null)
            {
                return(false);
            }

            if (DefinitionValues == null)
            {
                return(other.DefinitionValues == null || !other.DefinitionValues.Any());
            }

            if (other.DefinitionValues == null)
            {
                return(DefinitionValues == null || !DefinitionValues.Any());
            }

            return(DefinitionValues.Count == other.DefinitionValues.Count && DefinitionValues.Intersect(other.DefinitionValues).Count() == DefinitionValues.Count);
        }
コード例 #15
0
        public HttpResponseMessage Create(EntityResource resource)
        {
            _logWriter.Info(String.Format("Beginning of processing creation of Entity : {0}", resource.Name));

            if (resource == null)
                throw new ArgumentEmptyException("resource");

            _logWriter.Debug(resource.ToString());

            if (_readService.FindByIdentity(resource.Identity).Exists)
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Identity already exists. Identities must be unique");

            return _readService.FindByName(resource.Name).Fold(x =>
                                                                    Request.CreateErrorResponse(HttpStatusCode.BadRequest, resource.Name + " already exists. Names must be unique"),
                                                                    () =>
                                                                    {
                                                                        var command = resource.ToCreateCommand();
                                                                        _dispatcher.Dispatch(command);

                                                                        _logWriter.Info(String.Format("Completion of processing creation of Entity : {0}", resource.Name));

                                                                        return Request.CreateResponse(HttpStatusCode.Created);
                                                                    });
        }
コード例 #16
0
        public static void GenerateCommands(this ICommandDispatcher dispatcher, IEntityReadService readService, EntityResource resource)
        {
            var current = readService.FindByIdentity(resource.Identity);

            current.Foreach(original =>
            {
                GenerateReLabelCommand(dispatcher, original, resource);
                GenerateChangeGroupCommand(dispatcher, original, resource);
                GenerateValues(dispatcher, original, resource);
            });
        }
コード例 #17
0
        private static void GenerateChangeGroupCommand(ICommandDispatcher dispatcher, EntityResource original, EntityResource updated)
        {
            if (original.DefinitionGroup != null && Equals(original.DefinitionGroup.Id, updated.DefinitionGroup.Id))
            {
                return;
            }

            dispatcher.Dispatch(new EntityChangedGroupCommand(updated.Identity, updated.DefinitionGroup.Id));
        }
コード例 #18
0
 public static CreateEntityCommand ToCreateCommand(this EntityResource resource)
 {
     return(new CreateEntityCommand(resource.Identity, resource.DefinitionGroup.Id, resource.Name, GetValues(resource)));
 }