Skip to content

Commit

Permalink
fixed isssue with all day event
Browse files Browse the repository at this point in the history
  • Loading branch information
JaySmith committed Jun 11, 2015
1 parent f6a76fe commit c6aa00c
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 12 deletions.
16 changes: 12 additions & 4 deletions Marble/Core/CalendarSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
using System.Collections.Generic;
using System.Linq;

using System.Windows.Forms.VisualStyles;
using System.Xml;
using Google.Apis.Calendar.v3.Data;
using Microsoft.SqlServer.Server;
using Marble.Data;
using Marble.Google;
using Marble.Outlook;
Expand Down Expand Up @@ -41,8 +44,8 @@ public void Sync()
return;
}

List<Appointment> googleAppoinments = googleCalendarService.GetAppointmentsInRange();
List<Appointment> outlookAppoinments = outlookCalendarService.GetAppointmentsInRange();
List<Appointment> googleAppoinments = googleCalendarService.GetAppointmentsInRange();

var comparer = new AppointmentComparer();
// Items in google that are not in outlook should be deleted
Expand All @@ -52,6 +55,11 @@ public void Sync()
// items in outlook that are not in google should be created
var googleItemsToAdd = outlookAppoinments.Except(googleAppoinments, comparer).ToList();
AddOutLookEventsToGoogleCalendar(googleItemsToAdd);

if (Globals.HasError)
{
System.Windows.Forms.MessageBox.Show(Globals.ErrorMessage);
}
}

string[] splitAttendees(string attendees)
Expand Down Expand Up @@ -79,14 +87,14 @@ void AddOutLookEventsToGoogleCalendar(List<Appointment> items)
{
var googleEvent = new Event
{
Start = new EventDateTime(),
End = new EventDateTime(),
//Start = new EventDateTime(),
//End = new EventDateTime(),
Summary = item.Summary,
Location = item.Location,
Description = item.Description,
Attendees = new List<EventAttendee>()
};

var currentTimeZone = TimeZone.CurrentTimeZone;

var startDateTime = new DateTimeOffset(item.Start, currentTimeZone.GetUtcOffset(item.Start));
Expand Down
26 changes: 26 additions & 0 deletions Marble/Core/Globals.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Created by SharpDevelop.
* User: smithjay
* Date: 6/10/2015
* Time: 11:11 AM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;

namespace Marble
{
/// <summary>
/// Description of Globals.
/// </summary>
public static class Globals
{
public static string CalendarAccount {
get { return Properties.Settings.Default.CalendarAccount; }
}

public static bool HasError { get; set; }

public static string ErrorMessage { get; set; }
}
}
39 changes: 32 additions & 7 deletions Marble/Google/GoogleCalendarService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Windows.Forms.VisualStyles;
using Google.Apis.Calendar.v3;
using Google.Apis.Calendar.v3.Data;
using Marble.Data;
Expand All @@ -11,6 +12,8 @@ public class GoogleCalendarService
{
readonly GoogleClient client;
readonly CalendarService service;
readonly Logger Logger = LogFactory.GetLoggerFor(typeof(GoogleCalendarService));


public GoogleCalendarService(GoogleClient googleClient)
{
Expand Down Expand Up @@ -64,13 +67,35 @@ public List<Appointment> GetAppointmentsInRange()

Appointment MapGoogleEventtoAppointment(Event googleEvent)
{
var appointment = new Appointment() {
Id = googleEvent.Id,
Start = (DateTime) googleEvent.Start.DateTime,
End = (DateTime) googleEvent.End.DateTime,
Summary = googleEvent.Summary,
Location = googleEvent.Location
};
var appointment = new Appointment();

try
{
appointment.Id = googleEvent.Id;

if (googleEvent.Start.DateTime == null)
{
appointment.IsAllDayEvent = true;
appointment.Start = DateTime.Parse(googleEvent.Start.Date);
appointment.End = DateTime.Parse(googleEvent.End.Date);
}
else
{
appointment.IsAllDayEvent = false;
appointment.Start = (DateTime) googleEvent.Start.DateTime;
appointment.End = (DateTime) googleEvent.End.DateTime;
}


appointment.Summary = googleEvent.Summary;
appointment.Location = string.IsNullOrEmpty(googleEvent.Location) ? "none" : googleEvent.Location;
}
catch(Exception ex)
{
Globals.HasError = true;
Globals.ErrorMessage = "An error occured while updated Google Calendar. Please see the log file for more details.";
Logger.Fatal(ex.Message, ex);
}

return appointment;
}
Expand Down
1 change: 1 addition & 0 deletions Marble/Marble.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Core\CalendarSync.cs" />
<Compile Include="Core\Globals.cs" />
<Compile Include="Core\LogFactory.cs" />
<Compile Include="Core\Logger.cs" />
<Compile Include="Core\OutookServiceProvider.cs" />
Expand Down
2 changes: 1 addition & 1 deletion Marble/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
[assembly: ComVisible(false)]

// Following Symantic Version http://semver.org/
[assembly: AssemblyVersion("0.0.1.11")]
[assembly: AssemblyVersion("0.0.1.12")]

public class AssemblyInfo
{
Expand Down

0 comments on commit c6aa00c

Please sign in to comment.