OpenConnection() public method

public OpenConnection ( ) : IDbConnection
return IDbConnection
        public void SaveEndpoint(Endpoint endpoint)
        {
            using (var conn = _db.OpenConnection())
                using (var tx = conn.BeginTransaction())
                {
                    var tags = endpoint.Metadata.Tags.ToDbString();

                    conn.Execute(
                        $"replace into EndpointConfig(MonitorType, Address, GroupName, Name, Id, Password, RegisteredOnUtc, RegistrationUpdatedOnUtc, MonitorTag{(tags != null ? ", Tags" : "")}) values(@MonitorType,@Address,@Group,@Name,@Id,@Password,@RegisteredOnUtc,@RegistrationUpdatedOnUtc,@MonitorTag{(tags != null ? ",@Tags" : "")})",
                        new
                    {
                        endpoint.Identity.MonitorType,
                        endpoint.Identity.Address,
                        endpoint.Metadata.Group,
                        endpoint.Metadata.Name,
                        endpoint.Identity.Id,
                        endpoint.Password,
                        endpoint.Metadata.RegisteredOnUtc,
                        endpoint.Metadata.RegistrationUpdatedOnUtc,
                        endpoint.Metadata.MonitorTag,
                        tags
                    }, tx);

                    tx.Commit();
                }
        }
 public void SaveMonitorType(string monitorType)
 {
     using (var conn = _db.OpenConnection())
         using (var tx = conn.BeginTransaction())
         {
             conn.Execute("replace into HealthMonitorTypes(MonitorType) values(@monitorType)", new { monitorType });
             tx.Commit();
         }
 }
Exemplo n.º 3
0
 public void InsertEndpointStatistics(Guid endpointId, EndpointHealth stats)
 {
     using (var conn = _db.OpenConnection())
         using (var tx = conn.BeginTransaction())
         {
             var id = Guid.NewGuid();
             conn.Execute(
                 "insert into EndpointStats (Id, EndpointId, CheckTimeUtc, ResponseTime, Status) values (@id, @endpointId, @checkTimeUtc, @responseTime, @status)",
                 new { id, endpointId, stats.CheckTimeUtc, responseTime = stats.ResponseTime.Ticks, stats.Status }, tx);
             tx.Commit();
         }
 }
Exemplo n.º 4
0
        public void SaveEndpoint(Endpoint endpoint)
        {
            using (var conn = _db.OpenConnection())
                using (var tx = conn.BeginTransaction())
                {
                    var tags = endpoint.Metadata.Tags.ToDbString();

                    if (conn.Execute($"update EndpointConfig set MonitorType=@MonitorType, Address=@Address, GroupName=@Group, Name=@Name{(tags != null ? ", Tags=@tags" : "")} where Id=@Id",
                                     new { endpoint.Identity.MonitorType, endpoint.Identity.Address, endpoint.Metadata.Group, endpoint.Metadata.Name, tags, endpoint.Identity.Id }, tx) == 0)
                    {
                        conn.Execute("insert into EndpointConfig (MonitorType, Address, GroupName, Name, Id, Tags) values(@MonitorType,@Address,@Group,@Name,@Id,@Tags)",
                                     new { endpoint.Identity.MonitorType, endpoint.Identity.Address, endpoint.Metadata.Group, endpoint.Metadata.Name, endpoint.Identity.Id, tags }, tx);
                    }

                    tx.Commit();
                }
        }