Example #1
0
    public static void OnCreatedEntity(Entity entity)
    {
        if (!instance.entityMessageWaitingList.ContainsKey(entity.GetId()))
        {
            return;
        }

        for (int i = 0; i < instance.entityMessageWaitingList[entity.GetId()].Count; i++)
        {
            NetDataReader       data        = instance.entityMessageWaitingList[entity.GetId()][i];
            NetworkMessage.Type messageType = (NetworkMessage.Type)data.GetByte();
            Game.AddThreadAction(() => NetworkMessageResolve.Resolve(messageType, data));
        }
        instance.entityMessageWaitingList.Remove(entity.GetId());
    }
Example #2
0
        public void Test_NewInstance_GetInstancesOfTypeManual()
        {
            if (_runner == "EntityInfoService")
            {
                Assert.Ignore();
            }

            var typeId = Entity.GetId("test:herb");

            EntityMemberRequest request = EntityRequestHelper.BuildRequest("instancesOfType.id");
            var svc = GetService();

            // Check before create
            EntityData result = svc.GetEntityData(typeId, request);
            int        count  = result.Relationships[0].Instances.Count;

            // Create the instance
            using (var ctx = DatabaseContext.GetContext(true, preventPostSaveActionsPropagating: true))
            {
                Create("test:herb", "AAA");

                ctx.CommitTransaction();
            }

            // Check after create
            result = svc.GetEntityData(typeId, request);
            int count2 = result.Relationships[0].Instances.Count;

            Assert.AreEqual(count + 1, count2);
        }
            /// <summary>
            ///     Gets the user account cache entry.
            /// </summary>
            /// <param name="username">The username.</param>
            /// <returns></returns>
            private UserAccountCacheEntry GetUserAccountCacheEntry(string username)
            {
                UserAccountCacheEntry entry;

                lock ( _innerLockObject )
                {
                    if (PasswordPolicyId == 0)
                    {
                        // Cache the password policy instance id
                        PasswordPolicyId = Entity.GetId("core:passwordPolicyInstance");
                    }

                    if (!InnerCache.TryGetValue(username, out entry))
                    {
                        // We don't have a cache entry for this user name.
                        // Get the user account by user name and add it to the cache
                        UserAccount userAccountByName = Entity.GetByField <UserAccount>(username, true, new EntityRef("core", "name")).FirstOrDefault( );

                        if (userAccountByName == null)
                        {
                            return(null);
                        }

                        entry = AddAccount(userAccountByName);
                    }
                }

                return(entry);
            }
Example #4
0
        public void GetUpgradeId( )
        {
            long id        = Entity.GetId("core:type");
            Guid upgradeId = Factory.UpgradeIdProvider.GetUpgradeId(id);

            Assert.That(upgradeId, Is.EqualTo(new Guid("c0c6de86-2c65-47d2-bd5d-1751eed77378")));
        }
Example #5
0
        public void Test_Filter_InvalidEntity()
        {
            SecurityActionMenuItemFilter       securityActionMenuItemFilter;
            List <ActionMenuItemInfo>          actions;
            Mock <IEntityAccessControlService> mockEntityAccessControlService;
            long id;

            id      = Entity.GetId("console:viewResourceAction");
            actions = new List <ActionMenuItemInfo>
            {
                new ActionMenuItemInfo
                {
                    Id       = id,
                    EntityId = 0,
                    Children = null
                }
            };

            mockEntityAccessControlService = new Mock <IEntityAccessControlService>(MockBehavior.Strict);
            mockEntityAccessControlService.Setup(
                eacs => eacs.Check(
                    It.Is <IList <EntityRef> >(list => list.SequenceEqual(new[] { new EntityRef(id) }, EntityRefComparer.Instance)),
                    It.IsAny <IList <EntityRef> >()))
            .Returns(new Dictionary <long, bool> {
                { id, true }
            });

            securityActionMenuItemFilter = new SecurityActionMenuItemFilter(mockEntityAccessControlService.Object);
            securityActionMenuItemFilter.Filter(-1, new[] { id }, actions);

            mockEntityAccessControlService.VerifyAll();
        }
Example #6
0
        public void Test_Filter(string actionAlias, string[] expectedCheckedPermissionAliases)
        {
            SecurityActionMenuItemFilter       securityActionMenuItemFilter;
            List <ActionMenuItemInfo>          actions;
            Mock <IEntityAccessControlService> mockEntityAccessControlService;
            long id;

            id      = Entity.GetId(actionAlias);
            actions = new List <ActionMenuItemInfo>
            {
                new ActionMenuItemInfo
                {
                    Id       = id,
                    EntityId = id,
                    Children = null
                }
            };

            mockEntityAccessControlService = new Mock <IEntityAccessControlService>(MockBehavior.Strict);
            mockEntityAccessControlService.Setup(
                eacs => eacs.Check(
                    It.Is <IList <EntityRef> >(list => list.SequenceEqual(new [] { new EntityRef(id) }, EntityRefComparer.Instance)),
                    It.Is <IList <EntityRef> >(p => p.Select(er => er.Id).OrderBy(l => l).SequenceEqual(expectedCheckedPermissionAliases.Select(Entity.GetId).OrderBy(l => l)))))
            .Returns(new Dictionary <long, bool> {
                { id, true }
            });
            mockEntityAccessControlService.Setup(eacs => eacs.Check(It.IsAny <EntityRef>(), It.IsAny <IList <EntityRef> >())).Returns(true);

            securityActionMenuItemFilter = new SecurityActionMenuItemFilter(mockEntityAccessControlService.Object);
            securityActionMenuItemFilter.Filter(-1, new[] { id }, actions);

            mockEntityAccessControlService.VerifyAll();
            Assert.That(actions, Has.Count.EqualTo(1), "Action menu item removed incorrectly");
        }
Example #7
0
        public void Test_NewById_GetEntitiesUsingInstancesOfType()
        {
            long typeId = Entity.GetId("test:herb");

            EntityMemberRequest request = EntityRequestHelper.BuildRequest("instancesOfType.{alias,name,description}");
            var svc = GetService();

            // Check before create
            var result = svc.GetEntityData(typeId, request);
            int count  = result.Relationships[0].Instances.Count;

            Assert.IsTrue(count > 1);

            // Create the instance
            using (var ctx = DatabaseContext.GetContext(true, preventPostSaveActionsPropagating: true))
            {
                Create("test:herb", "AAA");

                ctx.CommitTransaction();
            }

            // Check after create
            var result2 = svc.GetEntityData(typeId, request);
            int count2  = result2.Relationships[0].Instances.Count;

            Assert.AreEqual(count + 1, count2);
        }
Example #8
0
        public void Test_NewInstance_GetEntitiesByType()
        {
            if (_runner == "EntityInfoService")
            {
                Assert.Ignore();
            }

            var typeId = Entity.GetId("test:herb");

            EntityMemberRequest request = EntityRequestHelper.BuildRequest("id");
            var svc = GetService();

            // Check before create
            var result = svc.GetEntitiesByType(typeId, false, request);
            int count  = result.Count();

            // Create the instance
            Create("test:herb", "AAA");

            // Check after create
            result = svc.GetEntitiesByType(typeId, false, request);
            int count2 = result.Count();

            Assert.AreEqual(count + 1, count2);
        }
		/**
		 * @param e entity
		 * @return the name of the group that this entity belongs to, null if none.
		 */
		public String GetGroupOf(Entity e) {
			int entityId = e.GetId();
			if(entityId < groupByEntity.GetCapacity()) {
				return groupByEntity.Get(entityId);
			}
			return null;
		}
        public void Test_SameRelInFwdAndRev(string requestString, string metadataOnlyDir)
        {
            EntityMemberRequest request = EntityRequestHelper.BuildRequest("id");
            var svc = GetService();

            var resource = new EntityRef("core", "chart");

            // get 'isOfType' relationship Id
            long relId = Entity.GetId("core:isOfType");

            Assert.IsTrue(relId > 0);

            // build request string to get relationship fields in fwd direction and then metaData for the same relationship in reverse direction
            var relRequestString           = string.Format(requestString, relId);
            EntityMemberRequest relRequest = EntityRequestHelper.BuildRequest(relRequestString);
            EntityData          result     = svc.GetEntityData(resource, relRequest);

            if (metadataOnlyDir == "fwd")
            {
                Assert.IsTrue(!result.GetRelationship(relId, Direction.Forward).Entities.Any());
                Assert.IsTrue(result.GetRelationship(relId, Direction.Reverse).Entities.Any());
            }
            else
            {
                Assert.IsTrue(result.GetRelationship(relId, Direction.Forward).Entities.Any());
                Assert.IsTrue(!result.GetRelationship(relId, Direction.Reverse).Entities.Any());
            }
        }
        void IRunNowActivity.OnRunNow(IRunState context, ActivityInputs inputs)
        {
            _activityInputs = inputs;
            try
            {
                if (string.IsNullOrEmpty(TenantEmailSetting.SmtpServer))
                {
                    throw new Exception("smtpServer has not been specified.");
                }

                var sendEmailRecipientsType = GetArgumentValue <Resource>(inputs, "core:sendEmailRecipientsType");

                var sentEmailMessages = new List <SentEmailMessage>();
                if (string.IsNullOrEmpty(sendEmailRecipientsType?.Alias) || (sendEmailRecipientsType?.Alias == "core:sendEmailActivityRecipientsAddress"))
                {
                    sentEmailMessages.Add(GenerateEmailToRecipientsExpression());
                }
                else
                {
                    var sendEmailDistributionType = GetArgumentValue <Resource>(inputs, "core:sendEmailDistributionType");
                    if (string.IsNullOrEmpty(sendEmailDistributionType?.Alias) || (sendEmailDistributionType?.Alias == "core:sendEmailActivityGroupDistribution"))
                    {
                        sentEmailMessages.Add(GenerateGroupEmailsToRecipientsList());
                    }
                    else
                    {
                        sentEmailMessages.AddRange(GenerateIndividualEmailsToRecipientsList());
                    }
                }

                var mailMessages = new List <MailMessage>();
                sentEmailMessages.RemoveAll(msg => string.IsNullOrEmpty(msg.EmTo) && string.IsNullOrEmpty(msg.EmCC) && string.IsNullOrEmpty(msg.EmBCC));
                sentEmailMessages.RemoveAll(msg => string.IsNullOrEmpty(msg.EmSubject));
                sentEmailMessages.ForEach(msg =>
                {
                    msg.EmSentDate = DateTime.UtcNow;
                    msg.Save();
                    mailMessages.Add(msg.ToMailMessage());
                });

                RecordInfoToUserLog(context, $"Sending {sentEmailMessages.Count} emails");

                if (sentEmailMessages.Count == 0)
                {
                    context.ExitPointId = Entity.GetId("core:sendEmailSucceededSend");
                    return;
                }

                EmailSender.SendMessages(mailMessages);

                context.SetArgValue(ActivityInstance, GetArgumentKey("core:outSentEmailMessages"), sentEmailMessages);
                context.ExitPointId = Entity.GetId("core:sendEmailSucceededSend");
            }
            catch (Exception ex)
            {
                RecordErrorToUserLog(context, ex);
                context.ExitPointId = Entity.GetId("core:sendEmailFailedSend");
            }
        }
Example #12
0
            public Entity RegisterEntityTarget(int id, object target, System constructor_system, SystemMethod_Constructor constructor, object[] constructor_arguments)
            {
                Entity entity = new Entity(id, target, constructor_system, constructor, constructor_arguments, this);

                entitys_by_id.Add(entity.GetId(), entity);
                entitys_by_target.Add(entity.GetTarget(), entity);

                return(entity);
            }
        public void BuildAndSecureResults_WriteOnlyFields()
        {
            BulkRequestResult bulkRequestResult;
            long               administratorUserAccountId;
            EntityRequest      entityRequest;
            IList <EntityData> results;
            EntityData         result;
            EntityRef          passwordField;
            EntityRef          nameField;
            PasswordPolicy     passwordPolicy;

            administratorUserAccountId = Entity.GetId("core:administratorUserAccount");
            Assert.That(administratorUserAccountId, Is.Positive, "Administrator account missing");

            passwordField = new EntityRef("core:password");
            Assert.That(passwordField.Entity.As <Field>(), Has.Property("IsFieldWriteOnly").True);

            nameField = new EntityRef("core:name");

            passwordPolicy = Entity.Get <PasswordPolicy>("core:passwordPolicyInstance");
            Assert.That(passwordPolicy, Is.Not.Null, "Password policy missing");

            // Build the results
            entityRequest = new EntityRequest
            {
                QueryType     = QueryType.Basic,
                Entities      = new [] { new EntityRef("core:administratorUserAccount") },
                RequestString = "name, password",
                Hint          = "NUnit test"
            };
            bulkRequestResult = BulkResultCache.GetBulkResult(entityRequest);

            results = BulkRequestResultConverter.BuildAndSecureResults(
                bulkRequestResult,
                new[] { administratorUserAccountId },
                SecurityOption.SkipDenied).ToList();
            Assert.That(results, Has.Count.EqualTo(1), "Incorrect number of results");

            result = results.FirstOrDefault();
            Assert.That(result, Is.Not.Null);
            Assert.That(result.Fields, Has.Count.EqualTo(2), "Incorrect number of fields");
            Assert.That(
                result.Fields,
                Has.Exactly(1)
                .Property("FieldId").EqualTo(nameField)
                .And.Property("Value").Property("Value").EqualTo("Administrator"),
                "Incorrect password field value");
            Assert.That(
                result.Fields,
                Has.Exactly(1)
                .Property("FieldId").EqualTo(passwordField)
                .And.Property("Value").Property("Value").EqualTo(
                    new string('*',
                               passwordPolicy.MinimumPasswordLength ?? WriteOnlyFieldReadValueGenerator.DefaultWriteOnlyStringResultLength)),
                "Incorrect password field value");
        }
Example #14
0
        void IRunNowActivity.OnRunNow(IRunState context, ActivityInputs inputs)
        {
            var haveStarted         = GetArgumentKey("forEachHaveStarted");
            var foreachList         = GetArgumentKey("forEachResourceList");
            var resourceListKey     = GetArgumentKey("foreachList");
            var selectedResourceKey = GetArgumentKey("foreachSelectedResource");


            IEnumerable <IEntity> resourceList;


            if (!(context.GetArgValue <bool?>(ActivityInstance, haveStarted) ?? false))
            {
                context.SetArgValue(ActivityInstance, haveStarted, true);

                //
                // it's the first time into the loop
                //
                object listObj;
                if (inputs.TryGetValue(resourceListKey, out listObj))
                {
                    if (listObj == null)
                    {
                        throw new ApplicationException("The [List] argument is null. This should never happen.");
                    }

                    resourceList = (IEnumerable <IEntity>)listObj;
                }
                else
                {
                    throw new ApplicationException("The [List] is missing from the input arguments. This should never happen.");
                }
            }
            else
            {
                resourceList = context.GetArgValue <IEnumerable <IEntity> >(ActivityInstance, foreachList);
            }

            var selectedResourceRef = resourceList.FirstOrDefault();


            if (selectedResourceRef != null)
            {
                context.SetArgValue(ActivityInstance, selectedResourceKey, selectedResourceRef);
                resourceList = resourceList.Skip(1);
                context.SetArgValue(ActivityInstance, foreachList, resourceList);
                context.ExitPointId = Entity.GetId(LoopExitPointAlias);
            }
            else
            {
                // We have finished
                context.SetArgValue(ActivityInstance, haveStarted, false);
                context.SetArgValue(ActivityInstance, foreachList, null);
                context.ExitPointId = Entity.GetId("core", "foreachCompletedExitPoint");
            }
        }
Example #15
0
        public void GetUpgradeIds( )
        {
            long id1 = Entity.GetId("core:type");
            long id2 = Entity.GetId("core:resource");
            IDictionary <long, Guid> result = Factory.UpgradeIdProvider.GetUpgradeIds(new[] { id1, id2, -1 });

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Count, Is.EqualTo(2));
            Assert.That(result[id1], Is.EqualTo(new Guid("c0c6de86-2c65-47d2-bd5d-1751eed77378")));
            Assert.That(result[id2], Is.EqualTo(new Guid("69224903-ca05-48cb-a13d-786c49f08e18")));
        }
		/**
		 * Set the group of the entity.
		 * 
		 * @param group group to set the entity into.
		 * @param e entity to set into the group.
		 */
		public void Set(String group, Entity e) {
			Remove(e); // Entity can only belong to one group.
			
			Bag<Entity> entities;
			if(!entitiesByGroup.TryGetValue(group,out entities)) {
				entities = new Bag<Entity>();
				entitiesByGroup.Add(group, entities);
			}
			entities.Add(e);
			
			groupByEntity.Set(e.GetId(), group);
		}
		public void Change(Entity e) {
			bool contains = (systemBit & e.GetSystemBits()) == systemBit;
			bool interest = (typeFlags & e.GetTypeBits()) == typeFlags;
	
			if (interest && !contains && typeFlags > 0) {
				actives.Add(e.GetId(),e);
				e.AddSystemBit(systemBit);
				Added(e);
			} else if (!interest && contains && typeFlags > 0) {
				Remove(e);
			}
		}
Example #18
0
        public void GetRelationshipInstancesByRelId( )
        {
            IEntity entity = Entity.GetByName("Test 01").First( );
            long    relId  = Entity.GetId("test", "herbs");

            IEntityRelationshipCollection <IEntity> instances =
                entity.GetRelationships(relId, Direction.Forward);

            foreach (var i in instances)
            {
                IEntity relatedEntity = i.Entity;                 // this is typically what you want
            }
        }
Example #19
0
        public void Test_PasswordEmptyInResponse()
        {
            long                  administratorId;
            long                  passwordFieldId;
            long                  nameFieldId;
            List <long>           entitiesToDelete;
            HttpWebResponse       response;
            JsonEntityQueryResult jsonEntityQueryResult;
            JsonEntity            jsonEntity;

            entitiesToDelete = new List <long>();
            try
            {
                administratorId = Entity.GetId("core:administratorUserAccount");
                Assert.That(administratorId, Is.Positive, "Missing administrator account");

                passwordFieldId = Entity.GetId("core:password");
                Assert.That(passwordFieldId, Is.Positive, "Missing password field");

                nameFieldId = Entity.GetId("core:name");
                Assert.That(nameFieldId, Is.Positive, "Missing name field");

                using (PlatformHttpRequest request = new PlatformHttpRequest(string.Format(@"data/v1/entity/{0}?request=name,password", administratorId)))
                {
                    response = request.GetResponse();

                    Assert.That(response, Has.Property("StatusCode").EqualTo(HttpStatusCode.OK),
                                "Web service call failed");
                    jsonEntityQueryResult = request.DeserialiseResponseBody <JsonEntityQueryResult>();

                    Assert.That(jsonEntityQueryResult.Entities, Has.Count.EqualTo(1), "Incorrect Entities count");
                    jsonEntity = jsonEntityQueryResult.Entities.First();
                    Assert.That(jsonEntity.Fields, Has.Exactly(1).Property("FieldId").EqualTo(passwordFieldId)
                                .And.Property("Value").Matches("[*]+"));
                    Assert.That(jsonEntity.Fields, Has.Exactly(1).Property("FieldId").EqualTo(nameFieldId)
                                .And.Property("Value").EqualTo("Administrator"));
                }
            }
            finally
            {
                try
                {
                    Entity.Delete(entitiesToDelete);
                }
                catch (Exception)
                {
                    // Do nothing
                }
            }
        }
		/**
		 * Removes the provided entity from the group it is assigned to, if any.
		 * @param e the entity.
		 */
		public void Remove(Entity e) {
			int entityId = e.GetId();
			if(entityId < groupByEntity.GetCapacity()) {
				String group = groupByEntity.Get(entityId);
				if(group != null) {
					groupByEntity.Set(entityId, null);
					
					Bag<Entity> entities;
					if(entitiesByGroup.TryGetValue(group,out entities)) {
						entities.Remove(e);
					}
				}
			}
		}
        public override KeyValuePair <Person, Attrition> BuildPerson(List <Person> records)
        {
            if (records == null || records.Count == 0)
            {
                return(new KeyValuePair <Person, Attrition>(null, Attrition.UnacceptablePatientQuality));
            }

            var ordered = records.OrderByDescending(p => p.StartDate).ThenBy(p => p.EndDate).ToArray();

            foreach (var p in ordered)
            {
                if (p.PotentialChildId.HasValue && p.PotentialChildBirthDate != DateTime.MinValue)
                {
                    if (!_potentialChilds.ContainsKey(p.PotentialChildId.Value))
                    {
                        _potentialChilds.Add(p.PotentialChildId.Value, new HashSet <DateTime>());
                    }

                    _potentialChilds[p.PotentialChildId.Value].Add(p.PotentialChildBirthDate);
                }
            }

            var person = ordered.Take(1).Last();

            if (records.Where(r => r.YearOfBirth.HasValue && r.YearOfBirth > 1900).Max(r => r.YearOfBirth) -
                records.Where(r => r.YearOfBirth.HasValue && r.YearOfBirth > 1900).Min(r => r.YearOfBirth) > 2)
            {
                return(new KeyValuePair <Person, Attrition>(null, Attrition.MultipleYearsOfBirth));
            }

            person.LocationId = Entity.GetId(person.LocationSourceValue);

            if (person.GenderConceptId == 8551) //UNKNOWN
            {
                return(new KeyValuePair <Person, Attrition>(null, Attrition.UnknownGender));
            }

            if (person.YearOfBirth < 1900) //UNKNOWN
            {
                return(new KeyValuePair <Person, Attrition>(null, Attrition.ImplausibleYOBPast));
            }

            if (records.Any(r => r.GenderConceptId != 8551 && r.GenderConceptId != person.GenderConceptId))
            {
                return(new KeyValuePair <Person, Attrition>(null, Attrition.GenderChanges)); // Gender changed over different enrollment period
            }

            return(new KeyValuePair <Person, Attrition>(person, Attrition.None));
        }
Example #22
0
        public void Test001Get()
        {
            var someId = Entity.GetId("test", "peterAylett");

            var actionRequest = new ActionRequest {
                SelectedResourceIds = new[] { someId }
            };

            using (var request = new PlatformHttpRequest("data/v1/actions", PlatformHttpMethod.Post))
            {
                request.PopulateBody(actionRequest);
                HttpWebResponse response = request.GetResponse();
                Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
            }
        }
Example #23
0
        // set corresponding ProviderIds
        protected void SetProviderIds <T>(IEnumerable <T> inputRecords) where T : class, IEntity
        {
            var records = inputRecords as T[] ?? inputRecords.ToArray();

            if (inputRecords == null || !records.Any())
            {
                return;
            }


            foreach (var e in records.Where(e => !string.IsNullOrEmpty(e.ProviderKey)))
            {
                e.ProviderId = Entity.GetId(e.ProviderKey);
            }
        }
        public override IEnumerable <IEntity> GetConcepts(Concept concept, IDataRecord reader,
                                                          KeyMasterOffsetManager keyOffset)
        {
            var loc = new Location
            {
                State       = reader.GetString(State),
                SourceValue = reader.GetString(SourceValue),
                County      = reader.GetString(Country),
                Address1    = reader.GetString(Address1),
                Address2    = reader.GetString(Address2)
            };

            loc.Id = string.IsNullOrEmpty(Id) ? Entity.GetId(loc.GetKey()) : reader.GetLong(Id).Value;
            yield return(loc);
        }
Example #25
0
        public void Test_Filter_Children()
        {
            SecurityActionMenuItemFilter       securityActionMenuItemFilter;
            List <ActionMenuItemInfo>          actions;
            Mock <IEntityAccessControlService> mockEntityAccessControlService;
            long parentId;
            long childId;

            parentId = Entity.GetId("console:viewResourceAction");
            childId  = Entity.GetId("console:editResourceAction");
            actions  = new List <ActionMenuItemInfo>
            {
                new ActionMenuItemInfo
                {
                    Id       = parentId,
                    EntityId = parentId,
                    Children = new List <ActionMenuItemInfo>
                    {
                        new ActionMenuItemInfo()
                        {
                            Id       = childId,
                            EntityId = childId,
                            Children = null
                        }
                    }
                }
            };

            mockEntityAccessControlService = new Mock <IEntityAccessControlService>(MockBehavior.Strict);
            mockEntityAccessControlService.Setup(
                eacs => eacs.Check(
                    It.Is <IList <EntityRef> >(list => list.SequenceEqual(new [] { new EntityRef(parentId) }, EntityRefComparer.Instance)),
                    It.IsAny <IList <EntityRef> >()))
            .Returns(new Dictionary <long, bool> {
                { parentId, true }
            });
            mockEntityAccessControlService.Setup(eacs => eacs.Check(It.IsAny <EntityRef>(), It.IsAny <IList <EntityRef> >())).Returns(true);

            securityActionMenuItemFilter = new SecurityActionMenuItemFilter(mockEntityAccessControlService.Object);
            securityActionMenuItemFilter.Filter(-1, new[] { parentId }, actions);

            mockEntityAccessControlService.VerifyAll();
            Assert.That(actions, Has.Count.EqualTo(1), "Action menu removed incorrectly");
            Assert.That(actions[0], Has.Property("Children").Count.EqualTo(1), "Child action menu removed incorrectly");
        }
Example #26
0
            public void SendConstructorReplay(System system, NetworkRecipient recipient, object[] arguments, Entity spawned_entity)
            {
                Syncronizer  syncronizer = system.GetSyncronizer();
                NetworkActor actor       = syncronizer.GetNetworkActor();

                syncronizer.CreateMessage(MessageType.InvokeSystemMethod, NetDeliveryMethod.ReliableOrdered, delegate(Buffer buffer) {
                    buffer.WriteSystemReference(system);
                    buffer.WriteSystemMethod(this);

                    WriteArguments(arguments, buffer);

                    if (actor.IsServer())
                    {
                        buffer.WriteInt32(spawned_entity.GetId());
                        spawned_entity.WriteSync(buffer);
                    }
                }).Send(recipient);
            }
Example #27
0
        public void Test_NewDerivedInstance_GetEntitiesByType()
        {
            var typeId = Entity.GetId("test:person");

            EntityMemberRequest request = EntityRequestHelper.BuildRequest("id");
            var svc = GetService();

            // Check before create
            var result = svc.GetEntitiesByType(typeId, true, request);
            int count  = result.Count();

            // Create the instance
            Create("test:employee", "AAA");

            // Check after create
            result = svc.GetEntitiesByType(typeId, true, request);
            int count2 = result.Count();

            Assert.AreEqual(count + 1, count2);
        }
Example #28
0
        private void CheckAllTempObjectMarkedAsCreate(EntityData entityData, HashSet <long> passedObjects = null)
        {
            if (passedObjects == null)
            {
                passedObjects = new HashSet <long>();
            }

            // prevent loops
            if (passedObjects.Contains(entityData.Id.Id))
            {
                return;
            }

            passedObjects.Add(entityData.Id.Id);

            if (entityData.Id.Id > 1000000)
            {
                Assert.AreEqual(entityData.DataState, DataState.Create, "Temp item has Create datastate");

                long isOfType = Entity.GetId("core:isOfType");
                foreach (RelationshipData relationship in entityData.Relationships.Where(r => r.RelationshipTypeId.Id != isOfType))
                {
                    foreach (RelationshipInstanceData ri in relationship.Instances)
                    {
                        Assert.AreEqual(ri.DataState, DataState.Create, "Temp item relationship has Create data state");
                    }
                }
            }

            // Walk the rest of the tree
            foreach (RelationshipData relationship in entityData.Relationships)
            {
                foreach (RelationshipInstanceData relationshipInstance in relationship.Instances)
                {
                    CheckAllTempObjectMarkedAsCreate(relationshipInstance.Entity, passedObjects);
                }
            }
        }
Example #29
0
        public void Test_DeleteInstance_GetInstancesOfTypeManual()
        {
            var typeId = Entity.GetId("test:herb");

            // Create the instance
            var entity = Create("test:herb", "AAA");

            EntityMemberRequest request = EntityRequestHelper.BuildRequest("instancesOfType.id");
            var svc = GetService();

            // Check before delete
            EntityData result = svc.GetEntityData(typeId, request);
            int        count  = result.Relationships[0].Instances.Count;

            // Delete
            entity.Delete();

            // Check after delete
            result = svc.GetEntityData(typeId, request);
            int count2 = result.Relationships[0].Instances.Count;

            Assert.AreEqual(count - 1, count2);
        }
Example #30
0
        public void Test_DeleteInstance_GetEntitiesByType()
        {
            var typeId = Entity.GetId("test:herb");

            // Create the instance
            var entity = Create("test:herb", "AAA");

            EntityMemberRequest request = EntityRequestHelper.BuildRequest("id");
            var svc = GetService();

            // Check before delete
            var result = svc.GetEntitiesByType(typeId, false, request);
            int count  = result.Count();

            // Delete
            entity.Delete();

            // Check after delete
            result = svc.GetEntitiesByType(typeId, false, request);
            int count2 = result.Count();

            Assert.AreEqual(count - 1, count2);
        }
Example #31
0
        private void LoadLocation(List <Location> locationConcepts)
        {
            if (_taskQueue.Aborted)
            {
                return;
            }
            Console.WriteLine("Loading locations...");
            WriteLog(Status.Running, "Loading locations...", 0);
            var location = _settings.SourceQueryDefinitions.FirstOrDefault(qd => qd.Locations != null);

            if (location != null)
            {
                FillList <Location>(locationConcepts, location, location.Locations[0]);
            }

            if (locationConcepts.Count == 0)
            {
                locationConcepts.Add(new Location {
                    Id = Entity.GetId(null)
                });
            }
            Console.WriteLine("Locations was loaded");
            WriteLog(Status.Running, "Locations was loaded", 0);
        }
Example #32
0
        public override KeyValuePair <Person, Attrition> BuildPerson(List <Person> records)
        {
            if (records == null || records.Count == 0)
            {
                return(new KeyValuePair <Person, Attrition>(null, Attrition.UnacceptablePatientQuality));
            }

            var ordered = records.OrderByDescending(p => p.StartDate).ThenBy(p => p.EndDate);
            var person  = ordered.Take(1).Last();

            person.LocationId = Entity.GetId(person.LocationSourceValue);

            if (person.GenderConceptId == 8551) //UNKNOWN
            {
                return(new KeyValuePair <Person, Attrition>(null, Attrition.UnknownGender));
            }

            if (!person.YearOfBirth.HasValue)
            {
                return(new KeyValuePair <Person, Attrition>(null, Attrition.UnknownYearOfBirth));
            }

            return(new KeyValuePair <Person, Attrition>(person, Attrition.None));
        }
Example #33
0
        private void LoadLocation(List <Location> locationConcepts)
        {
            if (_taskQueue.Aborted)
            {
                return;
            }
            Console.WriteLine("Loading locations...");
            _logHub.Clients.All.SendAsync("Log", "Loading locations...").Wait();
            var location = _settings.SourceQueryDefinitions.FirstOrDefault(qd => qd.Locations != null);

            if (location != null)
            {
                FillList <Location>(locationConcepts, location, location.Locations[0]);
            }

            if (locationConcepts.Count == 0)
            {
                locationConcepts.Add(new Location {
                    Id = Entity.GetId(null)
                });
            }
            Console.WriteLine("Locations was loaded");
            _logHub.Clients.All.SendAsync("Log", "Locations was loaded").Wait();
        }
Example #34
0
 void EnsureMutable()
 {
     if (Entity.Services.IsImmutable(Entity))
     {
         throw new ArgumentException("An immutable record must be cloned before any modifications can be applied on it. " +
                                     $"Type={Entity.GetType().FullName}, Id={Entity.GetId()}.");
     }
 }
 private void Remove(Entity e)
 {
     actives.Remove(e.GetId());
     e.RemoveSystemBit(systemBit);
     Removed(e);
 }