internal MobeelizerInputData(Others.File inputFile) { MemoryStream tmpStream = new MemoryStream(); using (IsolatedStorageFileStream stream = inputFile.OpenToRead()) { stream.CopyTo(tmpStream); } this.zipFile = new ZipFile(tmpStream); }
public MobeelizerSyncResponse SendSyncDiffRequest(Others.File outputFile) { String boundary = DateTime.Now.Ticks.ToString(); WebRequest request = WebRequest.Create(GetUrl("/synchronize")); request.Method = "POST"; request.ContentType = String.Format("multipart/form-data; boundary={0}",boundary); using (Stream requestStream = new Synchronizer().GetRequestStream(request)) { String header = String.Format("--{0}\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file\";\r\nContent-Type: application/octet-stream\r\n\r\n", boundary); requestStream.Write(Encoding.UTF8.GetBytes(header), 0, header.Length); using (IsolatedStorageFileStream stream = outputFile.OpenToRead()) { int lenght = (int)stream.Length; byte[] bytes = new byte[lenght]; stream.Read(bytes, 0, lenght); requestStream.Write(bytes, 0, lenght); } string footer = "\r\n--" + boundary + "--\r\n"; byte[] footerbytes = Encoding.UTF8.GetBytes(footer); requestStream.Write(footerbytes, 0, footerbytes.Length); } SetHeaders(request, false, true); try { MobeelizerResponse response = new Synchronizer().GetResponse(request); if (response.StatusCode == HttpStatusCode.OK) { return new MobeelizerSyncResponse((response as MobeelizerTicketResponse).Ticket); } else if (response.StatusCode == HttpStatusCode.InternalServerError) { return new MobeelizerSyncResponse(MobeelizerOperationError.ServerError((response as MobeelizerJsonResponse).Json)); } else { throw new IOException("Http connection status code: " + response.StatusCode.ToString()); } } catch (NullReferenceException) { throw new IOException("Server not respond."); } }