protected override void HandleMessage(EntitySnapshotRequest <User> message)
        {
            IReadOnlyEntityRepository <User> userRepository = ServiceRegistry.GetService <RepositoryManager>().GetRepository <User>();
            var clientManager = ServiceRegistry.GetService <IClientManager>();

            IEnumerable <User> currentUsers = userRepository.GetAllEntities();
            var userSnapshot = new EntitySnapshot <User>(currentUsers);

            clientManager.SendMessageToClient(userSnapshot, message.UserId);
        }
        protected override void HandleMessage(EntitySnapshot <Conversation> message)
        {
            var conversationRepository = (ConversationRepository)ServiceRegistry.GetService <RepositoryManager>().GetRepository <Conversation>();

            foreach (Conversation conversation in message.Entities)
            {
                conversationRepository.AddEntity(conversation);
            }

            OnConversationBootstrapCompleted();
        }
        protected override void HandleMessage(EntitySnapshot <Participation> message)
        {
            var participationRepository = (IEntityRepository <Participation>)ServiceRegistry.GetService <RepositoryManager>().GetRepository <Participation>();

            foreach (Participation participation in message.Entities)
            {
                participationRepository.AddEntity(participation);
            }

            OnParticipationBootstrapCompleted();
        }
Пример #4
0
        protected override void HandleMessage(EntitySnapshot <User> message)
        {
            var userRepository = (UserRepository)ServiceRegistry.GetService <RepositoryManager>().GetRepository <User>();

            foreach (User user in message.Entities)
            {
                userRepository.AddEntity(user);
            }

            OnUserBootstrapCompleted();
        }
Пример #5
0
 protected override void OnEditing(MediaEditorModel model, EntitySnapshot <TypedEntity> entity)
 {
     //we need to flag if this model is editable based on whether or not it is in the recycle bin
     using (var uow = Hive.Create <IContentStore>())
     {
         var ancestorIds = uow.Repositories.GetAncestorIds(entity.Revision.Item.Id, FixedRelationTypes.DefaultRelationType);
         if (ancestorIds.Contains(FixedHiveIds.MediaRecylceBin, new HiveIdComparer(true)))
         {
             model.IsEditable = false;
         }
     }
 }
Пример #6
0
        /// <summary>
        /// Determines whether the revision has a pending publish to be made
        /// </summary>
        /// <param name="rev">The rev.</param>
        /// <returns>
        ///   <c>true</c> if [is publish pending] [the specified rev]; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsPublishPending(this EntitySnapshot <TypedEntity> rev)
        {
            if (rev == null)
            {
                return(false);
            }

            var lastPublished = rev.GetLatestDate(FixedStatusTypes.Published);
            var lastSaved     = rev.GetLatestDate(FixedStatusTypes.Draft);

            return(lastSaved > lastPublished);
        }
        protected override void HandleMessage(EntitySnapshotRequest <Conversation> message)
        {
            var participationRepository = (ParticipationRepository)ServiceRegistry.GetService <RepositoryManager>().GetRepository <Participation>();
            IReadOnlyEntityRepository <Conversation> conversationRepository = ServiceRegistry.GetService <RepositoryManager>().GetRepository <Conversation>();
            var clientManager = ServiceRegistry.GetService <IClientManager>();

            IEnumerable <int> conversationIds = participationRepository.GetAllConversationIdsByUserId(message.UserId);

            List <Conversation> conversations = conversationIds.Select(conversationRepository.FindEntityById).ToList();

            var conversationSnapshot = new EntitySnapshot <Conversation>(conversations);

            clientManager.SendMessageToClient(conversationSnapshot, message.UserId);
        }
Пример #8
0
        /// <summary>
        /// Returns the published date if it is published, otherwise returns null
        /// </summary>
        /// <param name="rev"></param>
        /// <returns></returns>
        public static DateTimeOffset?PublishedDate(this EntitySnapshot <TypedEntity> rev)
        {
            if (rev == null)
            {
                return(null);
            }

            var lastPublished   = rev.GetLatestDate(FixedStatusTypes.Published);
            var lastUnpublished = rev.GetLatestDate(FixedStatusTypes.Unpublished);

            return(lastPublished > lastUnpublished
                       ? (DateTimeOffset?)lastPublished
                       : null);
        }
Пример #9
0
        protected override void HandleMessage(EntitySnapshotRequest <Participation> message)
        {
            var participationRepository = (ParticipationRepository)ServiceRegistry.GetService <RepositoryManager>().GetRepository <Participation>();
            var clientManager           = ServiceRegistry.GetService <IClientManager>();

            var userParticipations = new List <Participation>();

            foreach (int conversationId in participationRepository.GetAllConversationIdsByUserId(message.UserId))
            {
                userParticipations.AddRange(participationRepository.GetParticipationsByConversationId(conversationId));
            }

            var participationSnapshot = new EntitySnapshot <Participation>(userParticipations);

            clientManager.SendMessageToClient(participationSnapshot, message.UserId);
        }
Пример #10
0
        /// <summary>
        /// Removes the entity snapshot refered from the given quadratic coordinates.
        /// </summary>
        /// <param name="quadCoord">The quadratic coordinates of the entity snapshot to remove.</param>
        private void RemoveEntitySnapshot(RCIntVector quadCoord)
        {
            EntitySnapshot snapshotToRemove = this.entitySnapshots[quadCoord.X, quadCoord.Y];

            if (snapshotToRemove == null)
            {
                return;
            }

            for (int col = snapshotToRemove.QuadraticPosition.Left; col < snapshotToRemove.QuadraticPosition.Right; col++)
            {
                for (int row = snapshotToRemove.QuadraticPosition.Top; row < snapshotToRemove.QuadraticPosition.Bottom; row++)
                {
                    this.entitySnapshots[col, row] = null;
                }
            }
        }
        internal static EntitySnapshot <T> GetLatestSnapshot <T>(this IEnumerable <IReadonlyProviderRevisionRepository <T> > readonlyRepositories, HiveId hiveId, Uri idRoot, RevisionStatusType revisionStatusType = null)
            where T : class, IVersionableEntity
        {
            EntitySnapshot <T> returnValue = null;

            //TODO: Determine which repo is the primary one
            //TODO: Ensure population of the incoming queue is sorted by Ordinal
            foreach (var reader in readonlyRepositories)
            {
                returnValue = reader.GetLatestSnapshot <T>(hiveId, revisionStatusType);
                if (returnValue != null)
                {
                    break;
                }
            }
            return(GroupSessionHelper.MakeIdsAbsolute(returnValue, idRoot));
        }
Пример #12
0
    /// <summary>
    /// This creates a "snapshot" of an entity's global positions and rotation. This includes the entity's entire hierarchy.
    /// </summary>
    private static void CreateSnapshotImpl(this Entity entity, EntitySnapshot root, List <EntitySnapshot> results)
    {
        if (entity == null || !entity.Valid)
        {
            return;
        }

        EntitySnapshot parent = new EntitySnapshot(entity, root);

        results.Add(parent);

        var children = entity.Children;

        foreach (var child in children)
        {
            CreateSnapshotImpl(child, parent, results);
        }
    }
Пример #13
0
        /// <summary>
        /// Gets the latest date from an EntitySnapshot
        /// <paramref name="alias"/>.
        /// </summary>
        public static DateTimeOffset GetLatestDate <T>(this EntitySnapshot <T> snapshot, string alias)
            where T : TypedEntity
        {
            Mandate.ParameterNotNull(snapshot, "coll");
            Mandate.ParameterNotNullOrEmpty(alias, "alias");

            //TODO: This is currenty a work around for an issue where NH isn't adding the current item's revision data to the revision list data. SD. 07/11/2011
            var latestInItem = snapshot.Revision.MetaData.StatusType.Alias == alias ? snapshot.Revision.MetaData.UtcStatusChanged : DateTimeOffset.MinValue;

            var latestInList = snapshot.EntityRevisionStatusList.OrderByDescending(x => x.UtcStatusChanged).FirstOrDefault(x => x.StatusType.Alias == alias);

            var latest = latestInList == null
                             ? latestInItem
                             : latestInItem > latestInList.UtcStatusChanged
                                   ? latestInItem
                                   : latestInList.UtcStatusChanged;

            return(latest);
        }
Пример #14
0
 /// <summary>
 /// Adds the given entity snapshot and all of its cutting quadratic tiles into the update lists.
 /// </summary>
 /// <param name="snapshot">The entity snapshot to add.</param>
 /// <param name="snapshotUpdateList">The snapshot update list.</param>
 /// <param name="quadTileUpdateList">The quadratic update list.</param>
 private void AddEntitySnapshotToUpdate(EntitySnapshot snapshot, RCSet <EntitySnapshot> snapshotUpdateList, RCSet <IQuadTile> quadTileUpdateList)
 {
     if (snapshot != null && snapshotUpdateList.Add(snapshot))
     {
         for (int col = snapshot.QuadraticPosition.Left; col < snapshot.QuadraticPosition.Right; col++)
         {
             for (int row = snapshot.QuadraticPosition.Top; row < snapshot.QuadraticPosition.Bottom; row++)
             {
                 IQuadTile quadTileToUpdate = this.ActiveScenario.Map.GetQuadTile(new RCIntVector(col, row));
                 if (quadTileToUpdate != null &&
                     (this.fowCacheMatrix.GetFullFowFlagsAtQuadTile(quadTileToUpdate.MapCoords) != FOWTileFlagsEnum.None ||
                      this.fowCacheMatrix.GetPartialFowFlagsAtQuadTile(quadTileToUpdate.MapCoords) != FOWTileFlagsEnum.None))
                 {
                     quadTileUpdateList.Add(quadTileToUpdate);
                 }
             }
         }
     }
 }
Пример #15
0
 public void ServerUpdateSerializer_Serialization_Empty()
 {
     byte[] serializedData = new byte[1024];
     {
         EntityArray    entityArray    = EntityTests.CreateStandardEntityArray();
         EntitySnapshot entitySnapshot = new EntitySnapshot(3, EntityTests.CreateComponentsDefinition());
         entitySnapshot.Update(66, entityArray);
         OutgoingMessage outgoingMessage = new OutgoingMessage(serializedData);
         ServerUpdateSerializer.Serialize(outgoingMessage, null, entitySnapshot, 63, 13);
         serializedData = outgoingMessage.ToArray();
     }
     {
         EntitySnapshot entitySnapshot = new EntitySnapshot(3, EntityTests.CreateComponentsDefinition());
         ServerUpdateSerializer.Deserialize(new IncomingMessage(serializedData), new EntitySnapshot[0], entitySnapshot, out int latestClientTickAcknowledgedByServer, out int clientCommandingEntityID);
         Assert.AreEqual(63, latestClientTickAcknowledgedByServer);
         Assert.AreEqual(13, clientCommandingEntityID);
         Assert.AreEqual(66, entitySnapshot.ServerFrameTick);
         EntityTests.AssertStandardEntityArray(entitySnapshot.EntityArray);
     }
 }
Пример #16
0
        private static void BlankFace(EntitySnapshot caim, IList <RaidAction> raidActions)
        {
            var lastAbility = caim.Raid.GetLastAbilityUsed();

            if (lastAbility != null)
            {
                if (lastAbility.Type == Ability.Types.AbilityType.Offensive)
                {
                    caim.GlobalState["blank_face"] = TypedValue.FromString("spades");
                    if (caim.PositionInFrontline < 4)
                    {
                        SpadesPreparation().Cast(caim, raidActions);
                    }
                }
                else if (lastAbility.Type == Ability.Types.AbilityType.Healing)
                {
                    caim.GlobalState["blank_face"] = TypedValue.FromString("hearts");
                    if (caim.PositionInFrontline < 4)
                    {
                        HeartsPreparation().Cast(caim, raidActions);
                    }
                }
                else if (lastAbility.Type == Ability.Types.AbilityType.Support)
                {
                    caim.GlobalState["blank_face"] = TypedValue.FromString("diamonds");
                    if (caim.PositionInFrontline < 4)
                    {
                        DiamondsPreparation().Cast(caim, raidActions);
                    }
                }
                else if (lastAbility.Type == Ability.Types.AbilityType.Defensive)
                {
                    caim.GlobalState["blank_face"] = TypedValue.FromString("clubs");
                    if (caim.PositionInFrontline < 4)
                    {
                        ClubsPreparation().Cast(caim, raidActions);
                    }
                }
            }
        }
Пример #17
0
 public void ServerUpdateSerializer_DeserializeIfNewer_IsNewer()
 {
     byte[] serializedData = new byte[1024];
     {
         EntitySnapshot entitySnapshot = new EntitySnapshot(3, EntityTests.CreateComponentsDefinition());
         entitySnapshot.Update(68, entitySnapshot.EntityArray);
         OutgoingMessage outgoingMessage = new OutgoingMessage(serializedData);
         ServerUpdateSerializer.Serialize(outgoingMessage, null, entitySnapshot, 73, 17);
         serializedData = outgoingMessage.ToArray();
     }
     {
         EntityArray    entityArray    = EntityTests.CreateStandardEntityArray();
         EntitySnapshot entitySnapshot = new EntitySnapshot(3, EntityTests.CreateComponentsDefinition());
         entitySnapshot.Update(65, entityArray);
         Assert.IsTrue(ServerUpdateSerializer.DeserializeIfNewer(new IncomingMessage(serializedData), new EntitySnapshot[0], entitySnapshot, out int latestClientTickAcknowledgedByServer, out int clientCommandingEntityID));
         Assert.AreEqual(73, latestClientTickAcknowledgedByServer);
         Assert.AreEqual(17, clientCommandingEntityID);
         Assert.AreEqual(68, entitySnapshot.ServerFrameTick);
         Assert.IsFalse(entitySnapshot.EntityArray.TryGetEntity(0, out _));
         Assert.IsFalse(entitySnapshot.EntityArray.TryGetEntity(1, out _));
         Assert.IsFalse(entitySnapshot.EntityArray.TryGetEntity(2, out _));
     }
 }
Пример #18
0
        /// <summary>
        /// Calculates the entity snapshot for the given quadratic tile.
        /// </summary>
        /// <param name="quadCoords">The quadratic coordinates of the tile.</param>
        private void CalculateEntitySnapshot(RCIntVector quadCoords)
        {
            bool           isFowRunning           = false;
            EntitySnapshot entitySnapshot         = null;
            int            greatestExpirationTime = -1;

            for (int idx = 0; idx < Player.MAX_PLAYERS; idx++)
            {
                if (this.runningFows[idx] != null)
                {
                    int expirationTime = this.runningFows[idx].GetExpirationTime(quadCoords);
                    if (expirationTime > greatestExpirationTime)
                    {
                        entitySnapshot         = this.runningFows[idx].GetEntitySnapshot(quadCoords);
                        greatestExpirationTime = expirationTime;
                    }
                    isFowRunning = true;
                }
            }

            this.fowCacheMatrix[quadCoords.X, quadCoords.Y].LastEntitySnapshotUpdate = this.scenario.CurrentFrameIndex;
            this.fowCacheMatrix[quadCoords.X, quadCoords.Y].EntitySnapshot           = isFowRunning ? entitySnapshot : null;
        }
 public static void FillDiamonds(this EntitySnapshot npc, IList <RaidAction> raidActions)
 {
     throw new NotImplementedException();
 }
Пример #20
0
 private static void ProcessPassiveEffects(EntitySnapshot template)
 {
 }
Пример #21
0
 public static void StoreSnapshot(ISnapshotStore snapshotStore, EntitySnapshot snapshot)
 {
     storeSnapshotDelegates[snapshot.GetType()](snapshotStore, snapshot);
 }
Пример #22
0
 internal static EntitySnapshot <T> SetProviderAliasOnId <T>(ProviderMetadata providerMetadata, EntitySnapshot <T> entity) where T : class, IVersionableEntity
 {
     if (entity == null)
     {
         return(null);
     }
     SetProviderAliasOnId(providerMetadata, entity.Revision);
     return(entity);
 }
Пример #23
0
        public void StoreSnapshot(EntitySnapshot snapshot)
        {
            TSnapshot typedSnapshot = (TSnapshot)snapshot;

            StoreSnapshot(typedSnapshot);
        }
 public static UseAbility UseAbility(this EntitySnapshot hero, int abilityIndex, int targetIndex)
 {
     throw new NotImplementedException();
 }
Пример #25
0
        /// <summary>
        /// Continues to update the Fog Of War informations based on the current positions of the owner's entities.
        /// </summary>
        /// <param name="maxEntities">The maximum number of entities to be processed.</param>
        /// <returns>The actual number of processed entities.</returns>
        /// <remarks>
        /// The already processed entities won't be processed again. Use FogOfWar.RestartUpdate to restart the update procedure.
        /// </remarks>
        public int ContinueUpdate(int maxEntities)
        {
            if (maxEntities < 0)
            {
                throw new ArgumentOutOfRangeException("maxEntities", "maxEntities shall be non-negative!");
            }

            /// Update every quadratic tiles that are visible by the friendly entities.
            int processedEntitiesCount = 0;

            using (IEnumerator <Entity> entitiesIterator = this.owner.Entities.GetEnumerator())
            {
                while (processedEntitiesCount < maxEntities && entitiesIterator.MoveNext())
                {
                    Entity entity = entitiesIterator.Current;
                    if (!this.processedEntities.Contains(entity.ID.Read()))
                    {
                        foreach (RCIntVector visibleQuadCoord in entity.Locator.VisibleQuadCoords)
                        {
                            /// Update the expiration time of the quadratic tile.
                            this.fowExpirationTimes[visibleQuadCoord.X, visibleQuadCoord.Y] =
                                this.owner.Scenario.CurrentFrameIndex + PARTIAL_FOW_EXPIRATION_TIME;

                            /// If there was a snapshot at the given quadratic tile -> remove it.
                            this.RemoveEntitySnapshot(visibleQuadCoord);

                            /// If there is a non-friendly Entity fixed on the given quadratic tile -> start monitoring.
                            Entity entityAtQuadTile = this.owner.Scenario.GetFixedEntity <Entity>(visibleQuadCoord);
                            if (entityAtQuadTile != null && entityAtQuadTile.Owner != this.owner)
                            {
                                this.monitoredEntities.Add(entityAtQuadTile.ID.Read());
                            }
                        }
                        this.processedEntities.Add(entity.ID.Read());
                        processedEntitiesCount++;
                    }
                }
            }

            /// Check the monitored entities if we still need to monitor them.
            List <int> monitoredEntitiesCopy = new List <int>(this.monitoredEntities);

            foreach (int monitoredEntityId in monitoredEntitiesCopy)
            {
                Entity monitoredEntity = this.owner.Scenario.GetElementOnMap <Entity>(monitoredEntityId, MapObjectLayerEnum.GroundObjects);
                if (monitoredEntity != null && monitoredEntity.Owner != this.owner && monitoredEntity.MotionControl.Status == MotionControlStatusEnum.Fixed)
                {
                    /// Check if the monitored entity is still visible.
                    bool isStillVisible = false;
                    for (int col = monitoredEntity.MapObject.QuadraticPosition.Left; !isStillVisible && col < monitoredEntity.MapObject.QuadraticPosition.Right; col++)
                    {
                        for (int row = monitoredEntity.MapObject.QuadraticPosition.Top; row < monitoredEntity.MapObject.QuadraticPosition.Bottom; row++)
                        {
                            if (this.GetFogOfWar(new RCIntVector(col, row)) == FOWTypeEnum.None)
                            {
                                /// Found at least 1 quadratic tile where the monitored entity is still visible.
                                isStillVisible = true;
                                break;
                            }
                        }
                    }

                    if (!isStillVisible)
                    {
                        /// Take a snapshot...
                        EntitySnapshot snapshot = new EntitySnapshot(monitoredEntity);
                        for (int col = snapshot.QuadraticPosition.Left; col < snapshot.QuadraticPosition.Right; col++)
                        {
                            for (int row = snapshot.QuadraticPosition.Top; row < snapshot.QuadraticPosition.Bottom; row++)
                            {
                                this.entitySnapshots[col, row] = snapshot;
                            }
                        }

                        /// ...and stop monitoring.
                        this.monitoredEntities.Remove(monitoredEntityId);
                    }
                }
                else
                {
                    /// The monitored entity is not bound to the quadratic grid or became friendly -> stop monitoring.
                    this.monitoredEntities.Remove(monitoredEntityId);
                }
            }

            return(processedEntitiesCount);
        }
Пример #26
0
 public static void FillDiamonds(this EntitySnapshot npc, IList <RaidAction> raidActions, bool applyToAllRaidParticipants = false)
 {
     throw new NotImplementedException();
 }
Пример #27
0
 /// <summary>
 /// Allows inheritors to modify the model before being passed to the view
 /// </summary>
 /// <param name="model">The model being returned to the view</param>
 /// <param name="entity">The entity that the model was created from</param>
 protected virtual void OnEditing(TEditorModel model, EntitySnapshot <TypedEntity> entity)
 {
 }
Пример #28
0
 public void ProcessEffects(EntitySnapshot caster, IList <RaidAction> raidActions)
 {
     throw new NotImplementedException();
 }
Пример #29
0
 private static bool Equals(ResourceEntity entity, EntitySnapshot snapshot)
 {
     return(string.Equals(entity.ProjectName, snapshot.ProjectName, StringComparison.OrdinalIgnoreCase) &&
            string.Equals(entity.UniqueName, snapshot.UniqueName, StringComparison.OrdinalIgnoreCase));
 }
Пример #30
0
 public void ProcessEffects(EntitySnapshot caster, int targetPositionInFrontline, IList <RaidAction> raidActions)
 {
     throw new NotImplementedException();
 }