Exemplo n.º 1
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

#if !DEBUG
            App.Tracker.Send(HitBuilder.CreateScreenView("Send").Build());
#endif
            PersistentDisplay.ActivatePersistentDisplay();

            if (Frame.BackStackDepth > 0)
            {
                if (Frame.BackStack[Frame.BackStackDepth - 1].SourcePageType == typeof(MainSend))
                {
                    Frame.BackStack.RemoveAt(Frame.BackStackDepth - 1);
                }
            }

            bool preserveFolderStructure = (Frame.BackStackDepth <= 0 || Frame.BackStack[Frame.BackStackDepth - 1].SourcePageType != typeof(PicturePicker));

            var rs = MainPage.Current.GetSelectedSystem();

            bool isDestinationAndroid;

            IRomePackageManager packageManager;
            if (rs is NormalizedRemoteSystem)
            {
                isDestinationAndroid = true;

                var nrs = rs as NormalizedRemoteSystem;

                if ((!string.IsNullOrEmpty(nrs.AppVersion)) &&
                    (Version.TryParse(nrs.AppVersion, out Version remoteAppVersion)) &&
                    (remoteAppVersion < new Version("2.1.4")))
                {
                    MainPage.Current.AndroidPackageManager.Mode = AndroidRomePackageManager.AndroidPackageManagerMode.MessageCarrier;
                }
                else
                {
                    PackageManagerHelper.InitAndroidPackageManagerMode();
                }
            }
            else
            {
                isDestinationAndroid = false;
            }

            string deviceName;

            var localDeviceInfo = NetworkInformation.GetHostNames().FirstOrDefault(name => name.DisplayName.EndsWith(".local"));
            if (localDeviceInfo != null)
            {
                deviceName = localDeviceInfo.DisplayName.Substring(0, localDeviceInfo.DisplayName.Length - ".local".Length);
            }
            else
            {
                deviceName = (new Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation()).FriendlyName;
            }

            var mode = e.Parameter.ToString();

            bool succeed = true;
            FileTransferResult fileTransferResult = FileTransferResult.Successful;
            try
            {
                if (mode == "launchUri")
                {
                    await LaunchUri(rs);
                }
                else if (mode == "text")
                {
                    string text           = SendDataTemporaryStorage.Text;
                    bool   fastSendResult = await TrySendFastClipboard(text, rs, deviceName);

                    if (fastSendResult)
                    {
                        SendTextFinished("");
                    }
                    else
                    {
                        SendTextFinished("Send failed. Text is too long.");
#if !DEBUG
                        App.Tracker.Send(HitBuilder.CreateCustomEvent("SendTextFailed", "TooLong").Build());
#endif
                        //ViewModel.ProgressPercentIndicatorVisibility = Visibility.Visible;
                        //var result = await Connect(rs);
                        //var connectResult = result.Item1;
                        //packageManager = result.Item2;

                        //if (connectResult != RomeAppServiceConnectionStatus.Success)
                        //{
                        //    HideEverything();

                        //    succeed = false;
                        //    string errorMessage;

                        //    if ((connectResult == RomeAppServiceConnectionStatus.RemoteSystemUnavailable) && (packageManager is AndroidRomePackageManager))
                        //    {
                        //        errorMessage = "Can't connect to device. Open Roamit on your Android device and then try again.";
                        //    }
                        //    else
                        //    {
                        //        errorMessage = connectResult.ToString();
                        //    }

                        //    Frame.Navigate(typeof(MainSendFailed), JsonConvert.SerializeObject(new SendFailedViewModel
                        //    {
                        //        ErrorTitle = "Can't connect",
                        //        ErrorDescription = errorMessage,
                        //    }));
                        //    return;
                        //}

                        //ViewModel.UnlockNoticeVisibility = Visibility.Collapsed;

                        //await SendText(packageManager, deviceName, text);
                    }
                }
                else if (mode == "file")
                {
                    ViewModel.ProgressPercentIndicatorVisibility = Visibility.Visible;
                    var result = await Connect(rs, openReceiveFileDialogIfOverCloud : true);

                    var connectResult = result.Item1;
                    packageManager = result.Item2;


                    if (connectResult != RomeAppServiceConnectionStatus.Success)
                    {
                        HideEverything();

                        succeed = false;
                        string errorMessage;

                        if ((connectResult == RomeAppServiceConnectionStatus.RemoteSystemUnavailable) && (packageManager is AndroidRomePackageManager))
                        {
                            errorMessage = "Can't connect to device. Open Roamit on your Android device and then try again.";
                        }
                        else
                        {
                            errorMessage = connectResult.ToString();
                        }

                        Frame.Navigate(typeof(MainSendFailed), JsonConvert.SerializeObject(new SendFailedViewModel
                        {
                            ErrorTitle       = "Can't connect",
                            ErrorDescription = errorMessage,
                        }));
                        return;
                    }

                    ViewModel.UnlockNoticeVisibility = Visibility.Collapsed;
                    if (!isDestinationAndroid)
                    {
                        ViewModel.LeaveScreenOnNoticeVisibility = Visibility.Visible;
                    }

                    fileTransferResult = await SendFile(rs, packageManager, deviceName, preserveFolderStructure);

                    if (fileTransferResult != FileTransferResult.Successful)
                    {
                        succeed = false;
                        return;
                    }

                    if (!isDestinationAndroid)
                    {
                        ViewModel.LeaveScreenOnNoticeVisibility = Visibility.Collapsed;
                    }
                }
                else
                {
                    succeed = false;
                    Frame.Navigate(typeof(MainSendFailed), JsonConvert.SerializeObject(new SendFailedViewModel
                    {
                        ErrorTitle       = "Invalid parameter",
                        ErrorDescription = "[MainSend]",
                    }));
                    return;
                }
            }
            finally
            {
                PersistentDisplay.ReleasePersistentDisplay();
#if !DEBUG
                if (rs is NormalizedRemoteSystem)
                {
                    App.Tracker.Send(HitBuilder.CreateCustomEvent("SendToAndroid", mode, succeed ? "Success" : ((mode == "file") ? fileTransferResult.ToString() : "Failed")).Build());
                }
                else
                {
                    App.Tracker.Send(HitBuilder.CreateCustomEvent("SendToWindows", mode, succeed ? "Success" : ((mode == "file") ? fileTransferResult.ToString() : "Failed")).Build());
                }
#endif
                sendingFile = false;
            }

            if (SendDataTemporaryStorage.IsSharingTarget)
            {
                if (App.ShareOperation == null)
                {
#if !DEBUG
                    App.Tracker.Send(HitBuilder.CreateCustomEvent("Send", "UriTarget").Build());
#endif
                    await Task.Delay(TimeSpan.FromSeconds(1.5));

                    App.Current.Exit();
                }
                else
                {
#if !DEBUG
                    App.Tracker.Send(HitBuilder.CreateCustomEvent("Send", "ShareTarget").Build());
#endif
                    await Task.Delay(TimeSpan.FromSeconds(1.5));

                    App.ShareOperation.ReportCompleted();
                }
                SendDataTemporaryStorage.IsSharingTarget = false;
                App.ShareOperation = null;
            }
            else
            {
                ViewModel.GoBackButtonVisibility = Visibility.Visible;
                GoBackButtonShowStoryboard.Begin();

                if (succeed)
                {
                    await AskForReviewIfNecessary();
                }

#if !DEBUG
                App.Tracker.Send(HitBuilder.CreateCustomEvent("Send", "WithinApp").Build());
#endif
            }
        }
Exemplo n.º 2
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

#if !DEBUG
            App.Tracker.Send(HitBuilder.CreateScreenView("Send").Build());
#endif
            PersistentDisplay.ActivatePersistentDisplay();

            if (Frame.BackStackDepth > 0)
            {
                if (Frame.BackStack[Frame.BackStackDepth - 1].SourcePageType == typeof(MainSend))
                {
                    Frame.BackStack.RemoveAt(Frame.BackStackDepth - 1);
                }
            }

            var rs = MainPage.Current.GetSelectedSystem();

            bool isDestinationAndroid;

            IRomePackageManager packageManager;
            if (rs is NormalizedRemoteSystem)
            {
                isDestinationAndroid = true;
                packageManager       = MainPage.Current.AndroidPackageManager;

                var nrs = rs as NormalizedRemoteSystem;

                if ((!string.IsNullOrEmpty(nrs.AppVersion)) &&
                    (Version.TryParse(nrs.AppVersion, out Version remoteAppVersion)) &&
                    (remoteAppVersion < new Version("2.1.4")))
                {
                    MainPage.Current.AndroidPackageManager.Mode = AndroidRomePackageManager.AndroidPackageManagerMode.MessageCarrier;
                }
                else
                {
                    PackageManagerHelper.InitAndroidPackageManagerMode();
                }
            }
            else
            {
                isDestinationAndroid = false;
                packageManager       = MainPage.Current.PackageManager;
            }

            string deviceName = (new Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation()).FriendlyName;
            var    mode       = e.Parameter.ToString();

            if ((mode == "file") && (!(await IsAllowedToSendAsync())))
            {
                ViewModel.SendStatus = "";

                await TrialHelper.AskForUpgradeWhileSending();

                if (!(await IsAllowedToSendAsync()))
                {
#if !DEBUG
                    App.Tracker.Send(HitBuilder.CreateCustomEvent("Send", "AskedToUpgrade", "Rejected").Build());
#endif
                    PersistentDisplay.ReleasePersistentDisplay();
                    Frame.GoBack();
                    return;
                }
#if !DEBUG
                App.Tracker.Send(HitBuilder.CreateCustomEvent("Send", "AskedToUpgrade", "Accepted").Build());
#endif
                ViewModel.SendStatus = "Connecting...";
            }

            bool succeed = true;
            FileTransferResult fileTransferResult = FileTransferResult.Successful;
            try
            {
                if (mode == "launchUri")
                {
                    await LaunchUri(rs);
                }
                else if (mode == "text")
                {
                    string text           = SendDataTemporaryStorage.Text;
                    bool   fastSendResult = await TrySendFastClipboard(text, rs, deviceName);

                    if (fastSendResult)
                    {
                        SendTextFinished("");
                    }
                    else
                    {
                        ViewModel.ProgressPercentIndicatorVisibility = Visibility.Visible;
                        RomeAppServiceConnectionStatus result = await Connect(rs);

                        if (result != RomeAppServiceConnectionStatus.Success)
                        {
                            HideEverything();

                            succeed = false;
                            string errorMessage;

                            if ((result == RomeAppServiceConnectionStatus.RemoteSystemUnavailable) && (packageManager is AndroidRomePackageManager))
                            {
                                errorMessage = "Can't connect to device. Open Roamit on your Android device and then try again.";
                            }
                            else
                            {
                                errorMessage = result.ToString();
                            }

                            await(new MessageDialog(errorMessage, "Can't connect")).ShowAsync();
                            Frame.GoBack();
                            return;
                        }

                        ViewModel.UnlockNoticeVisibility = Visibility.Collapsed;

                        await SendText(packageManager, deviceName, text);
                    }
                }
                else if (mode == "file")
                {
                    ViewModel.ProgressPercentIndicatorVisibility = Visibility.Visible;
                    RomeAppServiceConnectionStatus result = await Connect(rs);

                    if (result != RomeAppServiceConnectionStatus.Success)
                    {
                        HideEverything();

                        succeed = false;
                        string errorMessage;

                        if ((result == RomeAppServiceConnectionStatus.RemoteSystemUnavailable) && (packageManager is AndroidRomePackageManager))
                        {
                            errorMessage = "Can't connect to device. Open Roamit on your Android device and then try again.";
                        }
                        else
                        {
                            errorMessage = result.ToString();
                        }

                        await(new MessageDialog(errorMessage, "Can't connect")).ShowAsync();
                        Frame.GoBack();
                        return;
                    }

                    ViewModel.UnlockNoticeVisibility = Visibility.Collapsed;
                    if (!isDestinationAndroid)
                    {
                        ViewModel.LeaveScreenOnNoticeVisibility = Visibility.Visible;
                    }

                    fileTransferResult = await SendFile(rs, packageManager, deviceName);

                    if (fileTransferResult != FileTransferResult.Successful)
                    {
                        HideEverything();

                        succeed = false;
                        Frame.GoBack();
                        return;
                    }

                    if (!isDestinationAndroid)
                    {
                        ViewModel.LeaveScreenOnNoticeVisibility = Visibility.Collapsed;
                    }
                }
                else
                {
                    succeed = false;
                    await(new MessageDialog("MainSend::Invalid parameter.")).ShowAsync();
                    Frame.GoBack();
                    return;
                }
            }
            finally
            {
                PersistentDisplay.ReleasePersistentDisplay();
#if !DEBUG
                if (rs is NormalizedRemoteSystem)
                {
                    App.Tracker.Send(HitBuilder.CreateCustomEvent("SendToAndroid", mode, succeed ? "Success" : ((mode == "file") ? fileTransferResult.ToString() : "Failed")).Build());
                }
                else
                {
                    App.Tracker.Send(HitBuilder.CreateCustomEvent("SendToWindows", mode, succeed ? "Success" : ((mode == "file") ? fileTransferResult.ToString() : "Failed")).Build());
                }
#endif
                sendingFile = false;
            }

            if (SendDataTemporaryStorage.IsSharingTarget)
            {
                if (App.ShareOperation == null)
                {
#if !DEBUG
                    App.Tracker.Send(HitBuilder.CreateCustomEvent("Send", "UriTarget").Build());
#endif
                    await Task.Delay(TimeSpan.FromSeconds(1.5));

                    App.Current.Exit();
                }
                else
                {
#if !DEBUG
                    App.Tracker.Send(HitBuilder.CreateCustomEvent("Send", "ShareTarget").Build());
#endif
                    await Task.Delay(TimeSpan.FromSeconds(1.5));

                    App.ShareOperation.ReportCompleted();
                }
                SendDataTemporaryStorage.IsSharingTarget = false;
                App.ShareOperation = null;
            }
            else
            {
                ViewModel.GoBackButtonVisibility = Visibility.Visible;
                GoBackButtonShowStoryboard.Begin();

                if (succeed)
                {
                    await AskForReviewIfNecessary();
                }

#if !DEBUG
                App.Tracker.Send(HitBuilder.CreateCustomEvent("Send", "WithinApp").Build());
#endif
            }
        }