示例#1
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            AddServiceWindow addServiceWindow = new AddServiceWindow()
            {
                Width                 = 400,
                Height                = 150,
                ResizeMode            = System.Windows.ResizeMode.NoResize,
                WindowState           = System.Windows.WindowState.Normal,
                WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen
            };

            addServiceWindow.ShowDialog();
        }
示例#2
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            try
            {
                EnvDTE.DTE dte = Package.GetGlobalService(typeof(SDTE)) as EnvDTE.DTE;

                EnvDTE.ProjectItem projectItem = dte.SelectedItems.Item(1).ProjectItem;
                string             directory   = Path.GetDirectoryName(projectItem.FileNames[0]);
                string             settingFile = Path.Combine(directory, "setting.signalgo");
                if (File.Exists(settingFile))
                {
                    AddReferenceConfigInfo config = null;
                    try
                    {
                        config = JsonConvert.DeserializeObject <AddReferenceConfigInfo>(File.ReadAllText(settingFile, Encoding.UTF8));
                    }
                    catch (Exception ex)
                    {
                        config = new AddReferenceConfigInfo();
                        string[] lines = File.ReadAllLines(settingFile, Encoding.UTF8);
                        if (lines.Length <= 1)
                        {
                            MessageBox.Show("Setting file is empty! please try to recreate your service!", "error", MessageBoxButton.OK, MessageBoxImage.Error);
                            return;
                        }
                        config.ServiceUrl       = lines[0];
                        config.ServiceNameSpace = lines[1];
                        config.LanguageType     = int.Parse(lines[2]);
                    }

                    AddServiceWindow addServiceWindow = new AddServiceWindow()
                    {
                        Width                 = 400,
                        Height                = 150,
                        ResizeMode            = System.Windows.ResizeMode.NoResize,
                        WindowState           = System.Windows.WindowState.Normal,
                        WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen
                    };
                    AddServiceWindowControl content = addServiceWindow.Content as AddServiceWindowControl;
                    content.txtServiceAddress.Text            = config.ServiceUrl;
                    content.txtServiceName.Text               = config.ServiceNameSpace;
                    content.cboLanguage.SelectedIndex         = config.LanguageType;
                    content.cboServiceType.SelectedIndex      = config.ServiceType;
                    content.chkJustServices.IsChecked         = config.IsJustGenerateServices;
                    content.chkAsyncMethods.IsChecked         = config.IsGenerateAsyncMethods;
                    content.rdoIsAutomaticDetection.IsChecked = config.IsAutomaticSyncAndAsyncDetection;
                    content.rdoIsRealMethods.IsChecked        = !config.IsAutomaticSyncAndAsyncDetection;
                    content.customNameSpaces.Text             = config.CustomNameSpaces;
                    if (config.ReplaceNameSpaces != null)
                    {
                        foreach (var item in config.ReplaceNameSpaces)
                        {
                            content.ReplaceNameSpaces.Add(item);
                        }
                    }
                    if (config.SkipAssemblies != null)
                    {
                        foreach (var item in config.SkipAssemblies)
                        {
                            content.SkipAssemblies.Add(item);
                        }
                    }
                    addServiceWindow.ShowDialog();
                }
                else
                {
                    MessageBox.Show("setting file not found!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }