Пример #1
0
        private string PrepareDataAndPostSession(string sessionId,
                                                 bool appendData, ref NameValueCollection postParams)
        {
            //CacheProcessor.CreateDecryptedImages(sessionId);
            //List<string> decryptedImagePaths = new List<string>(CacheProcessor.GetDecryptedImagePaths(sessionId));
            //if (decryptedImagePaths == null || decryptedImagePaths.Count <= 0)
            //    return string.Empty;

            CacheProcessor.DecryptData(sessionId);
            List <string> loadedData = CacheProcessor.LoadData(sessionId);

            if ((loadedData == null || loadedData.Count <= 0) && !appendData)
            {
                CacheProcessor.DeleteSessionFolder(sessionId);
                return("EMPTY_FOLDER");
            }

            CacheProcessor.CreateDecryptedImages(sessionId);
            List <string> decryptedImagePaths = new List <string>(CacheProcessor.GetDecryptedImagePaths(sessionId));

            if (appendData)
            {
                postParams = _ServerApiProvider.AppendPostSessionParams(loadedData,
                                                                        CurrentContext.GetInstance().Session, CurrentContext.GetInstance().LoginData);
            }
            else
            {
                postParams = _ServerApiProvider.CreatePostSessionParams(loadedData);
            }

            string postUrl = _ServerApiProvider.CreatePostSessionUrl();

            if (!WebProcessor.CheckInternetConnection())
            {
                ErrorTimer.GetInstance().StartTimer();
                return("CONNECTION_FAIL");
            }

            return(WebProcessor.UploadFileWithParams(postUrl,
                                                     _ServerApiProvider.PrepareFilesData(decryptedImagePaths, "screenshot_files[]", "image/jpeg"), postParams));

            /* MOCK */

            /*FAKE++;
             *
             * if (FAKE == 0)
             *  return WebProcessor.UploadFileWithParams(postUrl,
             *  _ServerApiProvider.PrepareFilesData(decryptedImagePaths), postParams);
             * else if (FAKE > 0 && FAKE < 3)
             *  return "FAIL";
             * else
             *  return WebProcessor.UploadFileWithParams(postUrl,
             *  _ServerApiProvider.PrepareFilesData(decryptedImagePaths), postParams);*/

            /* MOCK */
        }
        public void DecryptedImageSaveTest()
        {
            Image  img       = ActivityProcessor.GetInstance().MakeScreenshot();
            string sessionId = (200 + TimingHelper.GetCurrentTimestamp()).ToString();

            CacheProcessor.SaveImage(img, "300", sessionId, false);
            string[] imgPaths = CacheProcessor.GetDecryptedImagePaths(sessionId);
            Assert.IsTrue(imgPaths.Length == 1);
            Assert.IsTrue(imgPaths[0].Contains("300.jpg"));
            CacheProcessor.DeleteAllSessions();
        }