Beispiel #1
0
        public ActionResult CreateRelease(string[] selectedCompanys)
        {
            var parameterInstance = ParameterSingleton.Instance;
            var nameVersion       = $"{parameterInstance.ParameterList.FirstOrDefault(x => x.ParameterInternalIdentificator == ParameterInternalIdentificator.VersionValue).Value}.{DateTime.Now.Year.ToString().Substring(2)}.{DateTime.Now.Month}.{DateTime.Now.DayOfYear}.{DateTime.Now.Hour}";
            var path = $"{_directoryPath}/{nameVersion}";

            if (!Directory.Exists(path))
            {
                return(RedirectToAction("Index"));
            }

            var currentNotesData = Request.Form["Notes"];

            if (currentNotesData == null)
            {
                throw new Exception("Notes relase was not found");
            }

            if (string.IsNullOrEmpty(currentNotesData) || currentNotesData.Length < Convert.ToInt32(parameterInstance.ParameterList.FirstOrDefault(x => x.ParameterInternalIdentificator == ParameterInternalIdentificator.ValidDaysToken).Value))
            {
                ModelState.AddModelError(string.Empty, @"Ingrese las notas de la versión, al menos " + parameterInstance.ParameterList.FirstOrDefault(x => x.ParameterInternalIdentificator == ParameterInternalIdentificator.ValidDaysToken).Value + " caractéres");
                ViewBag.Companys = _companyService.GetAllCompanys();
                return(View("Create"));
            }

            if (!Directory.Exists($"{path}.zip"))
            {
                Compress.CompressFolder($"{path}.zip", path);
                byte[] releaseContent = System.IO.File.ReadAllBytes($"{path}.zip");
                var    release        = new Release
                {
                    UserId         = User.Id,
                    IsSafe         = true,
                    Published      = DateTime.Now,
                    Version        = nameVersion,
                    Notes          = currentNotesData,
                    ReleaseContent = releaseContent
                };

                _releaseService.Create(release);
                Log.Instance.Info($"Usuario {User.Name} {User.LastName} creo el release {nameVersion}");

                if (selectedCompanys != null)
                {
                    foreach (var company in selectedCompanys)
                    {
                        _companyReleaseService.Save(new ServerRelease
                        {
                            ServerId  = new Guid(company),
                            ReleaseId = release.Id
                        });
                    }
                }

                Directory.Delete(_directoryPath, true);
            }

            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        private byte[] CreateRelease(ServerUpdate companyUpdate, List <Release> recenteRelease)
        {
            var pathDownload = Path.Combine(_directoryPath + $@"\Isolucion_{User.Name}_{recenteRelease.Last().Version}");

            Directory.CreateDirectory(pathDownload);
            foreach (var release in recenteRelease)
            {
                Log.Instance.Info($"Copiando release {release.Version} para descargar");
                System.IO.File.WriteAllBytes($@"{_directoryPath}\{release.Version}.zip", release.ReleaseContent);
                var path = Path.Combine(_directoryPath + $@"\{release.Version}.zip");
                if (!Directory.Exists(path))
                {
                    System.IO.File.Copy(path, $@"{pathDownload}\{release.Version}.zip", true);
                }

                _companyUpdateService.Save(new ServerUpdate
                {
                    ReleaseId = release.Id,
                    ServerId  = companyUpdate.ServerId,
                    Update    = companyUpdate.Update
                });
            }

            _companyUpdateService.CreateXml(new ServerUpdate
            {
                ReleaseId = recenteRelease.LastOrDefault().Id,
                ServerId  = companyUpdate.ServerId,
                Update    = companyUpdate.Update
            }, $@"{pathDownload}\CompanyUpdate.xml");

            if (!Directory.Exists($"{pathDownload}.zip"))
            {
                Compress.CompressFolder($"{pathDownload}.zip", pathDownload);
                Log.Instance.Info($"Comprimiendo archivo {pathDownload}.zip para descargar");
            }

            var fs   = System.IO.File.OpenRead($"{pathDownload}.zip");
            var data = new byte[fs.Length];
            var br   = fs.Read(data, 0, data.Length);

            if (br != fs.Length)
            {
                throw new IOException($"{pathDownload}.zip");
            }
            return(data);
        }
Beispiel #3
0
        /// <summary>
        /// </summary>
        /// <param name="blobData"></param>
        /// <param name="appContentType"></param>
        /// <param name="Base64TokenApplication"></param>
        /// <returns></returns>
        public OperationResult AssembleTokenApplication(byte[] blobData, out string appContentType, out string Base64TokenApplication)
        {
            appContentType         = null;
            Base64TokenApplication = null;

            string   _tempFolder  = null;
            Extract  _cabExtract  = new Extract();
            Compress _cabCompress = new Compress();

            try
            {
                _tempFolder = _getTempFolder();
                _cabExtract.ExtractFile(_getTemplateFile(), _tempFolder);
                _writeBlobFile(_tempFolder, blobData);

                _cabCompress.SwitchCompression(false);  // pocket´s withdout compression
                //_cabCompress.SetEncryptionKey("");
                _cabCompress.CompressFolder(_tempFolder, _tempFolder + cAPPFILESYSTEM_NAME, "", true, true, 0x7FFFFFFF);


                using (Stream st = File.Open(_tempFolder + cAPPFILESYSTEM_NAME, FileMode.Open, FileAccess.Read))
                {
                    using (BinaryReader br = new BinaryReader(st, Encoding.Default))
                    {
                        Base64TokenApplication = Convert.ToBase64String(br.ReadBytes(Convert.ToInt32(br.BaseStream.Length)));
                        appContentType         = cCONTENT_TYPE_NAME;
                    }
                }
                return(OperationResult.Success);
            }
            catch
            {
                Base64TokenApplication = null;
                return(OperationResult.Error);
            }
            finally
            {
                _cabExtract  = null;
                _cabCompress = null;

                if (Directory.Exists(_tempFolder))
                {
                    Directory.Delete(_tempFolder, true);
                }
            }
        }
        /// <summary>
        /// </summary>
        /// <param name="blobData"></param>
        /// <param name="appContentType"></param>
        /// <param name="Base64TokenApplication"></param>
        /// <returns></returns>
        public OperationResult AssembleTokenApplication(byte[] blobData, out string appContentType, out string Base64TokenApplication)
        {
            appContentType = null;
            Base64TokenApplication = null;

            string _tempFolder = null;
            Extract _cabExtract = new Extract();
            Compress _cabCompress = new Compress();

            try
            {
                _tempFolder = _getTempFolder();
                _cabExtract.ExtractFile(_getTemplateFile(), _tempFolder); 
                _writeBlobFile(_tempFolder, blobData);

                _cabCompress.SwitchCompression(false);  // pocket´s withdout compression
                //_cabCompress.SetEncryptionKey("");
                _cabCompress.CompressFolder(_tempFolder, _tempFolder + cAPPFILESYSTEM_NAME, "", true, true, 0x7FFFFFFF);


                using (Stream st = File.Open(_tempFolder + cAPPFILESYSTEM_NAME, FileMode.Open, FileAccess.Read))
                {
                    using (BinaryReader br = new BinaryReader(st, Encoding.Default))
                    {
                        Base64TokenApplication = Convert.ToBase64String(br.ReadBytes(Convert.ToInt32(br.BaseStream.Length)));
                        appContentType = cCONTENT_TYPE_NAME;
                    }
                }
                return OperationResult.Success;

            }
            catch
            {
                Base64TokenApplication = null;
                return OperationResult.Error;
            }
            finally
            {
                _cabExtract = null;
                _cabCompress = null;

                if (Directory.Exists(_tempFolder))
                    Directory.Delete(_tempFolder, true);
            }
        }