Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions kr.devany.googleapi.sdPlugin/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,25 @@
"UUID": "kr.devany.googleapi.adsensemanagement",
"PropertyInspectorPath": "propertyInspector/adsensemanagement/index.html"
},
{
"Icon": "images/calendar",
"Name": "Google Calendar",
"States": [
{
"FontSize": "10",
"TitleAlignment": "bottom",
"Image": "images/calendar"
}
],
"Controllers": [
"Keypad",
"Information"
],
"SupportedInMultiActions": false,
"Tooltip": "구글 캘린더",
"UUID": "kr.devany.googleapi.googlecalendar",
"PropertyInspectorPath": "propertyInspector/googlecalendar/index.html"
},
{
"Icon": "images/gmail.png",
"Name": "Gmail",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Google Calendar</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/barraider/streamdeck-easypi@latest/src/sdpi.css">
<script src="https://cdn.jsdelivr.net/gh/barraider/streamdeck-easypi@latest/src/sdtools.common.js"></script>

<script src="PluginActionPI.js"></script>
</head>

<body>
<div class="sdpi-wrapper">
<div type="color" class="sdpi-item" id="dvFrontolor">
<div class="sdpi-item-label">Front Color</div>
<input type="color" class="sdpi-item-value sdProperty" value="#FFFFFF" id="frontColor" oninput="setSettings()">
</div>
<div type="color" class="sdpi-item" id="dvBackColor">
<div class="sdpi-item-label">Back Color</div>
<input type="color" class="sdpi-item-value sdProperty" value="#000000" id="backColor" oninput="setSettings()">
</div>
</div>
</body>
</html>
42 changes: 40 additions & 2 deletions src/GoogleAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<LangVersion>preview</LangVersion>
<PublishUrl>게시\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -58,6 +73,9 @@
<Reference Include="Google.Apis.Auth, Version=1.68.0.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
<HintPath>..\packages\Google.Apis.Auth.1.68.0\lib\net462\Google.Apis.Auth.dll</HintPath>
</Reference>
<Reference Include="Google.Apis.Calendar.v3, Version=1.35.1.1321, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
<HintPath>..\packages\Google.Apis.Calendar.v3.1.35.1.1321\lib\net45\Google.Apis.Calendar.v3.dll</HintPath>
</Reference>
<Reference Include="Google.Apis.Core, Version=1.68.0.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
<HintPath>..\packages\Google.Apis.Core.1.68.0\lib\net462\Google.Apis.Core.dll</HintPath>
</Reference>
Expand All @@ -74,11 +92,14 @@
<Reference Include="System.CodeDom, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.CodeDom.7.0.0\lib\net462\System.CodeDom.dll</HintPath>
</Reference>
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Data.Linq" />
<Reference Include="System.Drawing" />
<Reference Include="System.Drawing.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<Reference Include="System.Drawing.Common, Version=8.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\System.Drawing.Common.8.0.1\lib\net462\System.Drawing.Common.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.IO.Compression" />
<Reference Include="System.Management" />
Expand All @@ -100,10 +121,14 @@
<Compile Include="GoogleAPIs\AdSenseManagement\PluginAction.cs" />
<Compile Include="GoogleAPIs\AdSenseManagement\Enums\Resources.cs" />
<Compile Include="GoogleAPIs\GoogleAPIs.cs" />
<Compile Include="GoogleAPIs\GoogleCalendar\ApiAction.cs" />
<Compile Include="GoogleAPIs\GoogleCalendar\GoogleAPIQuery.cs" />
<Compile Include="GoogleAPIs\GoogleCalendar\Models\Item.cs" />
<Compile Include="GoogleAPIs\GoogleCalendar\Models\PluginSettings.cs" />
<Compile Include="GoogleAPIs\GoogleCalendar\PluginAction.cs" />
<Compile Include="Helpers\ImageHelper.cs" />
<Compile Include="GoogleAPIs\AdSenseManagement\GoogleAPIQuery.cs" />
<Compile Include="GoogleAPIs\AdSenseManagement\ApiAction.cs" />
<Compile Include="Models\IPluginSettings.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="GoogleAPIs\AdSenseManagement\Models\PluginSettings.cs" />
Expand All @@ -119,6 +144,7 @@
</ItemGroup>
<ItemGroup>
<Folder Include="GoogleAPIs\Gmail\" />
<Folder Include="Models\" />
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Connected Services\" />
Expand All @@ -132,5 +158,17 @@
<ItemGroup>
<Content Include="DevAny.ico" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.8.1">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.8.1%28x86 및 x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
11 changes: 10 additions & 1 deletion src/GoogleAPIs/AdSenseManagement/PluginAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,16 @@ public PluginAction(ISDConnection connection, InitialPayload payload) : base(con
private async void Connection_OnTitleParametersDidChange(object sender, SDEventReceivedEventArgs<BarRaider.SdTools.Events.TitleParametersDidChange> e)
{
Logger.Instance.LogMessage(TracingLevel.INFO, "OnTitleParametersDidChange Event Handled");
await DisplayInitialAsync();

if (!File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"DevAny\StreamDock.Plugins\GoogleAPI\Google.Apis.Auth.OAuth2.Responses.TokenResponse-user")))
{
await DisplayInitialAsync();
}
else
{
await DisplayBusyAsync();
await UpdateApiDataAsync();
}
}

/// <summary>
Expand Down
6 changes: 5 additions & 1 deletion src/GoogleAPIs/GoogleAPIs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using Google.Apis.Adsense.v2;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Calendar.v3;

namespace StreamDock.Plugins.GoogleAPIs
{
Expand All @@ -31,7 +32,10 @@ protected async Task<UserCredential> GetClientSecretAsync()
{
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.FromStream(stream).Secrets,
new[] { AdsenseService.Scope.AdsenseReadonly },
new[] {
AdsenseService.Scope.AdsenseReadonly,
CalendarService.Scope.Calendar
},
"user", CancellationToken.None);
}
Logger.Instance.LogMessage(TracingLevel.INFO, "Read client_secrets.json");
Expand Down
110 changes: 110 additions & 0 deletions src/GoogleAPIs/GoogleCalendar/ApiAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

using BarRaider.SdTools;

using Google.Apis.Calendar.v3;
using Google.Apis.Services;

using Newtonsoft.Json.Linq;

namespace StreamDock.Plugins.GoogleAPIs.GoogleCalendar
{
/// <summary>
/// API 동작 정의 프로시저
/// </summary>
internal class ApiAction : GoogleAPI
{
PluginSettings pluginSettings { get; set; }
Item item { get; set; }

internal ApiAction(PluginSettings pluginsettings, Item item)
{
this.pluginSettings = pluginsettings;
this.item = item;
}
internal async Task<CalendarService> GetService()
{
// 서비스 생성
var service = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = await GetClientSecretAsync(),
ApplicationName = "StreamDock Plugin"
});

return service;
}
/// <summary>
/// 키가 눌렸을 때 동작 정의. Google API 통신.
/// </summary>
internal async Task<Item> ExecuteAsync()
{
Item _item = this.item;

try
{
// 서비스 생성
var service = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = await GetClientSecretAsync(),
ApplicationName = "StreamDock Plugin"
});

// 구글 API 통신 인스턴스
GoogleAPIQuery googleAPIQuery = new GoogleAPIQuery(service);

if (pluginSettings.CalendarSummary.IsNullOrEmpty())
{
item.calendarID = googleAPIQuery.GetPrimaryCalendar().Id;
}
else
{
item.calendarID = googleAPIQuery.GetCalendar(pluginSettings.CalendarSummary).Id;
}

Logger.Instance.LogMessage(TracingLevel.INFO, item.calendarID);

// StreamDock 설정에 따른 동작 호출
item.Events = await googleAPIQuery.CalendarEventsToday(item.calendarID);

// 디스플레이용 데이터 가공
_item = SetDisplayValue();
}
catch (Exception ex)
{
Logger.Instance.LogMessage(TracingLevel.ERROR, ex.Message);
Logger.Instance.LogMessage(TracingLevel.ERROR, ex.StackTrace);
}
return _item;
}

/// <summary>
/// StreamDock 설정에 따라 표시할 데이터를 지정합니다.
/// </summary>
/// <returns></returns>
internal Item SetDisplayValue()
{
try
{
item.DisplayValues.Clear();

foreach (var value in item.Events) {
if (value.End.Date.IsDateTime())
{

}
item.DisplayValues.Add(value.Summary);
}
}
catch (Exception ex)
{
Logger.Instance.LogMessage(TracingLevel.ERROR, ex.Message);
Logger.Instance.LogMessage(TracingLevel.ERROR, ex.StackTrace);
}

return item;
}
}
}
80 changes: 80 additions & 0 deletions src/GoogleAPIs/GoogleCalendar/GoogleAPIQuery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System.Collections.Generic;
using System.Linq;

using BarRaider.SdTools;

using Google.Apis.Calendar.v3;
using Google.Apis.Calendar.v3.Data;

using System.Threading.Tasks;
using Google.Apis.Adsense.v2.Data;
using System;

namespace StreamDock.Plugins.GoogleAPIs.GoogleCalendar
{
internal class GoogleAPIQuery
{
private CalendarService service;

/// <summary>
/// <see cref="GoogleAPIQuery"/> 클래스의 새 인스턴스를 초기화합니다.
/// </summary>
/// <param name="service">요청을 실행할 애드센스 서비스 개체입니다.</param>
/// <param name="maxListPageSize">검색할 최대 페이지 크기입니다.</param>
internal GoogleAPIQuery(CalendarService service)
{
this.service = service;
}

/// <summary>
/// 계정의 모든 캘린더를 가져옵니다.
/// </summary>
/// <returns>검색된 계정의 마지막 페이지입니다.</returns>
internal IList<CalendarListEntry> GetAllCalendars()
{
string pageToken = null;
CalendarList calendarList = null;

do
{
var calendarListRequest = service.CalendarList.List();
calendarListRequest.PageToken = pageToken;
calendarList = calendarListRequest.Execute();
pageToken = calendarList.NextPageToken;
} while (pageToken != null);
return calendarList.Items;
}
/// <summary>
/// 단일 캘린더를 가져옵니다.
/// </summary>
/// <returns></returns>
internal CalendarListEntry GetCalendar(string summary)
{
return GetAllCalendars().First(s => s.Summary == summary);
}
/// <summary>
/// 단일 캘린더를 가져옵니다.
/// </summary>
/// <returns></returns>
internal CalendarListEntry GetPrimaryCalendar()
{
return GetAllCalendars().First(s => s.Primary == true);
}
/// <summary>
/// 오늘 이벤트를 가져옵니다.
/// </summary>
/// <returns></returns>
internal async Task<IList<Event>> CalendarEventsToday(string id)
{
var requeust = service.Events.List(id);

requeust.MaxResults = 5;
requeust.TimeMin = DateTime.Today;
requeust.TimeMax = DateTime.Today.AddDays(1).AddSeconds(-1);

var result = await requeust.ExecuteAsync();

return result.Items;
}
}
}
Loading