Пример #1
0
        private void AddRemoveConnection(AttachmentKind kind, AttachedGrid attached, bool add)
        {
            Attachments attach;

            if (!Connections.TryGetValue(attached, out attach))
            {
                if (add)
                {
                    attach = new Attachments(myGrid, attached.myGrid);
                    Connections.Add(attached, attach);
                }
                else
                {
                    Log.AlwaysLog("cannot remove, no attachments of kind " + kind, Logger.severity.ERROR);
                    return;
                }
            }

            if (add)
            {
                attach.Add(kind);
            }
            else
            {
                attach.Remove(kind);
            }
        }
Пример #2
0
        /// <summary>
        /// Yields attached grids.
        /// </summary>
        /// <param name="startGrid">Grid to start search from.</param>
        /// <param name="allowedConnections">The types of connections allowed between grids.</param>
        /// <param name="runOnStartGrid">If true, yields the startGrid.</param>
        /// <returns>Each attached grid.</returns>
        public static IEnumerable <IMyCubeGrid> AttachedGrids(IMyCubeGrid startGrid, AttachmentKind allowedConnections, bool runOnStartGrid)
        {
            if (runOnStartGrid)
            {
                yield return(startGrid);
            }

            AttachedGrid attached = GetFor(startGrid);

            if (attached == null)
            {
                yield break;
            }

            HashSet <AttachedGrid> search = s_searchSet.Get();

            try
            {
                foreach (IMyCubeGrid grid in attached.Attached(allowedConnections, search))
                {
                    yield return(grid);
                }
            }
            finally
            {
                search.Clear();
                s_searchSet.Return(search);
            }
        }
Пример #3
0
        /// <summary>
        /// Determines if two grids are attached.
        /// </summary>
        /// <param name="grid0">The starting grid.</param>
        /// <param name="grid1">The grid to search for.</param>
        /// <param name="allowedConnections">The types of connections allowed between grids.</param>
        /// <returns>True iff the grids are attached.</returns>
        public static bool IsGridAttached(IMyCubeGrid grid0, IMyCubeGrid grid1, AttachmentKind allowedConnections)
        {
            Logger.DebugLog("condition: grid0 == null", Logger.severity.FATAL, condition: grid0 == null);
            Logger.DebugLog("condition: grid1 == null", Logger.severity.FATAL, condition: grid1 == null);

            if (grid0 == grid1)
            {
                return(true);
            }

            AttachedGrid attached1 = GetFor(grid0);

            if (attached1 == null)
            {
                return(false);
            }
            AttachedGrid attached2 = GetFor(grid1);

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

            HashSet <AttachedGrid> search = s_searchSet.Get();
            bool result = attached1.IsGridAttached(attached2, allowedConnections, search);

            search.Clear();
            s_searchSet.Return(search);
            return(result);
        }
Пример #4
0
        public async Task <List <Message> > GetAttachments(AttachmentKind kind, int conversationId, string whoAccessedId,
                                                           int offset, int count)
        {
            var conversation = await conversationRepository.GetByIdAsync(conversationId);

            if (conversation == null)
            {
                throw new KeyNotFoundException("Wrong conversation to get attachments from.");
            }

            //only member of conversation could request messages of non-public conversation.

            if (!await usersConversationsRepository.Exists(whoAccessedId, conversationId) && !conversation.IsPublic)
            {
                throw new UnauthorizedAccessException("You are unauthorized to do such an action.");
            }

            var deleted = await deletedMessages.AsQuerableAsync(
                new GetDeletedMessagesOfUserSpec(whoAccessedId));

            var messages = await messagesRepository.ListAsync(
                new GetSpecificAttachmentsSpec
                (deleted,
                 conversationId,
                 kind,
                 offset,
                 count));

            return((from msg in messages
                    select msg.ToMessage()).ToList());
        }
    private LevelStructure RandomKind(AttachmentKind kind)
    {
        var validComponents = Components.Where(structure => (structure.HasAttachmentKindAndDirection(kind, AttachmentDirection.InAttach)));
        int count           = validComponents.Count();

        Debug.Assert(count > 0);
        return(validComponents.ElementAt(UnityEngine.Random.Range(0, count)));
    }
Пример #6
0
 // This is mainly used to find the "root" objects we can start with
 public bool HasAttachmentKindAndDirection(AttachmentKind kind, AttachmentDirection direction)
 {
     foreach (StructureAttachmentPoint inAttachPoint in this.GetComponentsInChildren <StructureAttachmentPoint>())
     {
         if (((inAttachPoint.Kind & kind) != 0) && (inAttachPoint.Direction == direction))
         {
             return(true);
         }
     }
     return(false);
 }
Пример #7
0
			public void Add(AttachmentKind kind)
			{
				myLogger.debugLog("adding: " + kind, "Add()");

				ushort count;
				if (!dictionary.TryGetValue(kind, out count))
				{
					attachmentKinds |= kind;
					count = 0;
				}

				count++;
				myLogger.debugLog(kind + " count: " + count, "Add()");
				dictionary[kind] = count;
			}
Пример #8
0
            public void Add(AttachmentKind kind)
            {
                Log.DebugLog("adding: " + kind);

                ushort count;

                if (!dictionary.TryGetValue(kind, out count))
                {
                    attachmentKinds |= kind;
                    count            = 0;
                }

                count++;
                Log.DebugLog(kind + " count: " + count);
                dictionary[kind] = count;
            }
Пример #9
0
			public void Remove(AttachmentKind kind)
			{
				myLogger.debugLog("removing: " + kind, "Remove()");

				ushort count = dictionary[kind];
				count--;
				if (count == 0)
				{
					attachmentKinds &= ~kind;
					dictionary.Remove(kind);
				}
				else
					dictionary[kind] = count;

				myLogger.debugLog(kind + " count: " + count, "Add()");
			}
Пример #10
0
        /// <summary>
        /// Determines if two grids are attached.
        /// </summary>
        /// <param name="grid0">The starting grid.</param>
        /// <param name="grid1">The grid to search for.</param>
        /// <param name="allowedConnections">The types of connections allowed between grids.</param>
        /// <returns>True iff the grids are attached.</returns>
        public static bool IsGridAttached(IMyCubeGrid grid0, IMyCubeGrid grid1, AttachmentKind allowedConnections)
        {
            if (grid0 == grid1)
                return true;

            using (lock_search.AcquireExclusiveUsing())
            {
                AttachedGrid attached1 = GetFor(grid0);
                if (attached1 == null)
                    return false;
                AttachedGrid attached2 = GetFor(grid1);
                if (attached2 == null)
                    return false;
                return attached1.IsGridAttached(attached2, allowedConnections, searchIdPool++);
            }
        }
Пример #11
0
        internal static void AddRemoveConnection(AttachmentKind kind, IMyCubeGrid grid1, IMyCubeGrid grid2, bool add)
        {
            if (grid1 == grid2 || Globals.WorldClosed)
            {
                return;
            }

            AttachedGrid
                attached1 = GetFor(grid1),
                attached2 = GetFor(grid2);

            if (attached1 == null || attached2 == null)
            {
                return;
            }

            attached1.AddRemoveConnection(kind, attached2, add);
            attached2.AddRemoveConnection(kind, attached1, add);
        }
Пример #12
0
            public void Remove(AttachmentKind kind)
            {
                Log.DebugLog("removing: " + kind);

                ushort count = dictionary[kind];

                count--;
                if (count == 0)
                {
                    attachmentKinds &= ~kind;
                    dictionary.Remove(kind);
                }
                else
                {
                    dictionary[kind] = count;
                }

                Log.DebugLog(kind + " count: " + count);
            }
Пример #13
0
        private bool IsGridAttached(AttachedGrid target, AttachmentKind allowedConnections, HashSet <AttachedGrid> searched)
        {
            if (!searched.Add(this))
            {
                throw new Exception("AttachedGrid already searched");
            }

            foreach (var gridAttach in Connections)
            {
                if ((gridAttach.Value.attachmentKinds & allowedConnections) == 0 || searched.Contains(gridAttach.Key))
                {
                    continue;
                }

                if (gridAttach.Key == target || gridAttach.Key.IsGridAttached(target, allowedConnections, searched))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #14
0
        private IEnumerable <IMyCubeGrid> Attached(AttachmentKind allowedConnections, HashSet <AttachedGrid> searched)
        {
            if (!searched.Add(this))
            {
                throw new Exception("AttachedGrid already searched");
            }

            foreach (var gridAttach in Connections)
            {
                if ((gridAttach.Value.attachmentKinds & allowedConnections) == 0 || searched.Contains(gridAttach.Key))
                {
                    continue;
                }

                yield return(gridAttach.Key.myGrid);

                foreach (var result in gridAttach.Key.Attached(allowedConnections, searched))
                {
                    yield return(result);
                }
            }
        }
 public GetSpecificAttachmentsSpec(
     IQueryable <DeletedMessagesDataModel> deletedMessages,
     int conversationId,
     AttachmentKind attachmentKind,
     int offset,
     int count
     ) :
     base(
         msg =>
         msg.ConversationID == conversationId &&
         msg.Type == MessageType.Attachment &&
         msg.AttachmentInfo.AttachmentKind.Kind == attachmentKind &&
         !deletedMessages.Any(x => x.MessageID == msg.MessageID)
         )
 {
     ApplyOrderByDescending(x => x.TimeReceived);
     ApplyPaging(offset, count);
     AddNestedInclude(x => x.AttachmentInfo.AttachmentKind);
     AddInclude(x => x.User);
     AddNestedInclude(x => x.ForwardedMessage.AttachmentInfo.AttachmentKind);
     AddNestedInclude(x => x.ForwardedMessage.User);
     AsNoTracking();
 }
Пример #16
0
		/// <summary>
		/// Runs a function on all the attached grids.
		/// </summary>
		/// <param name="startGrid">The starting grid/</param>
		/// <param name="allowedConnections">The types of connections allowed between grids.</param>
		/// <param name="runFunc">Func that runs on attached grids, if it returns true, short-circuit</param>
		/// <param name="runOnStartGrid">Iff true, action will be run on startGrid.</param>
		public static void RunOnAttached(IMyCubeGrid startGrid, AttachmentKind allowedConnections, Func<IMyCubeGrid, bool> runFunc, bool runOnStartGrid = false)
		{
			if (runOnStartGrid && runFunc(startGrid))
				return;
			using (lock_search.AcquireExclusiveUsing())
			{
				AttachedGrid attached = GetFor(startGrid);
				if (attached == null)
					return;
				attached.RunOnAttached(allowedConnections, runFunc, searchIdPool++);
			}
		}
Пример #17
0
 /// <summary>
 /// Yields each slim block on each attached grid. If a grid is closed, it is skipped.
 /// </summary>
 /// <param name="startGrid">Grid to start search from.</param>
 /// <param name="allowedConnections">The types of connections allowed between grids.</param>
 /// <param name="runOnStartGrid">If true, yields the startGrid.</param>
 /// <returns>Each block on each attached grid</returns>
 public static IEnumerable <IMySlimBlock> AttachedSlimBlocks(IMyCubeGrid startGrid, AttachmentKind allowedConnections, bool runOnStartGrid)
 {
     foreach (CubeGridCache cache in AttachedGridCache(startGrid, allowedConnections, runOnStartGrid))
     {
         foreach (IMySlimBlock block in cache.AllSlimBlocks())
         {
             yield return(block);
         }
     }
 }
Пример #18
0
		private void RunOnAttached(AttachmentKind allowedConnections, Func<IMyCubeGrid, bool> runFunc, uint searchId)
		{
			myLogger.debugLog(lastSearchId == searchId, "Already searched! lastSearchId == searchId", "GetAttached()", Logger.severity.ERROR);
			lastSearchId = searchId;

			using (lock_Connections.AcquireSharedUsing())
				foreach (var gridAttachments in Connections)
				{
					if (searchId == gridAttachments.Key.lastSearchId)
						continue;

					if ((gridAttachments.Value.attachmentKinds & allowedConnections) == 0)
						continue;

					if (runFunc(gridAttachments.Key.myGrid))
						return;

					gridAttachments.Key.RunOnAttached(allowedConnections, runFunc, searchId);
				}
		}
Пример #19
0
 public ValueTask <AttachmentKindDataModel> GetById(AttachmentKind kind)
 {
     return(_dbContext.AttachmentKinds.FindAsync(kind));
 }
Пример #20
0
		private bool IsGridAttached(AttachedGrid target, AttachmentKind allowedConnections, uint searchId)
		{
			myLogger.debugLog(lastSearchId == searchId, "Already searched! lastSearchId == searchId", "IsGridAttached()", Logger.severity.ERROR);
			lastSearchId = searchId;

			using (lock_Connections.AcquireSharedUsing())
				foreach (var gridAttachments in Connections)
				{
					if (searchId == gridAttachments.Key.lastSearchId)
						continue;

					if ((gridAttachments.Value.attachmentKinds & allowedConnections) == 0)
						continue;

					if (gridAttachments.Key == target)
						return true;
					if (gridAttachments.Key.IsGridAttached(target, allowedConnections, searchId))
						return true;
				}

			return false;
		}
Пример #21
0
		private void AddRemoveConnection(AttachmentKind kind, AttachedGrid attached, bool add)
		{
			using (lock_Connections.AcquireExclusiveUsing())
			{
				Attachments attach;
				if (!Connections.TryGetValue(attached, out attach))
				{
					attach = new Attachments(myGrid, attached.myGrid);
					Connections.Add(attached, attach);
				}

				if (add)
					attach.Add(kind);
				else
					attach.Remove(kind);
			}
		}
Пример #22
0
		internal static void AddRemoveConnection(AttachmentKind kind, IMyCubeGrid grid1, IMyCubeGrid grid2, bool add)
		{
			if (grid1 == grid2)
				return;

			AttachedGrid
				attached1 = GetFor(grid1),
				attached2 = GetFor(grid2);

			if (attached1 != null)
				attached1.AddRemoveConnection(kind, attached2, add);
			if (attached2 != null)
				attached2.AddRemoveConnection(kind, attached1, add);
		}
Пример #23
0
		internal static void AddRemoveConnection(AttachmentKind kind, Ingame.IMyCubeGrid grid1, Ingame.IMyCubeGrid grid2, bool add)
		{ AddRemoveConnection(kind, grid1 as IMyCubeGrid, grid2 as IMyCubeGrid, add); }
Пример #24
0
		/// <summary>
		/// Runs a function on all the blocks in all the attached grids.
		/// </summary>
		/// <param name="startGrid">Grid to start at.</param>
		/// <param name="allowedConnections">The types of connections allowed between grids.</param>
		/// <param name="runFunc">Func that runs on blocks of attached grids, if it returns true, short-circuit</param>
		/// <param name="runOnStartGrid">Iff true, action will be run on blocks of startGrid.</param>
		public static void RunOnAttachedBlock(IMyCubeGrid startGrid, AttachmentKind allowedConnections, Func<IMySlimBlock, bool> runFunc, bool runOnStartGrid = false)
		{
			List<IMySlimBlock> dummy = new List<IMySlimBlock>();
			bool terminated = false;

			Func<IMyCubeGrid, bool> runOnGrid = grid => {
				grid.GetBlocks_Safe(dummy, slim => {
					if (!terminated)
						terminated = runFunc(slim);
					return false;
				});
				return terminated;
			};

			RunOnAttached(startGrid, allowedConnections, runOnGrid, runOnStartGrid);
		}
Пример #25
0
        private void AddRemoveConnection(AttachmentKind kind, AttachedGrid attached, bool add)
        {
            using (lock_Connections.AcquireExclusiveUsing())
            {
                Attachments attach;
                if (!Connections.TryGetValue(attached, out attach))
                {
                    if (add)
                    {
                        attach = new Attachments(myGrid, attached.myGrid);
                        Connections.Add(attached, attach);
                    }
                    else
                    {
                        myLogger.alwaysLog("cannot remove, no attachments of kind " + kind, Logger.severity.ERROR);
                        return;
                    }
                }

                if (add)
                    attach.Add(kind);
                else
                    attach.Remove(kind);
            }
        }