Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sharepoint synchronization functionality #763

Merged
merged 16 commits into from
Feb 13, 2020
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Platforms>AnyCPU;x64</Platforms>
ShilovSS marked this conversation as resolved.
Show resolved Hide resolved
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace Arcadia.Assistant.Calendar.Abstractions
{
using System.Linq;

public class CalendarEvent
ShilovSS marked this conversation as resolved.
Show resolved Hide resolved
{
public CalendarEvent(
string eventId,
string type,
DatesPeriod dates,
string status,
string employeeId,
CalendarEventAdditionalDataEntry[]? additionalData = null)
{
this.EventId = eventId;
this.Dates = dates;
this.Status = status;
this.Type = type;
this.EmployeeId = employeeId;
this.AdditionalData = additionalData ?? new CalendarEventAdditionalDataEntry[0];
this.IsPending = new CalendarEventStatuses().PendingForType(type).Contains(status);
}

public string EventId { get; }

public DatesPeriod Dates { get; }

public string Status { get; }

public string Type { get; }

public bool IsPending { get; }

public string EmployeeId { get; }

public CalendarEventAdditionalDataEntry[] AdditionalData { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Arcadia.Assistant.Calendar.Abstractions
{
public class CalendarEventAdditionalDataEntry
{
public CalendarEventAdditionalDataEntry(string key, string value)
{
this.Key = key;
this.Value = value;
}

public string Key { get; }

public string Value { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
namespace Arcadia.Assistant.Calendar.Abstractions
{
using System.Collections.Generic;

public class CalendarEventStatuses
{
private static readonly IReadOnlyDictionary<string, string[]> StatusesByType = new Dictionary<string, string[]>
{
{ CalendarEventTypes.Dayoff, WorkHoursChangeStatuses.All },
{ CalendarEventTypes.Workout, WorkHoursChangeStatuses.All },
{ CalendarEventTypes.Sickleave, SickLeaveStatuses.All },
{ CalendarEventTypes.Vacation, VacationStatuses.All }
};

private static readonly IReadOnlyDictionary<string, string[]> PendingStatusesByType = new Dictionary<string, string[]>
{
{ CalendarEventTypes.Dayoff, WorkHoursChangeStatuses.Pending },
{ CalendarEventTypes.Workout, WorkHoursChangeStatuses.Pending },
{ CalendarEventTypes.Sickleave, SickLeaveStatuses.Pending },
{ CalendarEventTypes.Vacation, VacationStatuses.Pending }
};

private static readonly IReadOnlyDictionary<string, string[]> ActualStatusesByType = new Dictionary<string, string[]>
{
{ CalendarEventTypes.Dayoff, WorkHoursChangeStatuses.Actual },
{ CalendarEventTypes.Workout, WorkHoursChangeStatuses.Actual },
{ CalendarEventTypes.Sickleave, SickLeaveStatuses.Actual },
{ CalendarEventTypes.Vacation, VacationStatuses.Actual }
};

private static readonly IReadOnlyDictionary<string, string> ApprovedStatusByType = new Dictionary<string, string>
{
{ CalendarEventTypes.Dayoff, WorkHoursChangeStatuses.Approved },
{ CalendarEventTypes.Workout, WorkHoursChangeStatuses.Approved },
{ CalendarEventTypes.Vacation, VacationStatuses.Approved }
};

private static readonly IReadOnlyDictionary<string, string> RejectedStatusByType = new Dictionary<string, string>
{
{ CalendarEventTypes.Dayoff, WorkHoursChangeStatuses.Rejected },
{ CalendarEventTypes.Workout, WorkHoursChangeStatuses.Rejected },
{ CalendarEventTypes.Vacation, VacationStatuses.Rejected }
};

private static readonly IReadOnlyDictionary<string, string> CancelledStatusByType = new Dictionary<string, string>
{
{ CalendarEventTypes.Dayoff, WorkHoursChangeStatuses.Cancelled },
{ CalendarEventTypes.Workout, WorkHoursChangeStatuses.Cancelled },
{ CalendarEventTypes.Sickleave, SickLeaveStatuses.Cancelled },
{ CalendarEventTypes.Vacation, VacationStatuses.Cancelled }
};

public string[] AllForType(string type)
{
if (StatusesByType.TryGetValue(type, out var statuses))
{
return statuses;
}

return new string[0];
}

public string[] PendingForType(string type)
{
if (PendingStatusesByType.TryGetValue(type, out var statuses))
{
return statuses;
}

return new string[0];
}

public string[] ActualForType(string type)
{
if (ActualStatusesByType.TryGetValue(type, out var statuses))
{
return statuses;
}

return new string[0];
}

public string? ApprovedForType(string type)
{
if (ApprovedStatusByType.TryGetValue(type, out var status))
{
return status;
}

return null;
}

public string? RejectedForType(string type)
{
if (RejectedStatusByType.TryGetValue(type, out var status))
{
return status;
}

return null;
}

public string? CancelledForType(string type)
{
if (CancelledStatusByType.TryGetValue(type, out var status))
{
return status;
}

return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace Arcadia.Assistant.Calendar.Abstractions
{
using System;
using System.Linq;

public static class CalendarEventTypes
{
public const string Vacation = "Vacation";

public const string Dayoff = "Dayoff";

public const string Workout = "Workout";

public const string Sickleave = "Sickleave";

public static readonly string[] All = { Vacation, Dayoff, Workout, Sickleave };

public static bool IsKnownType(string x)
{
return All.Contains(x, StringComparer.InvariantCultureIgnoreCase);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Arcadia.Assistant.Calendar.Abstractions
{
using System;

public static class CspCalendarEventIdParser
{
public static int GetCspIdFromCalendarEvent(string calendarEventId, string calendarEventType)
{
var parts = calendarEventId.Split('_');

if (parts.Length != 2 || parts[0] != calendarEventType || !int.TryParse(parts[1], out var cspId))
{
throw new ArgumentException("Calendar event id has wrong format");
}

return cspId;
}

public static string GetCalendarEventIdFromCspId(int cspId, string calendarEventType)
{
return $"{calendarEventType}_{cspId}";
}

public static string GetCalendarEventIdFromCspId(Guid cspId, string calendarEventType)
{
return $"{calendarEventType}_{cspId}";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
namespace Arcadia.Assistant.Calendar.Abstractions
{
using System;

public sealed class DatesPeriod
{
public DatesPeriod(DateTime startDate, DateTime endDate, int startWorkingHour = 0, int finishWorkingHour = 8)
{
this.StartDate = MinDate(startDate, endDate);
this.EndDate = MaxDate(startDate, endDate);
this.StartWorkingHour = Math.Min(startWorkingHour, finishWorkingHour);
this.FinishWorkingHour = Math.Max(startWorkingHour, finishWorkingHour);
}

public DateTime StartDate { get; }

public DateTime EndDate { get; }

/// <summary>
/// Starting working hour index. Typically, 0 or 4.
/// </summary>
public int StartWorkingHour { get; }

/// <summary>
/// Finish working hour index. Typically, 4 or 8
/// </summary>
public int FinishWorkingHour { get; }

private bool Equals(DatesPeriod other)
{
return this.StartDate.Equals(other.StartDate)
&& this.EndDate.Equals(other.EndDate)
&& this.StartWorkingHour == other.StartWorkingHour
&& this.FinishWorkingHour == other.FinishWorkingHour;
}

public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}

if (ReferenceEquals(this, obj))
{
return true;
}

if (obj.GetType() != this.GetType())
{
return false;
}

return this.Equals((DatesPeriod)obj);
}

public override int GetHashCode()
{
unchecked
{
var hashCode = this.StartDate.GetHashCode();
hashCode = (hashCode * 397) ^ this.EndDate.GetHashCode();
hashCode = (hashCode * 397) ^ this.StartWorkingHour;
hashCode = (hashCode * 397) ^ this.FinishWorkingHour;
return hashCode;
}
}

public static bool operator ==(DatesPeriod left, DatesPeriod right)
{
return Equals(left, right);
}

public static bool operator !=(DatesPeriod left, DatesPeriod right)
{
return !Equals(left, right);
}

public bool DatesIntersectsWith(DatesPeriod? period)
{
if (period == null)
{
return false;
}

if (this.EndDate < period.StartDate || period.EndDate < this.StartDate)
{
return false;
}

return true;
}

private static DateTime MinDate(DateTime first, DateTime second)
{
return first <= second ? first : second;
}

private static DateTime MaxDate(DateTime first, DateTime second)
{
return first >= second ? first : second;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Arcadia.Assistant.Calendar.Abstractions
{
public static class SickLeaveStatuses
{
public const string Requested = "Requested";

public const string Cancelled = "Cancelled";

public const string Completed = "Completed";

public static readonly string[] All = { Requested, Completed, Cancelled };

public static readonly string[] Pending = { Requested };

public static readonly string[] Actual = { Requested, Completed };
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace Arcadia.Assistant.Calendar.Abstractions
{
public static class VacationStatuses
{
public const string Requested = "Requested";

public const string Cancelled = "Cancelled";

public const string Approved = "Approved";

public const string Rejected = "Rejected";

public const string AccountingReady = "AccountingReady";

public const string Processed = "Processed";

public static readonly string[] All = { Requested, Approved, Cancelled, Rejected, AccountingReady, Processed };

public static readonly string[] Pending = { Requested };

public static readonly string[] Actual = { Requested, Approved, AccountingReady, AccountingReady, Processed };
}
}
Loading