コード例 #1
0
        public MainPage()
        {
            this.InitializeComponent();
            TaskCollection = new ObservableCollection <TodoTask>();

            _clientId = "xxx";
            _scopes   = new string[] { "Tasks.ReadWrite" };

            var webAccountProviderConfig = new WebAccountProviderConfig(WebAccountProviderType.Msa, _clientId);
            var authProvider             = new WindowsProvider(_scopes, webAccountProviderConfig, autoSignIn: false);

            ProviderManager.Instance.GlobalProvider = authProvider;
        }
コード例 #2
0
        /// <summary>
        /// Makes a new instance of <see cref="GameHost"/> class.
        /// </summary>
        public GameHost()
        {
            // - Initialize environment if not initialized
            pEngine.Platform.Environment.Initialize();

            // - Make game loops
            InputGameLoop   = new GameLoop(HandleInput, InputInitialization, "InputThread");
            PhysicsGameLoop = new ThreadedGameLoop(HandlePhysics, PhysicsInitialization, "PhysicsThread");

            // - Modules
            Input    = new InputEngine(this, InputGameLoop);
            GameTree = new GameTree(this, PhysicsGameLoop);
            Windows  = new WindowsProvider(this, InputGameLoop);
        }
コード例 #3
0
        /// <summary>
        /// Displays the <paramref name="fileName"/> in a <see cref="DocumentViewer"/>
        /// </summary>
        /// <param name="fileName">The file to open.</param>
        /// <param name="title">The tile of the window.</param>
        /// <param name="windowProvider">An implementation for creating a customized window. If null, default implementation is used.</param>
        public static void ShowXps(string fileName, string title, IWindowProvider windowProvider = null)
        {
            var xpsDocument = new XpsDocument(fileName, FileAccess.Read);

            var documentViewer = new DocumentViewer {
                Document = xpsDocument.GetFixedDocumentSequence()
            };

            if (windowProvider == null)
            {
                windowProvider = new WindowsProvider();
            }

            windowProvider.Closed += PreviewWindowOnClosed(fileName, xpsDocument);
            windowProvider.Show(title, documentViewer);
            windowProvider.Closed -= PreviewWindowOnClosed(fileName, xpsDocument);
        }
コード例 #4
0
        /// <summary>
        /// Create a new instance of IProvider and check that it has the proper default state, then execute the provided action.
        /// </summary>
        private async void PrepareProvider(Action test)
        {
            await App.DispatcherQueue.EnqueueAsync(async() =>
            {
                var provider = new WindowsProvider(new string[] { "User.Read", "Files.ReadWrite" }, autoSignIn: false);

                ProviderManager.Instance.ProviderStateChanged += (s, e) =>
                {
                    var providerManager = s as ProviderManager;
                    if (providerManager.GlobalProvider.State == ProviderState.SignedIn)
                    {
                        test.Invoke();
                    }
                };

                ProviderManager.Instance.GlobalProvider = provider;

                await provider.SignInAsync();
            });
        }
コード例 #5
0
        public async Task Test_WindowsProvider_SignInAsync()
        {
            await App.DispatcherQueue.EnqueueAsync(async() =>
            {
                // Create the new provider.
                WindowsProvider provider = new WindowsProvider();

                // Run logout to ensure that no cached users affect the test.
                await provider.SignOutAsync();

                // The newly created provider should be in a logged out state.
                Assert.AreEqual(ProviderState.SignedOut, provider.State);

                // Listen for changes in the provider state and count them.
                int eventCount         = 0;
                provider.StateChanged += (s, e) =>
                {
                    eventCount += 1;

                    // Ensure that the states are properly reported through the StateChanged event.
                    switch (e.OldState)
                    {
                    case ProviderState.SignedOut:
                        // Login has been initiated, the provider should now be loading.
                        Assert.AreEqual(ProviderState.Loading, e.NewState);

                        // Loading should be the first event fired.
                        Assert.AreEqual(eventCount, 1);
                        break;

                    case ProviderState.Loading:
                        // The provider has completed login, the provider should now be signed in.
                        Assert.AreEqual(ProviderState.SignedIn, e.NewState);

                        // SignedIn should be the second event fired.
                        Assert.AreEqual(eventCount, 2);
                        break;

                    case ProviderState.SignedIn:
                        // The provider has completed login, the provider should now be signed in.
                        Assert.AreEqual(ProviderState.SignedOut, e.NewState);

                        // SignedIn should be the second event fired.
                        Assert.AreEqual(eventCount, 3);
                        break;

                    default:
                        // This is unexpected, something went wrong during the test.
                        Assert.Fail("The provider has transitioned from an unexpected state: " + Enum.GetName(typeof(ProviderState), e.OldState));
                        break;
                    }
                };

                // Initiate logout.
                await provider.SignInAsync();

                // Logout has completed, the provider should be signed out.
                Assert.AreEqual(ProviderState.SignedIn, provider.State);

                // Initiate logout, which should skip loading, and go straight to signed out.
                await provider.SignOutAsync();

                // Ensure the proper number of events were fired.
                Assert.AreEqual(eventCount, 3);
            });
        }
コード例 #6
0
        public void Test_WindowsProvider_Default()
        {
            WindowsProvider provider = new WindowsProvider();

            Assert.AreEqual(ProviderState.SignedOut, provider.State);
        }
コード例 #7
0
ファイル: SMonHost.cs プロジェクト: staret-hub/SMon
        public static void Run(Action <string[]> main, string[] args, ServiceSettings settings)
        {
            if (args.Length > 0 && CommandArguments.Any(x => x == args[0]) == true)
            {
                // Get the ServiceSettings instance from the service settings file.
                if (settings == null)
                {
                    try
                    {
                        var json = File.ReadAllText(ServiceSettingsFilepath);
                        settings = JsonSerializer.Deserialize <ServiceSettings>(json);
                    }
                    catch
                    {
                        throw new SMonException("The service settings file does not exist or is invalid.");
                    }
                }

                IProvider provider;
                //if (Settings.OSName.Contains("Windows") == true)
                //{   // ex: Microsoft Windows NT 6.2.9200.0
                //    provider = new WindowsProvider(Settings);
                //}
                //else
                //{   // ex: Unix 4.4.0.18362
                //    provider = new LinuxProvider(Settings);
                //}
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) == true)
                {
                    provider = new WindowsProvider(settings);
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) == true)
                {
                    provider = new LinuxProvider(settings);
                }
                else
                {
                    throw new SMonException("OS platform not supported.");
                }

                switch (args[0])
                {
                case "install":
                    args[0] = "run";
                    provider.Install(args);
                    return;

                case "uninstall":
                    provider.Uninstall();
                    return;

                case "start":
                    provider.Start();
                    return;

                case "stop":
                    provider.Stop();
                    return;

                case "restart":
                    provider.Restart();
                    return;
                }
            }

            //Console.CancelKeyPress += (s, e) =>
            //{
            //    e.Cancel = true;
            //};

            var asService = args.Length > 0 && args[0] == "run";

            if (asService == true)
            {
                args = args[1..^ 0];