Skip to content

Commit

Permalink
Merged PR 110: Updated to support null references for target suite co…
Browse files Browse the repository at this point in the history
…nfigurations... #51 for

Updated to support null references for target suite configurations... #51 for the wim...
  • Loading branch information
MrHinsh committed Aug 22, 2017
1 parent 23e6fd3 commit 94707ac
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 20 deletions.
58 changes: 45 additions & 13 deletions src/VstsSyncMigrator.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ class RunOptions
public string ConfigFile { get; set; }
}

static DateTime startTime = DateTime.Now;
static Stopwatch mainTimer = new Stopwatch();


public static int Main(string[] args)
{
Telemetry.Current.TrackEvent("ApplicationStart");
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
DateTime startTime = DateTime.Now;
Stopwatch mainTimer = new Stopwatch();
mainTimer.Start();
Telemetry.Current.TrackEvent("ApplicationStart");
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
/////////////////////////////////////////////////
string logsPath = CreateLogsPath();
//////////////////////////////////////////////////
Expand Down Expand Up @@ -113,6 +115,7 @@ public static int Main(string[] args)
return result;
}


private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
ExceptionTelemetry excTelemetry = new ExceptionTelemetry((Exception)e.ExceptionObject);
Expand Down Expand Up @@ -173,16 +176,39 @@ private static object RunInitAndReturnExitCode(InitOptions opts)

private static Version GetLatestVersion()
{
DateTime startTime = DateTime.Now;
Stopwatch mainTimer = new Stopwatch();
mainTimer.Start();
//////////////////////////////////
string packageID = "vsts-sync-migrator";

//Connect to the official package repository
IPackageRepository repo = PackageRepositoryFactory.Default.CreateRepository("https://chocolatey.org/api/v2/");
var version = repo.FindPackagesById(packageID).Max(p => p.Version);
SemanticVersion version = null;
bool sucess = false;
try
{
//Connect to the official package repository
IPackageRepository repo = PackageRepositoryFactory.Default.CreateRepository("https://chocolatey.org/api/v2/");
version = repo.FindPackagesById(packageID).Max(p => p.Version);
sucess = true;
}
catch (Exception ex)
{
Telemetry.Current.TrackException(ex);
sucess = false;
}
/////////////////
mainTimer.Stop();
Telemetry.Current.TrackDependency(new DependencyTelemetry("PackageRepository", "chocolatey.org", "vsts-sync-migrator", version.ToString(), startTime, mainTimer.Elapsed, null, sucess));
return new Version(version.ToString());
}

private static bool IsOnline()
{
DateTime startTime = DateTime.Now;
Stopwatch mainTimer = new Stopwatch();
mainTimer.Start();
//////////////////////////////////
bool isOnline = false;
string responce = "none";
try
{
Ping myPing = new Ping();
Expand All @@ -191,18 +217,24 @@ private static bool IsOnline()
int timeout = 1000;
PingOptions pingOptions = new PingOptions();
PingReply reply = myPing.Send(host, timeout, buffer, pingOptions);
responce = reply.Status.ToString();
if (reply.Status == IPStatus.Success)
{
return true;
isOnline = true;
}
return false;
isOnline= false;
}
catch (Exception)
catch (Exception ex)
{
// Likley no network is even available
return false;
Telemetry.Current.TrackException(ex);
responce = "error";
isOnline = false;
}

/////////////////
mainTimer.Stop();
Telemetry.Current.TrackDependency(new DependencyTelemetry("Ping","GoogleDNS", "IsOnline", null, startTime, mainTimer.Elapsed, responce, true));
return isOnline;
}

private static string CreateLogsPath()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,10 @@ private void ApplyConfigurations(ITestSuiteBase source, ITestSuiteBase target)

private void ApplyConfigurations(ITestSuiteEntry sourceEntry, ITestSuiteEntry targetEntry)
{
if (sourceEntry.Configurations != null)
{
if (sourceEntry.Configurations.Count != targetEntry.Configurations.Count)
int SourceConfigCount = sourceEntry.Configurations != null ? sourceEntry.Configurations.Count : 0;
int TargetConfigCount = targetEntry.Configurations != null ? targetEntry.Configurations.Count : 0;

if (SourceConfigCount != TargetConfigCount)
{
Trace.WriteLine(string.Format(" CONFIG MNISSMATCH FOUND --- FIX AATTEMPTING"), "TestPlansAndSuites");
targetEntry.Configurations.Clear();
Expand All @@ -279,14 +280,14 @@ private void ApplyConfigurations(ITestSuiteEntry sourceEntry, ITestSuiteEntry ta
{
targetEntry.SetConfigurations(targetConfigs);
}
catch (Exception)
catch (Exception ex)
{
// SOmetimes this will error out for no reason.
// SOmetimes this will error out for no reason.
Telemetry.Current.TrackException(ex);
}

}

}

}

private bool HasChildTestCases(ITestSuiteBase sourceSuit)
Expand Down

0 comments on commit 94707ac

Please sign in to comment.