Пример #1
0
        /// <include file='doc\MessageQueueInstaller.uex' path='docs/doc[@for="MessageQueueInstaller.RestoreQueue"]/*' />
        /// <devdoc>
        /// Called by Rollback and Uninstall to restore a queue to its state prior to Install
        /// </devdoc>
        private void RestoreQueue(IDictionary state)
        {
            bool exists = false;

            if (state != null && state["Exists"] != null)
            {
                exists = (bool)state["Exists"];
            }
            else
            {
                // this can only happen at uninstall - the user might have deleted the .InstallState
                // file since Install ran. It's probably best to leave things the way they are.
                return;
            }

            if (exists)
            {
                Context.LogMessage(Res.GetString(Res.RestoringQueue, Path));
                // the queue existed before install. Restore the properties

                MessageQueue queue = null;

                // first, restore the queue with the right Transactional property
                if (!MessageQueue.Exists(Path))
                {
                    // weird, but possible: the queue used to exist, but it doesn't now.
                    // put it back
                    queue = MessageQueue.Create(Path, (bool)state["Transactional"]);
                }
                else
                {
                    queue = new MessageQueue(Path);
                    if (queue.Transactional != (bool)state["Transactional"])
                    {
                        // the transactional property doesn't match. Recreate so it does
                        MessageQueue.Delete(Path);
                        queue = MessageQueue.Create(Path, (bool)state["Transactional"]);
                    }
                }

                // now change all the other properties to how they were.
                queue.Authenticate       = (bool)state["Authenticate"];
                queue.BasePriority       = (short)state["BasePriority"];
                queue.Category           = (Guid)state["Category"];
                queue.EncryptionRequired = (EncryptionRequired)state["EncryptionRequired"];
                queue.Label = (string)state["Label"];
                queue.MaximumJournalSize = (long)state["MaximumJournalSize"];
                queue.MaximumQueueSize   = (long)state["MaximumQueueSize"];
                if (MessageQueue.Msmq3OrNewer) //this feature is unavailable on win2k
                {
                    queue.MulticastAddress = (string)state["MulticastAddress"];
                }

                queue.UseJournalQueue = (bool)state["UseJournalQueue"];
                queue.ResetPermissions();
            }
            else
            {
                Context.LogMessage(Res.GetString(Res.RemovingQueue, Path));
                // it wasn't there before install, so let's make sure it still isn't
                if (MessageQueue.Exists(path))
                {
                    MessageQueue.Delete(path);
                }
            }
        }
Пример #2
0
        /// <include file='doc\MessageQueueInstaller.uex' path='docs/doc[@for="MessageQueueInstaller.Install"]/*' />
        /// <devdoc>
        ///    <para>Writes message queue information to the registry. This method is meant to be
        ///       used by installation tools, which process the appropriate methods
        ///       automatically</para>
        /// </devdoc>
        public override void Install(IDictionary stateSaver)
        {
            base.Install(stateSaver);

            Context.LogMessage(Res.GetString(Res.CreatingQueue, Path));

            bool exists = MessageQueue.Exists(path);

            stateSaver["Exists"] = exists;
            MessageQueue queue = null;

            if (!exists)
            {
                queue = MessageQueue.Create(Path, Transactional);
            }
            else
            {
                // it exists. If it's got the right transactional property, we're OK.
                // Otherwise we have to recreate.
                queue = new MessageQueue(Path);

                // save off the properties for rollback
                stateSaver["Authenticate"]       = queue.Authenticate;
                stateSaver["BasePriority"]       = queue.BasePriority;
                stateSaver["Category"]           = queue.Category;
                stateSaver["EncryptionRequired"] = queue.EncryptionRequired;
                stateSaver["Label"] = queue.Label;
                stateSaver["MaximumJournalSize"] = queue.MaximumJournalSize;
                stateSaver["MaximumQueueSize"]   = queue.MaximumQueueSize;
                stateSaver["Path"]            = queue.Path;
                stateSaver["Transactional"]   = queue.Transactional;
                stateSaver["UseJournalQueue"] = queue.UseJournalQueue;
                if (MessageQueue.Msmq3OrNewer) //this feature is unavailable on win2k
                {
                    stateSaver["MulticastAddress"] = queue.MulticastAddress;
                }


                if (queue.Transactional != Transactional)
                {
                    // Messages won't be kept.
                    MessageQueue.Delete(Path);
                    queue = MessageQueue.Create(Path, Transactional);
                }
            }

            // now change all the properties to how we want them.
            queue.Authenticate       = Authenticate;
            queue.BasePriority       = BasePriority;
            queue.Category           = Category;
            queue.EncryptionRequired = EncryptionRequired;
            queue.Label = Label;
            queue.MaximumJournalSize = MaximumJournalSize;
            queue.MaximumQueueSize   = MaximumQueueSize;
            queue.UseJournalQueue    = UseJournalQueue;
            if (MessageQueue.Msmq3OrNewer) //this feature is unavailable on win2k
            {
                queue.MulticastAddress = MulticastAddress;
            }


            if (permissions != null)
            {
                queue.SetPermissions(permissions);
            }
        }