Skip to content
This repository has been archived by the owner on Jan 31, 2023. It is now read-only.

Commit

Permalink
Merge pull request #42 from GDKsoftware/41
Browse files Browse the repository at this point in the history
41
  • Loading branch information
cmgeuze authored Jul 10, 2017
2 parents ffee854 + 884c8c6 commit e6b8664
Show file tree
Hide file tree
Showing 16 changed files with 281 additions and 83 deletions.
6 changes: 3 additions & 3 deletions GitBitter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
using GitBitterLib;
using Microsoft.Practices.Unity;

class Program
public class Program
{
static void Main(string[] args)
public static void Main(string[] args)
{
GitBitterContainer.Default.RegisterType<ICloner, GitSharpCloner>();

Expand All @@ -19,7 +19,7 @@ static void Main(string[] args)
GitBitterContainer.Default.RegisterType<ICredentialManager, CredentialManagerWindows>();
GitBitterContainer.Default.RegisterType<IIniFile, IniFileWindows>();
GitBitterContainer.Default.RegisterType<IGitFilesAndFolders, GitFilesAndFoldersWindows>();
GitBitterContainer.Default.RegisterType<IGitBitterLogging, GitBitterLoggingCommandLine>();
GitBitterContainer.Default.RegisterType<IGitBitterLogging, GitBitterLoggingCommandLine>();
#endif

try
Expand Down
8 changes: 8 additions & 0 deletions GitBitterEdit/GitBitterEdit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@
<Compile Include="GitConfigEdit.xaml.cs">
<DependentUpon>GitConfigEdit.xaml</DependentUpon>
</Compile>
<Compile Include="LoggingForm.xaml.cs">
<DependentUpon>LoggingForm.xaml</DependentUpon>
</Compile>
<Compile Include="LoggingUI.cs" />
<Compile Include="LoginForm.xaml.cs">
<DependentUpon>LoginForm.xaml</DependentUpon>
</Compile>
Expand All @@ -122,6 +126,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="LoggingForm.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="LoginForm.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
12 changes: 12 additions & 0 deletions GitBitterEdit/LoggingForm.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Window x:Name="FrmLogging" x:Class="GitBitterEdit.LoggingForm"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:GitBitterEdit"
mc:Ignorable="d"
Title="Logging" Height="300" Width="300">
<Grid>
<ListBox x:Name="listBox"/>
</Grid>
</Window>
34 changes: 34 additions & 0 deletions GitBitterEdit/LoggingForm.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace GitBitterEdit
{
/// <summary>
/// Interaction logic for LoggingForm.xaml
/// </summary>
public partial class LoggingForm : Window
{
public LoggingForm()
{
InitializeComponent();
}

public void SetList(IEnumerable ASource)
{
listBox.ItemsSource = null;
listBox.ItemsSource = ASource;
}
}
}
61 changes: 61 additions & 0 deletions GitBitterEdit/LoggingUI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
namespace GitBitterEdit
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GitBitterLib;
using System.Threading;
using System.Windows;

public class LoggingUI : IGitBitterLogging
{
private LoggingForm form = null;
private List<string> collectedLogging = null;
private TaskScheduler mainThreadScheduler = null;

public LoggingUI(TaskScheduler AMainThreadScheduler)
{
collectedLogging = new List<string>();

mainThreadScheduler = AMainThreadScheduler;

form = new LoggingForm();

Application.Current.MainWindow.Closed += (object sender, EventArgs e) =>
{
if (form != null) form.Close();
};
}

private void ExecuteInMainContext(Action action)
{
Task task = new Task(action);
task.Start(mainThreadScheduler);
}

public void Add(string AMessage, LoggingLevel ALevel, string AModule)
{
collectedLogging.Add("[" + AModule + "] " + AMessage.Trim());

ExecuteInMainContext(() =>
{
if (!form.IsVisible)
{
try
{
form.Show();
}
catch (Exception)
{
form = new LoggingForm();
form.Show();
}
}
form.SetList(collectedLogging);
});
}
}
}
28 changes: 18 additions & 10 deletions GitBitterEdit/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public MainWindow()
GitBitterContainer.Default.RegisterType<IIniFile, IniFileWindows>();
GitBitterContainer.Default.RegisterType<IGitFilesAndFolders, GitFilesAndFoldersWindows>();
GitBitterContainer.Default.RegisterType<ICredentialUI, CredentialUIWindows>();
GitBitterContainer.Default.RegisterType<IGitBitterLogging, GitBitterLoggingVoid>();
GitBitterContainer.Default.RegisterInstance<IGitBitterLogging>(new LoggingUI(TaskScheduler.FromCurrentSynchronizationContext())); // use as singleton and create form in mainthread
#endif

settingsPath = Environment.CurrentDirectory;
Expand Down Expand Up @@ -71,15 +71,23 @@ private void btnUpdateAll_Click(object sender, RoutedEventArgs e)
Cursor = Cursors.Wait;
try
{
var cloner = new PackageUnwrapper(config.Filename);
try
{
cloner.StartAndWaitForUnwrapping();
}
catch (Exception ex)
var logging = GitBitterContainer.Default.Resolve<IGitBitterLogging>();
logging.Add("Updating", LoggingLevel.Info, "GitBitter");

new Task(() =>
{
MessageBox.Show(ex.Message + "\n\n" + ex.InnerException.Message + "\n\n" + ex.InnerException.StackTrace);
}
var cloner = new PackageUnwrapper(config.Filename);
try
{
cloner.StartAndWaitForUnwrapping();
}
catch (Exception ex)
{
var errormessage = ex.Message + "\n\n" + ex.InnerException.Message + "\n\n" + ex.InnerException.StackTrace;
logging.Add(errormessage, LoggingLevel.Info, "GitBitter");
MessageBox.Show(errormessage);
}
}).Start();
}
finally
{
Expand Down Expand Up @@ -121,7 +129,7 @@ private void AddPackage(RepositoryDescription repo)
var package = new Package();
package.Repository = repo.URL;
package.Folder = repo.Name;
if (!String.IsNullOrEmpty(repo.DefaultBranch))
if (!string.IsNullOrEmpty(repo.DefaultBranch))
{
package.Branch = repo.DefaultBranch;
}
Expand Down
2 changes: 1 addition & 1 deletion GitBitterEdit/RepoSelect.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private void RefreshTeams()

edTeam.ItemsSource = this.repoLister.GetTeams();

if (currentSelection != "")
if (currentSelection != string.Empty)
{
var idx = edTeam.Items.IndexOf(currentSelection);
if (idx != -1)
Expand Down
20 changes: 9 additions & 11 deletions GitBitterLib/GitBitterLoggingVoid.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
namespace GitBitterLib
{
using System;
public class GitBitterLoggingVoid : IGitBitterLogging
{
public GitBitterLoggingVoid()
{
}

public class GitBitterLoggingVoid : IGitBitterLogging
{
public GitBitterLoggingVoid()
{
}

public void Add(string AMessage, LoggingLevel ALevel)
{
}
}
public void Add(string message, LoggingLevel level, string module)
{
}
}
}
2 changes: 1 addition & 1 deletion GitBitterLib/Implementations/BitbucketLister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public List<string> GetTeams()
sharpBucket = new SharpBucketV2();
if (Login())
{
var endpoint = sharpBucket.TeamsEndPoint("");
var endpoint = sharpBucket.TeamsEndPoint(string.Empty);
foreach (var team in endpoint.GetUserTeams())
{
teamnames.Add(team.username);
Expand Down
2 changes: 1 addition & 1 deletion GitBitterLib/Implementations/CredentialManagerPlainText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public Credential ReadCredential(string applicationName)
var username = ini.IniReadValue(applicationName, "username");
var password = ini.IniReadValue(applicationName, "password");

if ((username == "") && (password == ""))
if ((username == string.Empty) && (password == string.Empty))
{
return null;
}
Expand Down
6 changes: 3 additions & 3 deletions GitBitterLib/Implementations/GitBitterLoggingCommandLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ public GitBitterLoggingCommandLine()
{
}

public void Add(string AMessage, LoggingLevel ALevel)
public void Add(string message, LoggingLevel level, string module)
{
if (ALevel != LoggingLevel.Debugging)
if (level != LoggingLevel.Debugging)
{
Console.WriteLine(AMessage);
Console.WriteLine("[" + module + "] " + message);
}
}
}
Expand Down
Loading

0 comments on commit e6b8664

Please sign in to comment.