Пример #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 EncryptDecryptTextFromFile()
        {
            IList <string> data      = PrepareData();
            string         sessionId = (200 + TimingHelper.GetCurrentTimestamp()).ToString();

            CacheProcessor.SaveData(data, sessionId, false);
            CacheProcessor.EncryptData(sessionId);
            CacheProcessor.DeleteDecryptedData(sessionId);
            CacheProcessor.DecryptData(sessionId);
            CacheProcessor.DeleteEncryptedData(sessionId);
            IList <string> loadedData = CacheProcessor.LoadData(sessionId);

            Assert.IsTrue(loadedData.Count == data.Count);
            for (int i = 0; i < loadedData.Count; i++)
            {
                Assert.IsTrue(data[i].Equals(loadedData[i]));
            }

            CacheProcessor.DeleteAllSessions();
        }