Example #1
0
        public async Task <IEnumerable <ReceivedMessageModel> > WaitForMessages()
        {
            string deviceId = DeviceId;
            string userName = UserName;

            DateTime startDate = DateTime.Now;

            while (DateTime.Now.Subtract(startDate).TotalSeconds < 600)
            {
                var ids = QueueInstances.MessageQueue.GetUnReceivedMessages(userName, deviceId);
                if (ids.Count() > 0)
                {
                    return(Get(ids.ToArray()));
                }

                await UserCommandsLock.Wait(userName, DeviceId);
            }
            return(null);
        }
        public async Task <CommandModel> WaitForCommand()
        {
            string deviceId = DeviceId;
            string userName = UserName;

            DateTime startDate = DateTime.Now;

            while (DateTime.Now.Subtract(startDate).TotalSeconds < 600)
            {
                var ids = QueueInstances.MessageQueue.GetUnReceivedMessages(userName, deviceId);
                if (ids.Count() > 0)
                {
#if DEBUG
                    Console.WriteLine("WaitForCommand : Returning ReceiveMessage command to User " + userName);
#endif
                    return(new CommandModel()
                    {
                        CommandType = CommandTypeEnum.ReceiveMessage,
                        Date = DateTime.Now,
                        DestinationUserName = userName,
                        ItemIds = ids.ToArray()
                    });
                }

                ids = QueueInstances.FileTransfersQueue.GetUnReceivedDownloadCommands(userName, deviceId);
                if (ids.Count() > 0)
                {
#if DEBUG
                    Console.WriteLine("WaitForCommand : Returning download commandto User " + userName);
#endif
                    return(new CommandModel()
                    {
                        CommandType = CommandTypeEnum.DownloadFile,
                        Date = DateTime.Now,
                        DestinationUserName = userName,
                        ItemIds = ids.ToArray()
                    });
                }

                ids = QueueInstances.FileTransfersQueue.GetUnReceivedUploadCommands(userName, deviceId);
                if (ids.Count() > 0)
                {
#if DEBUG
                    Console.WriteLine("WaitForCommand : Returning Upload command to User " + userName);
#endif
                    return(new CommandModel()
                    {
                        CommandType = CommandTypeEnum.UploadFile,
                        Date = DateTime.Now,
                        DestinationUserName = userName,
                        ItemIds = ids.ToArray()
                    });
                }

                ids = Program.ConnectionRequestsManager.GetApprovedConnections(userName, deviceId);
                if (ids.Count() > 0)
                {
#if DEBUG
                    Console.WriteLine("WaitForCommand : Returning ApprovedConnectionRequest command to User " + userName);
#endif
                    return(new CommandModel()
                    {
                        CommandType = CommandTypeEnum.ApprovedConnectionRequest,
                        Date = DateTime.Now,
                        DestinationUserName = userName,
                        ItemIds = ids.ToArray()
                    });
                }

                ids = Program.ConnectionRequestsManager.GetRequestedConnections(userName, deviceId);
                if (ids.Count() > 0)
                {
#if DEBUG
                    Console.WriteLine("WaitForCommand : Returning ConnectionRequest command to User " + userName);
#endif
                    return(new CommandModel()
                    {
                        CommandType = CommandTypeEnum.ConnectionRequest,
                        Date = DateTime.Now,
                        DestinationUserName = userName,
                        ItemIds = ids.ToArray()
                    });
                }

                await UserCommandsLock.Wait(userName, DeviceId);
            }
            return(null);
        }