Пример #1
0
        static void CommonTest()
        {
            var client = new FSClient(512 * 1024, 1, Properties.Settings.Default.StorageUrl, 1);

            SimpleActionResult response;

            Console.WriteLine("Sending file to a server...");
            using (var file = new FileStream(Path.Combine("files", BinaryFileName), FileMode.Open))
            {
                response = client.SendFile(file, BinaryFileName, "1", "test");
            }
            Console.WriteLine(response.Status);

            Console.WriteLine("Checking file existance on a server...");
            response = client.FileExists(BinaryFileName, "1", "test");
            Console.WriteLine(response.Status);

            Console.WriteLine("Checking file MD5 sum on a server...");
            response = client.FileMD5(BinaryFileName, "1", "test");
            using (var file = new FileStream(Path.Combine("files", BinaryFileName), FileMode.Open))
            {
                Console.WriteLine(((StringActionResult)response).Value == FSClient.FileMD5Local(file));
            }

            Console.WriteLine("Checking file length on a server...");
            response = client.FileLength(BinaryFileName, "1", "test");
            using (var file = new FileStream(Path.Combine("files", BinaryFileName), FileMode.Open))
            {
                Console.WriteLine(((LongActionResult)response).Value == file.Length);
            }

            Console.WriteLine("Checking get file from a server...");
            using (var file = new FileStream(Path.Combine("files", TextFileName), FileMode.Open))
            {
                client.SendFile(file, TextFileName, "1", "test");
            }
            response = client.GetFile(TextFileName, "1", "test");
            using (var sr = new StreamReader(((StreamActionResult)response).Value))
            {
                Console.WriteLine(string.Format("File data is: {0}", sr.ReadToEnd()));
            }

            Console.WriteLine("Deleting file from a server...");
            response = client.DelFile(BinaryFileName, "1", "test");
            Console.WriteLine(response.Status);
        }