当前位置: 首页>>代码示例>>C#>>正文


C# CommandEventArgs.GetService方法代码示例

本文整理汇总了C#中CommandEventArgs.GetService方法的典型用法代码示例。如果您正苦于以下问题:C# CommandEventArgs.GetService方法的具体用法?C# CommandEventArgs.GetService怎么用?C# CommandEventArgs.GetService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CommandEventArgs的用法示例。


在下文中一共展示了CommandEventArgs.GetService方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnExecute

        public override void OnExecute(CommandEventArgs e)
        {
            IUIShell shell = e.GetService<IUIShell>();
            Uri info;

            if (e.Argument is string)
            {
                string arg = (string)e.Argument;

                info = null;
                if (SvnItem.IsValidPath(arg, true))
                {
                    SvnItem item = e.GetService<IFileStatusCache>()[arg];

                    if (item.IsVersioned)
                    {
                        info = item.Uri;

                        if (item.IsFile)
                            info = new Uri(info, "./");
                    }
                }

                if (info == null)
                    info = new Uri((string)e.Argument);
            }
            else if (e.Argument is Uri)
                info = (Uri)e.Argument;
            else
                using (AddRepositoryRootDialog dlg = new AddRepositoryRootDialog())
                {
                    if (dlg.ShowDialog(e.Context) != DialogResult.OK || dlg.Uri == null)
                        return;

                    info = dlg.Uri;
                }

            if (info != null)
            {
                RepositoryExplorerControl ctrl = e.Selection.ActiveDialogOrFrameControl as RepositoryExplorerControl;

                if (ctrl == null)
                {
                    IAnkhPackage pkg = e.GetService<IAnkhPackage>();
                    pkg.ShowToolWindow(AnkhToolWindow.RepositoryExplorer);
                }

                ctrl = e.Selection.ActiveDialogOrFrameControl as RepositoryExplorerControl;

                if (ctrl != null)
                    ctrl.AddRoot(info);
            }
        }
开发者ID:necora,项目名称:ank_git,代码行数:53,代码来源:RepositoryBrowseCommand.cs

示例2: OnExecute

        public override void OnExecute(CommandEventArgs e)
        {
            ISvnRepositoryItem item = EnumTools.GetSingle(e.Selection.GetSelection<ISvnRepositoryItem>());

            if (item == null)
                return;

            string newName = item.Origin.Target.FileName;

            if (e.Argument != null)
            {
                string[] items = e.Argument as string[];

                if (items != null)
                {
                    if (items.Length == 1)
                        newName = items[0];
                    else if (items.Length > 1)
                        newName = items[1];
                }
            }

            string logMessage;
            using (RenameDialog dlg = new RenameDialog())
            {
                dlg.Context = e.Context;
                dlg.OldName = item.Origin.Target.FileName;
                dlg.NewName = newName;

                if (DialogResult.OK != dlg.ShowDialog(e.Context))
                {
                    return;
                }
                newName = dlg.NewName;
                logMessage = dlg.LogMessage;
            }

            try
            {
                Uri itemUri = SvnTools.GetNormalizedUri(item.Origin.Uri);
                e.GetService<IProgressRunner>().RunModal(CommandStrings.RenamingNodes,
                    delegate(object sender, ProgressWorkerArgs we)
                    {
                        SvnMoveArgs ma = new SvnMoveArgs();
                        ma.LogMessage = logMessage;
                        we.Client.RemoteMove(itemUri, new Uri(itemUri, newName), ma);
                    });
            }
            finally
            {
                item.RefreshItem(true);
            }
        }
开发者ID:necora,项目名称:ank_git,代码行数:53,代码来源:RenameNode.cs

示例3: OnExecute

        public override void OnExecute(CommandEventArgs e)
        {
            List<SvnOrigin> items = new List<SvnOrigin>();
            List<ISvnRepositoryItem> refresh = new List<ISvnRepositoryItem>();
            foreach (ISvnRepositoryItem i in e.Selection.GetSelection<ISvnRepositoryItem>())
            {
                if (i.Origin == null || i.Origin.Target.Revision != SvnRevision.Head || i.Origin.IsRepositoryRoot)
                    break;

                items.Add(i.Origin);
                refresh.Add(i);
            }

            if(items.Count == 0)
                return;

            string logMessage;
            Uri[] uris;
            using(ConfirmDeleteDialog d = new ConfirmDeleteDialog())
            {
                d.Context = e.Context;
                d.SetUris(items);

                if (!e.DontPrompt && d.ShowDialog(e.Context) != System.Windows.Forms.DialogResult.OK)
                    return;

                logMessage = d.LogMessage;
                uris = d.Uris;
            }

            try
            {
                e.GetService<IProgressRunner>().RunModal("Deleting",
                    delegate(object sender, ProgressWorkerArgs a)
                    {
                        SvnDeleteArgs da = new SvnDeleteArgs();
                        da.LogMessage = logMessage;

                        a.Client.RemoteDelete(uris, da);
                    });
            }
            finally
            {
                // TODO: Don't refresh each item; refresh each parent!
                foreach(ISvnRepositoryItem r in refresh)
                {
                    r.RefreshItem(true);
                }
            }
        }
开发者ID:necora,项目名称:ank_git,代码行数:50,代码来源:DeleteRepositoryItemCommand.cs

示例4: OnExecute

        public override void OnExecute(CommandEventArgs e)
        {
            IAnkhDiffHandler diff = e.GetService<IAnkhDiffHandler>();
            ISvnRepositoryItem reposItem = EnumTools.GetSingle(e.Selection.GetSelection<ISvnRepositoryItem>());

            if (reposItem == null)
                return;

            SvnRevision from;
            SvnRevision to;
            if (e.Command == AnkhCommand.RepositoryCompareWithWc)
            {
                from = reposItem.Revision;
                to = SvnRevision.Working;
            }
            else
            {
                from = reposItem.Revision.Revision - 1;
                to = reposItem.Revision;
            }
            AnkhDiffArgs da = new AnkhDiffArgs();

            if (to == SvnRevision.Working)
            {
                da.BaseFile = diff.GetTempFile(reposItem.Origin.Target, from, true);

                if (da.BaseFile == null)
                    return; // User canceled

                da.MineFile = ((SvnPathTarget)reposItem.Origin.Target).FullPath;
            }
            else
            {
                string[] files = diff.GetTempFiles(reposItem.Origin.Target, from, to, true);

                if (files == null)
                    return; // User canceled
                da.BaseFile = files[0];
                da.MineFile = files[1];
                System.IO.File.SetAttributes(da.MineFile, System.IO.FileAttributes.ReadOnly | System.IO.FileAttributes.Normal);
            }

            da.BaseTitle = diff.GetTitle(reposItem.Origin.Target, from);
            da.MineTitle = diff.GetTitle(reposItem.Origin.Target, to);
            diff.RunDiff(da);
        }
开发者ID:necora,项目名称:ank_git,代码行数:46,代码来源:ShowRepositoryItemChanges.cs

示例5: OnExecute

        public override void OnExecute(CommandEventArgs e)
        {
            ISvnRepositoryItem selected = EnumTools.GetSingle(e.Selection.GetSelection<ISvnRepositoryItem>());

            string directoryName = "";

            using (CreateDirectoryDialog dlg = new CreateDirectoryDialog())
            {
                DialogResult result = dlg.ShowDialog(e.Context);

                directoryName = dlg.NewDirectoryName;

                if (result != DialogResult.OK || string.IsNullOrEmpty(directoryName))
                    return;

                string log = dlg.LogMessage;

                // Handle special characters like on local path
                Uri uri = SvnTools.AppendPathSuffix(selected.Uri, directoryName);

                ProgressRunnerResult prResult =
                    e.GetService<IProgressRunner>().RunModal(
                    CommandStrings.CreatingDirectories,
                    delegate(object sender, ProgressWorkerArgs ee)
                    {
                        SvnCreateDirectoryArgs args = new SvnCreateDirectoryArgs();
                        args.ThrowOnError = false;
                        args.CreateParents = true;
                        args.LogMessage = log;
                        ee.Client.RemoteCreateDirectory(uri, args);
                    }
                    );

                if (prResult.Succeeded)
                {
                    selected.RefreshItem(false);
                }
            }
        }
开发者ID:necora,项目名称:ank_git,代码行数:39,代码来源:CreateDirectoryCommand.cs

示例6: OnExecute

        public override void OnExecute(CommandEventArgs e)
        {
            ISvnRepositoryItem ri = null;

            foreach (ISvnRepositoryItem i in e.Selection.GetSelection<ISvnRepositoryItem>())
            {
                if (i.Origin == null)
                    continue;

                ri = i;
                break;
            }
            if (ri == null)
                return;

            string toFile = e.GetService<IAnkhTempFileManager>().GetTempFileNamed(ri.Origin.Target.FileName);
            string ext = Path.GetExtension(toFile);

            if (!SaveFile(e, ri, toFile))
                return;

            if (e.Command == AnkhCommand.ViewInVsNet)
                VsShellUtilities.OpenDocument(e.Context, toFile);
            else if (e.Command == AnkhCommand.ViewInVsText)
            {
                IVsUIHierarchy hier;
                IVsWindowFrame frame;
                uint id;
                VsShellUtilities.OpenDocument(e.Context, toFile, VSConstants.LOGVIEWID_TextView, out hier, out id, out frame);
            }
            else
            {
                Process process = new Process();
                process.StartInfo.UseShellExecute = true;

                if (e.Command == AnkhCommand.ViewInWindowsWith
                    && !string.Equals(ext, ".zip", StringComparison.OrdinalIgnoreCase))
                {
                    // TODO: BH: I tested with adding quotes around {0} but got some error

                    // BH: Don't call this on .zip files in vista, as it will break the builtin
                    // zip file support in the Windows Explorer (as that isn't available in the list)

                    process.StartInfo.FileName = "rundll32.exe";
                    process.StartInfo.Arguments = string.Format("Shell32,OpenAs_RunDLL {0}", toFile);
                }
                else
                    process.StartInfo.FileName = toFile;

                try
                {
                    process.Start();
                }
                catch (Win32Exception ex)
                {
                    // no application is associated with the file type
                    if (ex.NativeErrorCode == NOASSOCIATEDAPP)
                        e.GetService<IAnkhDialogOwner>()
                            .MessageBox.Show("Windows could not find an application associated with the file type",
                            "No associated application", MessageBoxButtons.OK);
                    else
                        throw;
                }
            }
        }
开发者ID:necora,项目名称:ank_git,代码行数:65,代码来源:ViewInVSNetCommand.cs

示例7: OnExecute

        public override void OnExecute(CommandEventArgs e)
        {
            Uri target = null;
            Uri root = null;

            List<SvnUriTarget> copyFrom = new List<SvnUriTarget>();
            foreach (ISvnRepositoryItem item in e.Selection.GetSelection<ISvnRepositoryItem>())
            {
                SvnUriTarget utt = item.Origin.Target as SvnUriTarget;

                if(utt == null)
                    utt = new SvnUriTarget(item.Origin.Uri, item.Origin.Target.Revision);

                copyFrom.Add(utt);

                if(root == null)
                    root = item.Origin.RepositoryRoot;

                if (target == null)
                    target = item.Origin.Uri;
                else
                {
                    Uri itemUri = SvnTools.GetNormalizedUri(item.Origin.Uri);

                    Uri r = item.Origin.Uri.MakeRelativeUri(target);

                    if(r.IsAbsoluteUri)
                    {
                        target = null;
                        break;
                    }

                    string rs = r.ToString();

                    if(r.ToString().StartsWith("/", StringComparison.Ordinal))
                    {
                        target = new Uri(target, "/");
                        break;
                    }

                    while(r.ToString().StartsWith("../"))
                    {
                        target = new Uri(target, "../");
                        r = item.Origin.Uri.MakeRelativeUri(target);
                    }
                }
            }

            bool isMove = e.Command == AnkhCommand.ReposMoveTo;
            Uri toUri;
            string logMessage;
            using (CopyToDialog dlg = new CopyToDialog())
            {
                dlg.RootUri = root;
                dlg.SelectedUri = target;

                dlg.Text = isMove ? "Move to Url" : "Copy to Url";

                if (dlg.ShowDialog(e.Context) != System.Windows.Forms.DialogResult.OK)
                    return;

                toUri = dlg.SelectedUri;
                logMessage = dlg.LogMessage;
            }

            // TODO: BH: Make sure the 2 attempts actually make sense

            e.GetService<IProgressRunner>().RunModal(isMove ? "Moving" : "Copying",
                delegate(object snd, ProgressWorkerArgs a)
                {
                    if (isMove)
                    {
                        List<Uri> uris = new List<Uri>();
                        foreach (SvnUriTarget ut in copyFrom)
                            uris.Add(ut.Uri);

                        SvnMoveArgs ma = new SvnMoveArgs();
                        ma.LogMessage = logMessage;
                        ma.CreateParents = true;

                        try
                        {
                            // First try with the full new name
                            a.Client.RemoteMove(uris, toUri, ma);
                        }
                        catch (SvnFileSystemException fs)
                        {
                            if (fs.SvnErrorCode != SvnErrorCode.SVN_ERR_FS_ALREADY_EXISTS)
                                throw;

                            // If exists retry below this directory with the existing name
                            ma.AlwaysMoveAsChild = true;
                            a.Client.RemoteMove(uris, toUri, ma);
                        }
                    }
                    else
                    {
                        SvnCopyArgs ca = new SvnCopyArgs();
                        ca.LogMessage = logMessage;
                        ca.CreateParents = true;
//.........这里部分代码省略.........
开发者ID:necora,项目名称:ank_git,代码行数:101,代码来源:CopyToOrMove.cs

示例8: OnExecute

        public override void OnExecute(CommandEventArgs e)
        {
            ISvnRepositoryItem item = EnumTools.GetSingle(e.Selection.GetSelection<ISvnRepositoryItem>());

            if (item == null)
                return;

            string copyTo;
            bool copyBelow = false;
            bool suggestExport = false;
            IFileStatusCache cache = e.GetService<IFileStatusCache>();

            if (item.NodeKind == SharpSvn.SvnNodeKind.Directory)
            {
                using (FolderBrowserDialog fd = new FolderBrowserDialog())
                {
                    fd.ShowNewFolderButton = false;

                    if (DialogResult.OK != fd.ShowDialog(e.Context.DialogOwner))
                        return;

                    copyTo = fd.SelectedPath;
                    copyBelow = true;

                    SvnItem dirItem = cache[copyTo];

                    if (dirItem == null || !dirItem.IsVersioned)
                        suggestExport = true;
                }
            }
            else
            {
                using (SaveFileDialog sfd = new SaveFileDialog())
                {
                    sfd.CheckPathExists = true;
                    sfd.OverwritePrompt = true;
                    string name = item.Origin.Target.FileName;
                    string ext = Path.GetExtension(item.Origin.Target.FileName);
                    sfd.Filter = string.Format("{0} files|*.{0}|All files (*.*)|*", ext.TrimStart('.'));
                    sfd.FileName = name;

                    if (DialogResult.OK != sfd.ShowDialog(e.Context.DialogOwner))
                        return;

                    copyTo = SvnTools.GetNormalizedFullPath(sfd.FileName);

                    SvnItem fileItem = cache[copyTo];

                    if (File.Exists(copyTo))
                    {
                        // We prompted to confirm; remove the file!

                        if (fileItem.IsVersioned)
                            e.GetService<IProgressRunner>().RunModal("Copying",
                                delegate(object sender, ProgressWorkerArgs a)
                                {
                                    SvnDeleteArgs da = new SvnDeleteArgs();
                                    da.Force = true;
                                    a.Client.Delete(copyTo, da);
                                });
                        else
                            File.Delete(copyTo);
                    }

                    SvnItem dir = fileItem.Parent;

                    if (dir == null || !(dir.IsVersioned && dir.IsVersionable))
                        suggestExport = true;
                }
            }

            if (!suggestExport)
            {
                e.GetService<IProgressRunner>().RunModal("Copying",
                    delegate(object sender, ProgressWorkerArgs a)
                    {
                        SvnCopyArgs ca = new SvnCopyArgs();
                        ca.CreateParents = true;
                        if (copyBelow)
                            ca.AlwaysCopyAsChild = true;

                        a.Client.Copy(item.Origin.Target, copyTo, ca);
                    });
            }
            else
            {
                AnkhMessageBox mb = new AnkhMessageBox(e.Context);

                if (DialogResult.Yes == mb.Show("The specified path is not in a workingcopy; would you like to export the file instead?",
                    "No Working Copy", MessageBoxButtons.YesNo, MessageBoxIcon.Information))
                {
                    e.GetService<IProgressRunner>().RunModal("Exporting",
                    delegate(object sender, ProgressWorkerArgs a)
                    {
                        SvnExportArgs ea = new SvnExportArgs();
                        ea.Revision = item.Revision;

                        a.Client.Export(item.Origin.Target, copyTo, ea);
                    });
                }
//.........这里部分代码省略.........
开发者ID:necora,项目名称:ank_git,代码行数:101,代码来源:CopyToWorkingCopy.cs


注:本文中的CommandEventArgs.GetService方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。