public static void Main(string[] cmdArgs)
        {
            //if app isn't running with identity, register its sparse package
            if (!ExecutionMode.IsRunningWithIdentity())
            {
                //TODO - update the value of externalLocation to match the output location of your VS Build binaries and the value of
                //sparsePkgPath to match the path to your signed Sparse Package (.msix).
                //Note that these values cannot be relative paths and must be complete paths
                string externalLocation = @"";
                string sparsePkgPath    = @"";

                //Attempt registration
                if (registerSparsePackage(externalLocation, sparsePkgPath))
                {
                    //Registration succeded, restart the app to run with identity
                    System.Diagnostics.Process.Start(Application.ResourceAssembly.Location, arguments: cmdArgs?.ToString());
                }
                else //Registration failed, run without identity
                {
                    Debug.WriteLine("Package Registation failed, running WITHOUT Identity");
                    SingleInstanceManager wrapper = new SingleInstanceManager();
                    wrapper.Run(cmdArgs);
                }
            }
            else //App is registered and running with identity, handle launch and activation
            {
                //Handle Sparse Package based activation e.g Share target activation or clicking on a Tile
                // Launching the .exe directly will have activationArgs == null
                var activationArgs = AppInstance.GetActivatedEventArgs();
                if (activationArgs != null)
                {
                    switch (activationArgs.Kind)
                    {
                    case ActivationKind.Launch:
                        HandleLaunch(activationArgs as LaunchActivatedEventArgs);
                        break;

                    case ActivationKind.ToastNotification:
                        HandleToastNotification(activationArgs as ToastNotificationActivatedEventArgs);
                        break;

                    case ActivationKind.ShareTarget:
                        HandleShareAsync(activationArgs as ShareTargetActivatedEventArgs);
                        break;

                    default:
                        HandleLaunch(null);
                        break;
                    }
                }
                //This is a direct exe based launch e.g. double click app .exe or desktop shortcut pointing to .exe
                else
                {
                    SingleInstanceManager singleInstanceManager = new SingleInstanceManager();
                    singleInstanceManager.Run(cmdArgs);
                }
            }
        }
Beispiel #2
0
        public static void Main(string[] cmdArgs)
        {
            //Non-packaged version of app running
            if (!ExecutionMode.IsRunningWithIdentity())
            {
                Debug.WriteLine("Running non-packaged version");
                SingleInstanceManager wrapper = new SingleInstanceManager();
                wrapper.Run(cmdArgs);
            }
            else //App is packaged and running with identity, handle launch and other activation typed
            {
                //Handle Packaged Activation e.g Share target activation or clicking on a Tile
                // Launching the .exe directly will have activationArgs == null
                var activationArgs = AppInstance.GetActivatedEventArgs();
                if (activationArgs != null)
                {
                    switch (activationArgs.Kind)
                    {
                    case ActivationKind.Launch:
                        HandleLaunch(activationArgs as LaunchActivatedEventArgs);
                        break;

                    case ActivationKind.Protocol:
                        HandleProtocolActivation(activationArgs as ProtocolActivatedEventArgs);
                        break;

                    case ActivationKind.ToastNotification:
                        HandleToastNotification(activationArgs as ToastNotificationActivatedEventArgs);
                        break;

                    case ActivationKind.ShareTarget:
                        HandleShareAsync(activationArgs as ShareTargetActivatedEventArgs);
                        break;

                    default:
                        string path = $"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}//AppInstaller.txt";

                        System.IO.File.WriteAllText(path, activationArgs.ToString());
                        HandleLaunch(null);
                        break;
                    }
                }
                //This is a direct exe based launch e.g. double click app .exe or desktop shortcut pointing to .exe
                else
                {
                    if (cmdArgs[0] != null)
                    {
                        string path = $"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}//AppInstaller.txt";
                        System.IO.File.WriteAllText(path, cmdArgs[0]);
                    }
                    SingleInstanceManager singleInstanceManager = new SingleInstanceManager();
                    singleInstanceManager.Run(cmdArgs);
                }
            }
        }
Beispiel #3
0
        public static void Main(string[] cmdArgs)
        {
            //if app isn't running with identity, register its sparse package
            if (!ExecutionMode.IsRunningWithIdentity())
            {
                string externalLocation = @"C:\Users\tajimha.000\source\repos\tajimha\alacarte\SparsePkg\PhotoStoreDemo\bin\x64\Debug\";
                string sparsePkgPath    = @"C:\Users\tajimha.000\source\repos\tajimha\alacarte\SparsePkg\PhotoStoreDemo.msix";

                //Attempt registration
                if (registerSparsePackage(externalLocation, sparsePkgPath))
                {
                    //Registration succeded, restart the app to run with identity
                    System.Diagnostics.Process.Start(Application.ResourceAssembly.Location, arguments: cmdArgs?.ToString());
                }
                else //Registration failed, run without identity
                {
                    Debug.WriteLine("Package Registation failed, running WITHOUT Identity");
                    SingleInstanceManager wrapper = new SingleInstanceManager();
                    wrapper.Run(cmdArgs);
                }
            }
            else //App is registered and running with identity, handle launch and activation
            {
                //Handle Sparse Package based activation e.g Share target activation or clicking on a Tile
                // Launching the .exe directly will have activationArgs == null
                var activationArgs = AppInstance.GetActivatedEventArgs();
                if (activationArgs != null)
                {
                    switch (activationArgs.Kind)
                    {
                    case ActivationKind.Launch:
                        HandleLaunch(activationArgs as LaunchActivatedEventArgs);
                        break;

                    case ActivationKind.ToastNotification:
                        HandleToastNotification(activationArgs as ToastNotificationActivatedEventArgs);
                        break;

                    case ActivationKind.ShareTarget:
                        HandleShareAsync(activationArgs as ShareTargetActivatedEventArgs);
                        break;

                    default:
                        HandleLaunch(null);
                        break;
                    }
                }
                //This is a direct exe based launch e.g. double click app .exe or desktop shortcut pointing to .exe
                else
                {
                    SingleInstanceManager singleInstanceManager = new SingleInstanceManager();
                    singleInstanceManager.Run(cmdArgs);
                }
            }
        }
        static void HandleLaunch(LaunchActivatedEventArgs args)
        {
            Debug.Listeners.Add(new TextWriterTraceListener(Console.Out));
            Debug.AutoFlush = true;
            Debug.Indent();
            Debug.WriteLine("WPF App using a Sparse Package");


            SingleInstanceManager singleInstanceManager = new SingleInstanceManager();

            singleInstanceManager.Run(Environment.GetCommandLineArgs());
        }
Beispiel #5
0
        static void HandleToastNotification(ToastNotificationActivatedEventArgs args)
        {
            ValueSet userInput     = args.UserInput;
            string   pathFromToast = userInput["textBox"].ToString();

            ImageFile item = new ImageFile(pathFromToast);

            item.AddToCache();

            SingleInstanceManager singleInstanceManager = new SingleInstanceManager();

            singleInstanceManager.Run(Environment.GetCommandLineArgs());
        }
Beispiel #6
0
        static void HandleLaunch(LaunchActivatedEventArgs args)
        {
            string path = $"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}//AppInstaller.txt";

            if (args.Arguments != null)
            {
                System.IO.File.WriteAllText(path, args.Arguments);
            }
            else
            {
                System.IO.File.WriteAllText(path, "No arguments available");
            }


            SingleInstanceManager singleInstanceManager = new SingleInstanceManager();

            singleInstanceManager.Run(Environment.GetCommandLineArgs());
        }
Beispiel #7
0
        static async void HandleShareAsync(ShareTargetActivatedEventArgs args)
        {
            ShareOperation shareOperation = args.ShareOperation;

            if (shareOperation.Data.Contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.Bitmap))
            {
                try
                {
                    Stream    bitMapStream = (Stream)shareOperation.Data.GetBitmapAsync();
                    ImageFile image        = new ImageFile(bitMapStream);
                    image.AddToCache();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            if (shareOperation.Data.Contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.StorageItems))
            {
                try
                {
                    IReadOnlyList <IStorageItem> items = await shareOperation.Data.GetStorageItemsAsync();

                    IStorageFile file = (IStorageFile)items[0];
                    string       path = file.Path;

                    ImageFile image = new ImageFile(path);
                    image.AddToCache();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            shareOperation.ReportCompleted();
            SingleInstanceManager singleInstanceManager = new SingleInstanceManager();

            singleInstanceManager.Run(Environment.GetCommandLineArgs());
        }
        public static void Main(string[] args)
        {
            SingleInstanceManager wrapper = new SingleInstanceManager();

            wrapper.Run(args);
        }