コード例 #1
0
		/// <summary>
		/// If VSS conatins $/Project1 but requested $/project1, then case will not be fixed and $/project1 will be retuned.
		/// This methor return case to normal -> $/Project1
		/// </summary>
		/// <param name="item">Item for normalize</param>
		/// <returns>Normalized item</returns>
		public static IVSSItem Normalize(this IVSSItem item, IVSSDatabase db)
		{
			IVSSItem current = db.VSSItem["$/"];

			if (item.Spec.Replace('\\', '/').TrimEnd("/".ToCharArray()) == "$")
				return current;

			foreach (var pathPart in item.Spec.Replace('\\', '/').TrimStart("$/".ToCharArray()).TrimEnd('/').Split('/'))
			{
				IVSSItem next = null;
				foreach (IVSSItem child in current.Items)
				{
					var parts = child.Spec.TrimEnd('/').Split('/');
					var lastPart = parts[parts.Length - 1];

					if(String.Compare(pathPart, lastPart, StringComparison.OrdinalIgnoreCase) == 0)
					{
						next = child;
						break;
					}
				}

				if(next == null)
					throw new ApplicationException("Can't normalize: " + item.Spec);

				current = next;
			}

			return current;
		}
コード例 #2
0
		public void Build(List<FileRevision> versions, Action<float> progress = null)
		{
			var sw = Stopwatch.StartNew();

			_tempDir = Path.Combine(Environment.CurrentDirectory, "vss-temp");
			Directory.CreateDirectory(_tempDir);

			_db = _options.DB.Value;
			var originalVersions = versions.ToList();

			using(_cache = new VssFileCache(_options.CacheDir, _db.SrcSafeIni))
			{
				// filterout cached versions
				if (!_options.Force)
				{
					Console.WriteLine("Skip already cached versions...");

					var cached = 0;
					var notRetained = 0;
					var errors = 0;

					versions.Clear();
					foreach (var file in originalVersions)
					{
						if (_cache.GetFilePath(file.FileSpec, file.VssVersion) != null)
						{
							cached++;
							continue;
						}

						if (!string.IsNullOrWhiteSpace(_cache.GetFileError(file.FileSpec, file.VssVersion)))
						{
							var err = _cache.GetFileError(file.FileSpec, file.VssVersion);

							if (err == "not-retained")
								notRetained++;
							else
								errors++;

							continue;
						}

						versions.Add(file);
					}

					Console.WriteLine("Cached(good): {0}", cached);
					Console.WriteLine("Cached(errors): {0}", errors);
					Console.WriteLine("Cached(not retained version): {0}", notRetained);
					Console.WriteLine("Not Cached: {0}", versions.Count);
				}
				Console.WriteLine();

				// sort versions
				versions = versions
					.GroupBy(f => f.FileSpec)
					// order by versions count. posible you do not want to convert all versions for some autogenerated files
					.OrderBy(g => g.Count())
					// start retrieveing from recent (high versions) to ancient (version 1)
					.SelectMany(g => g.OrderByDescending(v => v.VssVersion))
					.ToList()
				;

				using(_log = File.CreateText(LogFileName))
				{
					_log.AutoFlush = true;

					// cache
					var fileGroups = versions.GroupBy(v => v.FileSpec).ToList();

					for (var j = 0; j < fileGroups.Count; j++)
					{
						var fileGroup = fileGroups[j];

						Console.Write("[{0}/{1}] Get: {3,5} x {2}", j, fileGroups.Count, fileGroup.Key, fileGroup.Count());
						if (progress != null)
							progress((float)j / fileGroups.Count);

						foreach (var fg in fileGroup)
						{
							Process(fg);
						}

						Console.WriteLine();
					}
				}

				// build cached versions list
				BuildCachedVersionsList(originalVersions);
			}

			sw.Stop();

			Console.WriteLine();
			Console.WriteLine("Building cache complete. Take {0}", sw.Elapsed);
		}