Example #1
0
        public void Copy()
        {
            try
            {
                if (_share.Data.Properties.ApplicationName != Constants.ApplicationName)
                {
                    _share.ReportSubmittedBackgroundTask();

                    var content = new DataPackage();
                    _values.CopyTo(content);

                    Windows.ApplicationModel.DataTransfer.Clipboard.SetContent(content);
                    Windows.ApplicationModel.DataTransfer.Clipboard.Flush();
                    Windows.ApplicationModel.DataTransfer.Clipboard.ContentChanged += OnClipboardContentChanged;

                    _share.DismissUI();
                }
                else
                {
                    _share.ReportCompleted();
                }
            }
            catch (Exception ex)
            {
                _share.ReportError(ex.Message);
            }
        }
Example #2
0
        public async void AddApp()
        {
            shareOperation.ReportStarted();
            var database = new Database();
            await database.Add(AppInfo);

            App.InvokeAppAdded();
            Analytics.TrackEvent("NewAppAdded");
            shareOperation.ReportCompleted();
        }
        private async void OnReportSuccessClick(Object sender, RoutedEventArgs e)
        {
            var useQuickLink = (Boolean)(DefaultViewModel["UseQuickLink"] ?? false);

            if (useQuickLink)
            {
                // Make sure a thumbnail is available
                if (_shareOperation.Data.Properties.Square30x30Logo == null)
                {
                    return;
                }
                var quickLinkThumbnail = RandomAccessStreamReference.CreateFromStream(await _shareOperation.Data.Properties.Square30x30Logo.OpenReadAsync());

                // Make sure a title is available
                var quickLinkTitle = (DefaultViewModel["QuickLinkTitle"] ?? String.Empty).ToString();
                if (String.IsNullOrWhiteSpace(quickLinkTitle))
                {
                    return;
                }

                var quickLinkTag = (DefaultViewModel["QuickLinkTag"] ?? String.Empty).ToString();
                if (String.IsNullOrWhiteSpace(quickLinkTag))
                {
                    return;
                }

                var quickLink = new QuickLink
                {
                    SupportedFileTypes = { "*" },
                    Thumbnail          = quickLinkThumbnail,
                    Title = quickLinkTitle,
                    Id    = quickLinkTag,
                };

                // Just reuse the current set of data formats, though it could be selective
                // based on the context of how the id value will be used.
                var quickLinkFormats = _shareOperation.Data.AvailableFormats;
                foreach (var item in quickLinkFormats)
                {
                    quickLink.SupportedDataFormats.Add(item);
                }

                _shareOperation.ReportCompleted(quickLink);
            }
            else
            {
                // Close the UI and inform Windows that the sharing completed succesfully
                _shareOperation.ReportCompleted();
            }
        }
Example #4
0
 private async void Save_Click(object sender, RoutedEventArgs e)
 {
     if (String.IsNullOrWhiteSpace(Title_TextBox.Text))
     {
         var dialog = new ContentDialog
         {
             Title             = "请输入标题",
             PrimaryButtonText = "确定"
         };
         await dialog.ShowAsync();
     }
     else
     {
         using (var conn = ConnectMemoDatabase.GetMemoDbConnect())
         {
             var AddMemo = new Memo();
             AddMemo.Title     = Title_TextBox.Text;
             AddMemo.Memo_Date = Calendar_TextBlock.Text;
             AddMemo.Body      = Content_TextBox.Text;
             conn.Insert(AddMemo);
             shrOpration?.ReportCompleted();
             if (Frame.CanGoBack)
             {
                 Frame.GoBack();
             }
         }
     }
 }
Example #5
0
        protected override void WireMessages()
        {
            Messenger.Default.Register <NotificationMessage>(this, m =>
            {
                if (m.Notification.Equals(Constants.Messages.ReaderViewLeftMsg))
                {
                    ShowFinishedScreen = false;
                    if (_readerTimer != null && _readerTimer.IsEnabled)
                    {
                        _readerTimer.Stop();
                    }

                    var wordsRead          = SelectedIndex * _settingsService.WordsAtATime;
                    var articleNotFinished = wordsRead < SelectedItem.WordCount;
                    if (articleNotFinished)
                    {
                        _roamingSettings.Set(SelectedItem.InternalId, wordsRead);
                    }
                    else
                    {
                        _roamingSettings.Remove(SelectedItem.InternalId);
                    }

                    SaveInProgressItems(wordsRead, !articleNotFinished);
                }
            });

            Messenger.Default.Register <ShareMessage>(this, async m =>
            {
                _shareOperation = (ShareOperation)m.Sender;
                if (_shareOperation.Data.Contains(StandardDataFormats.WebLink))
                {
                    var url     = await _shareOperation.Data.GetWebLinkAsync();
                    var message = new UriSchemeMessage(url.ToString(), true, SchemeType.Read);

                    await SaveItemFromExternal(message, async() =>
                    {
                        var title = _loader.GetString("ShareErrorTitle");
                        await _messageBox.ShowAsync(_loader.GetString("ShareErrorText"), title, new List <string> {
                            _loader.GetString("MessageBoxOk")
                        });
                        _shareOperation.ReportError(title);
                    });
                }
                else
                {
                    _shareOperation.ReportCompleted();
                }
            });

            Messenger.Default.Register <UriSchemeMessage>(this, async m =>
            {
                if (m.SchemeType != SchemeType.Read)
                {
                    return;
                }

                await SaveItemFromExternal(m);
            });
        }
        private async void ShareBtn_Click(object sender, RoutedEventArgs e)
        {
            await file.CopyAsync(ApplicationData.Current.LocalFolder);

            operation.ReportCompleted();
            await Windows.ApplicationModel.FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();
        }
        public async Task Share()
        {
            Sharing = true;
            ShareOperation.ReportStarted();
            var multa = new CriarMultaNova
            {
                Descricao = dadosDaMulta.Descricao,
                Placa     = dadosDaMulta.Placa,
                VideoUrl  = dadosDaMulta.VideoUrl
            };

            multa.SetaDataOcorrencia(dadosDaMulta.DataOcorrencia);
            try
            {
                MultadoComSucesso = await talao.MultarAsync(multa, fileInfo);

                if (MultadoComSucesso)
                {
                    Sharing = false;
                    ShareOperation.ReportCompleted();
                }
                else
                {
                    ShareOperation.ReportError("Não foi possível multar, favor tentar mais tarde.");
                }
            }
            catch (Exception ex)
            {
                ShareOperation.ReportError("Não foi possível multar, ocorreu um erro, favor tentar mais tarde.\nErro:" + ex.Message);
            }
        }
Example #8
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            // refer to https://msdn.microsoft.com/en-us/library/windows/apps/mt243292.aspx
            ShareOperation shareOperation = (ShareOperation)e.Parameter;
            Uri            uri;
            string         url = "";

            if (shareOperation.Data.Contains(StandardDataFormats.WebLink)) // URI
            {
                uri = await shareOperation.Data.GetWebLinkAsync();

                url = uri.AbsoluteUri;

                Debug.WriteLine("Uri: " + url);
            }

            if (url.StartsWith("http"))
            {
                // refer to https://msdn.microsoft.com/library/windows/apps/mt228341
                uri = new Uri($"alwaysontop://?q={Uri.EscapeDataString(url)}");
                var success = await Windows.System.Launcher.LaunchUriAsync(uri);
            }

            // Share completed
            shareOperation.ReportCompleted();
        }
Example #9
0
 private void CheckAndClearShareOperation()
 {
     if (_shareOperation != null)
     {
         _shareOperation.ReportCompleted();
         _shareOperation = null;
     }
 }
Example #10
0
        private void SaveContent()
        {
            var quickLink = new QuickLink
            {
                Id    = "LL.ShareTarget",
                Title = "Share Target"
            };

            _shareOperation.ReportCompleted(quickLink);
        }
Example #11
0
        async void ReportCompleted_Click(object sender, RoutedEventArgs e)
        {
            if (AddQuickLink.IsChecked.Equals(true))
            {
                QuickLink quickLinkInfo = new QuickLink
                {
                    Id    = QuickLinkId.Text,
                    Title = QuickLinkTitle.Text,

                    // For QuickLinks, the supported FileTypes and DataFormats are set independently from the manifest.
                    SupportedFileTypes   = { "*" },
                    SupportedDataFormats =
                    {
                        StandardDataFormats.Text,
                        StandardDataFormats.WebLink,
                        StandardDataFormats.ApplicationLink,
                        StandardDataFormats.Bitmap,
                        StandardDataFormats.StorageItems,
                        StandardDataFormats.Html,
                        dataFormatName
                    }
                };

                try
                {
                    StorageFile iconFile = await Package.Current.InstalledLocation.CreateFileAsync("assets\\user.png", CreationCollisionOption.OpenIfExists);

                    quickLinkInfo.Thumbnail = RandomAccessStreamReference.CreateFromFile(iconFile);
                    m_shareOperation.ReportCompleted(quickLinkInfo);
                }
                catch (Exception)
                {
                    // Even if the QuickLink cannot be created it is important to call ReportCompleted. Otherwise, if this is a long-running share,
                    // the app will stick around in the long-running share progress list.
                    m_shareOperation.ReportCompleted();
                    throw;
                }
            }
            else
            {
                m_shareOperation.ReportCompleted();
            }
        }
Example #12
0
        private async void OnReportSuccessClick(Object sender, RoutedEventArgs e)
        {
            var useQuickLink = (Boolean)(DefaultViewModel["UseQuickLink"] ?? false);

            if (useQuickLink)
            {
                // Make sure a thumbnail is available
                if (_shareOperation.Data.Properties.Square30x30Logo == null)
                {
                    return;
                }
                var quickLinkThumbnail = RandomAccessStreamReference.CreateFromStream(await _shareOperation.Data.Properties.Square30x30Logo.OpenReadAsync());

                // Make sure a title is available
                var quickLinkTitle = (DefaultViewModel["QuickLinkTitle"] ?? String.Empty).ToString();
                if (String.IsNullOrWhiteSpace(quickLinkTitle))
                {
                    return;
                }

                var quickLinkTag = (DefaultViewModel["QuickLinkTag"] ?? String.Empty).ToString();
                if (String.IsNullOrWhiteSpace(quickLinkTag))
                {
                    return;
                }

                var quickLink = new QuickLink
                {
                    Id = quickLinkTag,
                    SupportedDataFormats = { StandardDataFormats.Bitmap },
                    SupportedFileTypes   = { "*" },
                    Thumbnail            = quickLinkThumbnail,
                    Title = quickLinkTitle
                };
                _shareOperation.ReportCompleted(quickLink);
            }
            else
            {
                // Close the UI and inform Windows that the sharing completed succesfully
                _shareOperation.ReportCompleted();
            }
        }
Example #13
0
        protected override async void OnShareTargetActivated(ShareTargetActivatedEventArgs args)
        {
            ShareOperation shareOperation = args.ShareOperation;

            if (shareOperation.Data.Contains(StandardDataFormats.WebLink))
            {
                Uri uri = await shareOperation.Data.GetWebLinkAsync();

                await Windows.System.Launcher.LaunchUriAsync(new Uri("compactview:?" + Uri.EscapeDataString(uri.ToString())));
            }
            shareOperation.ReportCompleted();
        }
Example #14
0
        protected override async void OnShareTargetActivated(ShareTargetActivatedEventArgs args)
        {
            ShareOperation shareOperation = args.ShareOperation;

            if (shareOperation.Data.Contains(StandardDataFormats.StorageItems))
            {
                var sis = await shareOperation.Data.GetStorageItemsAsync();

                shareOperation.ReportStarted();
            }

            shareOperation.ReportCompleted();
        }
Example #15
0
        private void ShareButton_Click(object sender, RoutedEventArgs e)
        {
            DefaultViewModel["Sharing"] = true;
            _ShareOperation.ReportStarted();

            var link = DefaultViewModel["Link"] as Link;

            if (link != null)
            {
                var linkService = ServiceLocator.Current.GetInstance <ILinkService>();
                linkService.Add(link);
            }

            _ShareOperation.ReportCompleted();
        }
Example #16
0
        protected override async void OnShareTargetActivated(ShareTargetActivatedEventArgs args)
        {
            ShareOperation shareOperation = args.ShareOperation;

            new MessageDialog(shareOperation.Data.ToString(), "消息提示").ShowAsync();
            shareOperation.ReportCompleted();

            /*if (shareOperation.Data.Contains(StandardDataFormats.Text))
             * {
             *  string text = await shareOperation.Data.GetTextAsync();
             *  new MessageDialog(text, "消息提示").ShowAsync();
             *  // To output the text from this example, you need a TextBlock control
             *  // with a name of "sharedContent".
             *  //sharedContent.Text = "Text: " + text;
             * }*/
        }
        async private void SaveCustomer(object sender, RoutedEventArgs e)
        {
            _customer.CustomerName = txt_name.Text;
            _customer.Email        = txt_email.Text;
            _customer.DOB          = control_dob.Date.Date;
            App.State.Customers.Add(_customer);
            await App.State.SaveAsync();

            if (_share_activated)
            {
                _share.ReportCompleted();
            }
            else
            {
                Frame.GoBack();
            }
        }
Example #18
0
 private void CreateButton_Click(object sender, RoutedEventArgs e)
 {
     Models.TodoItem TodoToCreate = new Models.TodoItem(TitleTextBox.Text,
                                                        DetailTextBox.Text, DueDatePicker.Date, TodoImage.Source, ImageFile);
     if (shareOp == null)
     {
         if (TodoToCreate.TodoInfoValidator())
         {
             ViewModel.AddTodoItem(TodoToCreate);
             ViewModel.NewestItem = TodoToCreate;
             Frame.Navigate(typeof(MainPage), ViewModel);
         }
     }
     else
     { // on sharing
         shareOp.ReportCompleted();
     }
 }
Example #19
0
        public async Task ActivateAsync(ShareTargetActivatedEventArgs args)
        {
            // <Snippetcs_HandleSharedText>
            ShareOperation shareOperation = args.ShareOperation;

            if (shareOperation.Data.Contains(StandardDataFormats.Text))
            {
                string text = await shareOperation.Data.GetTextAsync();

                // To output the text from this example, you need a TextBlock control
                // with a name of "sharedContent".
                sharedContent.Text = "Text: " + text;
            }
            // </Snippetcs_HandleSharedText>

            if (shareOperation.Data.Contains(StandardDataFormats.StorageItems))
            {
                // <Snippetcs_ReportStarted>
                shareOperation.ReportStarted();
                // </Snippetcs_ReportStarted>
                IReadOnlyList <IStorageItem> storageItems = null;
                storageItems = await shareOperation.Data.GetStorageItemsAsync();

                string fileList = String.Empty;

                for (int index = 0; index < storageItems.Count; index++)
                {
                    fileList += storageItems[index].Name;
                    if (index < storageItems.Count - 1)
                    {
                        fileList += ", ";
                    }
                }

                // To output the text from this example, you need a TextBlock control
                // with a name of "sharedContent".
                sharedContent.Text += "StorageItems: " + fileList + Environment.NewLine;

                shareOperation.ReportCompleted();
            }

            Window.Current.Content = this;
            Window.Current.Activate();
        }
Example #20
0
        // Note that the following code if for snippeting only. It's not actually called in
        // this app. It's derived from the SharingTarget sample, so I'm confident it works.

        // <Snippetcs_HowToCreateAQuickLink>
        async void ReportCompleted(ShareOperation shareOperation, string quickLinkId, string quickLinkTitle)
        {
            QuickLink quickLinkInfo = new QuickLink
            {
                Id    = quickLinkId,
                Title = quickLinkTitle,

                // For quicklinks, the supported FileTypes and DataFormats are set
                // independently from the manifest
                SupportedFileTypes   = { "*" },
                SupportedDataFormats = { StandardDataFormats.Text,   StandardDataFormats.Uri,
                                         StandardDataFormats.Bitmap, StandardDataFormats.StorageItems }
            };

            StorageFile iconFile = await Windows.ApplicationModel.Package.Current.InstalledLocation.CreateFileAsync(
                "assets\\user.png", CreationCollisionOption.OpenIfExists);

            quickLinkInfo.Thumbnail = RandomAccessStreamReference.CreateFromFile(iconFile);
            shareOperation.ReportCompleted(quickLinkInfo);
        }
        private async void ShareButton_Click(object sender, RoutedEventArgs e)
        {
            if (file != null)
            {
                // copy file to app's local folder. Desktop Bridge app will detect new file with its FileWatcher
                try
                {
                    await file.CopyAsync(ApplicationData.Current.LocalFolder, file.Name, NameCollisionOption.ReplaceExisting);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("ShareButton_Click Error:" + ex.Message);
                }
            }

            if (operation != null)
            {
                operation.ReportCompleted();
            }
        }
Example #22
0
        private async void AppBarButton_Click_1(object sender, RoutedEventArgs e)
        {
            var result = await PostManagement.PostActivity(contentTextBox.Text, selectedItems, link, selectedEmoticon, reshareId, place, imageContent);

            if (result == 0)
            {
                if (operation != null)
                {
                    operation.ReportCompleted();
                }
                if (this.Frame.CanGoBack)
                {
                    this.Frame.GoBack();
                }
            }
            else
            {
                var messageDialog = new MessageDialog("Cannot into. Contact with developer.");
                await messageDialog.ShowAsync();
            }
        }
Example #23
0
        public ShareTargetPage()
        {
            InitializeComponent();
            ViewModel.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == nameof(ViewModel.AddingTask))
                {
                    AddStoryboard.Begin();

                    ViewModel.AddingTask.PropertyChanged += (sender, args) =>
                    {
                        if (args.PropertyName == "IsCompleted")
                        {
                            CompletedStoryboard.Begin();
                        }
                    };
                }
            };

            CompletedStoryboard.Completed += (s, e) => _shareOperation.ReportCompleted();
        }
Example #24
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());
        }
Example #25
0
        private async void sendButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (channelsBox.SelectedItem is DiscordChannel channel)
                {
                    if (_file != null)
                    {
                        overlay.Visibility = Visibility.Visible;
                        ring.Value         = 0;
                        subtext.Opacity    = 1;

                        var progress = new Progress <double?>(p => ring.Value = p ?? 0d);
                        var stream   = await _file.OpenReadAsync();

                        var dictionary = new Dictionary <string, IInputStream>()
                        {
                            [_file.Name] = stream
                        };
                        await Tools.SendFilesWithProgressAsync(channel, captionText.Text, null, null, dictionary, progress);
                    }
                    else if (!string.IsNullOrWhiteSpace(captionText.Text))
                    {
                        await channel.SendMessageAsync(captionText.Text);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
                await UIUtilities.ShowErrorDialogAsync("Sending failed!", ex.Message);

                _shareOperation.ReportError(ex.Message);
                return;
            }

            _shareOperation.ReportCompleted();
            //_shareOperation.DismissUI();
        }
Example #26
0
        private async void AddButton_Click(object sender, RoutedEventArgs e)
        {
            AddButton.IsEnabled                 = false;
            AddCategoryButton.IsEnabled         = false;
            LoadingControl.IsLoading            = true;
            LoadingControlMessageTextBlock.Text = new Windows.ApplicationModel.Resources.ResourceLoader().GetString("AddSoundsMessage");

            List <Guid> categoryUuids = new List <Guid>();

            foreach (var item in CategoriesListView.SelectedItems)
            {
                var category = (Category)item;
                categoryUuids.Add(category.Uuid);
            }

            if (items.Count > 0)
            {
                foreach (StorageFile storagefile in items)
                {
                    if (FileManager.allowedFileTypes.Contains(storagefile.FileType))
                    {
                        await FileManager.AddSoundAsync(Guid.Empty, storagefile.DisplayName, categoryUuids, storagefile);
                    }
                }
                await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    FileManager.itemViewHolder.AllSoundsChanged = true;
                });
            }

            await dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
            {
                await FileManager.UpdateGridViewAsync();
            });

            shareOperation.ReportCompleted();
        }
Example #27
0
        /*
         * 关于 QuickLink 的相关说明如下
         * 注:经测试,在我的 windows 10 环境中,此部分内容无效(应该是 windows 10 已经不再支持 QuickLink 了)
         *
         * ShareOperation - 分享操作的相关信息
         *     QuickLinkId - 如果是 QuickLink 激活的,此属性可获取此 QuickLink 的 Id
         *     RemoveThisQuickLink() - 如果是 QuickLink 激活的,此方法可删除此 QuickLink
         *     ReportCompleted(QuickLink quicklink) - 指定一个需要增加的 QuickLink 对象,然后通知系统分享操作已经完成(会自动关闭分享面板)
         *
         * QuickLink - 预定义了一些数据,指向相应分享目标的一个快捷方式,其会出现在分享面板的上部
         *     Id - 预定义数据
         *     Title - QuickLink 出现在分享面板上的时候所显示的名称
         *     Thumbnail - QuickLink 出现在分享面板上的时候所显示的图标
         *     SupportedDataFormats - 分享数据中所包含的数据格式与此定义相匹配(有一个匹配即可),QuickLink 才会出现在分享面板上
         *     SupportedFileTypes - 分享数据中所包含的文件的扩展名与此定义的相匹配(有一个匹配即可),QuickLink 才会出现在分享面板上
         *
         * QuickLink 的适用场景举例
         * 1、当用户总是分享信息到某一个邮件地址时,便可以在分享目标中以此邮件地址为 QuickLinkId 生成一个 QuickLink
         * 2、下回用户再分享时,此 QuickLink 就会出现在分享面板上,用户在分享面板上可以点击此 QuickLink 激活分享目标
         * 3、分享目标被 QuickLink 激活后便可以通过 ShareOperation 对象获取到 QuickLink,然后就可以拿到用户需要分享到的邮件地址(就是 QuickLink 的 Id),从而避免用户输入此邮件地址,从而方便用户的分享操作
         */

        // 演示如何增加一个 QuickLink
        private async void Button_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            OutputMessage("QuickLinkId: " + _shareOperation.QuickLinkId);

            QuickLink quickLink = new QuickLink
            {
                Id    = "*****@*****.**",
                Title = "分享到邮件: [email protected]", // QuickLink 在分享面板上显示的内容

                SupportedFileTypes   = { "*" },
                SupportedDataFormats =
                {
                    StandardDataFormats.Text,
                    StandardDataFormats.WebLink,
                    StandardDataFormats.ApplicationLink,
                    StandardDataFormats.Bitmap,
                    StandardDataFormats.StorageItems,
                    StandardDataFormats.Html,
                    "http://webabcd/sharedemo"
                }
            };

            try
            {
                // 设置 QuickLink 在分享面板上显示的图标
                StorageFile iconFile = await Package.Current.InstalledLocation.CreateFileAsync("Assets\\StoreLogo.png", CreationCollisionOption.OpenIfExists);

                quickLink.Thumbnail = RandomAccessStreamReference.CreateFromFile(iconFile);

                // 完成分享操作,同时在分享面板上增加一个指定的 QuickLink
                _shareOperation.ReportCompleted(quickLink);
            }
            catch (Exception ex)
            {
                OutputMessage(ex.ToString());
            }
        }
Example #28
0
 public void Share()
 {
     operation.ReportCompleted();
 }
Example #29
0
 public void Complete()
 {
     ShareOperation.ReportCompleted();
 }
        public StatusShareContractViewModel()
        {
            var uiThreadScheduler = new SynchronizationContextScheduler(SynchronizationContext.Current);

            Model = new StatusShareContractModel();

            IsEnableShareOperation = new ReactiveProperty <bool>(uiThreadScheduler,
                                                                 AdvancedSettingService.AdvancedSetting.Accounts?.Count > 0);

            if (IsEnableShareOperation.Value)
            {
                Accounts = new ReactiveCollection <ShareAccountViewModel>(
                    AdvancedSettingService.AdvancedSetting.Accounts.Select(x => new ShareAccountViewModel
                {
                    AccountSetting = new ReactiveProperty <AccountSetting>(x),
                    IsTweetEnabled = new ReactiveProperty <bool>(x.IsEnabled)
                })
                    .ToObservable(), uiThreadScheduler);
                SelectedAccounts = Accounts.ObserveElementObservableProperty(x => x.IsTweetEnabled)
                                   .Select(y => Accounts.Where(z => z.IsTweetEnabled.Value))
                                   .ToReactiveProperty(uiThreadScheduler);
            }
            else
            {
                Accounts         = new ReactiveCollection <ShareAccountViewModel>();
                SelectedAccounts = new ReactiveProperty <IEnumerable <ShareAccountViewModel> >();
            }

            Title       = new ReactiveProperty <string>(uiThreadScheduler);
            Description = new ReactiveProperty <string>(uiThreadScheduler);

            Text           = Model.ToReactivePropertyAsSynchronized(x => x.Text, uiThreadScheduler).AddTo(Disposable);
            CharacterCount = Model.ObserveProperty(x => x.CharacterCount)
                             .Select(x => x.ToString())
                             .ToReactiveProperty(uiThreadScheduler)
                             .AddTo(Disposable);

            Message       = Model.ObserveProperty(x => x.Message).ToReactiveProperty(uiThreadScheduler).AddTo(Disposable);
            ToolTipIsOpen = Model.ToReactivePropertyAsSynchronized(x => x.ToolTipIsOpen, uiThreadScheduler);

            StateSymbol = Model.ObserveProperty(x => x.State)
                          .Select(x =>
            {
                switch (x)
                {
                case "Accept":
                    return(Symbol.Accept);

                case "Cancel":
                    return(Symbol.Cancel);

                default:
                    return(Symbol.Accept);
                }
            })
                          .ToReactiveProperty(uiThreadScheduler)
                          .AddTo(Disposable);

            Updating = Model.ObserveProperty(x => x.Updating).ToReactiveProperty(uiThreadScheduler).AddTo(Disposable);

            Notice  = Notice.Instance;
            Setting = SettingService.Setting;

            Pictures = Model.ReadonlyPictures
                       .ToReadOnlyReactiveCollection(x => new PictureViewModel(x), uiThreadScheduler)
                       .AddTo(Disposable);

            TweetCommand = Model.ObserveProperty(x => x.CharacterCount)
                           .Select(x => x >= 0)
                           .ToReactiveCommand(uiThreadScheduler)
                           .AddTo(Disposable);
            TweetCommand.SubscribeOn(ThreadPoolScheduler.Default)
            .Subscribe(async x =>
            {
                var complete = await Model.Tweet(SelectedAccounts.Value.Select(y => y.AccountSetting.Value));
                if (!complete)
                {
                    return;
                }

                ShareOperation.ReportCompleted();
            })
            .AddTo(Disposable);
        }