Beispiel #1
0
 public void setMax(int max)
 {
     ProgressSpinner.Invoke((MethodInvoker)(() =>
     {
         ProgressSpinner.Maximum = max;
     }));
 }
Beispiel #2
0
 public void setProgress(int step)
 {
     ProgressSpinner.Invoke((MethodInvoker)(() =>
     {
         ProgressSpinner.Value = step;
     }));
 }
Beispiel #3
0
    public async Task WhenReceivesSingleTask_ItJustWorks()
    {
        var spinner = new ProgressSpinner("", new[] {
            CreateTask(true)
        });

        await spinner.Start();
    }
Beispiel #4
0
    public async Task WhenTaskFails_ThrowsSpinnerException()
    {
        var spinner = new ProgressSpinner("", new[] {
            CreateTask(false)
        });

        await Assert.ThrowsAsync <SpinnerException>(async() => await spinner.Start());
    }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            var context = TaskScheduler.FromCurrentSynchronizationContext();

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            var send = FindViewById<Button>(Resource.Id.Send);
            var host = FindViewById<Button>(Resource.Id.Host);
            var connect = FindViewById<Button>(Resource.Id.Connect);
            var listView = FindViewById<ListView>(Resource.Id.dataList);
            var text = FindViewById<EditText>(Resource.Id.sendText);
            var adapter = new MessageAdapter();
            listView.Adapter = adapter;

            host.Click += (sender, e) =>
            {
                _progress = ProgressSpinner.Show(this, null, null, true, false);

                _service.Host(new MultiplayerGame
                {
                    Name = Build.Manufacturer.Trim() + " " + Build.Model.Trim(),
                })
                .ContinueWith(t =>
                {
                    if (t.IsFaulted)
                    {
                        ShowPopUp("Error", t.Exception.InnerExceptions.First().Message);
                    }
                    else
                    {
                        ShowPopUp("Success", "You have hosted a game.");
                    }

                }, context);
            };

            connect.Click += (sender, e) =>
            {
                _progress = ProgressSpinner.Show(this, null, null, true, false);
                _service.FindGames()
                    .ContinueWith(t =>
                    {
                        if (t.IsFaulted)
                        {
                            ShowPopUp("Error", t.Exception.InnerExceptions.First().Message);
                            return;
                        }

                        AlertDialog dialog = null;
                        var games = t.Result.Select(g => g.Name).ToArray();
                        var builder = new AlertDialog.Builder(this);
                        builder.SetTitle("Select Connection");
                        builder.SetSingleChoiceItems(games, -1, (s, o) =>
                        {
                            var game = t.Result.ElementAtOrDefault(o.Which);
                            if (game != null)
                            {
                                _progress = ProgressSpinner.Show(this, null, null, true, false);
                                dialog.Dismiss();
                                _service.Join(game).ContinueWith(c =>
                                {
                                    if (c.IsFaulted)
                                    {
                                        ShowPopUp("Error", c.Exception.InnerExceptions.First().Message);
                                    }
                                    else
                                    {
                                        ShowPopUp("Success", "You have connected to the game.");
                                    }
                                }, context);
                            }
                        });
                        dialog = builder.Create();
                        dialog.Show();
                        _progress.Dismiss();
                    }, context);
            };

            send.Click += (sender, e) =>
            {
                var message = new TestMessage
                {
                    Text = text.Text,
                    ShouldEcho = true,
                    TimeStamp = DateTime.Now
                };

                _service.Send("T", message).ContinueWith(t =>
                {
                    if (t.IsFaulted)
                    {
                        ShowPopUp("Error", t.Exception.InnerExceptions.First().Message);
                        return;
                    }

                }, context);
            };

            _service.Received += (sender, e) =>
            {
                var message = e.Message as TestMessage;
                if (message.ShouldEcho)
                {
                    adapter.Logs.Add("RECEIVED: " + message.Text);
                    adapter.NotifyDataSetChanged();
                    message.ShouldEcho = false;
                    _service.Send("T", message);
                }

                else
                {
                    adapter.Logs.Add("Send: " + message.Text + " Latency: " + message.RoundTripMillis);
                }
            };
        }
Beispiel #6
0
        private void sendButton_Click(object sender, EventArgs e) //Кнопка отправить
        {
            ProgressSpinner.Visible = true;
            ProgressSpinner.Maximum = dt.Rows.Count;
            ProgressSpinner.Update();

            if (dt.Rows.Count > 0)
            {
                try
                {
                    MimeMessage message = new MimeMessage(); //создаем письмо
                    message.From.Add(new MailboxAddress(Settings.Default.Name, Settings.Default.Email));
                    message.Subject = SubjectTextBox.Text;

                    string       dirname   = "";                                                                                                                                   //Директория с изображениями
                    string       imagePath = Path.Combine(Path.GetDirectoryName(openFileDialog2.FileName), Path.GetFileNameWithoutExtension(openFileDialog2.FileName) + ".files"); //Определяем директорию с картинками письма
                    Stream       stream    = webBrowser1.DocumentStream;                                                                                                           //Читаем html текст письма
                    StreamReader sr        = new StreamReader(stream, Encoding.GetEncoding("windows-1251"));
                    string       HTMLtext  = sr.ReadToEnd();                                                                                                                       //Тело письма
                    stream.Close();

                    BodyBuilder builder = new BodyBuilder();

                    if (Directory.Exists(imagePath)) //Если картинки существуют, то добавляем их в тело письма
                    {
                        string[]     imagesList = Directory.GetFiles(imagePath);
                        MimeEntity[] imgs       = new MimeEntity[imagesList.Length];
                        dirname = new DirectoryInfo(Path.GetDirectoryName(imagesList[0])).Name;

                        for (int z = 0; z < imagesList.Length; z++)
                        {
                            var image = builder.LinkedResources.Add(imagesList[z]);
                            image.ContentId = MimeUtils.GenerateMessageId();
                            HTMLtext        = HTMLtext.Replace(dirname + "/" + Path.GetFileName(imagesList[z]), "cid:" + image.ContentId);
                        }
                    }

                    foreach (string itm in attachedFilesListBox.Items)
                    {
                        builder.Attachments.Add(itm);
                    }

                    builder.TextBody = webBrowser1.Document.Body.InnerText;
                    if (Settings.Default.IsHtml)
                    {
                        builder.HtmlBody = HTMLtext;
                    }

                    message.Body = builder.ToMessageBody();

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        ProgressSpinner.Value = i + 1;
                        ProgressSpinner.Update();

                        message.To.Clear();
                        message.To.Add(new MailboxAddress(dt.Rows[i]["Email"].ToString(), dt.Rows[i]["Email"].ToString()));

                        var client = new SmtpClient();
                        client.Connect(Settings.Default.Server, Settings.Default.Port, MailKit.Security.SecureSocketOptions.Auto);
                        client.Authenticate(Settings.Default.Email, Settings.Default.Password);
                        client.Send(message);
                        client.Disconnect(true);
                    }

                    ProgressSpinner.Visible = false;
                    MessageBox.Show("Успешно!");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Ошибка при отправке. Текст ошибки: \n \n" + ex.ToString());
                }
            }
        }
Beispiel #7
0
    public static int PublishFile(Config.Config config, string filepath)
    {
        Write.WithNL($"Publishing {Cyan(filepath)}", before: true, after: true);

        if (!File.Exists(filepath))
        {
            Write.ErrorExit(
                "File selected for publish was not found",
                $"Looked from: {White(Dim(filepath))}"
                );
            return(1);
        }

        UploadInitiateData uploadData;

        try
        {
            uploadData = InitiateUploadRequest(config, filepath);
        }
        catch (PublishCommandException)
        {
            return(1);
        }

        Task <CompletedUpload.CompletedPartData>[] uploadTasks;

        try
        {
            uploadTasks = uploadData.UploadUrls !.Select(  // Validated in InitiateUploadRequest
                partData => UploadChunk(partData, filepath)
                ).ToArray();
        }
        catch (PublishCommandException)
        {
            return(1);
        }

        string uploadUuid = uploadData.Metadata?.UUID !;  // Validated in InitiateUploadRequest

        try
        {
            var spinner = new ProgressSpinner("chunks uploaded", uploadTasks);
            spinner.Start().GetAwaiter().GetResult();
        }
        catch (SpinnerException)
        {
            HttpClient.Send(config.Api.AbortUploadMedia(uploadUuid));
            return(1);
        }

        var uploadedParts = uploadTasks.Select(x => x.Result).ToArray();

        try
        {
            var response = HttpClient.Send(
                config.Api.FinishUploadMedia(
                    new CompletedUpload
            {
                Parts = uploadedParts
            },
                    uploadUuid
                    )
                );

            HandleRequestError("Finishing usermedia upload", response);
            Write.Success("Successfully finalized the upload");
        }
        catch (PublishCommandException)
        {
            return(1);
        }

        try
        {
            PublishPackageRequest(config, uploadUuid);
        }
        catch (PublishCommandException)
        {
            return(1);
        }

        return(0);
    }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            var context = TaskScheduler.FromCurrentSynchronizationContext();

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            var send     = FindViewById <Button>(Resource.Id.Send);
            var host     = FindViewById <Button>(Resource.Id.Host);
            var connect  = FindViewById <Button>(Resource.Id.Connect);
            var listView = FindViewById <ListView>(Resource.Id.dataList);
            var text     = FindViewById <EditText>(Resource.Id.sendText);
            var adapter  = new MessageAdapter();

            listView.Adapter = adapter;

            host.Click += (sender, e) =>
            {
                _progress = ProgressSpinner.Show(this, null, null, true, false);

                _service.Host(new MultiplayerGame
                {
                    Name = Build.Manufacturer.Trim() + " " + Build.Model.Trim(),
                })
                .ContinueWith(t =>
                {
                    if (t.IsFaulted)
                    {
                        ShowPopUp("Error", t.Exception.InnerExceptions.First().Message);
                    }
                    else
                    {
                        ShowPopUp("Success", "You have hosted a game.");
                    }
                }, context);
            };

            connect.Click += (sender, e) =>
            {
                _progress = ProgressSpinner.Show(this, null, null, true, false);
                _service.FindGames()
                .ContinueWith(t =>
                {
                    if (t.IsFaulted)
                    {
                        ShowPopUp("Error", t.Exception.InnerExceptions.First().Message);
                        return;
                    }

                    AlertDialog dialog = null;
                    var games          = t.Result.Select(g => g.Name).ToArray();
                    var builder        = new AlertDialog.Builder(this);
                    builder.SetTitle("Select Connection");
                    builder.SetSingleChoiceItems(games, -1, (s, o) =>
                    {
                        var game = t.Result.ElementAtOrDefault(o.Which);
                        if (game != null)
                        {
                            _progress = ProgressSpinner.Show(this, null, null, true, false);
                            dialog.Dismiss();
                            _service.Join(game).ContinueWith(c =>
                            {
                                if (c.IsFaulted)
                                {
                                    ShowPopUp("Error", c.Exception.InnerExceptions.First().Message);
                                }
                                else
                                {
                                    ShowPopUp("Success", "You have connected to the game.");
                                }
                            }, context);
                        }
                    });
                    dialog = builder.Create();
                    dialog.Show();
                    _progress.Dismiss();
                }, context);
            };

            send.Click += (sender, e) =>
            {
                var message = new TestMessage
                {
                    Text       = text.Text,
                    ShouldEcho = true,
                    TimeStamp  = DateTime.Now
                };

                _service.Send("T", message).ContinueWith(t =>
                {
                    if (t.IsFaulted)
                    {
                        ShowPopUp("Error", t.Exception.InnerExceptions.First().Message);
                        return;
                    }
                }, context);
            };

            _service.Received += (sender, e) =>
            {
                var message = e.Message as TestMessage;
                if (message.ShouldEcho)
                {
                    adapter.Logs.Add("RECEIVED: " + message.Text);
                    adapter.NotifyDataSetChanged();
                    message.ShouldEcho = false;
                    _service.Send("T", message);
                }

                else
                {
                    adapter.Logs.Add("Send: " + message.Text + " Latency: " + message.RoundTripMillis);
                }
            };
        }