コード例 #1
0
ファイル: DdemlServer.cs プロジェクト: zyun1/dde-net
        public virtual void Resume(DdemlConversation conversation)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(this.GetType().ToString());
            }
            if (!IsRegistered)
            {
                throw new InvalidOperationException(Resources.NotRegisteredMessage);
            }
            if (conversation == null)
            {
                throw new ArgumentNullException("conversation");
            }
            if (!conversation.IsPaused)
            {
                throw new InvalidOperationException(Resources.NotPausedMessage);
            }

            // Enable the DDEML callback for the specified conversation only.
            bool result = Ddeml.DdeEnableCallback(_InstanceId, conversation.Handle, Ddeml.EC_ENABLEALL);

            // Check the result to see if the DDEML callback was enabled.
            if (!result)
            {
                int error = Ddeml.DdeGetLastError(_InstanceId);
                throw new DdemlException(Resources.ServerResumeFailedMessage, error);
            }

            // Decrement the conversation's waiting count.  The conversation will only resume if the count is zero.
            conversation.DecrementWaiting();
        }
コード例 #2
0
ファイル: DdemlServer.cs プロジェクト: zyun1/dde-net
        public virtual void Resume()
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(this.GetType().ToString());
            }
            if (!IsRegistered)
            {
                throw new InvalidOperationException(Resources.NotRegisteredMessage);
            }

            // Enable the DDEML callback for all conversations.
            bool result = Ddeml.DdeEnableCallback(_InstanceId, IntPtr.Zero, Ddeml.EC_ENABLEALL);

            // Check the result to see if the DDEML callback was enabled.
            if (!result)
            {
                int error = Ddeml.DdeGetLastError(_InstanceId);
                throw new DdemlException(Resources.ServerResumeAllFailedMessage, error);
            }

            // Decrement each conversation's waiting count.  The conversation will only resume if the count is zero.
            foreach (DdemlConversation conversation in _ConversationTable.Values)
            {
                conversation.DecrementWaiting();
            }
        }
コード例 #3
0
        public virtual void Register()
        {
            if (IsDisposed)
                throw new ObjectDisposedException(GetType().ToString());
            if (IsRegistered)
                throw new InvalidOperationException(Resources.AlreadyRegisteredMessage);

            // Make sure the context is initialized.
            if (!_Context.IsInitialized)
                _Context.Initialize();

            // Get a local copy of the DDEML instance identifier so that it can be used in the finalizer.
            _InstanceId = _Context.InstanceId;

            // Make sure the conversation table is empty.
            _ConversationTable.Clear();

            // Register the service name.
            _ServiceHandle = RegistrationManager.Register(_InstanceId, _Service);

            // If the service handle is null then the service name could not be registered.
            if (_ServiceHandle == IntPtr.Zero)
            {
                var error = Ddeml.DdeGetLastError(_InstanceId);
                var message = Resources.RegisterFailedMessage;
                message = message.Replace("${service}", _Service);
                throw new DdemlException(message, error);
            }

            // Register this server with the context so that it can receive DDEML callbacks.
            _Context.RegisterServer(this);

            // Raise the StateChange event.
            StateChange?.Invoke(this, EventArgs.Empty);
        }
コード例 #4
0
        public virtual void Pause()
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(this.GetType().ToString());
            }
            if (!IsRegistered)
            {
                throw new InvalidOperationException(DDE.NotRegisteredMessage);
            }

            // Disable the DDEML callback for all conversations.
            bool result = Ddeml.DdeEnableCallback(_InstanceId, IntPtr.Zero, Ddeml.EC_DISABLE);

            // Check the result to see if the DDEML callback was disabled.
            if (!result)
            {
                int error = Ddeml.DdeGetLastError(_InstanceId);
                throw new DdemlException(DDE.ServerPauseAllFailedMessage, error);
            }

            // Increment each conversation's waiting count.
            foreach (DdemlConversation conversation in _ConversationTable.Values)
            {
                conversation.IncrementWaiting();
            }
        }
コード例 #5
0
        public virtual void Pause(DdemlConversation conversation)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(this.GetType().ToString());
            }
            if (!IsRegistered)
            {
                throw new InvalidOperationException(DDE.NotRegisteredMessage);
            }
            if (conversation == null)
            {
                throw new ArgumentNullException("conversation");
            }
            if (conversation.IsPaused)
            {
                throw new InvalidOperationException(DDE.AlreadyPausedMessage);
            }

            // Disable the DDEML callback for the specified conversation only.
            bool result = Ddeml.DdeEnableCallback(_InstanceId, conversation.Handle, Ddeml.EC_DISABLE);

            // Check the result to see if the DDEML callback was disabled.
            if (!result)
            {
                int error = Ddeml.DdeGetLastError(_InstanceId);
                throw new DdemlException(DDE.ServerPauseFailedMessage, error);
            }

            // Increment the conversation's waiting count.
            conversation.IncrementWaiting();
        }
コード例 #6
0
ファイル: DdemlContext.cs プロジェクト: zhangjk1980/NDde
 internal void Initialize(int afCmd)
 {
     // Initialize a DDEML instance.
     _InstanceId = InstanceManager.Initialize(_Callback, afCmd);
     
     // If the instance identifier is null then the DDEML could not be initialized.
     if (_InstanceId == 0)
     {
         int error = Ddeml.DdeGetLastError(_InstanceId);
         throw new DdemlException(Resources.InitializeFailedMessage, error);
     }
 }
コード例 #7
0
ファイル: DdemlServer.cs プロジェクト: zhangjk1980/NDde
                public virtual void Advise(string topic, string item)
                    {
                        if (IsDisposed)
                            throw new ObjectDisposedException(GetType().ToString());
                        if (!IsRegistered)
                            throw new InvalidOperationException(Resources.NotRegisteredMessage);
                        if (topic == null)
                            throw new ArgumentNullException("topic");
                        if (topic.Length > Ddeml.MAX_STRING_SIZE)
                            throw new ArgumentException(Resources.StringParameterInvalidMessage, "topic");
                        if (item == null)
                            throw new ArgumentNullException("item");
                        if (item.Length > Ddeml.MAX_STRING_SIZE)
                            throw new ArgumentException(Resources.StringParameterInvalidMessage, "item");

                        // Assume the topic name and item name are wild.
                        var topicHandle = IntPtr.Zero;
                        var itemHandle = IntPtr.Zero;

                        // Create a string handle for the topic name if it is not wild.
                        if (topic != "*")
                            topicHandle = Ddeml.DdeCreateStringHandle(_InstanceId, topic, Ddeml.CP_WINANSI);

                        // Create a string handle for the item name if it is not wild.
                        if (item != "*")
                            itemHandle = Ddeml.DdeCreateStringHandle(_InstanceId, item, Ddeml.CP_WINANSI);

                        // Post an advise notification.  This will cause an XTYP_ADVREQ transaction for each conversation.
                        bool result = Ddeml.DdePostAdvise(_InstanceId, topicHandle, itemHandle);

                        // Free the string handles created earlier.
                        Ddeml.DdeFreeStringHandle(_InstanceId, itemHandle);
                        Ddeml.DdeFreeStringHandle(_InstanceId, topicHandle);

                        // Check the result to see if the post failed.
                        if (!result)
                            {
                                int error = Ddeml.DdeGetLastError(_InstanceId);
                                string message = Resources.AdviseFailedMessage;
                                message = message.Replace("${service}", _Service);
                                message = message.Replace("${topic}", topic);
                                message = message.Replace("${item}", item);
                                throw new DdemlException(message, error);
                            }
                    }