예제 #1
0
        private void GetMessage()
        {
            byte[] bytesFrom = new byte[_clientSocket.ReceiveBufferSize];

            _clientSocket.Client.Receive(bytesFrom);

            string dataFromClient = Encoding.Unicode.GetString(bytesFrom);

            lock (_previousPartialMessage)
            {
                DetectDisconnectedClient(dataFromClient);
                try
                {
                    string completeMessage = _previousPartialMessage + dataFromClient;
                    //string delimieter = MudMessageInstance.Regex;
                    //string[] sections = completeMessage.Split(new[] { delimieter }, StringSplitOptions.RemoveEmptyEntries);

                    Tuple <List <string>, string> result = MudMessageInstance.ParseRawMessage(completeMessage);
                    foreach (string message in result.Item1)
                    {
                        InQueue.Enqueue(message);
                    }
                    _previousPartialMessage = result.Item2;
                }
                catch /*(Exception ex)*/
                {
                    _previousPartialMessage += dataFromClient;
                    _previousPartialMessage  = _previousPartialMessage.Replace("\0", "");
                }
            }
        }
        public override void Tick()
        {
            var openCount = ParkingLocations.Count(r => !r.IsFull);

            if (openCount > 0)
            {
                while (InQueue.Count > 0)
                {
                    var location = FindOpenLocation();
                    if (location != null)
                    {
                        location.ParkAuto(InQueue.Dequeue());
                    }
                    else
                    {
                        break;
                    }
                }
            }

            var departing = ParkingLocations.Where(r => r.Occupant != null && r.Occupant.DateToDepart <= Simulator.Clock.Now);

            foreach (var item in departing)
            {
                AutoExitingFrom(item);
            }
            base.Tick();
            while (OutQueue.Count > 0)
            {
                Parent.OutQueue.Enqueue(OutQueue.Dequeue());
            }
        }
예제 #3
0
        protected void GetMessageLoop()
        {
            try
            {
                while ((_clientSocket.Connected))
                {
                    //Handle message from client
                    try
                    {
                        GetMessage();
                    }
                    catch /*(Exception ex)*/
                    {
                        //if (ex.InnerException != null && ex.InnerException.Message != "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond")
                        //{
                        //    throw;
                        //}
                        throw;
                    }
                }

                if (!_clientSocket.Connected)
                {
                    throw new Exception("Server shutdown.");
                }
            }
            catch (Exception ex)
            {
                InQueue.Enqueue("<Exception> " + ex.ToString() + " </Exception>");
                _clientSocket.Close();
            }
        }
예제 #4
0
        public override void Tick()
        {
            var openCount = Floors.Count(r => !r.IsFull);

            if (openCount > 0)
            {
                var gateCapacity = (int)(Simulator.Interval.TotalSeconds / 10.0);
                for (int i = 0; i < gateCapacity; i++)
                {
                    var floorsWithRoom = Floors.Where(r => !r.IsFull).ToList();
                    if (InQueue.Count > 0 && floorsWithRoom.Count > 0)
                    {
                        var floor = Simulator.Random.Next(floorsWithRoom.Count);
                        floorsWithRoom[floor].InQueue.Enqueue(InQueue.Dequeue());
                    }
                }
            }
            foreach (var item in Floors)
            {
                item.Tick();
            }
            base.Tick();
            while (OutQueue.Count > 0)
            {
                Parent.OutQueue.Enqueue(OutQueue.Dequeue());
            }
        }
예제 #5
0
 public override void Tick()
 {
     if (!IsFull)
     {
         var gateCapacity = (int)(Simulator.Interval.TotalSeconds / 60.0 * 5);
         for (int i = 0; i < gateCapacity; i++)
         {
             if (InQueue.Count > 0 && !IsFull)
             {
                 var ramp = GetOpenRamp();
                 if (ramp != null)
                 {
                     ramp.InQueue.Enqueue(InQueue.Dequeue());
                 }
                 else
                 {
                     break;
                 }
             }
         }
     }
     foreach (var item in ParkingRamps)
     {
         item.Tick();
     }
     base.Tick();
     while (OutQueue.Count > 0)
     {
         var auto = OutQueue.Dequeue();
         Simulator.Notifier.Notify(new AutoDepartingFacility {
             Auto = auto
         });
     }
 }
예제 #6
0
파일: DummyPort.cs 프로젝트: Knuhl/LoopOsc
 public SerialMessage Read()
 {
     if (InQueue.Count > 0)
     {
         return(InQueue.Dequeue());
     }
     return(null);
 }
예제 #7
0
 public void AutoArrives(Auto auto)
 {
     Simulator.Notifier.Notify(new AutoArrivingAtFacility {
         Auto = auto
     });
     if (InQueue.Count < 50)
     {
         InQueue.Enqueue(auto);
     }
     else
     {
         Simulator.Notifier.Notify(new AutoAbandoningFacility {
             Auto = auto
         });
     }
 }
예제 #8
0
 protected void SendMessageLoop()
 {
     try
     {
         while ((_clientSocket.Connected))
         {
             while (OutQueue.TryDequeue(out string outboundMessage))
             {
                 SendMessage(outboundMessage);
             }
             Thread.Sleep(10);
         }
     }
     catch (Exception ex)
     {
         InQueue.Enqueue(" >> " + ex.ToString());
     }
 }
예제 #9
0
        private void fillApprovalStatus()
        {
            List <XMLDictionary> approvalsStatusList = Common.XMLDictionaryList(_systemService, "13");

            if (!string.IsNullOrEmpty(FieldType) && FieldType == "Filter")
            {
                approvalsStatusList.Add(new XMLDictionary {
                    key = 0, value = Resources.Common.All
                });
            }

            if (!string.IsNullOrEmpty(InQueue) && InQueue.ToUpper() == "FALSE")
            {
                if (approvalsStatusList.Where(x => x.key == 3).Count() != 0)
                {
                    approvalsStatusList.Remove(approvalsStatusList.Where(x => x.key == 3).ToList().First());
                }
            }
            apStatusStore.DataSource = approvalsStatusList;
            apStatusStore.DataBind();
        }
예제 #10
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (Class != null)
         {
             hashCode = hashCode * 59 + Class.GetHashCode();
         }
         if (Name != null)
         {
             hashCode = hashCode * 59 + Name.GetHashCode();
         }
         if (Url != null)
         {
             hashCode = hashCode * 59 + Url.GetHashCode();
         }
         if (Color != null)
         {
             hashCode = hashCode * 59 + Color.GetHashCode();
         }
         if (Actions != null)
         {
             hashCode = hashCode * 59 + Actions.GetHashCode();
         }
         if (Description != null)
         {
             hashCode = hashCode * 59 + Description.GetHashCode();
         }
         if (DisplayName != null)
         {
             hashCode = hashCode * 59 + DisplayName.GetHashCode();
         }
         if (DisplayNameOrNull != null)
         {
             hashCode = hashCode * 59 + DisplayNameOrNull.GetHashCode();
         }
         if (FullDisplayName != null)
         {
             hashCode = hashCode * 59 + FullDisplayName.GetHashCode();
         }
         if (FullName != null)
         {
             hashCode = hashCode * 59 + FullName.GetHashCode();
         }
         if (Buildable != null)
         {
             hashCode = hashCode * 59 + Buildable.GetHashCode();
         }
         if (Builds != null)
         {
             hashCode = hashCode * 59 + Builds.GetHashCode();
         }
         if (FirstBuild != null)
         {
             hashCode = hashCode * 59 + FirstBuild.GetHashCode();
         }
         if (HealthReport != null)
         {
             hashCode = hashCode * 59 + HealthReport.GetHashCode();
         }
         if (InQueue != null)
         {
             hashCode = hashCode * 59 + InQueue.GetHashCode();
         }
         if (KeepDependencies != null)
         {
             hashCode = hashCode * 59 + KeepDependencies.GetHashCode();
         }
         if (LastBuild != null)
         {
             hashCode = hashCode * 59 + LastBuild.GetHashCode();
         }
         if (LastCompletedBuild != null)
         {
             hashCode = hashCode * 59 + LastCompletedBuild.GetHashCode();
         }
         if (LastFailedBuild != null)
         {
             hashCode = hashCode * 59 + LastFailedBuild.GetHashCode();
         }
         if (LastStableBuild != null)
         {
             hashCode = hashCode * 59 + LastStableBuild.GetHashCode();
         }
         if (LastSuccessfulBuild != null)
         {
             hashCode = hashCode * 59 + LastSuccessfulBuild.GetHashCode();
         }
         if (LastUnstableBuild != null)
         {
             hashCode = hashCode * 59 + LastUnstableBuild.GetHashCode();
         }
         if (LastUnsuccessfulBuild != null)
         {
             hashCode = hashCode * 59 + LastUnsuccessfulBuild.GetHashCode();
         }
         if (NextBuildNumber != null)
         {
             hashCode = hashCode * 59 + NextBuildNumber.GetHashCode();
         }
         if (QueueItem != null)
         {
             hashCode = hashCode * 59 + QueueItem.GetHashCode();
         }
         if (ConcurrentBuild != null)
         {
             hashCode = hashCode * 59 + ConcurrentBuild.GetHashCode();
         }
         if (Scm != null)
         {
             hashCode = hashCode * 59 + Scm.GetHashCode();
         }
         return(hashCode);
     }
 }
예제 #11
0
        /// <summary>
        /// Returns true if FreeStyleProject instances are equal
        /// </summary>
        /// <param name="other">Instance of FreeStyleProject to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(FreeStyleProject other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Class == other.Class ||
                     Class != null &&
                     Class.Equals(other.Class)
                     ) &&
                 (
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                 ) &&
                 (
                     Url == other.Url ||
                     Url != null &&
                     Url.Equals(other.Url)
                 ) &&
                 (
                     Color == other.Color ||
                     Color != null &&
                     Color.Equals(other.Color)
                 ) &&
                 (
                     Actions == other.Actions ||
                     Actions != null &&
                     Actions.SequenceEqual(other.Actions)
                 ) &&
                 (
                     Description == other.Description ||
                     Description != null &&
                     Description.Equals(other.Description)
                 ) &&
                 (
                     DisplayName == other.DisplayName ||
                     DisplayName != null &&
                     DisplayName.Equals(other.DisplayName)
                 ) &&
                 (
                     DisplayNameOrNull == other.DisplayNameOrNull ||
                     DisplayNameOrNull != null &&
                     DisplayNameOrNull.Equals(other.DisplayNameOrNull)
                 ) &&
                 (
                     FullDisplayName == other.FullDisplayName ||
                     FullDisplayName != null &&
                     FullDisplayName.Equals(other.FullDisplayName)
                 ) &&
                 (
                     FullName == other.FullName ||
                     FullName != null &&
                     FullName.Equals(other.FullName)
                 ) &&
                 (
                     Buildable == other.Buildable ||
                     Buildable != null &&
                     Buildable.Equals(other.Buildable)
                 ) &&
                 (
                     Builds == other.Builds ||
                     Builds != null &&
                     Builds.SequenceEqual(other.Builds)
                 ) &&
                 (
                     FirstBuild == other.FirstBuild ||
                     FirstBuild != null &&
                     FirstBuild.Equals(other.FirstBuild)
                 ) &&
                 (
                     HealthReport == other.HealthReport ||
                     HealthReport != null &&
                     HealthReport.SequenceEqual(other.HealthReport)
                 ) &&
                 (
                     InQueue == other.InQueue ||
                     InQueue != null &&
                     InQueue.Equals(other.InQueue)
                 ) &&
                 (
                     KeepDependencies == other.KeepDependencies ||
                     KeepDependencies != null &&
                     KeepDependencies.Equals(other.KeepDependencies)
                 ) &&
                 (
                     LastBuild == other.LastBuild ||
                     LastBuild != null &&
                     LastBuild.Equals(other.LastBuild)
                 ) &&
                 (
                     LastCompletedBuild == other.LastCompletedBuild ||
                     LastCompletedBuild != null &&
                     LastCompletedBuild.Equals(other.LastCompletedBuild)
                 ) &&
                 (
                     LastFailedBuild == other.LastFailedBuild ||
                     LastFailedBuild != null &&
                     LastFailedBuild.Equals(other.LastFailedBuild)
                 ) &&
                 (
                     LastStableBuild == other.LastStableBuild ||
                     LastStableBuild != null &&
                     LastStableBuild.Equals(other.LastStableBuild)
                 ) &&
                 (
                     LastSuccessfulBuild == other.LastSuccessfulBuild ||
                     LastSuccessfulBuild != null &&
                     LastSuccessfulBuild.Equals(other.LastSuccessfulBuild)
                 ) &&
                 (
                     LastUnstableBuild == other.LastUnstableBuild ||
                     LastUnstableBuild != null &&
                     LastUnstableBuild.Equals(other.LastUnstableBuild)
                 ) &&
                 (
                     LastUnsuccessfulBuild == other.LastUnsuccessfulBuild ||
                     LastUnsuccessfulBuild != null &&
                     LastUnsuccessfulBuild.Equals(other.LastUnsuccessfulBuild)
                 ) &&
                 (
                     NextBuildNumber == other.NextBuildNumber ||
                     NextBuildNumber != null &&
                     NextBuildNumber.Equals(other.NextBuildNumber)
                 ) &&
                 (
                     QueueItem == other.QueueItem ||
                     QueueItem != null &&
                     QueueItem.Equals(other.QueueItem)
                 ) &&
                 (
                     ConcurrentBuild == other.ConcurrentBuild ||
                     ConcurrentBuild != null &&
                     ConcurrentBuild.Equals(other.ConcurrentBuild)
                 ) &&
                 (
                     Scm == other.Scm ||
                     Scm != null &&
                     Scm.Equals(other.Scm)
                 ));
        }
예제 #12
0
 /// <summary>
 /// Retrieve a packet from the received packets queue.
 /// </summary>
 /// <param name="packet"> The retrieved packet if any. </param>
 /// <returns> True on success. </returns>
 public virtual bool DequeueReceivedPacketQueue(out Packet packet)
 {
     return(InQueue.TryDequeue(out packet));
 }
예제 #13
0
 /// <summary>
 /// Add a received packet to the queue.
 /// </summary>
 /// <param name="packet"> The packet to enqueue. </param>
 protected virtual void EnqueueReceivedPacket(Packet packet)
 {
     InQueue.Enqueue(packet);
 }
예제 #14
0
파일: ServerHandler.cs 프로젝트: crybx/mud
        private void MessageHandlerLoop()
        {
            bool     continueToLoop = true;
            DateTime lastMessage    = DateTime.Now;

            try
            {
                while (continueToLoop && _clientSocket.Connected)
                {
                    //Need to make the thread sleep
                    Thread.Sleep(10);

                    IPlayerCharacter pc = null;

                    TimeOutIdleConnection(lastMessage, pc);

                    #region Get Message From Client
                    //Handle message from client
                    try
                    {
                        string messageFromClient;
                        if (InQueue.TryDequeue(out messageFromClient))
                        {
                            switch (_loginState)
                            {
                            case LoginState.UserName:
                                _userName   = messageFromClient;
                                _loginState = LoginState.Password;
                                OutQueue.Enqueue(GlobalReference.GlobalValues.TagWrapper.WrapInTag("What is your password."));

                                break;

                            case LoginState.Password:
                                _password = messageFromClient;

                                pc = GlobalReference.GlobalValues.World.LoadCharacter(_userName);
                                if (pc == null)
                                {
                                    GlobalReference.GlobalValues.Logger.Log(LogLevel.ALL, string.Format("{0} is an unknown user, offered to make a new one.", _userName, _password));
                                    _loginState = LoginState.CreateCharacter;
                                    OutQueue.Enqueue(GlobalReference.GlobalValues.TagWrapper.WrapInTag("Character not found.  Would you like to create the character?"));
                                }
                                else
                                {
                                    if (pc.Password == _password)
                                    {
                                        GlobalReference.GlobalValues.Logger.Log(LogLevel.ALL, string.Format("{0} logged in successfully.", _userName));
                                        GlobalReference.GlobalValues.World.AddPlayerQueue.Enqueue(pc);
                                        GuidToCharacter.AddOrUpdate(_guid, pc, (k, v) => v = pc);
                                        _loginState = LoginState.LoggedIn;
                                    }
                                    else
                                    {
                                        GlobalReference.GlobalValues.Logger.Log(LogLevel.ALL, string.Format("{0} failed to log in with password {1}.", _userName, _password));
                                        _loginState = LoginState.AsciiArt;
                                        OutQueue.Enqueue(GlobalReference.GlobalValues.TagWrapper.WrapInTag("Invalid username/password."));
                                    }
                                }
                                break;

                            case LoginState.LoggedIn:
                                //player character should be loaded
                                GuidToCharacter.TryGetValue(_guid, out pc);
                                if (pc != null)
                                {
                                    pc.EnqueueCommand(messageFromClient);
                                    if (messageFromClient.ToUpper() == "LOGOUT")
                                    {
                                        continueToLoop = false;
                                    }
                                }
                                //not sure why we could not find the player character.  Relogin.
                                else
                                {
                                    _loginState = LoginState.AsciiArt;
                                }
                                break;

                            case LoginState.CreateCharacter:
                                if (messageFromClient.Substring(0, 1).ToUpper() == "Y")
                                {
                                    pc = GlobalReference.GlobalValues.World.CreateCharacter(_userName, _password);
                                    GuidToCharacter.AddOrUpdate(_guid, pc, (k, v) => v = pc);
                                    _loginState = LoginState.LoggedIn;
                                }
                                else if (messageFromClient.Substring(0, 1).ToUpper() == "N")
                                {
                                    _loginState = LoginState.AsciiArt;
                                }
                                else
                                {
                                    OutQueue.Enqueue(GlobalReference.GlobalValues.TagWrapper.WrapInTag("Character not found.  Would you like to create the character? Yes/No"));
                                }
                                break;
                            }

                            lastMessage = DateTime.Now;
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex.InnerException != null && ex.InnerException.Message != "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond")
                        {
                            throw;
                        }
                    }
                    #endregion Get Message From Client

                    #region Send Message To Client
                    switch (_loginState)
                    {
                    case LoginState.AsciiArt:
                        OutQueue.Enqueue(GlobalReference.GlobalValues.TagWrapper.WrapInTag(GlobalReference.GlobalValues.Settings.AsciiArt, TagType.AsciiArt));

                        OutQueue.Enqueue(GlobalReference.GlobalValues.TagWrapper.WrapInTag("Welcome adventure. What is your name?"));
                        _loginState = LoginState.UserName;
                        break;
                    }


                    if (_guid != null)
                    {
                        pc = null;
                        GuidToCharacter.TryGetValue(_guid, out pc);
                        if (pc != null)
                        {
                            string messageToClient = pc.DequeueMessage();
                            if (messageToClient != null)
                            {
                                OutQueue.Enqueue(messageToClient);
                            }
                        }
                    }
                    #endregion Send Mesage To Client
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(" >> " + ex.ToString());
            }
        }