public AutoCloseDuplexSessionChannel(IDuplexSessionChannel innerChannel)
 {
     this.innerChannel            = innerChannel;
     this.pendingMessages         = new InputQueue <Message>();
     this.messageDequeuedCallback = new Action(this.StartBackgroundReceive);
     this.closeState = new CloseState();
 }
Ejemplo n.º 2
0
 private void Abort(TraceEventType traceEventType, string timeoutErrorString, TransferOperation transferOperation)
 {
     lock (this.ThisLock)
     {
         if (this.closeState == CloseState.Closed)
         {
             return;
         }
         this.timeoutErrorString            = timeoutErrorString;
         this.timeoutErrorTransferOperation = transferOperation;
         this.aborted    = true;
         this.closeState = CloseState.Closed;
         if (!this.asyncReadPending)
         {
             this.FreeOverlappedContextAndReturnBuffer();
         }
         if (this.asyncReadPending)
         {
             this.CancelReceiveTimer();
         }
         if (this.asyncWritePending)
         {
             this.CancelSendTimer();
         }
     }
     if (DiagnosticUtility.ShouldTrace(traceEventType))
     {
         TraceUtility.TraceEvent(traceEventType, 0x4001b, System.ServiceModel.SR.GetString("TraceCodeSocketConnectionAbort"), this);
     }
     this.socket.Close(0);
 }
Ejemplo n.º 3
0
 public AutoCloseDuplexSessionChannel(IDuplexSessionChannel innerChannel)
 {
     this.innerChannel       = innerChannel;
     pendingMessages         = new InputQueue <Message>();
     messageDequeuedCallback = new Action(StartBackgroundReceive); // kick off a new receive when a message is picked up
     closeState = new CloseState();
 }
Ejemplo n.º 4
0
        private void InternalConstruct(string title,
                                       Control control,
                                       ImageList imageList,
                                       int imageIndex,
                                       Image image,
                                       Icon icon)
        {
            // Assign parameters to internal fields
            _title      = title;
            _control    = control;
            _imageIndex = imageIndex;
            _imageList  = imageList;
            _image      = image;
            _icon       = icon;
            _toolTip    = title;

            // Appropriate defaults
            _selected              = false;
            _closeState            = CloseState.Dispose;
            _startFocus            = null;
            _selectBackColor       = Color.Empty;
            _selectTextBackColor   = Color.Empty;
            _selectTextColor       = Color.Empty;
            _inactiveBackColor     = Color.Empty;
            _inactiveTextBackColor = Color.Empty;
            _inactiveTextColor     = Color.Empty;

            // Default to not being visible
            base.Visible = false;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 切断
        /// </summary>
        /// <param name="how">切断対象</param>
        public void Shutdown(SocketShutdown how)
        {
            try
            {
                this.Source.Client.Shutdown(how);
                // half close になったら60秒タイムアウトを設定する
                this.Source.ReceiveTimeout = 60 * 1000;
                this.Source.SendTimeout    = 60 * 1000;
                switch (how)
                {
                case SocketShutdown.Receive:
                    this.CloseState |= CloseState.ReceiveClosed;
                    break;

                case SocketShutdown.Send:
                    this.CloseState |= CloseState.SendClosed;
                    break;

                case SocketShutdown.Both:
                    this.CloseState |= CloseState.Both;
                    break;
                }
            }
            catch
            {
                this.CloseState = CloseState.Both;
                this.Dispose();
            }
        }
Ejemplo n.º 6
0
        public Issue()
        {
            WorkState   = new WorkState(this);
            CloseState  = new CloseState(this);
            DoneState   = new DoneState(this);
            RejectState = new RejectState(this);

            SetState(new NewState(this));
        }
Ejemplo n.º 7
0
    private void CloseDatabaseComplete(object state)
    {
        CloseState clState = state as CloseState;

        if (clState.Callback != null)
        {
            clState.Callback(clState.State);
        }
    }
Ejemplo n.º 8
0
        public SocketConnection(ConnectionBufferPool connectionBufferPool)
        {
            Contract.Assert(connectionBufferPool != null, "Argument connectionBufferPool cannot be null");

            _closeState = CloseState.Open;
            _connectionBufferPool = connectionBufferPool;
            _readBuffer = _connectionBufferPool.Take();
            _asyncReadBufferSize = _readBuffer.Length;
            _sendTimeout = _receiveTimeout = TimeSpan.MaxValue;
        }
Ejemplo n.º 9
0
        public SocketConnection(ConnectionBufferPool connectionBufferPool)
        {
            Contract.Assert(connectionBufferPool != null, "Argument connectionBufferPool cannot be null");

            _closeState           = CloseState.Open;
            _connectionBufferPool = connectionBufferPool;
            _readBuffer           = _connectionBufferPool.Take();
            _asyncReadBufferSize  = _readBuffer.Length;
            _sendTimeout          = _receiveTimeout = TimeSpan.MaxValue;
        }
Ejemplo n.º 10
0
        private static void CloseMessageBox(object state)
        {
            CloseState closeState = state as CloseState;

            Thread.Sleep(closeState.Timeout);
            IntPtr dlg = FindWindow(null, closeState.Caption);

            if (dlg != IntPtr.Zero)
            {
                PostMessage(dlg, 0x10, System.IntPtr.Zero, System.IntPtr.Zero);
            }
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            Context    context = new Context();
            CloseState close   = new CloseState();

            context.SetLiftState(close);
            context.Open();
            context.Close();
            context.Run();
            context.Run();
            context.Open();
            context.Run();
        }
Ejemplo n.º 12
0
    private void CloseMessageBox(object state)
    {
        CloseState closeState = state as CloseState;

        Thread.Sleep(closeState.Timeout);
        IntPtr dlg = FindWindow(null, closeState.Caption);

        if (dlg != IntPtr.Zero)
        {
            IntPtr result;
            EndDialog(dlg, out result);
        }
    }
        private HRESULT ProcessNotification(
            PRJ_CALLBACK_DATA callbackData,
            bool isDirectory,
            PRJ_NOTIFICATION notification,
            String destinationFileName,
            ref PRJ_NOTIFICATION_PARAMETERS operationParameters
            )
        {
            switch (notification)
            {
            case PRJ_NOTIFICATION.PRJ_NOTIFICATION_FILE_OPENED:
                return(_asyncOperations.ProcessCommandPossibleAsyncWithNotificationMask(callbackData.NamespaceVirtualizationContext, callbackData.CommandId, cts => Notifiable.FileOpened(callbackData.FilePathName, isDirectory, cts.Token), operationParameters));

            case PRJ_NOTIFICATION.PRJ_NOTIFICATION_NEW_FILE_CREATED:
                return(_asyncOperations.ProcessCommandPossibleAsyncWithNotificationMask(callbackData.NamespaceVirtualizationContext, callbackData.CommandId, cts => Notifiable.FileCreated(callbackData.FilePathName, isDirectory, cts.Token), operationParameters));

            case PRJ_NOTIFICATION.PRJ_NOTIFICATION_FILE_OVERWRITTEN:
                return(_asyncOperations.ProcessCommandPossibleAsyncWithNotificationMask(callbackData.NamespaceVirtualizationContext, callbackData.CommandId, cts => Notifiable.FileOverwritten(callbackData.FilePathName, isDirectory, cts.Token), operationParameters));

            case PRJ_NOTIFICATION.PRJ_NOTIFICATION_PRE_DELETE:
                return(_asyncOperations.ProcessCommandPossibleAsync(callbackData.NamespaceVirtualizationContext, callbackData.CommandId, cts => Notifiable.PreDelete(callbackData.FilePathName, isDirectory, cts.Token), b => b ? HRESULT.S_OK : HRESULT.E_INVALIDARG));

            case PRJ_NOTIFICATION.PRJ_NOTIFICATION_PRE_RENAME:
                return(_asyncOperations.ProcessCommandPossibleAsync(callbackData.NamespaceVirtualizationContext, callbackData.CommandId, cts => Notifiable.PreRename(callbackData.FilePathName, destinationFileName, isDirectory, cts.Token), b => b ? HRESULT.S_OK : HRESULT.E_INVALIDARG));

            case PRJ_NOTIFICATION.PRJ_NOTIFICATION_PRE_SET_HARDLINK:
                return(_asyncOperations.ProcessCommandPossibleAsync(callbackData.NamespaceVirtualizationContext, callbackData.CommandId, cts => Notifiable.PreHardlink(callbackData.FilePathName, destinationFileName, isDirectory, cts.Token), b => b ? HRESULT.S_OK : HRESULT.E_INVALIDARG));

            case PRJ_NOTIFICATION.PRJ_NOTIFICATION_FILE_RENAMED:
                return(_asyncOperations.ProcessCommandPossibleAsyncWithNotificationMask(callbackData.NamespaceVirtualizationContext, callbackData.CommandId, cts => Notifiable.FileRenamed(callbackData.FilePathName, destinationFileName, isDirectory, cts.Token), operationParameters));

            case PRJ_NOTIFICATION.PRJ_NOTIFICATION_HARDLINK_CREATED:
                return(_asyncOperations.ProcessCommandPossibleAsync(callbackData.NamespaceVirtualizationContext, callbackData.CommandId, cts => Notifiable.FileHardlinked(callbackData.FilePathName, destinationFileName, isDirectory, cts.Token)));

            case PRJ_NOTIFICATION.PRJ_NOTIFICATION_FILE_HANDLE_CLOSED_NO_MODIFICATION:
                return(_asyncOperations.ProcessCommandPossibleAsync(callbackData.NamespaceVirtualizationContext, callbackData.CommandId, cts => Notifiable.FileClosed(callbackData.FilePathName, isDirectory, CloseState.Unmodified, cts.Token)));

            case PRJ_NOTIFICATION.PRJ_NOTIFICATION_FILE_HANDLE_CLOSED_FILE_MODIFIED:
                return(_asyncOperations.ProcessCommandPossibleAsync(callbackData.NamespaceVirtualizationContext, callbackData.CommandId, cts => Notifiable.FileClosed(callbackData.FilePathName, isDirectory, CloseState.Modified, cts.Token)));

            case PRJ_NOTIFICATION.PRJ_NOTIFICATION_FILE_HANDLE_CLOSED_FILE_DELETED:
                CloseState state = operationParameters.IsFileModified ? CloseState.Modified | CloseState.Deleted : CloseState.Deleted;
                return(_asyncOperations.ProcessCommandPossibleAsync(callbackData.NamespaceVirtualizationContext, callbackData.CommandId, cts => Notifiable.FileClosed(callbackData.FilePathName, isDirectory, state, cts.Token)));

            case PRJ_NOTIFICATION.PRJ_NOTIFICATION_FILE_PRE_CONVERT_TO_FULL:
                return(_asyncOperations.ProcessCommandPossibleAsync(callbackData.NamespaceVirtualizationContext, callbackData.CommandId, cts => Notifiable.PreConvertToFull(callbackData.FilePathName, isDirectory, cts.Token)));
            }
            return(HRESULT.E_INVALIDARG);
        }
Ejemplo n.º 14
0
 public void ContinueClose(TimeSpan timeout)
 {
     if ((timeout <= TimeSpan.Zero) && DiagnosticUtility.ShouldTraceWarning)
     {
         TraceUtility.TraceEvent(TraceEventType.Warning, 0x4001c, System.ServiceModel.SR.GetString("TraceCodeSocketConnectionAbortClose"), this);
     }
     this.socket.Close(TimeoutHelper.ToMilliseconds(timeout));
     lock (this.ThisLock)
     {
         if (!this.asyncReadPending && (this.closeState != CloseState.Closed))
         {
             this.FreeOverlappedContextAndReturnBuffer();
         }
         this.closeState = CloseState.Closed;
     }
 }
Ejemplo n.º 15
0
        public void Shutdown(SocketShutdown how)
        {
            switch (how)
            {
            case SocketShutdown.Receive:
                this.CloseState |= CloseState.ReceiveClosed;
                break;

            case SocketShutdown.Send:
                this.CloseState |= CloseState.SendClosed;
                break;

            case SocketShutdown.Both:
                this.CloseState |= CloseState.Both;
                break;
            }
        }
Ejemplo n.º 16
0
        public void Close(TimeSpan timeout, bool asyncAndLinger)
        {
            lock (ThisLock)
            {
                if (_closeState == CloseState.Closing || _closeState == CloseState.Closed)
                {
                    // already closing or closed, so just return
                    return;
                }
                _closeState = CloseState.Closing;
            }

            _closeTimeoutHelper = new TimeoutHelper(timeout);

            // first we shutdown our send-side
            Shutdown(timeout);
            CloseCore(asyncAndLinger);
        }
Ejemplo n.º 17
0
    public Light _light;                   // 对象
    void Start()
    {
        Application.runInBackground = true;
        _light = GameObject.Find("Directional Light").GetComponent <Light>();

        #region 状态机的设置
        // 状态机
        _fsm = new MainStateMachine(StateName.MainMachine);
        // “关闭”状态
        _close = _fsm.AddState <CloseState>(StateName.Close, true);
        // “打开”子状态机
        _openfsm   = _fsm.AddState <OpenMachine>(StateName.OpenMachine);
        _intensity = _openfsm.AddState <IntensityState>(StateName.Intensity, true); // “亮度” 状态
        _color     = _openfsm.AddState <ColorState>(StateName.Color);               // “颜色” 状态
        // 设置所有的状态转换
        manager = new StateManager(_fsm, _openfsm, _intensity, _color, _close);
        // 具体项目的设置  将改变的对象传入
        manager.SetObject(this);
        #endregion
    }
        public SocketConnection(Socket socket, ConnectionBufferPool connectionBufferPool, bool autoBindToCompletionPort)
        {
            if (socket == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("socket");
            }

            Fx.Assert(connectionBufferPool != null, "Argument connectionBufferPool cannot be null");

            this.closeState = CloseState.Open;
            this.exceptionEventType = TraceEventType.Error;
            this.socket = socket;
            this.connectionBufferPool = connectionBufferPool;
            this.readBuffer = this.connectionBufferPool.Take();
            this.asyncReadBufferSize = this.readBuffer.Length;
            this.socket.SendBufferSize = this.socket.ReceiveBufferSize = this.asyncReadBufferSize;
            this.sendTimeout = this.receiveTimeout = TimeSpan.MaxValue;

            this.remoteEndpoint = null;

            if (autoBindToCompletionPort)
            {
                this.socket.UseOnlyOverlappedIO = false;
            }

            // In SMSvcHost, sockets must be duplicated to the target process. Binding a handle to a completion port
            // prevents any duplicated handle from ever binding to a completion port. The target process is where we
            // want to use completion ports for performance. This means that in SMSvcHost, socket.UseOnlyOverlappedIO
            // must be set to true to prevent completion port use.
            if (this.socket.UseOnlyOverlappedIO)
            {
                // Init BeginRead state
                if (onReceiveCompleted == null)
                {
                    onReceiveCompleted = Fx.ThunkCallback(new AsyncCallback(OnReceiveCompleted));
                }
            }

            this.TraceSocketInfo(socket, TraceCode.SocketConnectionCreate, SR.TraceCodeSocketConnectionCreate, null);
        }
Ejemplo n.º 19
0
 public void Close(TimeSpan timeout, bool asyncAndLinger)
 {
     lock (this.ThisLock)
     {
         if ((this.closeState == CloseState.Closing) || (this.closeState == CloseState.Closed))
         {
             return;
         }
         this.TraceSocketInfo(this.socket, 0x4001a, "TraceCodeSocketConnectionClose", timeout.ToString());
         this.closeState = CloseState.Closing;
     }
     this.closeTimeoutHelper = new TimeoutHelper(timeout);
     this.Shutdown(this.closeTimeoutHelper.RemainingTime());
     if (asyncAndLinger)
     {
         this.CloseAsyncAndLinger();
     }
     else
     {
         this.CloseSync();
     }
 }
Ejemplo n.º 20
0
 public SocketConnection(Socket socket, ConnectionBufferPool connectionBufferPool, bool autoBindToCompletionPort)
 {
     if (socket == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("socket");
     }
     this.closeState            = CloseState.Open;
     this.exceptionEventType    = TraceEventType.Error;
     this.socket                = socket;
     this.connectionBufferPool  = connectionBufferPool;
     this.readBuffer            = this.connectionBufferPool.Take();
     this.asyncReadBufferSize   = this.readBuffer.Length;
     this.socket.SendBufferSize = this.socket.ReceiveBufferSize = this.asyncReadBufferSize;
     this.sendTimeout           = this.receiveTimeout = TimeSpan.MaxValue;
     this.onReceive             = Fx.ThunkCallback(new AsyncCallback(this.OnReceive));
     this.asyncReadOverlapped   = new OverlappedContext();
     if (autoBindToCompletionPort)
     {
         this.socket.UseOnlyOverlappedIO = false;
     }
     this.TraceSocketInfo(socket, 0x40019, "TraceCodeSocketConnectionCreate", null);
 }
 public SocketConnection(Socket socket, ConnectionBufferPool connectionBufferPool, bool autoBindToCompletionPort)
 {
     if (socket == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("socket");
     }
     this.closeState = CloseState.Open;
     this.exceptionEventType = TraceEventType.Error;
     this.socket = socket;
     this.connectionBufferPool = connectionBufferPool;
     this.readBuffer = this.connectionBufferPool.Take();
     this.asyncReadBufferSize = this.readBuffer.Length;
     this.socket.SendBufferSize = this.socket.ReceiveBufferSize = this.asyncReadBufferSize;
     this.sendTimeout = this.receiveTimeout = TimeSpan.MaxValue;
     this.onReceive = Fx.ThunkCallback(new AsyncCallback(this.OnReceive));
     this.asyncReadOverlapped = new OverlappedContext();
     if (autoBindToCompletionPort)
     {
         this.socket.UseOnlyOverlappedIO = false;
     }
     this.TraceSocketInfo(socket, 0x40019, "TraceCodeSocketConnectionCreate", null);
 }
Ejemplo n.º 22
0
            /// <summary>
            /// 切换熔断器状态
            /// </summary>
            /// <param name="s"></param>
            public void ConvertState(State s)
            {
                Trace.WriteLine("ConvertState::" + s);
                State = s;
                switch (s)
                {
                case State.Close:
                    StateC = new CloseState(this);
                    break;

                case State.half_open:
                    StateC = new Half_OpenState(this);
                    break;

                case State.open:
                    StateC = new OpenState(this);
                    break;

                default:
                    break;
                }
            }
 public PipeConnection(PipeHandle pipe, int connectionBufferSize, bool isBoundToCompletionPort, bool autoBindToCompletionPort)
 {
     if (pipe == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("pipe");
     }
     if (pipe.IsInvalid)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("pipe");
     }
     this.closeState = CloseState.Open;
     this.exceptionEventType = TraceEventType.Error;
     this.isBoundToCompletionPort = isBoundToCompletionPort;
     this.autoBindToCompletionPort = autoBindToCompletionPort;
     this.pipe = pipe;
     this.readBufferSize = connectionBufferSize;
     this.writeBufferSize = connectionBufferSize;
     this.readOverlapped = new OverlappedContext();
     this.writeOverlapped = new OverlappedContext();
     this.atEOFEvent = new ManualResetEvent(false);
     this.onAsyncReadComplete = new OverlappedIOCompleteCallback(this.OnAsyncReadComplete);
     this.onAsyncWriteComplete = new OverlappedIOCompleteCallback(this.OnAsyncWriteComplete);
 }
Ejemplo n.º 24
0
        public BreakerState GetState(State state, IStateManager manager)
        {
            BreakerState breakerState = null;

            switch (state)
            {
            case State.Close:
                breakerState = new CloseState(manager);
                break;

            case State.Open:
                breakerState = new OpenState(manager);
                break;

            case State.HalfOpen:
                breakerState = new HalfOpenState(manager);
                break;

            default:
                throw new NotSupportedException("state");
            }

            return(breakerState);
        }
 public void Close(TimeSpan timeout, bool asyncAndLinger)
 {
     TimeoutHelper helper = new TimeoutHelper(timeout);
     this.FinishPendingWrite(timeout);
     bool flag = false;
     try
     {
         bool flag2 = false;
         bool flag3 = false;
         bool flag4 = false;
         lock (this.readLock)
         {
             lock (this.writeLock)
             {
                 if (!this.isShutdownWritten && this.inWritingState)
                 {
                     throw DiagnosticUtility.ExceptionUtility.ThrowHelper(new PipeException(System.ServiceModel.SR.GetString("PipeCantCloseWithPendingWrite")), this.ExceptionEventType);
                 }
                 if ((this.closeState == CloseState.Closing) || (this.closeState == CloseState.HandleClosed))
                 {
                     return;
                 }
                 this.closeState = CloseState.Closing;
                 flag = true;
                 if (!this.isAtEOF)
                 {
                     if (this.inReadingState)
                     {
                         flag2 = true;
                     }
                     else
                     {
                         flag3 = true;
                     }
                 }
                 if (!this.isShutdownWritten)
                 {
                     flag4 = true;
                     this.isShutdownWritten = true;
                 }
             }
         }
         if (flag4)
         {
             this.StartWriteZero(helper.RemainingTime());
         }
         if (flag3)
         {
             this.StartReadZero();
         }
         try
         {
             this.WaitForWriteZero(helper.RemainingTime(), true);
         }
         catch (TimeoutException exception)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelper(new TimeoutException(System.ServiceModel.SR.GetString("PipeShutdownWriteError"), exception), this.ExceptionEventType);
         }
         if (flag3)
         {
             try
             {
                 this.WaitForReadZero(helper.RemainingTime(), true);
                 goto Label_018E;
             }
             catch (TimeoutException exception2)
             {
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelper(new TimeoutException(System.ServiceModel.SR.GetString("PipeShutdownReadError"), exception2), this.ExceptionEventType);
             }
         }
         if (flag2 && !TimeoutHelper.WaitOne(this.atEOFEvent, helper.RemainingTime()))
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelper(new TimeoutException(System.ServiceModel.SR.GetString("PipeShutdownReadError")), this.ExceptionEventType);
         }
     Label_018E:
         try
         {
             this.StartWriteZero(helper.RemainingTime());
             this.StartReadZero();
             this.WaitForWriteZero(helper.RemainingTime(), false);
             this.WaitForReadZero(helper.RemainingTime(), false);
         }
         catch (PipeException exception3)
         {
             if (!this.IsBrokenPipeError(exception3.ErrorCode))
             {
                 throw;
             }
             if (DiagnosticUtility.ShouldTraceInformation)
             {
                 DiagnosticUtility.ExceptionUtility.TraceHandledException(exception3, TraceEventType.Information);
             }
         }
         catch (CommunicationException exception4)
         {
             if (DiagnosticUtility.ShouldTraceInformation)
             {
                 DiagnosticUtility.ExceptionUtility.TraceHandledException(exception4, TraceEventType.Information);
             }
         }
         catch (TimeoutException exception5)
         {
             if (DiagnosticUtility.ShouldTraceInformation)
             {
                 DiagnosticUtility.ExceptionUtility.TraceHandledException(exception5, TraceEventType.Information);
             }
         }
     }
     catch (TimeoutException exception6)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelper(new TimeoutException(System.ServiceModel.SR.GetString("PipeCloseFailed"), exception6), this.ExceptionEventType);
     }
     catch (PipeException exception7)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelper(this.ConvertPipeException(System.ServiceModel.SR.GetString("PipeCloseFailed"), exception7, TransferOperation.Undefined), this.ExceptionEventType);
     }
     finally
     {
         if (flag)
         {
             this.CloseHandle(false, null, TransferOperation.Undefined);
         }
     }
 }
Ejemplo n.º 26
0
 /// <summary>
 /// Initializes a new instance of the TabPage class.
 /// </summary>
 /// <param name="title">Title for the page.</param>
 /// <param name="control">Child control for display.</param>
 /// <param name="state">State for the page.</param>
 public TabPage(string title, Control control, CloseState state)
 {
     InternalConstruct(title, control, null, -1, null, null);
     this.PageCloseState = state;
 }
Ejemplo n.º 27
0
        private async void MainWindow_OnClosing(object sender, CancelEventArgs e)
        {
            if (CloseState.ForceClose.Equals(WindowCloseState))
            {
                return;
            }
            if (CloseState.Closing.Equals(WindowCloseState))
            {
                if (WindowState.Equals(WindowState.Minimized))
                {
                    WindowState = WindowState.Normal;
                }

                e.Cancel = true;
                SystemSounds.Exclamation.Play();
                return;
            }

            WindowCloseState = CloseState.Closing;

            if (Context.IsNotSaved)
            {
                e.Cancel = true;

                if (WindowState.Equals(WindowState.Minimized))
                {
                    WindowState = WindowState.Normal;
                    SystemSounds.Exclamation.Play();
                    RootDialog.Focus();
                }

                if (RootDialog.IsOpen)
                {
                    DialogHost.CloseDialogCommand.Execute(null, RootDialog);
                }

                var dialog = new DecisionDialog("Configuration has changed", "Do you want to save before closing?");
                var result = (MessageBoxResult?)await DialogHost.Show(dialog, "RootDialog");

                if (result == null)
                {
                    return;
                }

                switch (result)
                {
                case MessageBoxResult.None:
                case MessageBoxResult.Cancel:
                    WindowCloseState = CloseState.None;
                    return;

                case MessageBoxResult.OK:
                case MessageBoxResult.Yes:
                    Context.SaveContext();
                    WindowCloseState = CloseState.ForceClose;
                    Close();
                    break;

                case MessageBoxResult.No:
                    WindowCloseState = CloseState.ForceClose;
                    Close();
                    break;
                }
            }
        }
 private void Abort(TraceEventType traceEventType, string timeoutErrorString, TransferOperation transferOperation)
 {
     lock (this.ThisLock)
     {
         if (this.closeState == CloseState.Closed)
         {
             return;
         }
         this.timeoutErrorString = timeoutErrorString;
         this.timeoutErrorTransferOperation = transferOperation;
         this.aborted = true;
         this.closeState = CloseState.Closed;
         if (!this.asyncReadPending)
         {
             this.FreeOverlappedContextAndReturnBuffer();
         }
         if (this.asyncReadPending)
         {
             this.CancelReceiveTimer();
         }
         if (this.asyncWritePending)
         {
             this.CancelSendTimer();
         }
     }
     if (DiagnosticUtility.ShouldTrace(traceEventType))
     {
         TraceUtility.TraceEvent(traceEventType, 0x4001b, System.ServiceModel.SR.GetString("TraceCodeSocketConnectionAbort"), this);
     }
     this.socket.Close(0);
 }
Ejemplo n.º 29
0
 public void Close(IState state)
 {
     state = new CloseState();
 }
        void Abort(TraceEventType traceEventType, string timeoutErrorString, TransferOperation transferOperation)
        {
            if (TD.SocketConnectionAbortIsEnabled())
            {
                TD.SocketConnectionAbort(this.socket.GetHashCode());
            }
            lock (ThisLock)
            {
                if (closeState == CloseState.Closed)
                {
                    return;
                }

                this.timeoutErrorString = timeoutErrorString;
                this.timeoutErrorTransferOperation = transferOperation;
                aborted = true;
                closeState = CloseState.Closed;

                if (this.asyncReadPending)
                {
                    CancelReceiveTimer();
                }
                else
                {
                    this.DisposeReadEventArgs();
                }

                if (this.asyncWritePending)
                {
                    CancelSendTimer();
                }
                else
                {
                    this.DisposeWriteEventArgs();
                }
            }

            if (DiagnosticUtility.ShouldTrace(traceEventType))
            {
                TraceUtility.TraceEvent(traceEventType, TraceCode.SocketConnectionAbort,
                    SR.GetString(SR.TraceCodeSocketConnectionAbort), this);
            }

            socket.Close(0);
        }
 public void Close(TimeSpan timeout, bool asyncAndLinger)
 {
     lock (this.ThisLock)
     {
         if ((this.closeState == CloseState.Closing) || (this.closeState == CloseState.Closed))
         {
             return;
         }
         this.TraceSocketInfo(this.socket, 0x4001a, "TraceCodeSocketConnectionClose", timeout.ToString());
         this.closeState = CloseState.Closing;
     }
     this.closeTimeoutHelper = new TimeoutHelper(timeout);
     this.Shutdown(this.closeTimeoutHelper.RemainingTime());
     if (asyncAndLinger)
     {
         this.CloseAsyncAndLinger();
     }
     else
     {
         this.CloseSync();
     }
 }
        public void Close(TimeSpan timeout, bool asyncAndLinger)
        {
            lock (ThisLock)
            {
                if (closeState == CloseState.Closing || closeState == CloseState.Closed)
                {
                    // already closing or closed, so just return
                    return;
                }
                this.TraceSocketInfo(this.socket, TraceCode.SocketConnectionClose, SR.TraceCodeSocketConnectionClose, timeout.ToString());
                closeState = CloseState.Closing;
            }

            // first we shutdown our send-side
            closeTimeoutHelper = new TimeoutHelper(timeout);
            Shutdown(closeTimeoutHelper.RemainingTime());

            if (asyncAndLinger)
            {
                CloseAsyncAndLinger();
            }
            else
            {
                CloseSync();
            }
        }
        public void ContinueClose(TimeSpan timeout)
        {
            // trace if we're effectively aborting
            if (timeout <= TimeSpan.Zero && DiagnosticUtility.ShouldTraceWarning)
            {
                TraceUtility.TraceEvent(TraceEventType.Warning, TraceCode.SocketConnectionAbortClose,
                    SR.GetString(SR.TraceCodeSocketConnectionAbortClose), this);
            }

            socket.Close(TimeoutHelper.ToMilliseconds(timeout));

            lock (ThisLock)
            {
                // Abort could have been called on a separate thread and cleaned up 
                // our buffers/completion here
                if (this.closeState != CloseState.Closed)
                {
                    if (!this.asyncReadPending)
                    {
                        this.DisposeReadEventArgs();
                    }

                    if (!this.asyncWritePending)
                    {
                        this.DisposeWriteEventArgs();
                    }
                }

                closeState = CloseState.Closed;
            }
        }
 public void ContinueClose(TimeSpan timeout)
 {
     if ((timeout <= TimeSpan.Zero) && DiagnosticUtility.ShouldTraceWarning)
     {
         TraceUtility.TraceEvent(TraceEventType.Warning, 0x4001c, System.ServiceModel.SR.GetString("TraceCodeSocketConnectionAbortClose"), this);
     }
     this.socket.Close(TimeoutHelper.ToMilliseconds(timeout));
     lock (this.ThisLock)
     {
         if (!this.asyncReadPending && (this.closeState != CloseState.Closed))
         {
             this.FreeOverlappedContextAndReturnBuffer();
         }
         this.closeState = CloseState.Closed;
     }
 }
Ejemplo n.º 35
0
        void CloseHandle(bool abort, string timeoutErrorString, TransferOperation transferOperation)
        {
            lock (readLock)
            {
                lock (writeLock)
                {
                    if (this.closeState == CloseState.HandleClosed)
                    {
                        return;
                    }

                    this.timeoutErrorString = timeoutErrorString;
                    this.timeoutErrorTransferOperation = transferOperation;
                    this.aborted = abort;
                    this.closeState = CloseState.HandleClosed;
                    this.pipe.Close();
                    this.readOverlapped.FreeOrDefer();
                    this.writeOverlapped.FreeOrDefer();

                    if (this.atEOFEvent != null)
                    {
                        this.atEOFEvent.Close();
                    }

                    // This should only do anything in the abort case.
                    try
                    {
                        FinishPendingWrite(TimeSpan.Zero);
                    }
                    catch (TimeoutException exception)
                    {
                        if (TD.CloseTimeoutIsEnabled())
                        {
                            TD.CloseTimeout(exception.Message);
                        }
                        DiagnosticUtility.TraceHandledException(exception, TraceEventType.Information);
                    }
                    catch (CommunicationException exception)
                    {
                        DiagnosticUtility.TraceHandledException(exception, TraceEventType.Information);
                    }
                }
            }

            if (abort)
            {
                TraceEventType traceEventType = TraceEventType.Warning;

                // we could be timing out a cached connection
                if (this.ExceptionEventType == TraceEventType.Information)
                {
                    traceEventType = this.ExceptionEventType;
                }

                if (DiagnosticUtility.ShouldTrace(traceEventType))
                {
                    TraceUtility.TraceEvent(traceEventType, TraceCode.PipeConnectionAbort, SR.GetString(SR.TraceCodePipeConnectionAbort), this);
                }
            }
        }
 public Connection()
 {
     State = new CloseState();
 }
Ejemplo n.º 37
0
        public void Close(TimeSpan timeout, bool asyncAndLinger)
        {
            lock (ThisLock)
            {
                if (_closeState == CloseState.Closing || _closeState == CloseState.Closed)
                {
                    // already closing or closed, so just return
                    return;
                }
                _closeState = CloseState.Closing;
            }

            _closeTimeoutHelper = new TimeoutHelper(timeout);

            // first we shutdown our send-side
            Shutdown(timeout);
            CloseCore(asyncAndLinger);
        }
Ejemplo n.º 38
0
        // CSDMain 112188: Note asyncAndLinger has no effect here. Async pooling for Tcp was
        // added and NamedPipes currently doesn't obey the async model.
        public void Close(TimeSpan timeout, bool asyncAndLinger)
        {
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
            FinishPendingWrite(timeout);

            bool shouldCloseHandle = false;
            try
            {
                bool existingReadIsPending = false;
                bool shouldReadEOF = false;
                bool shouldWriteEOF = false;

                lock (readLock)
                {
                    lock (writeLock)
                    {
                        if (!isShutdownWritten && inWritingState)
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelper(
                                new PipeException(SR.GetString(SR.PipeCantCloseWithPendingWrite)), ExceptionEventType);
                        }

                        if (closeState == CloseState.Closing || closeState == CloseState.HandleClosed)
                        {
                            // already closing or closed, so just return
                            return;
                        }

                        closeState = CloseState.Closing;

                        shouldCloseHandle = true;

                        if (!isAtEOF)
                        {
                            if (inReadingState)
                            {
                                existingReadIsPending = true;
                            }
                            else
                            {
                                shouldReadEOF = true;
                            }
                        }

                        if (!isShutdownWritten)
                        {
                            shouldWriteEOF = true;
                            isShutdownWritten = true;
                        }
                    }
                }

                if (shouldWriteEOF)
                {
                    StartWriteZero(timeoutHelper.RemainingTime());
                }

                if (shouldReadEOF)
                {
                    StartReadZero();
                }

                // wait for shutdown write to complete
                try
                {
                    WaitForWriteZero(timeoutHelper.RemainingTime(), true);
                }
                catch (TimeoutException e)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelper(
                        new TimeoutException(SR.GetString(SR.PipeShutdownWriteError), e), ExceptionEventType);
                }

                // ensure we have received EOF signal
                if (shouldReadEOF)
                {
                    try
                    {
                        WaitForReadZero(timeoutHelper.RemainingTime(), true);
                    }
                    catch (TimeoutException e)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelper(
                            new TimeoutException(SR.GetString(SR.PipeShutdownReadError), e), ExceptionEventType);
                    }
                }
                else if (existingReadIsPending)
                {
                    if (!TimeoutHelper.WaitOne(atEOFEvent, timeoutHelper.RemainingTime()))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelper(
                            new TimeoutException(SR.GetString(SR.PipeShutdownReadError)), ExceptionEventType);
                    }
                }
                // else we had already seen EOF.

                // at this point, we may get exceptions if the other side closes the handle first
                try
                {
                    // write an ack for eof
                    StartWriteZero(timeoutHelper.RemainingTime());

                    // read an ack for eof
                    StartReadZero();

                    // wait for write to complete/fail
                    WaitForWriteZero(timeoutHelper.RemainingTime(), false);

                    // wait for read to complete/fail
                    WaitForReadZero(timeoutHelper.RemainingTime(), false);
                }
                catch (PipeException e)
                {
                    if (!IsBrokenPipeError(e.ErrorCode))
                    {
                        throw;
                    }
                    DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
                }
                catch (CommunicationException e)
                {
                    DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
                }
                catch (TimeoutException e)
                {
                    DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
                }
            }
            catch (TimeoutException e)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelper(
                    new TimeoutException(SR.GetString(SR.PipeCloseFailed), e), ExceptionEventType);
            }
            catch (PipeException e)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelper(
                    ConvertPipeException(SR.GetString(SR.PipeCloseFailed), e, TransferOperation.Undefined), ExceptionEventType);
            }
            finally
            {
                if (shouldCloseHandle)
                {
                    CloseHandle(false, null, TransferOperation.Undefined);
                }
            }
        }
 private void CloseHandle(bool abort, string timeoutErrorString, TransferOperation transferOperation)
 {
     lock (this.readLock)
     {
         lock (this.writeLock)
         {
             if (this.closeState == CloseState.HandleClosed)
             {
                 return;
             }
             this.timeoutErrorString = timeoutErrorString;
             this.timeoutErrorTransferOperation = transferOperation;
             this.aborted = abort;
             this.closeState = CloseState.HandleClosed;
             this.pipe.Close();
             this.readOverlapped.FreeOrDefer();
             this.writeOverlapped.FreeOrDefer();
             if (this.atEOFEvent != null)
             {
                 this.atEOFEvent.Close();
             }
             try
             {
                 this.FinishPendingWrite(TimeSpan.Zero);
             }
             catch (TimeoutException exception)
             {
                 if (DiagnosticUtility.ShouldTraceInformation)
                 {
                     DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information);
                 }
             }
             catch (CommunicationException exception2)
             {
                 if (DiagnosticUtility.ShouldTraceInformation)
                 {
                     DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, TraceEventType.Information);
                 }
             }
         }
     }
     if (abort)
     {
         TraceEventType warning = TraceEventType.Warning;
         if (this.ExceptionEventType == TraceEventType.Information)
         {
             warning = this.ExceptionEventType;
         }
         if (DiagnosticUtility.ShouldTrace(warning))
         {
             TraceUtility.TraceEvent(warning, 0x4001d, System.ServiceModel.SR.GetString("TraceCodePipeConnectionAbort"), this);
         }
     }
 }