|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using System.Runtime.InteropServices; |
| 7 | +using Microsoft.Vbe.Interop; |
| 8 | +using Rubberduck.SourceControl; |
| 9 | +using System.ComponentModel; |
| 10 | + |
| 11 | +namespace Rubberduck.Interop |
| 12 | +{ |
| 13 | + [ComVisible(true)] |
| 14 | + [Guid("335DA0D8-625C-4CB9-90CD-C9A306B9B787")] |
| 15 | + public interface _ISourceControlClassFactory |
| 16 | + { |
| 17 | + [DispId(1)] |
| 18 | + ISourceControlProvider CreateGitProvider(VBProject project, [Optional] IRepository repository, [Optional] string userName, [Optional] string passWord); |
| 19 | + |
| 20 | + [DispId(2)] |
| 21 | + IRepository CreateRepository(string name, string localDirectory, string remotePathOrUrl); |
| 22 | + } |
| 23 | + |
| 24 | + [ComVisible(true)] |
| 25 | + [Guid("29FB0A0E-F113-458F-823B-1CD1B60D2CA7")] |
| 26 | + [ProgId("Rubberduck.SourceControlClassFactory")] |
| 27 | + [ClassInterface(ClassInterfaceType.None)] |
| 28 | + public class SourceControlClassFactory : _ISourceControlClassFactory |
| 29 | + { |
| 30 | + [Description("Returns a new GitProvider. IRepository must be supplied if also passing user credentials.")] |
| 31 | + public ISourceControlProvider CreateGitProvider(VBProject project, [Optional] IRepository repository, [Optional] string userName, [Optional] string passWord) |
| 32 | + { |
| 33 | + if (passWord != null && userName != null) |
| 34 | + { |
| 35 | + if (repository == null) |
| 36 | + { |
| 37 | + throw new ArgumentNullException("Must supply an IRepository if supplying credentials."); |
| 38 | + } |
| 39 | + return new GitProvider(project, repository, userName, passWord); |
| 40 | + } |
| 41 | + |
| 42 | + if (repository != null) |
| 43 | + { |
| 44 | + return new GitProvider(project, repository); |
| 45 | + } |
| 46 | + |
| 47 | + return new GitProvider(project); |
| 48 | + } |
| 49 | + |
| 50 | + [Description("Returns new instance of repository struct.")] |
| 51 | + public IRepository CreateRepository(string name, string localDirectory, string remotePathOrUrl) |
| 52 | + { |
| 53 | + return new Repository(name, localDirectory, remotePathOrUrl); |
| 54 | + } |
| 55 | + } |
| 56 | +} |
0 commit comments