Esempio n. 1
0
        /// <include file='doc\QueuePathEditor.uex' path='docs/doc[@for="QueuePathEditor.EditValue"]/*' />
        /// <devdoc>
        ///      Edits the given object value using the editor style provided by
        ///      GetEditorStyle.  A service provider is provided so that any
        ///      required editing services can be obtained.
        /// </devdoc>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (provider != null)
            {
                IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                if (edSvc != null)
                {
                    QueuePathDialog dialog = new QueuePathDialog(provider);
                    MessageQueue queue = null;
                    if (value is MessageQueue)
                        queue = (MessageQueue)value;
                    else if (value is string)
                        queue = new MessageQueue((string)value);
                    else if (value != null)
                        return value;

                    if (queue != null)
                        dialog.SelectQueue(queue);

                    IDesignerHost host = (IDesignerHost)provider.GetService(typeof(IDesignerHost));
                    DesignerTransaction trans = null;
                    if (host != null)
                        trans = host.CreateTransaction();

                    try
                    {
                        if ((context == null || context.OnComponentChanging()) && edSvc.ShowDialog(dialog) == DialogResult.OK)
                        {
                            if (dialog.Path != String.Empty)
                            {
                                if (context.Instance is MessageQueue || context.Instance is MessageQueueInstaller)
                                    value = dialog.Path;
                                else
                                {
                                    value = MessageQueueConverter.GetFromCache(dialog.Path);
                                    if (value == null)
                                    {
                                        value = new MessageQueue(dialog.Path);
                                        MessageQueueConverter.AddToCache((MessageQueue)value);
                                        if (context != null)
                                            context.Container.Add((IComponent)value);
                                    }
                                }

                                context.OnComponentChanged();
                            }
                        }
                    }
                    finally
                    {
                        if (trans != null)
                        {
                            trans.Commit();
                        }
                    }
                }
            }

            return value;
        }
Esempio n. 2
0
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (provider != null)
     {
         IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         if (service == null)
         {
             return(value);
         }
         QueuePathDialog dialog = new QueuePathDialog(provider);
         MessageQueue    queue  = null;
         if (value is MessageQueue)
         {
             queue = (MessageQueue)value;
         }
         else if (value is string)
         {
             queue = new MessageQueue((string)value);
         }
         else if (value != null)
         {
             return(value);
         }
         if (queue != null)
         {
             dialog.SelectQueue(queue);
         }
         IDesignerHost       host        = (IDesignerHost)provider.GetService(typeof(IDesignerHost));
         DesignerTransaction transaction = null;
         if (host != null)
         {
             transaction = host.CreateTransaction();
         }
         try
         {
             if ((context != null) && !context.OnComponentChanging())
             {
                 return(value);
             }
             if ((service.ShowDialog(dialog) != DialogResult.OK) || !(dialog.Path != string.Empty))
             {
                 return(value);
             }
             if ((context.Instance is MessageQueue) || (context.Instance is MessageQueueInstaller))
             {
                 value = dialog.Path;
             }
             else
             {
                 value = MessageQueueConverter.GetFromCache(dialog.Path);
                 if (value == null)
                 {
                     value = new MessageQueue(dialog.Path);
                     MessageQueueConverter.AddToCache((MessageQueue)value);
                     if (context != null)
                     {
                         context.Container.Add((IComponent)value);
                     }
                 }
             }
             context.OnComponentChanged();
         }
         finally
         {
             if (transaction != null)
             {
                 transaction.Commit();
             }
         }
     }
     return(value);
 }
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (provider != null)
     {
         IWindowsFormsEditorService service = (IWindowsFormsEditorService) provider.GetService(typeof(IWindowsFormsEditorService));
         if (service == null)
         {
             return value;
         }
         QueuePathDialog dialog = new QueuePathDialog(provider);
         MessageQueue queue = null;
         if (value is MessageQueue)
         {
             queue = (MessageQueue) value;
         }
         else if (value is string)
         {
             queue = new MessageQueue((string) value);
         }
         else if (value != null)
         {
             return value;
         }
         if (queue != null)
         {
             dialog.SelectQueue(queue);
         }
         IDesignerHost host = (IDesignerHost) provider.GetService(typeof(IDesignerHost));
         DesignerTransaction transaction = null;
         if (host != null)
         {
             transaction = host.CreateTransaction();
         }
         try
         {
             if ((context != null) && !context.OnComponentChanging())
             {
                 return value;
             }
             if ((service.ShowDialog(dialog) != DialogResult.OK) || !(dialog.Path != string.Empty))
             {
                 return value;
             }
             if ((context.Instance is MessageQueue) || (context.Instance is MessageQueueInstaller))
             {
                 value = dialog.Path;
             }
             else
             {
                 value = MessageQueueConverter.GetFromCache(dialog.Path);
                 if (value == null)
                 {
                     value = new MessageQueue(dialog.Path);
                     MessageQueueConverter.AddToCache((MessageQueue) value);
                     if (context != null)
                     {
                         context.Container.Add((IComponent) value);
                     }
                 }
             }
             context.OnComponentChanged();
         }
         finally
         {
             if (transaction != null)
             {
                 transaction.Commit();
             }
         }
     }
     return value;
 }