Пример #1
0
        private async void uploadPhoto(HttpRequest request)
        {
            //var data = parseRequest(Encoding.UTF8.GetString(request.Content, 0, request.Content.Length));
            HttpResponse response = new HttpResponse();

            string endOfSOAP = "</SOAP-ENV:Envelope>";
            string boundaryDetect = "multipart/form-data; boundary=";
            string soapHexValue = "";
            string boundaryValue = "";
            string boundaryHexValue = "";

            soapHexValue = StringToHex(endOfSOAP);

            var parts = request.Headers["Content-Type"].Split();
            boundaryValue = parts[1].Split('=')[1].Trim();

            Debug.WriteLine("Content Length: " + request.Content.Length);
            string content = UTF8Encoding.UTF8.GetString(request.Content, 0, request.Content.Length);

            if (content.Contains(boundaryValue))
            {
                Debug.WriteLine("Boundary Found");

                int finalBoundary = content.LastIndexOf(boundaryValue);

                if (content.Contains("<filename>") && content.Contains("<filesize>"))
                {
                    int fileNameIndexStart = content.IndexOf("<filename>") + 10;
                    int fileNameIndexStop = content.IndexOf("</filename>");
                    int fileSizeStart = content.IndexOf("<filesize>") + 10;
                    int fileSizeStop = content.IndexOf("</filesize>");
                    int fileOffsetStart = content.IndexOf("<offset>");
                    int fileOffsetStop = content.IndexOf("</offset>");
                    int fileSize = Convert.ToInt32(content.Substring(fileSizeStart, fileSizeStop - fileSizeStart));
                    int fileOffset = Convert.ToInt32(content.Substring(fileOffsetStart, fileOffsetStop - fileOffsetStart));
                    string fileName = content.Substring(fileNameIndexStart, fileNameIndexStop - fileNameIndexStart);
                    fileName = fileName.Substring(0, fileName.IndexOf(".tar"));

                    var headEnd = "application/x-tar\r\n\r\n";
                    var header = Encoding.UTF8.GetBytes(content.Substring(0, content.LastIndexOf(headEnd) + headEnd.Length));

                    var dt = request.Content.ToList();
                    dt.RemoveRange(0, header.Length);

                    Debug.WriteLine(string.Format("File Size: {0} \r\n File Offset: {1}", fileSize, fileOffset));

                    MediaLibrary library = new MediaLibrary();

                    try
                    {

                        MemoryStream ms = new MemoryStream(dt.ToArray());

                        using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
                        {
                            TarReader reader = TarReader.Open(ms);
                            var archive = TarArchive.Open(ms);
                            while (reader.MoveToNextEntry())
                            {
                                Debug.WriteLine(reader.Entry.FilePath);
                                var isfs = new IsolatedStorageFileStream(reader.Entry.FilePath, FileMode.Create, FileAccess.ReadWrite, isf);
                                //StreamWriter writer = new StreamWriter(isfs);
                                reader.WriteEntryTo(isfs);
                                //writer.Close();
                                isfs.Close();
                            }
                        }

                        //respond that the photo has been uploaded
                        getPhotoUploadResponse(request);

                        //delete the tar file
                        try
                        {
                            //File.Delete(photoSaveLocation + "\\" + fileName + ".tar");
                        }
                        catch (Exception tarDeleteException)
                        {

                        }
                    }
                    catch (Exception e)
                    {

                    }
                }
            }
            else Debug.WriteLine("Boundary Not Found");             
        }
Пример #2
0
        private HttpResponse markLastPhotoInRoll(HttpRequest request)
        {
            var data = parseRequest(Encoding.UTF8.GetString(request.Content, 0, request.Content.Length));
            HttpResponse response = new HttpResponse();

            response.Protocol = "HTTP/1.1";
            response.StatusCode = 200;
            response.StatusDescription = "OK";
            response.KeepAlive = false;
            response.Headers.Add("Pragma", "no-cache");
            response.Headers.Add("Server", "Eye-Fi Agent/3.2.4 6(Windows, 32-bit)");
            response.ContentType = "text/xml; charset=\"utf-8\"";
            response.Content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"EyeFi/SOAP/EyeFilm\"><SOAP-ENV:Body><ns1:MarkLastPhotoInRoll><macaddress>" + data.MacAddress + "</macaddress><mergedelta>0</mergedelta></ns1:MarkLastPhotoInRoll></SOAP-ENV:Body></SOAP-ENV:Envelope>";
            return response;
        }
Пример #3
0
        private HttpResponse startSession(HttpRequest request)
        {
            var data = parseRequest(Encoding.UTF8.GetString(request.Content, 0, request.Content.Length));
            HttpResponse response = new HttpResponse();

            String credential = data.MacAddress + data.CNONCE + UPLOAD_KEY;
            byte[] byteResult = StringToByteArray(credential);
            string md5Credential = AnotherMD5(byteResult);

            response.Protocol = "HTTP/1.1";
            response.StatusCode = 200;
            response.StatusDescription = "OK";
            response.Headers.Add("Pragma", "no-cache");
            response.Headers.Add("Server", "Eye-Fi Agent/3.2.4 (Windows 7 Ultimate Edition, 32-bit)");
            response.ContentType = "text/xml; charset=\"utf-8\"";
            response.KeepAlive = true;

            StringBuilder sb = new StringBuilder();
            sb.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Body><StartSessionResponse xmlns=\"http://localhost/api/soap/eyefilm\"><credential>");
            sb.Append(md5Credential);
            sb.Append("</credential><snonce>1a125fd1d8ea28911a3decdb3169b26e</snonce><transfermode>32770</transfermode><transfermodetimestamp>1295190150</transfermodetimestamp><upsyncallowed>true</upsyncallowed></StartSessionResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>");
            response.Content = sb.ToString();

            return response;
        }
Пример #4
0
        private HttpResponse getPhotoStatus(HttpRequest request)
        {
            var data = parseRequest(Encoding.UTF8.GetString(request.Content, 0, request.Content.Length));
            HttpResponse response = new HttpResponse();

            response.Protocol = "HTTP/1.1";
            response.StatusCode = 200;
            response.StatusDescription = "OK";
            response.Headers.Add("Pragma", "no-cache");
            response.Headers.Add("Server", "Eye-Fi Agent/3.2.4 (Windows 7 Ultimate Edition, 32-bit)");
            response.ContentType = "text/xml; charset=\"utf-8\"";
            response.Content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Body><GetPhotoStatusResponse xmlns=\"http://localhost/api/soap/eyefilm\"><fileid>293</fileid><offset>0</offset></GetPhotoStatusResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>";
            response.KeepAlive = true;
            return response;
        }
Пример #5
0
        private HttpResponse getPhotoUploadResponse(HttpRequest request)
        {
            HttpResponse response = new HttpResponse();
            response.Protocol = "HTTP/1.1";
            response.StatusCode = 200;
            response.StatusDescription = "OK";
            response.Headers.Add("Date", DateTime.Today.ToString());
            response.Headers.Add("Pragma", "no-cache");
            response.Headers.Add("Server", "Eye-Fi Agent/3.2.4 (Windows 7 Ultimate Edition, 32-bit)");
            response.ContentType = "text/xml; charset=\"utf-8\"";

            String xmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Body><UploadPhotoResponse xmlns=\"http://localhost/api/soap/eyefilm\"><success>true</success></UploadPhotoResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>";
            return response;
        }