Ejemplo n.º 1
0
        /// <summary
        /// GetData , then encrypt , then Compress file and copy to file system
        /// </summary>
        /// <param name="datasetIds"></param>
        /// <param name="filePath"></param>
        /// <param name="folderPath"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public DataResponseModel generateJSON(List<int> datasetIds , string filePath , string folderPath , string fileName)
        {
            DataResponseModel dataResponseModel = new DataResponseModel();

            DataSetRepo dataSetRepo = new DataSetRepo();
            JsonDatasetModel Jdsm = dataSetRepo.GetData(datasetIds, filePath);

            if (Jdsm == null)
            {
                dataResponseModel.IsValid = true;
                dataResponseModel.Error = "Dataset Not Exist";
                return dataResponseModel;
            }

            #region Encrypt
            Encryption ec = new Encryption();
            JsonDatasetModel encryptedData = ec.Secure(Jdsm);
            #endregion

            #region CompressFileAndCopyToFileSystem
            CompressFile cf = new CompressFile();
            cf.GetCompressed(Jdsm, filePath, folderPath, fileName);
            #endregion

            return dataResponseModel;
        }
Ejemplo n.º 2
0
        public DataResponseModel UpdateFromServer()
        {
            var BackUpSourceDir = System.Web.Hosting.HostingEnvironment.MapPath(System.Configuration.ConfigurationManager.AppSettings["DataBackupSourcePath"]);
            var BackUpTargetDir = System.Web.Hosting.HostingEnvironment.MapPath(System.Configuration.ConfigurationManager.AppSettings["DataBackupTargetPath"]);
            BackUpTargetDir = string.Format("{0}{1}_{2}_{3}_{4}_{5}_{6}",BackUpTargetDir, DateTime.Now.Day , DateTime.Now.Month, DateTime.Now.Year ,DateTime.Now.Hour,DateTime.Now.Minute,DateTime.Now.Second);

            Backup createBackup = new Backup();
            createBackup.CreateBackupOfFiles(BackUpSourceDir ,BackUpTargetDir);

            bool IsDataSetPublished = true;
            DataResponseModel responseModel = new DataResponseModel();
            int[] datasetId = new int[5];
            datasetId[0] = 4;
            datasetId[1] = 7;
            datasetId[2] = 10004;
            datasetId[3] = 10007;

            List<int> datasetIds;
            for (int i = 0; i < 5; i++)
            {
                if (i == 4)
                {
                    datasetIds = new List<int>();
                    datasetIds.Add(datasetId[0]);
                    datasetIds.Add(datasetId[1]);
                    IsDataSetPublished = false;
                }

                else
                {
                    datasetIds = new List<int>();
                    datasetIds.Add(datasetId[i]);
                    IsDataSetPublished = true;

                }

                string fileName = "";
                var folderPath = "";
                var filePath = "";

                GenerateJSON createFile = new GenerateJSON();
                createFile.createFileName(datasetIds, ref filePath, ref folderPath, ref fileName);

                createFile.generateJSON(datasetIds, filePath, folderPath, fileName);


                if (IsDataSetPublished)   //Update Date Last Published On Data Set Table
                {
                    DataSetRepo repo = new DataSetRepo();
                    repo.DateLastPublished(datasetId[i]);
                }
            }

            responseModel.IsValid = true;
            responseModel.Error = null;
            return responseModel;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Delete free data , create file name , Get all dataset of users and generate file if not exist on file system
        /// </summary>
        /// <param name="requestModel"></param>
        /// <returns></returns>
        public DataResponseModel DownloadFile(DataRequestModel requestModel)
        {
            DataResponseModel dataResponseModel = new DataResponseModel();
            var datasetIds = new List<int>();

            DownloadRepo downloadrepo = new DownloadRepo();
            int? UserId = downloadrepo.GetUserId(requestModel.GUID, requestModel.DeviceId, requestModel.AppId);

            if(UserId == null)
            {
                dataResponseModel.IsValid = false;
                dataResponseModel.Error = "Invalid User";
                return dataResponseModel;
            }


            if ((requestModel.DatasetID == 0))   //Full Data                      //If full data
            {
                if (UserId == null)
                {
                    dataResponseModel.IsValid = false;
                    dataResponseModel.Error = "Invalid User";
                    return dataResponseModel;
                }


                List<int> getUserDataSets = downloadrepo.GetUserDataset(UserId.Value);

                if (getUserDataSets == null)
                {
                    dataResponseModel.IsValid = false;
                    dataResponseModel.Error = "Invalid User";
                    return dataResponseModel;
                }

                DestroyFreeDataRepo destroyFree = new DestroyFreeDataRepo();
                destroyFree.DeleteFreeData(UserId.Value);

                datasetIds = getUserDataSets;
            }
            else       
            {

                DestroyFreeDataRepo destroyFree = new DestroyFreeDataRepo();
                destroyFree.DeleteFreeData(UserId.Value);

                AddFreeData addFreeData = new AddFreeData();
                addFreeData.AddData(UserId.Value,requestModel.DatasetID);

                datasetIds.Add(requestModel.DatasetID);
            }

            string fileName = "";
            var folderPath = "";
            var filePath = "";

            GenerateJSON createFile = new GenerateJSON();            //Create File Name
            createFile.createFileName(datasetIds,ref filePath ,ref folderPath ,ref fileName);

            
            if (!File.Exists(filePath))
            {
                GenerateJSON generateJSON = new GenerateJSON();       //File Not Exists then generate data
                generateJSON.generateJSON(datasetIds,filePath,folderPath,fileName);
            }

            filePath = System.Web.Hosting.HostingEnvironment.MapPath(string.Format("{0}{1}", folderPath, fileName + ".gz"));   //Creating File Path

            GenerateTokenRepo token = new GenerateTokenRepo();
            string TokenId = token.AddToDatabase(requestModel.GUID , filePath);


            //InstallationRepo installationRepo = new InstallationRepo();
            //installationRepo.LastDateUpdated(requestModel.GUID);

            dataResponseModel.IsValid = true;
            dataResponseModel.Error = null;
            dataResponseModel.TokenId = TokenId;
            return dataResponseModel;
        }