コード例 #1
0
        private string PromptForFileName(string folder, AppServiceDialogViewModel viewmodel)
        {
            var dialog = new FileNameDialog(viewmodel);

            var hwnd   = new IntPtr(_dte.MainWindow.HWnd);
            var window = (System.Windows.Window)HwndSource.FromHwnd(hwnd).RootVisual;

            dialog.Owner = window;

            bool?result = dialog.ShowDialog();

            return((result.HasValue && result.Value) ? dialog.Input : string.Empty);
        }
コード例 #2
0
        public FileNameDialog(AppServiceDialogViewModel viewModel)
        {
            InitializeComponent();
            this.viewModel   = viewModel;
            this.DataContext = this.viewModel;
            //lblFolder.Content = string.Format("{0}/", folder);
            this.viewModel.AddFiles += (ok) =>
            {
                DialogResult = true;
                Close();
            };
            Loaded += (s, e) =>
            {
                Icon  = BitmapFrame.Create(new Uri("pack://application:,,,/AddAnyFile;component/Resources/icon.png", UriKind.RelativeOrAbsolute));
                Title = Vsix.Name;
                SetRandomTip();

                //txtName.Focus();
                //txtName.CaretIndex = 0;
                //txtName.Text = DEFAULT_TEXT;
                //txtName.Select(0, txtName.Text.Length);

                //txtName.PreviewKeyDown += (a, b) =>
                //{
                //    if (b.Key == Key.Escape)
                //    {
                //        if (string.IsNullOrWhiteSpace(txtName.Text) || txtName.Text == DEFAULT_TEXT)
                //            Close();
                //        else
                //            txtName.Text = string.Empty;
                //    }
                //    else if (txtName.Text == DEFAULT_TEXT)
                //    {
                //        txtName.Text = string.Empty;
                //        btnCreate.IsEnabled = true;
                //    }
                //};
            };
        }
コード例 #3
0
        private async void ExecuteAsync(object sender, EventArgs e)
        {
            //var assmbly = System.Reflection.Assembly.LoadFile(@"D:\sample\abp-master\abp-master\samples\BookStore\src\Acme.BookStore.Domain\bin\Debug\netcoreapp2.2\Acme.BookStore.Domain.dll");
            //if (assmbly != null) {
            //    var fullname = assmbly.FullName;
            //    var types = assmbly.GetTypes();
            //    foreach (var ty in types) {
            //        var typename = ty.FullName;
            //    }
            //}

            var    entities = GetEntities(AddAnyFilePackage._dte.Solution).ToArray();
            object item     = ProjectHelpers.GetSelectedItem();

            string folder = FindFolder(item);

            if (string.IsNullOrEmpty(folder) || !Directory.Exists(folder))
            {
                return;
            }

            var     selectedItem    = item as ProjectItem;
            var     selectedProject = item as Project;
            Project project         = selectedItem?.ContainingProject ?? selectedProject ?? ProjectHelpers.GetActiveProject();

            if (project == null)
            {
                return;
            }
            var dir = new DirectoryInfo(folder);

            this.rootNamespace = project.GetRootNamespace();
            var viewmodel = new AppServiceDialogViewModel()
            {
                Entities      = new System.Windows.Data.CollectionView(entities),
                SelectFolder  = dir.Name + "/",
                RootNamespace = this.rootNamespace
            };

            string input = PromptForFileName(folder, viewmodel).TrimStart('/', '\\').Replace("/", "\\");

            if (string.IsNullOrEmpty(input))
            {
                return;
            }

            //string[] parsedInputs = GetParsedInput(input);
            string[] parsedInputs = new string[] {
                viewmodel.DtoClass + ".cs",
                viewmodel.CudtoClass + ".cs",
                viewmodel.ServiceClass + ".cs",
                viewmodel.IServiceClass + ".cs"
            };
            foreach (string inputItem in parsedInputs)
            {
                input = inputItem;

                if (input.EndsWith("\\", StringComparison.Ordinal))
                {
                    input = input + "__dummy__";
                }

                var    file = new FileInfo(Path.Combine(folder, viewmodel.SubFolder, input));
                string path = file.DirectoryName;

                PackageUtilities.EnsureOutputPath(path);

                if (!file.Exists)
                {
                    int position = await WriteFileAsync(project, file.FullName);

                    try
                    {
                        ProjectItem projectItem = null;
                        if (item is ProjectItem projItem)
                        {
                            if ("{6BB5F8F0-4483-11D3-8BCF-00C04F8EC28C}" == projItem.Kind) // Constants.vsProjectItemKindVirtualFolder
                            {
                                projectItem = projItem.ProjectItems.AddFromFile(file.FullName);
                            }
                        }
                        if (projectItem == null)
                        {
                            projectItem = project.AddFileToProject(file);
                        }

                        if (file.FullName.EndsWith("__dummy__"))
                        {
                            projectItem?.Delete();
                            continue;
                        }

                        VsShellUtilities.OpenDocument(this, file.FullName);

                        // Move cursor into position
                        if (position > 0)
                        {
                            Microsoft.VisualStudio.Text.Editor.IWpfTextView view = ProjectHelpers.GetCurentTextView();

                            if (view != null)
                            {
                                view.Caret.MoveTo(new SnapshotPoint(view.TextBuffer.CurrentSnapshot, position));
                            }
                        }

                        _dte.ExecuteCommand("SolutionExplorer.SyncWithActiveDocument");
                        _dte.ActiveDocument.Activate();
                    }
                    catch (Exception ex)
                    {
                        Logger.Log(ex);
                    }
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("The file '" + file + "' already exist.");
                }
            }
        }