Exemple #1
0
        public DmeVersion UpdateVersion(VersionDTO dto)
        {
            DmeVersion currentVersion = this.GetCurrentVersion();

            if (null == currentVersion)
            {
                currentVersion = new DmeVersion()
                {
                    MajorVersion    = dto.MajorVersion,
                    MinorVersion    = dto.MinorVersion,
                    RevisionVersion = dto.RevisionVersion,
                    UpgradeTime     = DateUtil.CurrentTimeMillis
                };
                currentVersion = base.Db.Insertable <DmeVersion>(currentVersion).ExecuteReturnEntity();
            }
            else
            {
                currentVersion.MajorVersion    = dto.MajorVersion;
                currentVersion.MinorVersion    = dto.MinorVersion;
                currentVersion.RevisionVersion = dto.RevisionVersion;
                currentVersion.UpgradeTime     = DateUtil.CurrentTimeMillis;
                base.Db.Updateable <DmeVersion>(currentVersion).ExecuteCommand();
            }
            return(currentVersion);
        }
Exemple #2
0
        public VersionDTO MapToVersionDTO(Revision source, VersionDTO target)
        {
            if (source == null)
            {
                return(null);
            }

            MapToVersionInfoDTO(source, target);
            target.CreatedByUserId      = target.CreatedByUserId;
            target.LastModifiedByUserId = target.LastModifiedByUserId;
            return(target);
        }
Exemple #3
0
        public VersionDTO GetAllVersionInfo()
        {
            var versionDto = new VersionDTO();
            var dbversions = _uow.CdVersionRepository.GetById(1);

            versionDto.FirstRunCompleted = Convert.ToBoolean(_uow.CdVersionRepository.GetById(1).FirstRunCompleted);
            versionDto.DatabaseVersion   = dbversions.DatabaseVersion;
            var versionMapping = new VersionMapping().Get();

            versionDto.TargetDbVersion = versionMapping[SettingStrings.Version].ToString();
            return(versionDto);
        }
Exemple #4
0
 public ActionResult Post([FromBody] VersionDTO value)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     if (value == null)
     {
         return(BadRequest());
     }
     repoWrapper.Version.Insert(mapper.Map <Models.Version>(value));
     repoWrapper.Save();
     return(Ok());
 }
Exemple #5
0
        [Route("ConsultarVersionSICOF")] //Averiguar parametro
        public ActionResult ConsultarVersionSICOF()
        {
            try
            {
                //Ini Log
                _logger.LogInformation("Se inicia el metodo ConsultarVersionSICOF");

                VersionDTO ultimaVerion = _gestionVersionBusiness.ConsultarVersionSICOF();

                _logger.LogInformation("Se Finaliza el metodo ConsultarVersionSICOF");
                return(Ok(ultimaVerion));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
                return(BadRequest());
            }
        }
        private async Task <SpkResult> GetRepositoryPackagesInternal(
            PredefinedSources predefinedSources,
            string packageUpdateChannel,
            string arch,
            string unique,
            VersionDTO versionDto,
            IList <string> manualSources
            )
        {
            bool           isBeta  = string.Equals("beta", packageUpdateChannel, StringComparison.InvariantCultureIgnoreCase);
            IList <string> sources = GetSources(predefinedSources, manualSources, versionDto.Major);

            IList <Task <RawSpkResultDto> > downloadTasks = new List <Task <RawSpkResultDto> >();
            SpkResult spkResult = new SpkResult();

            foreach (var sourceName in sources)
            {
                var sourceDto = sourceService.GetSource(sourceName);
                var task      = this.spkService.GetRawPackages(sourceName,
                                                               sourceDto.Url,
                                                               arch,
                                                               unique,
                                                               versionDto,
                                                               isBeta,
                                                               sourceDto.CustomUserAgent,
                                                               false,
                                                               null,
                                                               sourceDto.UseGetMethod);
                downloadTasks.Add(task);
            }
            await Task.WhenAll(downloadTasks.ToArray()).ConfigureAwait(false);

            foreach (var task in downloadTasks)
            {
                var result = await task.ConfigureAwait(false);

                if (result.Success && result.SpkResult?.Packages != null)
                {
                    spkResult.Packages.AddRange(result.SpkResult.Packages);
                }
            }
            return(spkResult);
        }
Exemple #7
0
        public ActionResult Put(Guid id, [FromBody] VersionDTO value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (id != value.Id)
            {
                return(BadRequest("Doesnt exist."));
            }
            var version = repoWrapper.Version.GetById(id);

            if (version == null)
            {
                return(BadRequest());
            }
            mapper.Map <VersionDTO, Models.Version>(value, version);
            repoWrapper.Save();
            return(Ok());
        }
Exemple #8
0
 public Result UpdateVersion([FromBody] VersionDTO dto)
 {
     return(base.Success(base.versionService.UpdateVersion(dto)));
 }
        public async Task <SourceServerResponseDTO> GetPackages(
            string sourceName,
            string url,
            string arch,
            string model,
            VersionDTO versionDto,
            bool isBeta,
            string customUserAgent,
            bool isSearch,
            string keyword    = null,
            bool useGetMethod = false)
        {
            Stopwatch stopwatch = new Stopwatch();

            string            errorMessage;
            ResultFrom        resultFrom;
            double?           cacheOld   = null;
            ParametersDTO     parameters = new ParametersDTO(sourceName, model, versionDto, isBeta, keyword);
            SearchLogEntryDTO logEntry   = new SearchLogEntryDTO(parameters);

            logEntry.RequestType = isSearch ? RequestType.Search : RequestType.Browse;
            logEntry.LogType     = LogType.Parameters;
            logger.LogInformation(Utils.GetSearchLogEntryString(logEntry));
            logEntry.LogType = LogType.Result;
            stopwatch.Start();
            var cacheResult = await cacheService.GetSpkResponseFromCache(sourceName, arch, model, versionDto.Build.ToString(), isBeta);

            SpkResult result;

            if (!cacheResult.HasValidCache)
            {
                string unique            = $"synology_{arch}_{model}"; //TODO: DSM provide model without leading "DS" or "RS", so we should do the same some day.
                var    parametersRequest = PrepareParametersForRequest(arch, unique, versionDto, isBeta, customUserAgent, out var userAgent);

                IDownloadService downloadService = downloadFactory.GetDefaultDownloadService();
                var response = await downloadService.Execute(url, parametersRequest, userAgent, useGetMethod);

                if (response.Success)
                {
                    try
                    {
                        result     = ParseResponse(sourceName, url, arch, model, versionDto, isBeta, response.Content);
                        resultFrom = ResultFrom.Server;
                    }
                    catch (Exception ex)
                    {
                        logger.LogError(ex, $"Unable to parse response from {url}: {response.Content}");
                        if (cacheResult.Cache != null)
                        {
                            logger.LogInformation("Returning data from cache");
                            result     = cacheResult.Cache.SpkResult;
                            resultFrom = ResultFrom.Cache;
                            cacheOld   = cacheResult.Cache.CacheOld;
                        }
                        else
                        {
                            logger.LogError($"Error getting response for url: {url}. No cache available.");
                            return(new SourceServerResponseDTO(false, "No data from source server. No cache available", parameters, null, ResultFrom.NotSpecified, null));
                        }
                    }
                }
                else if (cacheResult.Cache != null)
                {
                    logger.LogError($"Error getting response for url: {url}: {response.ErrorMessage}");
                    result     = cacheResult.Cache.SpkResult;
                    resultFrom = ResultFrom.ExpiredCache;
                    cacheOld   = cacheResult.Cache.CacheOld;
                }
                else //no cache && no server response
                {
                    errorMessage = $"{response.ErrorMessage}";
                    logger.LogError($"Error getting response for url: {url}: {errorMessage}");
                    return(new SourceServerResponseDTO(false, errorMessage, parameters, null, ResultFrom.NotSpecified, null));
                }
            }
            else // get data from Valid cache
            {
                result     = cacheResult.Cache.SpkResult;
                resultFrom = ResultFrom.Cache;
                cacheOld   = cacheResult.Cache.CacheOld;
            }

            if (result != null)
            {
                var finalResult = await GenerateResult(sourceName, keyword, parameters, result, resultFrom, cacheOld);

                stopwatch.Stop();
                logEntry.ResultFrom    = resultFrom;
                logEntry.CacheOld      = cacheOld;
                logEntry.ExecutionTime = stopwatch.ElapsedMilliseconds;
                logger.LogInformation(Utils.GetSearchLogEntryString(logEntry));
                return(finalResult);
            }
            else
            {
                errorMessage = "Spk result is empty";
                stopwatch.Stop();
                logEntry.ResultFrom    = ResultFrom.NotSpecified;
                logEntry.CacheOld      = null;
                logEntry.ExecutionTime = stopwatch.ElapsedMilliseconds;
                logger.LogWarning("Spk result is empty {0}", Utils.GetSearchLogEntryString(logEntry));
                return(new SourceServerResponseDTO(false, errorMessage, parameters, null, resultFrom, cacheOld));
            }
        }
Exemple #10
0
        private static IEnumerable <KeyValuePair <string, object> > PrepareParametersForRequest(string arch, string unique, VersionDTO versionDto, bool isBeta, string customUserAgent, out string userAgent)
        {
            List <KeyValuePair <string, object> > list = new List <KeyValuePair <string, object> >();

            list.Add(new KeyValuePair <string, object>("language", "enu"));
            list.Add(new KeyValuePair <string, object>("unique", unique));
            list.Add(new KeyValuePair <string, object>("arch", arch));
            list.Add(new KeyValuePair <string, object>("major", versionDto.Major.ToString()));
            list.Add(new KeyValuePair <string, object>("minor", versionDto.Minor.ToString()));
            list.Add(new KeyValuePair <string, object>("build", versionDto.Build.ToString()));
            list.Add(new KeyValuePair <string, object>("package_update_channel", isBeta ? "beta" : "stable"));
            list.Add(new KeyValuePair <string, object>("timezone", "Brussels"));


            userAgent = customUserAgent ?? unique;
            return(list);
        }
Exemple #11
0
        private SpkResult ParseResponse(string sourceName, string url, string arch, string modelOrUnique, VersionDTO versionDto, bool isBeta, string responseContent)
        {
            SpkResult result;

            if (responseContent != null)
            {
                if (responseContent.Contains("\"packages\""))
                {
                    result = JsonConvert.DeserializeObject <SpkResult>(responseContent, new CustomBooleanJsonConverter());
                }
                else
                {
                    result          = new SpkResult();
                    result.Packages = JsonConvert.DeserializeObject <List <SpkPackage> >(responseContent, new CustomBooleanJsonConverter());
                }
                if (result != null)
                {
                    cacheService.SaveSpkResult(sourceName, arch, modelOrUnique, versionDto.Build.ToString(), isBeta, result);
                }
            }
            else
            {
                logger.LogWarning($"No data for url: {url}");
                result = new SpkResult();
            }

            return(result);
        }
Exemple #12
0
        public async Task <RawSpkResultDto> GetRawPackages(
            string sourceName,
            string url,
            string arch,
            string unique,
            VersionDTO versionDto,
            bool isBeta,
            string customUserAgent,
            bool isSearch,
            string keyword    = null,
            bool useGetMethod = false
            )
        {
            RawSpkResultDto   result;
            ParametersDTO     parameters = new ParametersDTO(sourceName, unique, versionDto, isBeta, keyword);
            SearchLogEntryDTO logEntry   = new SearchLogEntryDTO(parameters);

            logEntry.RequestType = isSearch ? RequestType.Search : RequestType.Browse;
            logEntry.LogType     = LogType.Parameters;
            logger.LogInformation(Utils.GetSearchLogEntryString(logEntry));
            logEntry.LogType = LogType.Result;
            var stopwatch   = Stopwatch.StartNew();
            var cacheResult = await cacheService.GetSpkResponseForRepositoryFromCache(sourceName, arch, versionDto.Build.ToString(), isBeta);

            if (!cacheResult.HasValidCache)
            {
                var parametersRequest = PrepareParametersForRequest(arch, unique, versionDto, isBeta, customUserAgent, out var userAgent);

                IDownloadService downloadService = downloadFactory.GetDefaultDownloadService();
                var response = await downloadService.Execute(url, parametersRequest, userAgent, useGetMethod);

                if (response.Success)
                {
                    logEntry.ResultFrom = ResultFrom.Server;
                    try
                    {
                        var rawResponse = ParseResponse(sourceName, url, arch, unique, versionDto, isBeta, response.Content);
                        result = new RawSpkResultDto(rawResponse, null);
                    }
                    catch (Exception ex)
                    {
                        logger.LogError(ex, $"Could not parse response from server {url}");
                        result = new RawSpkResultDto(null, ex.Message);
                    }
                }
                else
                {
                    logger.LogError($"Could not get any data from the server {url}");
                    result = new RawSpkResultDto(null, $"Could not get any data from the server {url}");
                }
            }
            else //return response from valid cache
            {
                result              = new RawSpkResultDto(cacheResult.Cache?.SpkResult, null);
                logEntry.CacheOld   = cacheResult.Cache.CacheOld;
                logEntry.LogType    = LogType.Result;
                logEntry.ResultFrom = ResultFrom.Cache;
            }

            stopwatch.Stop();
            logEntry.ExecutionTime = stopwatch.ElapsedMilliseconds;
            logger.LogInformation(Utils.GetSearchLogEntryString(logEntry));
            return(result);
        }