Exemplo n.º 1
0
        private void Configure()
        {
            lock (_syncRoot)
            {
                if (_configuration != null)
                {
                    return;
                }

                var cfg = CreateConfiguration();

                var keyboardEventHandler = cfg.KeyboardEventHandler ?? new BlockAllKeyInputEventHandler();

                _configuration      = cfg;
                _lifetimeSupervisor = cfg.LifetimeSupervisor;
                _lifetimeSupervisor.UseDispatcher(cfg.Dispatcher);

                _displaySupervisor = new NotificationsDisplaySupervisor(
                    cfg.Dispatcher,
                    cfg.PositionProvider,
                    cfg.LifetimeSupervisor,
                    cfg.DisplayOptions,
                    keyboardEventHandler);
            }
        }
Exemplo n.º 2
0
        private static async Task MainAsync()
        {
            SyncConfiguration.SetFeatureToken(Constants.FeatureToken);

            var credentials = Credentials.UsernamePassword(Constants.RosUsername, Constants.RosPassword, createUser: false);
            var admin       = await User.LoginAsync(credentials, new Uri($"http://{Constants.RosUrl}"));

            // Hack to create synchronized Realm the first time it's used
            var syncConfig = new SyncConfiguration(admin, new Uri($"realm://{Constants.RosUrl}/{Constants.FeedbackRealm}"));

            using (var realm = Realm.GetInstance(syncConfig))
            {
                if (!realm.All <Foo>().Any())
                {
                    realm.Write(() => realm.Add(new Foo()));
                    await realm.GetSession().WaitForUploadAsync();

                    await admin.ApplyPermissionsAsync(PermissionCondition.Default, syncConfig.ServerUri.ToString(), AccessLevel.Write);
                }
            }

            var config = new NotifierConfiguration(admin)
            {
                Handlers         = { new FeedbackHandler() },
                WorkingDirectory = Path.Combine(Directory.GetCurrentDirectory(), Constants.NotifierDirectory)
            };

            using (var notifier = await Notifier.StartAsync(config))
            {
                do
                {
                    Console.WriteLine("Type in 'exit' to quit the app.");
                }while (Console.ReadLine() != "exit");
            }
        }
Exemplo n.º 3
0
 void ConfigureNotifier(NotifierConfiguration cfg)
 {
     cfg.Dispatcher             = Dispatcher;
     cfg.DisplayOptions.Width   = 400;
     cfg.DisplayOptions.TopMost = true;
     cfg.LifetimeSupervisor     = new TimeAndCountBasedLifetimeSupervisor(TimeSpan.FromSeconds(10), MaximumNotificationCount.FromCount(5));
     cfg.PositionProvider       = new GdiPrimaryScreenPositionProvider(Corner.BottomRight, 0, 0);
 }
Exemplo n.º 4
0
        private void ConfigNotifier(NotifierConfiguration cfg)
        {
#if DEBUG
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
#endif

            cfg.PositionProvider = new WindowPositionProvider(
                parentWindow: Application.Current.MainWindow,
                corner: Corner.TopRight,
                offsetX: 10,
                offsetY: 10);

            cfg.LifetimeSupervisor = new TimeAndCountBasedLifetimeSupervisor(
                notificationLifetime: TimeSpan.FromSeconds(3),
                maximumNotificationCount: MaximumNotificationCount.FromCount(5));

            cfg.Dispatcher = Application.Current.Dispatcher;
        }
Exemplo n.º 5
0
        private static async Task AsyncMain()
        {
            try
            {
                var credentials = Credentials.UsernamePassword(Constants.RosUsername, Constants.RosPassword, false);
                var admin       = await User.LoginAsync(credentials, new Uri($"http://{Constants.RosUrl}"));

                // Hack to create permissions only the first time it's used
                // this is the only scope of the Foo class
                var syncConfig = new SyncConfiguration(admin, new Uri($"realm://{Constants.RosUrl}/{Constants.RealmName}"));
                using (var realm = Realm.GetInstance(syncConfig))
                {
                    if (!realm.All <Foo>().Any())
                    {
                        realm.Write(() => realm.Add(new Foo {
                            Value = 6
                        }));
                        await realm.GetSession().WaitForUploadAsync();

                        await admin.ApplyPermissionsAsync(PermissionCondition.Default, syncConfig.ServerUri.ToString(), AccessLevel.Write);
                    }
                }

                var notifierConfig = new NotifierConfiguration(admin)
                {
                    Handlers         = { new TextAnalyticsHandler() },
                    WorkingDirectory = Path.Combine(Directory.GetCurrentDirectory(), Constants.NotifierDirectory)
                };

                using (var notifier = await Notifier.StartAsync(notifierConfig))
                {
                    do
                    {
                        Console.WriteLine("'exit' to quit the app.");
                    }while (Console.ReadLine() != "exit");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
        }
Exemplo n.º 6
0
        private NotifierConfiguration CreateConfiguration()
        {
            var cfg = new NotifierConfiguration
            {
                Dispatcher = Application.Current.Dispatcher
            };

            _configureAction(cfg);

            if (cfg.LifetimeSupervisor == null)
            {
                throw new ArgumentNullException(nameof(cfg.LifetimeSupervisor), "Missing configuration argument");
            }

            if (cfg.PositionProvider == null)
            {
                throw new ArgumentNullException(nameof(cfg.PositionProvider), "Missing configuration argument");
            }
            return(cfg);
        }
        private void LoadEngines(NotifierConfiguration config)
        {
            foreach (NotifierInformationElement notifier in config.Notifiers)
            {
                var processor = GetProcessorFromTypeString(notifier.ProcessorType);
                if (processor == null)
                {
                    continue;
                }

                var parms =
                    notifier.
                    Parameters.
                    Cast <NotifierParameterElement>().ToDictionary(parm => parm.Name, parm => parm.Value);

                processor.Initialize(parms);

                var engine = new MSMQNotifierEngine(notifier.QueuePath, processor);
                _notifiers.Add(engine);
            }
        }
Exemplo n.º 8
0
        public static async Task MainAsync()
        {
            // Login the admin user
            var credentials = Credentials.UsernamePassword(AdminUsername, AdminPassword, createUser: false);
            var admin       = await User.LoginAsync(credentials, new Uri($"http://{ServerUrl}"));

            var config = new NotifierConfiguration(admin)
            {
                // Add all handlers that this notifier will invoke
                Handlers = { new CouponHandler() }
            };

            // Start the notifier. Your handlers will be invoked for as
            // long as the notifier is not disposed.
            using (var notifier = await Notifier.StartAsync(config))
            {
                do
                {
                    Console.WriteLine("Type in 'exit' to quit the app.");
                }while (Console.ReadLine() != "exit");
            }
        }