public static async Task <bool> CreateEmployee(Employee employee)
        {
            string sql = "INSERT INTO Employee " +
                         "(Name, Email, Salary, Gender, ContractType, RegisterDate) " +
                         "VALUES (@Name, @Email, @Salary, @Gender, @ContractType, @RegisterDate";

            SqlCeCommand command = new SqlCeCommand(sql, con);

            command.Parameters.Add("@Name", employee.Name);
            command.Parameters.Add("@Email", employee.Email);
            command.Parameters.Add("@Salary", employee.Salary);
            command.Parameters.Add("@Gender", employee.Gender);
            command.Parameters.Add("@ContractType", employee.ContractType);
            command.Parameters.Add("@RegisterDate", employee.RegisterDate);

            await con.OpenAsync();

            if (await command.ExecuteNonQueryAsync() > 0)
            {
                con.Close();
                return(true);
            }
            else
            {
                con.Close();
                return(false);
            }
        }
Beispiel #2
0
        public async Task <HttpResponseMessage> Post(JObject value)
        {
            dynamic           data = value;
            IEnumerable <int> result;

            using (var connection = new SqlCeConnection(_connString))
            {
                await connection.OpenAsync();

                connection.Execute(
                    "insert into Tasks (Title, Description, CreatedDate) values (@title, @description, @createdDate);",
                    new
                {
                    title       = (string)data.title,
                    description = (string)data.description,
                    createdDate = DateTime.Parse((string)data.createdDate)
                }
                    );

                result = await connection.QueryAsync <int>("select max(Id) as id from Tasks;");
            }

            int id = result.First();

            data.id = id;
            var response = Request.CreateResponse(HttpStatusCode.Created, (JObject)data);

            response.Headers.Location = new Uri(Url.Link("DefaultApi", new { controller = "Tasks", id = id }));
            return(response);
        }
        /// <summary>
        /// Получить новое подключение к базе данных.
        /// </summary>
        /// <returns>
        /// Новое открытое подключение к базе данных.
        /// Необходимо использователь в выражениях using, либо явно делать Close().
        /// </returns>
        public async Task <IDbConnection> GetConnectionAsync()
        {
            var connection = new SqlCeConnection(this.ConnectionString);
            await connection.OpenAsync();

            return(connection);
        }
Beispiel #4
0
        public async Task DeleteAsync(int id)
        {
            // If error is not exist in list then exit
            if (!ErrorIds.ContainsKey(id))
            {
                return;
            }

            using (var sqlConn = new SqlCeConnection(ConnectionString))
                using (var cmd = sqlConn.CreateCommand())
                {
                    try
                    {
                        cmd.CommandText = string.Format("Delete From ErrorLog Where ErrorId = {0}", id);

                        await sqlConn.OpenAsync();

                        await cmd.ExecuteNonQueryAsync();

                        ErrorIds.Remove(id);
                    }
                    finally
                    {
                        sqlConn.Close();
                    }
                }
        }
        /// <summary>
        /// Gets the member id of the associated name
        /// </summary>
        private async Task <int> GetMemberID(string memberName)
        {
            int memberID = 0;

            using (SqlCeConnection connection = new SqlCeConnection(connectionFilePath))
            {
                await connection.OpenAsync();

                // TODO: Establish unique item

                string query = "SELECT ID FROM Members WHERE NAME='" + memberName + "'";

                SqlCeCommand command = new SqlCeCommand();
                command.Connection  = connection;
                command.CommandText = query;

                DbDataReader reader = await command.ExecuteReaderAsync();

                try
                {
                    while (reader.Read())
                    {
                        memberID = reader.GetInt32(0);
                    }
                }
                finally
                {
                    reader.Close();
                }

                connection.Close();
            }

            return(memberID);
        }
        public static async Task CreateSdfAsync(string filePath)
        {
            SetConnectionString(filePath);

            if (File.Exists(filePath))
            {
                CheckSdf(filePath);
                return;
            }

            new SqlCeEngine(ConnectionString).CreateDatabase();

            const string createErrorLogTable = @"CREATE TABLE [ErrorLog](
	                                [ErrorId] [int] NOT NULL CONSTRAINT PK_ErrorLog PRIMARY KEY,
	                                [ServerDateTime] [datetime] NULL,
	                                [Host] [nvarchar](200) NULL,
	                                [User] [nvarchar](200) NULL,
	                                [IsHandled] [bit] NOT NULL,
	                                [Type] [nvarchar](200) NULL,
	                                [AppName] [nvarchar](200) NULL,
	                                [CurrentCulture] [nvarchar](200) NULL,
	                                [CLRVersion] [nvarchar](100) NULL,
	                                [Message] [nvarchar](2000) NULL,
	                                [Source] [nvarchar](200) NULL,
	                                [StackTrace] [ntext] NULL,
	                                [ModuleName] [nvarchar](200) NULL,
	                                [MemberType] [nvarchar](200) NULL,
	                                [Method] [nvarchar](500) NULL,
	                                [Processes] [ntext] NULL,
	                                [ErrorDateTime] [datetime] NULL,
	                                [OS] [nvarchar](1000) NULL,
	                                [IPv4Address] [nvarchar](50) NULL,
	                                [MACAddress] [nvarchar](50) NULL,
	                                [HResult] [int] NULL,
	                                [Line] [int] NULL,
                                    [Column] [int] NULL,
                                    [ScreenCapture] [image] NULL,
	                                [DuplicateNo] [int] NULL, 
                                    [Data] [ntext] NULL) ";


            using (var sqlCon = new SqlCeConnection(ConnectionString))
                using (var cmd = sqlCon.CreateCommand())
                {
                    try
                    {
                        cmd.CommandText = createErrorLogTable;

                        await sqlCon.OpenAsync();

                        await cmd.ExecuteNonQueryAsync();
                    }
                    finally
                    {
                        sqlCon.Close();
                    }
                }
        }
        public async Task<IEnumerable<dynamic>> GetAll()
        {
            using (var connection = new SqlCeConnection(_connString))
            {
                await connection.OpenAsync();

                IEnumerable<dynamic> tasks = await connection.QueryAsync<dynamic>("select Id as id, Title as title, Description as description, CreatedDate as createdDate from Tasks;");
                return tasks;
            }
        }
Beispiel #8
0
        public async Task <IEnumerable <dynamic> > GetAll()
        {
            using (var connection = new SqlCeConnection(_connString))
            {
                await connection.OpenAsync();

                IEnumerable <dynamic> tasks = await connection.QueryAsync <dynamic>("select Id as id, Title as title, Description as description, CreatedDate as createdDate from Tasks;");

                return(tasks);
            }
        }
Beispiel #9
0
        public void Execute(string output)
        {
            using (var connection = new SqlCeConnection(connString))
            {
                connection.OpenAsync().Wait();
                var command = connection.CreateCommand();
                command.CommandText = output;
                command.CommandType = System.Data.CommandType.Text;

                command.ExecuteNonQueryAsync().Wait();

                connection.Close();
            }
        }
Beispiel #10
0
        public async Task <dynamic> Get(int id)
        {
            using (var connection = new SqlCeConnection(_connString))
            {
                await connection.OpenAsync();

                IEnumerable <dynamic> tasks = await connection.QueryAsync <dynamic>("select Id as id, Title as title, Description as description, CreatedDate as createdDate from Tasks where Id = @id;", new { id = id });

                if (!tasks.Any())
                {
                    throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Task not found"));
                }

                return(tasks.First());
            }
        }
        /// <summary>
        /// Creates a ticket
        /// </summary>
        public async Task <int> CreateTicketAsync(int section, int row, int seat)
        {
            int newTicketID = MINIMUM_ID - 1; // Default settings for PK are (1,1).  ID's < 1 are invalid

            using (SqlCeConnection connection = new SqlCeConnection(connectionFilePath))
            {
                await connection.OpenAsync();

                // TODO: Establish unique item

                string query = "INSERT INTO Tickets(T_SECTION,T_ROW,T_SEAT) VALUES("
                               + section + ", "
                               + row + ", "
                               + seat + ")";

                SqlCeCommand command = new SqlCeCommand();
                command.Connection  = connection;
                command.CommandText = query;

                if ((await command.ExecuteNonQueryAsync()) < MINIMUM_ID)
                {
                    // Potential to use ID's < 1 as ERROR Codes
                    newTicketID = -1;
                }
                else
                {
                    // Get the last created record's PK scoped to the current connection for thread safety
                    query               = "SELECT @@IDENTITY";
                    command             = new SqlCeCommand();
                    command.Connection  = connection;
                    command.CommandText = query;

                    newTicketID = Convert.ToInt32((decimal)command.ExecuteScalar());
                }

                connection.Close();
            }

            if ((await AddTicketMappingAsync(newTicketID, MINIMUM_ID, TicketStatus.FREE)) < MINIMUM_ID)
            {
                // Something Illegal happened
                return(newTicketID);
            }

            return(newTicketID);
        }
Beispiel #12
0
        public async Task <ProxyError> GetErrorAsync(int id)
        {
            using (var sqlConn = new SqlCeConnection(ConnectionString))
                using (var cmd = sqlConn.CreateCommand())
                {
                    try
                    {
                        cmd.CommandText = string.Format("Select * From ErrorLog Where ErrorId = {0}", id);

                        await sqlConn.OpenAsync();

                        return(await cmd.ExecuteScalarAsync() as ProxyError);
                    }
                    finally
                    {
                        sqlConn.Close();
                    }
                }
        }
Beispiel #13
0
        public async Task <int> GetTheFirstErrorHoursAsync()
        {
            using (var sqlConn = new SqlCeConnection(ConnectionString))
                using (var cmd = sqlConn.CreateCommand())
                {
                    try
                    {
                        cmd.CommandText = string.Format("SELECT ABS(DATEDIFF(HH, Min([ErrorDateTime]), GETDATE())) FROM ErrorLog");

                        await sqlConn.OpenAsync();

                        return(await cmd.ExecuteScalarAsync() as int? ?? 0);
                    }
                    finally
                    {
                        sqlConn.Close();
                    }
                }
        }
Beispiel #14
0
        public async Task <int> CountAsync()
        {
            using (var sqlConn = new SqlCeConnection(ConnectionString))
                using (var cmd = sqlConn.CreateCommand())
                {
                    try
                    {
                        cmd.CommandText = string.Format("Select Count(ErrorId) From ErrorLog");

                        await sqlConn.OpenAsync();

                        return(await cmd.ExecuteScalarAsync() as int? ?? 0);
                    }
                    finally
                    {
                        sqlConn.Close();
                    }
                }
        }
            private async static Task AddHistoricMessage(MsSqlMessageStore sSqlMessageStore, Message message)
            {
                var sql = string.Format("INSERT INTO {0} (MessageId, MessageType, Topic, Body) VALUES (@MessageId, @MessageType, @Topic, @Body)", TableName);
                var parameters = new[]
                {
                    new SqlCeParameter("MessageId", message.Id),
                    new SqlCeParameter("MessageType", message.Header.MessageType.ToString()),
                    new SqlCeParameter("Topic", message.Header.Topic),
                    new SqlCeParameter("Body", message.Body.Value),
                };

                using (var connection = new SqlCeConnection(ConnectionString))
                using (var command = connection.CreateCommand())
                {
                    await connection.OpenAsync();

                    command.CommandText = sql;
                    command.Parameters.AddRange(parameters);
                    await command.ExecuteNonQueryAsync();
                }
            }
            private async static Task AddHistoricMessage(MsSqlMessageStore sSqlMessageStore, Message message)
            {
                var sql        = string.Format("INSERT INTO {0} (MessageId, MessageType, Topic, Body) VALUES (@MessageId, @MessageType, @Topic, @Body)", TableName);
                var parameters = new[]
                {
                    new SqlCeParameter("MessageId", message.Id),
                    new SqlCeParameter("MessageType", message.Header.MessageType.ToString()),
                    new SqlCeParameter("Topic", message.Header.Topic),
                    new SqlCeParameter("Body", message.Body.Value),
                };

                using (var connection = new SqlCeConnection(ConnectionString))
                    using (var command = connection.CreateCommand())
                    {
                        await connection.OpenAsync();

                        command.CommandText = sql;
                        command.Parameters.AddRange(parameters);
                        await command.ExecuteNonQueryAsync();
                    }
            }
Beispiel #17
0
        public async Task UpdateAsync(Error error)
        {
            // If error is not exist in list or error state is now at unhandled exception state then exit
            if (!ErrorIds.ContainsKey(error.Id) || !ErrorIds[error.Id])
            {
                return;
            }

            using (var sqlConn = new SqlCeConnection(ConnectionString))
                using (var cmd = sqlConn.CreateCommand())
                {
                    cmd.CommandText =
                        string.Format("UPDATE [ErrorLog] SET [DuplicateNo] = [DuplicateNo] + 1 {0} WHERE ErrorId = @id",
                                      error.IsHandled ? "" : ", [IsHandled] = @isHandled, [StackTrace] = @stackTrace");

                    //
                    // Add parameters to command, which will be passed to the stored procedure
                    cmd.Parameters.AddWithValue("@id", error.Id);
                    if (!error.IsHandled) // Just in Unhandled Exceptions
                    {
                        cmd.Parameters.AddWithValue("@isHandled", error.IsHandled);
                        cmd.Parameters.AddWithValue("@stackTrace", SubLimitString(error.StackTrace));
                    }

                    try
                    {
                        await sqlConn.OpenAsync();

                        await cmd.ExecuteNonQueryAsync();

                        ErrorIds[error.Id] = error.IsHandled;
                    }
                    finally
                    {
                        sqlConn.Close();
                    }
                }
        }
        /// <summary>
        /// Deletes a ticket/member mapping from the appropriate table
        /// </summary>
        private async Task <bool> DeleteTicketMappingAsync(int ticketID, int memberID, TicketStatus ticketStatus)
        {
            bool success = false;

            using (SqlCeConnection connection = new SqlCeConnection(connectionFilePath))
            {
                await connection.OpenAsync();

                string query = BuildDeleteTicketTableQuery(ticketID, memberID, ticketStatus);

                SqlCeCommand command = new SqlCeCommand();
                command.Connection  = connection;
                command.CommandText = query;
                if ((await command.ExecuteNonQueryAsync()) >= MINIMUM_ID)
                {
                    success = true;
                }

                connection.Close();
            }

            return(success);
        }
        /// <summary>
        /// Creates a member
        /// </summary>
        public async Task <int> CreateMemberAsync(string memberName)
        {
            int newMemberID = MINIMUM_ID - 1; // Default settings for PK are (1,1).  ID's < 1 are invalid

            using (SqlCeConnection connection = new SqlCeConnection(connectionFilePath))
            {
                await connection.OpenAsync();

                // TODO: Establish unique item

                string query = "INSERT INTO Members(NAME) VALUES('" + memberName + "')";

                SqlCeCommand command = new SqlCeCommand();
                command.Connection  = connection;
                command.CommandText = query;

                if ((await command.ExecuteNonQueryAsync()) < MINIMUM_ID)
                {
                    // Potential to use ID's < 1 as ERROR Codes
                    newMemberID = -1;
                }
                else
                {
                    // Get the last created record's PK scoped to the current connection for thread safety
                    query               = "SELECT @@IDENTITY";
                    command             = new SqlCeCommand();
                    command.Connection  = connection;
                    command.CommandText = query;

                    newMemberID = Convert.ToInt32((decimal)command.ExecuteScalar());
                }

                connection.Close();
            }

            return(newMemberID);
        }
        /// <summary>
        /// Gets the ticket id of the associated seat parameters
        /// </summary>
        private async Task <int> GetTicketID(int section, int row, int seat)
        {
            int ticketID = 0;

            using (SqlCeConnection connection = new SqlCeConnection(connectionFilePath))
            {
                await connection.OpenAsync();

                // TODO: Establish unique item

                string query = "SELECT ID FROM Tickets WHERE T_SECTION=" + section
                               + " AND T_ROW=" + row
                               + " AND T_SEAT=" + seat;

                SqlCeCommand command = new SqlCeCommand();
                command.Connection  = connection;
                command.CommandText = query;

                DbDataReader reader = await command.ExecuteReaderAsync();

                try
                {
                    while (reader.Read())
                    {
                        ticketID = reader.GetInt32(0);
                    }
                }
                finally
                {
                    reader.Close();
                }

                connection.Close();
            }

            return(ticketID);
        }
        /// <summary>
        /// Adds a ticket/member mapping to the appropriate table
        /// </summary>
        private async Task <int> AddTicketMappingAsync(int ticketID, int memberID, TicketStatus ticketStatus)
        {
            int newTicketMappingID = 0;

            using (SqlCeConnection connection = new SqlCeConnection(connectionFilePath))
            {
                await connection.OpenAsync();

                // TODO: Establish unique item

                string query = BuildInsertTicketTableQuery(ticketID, memberID, ticketStatus);

                SqlCeCommand command = new SqlCeCommand();
                command.Connection  = connection;
                command.CommandText = query;

                if ((await command.ExecuteNonQueryAsync()) < MINIMUM_ID)
                {
                    // Potential to use ID's < 1 as ERROR Codes
                    newTicketMappingID = -1;
                }
                else
                {
                    // Get the last created record's PK scoped to the current connection for thread safety
                    query               = "SELECT @@IDENTITY";
                    command             = new SqlCeCommand();
                    command.Connection  = connection;
                    command.CommandText = query;

                    newTicketMappingID = Convert.ToInt32((decimal)command.ExecuteScalar());
                }

                connection.Close();
            }

            return(newTicketMappingID);
        }
        public async Task<int> GetTheFirstErrorHoursAsync()
        {
            using (var sqlConn = new SqlCeConnection(ConnectionString))
            using (var cmd = sqlConn.CreateCommand())
            {
                try
                {
                    cmd.CommandText = string.Format("SELECT ABS(DATEDIFF(HH, Min([ErrorDateTime]), GETDATE())) FROM ErrorLog");

                    await sqlConn.OpenAsync();

                    return await cmd.ExecuteScalarAsync() as int? ?? 0;
                }
                finally
                {
                    sqlConn.Close();
                }
            }
        }
        public async Task<dynamic> Get(int id)
        {
            using (var connection = new SqlCeConnection(_connString))
            {
                await connection.OpenAsync();

                IEnumerable<dynamic> tasks = await connection.QueryAsync<dynamic>("select Id as id, Title as title, Description as description, CreatedDate as createdDate from Tasks where Id = @id;", new { id = id });
                if (!tasks.Any())
                    throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Task not found"));
                
                return tasks.First();
            }
        }
Beispiel #24
0
 public override Task OpenAsync(CancellationToken cancellationToken) => _sqlCeConnection.OpenAsync(cancellationToken);
        public async Task UpdateAsync(Error error)
        {
            // If error is not exist in list or error state is now at unhandled exception state then exit
            if (!ErrorIds.ContainsKey(error.Id) || !ErrorIds[error.Id]) return;

            using (var sqlConn = new SqlCeConnection(ConnectionString))
            using (var cmd = sqlConn.CreateCommand())
            {
                cmd.CommandText =
                    string.Format("UPDATE [ErrorLog] SET [DuplicateNo] = [DuplicateNo] + 1 {0} WHERE ErrorId = @id",
                        error.IsHandled ? "" : ", [IsHandled] = @isHandled, [StackTrace] = @stackTrace");

                //
                // Add parameters to command, which will be passed to the stored procedure
                cmd.Parameters.AddWithValue("@id", error.Id);
                if (!error.IsHandled) // Just in Unhandled Exceptions
                {
                    cmd.Parameters.AddWithValue("@isHandled", error.IsHandled);
                    cmd.Parameters.AddWithValue("@stackTrace", SubLimitString(error.StackTrace));
                }

                try
                {
                    await sqlConn.OpenAsync();
                    await cmd.ExecuteNonQueryAsync();

                    ErrorIds[error.Id] = error.IsHandled;
                }
                finally
                {
                    sqlConn.Close();
                }
            }
        }
        public async Task InsertAsync(Error error)
        {
            using (var sqlConn = new SqlCeConnection(ConnectionString))
            using (var cmd = sqlConn.CreateCommand())
            {
                cmd.CommandText = @"INSERT  INTO [ErrorLog]
					   ([ErrorId]
                       ,[ServerDateTime]
					   ,[Host]
					   ,[User]
					   ,[IsHandled]
					   ,[Type]
					   ,[AppName]
					   ,[CurrentCulture]
					   ,[CLRVersion]
					   ,[Message]
					   ,[Source]
					   ,[StackTrace]
					   ,[ModuleName]
					   ,[MemberType]
					   ,[Method]
					   ,[Processes]
					   ,[ErrorDateTime]
					   ,[OS]
					   ,[IPv4Address]
					   ,[MACAddress]
					   ,[HResult]
					   ,[Line]
                       ,[Column]
                       ,[ScreenCapture]
					   ,[DuplicateNo]
                       ,[Data])
            VALUES  ( 
                        @Id
                       ,@ServerDateTime
					   ,@Host
					   ,@User
					   ,@IsHandled
					   ,@Type
					   ,@AppName
					   ,@CurrentCulture
					   ,@CLRVersion
					   ,@Message
					   ,@Source
					   ,@StackTrace
					   ,@ModuleName
					   ,@MemberType
					   ,@Method
					   ,@Processes
					   ,@ErrorDateTime
					   ,@OS
					   ,@IPv4Address
					   ,@MACAddress
					   ,@HResult
					   ,@Line
                       ,@Column
                       ,@Snapshot
					   ,@Duplicate
                       ,@Data
                    )";

                //
                // Add parameters to command, which will be passed to the stored procedure
                cmd.Parameters.AddWithValue("@Id", error.Id);
                cmd.Parameters.AddWithValue("@ServerDateTime", error.ServerDateTime);
                cmd.Parameters.AddWithValue("@Host", error.Host);
                cmd.Parameters.AddWithValue("@User", error.User);
                cmd.Parameters.AddWithValue("@IsHandled", error.IsHandled);
                cmd.Parameters.AddWithValue("@Type", error.ErrorType);
                cmd.Parameters.AddWithValue("@AppName", error.AppName);
                cmd.Parameters.AddWithValue("@CurrentCulture", error.CurrentCulture);
                cmd.Parameters.AddWithValue("@CLRVersion", error.ClrVersion);
                cmd.Parameters.AddWithValue("@Message", error.Message);
                cmd.Parameters.AddWithValue("@Source", error.Source ?? "Source Not Found");
                cmd.Parameters.AddWithValue("@StackTrace", SubLimitString(error.StackTrace));
                cmd.Parameters.AddWithValue("@ModuleName", error.ModuleName);
                cmd.Parameters.AddWithValue("@MemberType", error.MemberType);
                cmd.Parameters.AddWithValue("@Method", error.Method);
                cmd.Parameters.AddWithValue("@Processes", SubLimitString(error.Processes));
                cmd.Parameters.AddWithValue("@ErrorDateTime", error.ErrorDateTime);
                cmd.Parameters.AddWithValue("@OS", error.OS);
                cmd.Parameters.AddWithValue("@IPv4Address", error.IPv4Address);
                cmd.Parameters.AddWithValue("@MACAddress", error.MacAddress);
                cmd.Parameters.AddWithValue("@HResult", error.HResult);
                cmd.Parameters.AddWithValue("@Line", error.LineColumn.Line);
                cmd.Parameters.AddWithValue("@Column", error.LineColumn.Column);
                cmd.Parameters.AddWithValue("@Duplicate", error.Duplicate);
                cmd.Parameters.AddWithValue("@Data", SubLimitString(error.Data));
                if (error.Snapshot == null) cmd.Parameters.AddWithValue("@Snapshot", DBNull.Value);
                else cmd.Parameters.AddWithValue("@Snapshot", error.Snapshot.ToBytes());

                try
                {
                    await sqlConn.OpenAsync();
                    await cmd.ExecuteNonQueryAsync();

                    ErrorIds.Add(error.Id, error.IsHandled);
                }
                finally
                {
                    sqlConn.Close();
                }
            }
        }
        public async Task<HttpResponseMessage> Post(JObject value)
        {
            dynamic data = value;
            IEnumerable<int> result;
            using (var connection = new SqlCeConnection(_connString))
            {
                await connection.OpenAsync();

                connection.Execute(
                    "insert into Tasks (Title, Description, CreatedDate) values (@title, @description, @createdDate);",
                    new
                    {
                        title = (string)data.title,
                        description = (string)data.description,
                        createdDate = DateTime.Parse((string)data.createdDate)
                    }
                );

                result = await connection.QueryAsync<int>("select max(Id) as id from Tasks;");
            }

            int id = result.First();
            data.id = id;
            var response = Request.CreateResponse(HttpStatusCode.Created, (JObject)data);
            response.Headers.Location = new Uri(Url.Link("DefaultApi", new { controller = "Tasks", id = id }));
            return response;
        }
        public async Task<ProxyError> GetErrorAsync(int id)
        {
            using (var sqlConn = new SqlCeConnection(ConnectionString))
            using (var cmd = sqlConn.CreateCommand())
            {
                try
                {
                    cmd.CommandText = string.Format("Select * From ErrorLog Where ErrorId = {0}", id);

                    await sqlConn.OpenAsync();

                    return await cmd.ExecuteScalarAsync() as ProxyError;
                }
                finally
                {
                    sqlConn.Close();
                }
            }
        }
        public async Task DeleteAsync(int id)
        {
            // If error is not exist in list then exit
            if (!ErrorIds.ContainsKey(id)) return;

            using (var sqlConn = new SqlCeConnection(ConnectionString))
            using (var cmd = sqlConn.CreateCommand())
            {
                try
                {
                    cmd.CommandText = string.Format("Delete From ErrorLog Where ErrorId = {0}", id);

                    await sqlConn.OpenAsync();

                    await cmd.ExecuteNonQueryAsync();

                    ErrorIds.Remove(id);
                }
                finally
                {
                    sqlConn.Close();
                }
            }
        }
Beispiel #30
0
        public async Task InsertAsync(Error error)
        {
            using (var sqlConn = new SqlCeConnection(ConnectionString))
                using (var cmd = sqlConn.CreateCommand())
                {
                    cmd.CommandText = @"INSERT  INTO [ErrorLog]
					   ([ErrorId]
                       ,[ServerDateTime]
					   ,[Host]
					   ,[User]
					   ,[IsHandled]
					   ,[Type]
					   ,[AppName]
					   ,[CurrentCulture]
					   ,[CLRVersion]
					   ,[Message]
					   ,[Source]
					   ,[StackTrace]
					   ,[ModuleName]
					   ,[MemberType]
					   ,[Method]
					   ,[Processes]
					   ,[ErrorDateTime]
					   ,[OS]
					   ,[IPv4Address]
					   ,[MACAddress]
					   ,[HResult]
					   ,[Line]
                       ,[Column]
                       ,[ScreenCapture]
					   ,[DuplicateNo]
                       ,[Data])
            VALUES  ( 
                        @Id
                       ,@ServerDateTime
					   ,@Host
					   ,@User
					   ,@IsHandled
					   ,@Type
					   ,@AppName
					   ,@CurrentCulture
					   ,@CLRVersion
					   ,@Message
					   ,@Source
					   ,@StackTrace
					   ,@ModuleName
					   ,@MemberType
					   ,@Method
					   ,@Processes
					   ,@ErrorDateTime
					   ,@OS
					   ,@IPv4Address
					   ,@MACAddress
					   ,@HResult
					   ,@Line
                       ,@Column
                       ,@Snapshot
					   ,@Duplicate
                       ,@Data
                    )";

                    //
                    // Add parameters to command, which will be passed to the stored procedure
                    cmd.Parameters.AddWithValue("@Id", error.Id);
                    cmd.Parameters.AddWithValue("@ServerDateTime", error.ServerDateTime);
                    cmd.Parameters.AddWithValue("@Host", error.Host);
                    cmd.Parameters.AddWithValue("@User", error.User);
                    cmd.Parameters.AddWithValue("@IsHandled", error.IsHandled);
                    cmd.Parameters.AddWithValue("@Type", error.ErrorType);
                    cmd.Parameters.AddWithValue("@AppName", error.AppName);
                    cmd.Parameters.AddWithValue("@CurrentCulture", error.CurrentCulture);
                    cmd.Parameters.AddWithValue("@CLRVersion", error.ClrVersion);
                    cmd.Parameters.AddWithValue("@Message", error.Message);
                    cmd.Parameters.AddWithValue("@Source", error.Source ?? "Source Not Found");
                    cmd.Parameters.AddWithValue("@StackTrace", SubLimitString(error.StackTrace));
                    cmd.Parameters.AddWithValue("@ModuleName", error.ModuleName);
                    cmd.Parameters.AddWithValue("@MemberType", error.MemberType);
                    cmd.Parameters.AddWithValue("@Method", error.Method);
                    cmd.Parameters.AddWithValue("@Processes", SubLimitString(error.Processes));
                    cmd.Parameters.AddWithValue("@ErrorDateTime", error.ErrorDateTime);
                    cmd.Parameters.AddWithValue("@OS", error.OS);
                    cmd.Parameters.AddWithValue("@IPv4Address", error.IPv4Address);
                    cmd.Parameters.AddWithValue("@MACAddress", error.MacAddress);
                    cmd.Parameters.AddWithValue("@HResult", error.HResult);
                    cmd.Parameters.AddWithValue("@Line", error.LineColumn.Line);
                    cmd.Parameters.AddWithValue("@Column", error.LineColumn.Column);
                    cmd.Parameters.AddWithValue("@Duplicate", error.Duplicate);
                    cmd.Parameters.AddWithValue("@Data", SubLimitString(error.Data));
                    if (error.Snapshot == null)
                    {
                        cmd.Parameters.AddWithValue("@Snapshot", DBNull.Value);
                    }
                    else
                    {
                        cmd.Parameters.AddWithValue("@Snapshot", error.Snapshot.ToBytes());
                    }

                    try
                    {
                        await sqlConn.OpenAsync();

                        await cmd.ExecuteNonQueryAsync();

                        ErrorIds.Add(error.Id, error.IsHandled);
                    }
                    finally
                    {
                        sqlConn.Close();
                    }
                }
        }
        public async Task<int> CountAsync()
        {
            using (var sqlConn = new SqlCeConnection(ConnectionString))
            using (var cmd = sqlConn.CreateCommand())
            {
                try
                {
                    cmd.CommandText = string.Format("Select Count(ErrorId) From ErrorLog");

                    await sqlConn.OpenAsync();

                    return await cmd.ExecuteScalarAsync() as int? ?? 0;
                }
                finally
                {
                    sqlConn.Close();
                }
            }
        }