Example #1
0
        /// <summary>
        /// 사용중인 리소스를 반환하고 소켓을 종료하여 네트워크 작업을 종료합니다.
        /// 종료처리 후 EventClose가 호출됩니다.
        /// </summary>
        public virtual void Close(int reason = AegisResult.Ok)
        {
            try
            {
                //  작업 중 다른 이벤트가 처리되지 못하도록 Clear까지 lock을 걸어야 한다.
                lock (this)
                {
                    if (Socket == null)
                    {
                        return;
                    }

                    Socket.LingerState = new LingerOption(true, 3);
                    Socket.Close();
                    Socket = null;


                    Inactivated?.Invoke(this);


                    SpinWorker.Dispatch(() =>
                    {
                        EventClose?.Invoke(new IOEventResult(this, IOEventType.Close, reason));
                    });


                    _method.Clear();
                }
            }
            catch (Exception e)
            {
                Logger.Err(LogMask.Aegis, e.ToString());
            }
        }
Example #2
0
        public void Close()
        {
            EventClose?.Invoke(new IOEventResult(this, IOEventType.Close, AegisResult.Ok));

            AegisTask.SafeAction(() =>
            {
                PipeStream?.Close();
                PipeStream = null;
            });
        }
Example #3
0
        private void SocketEvent_Receive(IAsyncResult ar)
        {
            EndPoint remoteEP = new IPEndPoint(IPAddress.Any, 0);


            try
            {
                lock (this)
                {
                    var socket     = _socket;
                    int transBytes = socket?.EndReceiveFrom(ar, ref remoteEP) ?? -1;
                    if (transBytes == -1)
                    {
                        return;
                    }

                    byte[] dispatchBuffer = new byte[transBytes];
                    Array.Copy(_receivedBuffer, dispatchBuffer, transBytes);
                    SpinWorker.Dispatch(() =>
                    {
                        EventRead?.Invoke(new IOEventResult(remoteEP, IOEventType.Read, dispatchBuffer, 0, transBytes, 0));
                    });

                    WaitForReceive();
                }
            }
            catch (SocketException)
            {
                SpinWorker.Dispatch(() =>
                {
                    EventClose?.Invoke(new IOEventResult(remoteEP, IOEventType.Close, AegisResult.ClosedByRemote));
                });

                WaitForReceive();
            }
            catch (Exception e)
            {
                if (ExceptionRaised == null)
                {
                    Logger.Err(LogMask.Aegis, e.ToString());
                }
                else
                {
                    ExceptionRaised.Invoke(e);
                }
            }
        }
Example #4
0
        private void OnRead(IAsyncResult ar)
        {
            int transBytes = PipeStream.EndRead(ar);

            if (transBytes == 0)
            {
                PipeStream.Close();
                PipeStream = null;

                EventClose?.Invoke(new IOEventResult(this, IOEventType.Close, AegisResult.ClosedByRemote));
                return;
            }


            EventRead?.Invoke(new IOEventResult(this, IOEventType.Read, _receivedBuffer, 0, transBytes, AegisResult.Ok));
            WaitForReceive();
        }
Example #5
0
        private void ReceiveThread()
        {
            byte[] buffer = new byte[BaudRate * 2];


            while (_receiveThread != null && Handle != null)
            {
                try
                {
                    int readBytes = Handle.Read(buffer, 0, BaudRate);
                    if (readBytes == 0)
                    {
                        lock (this)
                        {
                            Handle?.Close();
                            Handle         = null;
                            _receiveThread = null;
                        }

                        EventClose?.Invoke(new IOEventResult(this, IOEventType.Close, AegisResult.ClosedByRemote));
                        break;
                    }

                    EventRead?.Invoke(new IOEventResult(this, IOEventType.Read, buffer, 0, readBytes, AegisResult.Ok));
                }
                catch (System.IO.IOException)
                {
                    lock (this)
                    {
                        Handle?.Close();
                        Handle         = null;
                        _receiveThread = null;

                        EventClose?.Invoke(new IOEventResult(this, IOEventType.Close, AegisResult.ClosedByRemote));
                    }
                    break;
                }
                catch (Exception e)
                {
                    ErrorHandler?.Invoke(e);
                    Logger.Err(LogMask.Aegis, e.Message);
                }
            }
        }
Example #6
0
        public void Close()
        {
            lock (this)
            {
                if (_socket == null)
                {
                    return;
                }

                EndPoint ep = _endPoint;
                SpinWorker.Dispatch(() =>
                {
                    EventClose?.Invoke(new IOEventResult(ep, IOEventType.Close, 0));
                });

                _socket.Close();
                _socket = null;
            }
        }
Example #7
0
        public void Close()
        {
            lock (this)
            {
                try
                {
                    EventClose?.Invoke(new IOEventResult(this, IOEventType.Close, AegisResult.Ok));
                    Handle?.Close();
                    Handle?.Dispose();
                }
                catch (Exception e)
                {
                    Logger.Err(e.Message);
                }


                Handle         = null;
                _receiveThread = null;
            }
        }
Example #8
0
        private void DrawFooter(Rect rect)
        {
            try
            {
                GUI.BeginGroup(rect);

                if (state == BlueprintHandlerState.Normal)
                {
                    if (CloseButtonVisible)
                    {
                        Rect closeButtonRect = new Rect(ButtonIndent, rect.height / 2 - ButtonSize.y / 2, ButtonSize.x, ButtonSize.y);
                        if (Widgets.ButtonText(closeButtonRect, "Close".Translate()))
                        {
                            EventClose?.Invoke();
                        }
                    }

                    if (EditButtonVisible)
                    {
                        Rect editButtonRect = new Rect(rect.width - ButtonSize.x - ButtonIndent, rect.height / 2 - ButtonSize.y / 2, ButtonSize.x, ButtonSize.y);
                        if (Widgets.ButtonText(editButtonRect, "Edit".Translate()))
                        {
                            EventEdit?.Invoke();
                        }
                    }
                }
                else if (state == BlueprintHandlerState.New || state == BlueprintHandlerState.Edit)
                {
                    if (CancelButtonVisible)
                    {
                        Rect cancelButtonRect = new Rect(ButtonIndent, rect.height / 2 - ButtonSize.y / 2, ButtonSize.x, ButtonSize.y);
                        if (Widgets.ButtonText(cancelButtonRect, "Cancel".Translate()))
                        {
                            EventCancel?.Invoke();
                        }
                    }

                    if (AcceptButtonVisible)
                    {
                        Rect acceptButtonRect = new Rect(rect.width - ButtonSize.x - ButtonIndent, rect.height / 2 - ButtonSize.y / 2, ButtonSize.x, ButtonSize.y);
                        if (Widgets.ButtonText(acceptButtonRect, "Accept".Translate()))
                        {
                            EventAccept?.Invoke();
                        }
                    }
                }

                //Draw cpu, power draw and max power draw bars
                float remainingSpace = FooterRectHeight - DrawBarHeight * 2;
                float cpuY           = Mathf.Floor((FooterRectHeight / 2 - DrawBarHeight - remainingSpace / 3 / 2));
                Rect  cpuDrawRect    = new Rect(DisplayAreaWidth + SectionMargin, cpuY, PartSelectorAreaWidth, DrawBarHeight);
                var   cpuUsage       = Blueprint.GetUsedCPU;
                cpuBar.DrawProgressBar(cpuDrawRect, cpuUsage.value, Blueprint.GetMaxCPU.value, cpuUsage, Blueprint.CPUTooltip);

                Rect powerDrawRect = new Rect(cpuDrawRect.x, cpuDrawRect.yMax + remainingSpace / 3, cpuDrawRect.width, cpuDrawRect.height);
                var  powerDrain    = Blueprint.GetPowerDrain;
                powerBar.DrawProgressBar(powerDrawRect, powerDrain.value, Blueprint.GetMaxPowerDrain.value, powerDrain, Blueprint.PowerDrainTooltip);
            }
            finally
            {
                GUI.EndGroup();
            }
        }