Exemplo n.º 1
0
        static void Main()
        {
            while (true)
            {
                Console.Write("Enter file's size (MB): ");

                int size;
                if (!int.TryParse(Console.ReadLine(), out size))
                    return;

                using (var client = new RepositoryClientFactory().CreateClient())
                {
                    Console.WriteLine("Connecting...");
                    client.Open();

                    for (var i = 0; i < 1; i++)
                    {
                        Stream stream = null;
                        using (stream)
                        {
                            string data;
                            using (Perfomance.Trace("Generating data stream...").BindToConsole())
                            {
                                data = GenerateRandomString(size * 1024 * 1024);
                                stream = WriteString(data);
                            }

                            // Write
                            Guid id;
                            using (Perfomance.Trace("client.Upload").BindToConsole())
                            {
                                id = client.UploadNew("test", stream);
                            }

                            // Read all
                            var link = new FileLink { Id = id };
                            Stream download;
                            using (Perfomance.Trace("client.Download").BindToConsole())
                            {
                                download = client.Download(link.Id);
                            }
                            var readString = ReadString(download);
                            Console.WriteLine(readString == data
                                                  ? "Pass"
                                                  : "Fail");
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void CreateButton_Click(object sender, RoutedEventArgs _)
        {
            try
            {
                using (var client = new RepositoryClientFactory().CreateClient())
                {
                    client.Open();

                    for (var i = 0; i < 5; i++)
                    {

                        var data = GenerateRandomString(16 * 1024 * 1024);

                        // Create
                        var id = client.CreateNew("testFile");
                        var link = new FileLink { Id = id };

                        // Write
                        using (var stream = WriteString(data))
                        {
                            Action<string, long> onCompleted =
                                (msg, ms) => MessageBox.Show(string.Format("{0} in {1} ms", msg, ms));
                            using (Perfomance.Trace("client.Upload").BindToCallback(onCompleted))
                            {
                                client.Upload(link.Id, stream);
                            }

                            // Read all
                            Stream download;
                            using (Perfomance.Trace("client.Download").BindToCallback(onCompleted))
                            {
                                download = client.Download(link.Id);
                            }
                            MessageBox.Show(ReadString(download) == data ? "Pass" : "Fail",
                                            "All file");
                        }
                    }
                }
            }
            catch (WebException e)
            {
                var data = e.Response.GetResponseStream().ReadToBuffer();
                var str = Encoding.Default.GetString(data);
                MessageBox.Show(str);
                ErrorView.Show(e);
            }
        }
Exemplo n.º 3
0
 private void DeleteFile_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     var fileInfo = e.Parameter as FileInfo;
     if (MessageBox.Show(
         string.Format("Delete file {0} ({1})?", fileInfo.Name, fileInfo.Id),
         "Confirm",
         MessageBoxButton.YesNo) == MessageBoxResult.Yes)
     {
         this.Asynch(() =>
         {
             var id = fileInfo.Id;
             using (var client = new RepositoryClientFactory().CreateClient())
             {
                 client.Open();
                 client.Delete(id);
                 client.Close();
             }
         }, ShowWait, HideWait);
     }
 }
Exemplo n.º 4
0
        private void LoadPage(int page, int pageNumber)
        {
            IEnumerable<FileInfo> files = null;

            this.Asynch(() =>
            {
                using (var client = new RepositoryClientFactory().CreateClient())
                {
                    client.Open();
                    files = client.Browse(page * pageNumber, page).Select(x => new FileInfo { Id = x.Id, Name = x.Name });
                    client.Close();
                }
            }, ShowWait, HideWait, () =>
            {
                filesListView.ItemsSource = files;
            });
        }