Skip to content

Commit

Permalink
disables logging for final version
Browse files Browse the repository at this point in the history
  • Loading branch information
codingadventures committed Apr 2, 2018
1 parent bc6fe23 commit 19d00a2
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 63 deletions.
2 changes: 2 additions & 0 deletions Src/BridgeVs.Locations/CommonRegistryConfigurations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class CommonRegistryConfigurations
private const string LINQPadInstallationPathRegistryValue = "LINQPadInstallationPath";
private const string LINQPadVersionPathRegistryValue = "LINQPadVersion";

// ReSharper disable once InconsistentNaming
public static string LINQPadInstallationPath
{
get
Expand All @@ -25,6 +26,7 @@ public static string LINQPadInstallationPath
}
}

// ReSharper disable once InconsistentNaming
public static string LINQPadVersion
{
get
Expand Down
1 change: 1 addition & 0 deletions Src/DynamicCore/DynamicObjectSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public static void BroadCastData(object target, Stream outgoingData)
catch (Exception e)
{
Log.Write(e, "Error in BroadCastData");
throw;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ public override void GetData(object target, Stream outgoingData)
DynamicObjectSource.BroadCastData(target, outgoingData);
}
}
}
}
7 changes: 3 additions & 4 deletions Src/Grapple/Truck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ public Truck(string truckName)

internal Truck(string truckName, IGrapple grapple)
{
Log.Configure("Grapple", string.Empty);
Log.Write($"Setting Up the Truck {truckName}");

Log.Write("Setting Up the Truck {0}", truckName);
_truckName = truckName;
_grapple = grapple;
CreateDeliveryFolder(TruckPosition);
Expand Down Expand Up @@ -100,7 +99,7 @@ public void LoadCargo<T>(T item)
/// <returns></returns>
public bool DeliverTo(string address)
{
Log.Write("Delivering Cargo to {0}", address);
Log.Write($"Delivering Cargo to {address}");

try
{
Expand All @@ -120,7 +119,7 @@ public bool DeliverTo(string address)
stream.Write(buffer.Item2, 0, buffer.Item2.Length);
}
}
Log.Write("Cargo Successfully Delivered {0}", address);
Log.Write($"Cargo Successfully Delivered {address}");

return true;
}
Expand Down
30 changes: 13 additions & 17 deletions Src/Logging/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#endregion

using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
Expand All @@ -36,43 +37,35 @@ namespace BridgeVs.Logging
public static class Log
{
private static string _applicationName;
private static readonly string LocalApplicationData =
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
private static readonly string LocalApplicationData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

private static readonly MailAddress MailAddressFrom = new MailAddress("linqbridgevs@gmail.com", "No Reply Log");
private static string _logGzipFileName;

private static string _moduleName;
private static string _logsDir;
private static string _logTxtFilePath;
private static SmtpClient _smtpClient;

public static void Configure(string applicationName, string moduleName, SmtpClient smtpClient = null)
[Conditional("DEBUG")]
public static void Configure(string applicationName, string moduleName)
{
if (string.IsNullOrEmpty(applicationName))
throw new ArgumentNullException(nameof(applicationName), "Name of the application must not be null!");

_applicationName = applicationName;
_moduleName = moduleName;

var logTxtFileName = string.Concat(moduleName, ".txt");
string logTxtFileName = string.Concat(moduleName, ".txt");

_logGzipFileName = string.Concat(_applicationName, ".gz");
_logsDir = Path.Combine(LocalApplicationData, _applicationName);

_logTxtFilePath = Path.Combine(_logsDir, logTxtFileName);

_smtpClient = smtpClient;
}

[Conditional("DEBUG")]
public static void Write(Exception ex, string context = null)
{
try
{
var text = string.Concat(ex.GetType().Name, ": ", ex.Message, "\r\n", ex.StackTrace ?? "");
string text = string.Concat(ex.GetType().Name, ": ", ex.Message, "\r\n", ex.StackTrace ?? "");
if (ex.InnerException != null)
{
var text2 = text;
string text2 = text;
text = string.Concat(text2, "\r\nINNER: ", ex.InnerException.GetType().Name, ex.InnerException.Message, (ex.InnerException.StackTrace ?? "").Replace("\n", "\n "));
}
if (!string.IsNullOrEmpty(context))
Expand All @@ -88,16 +81,17 @@ public static void Write(Exception ex, string context = null)
}
}

[Conditional("DEBUG")]
private static void InternalWrite(string msg, params object[] args)
{

if (!Directory.Exists(_logsDir))
{
try
{
var sec = new DirectorySecurity();
DirectorySecurity sec = new DirectorySecurity();
// Using this instead of the "Everyone" string means we work on non-English systems.
var everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
sec.AddAccessRule(new FileSystemAccessRule(everyone, FileSystemRights.Modify | FileSystemRights.Synchronize, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
Directory.CreateDirectory(_logsDir, sec);
}
Expand Down Expand Up @@ -127,6 +121,7 @@ private static void InternalWrite(string msg, params object[] args)
/// <param name="msg">A composite format string (see Remarks) that contains text intermixed with zero or more format items, which correspond to objects in the <paramref name="args"/> array.</param><param name="args">An object array that contains zero or more objects to format. </param>


[Conditional("DEBUG")]
public static void Write(string msg, params object[] args)
{
if (string.IsNullOrEmpty(_applicationName))
Expand All @@ -144,6 +139,7 @@ public static void Write(string msg, params object[] args)
}
}

[Conditional("DEBUG")]
public static void WriteIf(bool condition, string msg, params object[] args)
{
if (!condition) return;
Expand Down
39 changes: 1 addition & 38 deletions Src/VsExtension.Helper/Installer/Welcome.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,44 +31,7 @@ public Welcome(DTE dte) : this()
{
_dte = dte;
}

//private async void BtnNext_Click(object sender, RoutedEventArgs e)
//{
// SetNextTab();
// if (_currentTab.Value.Name == "hdrSteady")
// {
// if (!IsElevated)
// {
// grdPrerequisites.Visibility = Visibility.Visible;
// grdInstallation.Visibility = Visibility.Hidden;
// btnNext.IsEnabled = false;
// }
// else
// {
// grdPrerequisites.Visibility = Visibility.Hidden;
// grdInstallation.Visibility = Visibility.Visible;
// await Task.Run(() => Install());
// prgInstallProgress.IsActive = false;
// SetNextTab();
// btnNext.Visibility = Visibility.Hidden;
// btnSkip.Content = "Finish";
// }
// }

// if (_currentTab.Value.Name == "hdrReady")
// {
// this.Close();
// }
//}

//private void SetNextTab()
//{
// _currentTab.Value.Focusable = false;
// _currentTab = _currentTab.Next ?? _currentTab.List.First;
// _currentTab.Value.Focusable = true;
// _currentTab.Value.Focus();
//}


private void btnRestart_Click(object sender, RoutedEventArgs e)
{
this.Close();
Expand Down
11 changes: 8 additions & 3 deletions Src/VsExtension/Package/BridgeVsPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public sealed class BridgeVsPackage : Microsoft.VisualStudio.Shell.Package

//if this is not null means vs has to restart
private Welcome _welcomePage;
private bool? _installationResult;
public static bool IsElevated => new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);

#region Package Members
Expand Down Expand Up @@ -135,9 +136,7 @@ protected override void Initialize()
}
else
{
MessageBox.Show(!PackageConfigurator.Install(_dte.Version, _dte.Edition)
? "LINQBridgeVs wasn't successfully configured. Please restart Visual Studio"
: "LINQBridgeVs has been successfully configured.");
_installationResult = PackageConfigurator.Install(_dte.Version, _dte.Edition);
}
}
catch (Exception e)
Expand All @@ -150,6 +149,12 @@ protected override void Initialize()
private void _dteEvents_OnStartupComplete()
{
_welcomePage?.Show();
if (_installationResult == null)
return;

MessageBox.Show(_installationResult.Value
? "LINQBridgeVs has been successfully configured."
: "LINQBridgeVs wasn't successfully configured. Please restart Visual Studio");
}
#endregion
}
Expand Down
19 changes: 19 additions & 0 deletions Test/LINQBridgeVs.Test/LINQBridgeVsExtension.UnitTests/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,24 @@
<configuration>
<runtime>

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

<dependentAssembly>

<assemblyIdentity name="Microsoft.VisualStudio.Threading" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />

<bindingRedirect oldVersion="0.0.0.0-15.6.0.0" newVersion="15.6.0.0" />

</dependentAssembly>

<dependentAssembly>

<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />

<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />

</dependentAssembly>

</assemblyBinding>
</runtime>
</configuration>

0 comments on commit 19d00a2

Please sign in to comment.