Пример #1
0
        private object getBehaviorImplementation(string implementationXml)
        {
            object classImplementation = null;

            try
            {
                classImplementation = XamlReader.Load(implementationXml);
                ISupportsConfiguration supportsConfiguration = classImplementation as ISupportsConfiguration;
                if (supportsConfiguration != null)
                {
                    try
                    {
                        supportsConfiguration.LoadConfiguration(ConfigData);
                    }
                    catch (Exception innerEx)
                    {
                        // Error in Load Configuration of command
                        Logger.Instance.LogError(innerEx);
                        OnBehaviorClassLoadConfigurationException(new ExceptionEventArgs(new Exception(string.Format("Failed to load configuration of behavior (Class: {0}).", Class),
                                                                                                       string.IsNullOrWhiteSpace(implementationXml) ? innerEx : new Exception(string.Format("Behavior Implementation XAML: {0}", implementationXml), innerEx)), null));
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.LogError(ex);
                OnBehaviorClassLoadException(new ExceptionEventArgs(new Exception(string.Format("Failed to instantiate behavior (Class: {0}).", Class),
                                                                                  string.IsNullOrWhiteSpace(implementationXml) ? ex : new Exception(string.Format("Behavior Implementation XAML: {0}", implementationXml), ex)), null));
            }
            return(classImplementation);
        }
        public override void Execute(object parameter)
        {
            ExtensionBehavior extensionBehavior = parameter as ExtensionBehavior;

            if (extensionBehavior == null)
            {
                return;
            }

            ISupportsConfiguration supportConfiguration = extensionBehavior.MapBehavior as ISupportsConfiguration;

            if (supportConfiguration != null)
            {
                try
                {
                    supportConfiguration.Configure();
                }
                catch (Exception ex)
                {
                    if (ViewerApplicationControl.Instance == null)
                    {
                        MessageBoxDialog.Show(LocalizableStrings.GetString("BehaviorConfigurationFailedDescription"), LocalizableStrings.GetString("BehaviorConfigurationFailed"), MessageBoxButton.OK);
                    }
                    else
                    {
                        NotificationPanel.Instance.AddNotification(LocalizableStrings.GetString("BehaviorConfigurationFailed"), LocalizableStrings.GetString("BehaviorConfigurationFailedDescription"), ex.ToString(), MessageType.Warning);
                    }
                }
            }
        }
        private void btnConfigure_Click(object sender, RoutedEventArgs e)
        {
            // Instantiate control
            ToolInstance = ToolInstance ?? Activator.CreateInstance(ToolType);

            // Get the "supports configuration" interface in order to invoke the configure method.
            ISupportsConfiguration supportsConfiguration = ToolInstance as ISupportsConfiguration;

            if (supportsConfiguration != null)
            {
                supportsConfiguration.Configure();
            }
        }
Пример #4
0
        public override void Execute(object parameter)
        {
            ConfigureControlDataItem ccdi = parameter as ConfigureControlDataItem;

            if (ccdi != null)
            {
                ISupportsConfiguration supportsConfig = ccdi.Element as ISupportsConfiguration;
                if (supportsConfig != null)
                {
                    supportsConfig.Configure();
                }
            }
        }
        /// <summary>
        /// Updates attached properties that determine whether to show the configure button
        /// and what its behavior is on click
        /// </summary>
        private void updateConfigureButton(Wizard wizard)
        {
            ISupportsConfiguration configurableCommand = Class as ISupportsConfiguration;

            if (configurableCommand != null && Class as ISupportsWizardConfiguration == null)
            {
                ControlExtensions.SetExtendedUIVisibility(wizard, Visibility.Visible);
                ControlExtensions.SetExtendedCommand(wizard,
                                                     new ParameterlessDelegateCommand(configurableCommand.Configure, delegate { return(true); }));
            }
            else
            {
                ControlExtensions.SetExtendedUIVisibility(wizard, Visibility.Collapsed);
                ControlExtensions.SetExtendedCommand(wizard, null);
            }
        }
Пример #6
0
        public override void Execute(object parameter)
        {
            // Create UI control
            configureControlsControl = new ConfigureControlsControl();

            // Create view model that interacts with UI and associate it as the data context so all elements
            // of the UI can use XAML binding to utilize the view model.
            ConfigureControlsViewModel vm = new ConfigureControlsViewModel();

            IApplicationAdmin appAdmin = MapApplication.Current as IApplicationAdmin;

            if (appAdmin != null && appAdmin.ConfigurableControls != null)
            {
                // Process each element in the configurable controls collection, looking for those that support configuration
                foreach (FrameworkElement elem in appAdmin.ConfigurableControls)
                {
                    if (string.IsNullOrWhiteSpace(elem.Name))
                    {
                        continue;
                    }

                    ISupportsConfiguration supportsConfig = elem as ISupportsConfiguration;
                    if (supportsConfig != null)
                    {
                        string displayName            = ElementExtensions.GetDisplayName(elem);
                        ConfigureControlDataItem ccdi = new ConfigureControlDataItem()
                        {
                            Label   = displayName ?? elem.Name.InsertSpaces(),
                            Element = elem
                        };

                        // Add this element to the list within the view model
                        vm.ConfigurableItems.Add(ccdi);
                    }
                }
            }

            // Associate close command with method that will hide the UI
            vm.Closed += new System.EventHandler(vm_Closed);

            // Assign view model as data context for UI
            configureControlsControl.DataContext = vm;

            // Display UI
            BuilderApplication.Instance.ShowWindow(ESRI.ArcGIS.Mapping.Builder.Resources.Strings.ConfigureControls,
                                                   configureControlsControl, true);
        }
Пример #7
0
 /// <summary>
 /// ConfigDataProperty property changed handler.
 /// </summary>
 /// <param name="d">ExtensionAttachedProperties that changed its ConfigData.</param>
 /// <param name="e">Event arguments.</param>
 private static void OnConfigDataPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     ButtonBase source = d as ButtonBase;
     if (source == null)
         return;
     ISupportsConfiguration supportConfig = source.Command as ISupportsConfiguration;
     if (supportConfig != null)
     {
         string value = e.NewValue as string;
         try
         {
             supportConfig.LoadConfiguration(value);
         }
         catch { }
     }
     
 }
        public override bool CanExecute(object parameter)
        {
            ExtensionBehavior extensionBehavior = parameter as ExtensionBehavior;

            if (extensionBehavior == null)
            {
                return(false);
            }

            ISupportsConfiguration supportConfiguration = extensionBehavior.MapBehavior as ISupportsConfiguration;

            if (supportConfiguration != null)
            {
                return(true);
            }

            return(false);
        }
Пример #9
0
        private void addBehaviorClassToXmlElement(XElement behavior, List <XNamespace> namespaces, out List <XAttribute> additionalTagPrefixes)
        {
            additionalTagPrefixes = null;
            if (behavior == null)
            {
                return;
            }

            if (ClassImplementation != null)
            {
                XElement behaviorElement = new XElement(CLASS);
                behavior.Add(behaviorElement);

                Type behaviorType = ClassImplementation.GetType();
                XmlnsDefinitionAttribute defnAttribute = null;
                object[] attribs = behaviorType.Assembly.GetCustomAttributes(typeof(XmlnsDefinitionAttribute), false);
                if (attribs != null && attribs.Length > 0)
                {
                    defnAttribute = attribs[0] as XmlnsDefinitionAttribute;
                }

                string behaviorNamespace = behaviorType.Namespace;
                string namespaceMapping  = null;
                if (defnAttribute != null)
                {
                    namespaceMapping = defnAttribute.XmlNamespace;
                }
                else
                {
                    namespaceMapping = string.Format("clr-namespace:{0};assembly={1}", behaviorNamespace, behaviorType.Assembly.FullName.Split(',')[0]);
                }

                XNamespace namespaceForCommand = namespaces.FirstOrDefault <XNamespace>(x => x.NamespaceName == namespaceMapping);
                if (namespaceForCommand == null)
                {
                    namespaceForCommand = namespaceMapping;
                    string tagPrefix = behaviorNamespace.Replace('.', '_');

                    if (additionalTagPrefixes == null)
                    {
                        additionalTagPrefixes = new List <XAttribute>();
                    }

                    additionalTagPrefixes.Add(new XAttribute(XNamespace.Xmlns + tagPrefix, namespaceMapping));
                }

                XElement behaviorCommandImplElement = new XElement(namespaceForCommand + behaviorType.Name);
                behaviorElement.Add(behaviorCommandImplElement);

                ISupportsConfiguration supportsConfiguration = ClassImplementation as ISupportsConfiguration;
                if (supportsConfiguration != null)
                {
                    //string configData = null;
                    //try
                    //{
                    //    configData = supportsConfiguration.SaveConfiguration();
                    //}
                    //catch (Exception ex)
                    //{
                    //    Logger.Instance.LogError(ex);
                    //    OnBehaviorClassSaveConfigurationException(new ExceptionEventArgs(ex, null));
                    //}
                    if (!string.IsNullOrWhiteSpace(ConfigData))
                    {
                        ConfigData = ConfigData.Trim();
                        XElement configDataElement = new XElement(CONFIG_DATA);
                        if (ConfigData.StartsWith("<", StringComparison.Ordinal) && ConfigData.EndsWith(">", StringComparison.Ordinal))
                        {
                            try
                            {
                                XDocument xDoc = XDocument.Parse(ConfigData);
                                configDataElement.Add(xDoc.Root);
                            }
                            catch
                            {
                                configDataElement.Value = ConfigData;
                            }
                        }
                        else
                        {
                            configDataElement.Value = ConfigData;
                        }
                        behavior.Add(configDataElement);
                    }
                }
            }
        }