Esempio n. 1
0
        public void StopRetryUpload(DS4Session session)
        {
            Uploader uploader;

            if (AllUploads.TryGetValue(session, out uploader))
            {
                uploader.TryCancel();
            }
        }
        public void StopRetryUpload(DS4Session session)
        {
            Uploader uploader;

            if (AllUploads.TryGetValue(session, out uploader))
            {
                uploader.TryCancel();
            }
        }
        public Uploader StartUpload(string apiKey, string apiSecret, string apiBase, DS4Session session)
        {
            Uploader uploader;

            if(!_uploaders.TryGetValue(session, out uploader))
            {
                uploader = new Uploader(apiKey, apiSecret, apiBase, session);
                uploader.Completing += (sender, e) =>
                {
                    if (e.Success)
                    {
                        //session.Metadata.BodyhubPersonId = e.BodyhubPersonId;
                        //_store.Save();
                    }
                };

                _uploaders[session] = uploader;
            }

            if (!File.Exists(session.CompressedScanFile))
            {
                // Something went wrong probably during Compression and file is deleted
                throw new InvalidOperationException("Compressed Scan file is missing!");

            }

            session.Uploader = uploader;

            if(uploader.Waiting)
            {
                throw new InvalidOperationException("Uploader is already enqueued for upload");
            }
            else if (uploader.InProgress)
            {
                throw new InvalidOperationException("Upload is already in progress");
            }
            else if (uploader.ReTrying)
            {
                AutoReTryer autoReTryer = uploader.ReTryer;

                if (autoReTryer == null)
                {
                    throw new InvalidOperationException("Uploader in ReTrying state should have a ReTryer registered");
                }

                autoReTryer.StartNow();
            }
            else
            {
                EnqueueUploadWork(uploader);
            }
            return uploader;
        }
Esempio n. 4
0
        public Uploader StartUpload(string apiKey, string apiSecret, string apiBase, DS4Session session)
        {
            Uploader uploader;

            if (!_uploaders.TryGetValue(session, out uploader))
            {
                uploader             = new Uploader(apiKey, apiSecret, apiBase, session);
                uploader.Completing += (sender, e) =>
                {
                    if (e.Success)
                    {
                        //session.Metadata.BodyhubPersonId = e.BodyhubPersonId;
                        //_store.Save();
                    }
                };

                _uploaders[session] = uploader;
            }

            if (!File.Exists(session.CompressedScanFile))
            {
                // Something went wrong probably during Compression and file is deleted
                throw new InvalidOperationException("Compressed Scan file is missing!");
            }

            session.Uploader = uploader;

            if (uploader.Waiting)
            {
                throw new InvalidOperationException("Uploader is already enqueued for upload");
            }
            else if (uploader.InProgress)
            {
                throw new InvalidOperationException("Upload is already in progress");
            }
            else if (uploader.ReTrying)
            {
                AutoReTryer autoReTryer = uploader.ReTryer;

                if (autoReTryer == null)
                {
                    throw new InvalidOperationException("Uploader in ReTrying state should have a ReTryer registered");
                }

                autoReTryer.StartNow();
            }
            else
            {
                EnqueueUploadWork(uploader);
            }
            return(uploader);
        }
Esempio n. 5
0
        public async Task ArchiveAndStartUpload(DS4Session session, string apiBase, string apiKey, string apiSecret)
        {
            // Archive

            if (!File.Exists(session.CompressedScanFile))
            {
                Archiver archiver = new Archiver();
                session.Compressing = true;
                ArchiveResult result = await archiver.PerformArchive(session.SessionPath, session.CompressedScanFile);

                if (!result.Success)
                {
                    return;
                }
            }

            session.Compressing = false;

            _upload(session, apiBase, apiKey, apiSecret);
        }
        public void StartNewSession(string name = "")
        {
            string guid = Guid.NewGuid().ToString();
            string sessionFolderName = name != "" ? String.Concat(name, "-", guid): guid;
            string path = Path.Combine(_baseDirectory, sessionFolderName);

            _session = new DS4Session(path, Enumerable.Empty <ShotDefinition>());
            //FIXEME: Load device config here
            _session.Metadata = new DS4Meta
            {
                DeviceConfig = new DS4Meta.DS4DeviceConfig {
                },
                CaptureMode  = this.CaptureMode.ToString().ToLower(),
                FrameItems   = new List <List <DS4SavedItem> >()
            };

            if (_sessionManager != null)
            {
                _sessionManager.Reset(_session);
            }
        }
        public async Task CompressAndUploadAndStartNewSession()
        {
            DS4Session oldSession = _captureController.Session;

            await _uploadManager.ArchiveAndStartUpload(oldSession, Settings.Default.apiBase, Settings.Default.accessKey, Settings.Default.secret);
        }
        private void _upload(DS4Session session, string apiBase, string apiKey, string apiSecret)
        {
            Uploader uploader = this.StartUpload(apiKey, apiSecret, apiBase, session);

            uploader.Completed += UploadFinished;
            
        }
        public async Task ArchiveAndStartUpload(DS4Session session, string apiBase, string apiKey, string apiSecret)
        {
            // Archive

            if (!File.Exists(session.CompressedScanFile))
            {
                Archiver archiver = new Archiver();
                session.Compressing = true;
                ArchiveResult result = await archiver.PerformArchive(session.SessionPath, session.CompressedScanFile);

                if (!result.Success)
                {
                    return;
                }
            }

            session.Compressing = false;

            _upload(session, apiBase, apiKey, apiSecret);
            
        }
Esempio n. 10
0
        /// <summary>
        /// Uploads the specified file to   the cloud.
        /// </summary>
        /// <param name="file">The full path to the desired .zip file.</param>
        private async Task<UploadResult> Upload(DS4Session session, CancellationToken ct)
        {
            string file = session.CompressedScanFile;
            string contentType = "application/x/7z-compressed";

            WebClient proxy;

            string result = string.Empty;

            // Step1: Get s3 signed URL
            proxy = new WebClient();

            // Gather data
            string fileName = Path.GetFileName(file);
            
            Dictionary<string, string> postDict = new Dictionary<string, string> {
                {"filename", fileName},
                {"file_type", contentType},
            };

            String postData = JSONHelper.Instance.Serialize(postDict);
            // Prepare request
            proxy.Headers["Content-Type"] = "application/json";
            proxy.Headers["Authorization"] = _authHeader;

            // Perform request            
            try
            {
                result = await proxy.UploadStringTaskAsync(this.BuildUri("s3/sign"), "POST", postData);
            }
            catch (WebException ex)
            {
                return new UploadResult { Success = false, Exception = ex };
            }

            ct.ThrowIfCancellationRequested();

            // Step 2: Upload to s3 signed PUT URL
            _s3Proxy = proxy = new WebClient();
            proxy.UploadProgressChanged += new UploadProgressChangedEventHandler(this.Progress);
            proxy.UploadDataCompleted += (s , e) => { if(ct.IsCancellationRequested) _canceled = true; };

            // Gather data
            Dictionary<string, string> response = JSONHelper.Instance.CreateDictionary(result);
            string url = response["signedUrl"];
            string key = response["key"];

            byte[] binaryData = File.ReadAllBytes(file);

            // Prepare headers
            proxy.Headers["Content-Type"] = contentType;

            // Prepare request
            Uri uri = new Uri(url, UriKind.Absolute);
            // Perform request
            try
            {
                byte[] uploadResponse = await proxy.UploadDataTaskAsync(uri, "PUT", binaryData);
            }
            catch (WebException ex)
            {
                
                Console.WriteLine(Uploader.GetErrorMsgFromWebException(ex));
                return new UploadResult { Success = false, Exception = ex, Canceled = _canceled };
            }

            ct.ThrowIfCancellationRequested();

            // Step 3: PostUpload and get returned BodyId
            proxy = new WebClient();

            //Assemble payload
            List<Dictionary<string, string> > artifacts = new List<Dictionary<string, string> >();
            artifacts.Add(new Dictionary<string, string> { 
                {"artifactsType","DS4Measurements"}
            });

            artifacts.Add(new Dictionary<string, string> { 
                {"artifactsType","DS4Alignment"}
            });

            DS4BodyRequest bodyRequest = new DS4BodyRequest("ds4_scan", key, artifacts);

            postData = JSONHelper.Instance.Serialize(bodyRequest);

            // Prepare request
            proxy.Headers["Content-Type"] = "application/json";
            proxy.Headers["Authorization"] = _authHeader;

            // Perform request
            try
            {
                result = await proxy.UploadStringTaskAsync(this.BuildUri("bodies/from_scan"), "POST", postData);
            }
            catch (WebException ex)
            {
                Console.WriteLine(Uploader.GetErrorMsgFromWebException(ex));
                return new UploadResult { Success = false, Exception = ex };
            }

            DS4PostUploadResponse ds4PostUploadResponse;
            using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(result)))
            {
                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(DS4PostUploadResponse));
                ds4PostUploadResponse = (DS4PostUploadResponse)serializer.ReadObject(ms);
                ms.Close();
            }

            string bodyId = ds4PostUploadResponse.BodyId;

            return new UploadResult { Success = true, BodyId = bodyId, Artifacts = ds4PostUploadResponse.Artifacts };
        }
Esempio n. 11
0
 public Uploader(string apiKey, string apiSecret, string apiBase, DS4Session session) : base(apiKey, apiSecret, apiBase) 
 {
     _session = session;
    
     _authHeader =  "SecretPair accessKey=" + apiKey + ",secret=" + apiSecret;
 }
Esempio n. 12
0
        /// <summary>
        /// Uploads the specified file to   the cloud.
        /// </summary>
        /// <param name="file">The full path to the desired .zip file.</param>
        private async Task <UploadResult> Upload(DS4Session session, CancellationToken ct)
        {
            string file        = session.CompressedScanFile;
            string contentType = "application/x/7z-compressed";

            WebClient proxy;

            string result = string.Empty;

            // Step1: Get s3 signed URL
            proxy = new WebClient();

            // Gather data
            string fileName = Path.GetFileName(file);

            Dictionary <string, string> postDict = new Dictionary <string, string> {
                { "filename", fileName },
                { "file_type", contentType },
            };

            String postData = JSONHelper.Instance.Serialize(postDict);

            // Prepare request
            proxy.Headers["Content-Type"]  = "application/json";
            proxy.Headers["Authorization"] = _authHeader;

            // Perform request
            try
            {
                result = await proxy.UploadStringTaskAsync(this.BuildUri("s3/sign"), "POST", postData);
            }
            catch (WebException ex)
            {
                return(new UploadResult {
                    Success = false, Exception = ex
                });
            }

            ct.ThrowIfCancellationRequested();

            // Step 2: Upload to s3 signed PUT URL
            _s3Proxy = proxy = new WebClient();
            proxy.UploadProgressChanged += new UploadProgressChangedEventHandler(this.Progress);
            proxy.UploadDataCompleted   += (s, e) => { if (ct.IsCancellationRequested)
                                                       {
                                                           _canceled = true;
                                                       }
            };

            // Gather data
            Dictionary <string, string> response = JSONHelper.Instance.CreateDictionary(result);
            string url = response["signedUrl"];
            string key = response["key"];

            byte[] binaryData = File.ReadAllBytes(file);

            // Prepare headers
            proxy.Headers["Content-Type"] = contentType;

            // Prepare request
            Uri uri = new Uri(url, UriKind.Absolute);

            // Perform request
            try
            {
                byte[] uploadResponse = await proxy.UploadDataTaskAsync(uri, "PUT", binaryData);
            }
            catch (WebException ex)
            {
                Console.WriteLine(Uploader.GetErrorMsgFromWebException(ex));
                return(new UploadResult {
                    Success = false, Exception = ex, Canceled = _canceled
                });
            }

            ct.ThrowIfCancellationRequested();

            // Step 3: PostUpload and get returned BodyId
            proxy = new WebClient();

            //Assemble payload
            List <Dictionary <string, string> > artifacts = new List <Dictionary <string, string> >();

            artifacts.Add(new Dictionary <string, string> {
                { "artifactsType", "DS4Measurements" }
            });

            artifacts.Add(new Dictionary <string, string> {
                { "artifactsType", "DS4Alignment" }
            });

            DS4BodyRequest bodyRequest = new DS4BodyRequest("ds4_scan", key, artifacts);

            postData = JSONHelper.Instance.Serialize(bodyRequest);

            // Prepare request
            proxy.Headers["Content-Type"]  = "application/json";
            proxy.Headers["Authorization"] = _authHeader;

            // Perform request
            try
            {
                result = await proxy.UploadStringTaskAsync(this.BuildUri("bodies/from_scan"), "POST", postData);
            }
            catch (WebException ex)
            {
                Console.WriteLine(Uploader.GetErrorMsgFromWebException(ex));
                return(new UploadResult {
                    Success = false, Exception = ex
                });
            }

            DS4PostUploadResponse ds4PostUploadResponse;

            using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(result)))
            {
                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(DS4PostUploadResponse));
                ds4PostUploadResponse = (DS4PostUploadResponse)serializer.ReadObject(ms);
                ms.Close();
            }

            string bodyId = ds4PostUploadResponse.BodyId;

            return(new UploadResult {
                Success = true, BodyId = bodyId, Artifacts = ds4PostUploadResponse.Artifacts
            });
        }
Esempio n. 13
0
        public Uploader(string apiKey, string apiSecret, string apiBase, DS4Session session) : base(apiKey, apiSecret, apiBase)
        {
            _session = session;

            _authHeader = "SecretPair accessKey=" + apiKey + ",secret=" + apiSecret;
        }
Esempio n. 14
0
        private void _upload(DS4Session session, string apiBase, string apiKey, string apiSecret)
        {
            Uploader uploader = this.StartUpload(apiKey, apiSecret, apiBase, session);

            uploader.Completed += UploadFinished;
        }
        public void StartNewSession(string name="")
        {
            string guid = Guid.NewGuid().ToString();
            string sessionFolderName = name !="" ? String.Concat(name, "-", guid): guid;
            string path = Path.Combine(_baseDirectory, sessionFolderName);
            _session = new DS4Session(path, Enumerable.Empty<ShotDefinition>());
            //FIXEME: Load device config here
            _session.Metadata = new DS4Meta
            {
                DeviceConfig = new DS4Meta.DS4DeviceConfig { },
                CaptureMode = this.CaptureMode.ToString().ToLower(),
                FrameItems = new List<List<DS4SavedItem>>()
            };

            if (_sessionManager != null)
            {
                _sessionManager.Reset(_session);
            }
        }