Skip to content

Commit

Permalink
Merge pull request #14 from solarwinds/Madhavan-OrionSDK
Browse files Browse the repository at this point in the history
Madhavan orion sdk
  • Loading branch information
tdanner committed Nov 4, 2015
2 parents ca9da3f + 54f521a commit f8ae116
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Src/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Reflection;

[assembly: AssemblyCompany("SolarWinds, Inc.")]
[assembly: AssemblyCompany("SolarWinds.")]
[assembly: AssemblyCopyright("Copyright © 2015 SolarWinds Worldwide, LLC. All rights reserved.")]
69 changes: 68 additions & 1 deletion Src/SwqlStudio/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.Windows.Forms;
using SwqlStudio.Properties;
using System.IO;
using System.Configuration;
using System.Linq;

namespace SwqlStudio
{
Expand All @@ -17,10 +20,16 @@ static void Main()
SolarWinds.Logging.Log.Configure(string.Empty);

AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException;

if (Settings.Default.UpdateRequired)
{
Settings.Default.Upgrade();

if (string.IsNullOrWhiteSpace(Settings.Default.PreviousServers))
{
SearchAndCopyLastUserConfig(new Version(Application.ProductVersion));
Settings.Default.Reload();
}

Settings.Default.UpdateRequired = false;
}

Expand All @@ -34,5 +43,63 @@ static void CurrentDomainUnhandledException(object sender, UnhandledExceptionEve
if (e.ExceptionObject is Exception)
log.Error("Unhandled exception", (Exception)e.ExceptionObject);
}

private static void SearchAndCopyLastUserConfig(Version currentVersion)
{
try
{
string userConfigFileName = "user.config";

// Expected location of the current user config
DirectoryInfo currentVersionConfigFileDir = new FileInfo(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath).Directory;
if (currentVersionConfigFileDir != null)
{
if (!currentVersionConfigFileDir.Exists)
currentVersionConfigFileDir.Create();

//1. Look for previous version with the same .net version
// grab the most recent folder from the list of user's settings folders, prior to the current version
var previousSettingsDir = (from dir in currentVersionConfigFileDir.Parent.EnumerateDirectories()
let dirVer = new { Dir = dir, Ver = new Version(dir.Name) }
where dirVer.Ver < currentVersion
orderby dirVer.Ver descending
select dir).FirstOrDefault();

if (previousSettingsDir != null)
{
CopyUserConfigSettings(currentVersion, userConfigFileName, currentVersionConfigFileDir, previousSettingsDir);
}
//2. If not present look for older version with different .net version
else
{
// grab the most recent folder from the list of user's settings folders, prior to the current version
previousSettingsDir = (from dir in currentVersionConfigFileDir.Parent.Parent.EnumerateDirectories("????.????.????.????", SearchOption.AllDirectories)
let dirVer = new { Dir = dir, Ver = new Version(dir.Name) }
where dirVer.Ver < currentVersion && dir.Parent.Name.ToLower().Contains("swqlstudio")
orderby dirVer.Ver descending
select dir).FirstOrDefault();

CopyUserConfigSettings(currentVersion, userConfigFileName, currentVersionConfigFileDir, previousSettingsDir);
}
}
}
catch (Exception ex)
{
log.Error("An error occurred while trying to upgrade user specific settings for the new version.", ex);
}
}

private static void CopyUserConfigSettings(Version currentVersion, string userConfigFileName, DirectoryInfo currentVersionConfigFileDir, DirectoryInfo previousSettingsDir)
{
string previousVersionConfigFile = string.Concat(previousSettingsDir.FullName, @"\", userConfigFileName);
string currentVersionConfigFile = string.Concat(currentVersionConfigFileDir.FullName, @"\", userConfigFileName);

if (!currentVersionConfigFileDir.Exists)
{
Directory.CreateDirectory(currentVersionConfigFileDir.FullName);
}

File.Copy(previousVersionConfigFile, currentVersionConfigFile, true);
}
}
}
1 change: 1 addition & 0 deletions Src/SwqlStudio/SwqlStudio.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<HintPath>.\Security.Cryptography.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
Expand Down

0 comments on commit f8ae116

Please sign in to comment.