示例#1
0
        private void ReadCacheFromDisk()
        {
            logger.Trace("ReadCacheFromDisk Path:{0}", cachePath.ToString());

            ConnectionCacheItem[] connections = null;

            if (cachePath.FileExists())
            {
                var json = cachePath.ReadAllText();
                try
                {
                    connections = SimpleJson.DeserializeObject <ConnectionCacheItem[]>(json);
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Error deserializing connection cache: {0}", cachePath);
                    cachePath.Delete();
                }
            }

            if (connections != null)
            {
                connectionCache =
                    connections.Select(item => new Connection {
                    Host = new UriString(item.Host), Username = item.Username
                })
                    .ToDictionary(connection => connection.Host);
            }
            else
            {
                connectionCache = new Dictionary <UriString, Connection>();
            }
        }
示例#2
0
        public async Task <bool> SetupIfNeeded(IProgress <float> zipFileProgress = null, IProgress <long> estimatedDurationProgress = null)
        {
            logger.Trace("SetupIfNeeded");

            cancellationToken.ThrowIfCancellationRequested();

            NPath tempPath = null;

            try
            {
                tempPath = NPath.CreateTempDirectory(TempPathPrefix);

                cancellationToken.ThrowIfCancellationRequested();

                var ret = await SetupGitIfNeeded(tempPath, zipFileProgress, estimatedDurationProgress);

                cancellationToken.ThrowIfCancellationRequested();

                ret &= await SetupGitLfsIfNeeded(tempPath, zipFileProgress, estimatedDurationProgress);

                tempPath.Delete();
                return(ret);
            }
            catch (Exception ex)
            {
                logger.Trace(ex);
                return(false);
            }
            finally
            {
                try
                {
                    if (tempPath != null)
                    {
                        tempPath.DeleteIfExists();
                    }
                }
                catch {}
            }
        }