예제 #1
0
 public RootNode(string filename)
     : this()
 {
     this.Text      = Path.GetFileName(filename);
     this.filename  = filename;
     this.resources = new ResourcesLocator(this.filename);
 }
예제 #2
0
 public RootNode()
     : base()
 {
     this.Text      = "<empty>";
     this.filename  = String.Empty;
     this.resources = new ResourcesLocator();
 }
        public static XmlDocument CreateTaskToastNotification(ITask task)
        {
            string content = string.Empty;

            try
            {
                XmlDocument xmlDocument = new XmlDocument();

                const string templateXml = @"
                    <toast scenario='reminder'>
                        <visual>
                            <binding template='ToastGeneric'>
                                <text>{0}</text>
                                <text>{1}</text>
                                <image placement='AppLogoOverride' src='{2}' />
                            </binding>
                        </visual>
                        <actions>
                            <input id='snoozeTime' type='selection' defaultInput='5'>
                              <selection id='5' content='5 {3}' />
                              <selection id='30' content='30 {3}' />
                              <selection id='60' content='1 {4}' />
                              <selection id='240' content='4 {5}' />
                              <selection id='1440' content='1 {6}' />
                            </input>
                            <action activationType='system' arguments='snooze' hint-inputId='snoozeTime' content=''/>
                            <action content='{7}' arguments='{8}' activationType='background' />
                            <action content='{9}' arguments='{10}' activationType='foreground' />
                        </actions>
                        <audio src='ms-winsoundevent:Notification.Reminder' />
                    </toast>
                    ";

                content = string.Format(
                    templateXml,
                    SafeEscape(task.Title),                         // 0
                    SafeEscape(task.Note ?? string.Empty),          // 1
                    ResourcesLocator.GetAppIconPng(),               // 2
                    StringResources.Notification_SnoozeMinutes,     // 3
                    StringResources.Notification_SnoozeHour,        // 4
                    StringResources.Notification_SnoozeHours,       // 5
                    StringResources.Notification_SnoozeDay,         // 6
                    StringResources.Notification_Done,              // 7
                    LaunchArgumentsHelper.GetArgCompleteTask(task), // 8
                    StringResources.Notification_Edit,              // 9
                    LaunchArgumentsHelper.GetArgEditTask(task)      // 10
                    );

                xmlDocument.LoadXml(content);

                return(xmlDocument);
            }
            catch (Exception ex)
            {
                TrackingManagerHelper.Exception(ex, string.Format("Exception CreateTaskToastNotification: {0}", content));
                return(null);
            }
        }
예제 #4
0
            public void Adjust(ResourcesLocator locator, ResourceType type)
            {
                using (MemoryStream stream = locator.GetResource(type, value))
                {
                    int image = this.TreeView.ImageList.Images.IndexOfKey(ResourceTreeView.BINARY_NODE);
                    switch (type.Type)
                    {
                    case ResourceTypes.RT_BITMAP:
                        image = this.TreeView.ImageList.Images.IndexOfKey(ResourceTreeView.BITMAP_NODE);
                        break;

                    case ResourceTypes.RT_CURSOR:
                    case ResourceTypes.RT_GROUP_CURSOR:
                        image = this.TreeView.ImageList.Images.IndexOfKey(ResourceTreeView.CURSOR_NODE);
                        break;

                    case ResourceTypes.RT_DIALOG:
                        image = this.TreeView.ImageList.Images.IndexOfKey(ResourceTreeView.DIALOG_NODE);
                        break;

                    case ResourceTypes.RT_HTML:
                        image = this.TreeView.ImageList.Images.IndexOfKey(ResourceTreeView.HTML_NODE);
                        break;

                    case ResourceTypes.RT_ICON:
                    case ResourceTypes.RT_GROUP_ICON:
                        image = this.TreeView.ImageList.Images.IndexOfKey(ResourceTreeView.ICON_NODE);
                        break;

                    case ResourceTypes.RT_MENU:
                        image = this.TreeView.ImageList.Images.IndexOfKey(ResourceTreeView.MENU_NODE);
                        break;

                    case ResourceTypes.RT_STRING:
                        image = this.TreeView.ImageList.Images.IndexOfKey(ResourceTreeView.STRING_NODE);
                        break;

                    case ResourceTypes.RT_VERSION:
                        image = this.TreeView.ImageList.Images.IndexOfKey(ResourceTreeView.VERSION_NODE);
                        break;

                    default:
                        if (!BaseNode.IsBinaryData(stream))
                        {
                            this.binary = false;
                            image       = this.TreeView.ImageList.Images.IndexOfKey(ResourceTreeView.TEXT_NODE);
                        }
                        break;
                    }
                    this.ImageIndex         = image;
                    this.SelectedImageIndex = this.ImageIndex;
                }
            }
예제 #5
0
        public DisplaySettingsPageViewModel(IWorkbook workbook, INavigationService navigationService, IMessageBoxService messageBoxService, IPlatformService platformService)
            : base(workbook, navigationService)
        {
            if (messageBoxService == null)
            {
                throw new ArgumentNullException(nameof(messageBoxService));
            }
            if (platformService == null)
            {
                throw new ArgumentNullException(nameof(platformService));
            }

            this.messageBoxService = messageBoxService;
            this.platformService   = platformService;

            this.useDarkTheme         = this.Settings.GetValue <bool>(CoreSettings.UseDarkTheme);
            this.previousUseDarkTheme = this.useDarkTheme;

            this.patterns = new List <string>(ResourcesLocator.Patterns);

            this.pickCustomImageCommand = new RelayCommand(this.PickCustomImageExecute);

            this.opacity = this.Settings.GetValue <double>(CoreSettings.BackgroundOpacity);

            string backgroundImage       = this.Settings.GetValue <string>(CoreSettings.BackgroundImage);
            string backgroundPatternName = this.Settings.GetValue <string>(CoreSettings.BackgroundPattern);
            string backgroundPattern     = ResourcesLocator.BuildPatternPath(
                backgroundPatternName,
                this.Settings.GetValue <bool>(CoreSettings.UseDarkTheme));

            this.useBackgroundPattern = !string.IsNullOrEmpty(backgroundPattern);
            this.useBackgroundImage   = !string.IsNullOrEmpty(backgroundImage) && !this.useBackgroundPattern;
            this.useBackgroundNone    = !this.useBackgroundPattern && !this.useBackgroundImage;

            if (this.useBackgroundPattern)
            {
                this.backgroundSource = backgroundPattern;
            }
            else if (this.useBackgroundImage)
            {
                this.backgroundSource = backgroundImage;
            }

            this.selectedPattern = backgroundPatternName;
            this.selectedPattern = this.patterns.FirstOrDefault(p => p.Equals(this.selectedPattern, StringComparison.OrdinalIgnoreCase));
        }
예제 #6
0
        private void UpdateAppTheme()
        {
            // set the theme on the main page + on opened flyouts
            ElementTheme theme     = this.viewmodel.UseLightTheme ? ElementTheme.Light : ElementTheme.Dark;
            Frame        rootFrame = Window.Current.Content as Frame;
            Page         page      = rootFrame.Content as Page;

            if (page != null)
            {
                page.RequestedTheme = theme;
            }

            var navigationService = (NavigationService)Ioc.Resolve <INavigationService>();

            foreach (var flyout in navigationService.Flyouts)
            {
                ((FrameworkElement)flyout.Content).RequestedTheme = theme;
            }

            ResourcesLocator.UpdateTheme(this.viewmodel.UseLightTheme);

            var workbook = Ioc.Resolve <IWorkbook>();

            foreach (var view in workbook.Views)
            {
                ((ModelEntityBase)view).RaisePropertyChanged("Color");
            }
            foreach (var context in workbook.Contexts)
            {
                ((ModelEntityBase)context).RaisePropertyChanged("Color");
            }
            foreach (var tag in workbook.Tags)
            {
                ((ModelEntityBase)tag).RaisePropertyChanged("Color");
            }
            foreach (var smartview in workbook.SmartViews)
            {
                ((ModelEntityBase)smartview).RaisePropertyChanged("Color");
            }
        }
예제 #7
0
        public override async Task <IWorkbook> ConfigureAsync(Frame rootFrame)
        {
            if (rootFrame == null)
            {
                throw new ArgumentNullException(nameof(rootFrame));
            }

            bool sendAnalytics = WinSettings.Instance.GetValue <bool>(CoreSettings.SendAnalytics);

            string deviceId = "n/a";

            try
            {
                var settings = WinSettings.Instance;
                if (!settings.HasValue(CoreSettings.DeviceId) || settings.GetValue <string>(CoreSettings.DeviceId) == "N/A")
                {
                    string id = this.ComputeDeviceId();
                    settings.SetValue(CoreSettings.DeviceId, id);
                }

                deviceId = settings.GetValue <string>(CoreSettings.DeviceId);
            }
            catch (Exception ex)
            {
                TrackingManagerHelper.Exception(ex, "Error while setting device id");
            }

            var platformService = new PlatformService(this.version, deviceId, () => CrashHandler.GetDiagnosticsInformation());

            Ioc.RegisterInstance <IPlatformService, PlatformService>(platformService);

            TrackingManager trackingManager = new TrackingManager(sendAnalytics, platformService.DeviceFamily);

            Ioc.RegisterInstance <ITrackingManager, TrackingManager>(trackingManager);

            HttpClientHandler.Setup();

            ResourcesLocator.Initialize("ms-appx://", UriKind.Absolute);
            if (!WinSettings.Instance.GetValue <bool>(CoreSettings.UseDarkTheme))
            {
                ResourcesLocator.UpdateTheme(true);
            }

            var persistence = Ioc.RegisterInstance <IPersistenceLayer, WinPersistenceLayer>(new WinPersistenceLayer(automaticSave: true));

            LogService.Log("Bootstraper", string.Format("Version: {0}", ApplicationVersion.GetAppVersion()));

            var navigationService = new NavigationService(rootFrame, platformService);

            Ioc.RegisterInstance <INavigationService, NavigationService>(navigationService);

            var messageBoxService = new MessageBoxService(navigationService);

            Ioc.RegisterInstance <IMessageBoxService, MessageBoxService>(messageBoxService);

            Ioc.RegisterInstance <ISpeechService, SpeechService>(new SpeechService(messageBoxService));

            var workbook = this.InitializeWorkbook(persistence, platformService);

            // we just read the latest value of data from the DB, so even if there was a background sync
            // we now have the latest version, so we remove the background sync flag here
            workbook.Settings.SetValue(CoreSettings.SyncBackgroundOccured, false);

            this.keyboardShortcutManager = new KeyboardShortcutManager(workbook, rootFrame, navigationService, trackingManager);

            var backgroundTaskManager = new BackgroundTaskManager(workbook);

            backgroundTaskManager.InitializeAsync();
            Ioc.RegisterInstance <IBackgroundTaskManager, BackgroundTaskManager>(backgroundTaskManager);

            var notificationService = new NotificationService();

            Ioc.RegisterInstance <INotificationService, NotificationService>(notificationService);

            var startupManager = Ioc.Build <StartupManager>();

            Ioc.RegisterInstance <IStartupManager, StartupManager>(startupManager);

            Ioc.RegisterInstance <IAlarmManager, AlarmManager>(new AlarmManager(workbook));

            var tileManager = new TileManager(workbook, trackingManager, notificationService, false);

            tileManager.LoadSecondaryTilesAsync();
            Ioc.RegisterInstance <ITileManager, TileManager>(tileManager);

            var synchronizationManager = await InitializeSyncAsync(workbook, platformService, trackingManager);

            // it is important to remove old task after sync is initialized otherwise changes would not
            // tracked and put in the changelog for the next sync
            workbook.RemoveOldTasks();

            var cortanaService = new CortanaRuntimeService(workbook);

            // no need to await this call because it can runs in the background
            Task.Run(() =>
            {
                JumpListManager.SetupJumpListAsync();
                cortanaService.SetupDefinitionsAsync();
            });
            Ioc.RegisterInstance <ICortanaRuntimeService, CortanaRuntimeService>(cortanaService);

            return(workbook);
        }
예제 #8
0
        public async void SafeRun(IBackgroundTaskInstance taskInstance)
        {
            bool hadException = false;

            // Register to receive an event if Cortana dismisses the background task. This will
            // occur if the task takes too long to respond, or if Cortana's UI is dismissed.
            // Any pending operations should be cancelled or waited on to clean up where possible.
            taskInstance.Canceled += this.OnTaskCanceled;

            WinSettings.Instance.SetValue(CoreSettings.BackgroundLastStartExecution, DateTime.Now);
            ReportStatus(BackgroundExecutionStatus.Started);

            LogService.Initialize(new WinLogHandler());
            LogService.Level = WinSettings.Instance.GetValue <LogLevel>(CoreSettings.LogLevel);

            ResourcesLocator.Initialize("ms-appx://", UriKind.Absolute);

            var mutex = new Mutex(false, Constants.SyncPrimitiveAppRunningForeground);

            if (!mutex.WaitOne(1))
            {
                LogService.Log("Agent", "Skipping background agent because app is foreground");
                await LogService.SaveAsync();

                this.deferral.Complete();

                ReportStatus(BackgroundExecutionStatus.Skipped);

                return;
            }

            ITrackingManager trackingManager = null;

            try
            {
                this.persistenceLayer = new WinPersistenceLayer(automaticSave: false);

                var deviceFamily = DeviceFamily.Unkown;

                if (AnalyticsInfo.VersionInfo.DeviceFamily.Equals("Windows.Desktop", StringComparison.OrdinalIgnoreCase))
                {
                    deviceFamily = DeviceFamily.WindowsDesktop;
                }
                else if (AnalyticsInfo.VersionInfo.DeviceFamily.Equals("Windows.Mobile", StringComparison.OrdinalIgnoreCase))
                {
                    deviceFamily = DeviceFamily.WindowsMobile;
                }

                trackingManager = new TrackingManager(false, deviceFamily);

                var workbook = this.persistenceLayer.Open(tryUpgrade: true) as Workbook;

                if (workbook != null)
                {
                    ReportStatus(BackgroundExecutionStatus.WorkbookLoaded);

                    Ioc.RegisterInstance <IWorkbook, Workbook>(workbook);
                    workbook.Initialize();

                    // important: load alarm manager so that we update reminders properly is a recurring task is created
                    var alarmManager = new AlarmManager(workbook);

                    var backgroundSyncManager = new BackgroundSynchronizationManager(workbook, trackingManager, ToastHelper.ToastMessage);
                    await backgroundSyncManager.SetupAsync();

                    if (backgroundSyncManager.CanSync())
                    {
                        ReportStatus(BackgroundExecutionStatus.SyncStarted);

                        this.synchronizationManager = backgroundSyncManager.SynchronizationManager;

                        if (workbook.Settings.GetValue <bool>(CoreSettings.BackgroundToast))
                        {
                            this.synchronizationManager.OperationCompleted += (s, e) => ToastHelper.ToastMessage(e.Item);
                            this.synchronizationManager.OperationFailed    += (s, e) => ToastHelper.ToastMessage(e.Message);
                        }

                        bool result = await backgroundSyncManager.TrySyncAsync(this.persistenceLayer);

                        if (result)
                        {
                            ReportStatus(BackgroundExecutionStatus.SyncCompleted);
                        }
                        else
                        {
                            ReportStatus(BackgroundExecutionStatus.SyncError);
                        }
                    }

                    // update tiles
                    ReportStatus(BackgroundExecutionStatus.TileStarted);

                    TileManager timeManager = new TileManager(workbook, trackingManager, null, true);
                    await timeManager.LoadSecondaryTilesAsync();

                    timeManager.UpdateTiles();

                    ReportStatus(BackgroundExecutionStatus.TileCompleted);

                    // save log
                    await LogService.SaveAsync();
                }
                else
                {
                    ReportStatus(BackgroundExecutionStatus.WorkbookNotLoaded);
                }
            }
            catch (Exception ex)
            {
                hadException = true;

                LogService.Level |= LogLevel.Debug;
                LogService.Log("WinBackgroundTaskHelper", "Exception during background execution: " + ex.GetAllMessages());

                if (trackingManager != null)
                {
                    trackingManager.Exception(ex, "Exception Background task helper");
                }

                ReportStatus(BackgroundExecutionStatus.CompletedException);
            }

            if (!hadException)
            {
                ReportStatus(BackgroundExecutionStatus.CompletedSuccess);
            }

            await LogService.SaveAsync();

            WinSettings.Instance.SetValue(CoreSettings.BackgroundLastEndExecution, DateTime.Now);

            this.deferral.Complete();
        }
        public static XmlDocument CreateTileNotification(string title, IList <ITask> tasks, IAbstractFolder folder = null)
        {
            string content = string.Empty;

            try
            {
                var xmlDocument = new XmlDocument();

                const string templateXml = @"
                    <tile>
                        <visual branding=""nameAndLogo"" displayName=""{0}"">
                            <binding template=""TileSmall"" hint-textStacking=""center"" branding=""none"">
                                <image placement=""peek"" src=""{3}""/>
                                <text hint-align=""center"" hint-style=""title"">{1}</text>
                            </binding>
                            <binding template=""TileMedium"">
                                {2}
                            </binding>
                            <binding template=""TileWide"" hint-lockDetailedStatus1=""{4}"" hint-lockDetailedStatus2=""{5}"" hint-lockDetailedStatus3=""{6}"">
                                <group>
                                    <subgroup hint-weight=""20"" hint-textStacking=""center"">
                                        <image src=""{3}""/>
                                    </subgroup>
                                    <subgroup hint-weight=""80"" hint-textStacking=""center"">
                                        {2}
                                    </subgroup>
                                </group>
                            </binding>
                            <binding template=""TileLarge"">
                                {2}
                            </binding>
                        </visual>
                    </tile>
                    ";

                var  builder = new StringBuilder();
                bool hasTask = false;

                string task1 = string.Empty;
                string task2 = string.Empty;
                string task3 = string.Empty;

                for (int i = 0; i < 10; i++)
                {
                    string taskName = TryGetTaskAt(tasks, i);
                    if (!string.IsNullOrWhiteSpace(taskName))
                    {
                        var safeEscapeTaskName = SafeEscape(taskName);
                        builder.AppendLine(string.Format("<text>{0}</text>", safeEscapeTaskName));
                        hasTask = true;

                        if (i == 0)
                        {
                            task1 = safeEscapeTaskName;
                        }
                        else if (i == 1)
                        {
                            task2 = safeEscapeTaskName;
                        }
                        else if (i == 2)
                        {
                            task3 = safeEscapeTaskName;
                        }
                    }
                }

                if (!hasTask)
                {
                    if (folder != null)
                    {
                        builder.AppendLine(string.Format("<text hint-style='captionsubtle' hint-wrap='true'>{0}</text>", SafeEscape(folder.EmptyHeader)));
                    }
                    else
                    {
                        builder.AppendLine(string.Format("<text hint-style='captionsubtle' hint-wrap='true'>{0}</text>", SafeEscape(StringResources.SystemView_Today_EmptyHeader)));
                    }
                }

                string displayName = SafeEscape(title);
                string counter     = tasks.Count.ToString(CultureInfo.InvariantCulture);
                string text        = builder.ToString();
                string picture     = folder != null?ResourcesLocator.GetFolderIconPng(folder) : ResourcesLocator.GetAppIconPng();

                content = string.Format(
                    templateXml,
                    displayName,   // 0
                    counter,       // 1
                    text,          // 2
                    picture,       // 3
                    task1,         // 4
                    task2,         // 5
                    task3          // 6
                    );

                xmlDocument.LoadXml(content);

                return(xmlDocument);
            }
            catch (Exception ex)
            {
                TrackingManagerHelper.Exception(ex, string.Format("Exception CreateTileNotification: {0}", content));
                return(null);
            }
        }
예제 #10
0
        public static XmlDocument CreateTileNotificationForTask(ITask task)
        {
            string content = string.Empty;

            try
            {
                var xmlDocument = new XmlDocument();

                const string templateXml = @"
                    <tile>
                      <visual branding=""nameAndLogo"">

                        <binding template=""TileSmall"" hint-textStacking=""center"">
                          <text hint-style=""subtitle"" hint-align=""center"">{0}</text>
                        </binding>

                        <binding template=""TileMedium"" displayName=""{3}"">
                          <text hint-style=""base"">{0}</text>
                          <text hint-style=""caption"">{1}</text>
                          <text hint-style=""captionSubtle"" hint-wrap=""true"">{2}</text>
                        </binding>

                        <binding template=""TileWide"" displayName=""{4}"">
                          <group>
                            <subgroup hint-weight=""33"">
                              <image src=""{5}"" />
                            </subgroup>
                            <subgroup>
                              <text hint-style=""base"">{0}</text>
                              <text hint-style=""caption"">{1}</text>
                              <text hint-style=""captionSubtle"" hint-wrap=""true"">{2}</text>
                            </subgroup>
                          </group>
                        </binding>

                        <binding template=""TileLarge"" displayName=""{4}"">
                          <group>
                            <subgroup>
                              <text hint-style=""base"">{0}</text>
                             <text hint-style=""caption"">{1}</text>
                              <text hint-style=""captionSubtle"" hint-wrap=""true"">{2}</text>
                              <image hint-align=""center"" src=""{5}"" />
                            </subgroup>
                          </group>
                        </binding>

                      </visual>
                    </tile>
                    ";

                string picture = ResourcesLocator.GetFolderIconPng(task.Folder);

                content = string.Format(
                    templateXml,
                    SafeEscape(task.Title),                                                             // 0 title
                    SafeEscape(task.Folder.Name),                                                       // 1 folder
                    SafeEscape(task.Note ?? string.Empty),                                              // 2 notes (max: 65 characters)
                    task.Due.HasValue ? task.Due.Value.ToString("M") : string.Empty,                    // 3 short due (Aug. 22)
                    task.Due.HasValue ? RelativeDateConverter.ConvertRelative(task.Due) : string.Empty, // 4 long due (Today Aug. 22)
                    picture                                                                             // 5 image
                    );

                xmlDocument.LoadXml(content);

                return(xmlDocument);
            }
            catch (Exception ex)
            {
                TrackingManagerHelper.Exception(ex, string.Format("Exception CreateTileNotification: {0}", content));
                return(null);
            }
        }