|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using System.Diagnostics; |
| 6 | + |
| 7 | +namespace QBox |
| 8 | +{ |
| 9 | + public class RSDemo |
| 10 | + { |
| 11 | + public static string tableName = "Bucket"; |
| 12 | + public static string key; |
| 13 | + public static string localFile; |
| 14 | + public static string DEMO_DOMAIN = "iovip.qbox.me/bucket"; |
| 15 | + public static Client conn; |
| 16 | + public static RSService rs; |
| 17 | + |
| 18 | + public static void PutFile() |
| 19 | + { |
| 20 | + Console.WriteLine("\n--- PutFile ---"); |
| 21 | + PrintInput(tableName, key, localFile, null); |
| 22 | + PutFileRet putFileRet = rs.PutFile(key, null, localFile, null); |
| 23 | + PrintRet(putFileRet); |
| 24 | + if (putFileRet.OK) |
| 25 | + { |
| 26 | + Console.WriteLine("Hash: " + putFileRet.Hash); |
| 27 | + } |
| 28 | + else |
| 29 | + { |
| 30 | + Console.WriteLine("Failed to PutFile"); |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + public static void Get() |
| 35 | + { |
| 36 | + Console.WriteLine("\n--- Get ---"); |
| 37 | + PrintInput(tableName, key, null, null); |
| 38 | + GetRet getRet = rs.Get(key, "attName"); |
| 39 | + PrintRet(getRet); |
| 40 | + if (getRet.OK) |
| 41 | + { |
| 42 | + Console.WriteLine("Hash: " + getRet.Hash); |
| 43 | + Console.WriteLine("FileSize: " + getRet.FileSize); |
| 44 | + Console.WriteLine("MimeType: " + getRet.MimeType); |
| 45 | + Console.WriteLine("Url: " + getRet.Url); |
| 46 | + } |
| 47 | + else |
| 48 | + { |
| 49 | + Console.WriteLine("Failed to Get"); |
| 50 | + } |
| 51 | + |
| 52 | + Console.WriteLine("\n--- GetIfNotModified ---"); |
| 53 | + PrintInput(tableName, key, null, null); |
| 54 | + getRet = rs.GetIfNotModified(key, "attName", getRet.Hash); |
| 55 | + PrintRet(getRet); |
| 56 | + if (getRet.OK) |
| 57 | + { |
| 58 | + Console.WriteLine("Hash: " + getRet.Hash); |
| 59 | + Console.WriteLine("FileSize: " + getRet.FileSize); |
| 60 | + Console.WriteLine("MimeType: " + getRet.MimeType); |
| 61 | + Console.WriteLine("Url: " + getRet.Url); |
| 62 | + } |
| 63 | + else |
| 64 | + { |
| 65 | + Console.WriteLine("Failed to GetIfNotModified"); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + public static void Stat() |
| 70 | + { |
| 71 | + Console.WriteLine("\n--- Stat ---"); |
| 72 | + PrintInput(tableName, key, null, null); |
| 73 | + StatRet statRet = rs.Stat(key); |
| 74 | + PrintRet(statRet); |
| 75 | + if (statRet.OK) |
| 76 | + { |
| 77 | + Console.WriteLine("Hash: " + statRet.Hash); |
| 78 | + Console.WriteLine("FileSize: " + statRet.FileSize); |
| 79 | + Console.WriteLine("PutTime: " + statRet.PutTime); |
| 80 | + Console.WriteLine("MimeType: " + statRet.MimeType); |
| 81 | + } |
| 82 | + else |
| 83 | + { |
| 84 | + Console.WriteLine("Failed to Stat"); |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + public static void Delete() |
| 89 | + { |
| 90 | + Console.WriteLine("\n--- Delete ---"); |
| 91 | + PrintInput(tableName, key, null, null); |
| 92 | + DeleteRet deleteRet = rs.Delete(key); |
| 93 | + PrintRet(deleteRet); |
| 94 | + if (!deleteRet.OK) |
| 95 | + { |
| 96 | + Console.WriteLine("Failed to Delete"); |
| 97 | + } |
| 98 | + } |
| 99 | + |
| 100 | + public static void Drop() |
| 101 | + { |
| 102 | + Console.WriteLine("\n--- Drop ---"); |
| 103 | + PrintInput(tableName, null, null, null); |
| 104 | + DropRet dropRet = rs.Drop(); |
| 105 | + PrintRet(dropRet); |
| 106 | + if (!dropRet.OK) |
| 107 | + { |
| 108 | + Console.WriteLine("Failed to Drop"); |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | + public static void Publish() |
| 113 | + { |
| 114 | + Console.WriteLine("\n--- Publish ---"); |
| 115 | + PrintInput(tableName, null, null, DEMO_DOMAIN); |
| 116 | + PublishRet publishRet = rs.Publish(DEMO_DOMAIN); |
| 117 | + PrintRet(publishRet); |
| 118 | + if (!publishRet.OK) |
| 119 | + { |
| 120 | + Console.WriteLine("Failed to Publish"); |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + public static void UnPublish() |
| 125 | + { |
| 126 | + Console.WriteLine("\n--- UnPublish ---"); |
| 127 | + PrintInput(tableName, null, null, DEMO_DOMAIN); |
| 128 | + PublishRet publishRet = rs.UnPublish(DEMO_DOMAIN); |
| 129 | + PrintRet(publishRet); |
| 130 | + if (!publishRet.OK) |
| 131 | + { |
| 132 | + Console.WriteLine("Failed to UnPublish"); |
| 133 | + } |
| 134 | + } |
| 135 | + |
| 136 | + public static PutAuthRet PutAuth() |
| 137 | + { |
| 138 | + Console.WriteLine("\n--- PutAuth ---"); |
| 139 | + PrintInput(null, null, null, null); |
| 140 | + PutAuthRet putAuthRet = rs.PutAuth(); |
| 141 | + PrintRet(putAuthRet); |
| 142 | + if (putAuthRet.OK) |
| 143 | + { |
| 144 | + Console.WriteLine("Expires: " + putAuthRet.Expires.ToString()); |
| 145 | + Console.WriteLine("Url: " + putAuthRet.Url); |
| 146 | + } |
| 147 | + else |
| 148 | + { |
| 149 | + Console.WriteLine("Failed to PutAuth"); |
| 150 | + } |
| 151 | + return putAuthRet; |
| 152 | + } |
| 153 | + |
| 154 | + public static void CliPutFile() |
| 155 | + { |
| 156 | + PutAuthRet putAuthRet = PutAuth(); |
| 157 | + Console.WriteLine("\n--- CliPutFile ---"); |
| 158 | + PrintInput(tableName, key, localFile, null); |
| 159 | + PutFileRet putFileRet = RSClient.PutFile(putAuthRet.Url, tableName, |
| 160 | + key, null, localFile, null, "key=Config.cs"); |
| 161 | + PrintRet(putFileRet); |
| 162 | + if (putFileRet.OK) |
| 163 | + { |
| 164 | + Console.WriteLine("Hash: " + putFileRet.Hash); |
| 165 | + } |
| 166 | + else |
| 167 | + { |
| 168 | + Console.WriteLine("Failed to CliPutFile"); |
| 169 | + } |
| 170 | + |
| 171 | + } |
| 172 | + |
| 173 | + public static void PrintInput( |
| 174 | + string tblName, string key, string localFile, string domain) |
| 175 | + { |
| 176 | + StringBuilder sb = new StringBuilder(); |
| 177 | + sb.AppendLine("\n[In]"); |
| 178 | + if (!String.IsNullOrEmpty(tblName)) |
| 179 | + sb.AppendLine("TableName: " + tblName); |
| 180 | + if (!String.IsNullOrEmpty(key)) |
| 181 | + sb.AppendLine("Key: " + key); |
| 182 | + if (!String.IsNullOrEmpty(localFile)) |
| 183 | + sb.AppendLine("LocalFile: " + localFile); |
| 184 | + if (!String.IsNullOrEmpty(domain)) |
| 185 | + sb.AppendLine("Domain: " + domain); |
| 186 | + Console.WriteLine(sb.ToString()); |
| 187 | + } |
| 188 | + |
| 189 | + |
| 190 | + public static void PrintRet(CallRet callRet) |
| 191 | + { |
| 192 | + Console.WriteLine("\n[Out]"); |
| 193 | + |
| 194 | + Console.WriteLine("\nCallRet"); |
| 195 | + Console.WriteLine("StatusCode: " + callRet.StatusCode.ToString()); |
| 196 | + Console.WriteLine("Response:\n" + callRet.Response); |
| 197 | + Console.WriteLine(); |
| 198 | + } |
| 199 | + |
| 200 | + public static void Main() |
| 201 | + { |
| 202 | + Config.ACCESS_KEY = "RLT1NBD08g3kih5-0v8Yi6nX6cBhesa2Dju4P7mT"; |
| 203 | + Config.SECRET_KEY = "k6uZoSDAdKBXQcNYG3UOm4bP3spDVkTg-9hWHIKm"; |
| 204 | + |
| 205 | + conn = new DigestAuthClient(); |
| 206 | + rs = new RSService(conn, tableName); |
| 207 | + localFile = Process.GetCurrentProcess().MainModule.FileName; |
| 208 | + key = System.IO.Path.GetFileName(localFile); |
| 209 | + |
| 210 | + PutFile(); |
| 211 | + Get(); |
| 212 | + Stat(); |
| 213 | + Delete(); |
| 214 | + CliPutFile(); |
| 215 | + Get(); |
| 216 | + Stat(); |
| 217 | + Publish(); |
| 218 | + UnPublish(); |
| 219 | + Drop(); |
| 220 | + |
| 221 | + Console.ReadLine(); |
| 222 | + } |
| 223 | + } |
| 224 | +} |
0 commit comments