├── .gitignore
├── Tomighty.Windows
├── Resources
│ ├── image_x.png
│ ├── image_clock.tiff
│ ├── image_pinned.png
│ ├── image_stop.tiff
│ ├── Audio
│ │ └── deskbell.wav
│ ├── icon_tomato_red.ico
│ ├── image_unpinned.png
│ ├── image_warning.png
│ ├── icon_tomato_black.ico
│ ├── icon_tomato_blue.ico
│ ├── icon_tomato_green.ico
│ ├── icon_tomato_white.ico
│ ├── image_tomato_red.tiff
│ ├── image_tomato_black.tiff
│ ├── image_tomato_blue.tiff
│ ├── image_tomato_green.tiff
│ └── Toasts
│ │ ├── image_toast_tomato_blue.png
│ │ ├── image_toast_tomato_red.png
│ │ ├── image_toast_tomato_green.png
│ │ ├── app-updated.xml
│ │ ├── interval-completed.xml
│ │ └── first-run.xml
├── Events.cs
├── App.config
├── Properties
│ ├── Settings.settings
│ ├── AssemblyInfo.cs
│ ├── Settings.Designer.cs
│ └── Resources.resx
├── packages.config
├── URLs.cs
├── StartupEventFlags.cs
├── Version.cs
├── Tray
│ ├── ITrayMenuMutator.cs
│ ├── ITrayMenu.cs
│ ├── TrayIconController.cs
│ ├── TrayMenuController.cs
│ └── TrayMenu.cs
├── StartupEvents.cs
├── NOTICE.txt
├── Directories.cs
├── IntervalTypeExtensions.cs
├── Notifications
│ ├── SoundNotificationPlayer.cs
│ ├── NotificationsPresenter.cs
│ └── Toasts.cs
├── Util
│ └── Hash.cs
├── About
│ ├── AboutWindowPresenter.cs
│ ├── AboutWindow.cs
│ ├── AboutWindow.resx
│ └── AboutWindow.Designer.cs
├── Program.cs
├── Preferences
│ ├── UserPreferencesPresenter.cs
│ ├── UserPreferencesForm.cs
│ ├── UserPreferences.cs
│ └── UserPreferencesForm.resx
├── Flags.cs
├── Logger.cs
├── Host.cs
├── TomightyApplication.cs
├── ErrorReportWindow.cs
├── Timer
│ ├── Taskbar.cs
│ ├── TimerWindow.resx
│ ├── TimerWindow.cs
│ └── TimerWindow.Designer.cs
├── AutoUpdate.cs
├── ErrorReportWindow.Designer.cs
├── LICENSE.txt
└── Tomighty.Windows.csproj
├── Tomighty.Update.Swap
├── App.config
├── Properties
│ ├── AssemblyInfo.cs
│ ├── Settings.settings
│ └── Settings.Designer.cs
├── Program.cs
└── Tomighty.Update.Swap.csproj
├── pack.ps1
├── Tomighty.Core
├── ICountdownClock.cs
├── IntervalType.cs
├── ITimer.cs
├── IEventHub.cs
├── Properties
│ └── AssemblyInfo.cs
├── Events
│ ├── PomodoroCompleted.cs
│ ├── PomodoroCountChanged.cs
│ ├── TimerStarted.cs
│ ├── TimeElapsed.cs
│ └── TimerStopped.cs
├── IPomodoroEngine.cs
├── IMutableUserPreferences.cs
├── IUserPreferences.cs
├── SynchronousEventHub.cs
├── Duration.cs
├── Timer.cs
├── PomodoroEngine.cs
└── Tomighty.Core.csproj
├── GlobalAssemblyInfo.cs
├── Tomighty.Core.Test
├── Properties
│ └── AssemblyInfo.cs
├── packages.config
├── FakeEventHub.cs
├── Tomighty.Core.Test.csproj
└── PomodoroEngineTest.cs
├── NOTICE.txt
├── README.md
├── dist.bat
├── Tomighty.sln
├── setup.nsi
└── LICENSE.txt
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | packages/
3 | bin/
4 | obj/
5 | build/
6 | dist/
7 | *~
8 | .vs/
9 | *.user
10 |
--------------------------------------------------------------------------------
/Tomighty.Windows/Resources/image_x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomighty/tomighty-windows/HEAD/Tomighty.Windows/Resources/image_x.png
--------------------------------------------------------------------------------
/Tomighty.Windows/Events.cs:
--------------------------------------------------------------------------------
1 | namespace Tomighty.Windows.Events
2 | {
3 | public class FirstRun { }
4 | public class AppUpdated { }
5 | }
6 |
--------------------------------------------------------------------------------
/Tomighty.Windows/Resources/image_clock.tiff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomighty/tomighty-windows/HEAD/Tomighty.Windows/Resources/image_clock.tiff
--------------------------------------------------------------------------------
/Tomighty.Windows/Resources/image_pinned.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomighty/tomighty-windows/HEAD/Tomighty.Windows/Resources/image_pinned.png
--------------------------------------------------------------------------------
/Tomighty.Windows/Resources/image_stop.tiff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomighty/tomighty-windows/HEAD/Tomighty.Windows/Resources/image_stop.tiff
--------------------------------------------------------------------------------
/Tomighty.Windows/Resources/Audio/deskbell.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomighty/tomighty-windows/HEAD/Tomighty.Windows/Resources/Audio/deskbell.wav
--------------------------------------------------------------------------------
/Tomighty.Windows/Resources/icon_tomato_red.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomighty/tomighty-windows/HEAD/Tomighty.Windows/Resources/icon_tomato_red.ico
--------------------------------------------------------------------------------
/Tomighty.Windows/Resources/image_unpinned.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomighty/tomighty-windows/HEAD/Tomighty.Windows/Resources/image_unpinned.png
--------------------------------------------------------------------------------
/Tomighty.Windows/Resources/image_warning.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomighty/tomighty-windows/HEAD/Tomighty.Windows/Resources/image_warning.png
--------------------------------------------------------------------------------
/Tomighty.Windows/Resources/icon_tomato_black.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomighty/tomighty-windows/HEAD/Tomighty.Windows/Resources/icon_tomato_black.ico
--------------------------------------------------------------------------------
/Tomighty.Windows/Resources/icon_tomato_blue.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomighty/tomighty-windows/HEAD/Tomighty.Windows/Resources/icon_tomato_blue.ico
--------------------------------------------------------------------------------
/Tomighty.Windows/Resources/icon_tomato_green.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomighty/tomighty-windows/HEAD/Tomighty.Windows/Resources/icon_tomato_green.ico
--------------------------------------------------------------------------------
/Tomighty.Windows/Resources/icon_tomato_white.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomighty/tomighty-windows/HEAD/Tomighty.Windows/Resources/icon_tomato_white.ico
--------------------------------------------------------------------------------
/Tomighty.Windows/Resources/image_tomato_red.tiff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomighty/tomighty-windows/HEAD/Tomighty.Windows/Resources/image_tomato_red.tiff
--------------------------------------------------------------------------------
/Tomighty.Windows/Resources/image_tomato_black.tiff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomighty/tomighty-windows/HEAD/Tomighty.Windows/Resources/image_tomato_black.tiff
--------------------------------------------------------------------------------
/Tomighty.Windows/Resources/image_tomato_blue.tiff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomighty/tomighty-windows/HEAD/Tomighty.Windows/Resources/image_tomato_blue.tiff
--------------------------------------------------------------------------------
/Tomighty.Windows/Resources/image_tomato_green.tiff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomighty/tomighty-windows/HEAD/Tomighty.Windows/Resources/image_tomato_green.tiff
--------------------------------------------------------------------------------
/Tomighty.Windows/Resources/Toasts/image_toast_tomato_blue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomighty/tomighty-windows/HEAD/Tomighty.Windows/Resources/Toasts/image_toast_tomato_blue.png
--------------------------------------------------------------------------------
/Tomighty.Windows/Resources/Toasts/image_toast_tomato_red.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomighty/tomighty-windows/HEAD/Tomighty.Windows/Resources/Toasts/image_toast_tomato_red.png
--------------------------------------------------------------------------------
/Tomighty.Windows/Resources/Toasts/image_toast_tomato_green.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tomighty/tomighty-windows/HEAD/Tomighty.Windows/Resources/Toasts/image_toast_tomato_green.png
--------------------------------------------------------------------------------
/Tomighty.Windows/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Tomighty.Update.Swap/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/pack.ps1:
--------------------------------------------------------------------------------
1 | param (
2 | [string]$directory,
3 | [string]$name
4 | )
5 |
6 | Add-Type -Assembly System.IO.Compression.FileSystem
7 | [System.IO.Compression.ZipFile]::CreateFromDirectory($directory, $name, [System.IO.Compression.CompressionLevel]::Optimal, $false)
--------------------------------------------------------------------------------
/Tomighty.Windows/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Tomighty.Windows/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Tomighty.Update.Swap/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | [assembly: AssemblyTitle("Tomighty.Update.Swap")]
6 | [assembly: ComVisible(false)]
7 | [assembly: Guid("3fc0dc20-6120-4cd7-8f54-a1ca6f8886bf")]
8 |
--------------------------------------------------------------------------------
/Tomighty.Update.Swap/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Tomighty.Windows/URLs.cs:
--------------------------------------------------------------------------------
1 | namespace Tomighty.Windows
2 | {
3 | internal class URLs
4 | {
5 | public static readonly string UpdateFeed = "https://raw.githubusercontent.com/tomighty/tomighty-update-feed/master/windows";
6 | public static readonly string ErrorReport = "https://tomighty-errors.herokuapp.com";
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/Tomighty.Windows/StartupEventFlags.cs:
--------------------------------------------------------------------------------
1 | namespace Tomighty.Windows
2 | {
3 | public class StartupEventFlags
4 | {
5 | public static readonly Flags Flags = new Flags("startup");
6 | public static readonly string FirstRunFlag = "firstrun";
7 | public static readonly string AppUpdatedFlag = "app_updated";
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/Tomighty.Core/ICountdownClock.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Tomighty - http://www.tomighty.org
3 | //
4 | // This software is licensed under the Apache License Version 2.0:
5 | // http://www.apache.org/licenses/LICENSE-2.0.txt
6 | //
7 |
8 | namespace Tomighty
9 | {
10 | public interface ICountdownClock
11 | {
12 | Duration RemainingTime { get; }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Tomighty.Core/IntervalType.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Tomighty - http://www.tomighty.org
3 | //
4 | // This software is licensed under the Apache License Version 2.0:
5 | // http://www.apache.org/licenses/LICENSE-2.0.txt
6 | //
7 |
8 | namespace Tomighty
9 | {
10 | public enum IntervalType
11 | {
12 | Pomodoro,
13 | ShortBreak,
14 | LongBreak
15 | }
16 | }
--------------------------------------------------------------------------------
/Tomighty.Core/ITimer.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Tomighty - http://www.tomighty.org
3 | //
4 | // This software is licensed under the Apache License Version 2.0:
5 | // http://www.apache.org/licenses/LICENSE-2.0.txt
6 | //
7 |
8 | namespace Tomighty
9 | {
10 | public interface ITimer : ICountdownClock
11 | {
12 | void Start(Duration duration, IntervalType intervalType);
13 | void Stop();
14 | }
15 | }
--------------------------------------------------------------------------------
/Tomighty.Core/IEventHub.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Tomighty - http://www.tomighty.org
3 | //
4 | // This software is licensed under the Apache License Version 2.0:
5 | // http://www.apache.org/licenses/LICENSE-2.0.txt
6 | //
7 |
8 | using System;
9 |
10 | namespace Tomighty
11 | {
12 | public interface IEventHub
13 | {
14 | void Publish(object @event);
15 | void Subscribe(Action eventHandler);
16 | }
17 | }
--------------------------------------------------------------------------------
/GlobalAssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Tomighty - http://www.tomighty.org
3 | //
4 | // This software is licensed under the Apache License Version 2.0:
5 | // http://www.apache.org/licenses/LICENSE-2.0.txt
6 | //
7 |
8 | using System.Reflection;
9 | using System.Resources;
10 |
11 | [assembly: AssemblyProduct("Tomighty")]
12 | [assembly: AssemblyCopyright("Copyright © 2010-2017 Celio Cidral Junior")]
13 | [assembly: NeutralResourcesLanguage("en-US")]
14 |
--------------------------------------------------------------------------------
/Tomighty.Core/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Tomighty - http://www.tomighty.org
3 | //
4 | // This software is licensed under the Apache License Version 2.0:
5 | // http://www.apache.org/licenses/LICENSE-2.0.txt
6 | //
7 |
8 | using System.Reflection;
9 | using System.Runtime.InteropServices;
10 |
11 | [assembly: AssemblyTitle("Tomighty Core")]
12 | [assembly: ComVisible(false)]
13 | [assembly: Guid("C7FF3B3E-0CC1-4EC7-A7C1-39B6361B5895")]
14 |
--------------------------------------------------------------------------------
/Tomighty.Core.Test/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Tomighty - http://www.tomighty.org
3 | //
4 | // This software is licensed under the Apache License Version 2.0:
5 | // http://www.apache.org/licenses/LICENSE-2.0.txt
6 | //
7 |
8 | using System.Reflection;
9 | using System.Runtime.InteropServices;
10 |
11 | [assembly: AssemblyTitle("Tomighty Core Tests")]
12 | [assembly: ComVisible(false)]
13 | [assembly: Guid("CAC6A930-C0E3-422B-A49E-7DE000DC9A40")]
14 |
--------------------------------------------------------------------------------
/Tomighty.Windows/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Tomighty - http://www.tomighty.org
3 | //
4 | // This software is licensed under the Apache License Version 2.0:
5 | // http://www.apache.org/licenses/LICENSE-2.0.txt
6 | //
7 |
8 | using System.Reflection;
9 | using System.Runtime.InteropServices;
10 |
11 | [assembly: AssemblyTitle("Tomighty")]
12 | [assembly: AssemblyDescription("Tomighty for Windows")]
13 | [assembly: ComVisible(false)]
14 | [assembly: Guid("f45108d8-e103-4db9-a43f-82f864fd9217")]
15 |
--------------------------------------------------------------------------------
/Tomighty.Core/Events/PomodoroCompleted.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Tomighty - http://www.tomighty.org
3 | //
4 | // This software is licensed under the Apache License Version 2.0:
5 | // http://www.apache.org/licenses/LICENSE-2.0.txt
6 | //
7 |
8 | namespace Tomighty.Events
9 | {
10 | public class PomodoroCompleted
11 | {
12 | public PomodoroCompleted(Duration duration)
13 | {
14 | Duration = duration;
15 | }
16 |
17 | public Duration Duration { get; }
18 | }
19 | }
--------------------------------------------------------------------------------
/Tomighty.Core/Events/PomodoroCountChanged.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Tomighty - http://www.tomighty.org
3 | //
4 | // This software is licensed under the Apache License Version 2.0:
5 | // http://www.apache.org/licenses/LICENSE-2.0.txt
6 | //
7 |
8 | namespace Tomighty.Events
9 | {
10 | public class PomodoroCountChanged
11 | {
12 | public PomodoroCountChanged(int count)
13 | {
14 | PomodoroCount = count;
15 | }
16 |
17 | public int PomodoroCount { get; }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Tomighty.Core/IPomodoroEngine.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Tomighty - http://www.tomighty.org
3 | //
4 | // This software is licensed under the Apache License Version 2.0:
5 | // http://www.apache.org/licenses/LICENSE-2.0.txt
6 | //
7 |
8 | namespace Tomighty
9 | {
10 | public interface IPomodoroEngine
11 | {
12 | void StartTimer(IntervalType intervalType);
13 | void StopTimer();
14 | void ResetPomodoroCount();
15 |
16 | int PomodoroCount { get; }
17 | IntervalType SuggestedBreakType { get; }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Tomighty.Windows/Resources/Toasts/app-updated.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Tomighty Updated
6 | A new version of Tomighty has been automatically installed
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Tomighty.Windows/Version.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics;
2 | using System.Reflection;
3 |
4 | namespace Tomighty.Windows
5 | {
6 | internal class Version
7 | {
8 | private static string product;
9 |
10 | public static string Product
11 | {
12 | get
13 | {
14 | if (product == null)
15 | product = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion;
16 | return product;
17 | }
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Tomighty.Windows/Resources/Toasts/interval-completed.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {interval_type} completed
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Tomighty.Core/IMutableUserPreferences.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Tomighty - http://www.tomighty.org
3 | //
4 | // This software is licensed under the Apache License Version 2.0:
5 | // http://www.apache.org/licenses/LICENSE-2.0.txt
6 | //
7 |
8 | namespace Tomighty
9 | {
10 | public interface IMutableUserPreferences : IUserPreferences
11 | {
12 | void SetIntervalDuration(IntervalType intervalType, Duration duration);
13 | new bool ShowToastNotifications { get; set; }
14 | new bool PlaySoundNotifications { get; set; }
15 | new int MaxPomodoroCount { get; set; }
16 | new bool AutoUpdate { get; set; }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Tomighty.Windows/Resources/Toasts/first-run.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | First time using Tomighty?
6 | There should be a tomato-shaped icon somewhere in your task bar.
7 | Start by clicking on it. The left button shows the menu.
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Tomighty.Core/IUserPreferences.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Tomighty - http://www.tomighty.org
3 | //
4 | // This software is licensed under the Apache License Version 2.0:
5 | // http://www.apache.org/licenses/LICENSE-2.0.txt
6 | //
7 |
8 | using System;
9 |
10 | namespace Tomighty
11 | {
12 | public interface IUserPreferences
13 | {
14 | Duration GetIntervalDuration(IntervalType intervalType);
15 | int MaxPomodoroCount { get; }
16 | bool ShowToastNotifications { get; }
17 | bool PlaySoundNotifications { get; }
18 | bool AutoUpdate { get; }
19 |
20 | void Update(Action action);
21 | }
22 | }
--------------------------------------------------------------------------------
/Tomighty.Windows/Tray/ITrayMenuMutator.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Tomighty - http://www.tomighty.org
3 | //
4 | // This software is licensed under the Apache License Version 2.0:
5 | // http://www.apache.org/licenses/LICENSE-2.0.txt
6 | //
7 |
8 | namespace Tomighty.Windows.Tray
9 | {
10 | internal interface ITrayMenuMutator
11 | {
12 | void UpdateRemainingTime(string text);
13 | void EnableStartPomodoroItem(bool enable);
14 | void EnableStartShortBreakItem(bool enable);
15 | void EnableStartLongBreakItem(bool enable);
16 | void EnableStopTimerItem(bool enable);
17 | void EnableResetPomodoroCountItem(bool enable);
18 | void UpdatePomodoroCount(int count);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Tomighty.Core/Events/TimerStarted.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Tomighty - http://www.tomighty.org
3 | //
4 | // This software is licensed under the Apache License Version 2.0:
5 | // http://www.apache.org/licenses/LICENSE-2.0.txt
6 | //
7 |
8 | namespace Tomighty.Events
9 | {
10 | public class TimerStarted
11 | {
12 | public IntervalType IntervalType { get; }
13 | public Duration Duration { get; }
14 | public Duration RemainingTime { get; }
15 |
16 | public TimerStarted(IntervalType intervalType, Duration duration, Duration remainingTime)
17 | {
18 | IntervalType = intervalType;
19 | Duration = duration;
20 | RemainingTime = remainingTime;
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/Tomighty.Core/Events/TimeElapsed.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Tomighty - http://www.tomighty.org
3 | //
4 | // This software is licensed under the Apache License Version 2.0:
5 | // http://www.apache.org/licenses/LICENSE-2.0.txt
6 | //
7 |
8 | namespace Tomighty.Events
9 | {
10 | public class TimeElapsed
11 | {
12 | public TimeElapsed(IntervalType intervalType, Duration duration, Duration remainingTime)
13 | {
14 | IntervalType = intervalType;
15 | Duration = duration;
16 | RemainingTime = remainingTime;
17 | }
18 |
19 | public Duration Duration { get; }
20 | public IntervalType IntervalType { get; }
21 | public Duration RemainingTime { get; }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/NOTICE.txt:
--------------------------------------------------------------------------------
1 | =========================================================================
2 | == NOTICE file corresponding to section 4(d) of the Apache License, ==
3 | == Version 2.0, in this case for the Tomighty distribution. ==
4 | =========================================================================
5 |
6 | Tomighty is a software developed by Célio Cidral Junior. You can find it
7 | at http://www.tomighty.org
8 |
9 | Pomodoro Technique® and Pomodoro™ are registered and filed trademarks
10 | owned by Francesco Cirillo. Tomighty is not affiliated by, associated
11 | with nor endorsed by Francesco Cirillo.
12 |
13 | Tomato icon designed by José Campos
14 |
15 | Clock icon designed by Thomas Le Bas
16 |
--------------------------------------------------------------------------------
/Tomighty.Core/Events/TimerStopped.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Tomighty - http://www.tomighty.org
3 | //
4 | // This software is licensed under the Apache License Version 2.0:
5 | // http://www.apache.org/licenses/LICENSE-2.0.txt
6 | //
7 |
8 | namespace Tomighty.Events
9 | {
10 | public class TimerStopped
11 | {
12 | public IntervalType IntervalType { get; }
13 | public Duration Duration { get; }
14 | public Duration RemainingTime { get; }
15 | public bool IsIntervalCompleted => RemainingTime == Duration.Zero;
16 |
17 | public TimerStopped(IntervalType intervalType, Duration duration, Duration remainingTime)
18 | {
19 | IntervalType = intervalType;
20 | Duration = duration;
21 | RemainingTime = remainingTime;
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/Tomighty.Windows/StartupEvents.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 | using Tomighty.Windows.Events;
4 |
5 | namespace Tomighty.Windows
6 | {
7 | public class StartupEvents : StartupEventFlags
8 | {
9 | public StartupEvents(IEventHub eventHub)
10 | {
11 | Task.Run(() =>
12 | {
13 | if (Flags.IsOn(FirstRunFlag, true))
14 | {
15 | Flags.TurnOff(FirstRunFlag);
16 | eventHub.Publish(new FirstRun());
17 | }
18 |
19 | if (Flags.IsOn(AppUpdatedFlag, false))
20 | {
21 | Flags.TurnOff(AppUpdatedFlag);
22 | eventHub.Publish(new AppUpdated());
23 | }
24 | });
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Tomighty.Windows/NOTICE.txt:
--------------------------------------------------------------------------------
1 | =========================================================================
2 | == NOTICE file corresponding to section 4(d) of the Apache License, ==
3 | == Version 2.0, in this case for the Tomighty distribution. ==
4 | =========================================================================
5 |
6 | Tomighty is a software developed by Célio Cidral Junior. You can find it
7 | at http://www.tomighty.org
8 |
9 | Pomodoro Technique® and Pomodoro™ are registered and filed trademarks
10 | owned by Francesco Cirillo. Tomighty is not affiliated by, associated
11 | with nor endorsed by Francesco Cirillo.
12 |
13 | Tomato icon designed by José Campos
14 |
15 | Clock icon designed by Thomas Le Bas
16 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Tomighty for Windows
2 | ====================
3 |
4 | Available for download at http://www.tomighty.org
5 |
6 | This repository contains the source code for the .NET version of Tomighty.
7 | If you are looking for the source code of the old, multiplatform (Java) version, see https://github.com/ccidral/tomighty
8 |
9 | Development Workflow
10 | ====================
11 |
12 | We follow the development model presented by Vincent Driessen:
13 |
14 | http://nvie.com/posts/a-successful-git-branching-model/
15 |
16 | Discuss
17 | =======
18 |
19 | For development related discussions, please subscribe to:
20 |
21 | https://groups.google.com/forum/#!forum/tomighty-developers
22 |
23 | License
24 | =======
25 |
26 | Tomighty for Windows is licensed under the terms of the Apache License 2.0. Read it here: https://www.apache.org/licenses/LICENSE-2.0.html
27 |
--------------------------------------------------------------------------------
/Tomighty.Core.Test/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Tomighty.Windows/Directories.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Tomighty - http://www.tomighty.org
3 | //
4 | // This software is licensed under the Apache License Version 2.0:
5 | // http://www.apache.org/licenses/LICENSE-2.0.txt
6 | //
7 |
8 | using System;
9 | using System.IO;
10 | using System.Reflection;
11 |
12 | namespace Tomighty.Windows
13 | {
14 | internal class Directories
15 | {
16 | public static string ProgramLocation => Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
17 |
18 | public static string AppData
19 | {
20 | get
21 | {
22 | var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Tomighty");
23 | if (!Directory.Exists(path))
24 | Directory.CreateDirectory(path);
25 | return path;
26 | }
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Tomighty.Windows/IntervalTypeExtensions.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Tomighty - http://www.tomighty.org
3 | //
4 | // This software is licensed under the Apache License Version 2.0:
5 | // http://www.apache.org/licenses/LICENSE-2.0.txt
6 | //
7 |
8 | using System;
9 | using Tomighty.Windows.Properties;
10 |
11 | namespace Tomighty.Windows
12 | {
13 | internal static class IntervalTypeExtensions
14 | {
15 | public static string GetName(this IntervalType intervalType)
16 | {
17 | switch (intervalType)
18 | {
19 | case IntervalType.Pomodoro: return Resources.String_Pomodoro;
20 | case IntervalType.ShortBreak: return Resources.String_ShortBreak;
21 | case IntervalType.LongBreak: return Resources.String_LongBreak;
22 | default: throw new ArgumentException($"Unknown interval type: {intervalType}");
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Tomighty.Windows/Notifications/SoundNotificationPlayer.cs:
--------------------------------------------------------------------------------
1 | using System.Media;
2 | using Tomighty.Events;
3 |
4 | namespace Tomighty.Windows.Notifications
5 | {
6 | public class SoundNotificationPlayer
7 | {
8 | private readonly IUserPreferences userPreferences;
9 | private readonly SoundPlayer intervalCompletedNotification = new SoundPlayer(Properties.Resources.audio_deskbell);
10 |
11 | public SoundNotificationPlayer(IUserPreferences userPreferences, IEventHub eventHub)
12 | {
13 | this.userPreferences = userPreferences;
14 | eventHub.Subscribe(OnTimerStopped);
15 | }
16 |
17 | private void OnTimerStopped(TimerStopped @event)
18 | {
19 | if (@event.IsIntervalCompleted && userPreferences.PlaySoundNotifications)
20 | {
21 | intervalCompletedNotification.Play();
22 | }
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Tomighty.Windows/Tray/ITrayMenu.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Tomighty - http://www.tomighty.org
3 | //
4 | // This software is licensed under the Apache License Version 2.0:
5 | // http://www.apache.org/licenses/LICENSE-2.0.txt
6 | //
7 |
8 | using System;
9 | using System.Windows.Forms;
10 |
11 | namespace Tomighty.Windows.Tray
12 | {
13 | internal interface ITrayMenu
14 | {
15 | ContextMenuStrip Component { get; }
16 |
17 | void OnAboutClick(EventHandler handler);
18 | void OnPreferencesClick(EventHandler handler);
19 | void OnStartPomodoroClick(EventHandler handler);
20 | void OnStartLongBreakClick(EventHandler handler);
21 | void OnStartShortBreakClick(EventHandler handler);
22 | void OnStopTimerClick(EventHandler handler);
23 | void OnResetPomodoroCountClick(EventHandler handler);
24 | void OnExitClick(EventHandler handler);
25 | void Update(Action action);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Tomighty.Windows/Util/Hash.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Tomighty - http://www.tomighty.org
3 | //
4 | // This software is licensed under the Apache License Version 2.0:
5 | // http://www.apache.org/licenses/LICENSE-2.0.txt
6 | //
7 |
8 | using System;
9 | using System.IO;
10 | using System.Security.Cryptography;
11 | using System.Text;
12 |
13 | namespace Tomighty.Windows.Util
14 | {
15 | public class Hash
16 | {
17 | public static string Sha1(string s)
18 | {
19 | var sha = new SHA1CryptoServiceProvider();
20 | var data = Encoding.UTF8.GetBytes(s);
21 | var hash = sha.ComputeHash(data);
22 | return BitConverter.ToString(hash).Replace("-", string.Empty).ToLower();
23 | }
24 |
25 | public static string Sha256(Stream stream)
26 | {
27 | var sha = new SHA256CryptoServiceProvider();
28 | var hash = sha.ComputeHash(stream);
29 | return BitConverter.ToString(hash).Replace("-", string.Empty).ToLower();
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Tomighty.Windows/About/AboutWindowPresenter.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Tomighty - http://www.tomighty.org
3 | //
4 | // This software is licensed under the Apache License Version 2.0:
5 | // http://www.apache.org/licenses/LICENSE-2.0.txt
6 | //
7 |
8 | using System.Windows.Forms;
9 |
10 | namespace Tomighty.Windows.About
11 | {
12 | internal class AboutWindowPresenter
13 | {
14 | private AboutWindow window;
15 |
16 | public void Show()
17 | {
18 | if (window == null)
19 | {
20 | window = new AboutWindow();
21 | window.FormClosed += OnWindowClosed;
22 | }
23 |
24 | if (window.Visible)
25 | {
26 | window.Focus();
27 | }
28 | else
29 | {
30 | window.ShowDialog();
31 | }
32 | }
33 |
34 | private void OnWindowClosed(object sender, FormClosedEventArgs e)
35 | {
36 | window.Dispose();
37 | window = null;
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Tomighty.Windows/About/AboutWindow.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Tomighty - http://www.tomighty.org
3 | //
4 | // This software is licensed under the Apache License Version 2.0:
5 | // http://www.apache.org/licenses/LICENSE-2.0.txt
6 | //
7 |
8 | using System;
9 | using System.IO;
10 | using System.Reflection;
11 | using System.Windows.Forms;
12 |
13 | namespace Tomighty.Windows.About
14 | {
15 | public partial class AboutWindow : Form
16 | {
17 | public AboutWindow()
18 | {
19 | InitializeComponent();
20 | }
21 |
22 | private void AboutForm_Load(object sender, EventArgs e)
23 | {
24 | var version = Assembly.GetExecutingAssembly().GetName().Version;
25 |
26 | titleLabel.Text = $"Tomighty {version.Major}.{version.Minor}.{version.Build}";
27 | licenseTextBox.Text = File.ReadAllText(@"LICENSE.txt");
28 | productVersionTextBox.Text = Version.Product;
29 | }
30 |
31 | private void closeButton_Click(object sender, EventArgs e)
32 | {
33 | Close();
34 | Dispose();
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Tomighty.Windows/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace Tomighty.Windows.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Tomighty.Update.Swap/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace Tomighty.Update.Swap.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Tomighty.Windows/Program.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Tomighty - http://www.tomighty.org
3 | //
4 | // This software is licensed under the Apache License Version 2.0:
5 | // http://www.apache.org/licenses/LICENSE-2.0.txt
6 | //
7 |
8 | using System;
9 | using System.Windows.Forms;
10 |
11 | namespace Tomighty.Windows
12 | {
13 | static class Program
14 | {
15 | [STAThread]
16 | static void Main()
17 | {
18 | Application.EnableVisualStyles();
19 | Application.SetCompatibleTextRenderingDefault(false);
20 | AppDomain.CurrentDomain.UnhandledException += (sender, args) => HandleUnhandledException(args.ExceptionObject as Exception);
21 | Application.ThreadException += (sender, args) => HandleUnhandledException(args.Exception);
22 |
23 | try
24 | {
25 | Application.Run(new TomightyApplication());
26 | }
27 | catch(Exception e)
28 | {
29 | Application.Run(new ErrorReportWindow(e));
30 | }
31 | }
32 |
33 | private static void HandleUnhandledException(Exception exception)
34 | {
35 | new ErrorReportWindow(exception).Show();
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Tomighty.Windows/Preferences/UserPreferencesPresenter.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Tomighty - http://www.tomighty.org
3 | //
4 | // This software is licensed under the Apache License Version 2.0:
5 | // http://www.apache.org/licenses/LICENSE-2.0.txt
6 | //
7 |
8 | using System.Windows.Forms;
9 |
10 | namespace Tomighty.Windows.Preferences
11 | {
12 | internal class UserPreferencesPresenter
13 | {
14 | private readonly IUserPreferences userPreferences;
15 | private UserPreferencesForm window;
16 |
17 | public UserPreferencesPresenter(IUserPreferences userPreferences)
18 | {
19 | this.userPreferences = userPreferences;
20 | }
21 |
22 | public void Show()
23 | {
24 | if (window == null)
25 | {
26 | window = new UserPreferencesForm(userPreferences);
27 | window.FormClosed += OnWindowClosed;
28 | }
29 |
30 | if (window.Visible)
31 | {
32 | window.Focus();
33 | }
34 | else
35 | {
36 | window.ShowDialog();
37 | }
38 | }
39 |
40 | private void OnWindowClosed(object sender, FormClosedEventArgs e)
41 | {
42 | window.Dispose();
43 | window = null;
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/Tomighty.Core/SynchronousEventHub.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Tomighty - http://www.tomighty.org
3 | //
4 | // This software is licensed under the Apache License Version 2.0:
5 | // http://www.apache.org/licenses/LICENSE-2.0.txt
6 | //
7 |
8 | using System;
9 | using System.Collections.Generic;
10 |
11 | namespace Tomighty
12 | {
13 | public class SynchronousEventHub : IEventHub
14 | {
15 | private readonly IDictionary>> allSubscribers = new Dictionary>>();
16 |
17 | public void Publish(object @event)
18 | {
19 | var eventType = @event.GetType();
20 |
21 | if (!allSubscribers.ContainsKey(eventType))
22 | return;
23 |
24 | foreach (var subscriber in allSubscribers[eventType])
25 | {
26 | subscriber(@event);
27 | }
28 | }
29 |
30 | public void Subscribe(Action eventHandler)
31 | {
32 | List> subscribers;
33 | var eventType = typeof(T);
34 |
35 | if (allSubscribers.ContainsKey(eventType))
36 | {
37 | subscribers = allSubscribers[eventType];
38 | }
39 | else
40 | {
41 | subscribers = new List>();
42 | allSubscribers[eventType] = subscribers;
43 | }
44 |
45 | subscribers.Add(e => eventHandler((T) e));
46 | }
47 | }
48 | }
--------------------------------------------------------------------------------
/Tomighty.Core/Duration.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Tomighty - http://www.tomighty.org
3 | //
4 | // This software is licensed under the Apache License Version 2.0:
5 | // http://www.apache.org/licenses/LICENSE-2.0.txt
6 | //
7 |
8 | using System;
9 |
10 | namespace Tomighty
11 | {
12 | public struct Duration
13 | {
14 | public static readonly Duration Zero = new Duration();
15 |
16 | public static Duration InSeconds(int seconds) => new Duration(seconds);
17 | public static Duration InMinutes(int minutes) => new Duration(minutes * 60);
18 |
19 | public Duration(int seconds)
20 | {
21 | if(seconds < 0)
22 | throw new ArgumentException($"Invalid duration of {seconds} seconds");
23 |
24 | Seconds = seconds;
25 | }
26 |
27 | public int Seconds { get; }
28 | public int Minutes => Seconds / 60;
29 |
30 | public Duration AddSeconds(int delta) => new Duration(Seconds + delta);
31 |
32 | public override string ToString() => $"{GetType().Name}({Seconds})";
33 |
34 | public string ToTimeString()
35 | {
36 | int minutes = Seconds / 60;
37 | int seconds = Seconds - minutes * 60;
38 | return $"{minutes.ToString("0#")}:{seconds.ToString("0#")}";
39 | }
40 |
41 | public static bool operator ==(Duration a, Duration b) => a.Seconds == b.Seconds;
42 | public static bool operator !=(Duration a, Duration b) => a.Seconds != b.Seconds;
43 | }
44 | }
--------------------------------------------------------------------------------
/Tomighty.Windows/Flags.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace Tomighty.Windows
5 | {
6 | public class Flags
7 | {
8 | private readonly string dir;
9 |
10 | public Flags(string name)
11 | {
12 | dir = Path.Combine(Directories.AppData, name);
13 | }
14 |
15 | public bool IsOn(string name, bool defaultValue)
16 | {
17 | return ReadFile(name, defaultValue);
18 | }
19 |
20 | public void TurnOn(string name)
21 | {
22 | WriteFile(name, true);
23 | }
24 |
25 | public void TurnOff(string name)
26 | {
27 | WriteFile(name, false);
28 | }
29 |
30 | private string GetFile(string name) => Path.Combine(dir, name);
31 |
32 | private void EnsureDirectoryExists()
33 | {
34 | if (!Directory.Exists(dir))
35 | Directory.CreateDirectory(dir);
36 | }
37 |
38 | private void WriteFile(string name, bool value)
39 | {
40 | EnsureDirectoryExists();
41 | File.WriteAllText(GetFile(name), value ? "1" : "0");
42 | }
43 |
44 | private bool ReadFile(string name, bool defaultValue)
45 | {
46 | EnsureDirectoryExists();
47 |
48 | var file = GetFile(name);
49 |
50 | if (File.Exists(file))
51 | return File.ReadAllText(file) == "1" ? true : false;
52 |
53 | return defaultValue;
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/dist.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | echo ==========================================================================
4 | echo Building Tomighty
5 | echo ==========================================================================
6 | echo.
7 |
8 | msbuild Tomighty.sln /t:rebuild /p:Configuration=Release
9 |
10 | for /f %%i in ('powershell -noprofile -executionpolicy bypass "(Get-Item Tomighty.Windows\bin\Release\Tomighty.Windows.exe).VersionInfo.FileVersion"') do set version=%%i
11 |
12 | set tag=%1
13 | if "%tag%"=="commit" (for /f %%i in ('git rev-parse --short HEAD') do set tag=%%i)
14 |
15 | set artifact=tomighty-windows-%version%
16 | if not "%tag%"=="" (set artifact=%artifact%-%tag%)
17 |
18 | set zipfile=dist\%artifact%.zip
19 | set src=Tomighty.Windows\bin\Release
20 | set dest=build\%artifact%
21 |
22 | IF NOT EXIST build (
23 | mkdir build
24 | )
25 |
26 | IF NOT EXIST dist (
27 | mkdir dist
28 | )
29 |
30 | IF EXIST %dest% (
31 | rmdir %dest% /S /Q
32 | )
33 |
34 | if exist %zipfile% (
35 | del %zipfile%
36 | )
37 |
38 | mkdir %dest%\Resources
39 |
40 | xcopy /f LICENSE.txt %dest%
41 | xcopy /f NOTICE.txt %dest%
42 | xcopy /f %src%\Tomighty.Windows.exe %dest%
43 | xcopy /f %src%\Tomighty.Core.dll %dest%
44 | xcopy /f %src%\Microsoft.Toolkit.Uwp.Notifications.dll %dest%
45 | xcopy /f /s %src%\Resources %dest%\Resources
46 | xcopy /f Tomighty.Update.Swap\bin\Release\Tomighty.Update.Swap.exe %dest%
47 |
48 | powershell -executionpolicy bypass -file pack.ps1 "%dest%" "%zipfile%"
49 |
50 | makensis -DPRODUCT_NAME=Tomighty -DPRODUCT_VERSION=%version% -DPRODUCT_FILE_VERSION=%version% -DARTIFACT_NAME=%artifact% -DBUILD_DIR=%dest% setup.nsi
51 |
52 | echo.
53 | echo --------------------------------------------------------------------------
54 | echo Package: %zipfile%
55 | echo Build finished
56 | echo --------------------------------------------------------------------------
57 |
--------------------------------------------------------------------------------
/Tomighty.Windows/Logger.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace Tomighty.Windows
5 | {
6 | class Logger : IDisposable
7 | {
8 | private const long MaxFileSize = 1024 * 512; //512KB
9 |
10 | private readonly StreamWriter writer;
11 |
12 | public Logger(string name)
13 | {
14 | writer = new StreamWriter(GetFile(name + ".log"));
15 | }
16 |
17 | private FileStream GetFile(string name)
18 | {
19 | var path = Path.Combine(Directories.AppData, name);
20 |
21 | if (HasReachedSizeLimit(path))
22 | {
23 | try
24 | {
25 | File.Delete(path);
26 | }
27 | catch
28 | {
29 | //That's ok, let's not break the program just because
30 | //we can't delete the log file
31 | }
32 | }
33 | return new FileStream(path, FileMode.Append);
34 | }
35 |
36 | private bool HasReachedSizeLimit(string filepath)
37 | {
38 | return File.Exists(filepath)
39 | && new FileInfo(filepath).Length > MaxFileSize;
40 | }
41 |
42 | private void Log(string level, string msg)
43 | {
44 | writer.WriteLine($"{DateTimeOffset.Now.ToString()} [{level}] {msg}");
45 | writer.Flush();
46 | }
47 |
48 | public void Info(string msg)
49 | {
50 | Log("INFO", msg);
51 | }
52 |
53 | public void Error(string msg)
54 | {
55 | Log("ERROR", msg);
56 | }
57 |
58 | public void Error(Exception e)
59 | {
60 | Error(e.ToString());
61 | }
62 |
63 | public void Dispose()
64 | {
65 | if (writer != null)
66 | writer.Close();
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/Tomighty.Core.Test/FakeEventHub.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Tomighty - http://www.tomighty.org
3 | //
4 | // This software is licensed under the Apache License Version 2.0:
5 | // http://www.apache.org/licenses/LICENSE-2.0.txt
6 | //
7 |
8 | using System;
9 | using System.Collections.Generic;
10 | using System.Linq;
11 |
12 | namespace Tomighty.Test
13 | {
14 | public class FakeEventHub : IEventHub
15 | {
16 | private readonly List subscribers = new List();
17 | private readonly List