예제 #1
0
        public async void RetrieveData()
        {
            try
            {
                if (dataRetrieved)
                {
                    await new MessageDialog("data already retrieved").ShowAsync();
                }
                _shareOperation.ReportStarted();
                switch (SelectedFormat)
                {
                case "Text":
                    Text = await _shareOperation.Data.GetTextAsync();

                    break;

                case "HTML Format":
                    Html = await _shareOperation.Data.GetHtmlFormatAsync();

                    break;

                default:
                    break;
                }
                _shareOperation.ReportDataRetrieved();
                dataRetrieved = true;
            }
            catch (Exception ex)
            {
                _shareOperation.ReportError(ex.Message);
            }
        }
        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);
            }
        }
예제 #3
0
        public async void Initialize(ShareOperation share)
        {
            _share = share;
            _share.ReportStarted();
            await _share.Data.CopyTo(_values);

            _share.ReportDataRetrieved();
        }
예제 #4
0
        public async void AddApp()
        {
            shareOperation.ReportStarted();
            var database = new Database();
            await database.Add(AppInfo);

            App.InvokeAppAdded();
            Analytics.TrackEvent("NewAppAdded");
            shareOperation.ReportCompleted();
        }
예제 #5
0
        private async void ShowSharedContent()
        {
            // Let Windows know that this app is starting to fetch data
            _shareOperation.ReportStarted();
            DefaultViewModel["ProcessingSharedData"] = true;

            try
            {
                var formatOrdering = new AppSettings().OrderedFormats.ToList();
                var shareData      = _shareOperation.Data;

                var preferredFormat = formatOrdering.FirstOrDefault(x => shareData.Contains(x.DataFormat));

                if (preferredFormat.DataFormat == StandardDataFormats.Text)
                {
                    await ShowSharedText(shareData);
                }
                //else if(preferredFormat.DataFormat == StandardDataFormats.Rtf)
                //{
                //    // Not Implemented
                //    //ShowSharedRtf(shareData);
                //}
                else if (preferredFormat.DataFormat == StandardDataFormats.Html)
                {
                    await ShowSharedHtml(shareData);
                }
                else if (preferredFormat.DataFormat == StandardDataFormats.Bitmap)
                {
                    await ShowSharedBitmap(shareData);
                }
                // NOTE - StandardDataFormats.Uri is effectively Deprecated - see SetApplicationLink and/or SetWebLink instead
                else if (preferredFormat.DataFormat == StandardDataFormats.ApplicationLink)
                {
                    await ShowSharedAppLink(shareData);
                }
                else if (preferredFormat.DataFormat == StandardDataFormats.WebLink)
                {
                    await ShowSharedWebLink(shareData);
                }
                else if (preferredFormat.DataFormat == StandardDataFormats.StorageItems)
                {
                    await ShowSharedStorageItems(shareData);
                }
                else if (preferredFormat.DataFormat == AppSettings.CustomPersonSchemaName)
                {
                    await ShowSharedCustomPerson(shareData);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Share data retrieval error: " + e);
                _shareOperation.ReportError("An error occurred while retrieving the shared data.");
            }
        }
예제 #6
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();
        }
예제 #7
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();
        }
예제 #8
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();
        }
예제 #9
0
        async private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            shareOperation.ReportStarted();

            var notebook = comboNotebooks.SelectedItem as NoteBook;
            var noteType = (NoteTypes)comboType.SelectedItem;

            switch (noteType)
            {
            case NoteTypes.ToDo:
                var todo = new ToDoDataItem(txtTitle.Text.HttpEncode(), notebook);
                todo.Description = txtDescription.Text.HttpEncode();
                await CopyDataToLocalStorageAsync(todo);

                NotesDataSource.Add(todo, notebook.UniqueId);
                break;

            case NoteTypes.Food:
                var food = new FoodDataItem(txtTitle.Text.HttpEncode(), notebook);
                food.Description = txtDescription.Text.HttpEncode();
                await CopyDataToLocalStorageAsync(food);

                NotesDataSource.Add(food, notebook.UniqueId);
                break;

            default:
                var note = new NoteDataItem(txtTitle.Text.HttpEncode(), notebook);
                note.Description = txtDescription.Text.HttpEncode();
                await CopyDataToLocalStorageAsync(note);

                NotesDataSource.Add(note, notebook.UniqueId);
                break;
            }

            DataManager.Save();

            this.shareOperation.ReportCompleted();
        }
예제 #10
0
        protected override async void OnShareTargetActivated(ShareTargetActivatedEventArgs args)
        {
            ShareOperation shareOperation = args.ShareOperation;

            var formats = shareOperation.Data.AvailableFormats.ToArray();

            if (shareOperation.Data.Contains(StandardDataFormats.StorageItems))
            {
                shareOperation.ReportStarted();

                var storageItems = await shareOperation.Data.GetStorageItemsAsync();

                var firstFile = storageItems.First() as StorageFile;

                string json = await FileToJson(firstFile);

                shareOperation.ReportDataRetrieved();

                LaunchMainUI(args);

                ApplicationCenter.Receive(json);
            }
        }
예제 #11
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                // BUGBUG: this is messy
                var items = new List <object> {
                    new { Name = "Direct Messages" }
                };
                items.AddRange(App.Discord.Guilds.Values.OrderBy(g => g.Name));
                guildBox.ItemsSource = items;

                channelsBox.ItemTemplateSelector = new ChannelTemplateSelector()
                {
                    ServerChannelTemplate = (DataTemplate)App.Current.Resources["NoIndicatorChannelListTemplate"],
                    DirectMessageTemplate = (DataTemplate)App.Current.Resources["NoIndicatorDMChannelTemplate"]
                };

                //if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 5))
                //{
                //    var contact = _shareOperation.Contacts.FirstOrDefault();
                //    if (contact != null)
                //    {
                //        var id = await ContactListManager.TryGetChannelIdAsync(contact);
                //        if (id != 0)
                //        {
                //            guildBox.SelectedIndex = 0;
                //            channelsBox.SelectedItem = await App.Discord.CreateDmChannelAsync(id);

                //            target.Text = contact.DisplayName;
                //            destinationGrid.Visibility = Visibility.Collapsed;
                //        }
                //    }
                //}

                _shareOperation.ReportStarted();

                var data = _shareOperation.Data;
                if (data.AvailableFormats.Contains(StandardDataFormats.StorageItems))
                {
                    _file = (await data.GetStorageItemsAsync()).FirstOrDefault() as StorageFile;

                    var img = new BitmapImage();
                    thumbnailImage.Source = img;
                    await img.SetSourceAsync(await _file.GetThumbnailAsync(ThumbnailMode.SingleItem));

                    return;
                }
                else if (data.AvailableFormats.Contains(StandardDataFormats.Bitmap))
                {
                    // do shit

                    _file = await Tools.GetImageFileFromDataPackage(data);

                    var img = new BitmapImage();
                    thumbnailImage.Source = img;
                    await img.SetSourceAsync(await _file.GetThumbnailAsync(ThumbnailMode.PicturesView));

                    return;
                }
                else
                {
                    thumbnailImage.Visibility   = Visibility.Collapsed;
                    captionText.PlaceholderText = "Type a message!";
                }

                if (data.AvailableFormats.Contains(StandardDataFormats.Text))
                {
                    var text = await data.GetTextAsync();

                    captionText.Text += text;
                }

                if (data.AvailableFormats.Contains(StandardDataFormats.WebLink))
                {
                    var text = await data.GetWebLinkAsync();

                    captionText.Text += text;
                }
            }
            finally
            {
                _shareOperation.ReportDataRetrieved();
                this.FindParent <MainPage>().HideConnectingOverlay();

                if (_file != null)
                {
                    var maxSize = (ulong)(App.Discord.CurrentUser.UploadLimit());
                    var props   = await _file.GetBasicPropertiesAsync();

                    if (props.Size >= maxSize)
                    {
                        await UIUtilities.ShowErrorDialogAsync("This file is too big!", $"We're gonna need something under {Tools.ToFileSizeString(maxSize)} please!");

                        Window.Current.Close();
                    }
                }
            }
        }
        private void ShowSharedContent()
        {
            // Let Windows know that this app is starting to fetch data
            _shareOperation.ReportStarted();
            DefaultViewModel["ProcessingSharedData"] = true;

            try
            {
                var shareData = _shareOperation.Data;

                var showContentTaskList = new List <Task>();
                if (shareData.Contains(StandardDataFormats.Text))
                {
                    var task = ShowSharedText(shareData);
                    showContentTaskList.Add(task);
                }

                if (shareData.Contains(StandardDataFormats.Rtf))
                {
                    // Not Implemented
                    //ShowSharedRtf(shareData);
                }

                if (shareData.Contains(StandardDataFormats.Html))
                {
                    var task = ShowSharedHtml(shareData);
                    showContentTaskList.Add(task);
                }

                if (shareData.Contains(StandardDataFormats.Bitmap))
                {
                    var task = ShowSharedBitmap(shareData);
                    showContentTaskList.Add(task);
                }

                // NOTE - SetUri is effectively Deprecated - see SetApplicationLink and/or SetWebLink instead
                if (shareData.Contains(StandardDataFormats.ApplicationLink))
                {
                    var task = ShowSharedAppLink(shareData);
                    showContentTaskList.Add(task);
                }
                if (shareData.Contains(StandardDataFormats.WebLink))
                {
                    var task = ShowSharedWebLink(shareData);
                    showContentTaskList.Add(task);
                }

                if (shareData.Contains(StandardDataFormats.StorageItems))
                {
                    var task = ShowSharedStorageItems(shareData);
                    showContentTaskList.Add(task);
                }

                if (shareData.Contains(AppSettings.CustomPersonSchemaName))
                {
                    var task = ShowSharedCustomPerson(shareData);
                    showContentTaskList.Add(task);
                }

                // Admittedly a bit unusual to be doing this "task stuff"; most apps will just bring in their "favorite" data format
                // and signal Retrieved/Complete right there...since this is more of a "sampler", the Task API is used to wait for
                // all of the retrives to finish and then signal that the data txfer is complete, and update the UI elements accordingly.
                Task.WhenAll(showContentTaskList).ContinueWith(task =>
                {
                    _shareOperation.ReportDataRetrieved();
                    DefaultViewModel["ProcessingSharedData"] = false;
                });
            }
            catch (Exception e)
            {
                Debug.WriteLine("Share data retrieval error: " + e);
                _shareOperation.ReportError("An error occurred while retrieving the shared data.");
            }
        }
예제 #13
0
 private void ReportStarted_Click(object sender, RoutedEventArgs e)
 {
     m_shareOperation.ReportStarted();
     rootPage.NotifyUser("Started...", NotifyType.StatusMessage);
 }
예제 #14
0
        public async Task ActiveSync(ShareOperation shareOperation)
        {
            _shareOperation = shareOperation;
            shareOperation.ReportStarted();

            try
            {
                var dataPackageView = shareOperation.Data;

                RequestTitle       = _shareOperation.Data.Properties.Title;
                RequestDescription = _shareOperation.Data.Properties.Description;

                if (dataPackageView.IsTextMessage())
                {
                    IsTextRequest  = true;
                    TextShareValue = await dataPackageView.GetTextAsync();
                }
                else if (dataPackageView.IsUrlMessage())
                {
                    IsUrlRequest = true;
                    var foundUri = await dataPackageView.GetUriAsync();

                    UrlShareValue = foundUri.AbsoluteUri;
                }
                else if (dataPackageView.IsImageMessage())
                {
                    IsImageRequest = true;

                    RandomAccessStreamReference imageReceived = await dataPackageView.GetBitmapAsync();

                    var imageStream = await imageReceived.OpenReadAsync();

                    ImageShareValue = new BitmapImage();
                    ImageShareValue.SetSource(imageStream);

                    OnPropertyChanged("ImageShareValue");
                }
                else if (dataPackageView.IsStorageItemsMessage())
                {
                    IsStorageRequest = true;
                    var storageItems = await dataPackageView.GetStorageItemsAsync();

                    if (storageItems.Any())
                    {
                        var storageItem = storageItems.First();
                        if (storageItem.IsOfType(StorageItemTypes.File))
                        {
                            StorageFileName = storageItem.Name;

                            var thumbnail = dataPackageView.Properties.Thumbnail;

                            var thumbnailStream = await thumbnail.OpenReadAsync();

                            ImageShareValue = new BitmapImage();
                            ImageShareValue.SetSource(thumbnailStream);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _shareOperation.ReportError(e.Message);
                RequestDescription = e.Message;
            }

            _shareOperation.ReportDataRetrieved();
        }
 /// <summary>
 /// Invoked when the user clicks the Share button.
 /// </summary>
 /// <param name="sender">Instance of Button used to initiate sharing.</param>
 /// <param name="e">Event data describing how the button was clicked.</param>
 private void ShareButton_Click(object sender, RoutedEventArgs e)
 {
     DefaultViewModel["Sharing"] = true;
     _shareOperation.ReportStarted();
     _shareOperation.ReportCompleted();
 }