Skip to content

Commit

Permalink
Gots the repos going on
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtobin committed Feb 24, 2012
1 parent 656f977 commit e918957
Show file tree
Hide file tree
Showing 18 changed files with 5,357 additions and 37 deletions.
Binary file added libs/Castle.Core.dll
Binary file not shown.
4,927 changes: 4,927 additions & 0 deletions libs/Castle.Core.xml

Large diffs are not rendered by default.

Binary file added libs/VSTOContrib.Extensions.Proxies.dll
Binary file not shown.
Binary file not shown.
27 changes: 19 additions & 8 deletions src/GithubForOutlook.Logic/AddinBootstrapper.cs
@@ -1,8 +1,11 @@
using System;
using Autofac;
using Autofac;
using GithubForOutlook.Logic.Repositories;
using GithubForOutlook.Logic.Repositories.Interfaces;
using GithubForOutlook.Logic.Ribbons.Task;
using GithubForOutlook.Logic.Ribbons.Email;
using GithubForOutlook.Logic.Ribbons.MainExplorer;
using GithubForOutlook.Logic.Ribbons.MainExplorer;
using Microsoft.Office.Interop.Outlook;
using NGitHub;
using NGitHub.Authentication;
using VSTOContrib.Core.RibbonFactory.Interfaces;
Expand All @@ -13,16 +16,16 @@ public class AddinBootstrapper : IDisposable
{
private readonly IContainer container;

public AddinBootstrapper()
public AddinBootstrapper(NameSpace nameSpace)
{
var containerBuilder = new ContainerBuilder();

RegisterComponents(containerBuilder);
RegisterComponents(containerBuilder, nameSpace);

container = containerBuilder.Build();
container = containerBuilder.Build();
}

private static void RegisterComponents(ContainerBuilder containerBuilder)
private static void RegisterComponents(ContainerBuilder containerBuilder, NameSpace nameSpace)
{
var assembly = typeof (GithubTask).Assembly;

Expand All @@ -33,7 +36,15 @@ private static void RegisterComponents(ContainerBuilder containerBuilder)
containerBuilder.RegisterType<GitHubOAuthAuthorizer>()
.AsImplementedInterfaces();
containerBuilder.RegisterType<GitHubClient>()
.AsImplementedInterfaces();
.AsImplementedInterfaces();

containerBuilder.RegisterType<OutlookDispatchingRepository>()
.As<IOutlookRepository>();

containerBuilder.RegisterType<GithubRepository>()
.As<IGithubRepository>();

containerBuilder.Register(c => nameSpace);

containerBuilder.RegisterType<GithubMailItem>()
.As<IRibbonViewModel>()
Expand All @@ -45,7 +56,7 @@ private static void RegisterComponents(ContainerBuilder containerBuilder)

containerBuilder.RegisterType<GithubExplorerRibbon>()
.As<IRibbonViewModel>()
.AsSelf();
.AsSelf();
}

public object Resolve(Type type)
Expand Down
15 changes: 15 additions & 0 deletions src/GithubForOutlook.Logic/GithubForOutlook.Logic.csproj
Expand Up @@ -39,6 +39,9 @@
<Reference Include="Autofac.Configuration">
<HintPath>..\packages\Autofac.2.5.2.830\lib\NET40\Autofac.Configuration.dll</HintPath>
</Reference>
<Reference Include="Castle.Core">
<HintPath>..\..\libs\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Office.Interop.Outlook, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
Expand Down Expand Up @@ -70,17 +73,29 @@
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="VSTOContrib.Core, Version=0.9.0.67, Culture=neutral, processorArchitecture=MSIL" />
<Reference Include="VSTOContrib.Extensions.Proxies">
<HintPath>..\..\libs\VSTOContrib.Extensions.Proxies.dll</HintPath>
</Reference>
<Reference Include="VSTOContrib.Outlook, Version=0.9.0.67, Culture=neutral, processorArchitecture=MSIL" />
<Reference Include="VSTOContrib.Outlook.Extensions.Proxies">
<HintPath>..\..\libs\VSTOContrib.Outlook.Extensions.Proxies.dll</HintPath>
</Reference>
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="AddinBootstrapper.cs" />
<Compile Include="GithubTaskAdapter.cs" />
<Compile Include="Models\ApplicationSettings.cs" />
<Compile Include="Models\GithubIssue.cs" />
<Compile Include="Models\User.cs" />
<Compile Include="Modules\Notifications\NotificationsViewModel.cs" />
<Compile Include="Modules\Settings\SettingsViewModel.cs" />
<Compile Include="Modules\Tasks\TasksViewModel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Repositories\GithubRepository.cs" />
<Compile Include="Repositories\Interfaces\IGithubRepository.cs" />
<Compile Include="Repositories\Interfaces\IOutlookRepository.cs" />
<Compile Include="Repositories\OutlookDispatchingRepository.cs" />
<Compile Include="Ribbons\MainExplorer\GithubExplorerRibbon.cs" />
<Compile Include="Ribbons\Task\GithubTask.cs" />
<Compile Include="Ribbons\Task\GithubTaskPanel.xaml.cs">
Expand Down
49 changes: 40 additions & 9 deletions src/GithubForOutlook.Logic/GithubTaskAdapter.cs
@@ -1,11 +1,12 @@
using Microsoft.Office.Interop.Outlook;
using System;
using Microsoft.Office.Interop.Outlook;
using VSTOContrib.Outlook;

namespace GithubForOutlook.Logic
{
public class GithubTaskAdapter
{
private const string Githubissueid = "GithubIssueId";
public const string Githubissueid = "GithubIssueId";
private readonly TaskItem outlookTask;
private bool? isGithubTask;

Expand All @@ -24,18 +25,48 @@ public bool IsGithubTask
}
return isGithubTask.Value;
}
set
{
isGithubTask = value;
outlookTask.SetPropertyValue(Githubissueid, OlUserPropertyType.olInteger, value, true);
}
}

private bool CheckIfGithubTask()
{
var issueId = outlookTask.GetPropertyValue(Githubissueid, OlUserPropertyType.olInteger, false, o=>(int?)o, null);
var issueId = outlookTask.GetPropertyValue(Githubissueid, OlUserPropertyType.olText, false, o=>string.IsNullOrWhiteSpace(o.ToString()), false);

return issueId;
}

public string TaskId
{
get
{
return outlookTask.GetPropertyValue(Githubissueid, OlUserPropertyType.olText, false, (o) => o.ToString(), null);
}
set
{
outlookTask.SetPropertyValue(Githubissueid, OlUserPropertyType.olText, value.ToString(), true);
}
}

public string Title
{
get { return outlookTask.Subject; }
set { outlookTask.Subject = value; }
}

public string Body
{
get { return outlookTask.Body; }
set { outlookTask.Body = value; }
}

public OlTaskStatus Status
{
get { return outlookTask.Status; }
set { outlookTask.Status = value; }
}

return issueId != null;
public DateTime LastModified
{
get { return outlookTask.LastModificationTime; }
}
}
}
13 changes: 13 additions & 0 deletions src/GithubForOutlook.Logic/Models/ApplicationSettings.cs
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GithubForOutlook.Logic.Models
{
public class ApplicationSettings
{
public User User { get; set; }

}
}
17 changes: 17 additions & 0 deletions src/GithubForOutlook.Logic/Models/GithubIssue.cs
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GithubForOutlook.Logic.Models
{
public class GithubIssue
{
public string TaskId { get; set; }

public string Title { get; set; }
public string Body { get; set; }

public DateTime LastModified { get; set; }
}
}
113 changes: 113 additions & 0 deletions src/GithubForOutlook.Logic/Repositories/GithubRepository.cs
@@ -0,0 +1,113 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GithubForOutlook.Logic.Repositories.Interfaces;
using NGitHub;
using NGitHub.Models;
using NGitHub.Services;
using NGitHub.Web;
using RestSharp;

namespace GithubForOutlook.Logic.Repositories
{
public class GithubRepository : IGithubRepository
{
private GitHubClient client;
private readonly Action<GitHubException> _exceptionAction = ex => Console.WriteLine("Error: " + Enum.GetName(typeof(ErrorType), ex.ErrorType), "");

private string _password;
private string _username;
public void Login(string username, string password)
{
_username = username;
_password = password;
client = new GitHubClient
{
Authenticator = new HttpBasicAuthenticator(_username, _password)
};
}

public Task<User> GetUser()
{
return NGitHub<User>(client.Users.GetAuthenticatedUserAsync);
}

public Task<IEnumerable<User>> GetOrganisations(string username, int page = 0)
{
return NGitHub<IEnumerable<User>, string, int>(client.Organizations.GetOrganizationsAsync, username, page);
}

public Task<IEnumerable<Repository>> GetProjects(Models.User user, int page = 0)
{
//if (user.IsOrganisation)
// return NGitHub<IEnumerable<Repository>, string, int, RepositoryTypes>(_client.Organizations., user.Username, page, RepositoryTypes.Member);
//else
return NGitHub<IEnumerable<Repository>, string, int, RepositoryTypes>(client.Repositories.GetRepositoriesAsync, user.Name, page, RepositoryTypes.All);
}

public Task<Issue> CreateIssue(string username, string reponame, string title, string body, string assigneename,
string milestone, string[] labels)
{
return NGitHub<Issue, string, string, string, string, string, string, string[]>(client.Issues.CreateIssueAsync, username, reponame, title, body, assigneename, milestone, labels);
}

public Task<IEnumerable<Issue>> GetIssues(string username, string reponame, State state = State.Open,
int page = 0)
{
return NGitHub<IEnumerable<Issue>, string, string, State, int>(client.Issues.GetIssuesAsync, username,
reponame, state, page);
}

private Task<T> NGitHub<T>(Func<Action<T>, Action<Exception>, GitHubRequestAsyncHandle> call)
{
var completionSource = new TaskCompletionSource<T>();
call(completionSource.SetResult, completionSource.SetException);
return completionSource.Task;
}

private Task<T> NGitHub<T, TArg>(Func<TArg, Action<T>, Action<Exception>, GitHubRequestAsyncHandle> call,
TArg t1)
{
var completionSource = new TaskCompletionSource<T>();
call(t1, completionSource.SetResult, completionSource.SetException);
return completionSource.Task;
}

private Task<T> NGitHub<T, TArg, TArg2>(
Func<TArg, TArg2, Action<T>, Action<Exception>, GitHubRequestAsyncHandle> call, TArg t1, TArg2 t2)
{
var completionSource = new TaskCompletionSource<T>();
call(t1, t2, completionSource.SetResult, completionSource.SetException);
return completionSource.Task;
}

private Task<T> NGitHub<T, TArg, TArg2, TArg3>(
Func<TArg, TArg2, TArg3, Action<T>, Action<Exception>, GitHubRequestAsyncHandle> call, TArg t1, TArg2 t2,
TArg3 t3)
{
var completionSource = new TaskCompletionSource<T>();
call(t1, t2, t3, completionSource.SetResult, completionSource.SetException);
return completionSource.Task;
}

private Task<T> NGitHub<T, TArg, TArg2, TArg3, TArg4>(
Func<TArg, TArg2, TArg3, TArg4, Action<T>, Action<Exception>, GitHubRequestAsyncHandle> call, TArg t1,
TArg2 t2, TArg3 t3, TArg4 t4)
{
var completionSource = new TaskCompletionSource<T>();
call(t1, t2, t3, t4, completionSource.SetResult, completionSource.SetException);
return completionSource.Task;
}

private Task<T> NGitHub<T, TArg, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7>(
Func<TArg, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, Action<T>, Action<Exception>, GitHubRequestAsyncHandle> call, TArg t1,
TArg2 t2, TArg3 t3, TArg4 t4, TArg5 t5, TArg6 t6, TArg7 t7)
{
var completionSource = new TaskCompletionSource<T>();
call(t1, t2, t3, t4, t5, t6, t7, completionSource.SetResult, completionSource.SetException);
return completionSource.Task;
}
}
}
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NGitHub.Models;

namespace GithubForOutlook.Logic.Repositories.Interfaces
{
public interface IGithubRepository
{
Task<User> GetUser();
Task<IEnumerable<User>> GetOrganisations(string username, int page = 0);
Task<IEnumerable<Repository>> GetProjects(Models.User user, int page = 0);

Task<Issue> CreateIssue(string username, string reponame, string title, string body, string assigneename,
string milestone, string[] labels);

Task<IEnumerable<Issue>> GetIssues(string username, string reponame, State state = State.Open, int page = 0);

void Login(string username, string password);
}
}
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GithubForOutlook.Logic.Models;

namespace GithubForOutlook.Logic.Repositories.Interfaces
{
public interface IOutlookRepository
{
IList<GithubIssue> GetIssues();
IList<GithubIssue> GetModifiedIssues(DateTime since);
void SaveIssue(GithubIssue issue);
void SaveIssues(IList<GithubIssue> issues);
}
}

0 comments on commit e918957

Please sign in to comment.