예제 #1
0
        public async Task UpdateApplicationStatus(IDbConnection conn, IDbTransaction tran, string apphash, LastApplicationStatus status)
        {
            var columnsToUpdate = new List <string>()
            {
                "ApplicationHash", "ApplicationPath", "Server", "LastUpdateTimeUtc"
            };

            if (status.ContainsPerformanceData())
            {
                columnsToUpdate.AddRange(new[] { "Cpu", "Memory", "LastPerformanceDataUpdateTimeUtc" });
            }
            if (status.ContainsErrorInformation())
            {
                columnsToUpdate.AddRange(new[] { "LastErrorTimeUtc", "LastErrorType" });
            }
            var model = new {
                ApplicationHash = apphash,
                status.ApplicationPath,
                status.Server,
                status.Cpu,
                status.Memory,
                status.LastUpdateTimeUtc,
                status.LastPerformanceDataUpdateTimeUtc,
                status.LastErrorType,
                status.LastErrorTimeUtc
            };
            await conn.ExecuteAsync(string.Format("replace into ApplicationStatus ({0}) values (@{1})", string.Join(",", columnsToUpdate),
                                                  string.Join(",@", columnsToUpdate)), model, tran);
        }
        private ElasticApplicationStatus UpdateOrCreateElasticApplicationStatus(ElasticApplicationStatus status, LastApplicationStatus appStatus)
        {
            if (status == null)
            {
                status = new ElasticApplicationStatus {
                    Id = GenerateElasticApplicationStatusId(appStatus),
                    ApplicationPath = appStatus.ApplicationPath,
                    Server          = appStatus.Server
                };
            }
            status.LastUpdateTimeUtc = appStatus.LastUpdateTimeUtc;

            if (appStatus.ContainsErrorInformation())
            {
                status.LastErrorTimeUtc = appStatus.LastErrorTimeUtc;
                status.LastErrorType    = appStatus.LastErrorType;
            }

            if (appStatus.ContainsPerformanceData())
            {
                status.Cpu    = appStatus.Cpu;
                status.Memory = appStatus.Memory;
                status.LastPerformanceDataUpdateTimeUtc = appStatus.LastPerformanceDataUpdateTimeUtc;
            }
            return(status);
        }
예제 #3
0
        public async Task UpdateApplicationStatus(IDbConnection conn, IDbTransaction tran, string apphash, LastApplicationStatus status)
        {
            var columnsToUpdate = new List <string>()
            {
                "LastUpdateTimeUtc", "ApplicationPath"
            };

            if (status.ContainsPerformanceData())
            {
                columnsToUpdate.AddRange(new[] { "Cpu", "Memory", "LastPerformanceDataUpdateTimeUtc" });
            }
            if (status.ContainsErrorInformation())
            {
                columnsToUpdate.AddRange(new[] { "LastErrorTimeUtc", "LastErrorType" });
            }
            var model = new {
                ApplicationHash = apphash,
                status.ApplicationPath,
                status.Server,
                status.Cpu,
                status.Memory,
                status.LastUpdateTimeUtc,
                status.LastPerformanceDataUpdateTimeUtc,
                status.LastErrorType,
                status.LastErrorTimeUtc
            };

            var buffer = new StringBuilder();

            foreach (var col in columnsToUpdate)
            {
                buffer.AppendFormat("{0}=@{0},", col);
            }
            buffer.Remove(buffer.Length - 1, 1); // last comma

            if (await conn.ExecuteAsync(string.Format("update ApplicationStatus set {0}", buffer.ToString()), model, transaction: tran) == 0)
            {
                columnsToUpdate.Add("ApplicationHash");
                columnsToUpdate.Add("Server");

                await conn.ExecuteAsync(string.Format("insert into ApplicationStatus ({0}) values (@{1})", string.Join(",", columnsToUpdate),
                                                      string.Join(",@", columnsToUpdate)), model, tran);
            }
        }