private async Task <SolutionResult> ExecuteSolutionScan(string solutionPath, ICancelableProgress <ProgressMessage> progress, bool executeGitFetch)
        {
            var result = new SolutionResult(new FileInfo(solutionPath), this);

            foreach (var projectPath in GetProjects(result.Info.DirectoryName))
            {
                if (progress.Token.IsCancellationRequested)
                {
                    Log.Information("Cancelling scan");

                    throw new OperationCanceledException("Operation was canceled by user");
                }

                var projectInfo = new FileInfo(projectPath);

                var packagePaths = GetPackages(projectInfo.DirectoryName);

                ProjectResult projectResult;

                if (packagePaths.Count() != 0)
                // Projects contains package.config file
                {
                    var packageInfo = new FileInfo(packagePaths.First());

                    projectResult = new ProjectResult(projectInfo, packageInfo);
                }
                else
                {
                    projectResult = new ProjectResult(projectInfo);
                }

                var nuspecInfo = GetNuspec(projectInfo.DirectoryName).FirstOrDefault();

                if (!string.IsNullOrEmpty(nuspecInfo))
                {
                    projectResult.NuspecInfo = new FileInfo(nuspecInfo);
                }

                result.Projects.Add(projectResult);
            }

            var gitPath = DirectoryTools.SearchDirectory(solutionPath, GetGitFolder);

            if (!string.IsNullOrEmpty(gitPath))
            {
                result.GitInformation = new GitInfo(gitPath, _gitEngine);

                await result.GitInformation.Init(executeGitFetch);
            }

            return(result);
        }
Beispiel #2
0
        public async Task <SolutionResult> ScanSolution(string rootDirectory, ICancelableProgress <ProgressMessage> progress, bool executeGitFetch)
        {
            var solutions = GetSolutions(rootDirectory);

            if (!solutions.Any())
            {
                var ex = new ArgumentException("No solutions were found");

                Log.Error(ex, "Exception in ScanSolution");

                throw ex;
            }

            return(await ExecuteSolutionScan(solutions.First(), progress, executeGitFetch));
        }
		/// <summary>
		/// Compress multiple items with the ZIP algorithm.
		/// </summary>
		/// <param name="infos">The items to compress.</param>
		/// <param name="progress1">The progress1.</param>
		/// <param name="progress2">The progress2.</param>
		/// <param name="destinationStream">The destination stream.</param>
		/// <returns></returns>
		private static Stream CompressHeterogenousToStream(
			CompressHeterogenousInfos infos,
			ICancelableProgress progress1,
			Cancelable progress2,
			Stream destinationStream )
		{
			if ( infos == null ||
				infos.InternalItems == null ||
				infos.InternalItems.Count <= 0 )
			{
				return null;
			}
			else
			{
				// No "using" block.
				ZipOutputStream zip = new ZipOutputStream( destinationStream );

				Crc32 crc = new Crc32();
				zip.SetLevel( 9 );	// 0..9.

				int index = 1;
				foreach ( CompressHeterogenousInfo info
					in infos.InternalItems )
				{
					// Cancel, if requested.
					if ( progress1 != null )
					{
						if ( progress1.OnProgress( null, EventArgs.Empty ) ==
							CancelMode.Cancel )
						{
							return null;
						}
					}
					// Cancel, if requested.
					if ( progress2 != null )
					{
						if ( progress2( info ) == CancelMode.Cancel )
						{
							return null;
						}
					}

					// --

					byte[] buffer = null;
					string fileName = null;
					bool putEntry;

					switch ( info.Type )
					{
						case CompressHeterogenousInfo.InfoType.String:
							fileName = info.FilePath;
							if ( fileName == null || fileName.Length <= 0 )
							{
								fileName =
									string.Format(
									@"file{0}.bin",
									index );
							}

							buffer = Encoding.UTF8.GetBytes( info.Content );

							putEntry = true;
							break;

						case CompressHeterogenousInfo.InfoType.File:
							fileName = Path.GetFileName( info.FilePath );

							ZipEntry entry = new ZipEntry( fileName );
							zip.PutNextEntry( entry );

							using ( FileStream fs = new FileStream(
								info.FilePath,
								FileMode.Open,
								FileAccess.Read,
								FileShare.Read ) )
							using ( BinaryReader r = new BinaryReader( fs ) )
							{
								byte[] smallBuffer = new byte[16384];

								int bytesRead;
								do
								{
									bytesRead = r.Read(
										smallBuffer,
										0,
										smallBuffer.Length );
									zip.Write( smallBuffer, 0, bytesRead );

									// --

									// Cancel, if requested.
									if ( progress1 != null )
									{
										if ( progress1.OnProgress(
											null,
											EventArgs.Empty ) ==
											CancelMode.Cancel )
										{
											return null;
										}
									}
									// Cancel, if requested.
									if ( progress2 != null )
									{
										if ( progress2( info ) ==
											CancelMode.Cancel )
										{
											return null;
										}
									}
								}
								while ( bytesRead > 0 );
							}

							putEntry = false;
							break;

						case CompressHeterogenousInfo.InfoType.Bytes:
							fileName = info.FilePath;
							if ( fileName == null ||
								fileName.Length <= 0 )
							{
								fileName =
									string.Format(
									@"file{0}.bin",
									index );
							}

							buffer = info.Bytes;

							putEntry = true;
							break;

						default:
							Debug.Assert(
								false,
								string.Format(
								@"Unknown compression info type '{0}'.",
								info.Type ) );
							putEntry = false;
							break;
					}

					// --

					if ( putEntry )
					{
						ZipEntry entry = new ZipEntry( fileName );
						entry.DateTime = DateTime.Now;
						entry.Size = buffer.Length;

						crc.Reset();
						crc.Update( buffer );

						entry.Crc = crc.Value;

						zip.PutNextEntry( entry );
						zip.Write( buffer, 0, buffer.Length );
					}

					index++;
				}

				zip.Finish();
				return zip;
			}
		}
		/// <summary>
		/// Compress multiple items with the ZIP algorithm.
		/// </summary>
		/// <param name="infos">The items to compress.</param>
		/// <param name="progress1">The progress1.</param>
		/// <param name="progress2">The progress2.</param>
		/// <param name="destinationFilePath">The destination file path.</param>
		private static void CompressHeterogenousToFile(
			CompressHeterogenousInfos infos,
			ICancelableProgress progress1,
			Cancelable progress2,
			FileInfo destinationFilePath )
		{
			if ( destinationFilePath.Exists )
			{
				destinationFilePath.Delete();
			}

			using ( FileStream destinationStream = new FileStream(
				destinationFilePath.FullName,
				FileMode.OpenOrCreate,
				FileAccess.ReadWrite ) )
			{
				Stream realStream =
					CompressHeterogenousToStream(
					infos,
					progress1,
					progress2,
					destinationStream );

				if ( realStream != null )
				{
					realStream.Dispose();
				}
			}
		}
		/// <summary>
		/// Compress multiple items with the ZIP algorithm.
		/// </summary>
		/// <param name="infos">The items to compress.</param>
		/// <param name="progress">The progress.</param>
		/// <param name="destinationFilePath">The destination file path.</param>
		public static void CompressHeterogenousToFile(
			CompressHeterogenousInfos infos,
			ICancelableProgress progress,
			FileInfo destinationFilePath )
		{
			CompressHeterogenousToFile(
				infos,
				progress,
				null,
				destinationFilePath );
		}
		/// <summary>
		/// Compress multiple items with the ZIP algorithm.
		/// </summary>
		/// <param name="infos">The items to compress.</param>
		/// <param name="progress1">The progress1.</param>
		/// <param name="progress2">The progress2.</param>
		/// <returns>Returns the compressed items.</returns>
		private static byte[] CompressHeterogenous(
			CompressHeterogenousInfos infos,
			ICancelableProgress progress1,
			Cancelable progress2 )
		{
			using ( MemoryStream destinationStream = new MemoryStream() )
			{
				Stream realStream = CompressHeterogenousToStream(
					infos,
					progress1,
					progress2,
					destinationStream );

				if ( realStream == null )
				{
					return null;
				}
				else
				{
					using ( realStream )
					{
						byte[] c = new byte[destinationStream.Length];

						destinationStream.Seek( 0, SeekOrigin.Begin );
						destinationStream.Read( c, 0, c.Length );

						return c;
					}
				}
			}
		}
		/// <summary>
		/// Compress multiple items with the ZIP algorithm.
		/// </summary>
		/// <param name="infos">The items to compress.</param>
		/// <param name="progress">The progress.</param>
		/// <returns>Returns the compressed items.</returns>
		public static byte[] CompressHeterogenous(
			CompressHeterogenousInfos infos,
			ICancelableProgress progress )
		{
			return CompressHeterogenous( infos, progress, null );
		}
Beispiel #8
0
        public async Task <IEnumerable <SolutionResult> > ScanSolutions(string rootDirectory, ICancelableProgress <ProgressMessage> progress, bool executeGitFetch)
        {
            progress.Report(new ProgressMessage {
                Value = 0D, Message = "Searching for solutions"
            });

            var solutions = GetSolutions(rootDirectory);

            double Progress(int current) => Math.Round(current / (solutions.Count() / 100D), 2);

            List <Task <SolutionResult> > SolutionsTask = new List <Task <SolutionResult> >();

            for (int i = 0; i < solutions.Length; i++)
            {
                string solution = solutions[i];

                progress.Report(new ProgressMessage {
                    Value = Progress(i + 1), Message = $"Scanning {i + 1}/{solutions.Count()}"
                });

                if (progress.Token.IsCancellationRequested)
                {
                    Log.Information("Cancelling scan");

                    throw new OperationCanceledException("Operation was canceled by user");
                }

                SolutionsTask.Add(ExecuteSolutionScan(solution, progress, executeGitFetch));
            }

            progress.Report(new ProgressMessage {
                Value = 0, Message = "Finishing scan"
            });

            await Task.WhenAll(SolutionsTask);

            return(SolutionsTask.Select(a => a.Result));
        }
		/// <summary>
		/// Compress multiple items with the ZIP algorithm.
		/// </summary>
		/// <param name="infos">The items to compress.</param>
		/// <returns>Returns the compressed items.</returns>
		private static byte[] CompressHeterogenous(
			CompressHeterogenousInfos infos,
			ICancelableProgress progress1,
			Cancelable progress2 )
		{
			if ( infos == null ||
				infos.InternalItems == null ||
				infos.InternalItems.Count <= 0 )
			{
				return null;
			}
			else
			{
				using ( MemoryStream buf = new MemoryStream() )
				using ( ZipOutputStream zip = new ZipOutputStream( buf ) )
				{
					Crc32 crc = new Crc32();
					zip.SetLevel( 9 );	// 0..9.

					int index = 1;
					foreach ( CompressHeterogenousInfo info in infos.InternalItems )
					{
						// Cancel, if requested.
						if ( progress1 != null )
						{
							if ( progress1.OnProgress( null, EventArgs.Empty ) ==
								CancelMode.Cancel )
							{
								return null;
							}
						}
						// Cancel, if requested.
						if ( progress2 != null )
						{
							if ( progress2() == CancelMode.Cancel )
							{
								return null;
							}
						}

						byte[] buffer = null;
						string fileName = null;
						bool putEntry;

						switch ( info.Type )
						{
							case CompressHeterogenousInfo.InfoType.String:
								fileName = info.FilePath;
								if ( fileName == null || fileName.Length <= 0 )
								{
									fileName =
										string.Format(
										@"file{0}.bin",
										index );
								}

								buffer = Encoding.UTF8.GetBytes( info.Content );

								putEntry = true;
								break;

							case CompressHeterogenousInfo.InfoType.File:
								using ( FileStream fs = new FileStream(
									info.FilePath,
									FileMode.Open,
									FileAccess.Read,
									FileShare.Read ) )
								using ( BinaryReader r = new BinaryReader( fs ) )
								{
									buffer = new byte[fs.Length];
									fs.Read( buffer, 0, buffer.Length );

									fileName = Path.GetFileName( info.FilePath );
								}

								putEntry = false;
								break;

							case CompressHeterogenousInfo.InfoType.Bytes:
								fileName = info.FilePath;
								if ( fileName == null ||
									fileName.Length <= 0 )
								{
									fileName =
										string.Format(
										@"file{0}.bin",
										index );
								}

								buffer = info.Bytes;

								putEntry = true;
								break;

							default:
								Debug.Assert(
									false,
									string.Format(
									@"Unknown compression info type '{0}'.",
									info.Type ) );
								putEntry = false;
								break;
						}

						// --

						if ( putEntry )
						{
							ZipEntry entry = new ZipEntry( fileName );
							entry.DateTime = DateTime.Now;
							entry.Size = buffer.Length;

							crc.Reset();
							crc.Update( buffer );

							entry.Crc = crc.Value;

							zip.PutNextEntry( entry );
							zip.Write( buffer, 0, buffer.Length );
						}

						index++;
					}

					zip.Finish();

					// --

					byte[] c = new byte[buf.Length];
					buf.Seek( 0, SeekOrigin.Begin );
					buf.Read( c, 0, c.Length );

					// --

					zip.Close();

					return c;
				}
			}
		}