Esempio n. 1
0
        public FeatureVersion(VersionRow row)
        {
            if (row == null) throw new ArgumentNullException(nameof(row));

            this.Row = row;
            this.Name = row.Name;
        }
Esempio n. 2
0
        public void UpdateToLatestVersion()
        {
            var context = Mvx.Resolve <UpdateContext>();

            context.Connection = _connection;
            var version = GetCurrentVersion();
            var updates = GetPendingUpdates(version);

            foreach (var update in updates)
            {
                var meta = update.Item2;
                var code = update.Item1;
                Trace($"Applying updated #{meta.Version} [{meta.Tag}]...");
                using (_connection.Lock())
                {
                    _connection.RunInTransaction(() =>
                    {
                        code.Apply(context);
                        var row = new VersionRow {
                            Tag = meta.Tag, Timestamp = new DateTime(), Version = meta.Version
                        };
                        _connection.Insert(row);
                    });
                }
                Trace($"Update #{meta.Version} [{meta.Tag}] was successfully applied.");
            }
        }
Esempio n. 3
0
        public void GetCurrentVersion()
        {
            if (versionTask == null)
            {
                Version.LoadTable();
            }

            versionTask   = Version.Rows.FirstOrDefault(x => x.Task.CompareTo("Version") == 0);
            ClientVersion = versionTask?.Content;
        }
Esempio n. 4
0
        public async Task <IActionResult> DownloadLastest()
        {
            VersionRow appVersion = await storeService.GetLastVersion();

            if (appVersion != null)
            {
                return(Redirect($"{config.FileServiceUrl}/{GetVersionFileKey(appVersion.Version)}/{appVersion.Hash}"));
            }

            return(NoContent());
        }
Esempio n. 5
0
        public async Task <IActionResult> GetLastVersion()
        {
            VersionRow appVersion = await storeService.GetLastVersion();

            if (appVersion != null)
            {
                return(Ok(appVersion));
            }

            return(NoContent());
        }
Esempio n. 6
0
        public async Task <IActionResult> PutAsync([FromBody] IFormFile file, [FromHeader(Name = "X-PackageVersion")] string version, [FromHeader(Name = "X-ServerDigest")] string digest)
        {
            if (digest != config.ServerDigest)
            {
                return(Unauthorized());
            }

            if (string.IsNullOrEmpty(version))
            {
                return(BadRequest());
            }

            byte[] buffer = new byte[file.Length];

            Stream fileStream = file.OpenReadStream();

            await fileStream.ReadAsync(buffer, 0, buffer.Length);

            using (var client = new HttpClient())
            {
                HttpResponseMessage response =
                    await client.PostAsync(config.FileServiceUrl,
                                           new MultipartFormDataContent
                {
                    { new ByteArrayContent(buffer), "data", file.FileName },
                    { new StringContent(GetVersionFileKey(version)), "key" }
                });

                if (response.IsSuccessStatusCode)
                {
                    string hash = await response.Content.ReadAsStringAsync();

                    VersionRow appVersion = await storeService.AddVersionAsync("spm", version, hash);

                    return(Ok(appVersion));
                }
                else
                {
                    return(BadRequest(await response.Content.ReadAsStringAsync()));
                }
            }
        }
Esempio n. 7
0
 public void ReloadAll()
 {
     if (versionTask != null)
     {
         versionTask.Content = ServerVersion;
         Version.SQLUpdate(Version.Rows.IndexOf(versionTask));
     }
     else
     {
         versionTask = new VersionRow()
         {
             Id      = 1,
             Task    = "Version",
             Content = ServerVersion,
             Comment = "None"
         };
         Version.SQLInsert(versionTask);
     }
     LoadTables();
 }
Esempio n. 8
0
        private bool IsUpdateVersion(ref VersionRow versionTask)
        {
            bool result = ClientVersion == null ? true : ClientVersion.CompareTo(ServerVersion) != 0;

            return(result);
        }
Esempio n. 9
0
        private static Dictionary<long, VersionRow> GetVersions(IDbContext context, List<ExceptionEntryRow> entries)
        {
            var values = new Dictionary<long, VersionRow>(entries.Count);

            var batchSize = 16;
            var sqlParams = CreateBatchParams(batchSize);

            var query = new Query(@"SELECT ID, NAME FROM FEATURE_VERSIONS WHERE ID IN (@p0,@p1,@p2,@p3,@p4,@p5,@p6,@p7,@p8,@p9,@p10,@p11,@p12,@p13,@p14,@p15)", sqlParams);

            var index = 0;
            foreach (var id in entries.Select(r => r.VersionId).Distinct())
            {
                if (index < batchSize)
                {
                    sqlParams[index++].Value = id;
                    continue;
                }

                context.Fill(values, (r, map) =>
                {
                    var row = new VersionRow(r.GetInt64(0), r.GetString(1));
                    map.Add(row.Id, row);
                }, query);

                sqlParams[0].Value = id;
                index = 1;
            }
            if (index > 0)
            {
                for (var i = index; i < sqlParams.Length; i++)
                {
                    sqlParams[i].Value = -1;
                }
                context.Fill(values, (r, map) =>
                {
                    var row = new VersionRow(r.GetInt64(0), r.GetString(1));
                    map.Add(row.Id, row);
                }, query);
            }

            return values;
        }