Exemplo n.º 1
0
        async Task LoadConnectionsFromCache()
        {
            foreach (var c in await cache.Load())
            {
                var client = await apiClientFactory.CreateGitHubClient(c.HostAddress);

                var addConnection = true;

                try
                {
                    await loginManager.LoginFromCache(c.HostAddress, client);
                }
                catch (Octokit.ApiException e)
                {
                    addConnection = false;
                    VsOutputLogger.WriteLine("Cached credentials for connection {0} were invalid: {1}", c.HostAddress, e);
                }
                catch (Exception)
                {
                    // Add the connection in this case - could be that there's no internet connection.
                }

                if (addConnection)
                {
                    AddConnection(c.HostAddress, c.UserName);
                }
            }

            Connections.CollectionChanged += RefreshConnections;
        }
Exemplo n.º 2
0
        static ToolWindowPane ShowToolWindow(Guid windowGuid)
        {
            IVsWindowFrame frame;

            if (ErrorHandler.Failed(Services.UIShell.FindToolWindow((uint)__VSCREATETOOLWIN.CTW_fForceCreate,
                                                                    ref windowGuid, out frame)))
            {
                VsOutputLogger.WriteLine("Unable to find or create GitHubPane '" + UI.GitHubPane.GitHubPaneGuid + "'");
                return(null);
            }
            if (ErrorHandler.Failed(frame.Show()))
            {
                VsOutputLogger.WriteLine("Unable to show GitHubPane '" + UI.GitHubPane.GitHubPaneGuid + "'");
                return(null);
            }

            object docView = null;

            if (ErrorHandler.Failed(frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out docView)))
            {
                VsOutputLogger.WriteLine("Unable to grab instance of GitHubPane '" + UI.GitHubPane.GitHubPaneGuid + "'");
                return(null);
            }
            return(docView as GitHubPane);
        }
Exemplo n.º 3
0
 static Assembly LoadAssemblyFromRunDir(object sender, ResolveEventArgs e)
 {
     try
     {
         var name = new AssemblyName(e.Name);
         if (!ourAssemblies.Contains(name.Name))
         {
             return(null);
         }
         var path     = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
         var filename = Path.Combine(path, name.Name + ".dll");
         if (!File.Exists(filename))
         {
             return(null);
         }
         return(Assembly.LoadFrom(filename));
     }
     catch (Exception ex)
     {
         var log = string.Format(CultureInfo.CurrentCulture,
                                 "Error occurred loading {0} from {1}.{2}{3}{4}",
                                 e.Name,
                                 Assembly.GetExecutingAssembly().Location,
                                 Environment.NewLine,
                                 ex,
                                 Environment.NewLine);
         VsOutputLogger.Write(log);
     }
     return(null);
 }
Exemplo n.º 4
0
        public Task <IEnumerable <ConnectionDetails> > Load()
        {
            if (os.File.Exists(cachePath))
            {
                try
                {
                    // TODO: Need a ReadAllTextAsync method here.
                    var data   = os.File.ReadAllText(cachePath, Encoding.UTF8);
                    var result = SimpleJson.DeserializeObject <CacheData>(data);
                    return(Task.FromResult(result.connections.Select(FromCache)));
                }
                catch (Exception e)
                {
                    try
                    {
                        os.File.Delete(cachePath);
                    }
                    catch { }

                    VsOutputLogger.WriteLine("Failed to read connection cache from {0}: {1}", cachePath, e);
                }
            }

            return(Task.FromResult(Enumerable.Empty <ConnectionDetails>()));
        }
Exemplo n.º 5
0
        protected ILocalRepositoryModel GetRepositoryByPath(string path)
        {
            try
            {
                if (!string.IsNullOrEmpty(path))
                {
                    var repo = ServiceProvider.TryGetService <IGitService>().GetRepository(path);
                    return(new LocalRepositoryModel(repo.Info.WorkingDirectory.TrimEnd('\\')));
                }
            }
            catch (Exception ex)
            {
                VsOutputLogger.WriteLine(string.Format(CultureInfo.CurrentCulture, "Error loading the repository from '{0}'. {1}", path, ex));
            }

            return(null);
        }
Exemplo n.º 6
0
        void RefreshRepo()
        {
            ActiveRepo = ServiceProvider.GetExportedValue <ITeamExplorerServiceHolder>().ActiveRepo;

            if (ActiveRepo == null)
            {
                var    vsservices = ServiceProvider.GetExportedValue <IVSServices>();
                string path       = vsservices?.GetActiveRepoPath() ?? String.Empty;
                try
                {
                    ActiveRepo = !String.IsNullOrEmpty(path) ? new SimpleRepositoryModel(path) : null;
                }
                catch (Exception ex)
                {
                    VsOutputLogger.WriteLine(string.Format(CultureInfo.CurrentCulture, "{0}: Error loading the repository from '{1}'. {2}", GetType(), path, ex));
                }
            }
        }
Exemplo n.º 7
0
        public Task Save(IEnumerable <ConnectionDetails> connections)
        {
            var data = SimpleJson.SerializeObject(new CacheData
            {
                connections = connections.Select(ToCache).ToList(),
            });

            try
            {
                os.File.WriteAllText(cachePath, data);
            }
            catch (Exception e)
            {
                VsOutputLogger.WriteLine("Failed to write connection cache to {0}: {1}", cachePath, e);
            }

            return(Task.CompletedTask);
        }
        Assembly LoadAssemblyFromExtensionDir(object sender, ResolveEventArgs e)
        {
            try
            {
                var name     = new AssemblyName(e.Name).Name;
                var filename = Path.Combine(extensionDir, name + ".dll");
                if (!File.Exists(filename))
                {
                    return(null);
                }

                var targetName = AssemblyName.GetAssemblyName(filename);

                // Resolve any exact `FullName` matches.
                if (e.Name != targetName.FullName)
                {
                    // Resolve any version of our assemblies.
                    if (!ourAssemblies.Contains(name, StringComparer.OrdinalIgnoreCase))
                    {
                        Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Not resolving '{0}' to '{1}'.", e.Name, targetName.FullName));
                        return(null);
                    }

                    Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Resolving '{0}' to '{1}'.", e.Name, targetName.FullName));
                }

                Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Loading '{0}' from '{1}'.", targetName.FullName, filename));
                return(Assembly.LoadFrom(filename));
            }
            catch (Exception ex)
            {
                var log = string.Format(CultureInfo.CurrentCulture,
                                        "Error occurred loading {0} from {1}.{2}{3}{4}",
                                        e.Name,
                                        Assembly.GetExecutingAssembly().Location,
                                        Environment.NewLine,
                                        ex,
                                        Environment.NewLine);
                Trace.WriteLine(log);
                VsOutputLogger.Write(log);
            }

            return(null);
        }
Exemplo n.º 9
0
        protected ISimpleRepositoryModel GetActiveRepo()
        {
            var activeRepo = ServiceProvider.GetExportedValue <ITeamExplorerServiceHolder>()?.ActiveRepo;

            // activeRepo can be null at this point because it is set elsewhere as the result of async operation that may not have completed yet.
            if (activeRepo == null)
            {
                var path = ServiceProvider.GetExportedValue <IVSServices>()?.GetActiveRepoPath() ?? String.Empty;
                try
                {
                    activeRepo = !string.IsNullOrEmpty(path) ? new SimpleRepositoryModel(path) : null;
                }
                catch (Exception ex)
                {
                    VsOutputLogger.WriteLine(string.Format(CultureInfo.CurrentCulture, "Error loading the repository from '{0}'. {1}", path, ex));
                }
            }
            return(activeRepo);
        }
Exemplo n.º 10
0
 public override void WriteLine(string message)
 {
     VsOutputLogger.WriteLine(message);
 }