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);
            }
        }