Esempio n. 1
0
        protected override void OnActivated(IActivatedEventArgs args)
        {
            switch (args.Kind)
            {
            case ActivationKind.CommandLineLaunch:
                CommandLineActivatedEventArgs  cmdLineArgs = args as CommandLineActivatedEventArgs;
                CommandLineActivationOperation operation   = cmdLineArgs.Operation;
                Organization = operation.Arguments.TrimEnd();
                break;

            case ActivationKind.StartupTask:
                // handle auto-launch specific here
                break;

            default:
                break;
            }

            Frame rootFrame = Window.Current.Content as Frame;

            if (rootFrame == null)
            {
                rootFrame = new Frame();
                Window.Current.Content = rootFrame;
            }
            rootFrame.Navigate(typeof(MainPage));

            Window.Current.Activate();
        }
Esempio n. 2
0
        protected override void OnActivated(IActivatedEventArgs args)
        {
            string additionParameter = "";

            switch (args.Kind)
            {
            case ActivationKind.CommandLineLaunch:
                CommandLineActivatedEventArgs cmdLineArgs =
                    args as CommandLineActivatedEventArgs;
                CommandLineActivationOperation operation = cmdLineArgs.Operation;
                string cmdLineString  = operation.Arguments;
                string activationPath = operation.CurrentDirectoryPath;
                break;

            case ActivationKind.Protocol:
                ProtocolActivatedEventArgs uriArg = args as ProtocolActivatedEventArgs;
                additionParameter = GetParameterURI(uriArg.Uri.OriginalString);
                break;
            }
            //Navigate
            Frame rootFrame = Window.Current.Content as Frame;

            if (rootFrame == null)
            {
                rootFrame = new Frame();
                Window.Current.Content = rootFrame;
            }
            rootFrame.Navigate(typeof(MainPage), additionParameter);

            Window.Current.Activate();
        }
Esempio n. 3
0
        protected async override void OnActivated(IActivatedEventArgs args)
        {
            switch (args.Kind)
            {
            case ActivationKind.CommandLineLaunch:
                CommandLineActivatedEventArgs  cmdLineArgs = args as CommandLineActivatedEventArgs;
                CommandLineActivationOperation operation   = cmdLineArgs.Operation;
                string cmdLineString  = operation.Arguments;
                string activationPath = operation.CurrentDirectoryPath;

                Frame rootFrame = Window.Current.Content as Frame;
                if (rootFrame == null)
                {
                    rootFrame = new Frame();
                    Window.Current.Content = rootFrame;
                }

                string[] argz = cmdLineString.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                if (argz.Length > 1 && argz[1].Length != 0)
                {
                    string arg1 = argz[1];
                    rootFrame.Navigate(typeof(MainPage), arg1);
                }
                else
                {
                    rootFrame.Navigate(typeof(MainPage), "https://google.com");
                }

                Window.Current.Activate();
                break;
            }
        }
Esempio n. 4
0
        public CommandLinePayload(CommandLineActivationOperation operation, IStorageFolder folder)
        {
            Operation         = operation;
            OriginalArguments = operation.Arguments;
            CurrentDirectory  = new NGFolder(folder);
            var parsedCommand = CommandLineUtilities.Parse(operation.Arguments);

            Command    = parsedCommand.Command;
            Parameters = parsedCommand.Parameters;
        }
Esempio n. 5
0
        protected override void OnActivated(IActivatedEventArgs args)
        {
            switch (args.Kind)
            {
            case ActivationKind.CommandLineLaunch:
                CommandLineActivatedEventArgs cmdLineArgs =
                    args as CommandLineActivatedEventArgs;
                CommandLineActivationOperation operation = cmdLineArgs.Operation;
                string cmdLineString  = operation.Arguments;
                string activationPath = operation.CurrentDirectoryPath;

                Frame rootFrame = Window.Current.Content as Frame;
                if (rootFrame == null)
                {
                    rootFrame = new Frame();
                    Window.Current.Content = rootFrame;
                }

                ParsedCommands parsedCommands =
                    CommandLineParser.ParseUntrustedArgs(cmdLineString);
                if (parsedCommands != null && parsedCommands.Count > 0)
                {
                    foreach (ParsedCommand command in parsedCommands)
                    {
                        switch (command.Type)
                        {
                        case ParsedCommandType.SelectItem:
                            rootFrame.Navigate(typeof(SelectItemPage), command.Payload);
                            break;

                        case ParsedCommandType.LoadConfig:
                            rootFrame.Navigate(typeof(LoadConfigPage), command.Payload);
                            break;

                        case ParsedCommandType.LoadFile:
                            string filePath = Path.Combine(activationPath, command.Payload);
                            rootFrame.Navigate(typeof(LoadFilePage), filePath);
                            break;

                        case ParsedCommandType.Unknown:
                            rootFrame.Navigate(typeof(HelpPage), cmdLineString);
                            break;
                        }
                    }
                }
                else
                {
                    rootFrame.Navigate(typeof(MainPage));
                }

                Window.Current.Activate();
                break;
            }
        }
Esempio n. 6
0
        protected override void OnActivated(IActivatedEventArgs args)
        {
            switch (args.Kind)
            {
            case ActivationKind.CommandLineLaunch:
                CommandLineActivatedEventArgs  cmdLineArgs = args as CommandLineActivatedEventArgs;
                CommandLineActivationOperation operation   = cmdLineArgs.Operation;
                string activationPath = operation.CurrentDirectoryPath;

                Frame rootFrame = Window.Current.Content as Frame;
                if (rootFrame == null)
                {
                    rootFrame = new Frame();
                    Window.Current.Content = rootFrame;
                }
                rootFrame.Navigate(typeof(MainPage), activationPath);
                Window.Current.Activate();
                break;
            }
        }
Esempio n. 7
0
        //Reference : https://docs.microsoft.com/en-us/uwp/api/windows.applicationmodel.activation.commandlineactivatedeventargs
        protected override void OnActivated(IActivatedEventArgs args)
        {
            string activationArgString = string.Empty;
            string activationPath      = string.Empty;
            string cmdLineString       = string.Empty;

            switch (args.Kind)
            {
            case ActivationKind.Launch:
                var launchArgs = args as LaunchActivatedEventArgs;
                activationArgString = launchArgs.Arguments;
                break;

            // A new ActivationKind for console activation of a windowed app.
            case ActivationKind.CommandLineLaunch:
                CommandLineActivatedEventArgs  cmdLineArgs = args as CommandLineActivatedEventArgs;
                CommandLineActivationOperation operation   = cmdLineArgs.Operation;
                cmdLineString  = operation.Arguments;
                activationPath = operation.CurrentDirectoryPath;
                break;
            }
        }
        // Learn more about these EventArgs at https://docs.microsoft.com/en-us/uwp/api/windows.applicationmodel.activation.commandlineactivatedeventargs
        protected override async Task HandleInternalAsync(CommandLineActivatedEventArgs args)
        {
            CommandLineActivationOperation operation = args.Operation;

            // Because these are supplied by the caller, they should be treated as untrustworthy.
            string cmdLineString = operation.Arguments;

            // The directory where the command-line activation request was made.
            // This is typically not the install location of the app itself, but could be any arbitrary path.
            string activationPath = operation.CurrentDirectoryPath;

            //// TODO WTS: parse the cmdLineString to determine what to do.
            //// If doing anything async, get a deferral first.
            //// using (var deferral = operation.GetDeferral())
            //// {
            ////     await ParseCmdString(cmdLineString, activationPath);
            //// }
            ////
            //// If the arguments warrant showing a different view on launch, that can be done here.
            //// NavigationService.Navigate(typeof(CmdLineActivationSamplePage), cmdLineString);
            //// If you do nothing, the app will launch like normal.

            await Task.CompletedTask;
        }
Esempio n. 9
0
        /// <summary>
        /// Called when the app view is activated. Activates the app's CoreWindow.
        /// </summary>
        private void OnViewActivated(CoreApplicationView sender, IActivatedEventArgs args)
        {
            // command line test
            // https://docs.microsoft.com/en-us/uwp/api/windows.applicationmodel.activation.commandlineactivatedeventargs
            switch (args.Kind)
            {
            case ActivationKind.Launch:
                var launchArgs          = args as LaunchActivatedEventArgs;
                var activationArgString = launchArgs.Arguments;
                break;

            // A new ActivationKind for console activation of a windowed app.
            case ActivationKind.CommandLineLaunch:
                CommandLineActivatedEventArgs  cmdLineArgs = args as CommandLineActivatedEventArgs;
                CommandLineActivationOperation operation   = cmdLineArgs.Operation;
                var cmdLineString  = operation.Arguments;
                var activationPath = operation.CurrentDirectoryPath;
                break;
            }
            //

            // Run() won't start until the CoreWindow is activated.
            sender.CoreWindow.Activate();
        }
Esempio n. 10
0
        protected override async void OnActivated(IActivatedEventArgs args)
        {
            switch (args.Kind)
            {
            case ActivationKind.CommandLineLaunch:
                CommandLineActivatedEventArgs cmdLineArgs =
                    args as CommandLineActivatedEventArgs;
                CommandLineActivationOperation operation = cmdLineArgs.Operation;
                string cmdLineString  = operation.Arguments;
                string activationPath = operation.CurrentDirectoryPath;

                string[] cmdArgs = cmdLineString.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);

                var mainPage = MainPage.Current;

                if (cmdArgs.Count() != 2)
                {
                    mainPage.NotifyUser("Invalid number of arguments. Usage: RadioControl.exe RADIO_INDEX_OR_NAME ON|OFF", MainPage.NotifyType.ErrorMessage);
                    return;
                }

                bool   isDeviceNumeric = false;
                int    deviceNumber    = 0;
                string deviceName      = "";
                try
                {
                    deviceNumber    = int.Parse(cmdArgs[0]);
                    isDeviceNumeric = true;
                } catch (FormatException)
                {
                    deviceName = cmdArgs[0];
                }

                bool actionEnable = false;
                if (cmdArgs[1].ToLower() == "on")
                {
                    actionEnable = true;
                }
                else if (cmdArgs[1].ToLower() != "off")
                {
                    mainPage.NotifyUser("Unsupported action '" + cmdArgs[1] + "'. Only 'on' and 'off' are supported.", MainPage.NotifyType.ErrorMessage);
                    return;
                }

                Debug.WriteLine("Will turn device " + (isDeviceNumeric ? deviceNumber.ToString() : deviceName) + " " + (actionEnable ? "on" : "off"));

                var accessLevel = await Radio.RequestAccessAsync();

                if (accessLevel != RadioAccessStatus.Allowed)
                {
                    mainPage.NotifyUser("Could not get access to radios. Allow it in Windows settings.", MainPage.NotifyType.ErrorMessage);
                    return;
                }
                else
                {
                    var radios = mainPage.radios;
                    for (int i = 0; i < radios.Count; i++)
                    {
                        var radio = radios[i];
                        if ((isDeviceNumeric && i == deviceNumber) || (!isDeviceNumeric && radio.Name.ToLower() == deviceName.ToLower()))
                        {
                            radio.IsRadioOn = actionEnable;
                            break;
                        }
                    }
                }

                break;
            }

            base.OnActivated(args);
        }
Esempio n. 11
0
        protected override async void OnActivated(IActivatedEventArgs args)
        {
            switch (args.Kind)
            {
            case ActivationKind.CommandLineLaunch:
                CommandLineActivatedEventArgs cmdLineArgs =
                    args as CommandLineActivatedEventArgs;
                CommandLineActivationOperation operation = cmdLineArgs.Operation;
                string cmdLineString  = operation.Arguments;
                string activationPath = operation.CurrentDirectoryPath;

                string[] cmdArgs = cmdLineString.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);

                if (cmdArgs.Count() != 2)
                {
                    ShowError("Invalid number of arguments. Usage: RadioControl.exe RADIO_INDEX_OR_NAME ON|OFF");
                    return;
                }

                bool   isDeviceNumeric = false;
                int    deviceNumber    = 0;
                string deviceName      = "";
                try
                {
                    deviceNumber    = int.Parse(cmdArgs[0]);
                    isDeviceNumeric = true;
                } catch (FormatException)
                {
                    deviceName = cmdArgs[0];
                }

                bool actionEnable = false;
                if (cmdArgs[1].ToLower() == "on")
                {
                    actionEnable = true;
                }
                else if (cmdArgs[1].ToLower() != "off")
                {
                    ShowError("Unsupported action '" + cmdArgs[1] + "'. Only 'on' and 'off' are supported.");
                    return;
                }

                var accessLevel = await Radio.RequestAccessAsync();

                if (accessLevel != RadioAccessStatus.Allowed)
                {
                    ShowError("Could not get access to radios. Allow it in Windows settings.");
                    return;
                }
                else
                {
                    var radios = await Radio.GetRadiosAsync();

                    for (int i = 0; i < radios.Count; i++)
                    {
                        var radio = radios[i];
                        if ((isDeviceNumeric && i == deviceNumber) || (!isDeviceNumeric && radio.Name.ToLower() == deviceName.ToLower()))
                        {
                            var radioState = actionEnable ? RadioState.On : RadioState.Off;
                            await radio.SetStateAsync(radioState);

                            CoreApplication.Exit();
                            return;
                        }
                    }

                    ShowError("Radio " + deviceName + "/" + deviceNumber + " was not found.");
                    return;
                }

                break;
            }
        }