Ejemplo n.º 1
0
        public User LoginAsync(bool enable2fa, string host, string email, string password, ApiVersion apiVersion)
        {
            NGitLab.GitLabClient client = null;
            User user = null;

            NGitLab.Impl.Api.ApiVersion _apiVersion = VsApiVersionToNgitLabversion(apiVersion);
            if (enable2fa)
            {
                client = NGitLab.GitLabClient.Connect(host, password, _apiVersion);
            }
            else
            {
                client = NGitLab.GitLabClient.Connect(host, email, password, _apiVersion);
            }
            try
            {
                user = client.Users.Current();
                user.PrivateToken = client.ApiToken;
                user.ApiVersion   = apiVersion;
            }
            catch (WebException ex)
            {
                var res        = (HttpWebResponse)ex.Response;
                var statusCode = (int)res.StatusCode;

                throw ex;
            }
            catch (Exception ex1)
            {
                throw ex1;
            }
            return(user);
        }
Ejemplo n.º 2
0
        public User LoginAsync(bool enable2fa, string host, string email, string password)
        {
            NGitLab.GitLabClient client = null;
            User user = null;

            if (enable2fa)
            {
                client = NGitLab.GitLabClient.Connect(host, password);
            }
            else
            {
                client = NGitLab.GitLabClient.Connect(host, email, password);
            }
            try
            {
                user = client.Users.Current();
                user.PrivateToken = client.ApiToken;
            }
            catch (WebException ex)
            {
                var res        = (HttpWebResponse)ex.Response;
                var statusCode = (int)res.StatusCode;

                throw new Exception($"错误代码: {statusCode}");
            }
            return(user);
        }
Ejemplo n.º 3
0
        static async Task Main(string[] args)
        {
            if (!Directory.Exists(workingDirectory))
            {
                Directory.CreateDirectory(workingDirectory);
            }

            oldApiClient = NGitLab.GitLabClient.Connect(oldGitUrl, oldApiKey);
            newApiClient = NGitLab.GitLabClient.Connect(newGitUrl, newApiKey);

            Console.Write("Getting old groups... ");
            oldGroups = oldApiClient.Groups.Accessible().ToList();
            Console.WriteLine("Done");

            var namespaces = oldApiClient.Groups.GetNamespaces();

            Console.Write("Getting old projects... ");
            oldProjects = oldApiClient.Projects.Accessible().ToList();
            Console.WriteLine("Done");

            Console.Write("Getting new groups... ");
            newGroups = newApiClient.Groups.Accessible().ToList();
            Console.WriteLine("Done");

            Console.Write("Getting new projects... ");
            newProjects = newApiClient.Projects.Accessible().ToList();
            Console.WriteLine("Done");

            if (isMultiThreaded)
            {
                var tasks = oldGroups.Select(g =>
                {
                    Action action = async() =>
                    {
                        Console.WriteLine("Task={0}, Group={1}, Thread={2}", Task.CurrentId, g.Name, Thread.CurrentThread.ManagedThreadId);
                        await CopyGroup(g);
                    };

                    var task = new Task(action);
                    task.Start();

                    return(task);
                });

                await Task.WhenAll(tasks);

                Console.WriteLine("Complete");
            }
            else
            {
                foreach (var group in oldGroups)
                {
                    await CopyGroup(group);
                }
            }

            Console.ReadLine();
        }
Ejemplo n.º 4
0
        public IReadOnlyList <NamespacesPath> GetNamespacesPathList()
        {
            List <NamespacesPath> nplist = new List <NamespacesPath>();

            NGitLab.GitLabClient client = GetClient();
            foreach (var item in client.Groups.GetNamespaces())
            {
                nplist.Add(item);
            }
            return(nplist);
        }
Ejemplo n.º 5
0
        public IReadOnlyList <NamespacesPath> GetNamespacesPathList()
        {
            List <NamespacesPath> nplist = new List <NamespacesPath>();

            try
            {
                NGitLab.GitLabClient client = GetClient();
                foreach (var item in client.Groups.GetNamespaces())
                {
                    nplist.Add(item);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            return(nplist);
        }