예제 #1
0
        public void 繞行SafeCollection操作集合_不同執行緒同時對SafeCollection新增與刪除元素_不應擲出例外()
        {
            var safeCollection = new SafeCollection <int> {
                1, 2, 3, 4, 5
            };

            Task.Run(() =>
            {
                while (true)
                {
                    safeCollection.Add(0);
                }
            });

            Task.Run(() =>
            {
                while (true)
                {
                    safeCollection.Remove(0);
                }
            });

            Task.Run(() =>
            {
                while (true)
                {
                    safeCollection.Clear();
                }
            });

            Action action = () => IterateCollection(safeCollection).Wait();

            action.Should().NotThrow();
        }
예제 #2
0
파일: ChatRoom.cs 프로젝트: rhoadsce/JabbR
 public ChatRoom()
 {
     Owners = new SafeCollection<ChatUser>();
     Messages = new SafeCollection<ChatMessage>();
     Users = new SafeCollection<ChatUser>();
     AllowedUsers = new SafeCollection<ChatUser>();
 }
예제 #3
0
파일: ChatUser.cs 프로젝트: rhoadsce/JabbR
 public ChatUser()
 {
     ConnectedClients = new SafeCollection<ChatClient>();
     OwnedRooms = new SafeCollection<ChatRoom>();
     Rooms = new SafeCollection<ChatRoom>();
     AllowedRooms = new SafeCollection<ChatRoom>();
 }
예제 #4
0
 public ChatRoom()
 {
     Owners       = new SafeCollection <ChatUser>();
     Messages     = new SafeCollection <ChatMessage>();
     Users        = new SafeCollection <ChatUser>();
     AllowedUsers = new SafeCollection <ChatUser>();
 }
예제 #5
0
 /// <summary>
 /// 把WCF的消息分发到本地
 /// </summary>
 /// <param name="listMessage"></param>
 public void SendMessage(SafeCollection <MessageModel> listMessage)
 {
     if (listMessage != null && listMessage.Count > 0)
     {
         MessageManager.Instance.AddMessageFromServer(listMessage);
     }
 }
예제 #6
0
파일: Room.cs 프로젝트: jrmitch120/Legend
 public Room()
 {
     PlayerReferences       = new SafeCollection <Reference <Player> >();
     Items                  = new SafeCollection <Item>();
     Spawns                 = new Spawns();
     AdjacentRoomReferences = new ConcurrentDictionary <char, Reference <Room> >();
 }
예제 #7
0
 /// <summary>
 /// 把WCF的通知分发到本地
 /// </summary>
 /// <param name="listNotice"></param>
 public void SendNotice(SafeCollection <NoticeModel> listNotice)
 {
     if (listNotice != null && listNotice.Count > 0)
     {
         MessageManager.Instance.AddNoticeFromServer(listNotice);
     }
 }
예제 #8
0
 public Room()
 {
     PlayerReferences = new SafeCollection<Reference<Player>>();
     Items = new SafeCollection<Item>();
     Spawns = new Spawns();
     AdjacentRoomReferences = new ConcurrentDictionary<char, Reference<Room>>();
 }
예제 #9
0
 public ChatUser()
 {
     ConnectedClients = new SafeCollection <ChatClient>();
     OwnedRooms       = new SafeCollection <ChatRoom>();
     Rooms            = new SafeCollection <ChatRoom>();
     AllowedRooms     = new SafeCollection <ChatRoom>();
 }
 public MessangerGroup()
 {
     Owners = new SafeCollection<MessangerUser>();
     Messages = new SafeCollection<Message>();
     Users = new SafeCollection<MessangerUser>();
     AllowedUsers = new SafeCollection<MessangerUser>();
 }
 public MessangerUser()
 {
     ConnectedClients = new SafeCollection<MessangerClient>();
     OwnedGroups = new SafeCollection<MessangerGroup>();
     Groups = new SafeCollection<MessangerGroup>();
     AllowedGroups = new SafeCollection<MessangerGroup>();
     ReadMessages = new SafeCollection<Message>();
 }
예제 #12
0
        public void 詢問SafeCollection是否包含目標元素_不含有該元素_應回傳False()
        {
            var safeCollection = new SafeCollection <int> {
                1, 2, 3
            };
            var isContain = safeCollection.Contains(4);

            isContain.Should().Be(false);
        }
예제 #13
0
        public void 詢問SafeCollection是否包含目標元素_含有該元素_應回傳True()
        {
            var safeCollection = new SafeCollection <int> {
                1, 2, 3
            };
            var isContain = safeCollection.Contains(2);

            isContain.Should().Be(true);
        }
예제 #14
0
파일: ChatRoom.cs 프로젝트: Widdershin/vox
 public ChatRoom()
 {
     Owners = new SafeCollection<ChatUser>();
     Messages = new SafeCollection<ChatMessage>();
     Users = new SafeCollection<ChatUser>();
     UserData = new SafeCollection<ChatRoomUserData>();
     AllowedUsers = new SafeCollection<ChatUser>();
     Attachments = new SafeCollection<Attachment>();
 }
예제 #15
0
파일: ChatUser.cs 프로젝트: yadyn/JabbR
 public ChatUser()
 {
     Identities = new SafeCollection<ChatUserIdentity>();
     ConnectedClients = new SafeCollection<ChatClient>();
     OwnedRooms = new SafeCollection<ChatRoom>();
     Rooms = new SafeCollection<ChatRoom>();
     AllowedRooms = new SafeCollection<ChatRoom>();
     Attachments = new SafeCollection<Attachment>();
     Notifications = new SafeCollection<Notification>();
 }
예제 #16
0
        public MinersJob()
        {
            Pool_Miners = new List <Miners>();
            this.UpdateMiners();

            this.timer           = new Timer(5 * 60 * 1000);
            this.timer.AutoReset = true;
            this.timer.Elapsed  += Timer_Elapsed;
            this.timer.Start();
        }
예제 #17
0
파일: ChatUser.cs 프로젝트: richross/JabbR
 public ChatUser()
 {
     Identities       = new SafeCollection <ChatUserIdentity>();
     ConnectedClients = new SafeCollection <ChatClient>();
     OwnedRooms       = new SafeCollection <ChatRoom>();
     Rooms            = new SafeCollection <ChatRoom>();
     AllowedRooms     = new SafeCollection <ChatRoom>();
     Attachments      = new SafeCollection <Attachment>();
     Notifications    = new SafeCollection <Notification>();
 }
예제 #18
0
        public void SafeCollection中移除指定元素_集合不包含該元素且移除元素失敗_集合長度不變且回傳False()
        {
            var safeCollection = new SafeCollection <int> {
                1, 2, 3, 4, 5
            };
            var       isSuccessful  = safeCollection.Remove(6);
            const int expectedCount = 5;

            safeCollection.Count.Should().Be(expectedCount);
            isSuccessful.Should().Be(false);
        }
예제 #19
0
        public void SafeCollection中移除指定元素_集合包含該元素且移除元素成功_集合長度減少1且回傳True()
        {
            var safeCollection = new SafeCollection <int> {
                1, 2, 3, 4, 5
            };
            var       isSuccessful  = safeCollection.Remove(4);
            const int expectedCount = 4;

            safeCollection.Count.Should().Be(expectedCount);
            isSuccessful.Should().Be(true);
        }
예제 #20
0
        public void 清除含有3個元素的SafeCollection_清除成功_集合長度應為0()
        {
            var safeCollection = new SafeCollection <int> {
                1, 2, 3
            };

            safeCollection.Clear();
            const int expecetedCount = 0;

            safeCollection.Count.Should().Be(expecetedCount);
        }
예제 #21
0
        public void 拷貝SafeCollection_從Index0開始拷貝_拷貝的結果應該與SafList相同()
        {
            var safeCollection = new SafeCollection <int>();
            var fixture        = new Fixture();

            safeCollection.AddMany(fixture.Create <int>, 10);
            var array = new int[10];

            safeCollection.CopyTo(array, 0);
            array.Should().BeEquivalentTo(safeCollection);
        }
예제 #22
0
        /// <summary>
        /// 接收来自服务端的信息
        /// </summary>
        public void AddNoticeFromServer(SafeCollection <NoticeModel> listNotice)
        {
            foreach (NoticeModel model in listNotice)
            {
                CometWaitThread cometWaitThread = CometThreadPool.GetUserThread(model.ReceiveUserId);

                if (cometWaitThread != null)
                {
                    cometWaitThread.AddNotice(model);
                }
            }
        }
예제 #23
0
        public void 初始化一個SafeCollection並加入1個元素_加入成功_集合中應包含該元素且長度為1()
        {
            var safeCollection = new SafeCollection <int>();
            var fixture        = new Fixture();
            var element        = fixture.Create <int>();

            safeCollection.Add(element);
            const int expecetedCount = 1;

            safeCollection.First().Should().Be(element);
            safeCollection.Count.Should().Be(expecetedCount);
        }
예제 #24
0
 public void Regist(string key, Action <string> action)
 {
     if (msgs.ContainsKey(key))
     {
         msgs[key].Add(action);
     }
     else
     {
         SafeCollection <Action <string> > actions = new SafeCollection <Action <string> >();
         actions.Add(action);
         msgs.Add(key, actions);
     }
 }
 public void AddRange(Type type, IEnumerable<MemberMetadata> metadatas)
 {
     type.ThrowIfNull("type", "Parameter cannot be null.");
     if (_container.ContainsKey(type))
     {
         _container[type].AddRange(metadatas);
     }
     else
     {
         SafeCollection<MemberMetadata> holder = new SafeCollection<MemberMetadata>();
         holder.AddRange(metadatas);
         _container.TryAdd(type, holder);
     }
 }
예제 #26
0
        public void 繞行SafeCollection_繞行成功_繞行結果需與原本集合相同()
        {
            var safeCollection = new SafeCollection <int>();
            var fixture        = new Fixture();

            safeCollection.AddMany(fixture.Create <int>, 10);
            var result = new Collection <int>();

            foreach (var x in safeCollection)
            {
                result.Add(x);
            }
            result.Should().BeEquivalentTo(safeCollection);
        }
        public void Add(Type contract, FastReflection.IDynamicConstructor ctor)
        {
            contract.ThrowIfNull("contract", "Parameter cannot be null.");
            ctor.ThrowIfNull("ctor", "Parameter cannot be null.");

            if (_ctorContainer.ContainsKey(contract))
            {
                _ctorContainer[contract].Add(ctor);
            }
            else
            {
                SafeCollection<FastReflection.IDynamicConstructor> collection = new SafeCollection<FastReflection.IDynamicConstructor>();
                collection.Add(ctor);
                _ctorContainer.TryAdd(contract, collection);
            }
        }
예제 #28
0
        public CustomRepository()
        {
            _users         = new SafeCollection <ChatUser>();
            _rooms         = new SafeCollection <ChatRoom>();
            _identities    = new SafeCollection <ChatUserIdentity>();
            _attachments   = new SafeCollection <Attachment>();
            _notifications = new SafeCollection <Notification>();
            _settings      = new SafeCollection <Settings>();

            LoadCollectionFromStorage(_users, _usersFileName);
            LoadCollectionFromStorage(_rooms, _roomsFileName);
            LoadCollectionFromStorage(_identities, _identitiesFileName);
            LoadCollectionFromStorage(_settings, _settingsFileName);

            FixNullCollections();
        }
예제 #29
0
파일: Player.cs 프로젝트: jrmitch120/Legend
        public Player()
        {
            ClientIds = new SafeCollection <string>();
            Items     = new SafeCollection <Item>();

            // need this because serialization doesn't store case insensitivity
            Spells = new CaseInsensitiveConcurrentDictionary <Spell>();

            /*
             * PlayerStatus = PlayerStatus | PlayerStatuses.Invisible;
             * var chk1 = PlayerStatus.HasFlag(PlayerStatuses.Invisible);
             * PlayerStatus = PlayerStatus ^ PlayerStatuses.Invisible;
             * var chk2 = PlayerStatus.HasFlag(PlayerStatuses.Invisible);
             */
            Reset();
        }
 public bool EmptyAndAddRange(Type type, SafeCollection<InterceptorInfo> interceptors)
 {
     if (!_interceptorsMappings.ContainsKey(type))
     {
         bool added = _interceptorsMappings.TryAdd(type, new SafeCollection<InterceptorInfo>());
         if (added)
         {
             _interceptorsMappings[type].AddRange(interceptors);
             return added;
         }
         else
             return false;
     }
     else
     {
         _interceptorsMappings[type].Clear();
         _interceptorsMappings[type].AddRange(interceptors);
         return true;
     }
 }
예제 #31
0
        /// <summary>
        /// 发送通知
        /// </summary>
        public bool SendNotice(Guid sendUserId, string sendNickName, Guid receiveUserId, int noticeType, int status, string args)
        {
            try
            {
                //InstanceContext instanceContext = new InstanceContext(new CommunicationCallback());

                var noticeModel = new NoticeModel
                {
                    SendUserId     = sendUserId,
                    SendNickName   = sendNickName,
                    ReceiveUserId  = receiveUserId,
                    NoticeType     = noticeType,
                    Status         = status,
                    Args           = args,
                    LastActiveDate = DateTime.Now
                };

                //处理用户消息
                SafeCollection <NoticeModel> listNoticeModel = new SafeCollection <NoticeModel>();
                listNoticeModel.Add(noticeModel);
                ICommunicationCallback _client = new CommunicationCallback();
                //向服务器发送通知
                _client.SendNotice(listNoticeModel);

                //using (DuplexChannelFactory<ICommunication> channelFactory = new DuplexChannelFactory<ICommunication>(instanceContext, "CommunicationService"))
                //{
                //    ICommunication proxy = channelFactory.CreateChannel();

                //    using (proxy as IDisposable)
                //    {
                //        proxy.InsertNotice(noticeModel);
                //    }
                //}

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
예제 #32
0
        private BackgroundWorker worker; // the library background worker

        #endregion Fields

        #region Constructors

        //========================================================================================
        // Constructors
        //========================================================================================
        /// <summary>
        /// Private singleton constructor.
        /// </summary>
        private Librarian(Controller controller)
        {
            this.controller = controller;
            this.queue = new BlockingQueue<IScanner>();
            this.actives = new SafeCollection<IScanner>();
            this.cleansed = new StringCollection();
            this.disabled = new StringCollection();
            this.scanner = null;
            this.sync = new Object();

            // temporarily reference an empty catalog
            this.catalog = new TerseCatalog();

            this.worker = new BackgroundWorker();
            this.worker.DoWork += new DoWorkEventHandler(DoWork);
            this.worker.ProgressChanged += new ProgressChangedEventHandler(DoProgressChanged);
            this.worker.WorkerReportsProgress = true;
            this.worker.WorkerSupportsCancellation = true;
            this.worker.RunWorkerAsync();

            AddScanner(new InitializingScanner(controller, this));
        }
예제 #33
0
        /// <summary>
        /// 获取用户消息
        /// </summary>
        public List <MessageModel> GetMessage(Guid receiveUserId)
        {
            try
            {
                List <MessageModel> listMessageModel = new List <MessageModel>();
                int nGroup = GuidCoveter.CoveterFirstChat(receiveUserId) % groups;

                Thread.Sleep(3);

                if (listMessage[nGroup] == null)
                {
                    listMessage[nGroup] = new SafeCollection <MessageModel>();
                }

                foreach (MessageModel model in listMessage[nGroup])
                {
                    //清理掉超时5分钟没被领走的消息
                    if (DateTime.Now.Subtract(model.SendTimeOfService).TotalSeconds > 300)
                    {
                        listMessage[nGroup].Remove(model);
                        continue;
                    }

                    if (model.ReceiveUserId == receiveUserId)
                    {
                        listMessageModel.Add(model);
                        listMessage[nGroup].Remove(model);
                    }
                }

                return(listMessageModel);
            }
            catch (Exception exception)
            {
                log.Warn("获取线程内消息队列出现异常:" + exception.Message);
                return(new List <MessageModel>());
            }
        }
예제 #34
0
        /// <summary>
        /// 取用户的通知
        /// </summary>
        /// <param name="receiveUserId"></param>
        /// <returns></returns>
        public List <NoticeModel> GetNotice(Guid receiveUserId)
        {
            try
            {
                List <NoticeModel> listNoticeModel = new List <NoticeModel>();
                int nGroup = GuidCoveter.CoveterFirstChat(receiveUserId) % groups;

                Thread.Sleep(3);

                if (listNotice[nGroup] == null)
                {
                    listNotice[nGroup] = new SafeCollection <NoticeModel>();
                }

                foreach (NoticeModel model in listNotice[nGroup])
                {
                    //清理掉超时50秒没被领走的消息
                    if (DateTime.Now.Subtract(model.LastActiveDate).Seconds > 50)
                    {
                        listNotice[nGroup].Remove(model);
                        continue;
                    }

                    if (model.ReceiveUserId == receiveUserId)
                    {
                        listNoticeModel.Add(model);
                        listNotice[nGroup].Remove(model);
                    }
                }

                return(listNoticeModel);
            }
            catch (Exception exception)
            {
                log.Warn("获取线程内通知队列出现异常:" + exception.Message);
                return(new List <NoticeModel>());
            }
        }
예제 #35
0
        private void UpdateServerTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            updateServerTimer.Stop();
            try
            {
                var poolIds = RedisManager.Current.GetDataInRedis <List <string> >(KeyHelper.GetPoolCenterName(isTestnet));
                if (poolIds == null || !poolIds.Any())
                {
                    Pools = new SafeCollection <PoolInfo>();
                    LogHelper.Info("poolIds is null");
                    return;
                }
                var poolInfoKeys = poolIds.Select(x => KeyHelper.GetPoolInfoKey(x));
                if (poolInfoKeys == null || !poolInfoKeys.Any())
                {
                    Pools = new SafeCollection <PoolInfo>();
                    LogHelper.Info("poolInfoKeys is null");
                    return;
                }
                var serverList = poolInfoKeys.Select(x => RedisManager.Current.GetDataInRedis <PoolInfo>(x)).ToList();
                if (poolInfoKeys == null || !serverList.Any())
                {
                    Pools = new SafeCollection <PoolInfo>();
                    LogHelper.Info("serverList is null");
                    return;
                }

                Pools = serverList;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.ToString());
            }
            finally
            {
                updateServerTimer.Start();
            }
        }
예제 #36
0
        /// <summary>
        /// 添加用户消息
        /// </summary>
        public void AddMessage(MessageModel model)
        {
            try
            {
                if (model == null)
                {
                    return;
                }

                int group = GuidCoveter.CoveterFirstChat(model.ReceiveUserId) % groups;

                if (listMessage[group] == null)
                {
                    listMessage[group] = new SafeCollection <MessageModel>();
                }

                listMessage[group].Add(model);
            }
            catch (Exception exception)
            {
                log.Warn("发送消息给线程内队列出现异常:" + exception.Message);
            }
        }
예제 #37
0
        /// <summary>
        /// 发送消息
        /// </summary>
        public bool SendPrivateMessage(Guid sendUserId, Guid receiveUserId, string message)
        {
            try
            {
                //InstanceContext instanceContext = new InstanceContext(new CommunicationCallback());

                var messageModel = new MessageModel
                {
                    SendUserId        = sendUserId,
                    ReceiveUserId     = receiveUserId,
                    Message           = message,
                    SendTimeOfService = DateTime.Now
                };

                //处理用户消息
                SafeCollection <MessageModel> listMessageModel = new SafeCollection <MessageModel>();
                listMessageModel.Add(messageModel);
                ICommunicationCallback _client = new CommunicationCallback();
                //向服务器发送消息
                _client.SendMessage(listMessageModel);

                //using (DuplexChannelFactory<ICommunication> channelFactory = new DuplexChannelFactory<ICommunication>(instanceContext, "CommunicationService"))
                //{
                //    ICommunication proxy = channelFactory.CreateChannel();

                //    using (proxy as IDisposable)
                //    {
                //        proxy.InsertMessage(message);
                //    }
                //}
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        public void TetsTypeGetHashCode()
        {
            SafeCollection<int> coll = new SafeCollection<int>();

            var types = from a in AppDomain.CurrentDomain.GetAssemblies().AsParallel()
                        let tps = a.GetTypes()
                        from t in tps

                        where !a.FullName.Contains("System") && t.IsPublic && t != null & !t.IsNested
                        select new { Asm= a, Types= tps };

            foreach(var item in types)
            {
                if (item.Asm == null)
                    continue;
                foreach (Type t in item.Types)
                {
                    if (t != null)
                    {
                        coll.Add(t.GetHashCode());
                    }
                }
            }
        }
예제 #39
0
 public Message()
 {
     UsersWhoRead = new SafeCollection<MessangerUser>();
 }
예제 #40
0
        private void UpdateMiners()
        {
            MinersComponent minersComponent = new MinersComponent();

            Pool_Miners = new SafeCollection <Miners>(minersComponent.GetAllMiners());
        }
예제 #41
0
 public Spell()
 {
     Reagents = new SafeCollection<Reference<Item>>();
     MinLevel = 0;
 }
예제 #42
0
 internal PoolTask()
 {
     MinerEfforts       = new SafeCollection <MinerEffort>();
     SavingMinerEfforts = new SafeCollection <MinerEffort>();
 }
예제 #43
0
        /// <summary>
        /// Ensures the queued workers are stopped and disposed.
        /// </summary>
        public void Dispose()
        {
            if (!isDisposed)
            {
                if (watcher != null)
                {
                    watcher.EnableRaisingEvents = false;
                    watcher.Dispose();
                    watcher = null;
                }

                if (queue != null)
                {
                    queue.Dispose();
                    queue = null;
                }

                if (worker != null)
                {
                    if (worker.IsBusy)
                    {
                        worker.CancelAsync();
                    }

                    worker.Dispose();
                    worker = null;
                }

                if (catalog != null)
                {
                    catalog.Dispose();
                    catalog = null;
                }

                if (actives != null)
                {
                    actives.Clear();
                    actives = null;
                }

                if (disabled != null)
                {
                    disabled.Clear();
                    disabled = null;
                }

                if (cleansed != null)
                {
                    cleansed.Clear();
                    cleansed = null;
                }

                controller = null;

                isDisposed = true;
            }
        }
예제 #44
0
 public Spawns()
 {
     ItemSpawns = new SafeCollection<ItemSpawn>();
 }
예제 #45
0
 public ChatMessage()
 {
     Notifications = new SafeCollection<Notification>();
 }