コード例 #1
0
        public static ServerInstanceRow Copy(ITableRow sourceRow)
        {
            ServerInstanceRow row = new ServerInstanceRow();

            sourceRow.CopyValues(row);
            return(row);
        }
コード例 #2
0
        public static TRow Convert <TRow>(ITableRow sourceRow) where TRow : ITableRow, new()
        {
            TRow row = new TRow();

            sourceRow.CopyValues(row);

            return(row);
        }
コード例 #3
0
		public void DecryptFrom(ITableRow encryptedRow, ICryptoService cryptoService)
		{
			encryptedRow.CopyValues(this);

			foreach (string encryptedField in EncryptedStringFields)
			{
				if (this.TableDefinition.Fields.ContainsKey(encryptedField))
				{
					FieldDefinition def = this.TableDefinition.Fields[encryptedField];

					if (def.SqlType == SqlDbType.NVarChar)
					{
						string decryptedValue = cryptoService.Decrypt(GetValue<string>(encryptedField));

						SetValue(encryptedField, decryptedValue);
					}
				}
			}
		}
コード例 #4
0
        public void DecryptFrom(ITableRow encryptedRow, ICryptoService cryptoService)
        {
            encryptedRow.CopyValues(this);

            foreach (string encryptedField in EncryptedStringFields)
            {
                if (this.TableDefinition.Fields.ContainsKey(encryptedField))
                {
                    FieldDefinition def = this.TableDefinition.Fields[encryptedField];

                    if (def.SqlType == SqlDbType.NVarChar)
                    {
                        string decryptedValue = cryptoService.Decrypt(GetValue <string>(encryptedField));

                        SetValue(encryptedField, decryptedValue);
                    }
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Find or create row according values
        /// </summary>
        /// <param name="row">Row to search or create</param>
        /// <param name="beforeRowUpdate">Code to be executed before row update. If null no update executes.</param>
        /// <param name="beforeRowAdd">Code to be executed before row insert</param>
        /// <returns></returns>
        public Int64?InsertOrUpdateRow(
            ITableRow row,
            Action <ITableRow> beforeRowUpdate = null,
            Action <ITableRow> beforeRowAdd    = null
            )
        {
            Int64? identity = null;
            string clause   = null;
            List <SQLiteParameter> parameters = null;
            List <ITableRow>       result     = null;

            this.GetQueryDataForRow(row, out clause, out parameters);

            using (this.Connection.OpenWrapper())
            {
                result = this.GetRows(clause, parameters, 1);

                if (result != null && result.Count > 0)
                {
                    // Log.DebugFormat("Record exists(1):Count:'{0}'",
                    //    result.Count
                    // );

                    ITableRow existRow = result.First();

                    if (beforeRowUpdate != null)
                    {
                        beforeRowUpdate(row);
                    }

                    if (row.CopyValues(existRow))
                    {
                        this.UpdateRow(existRow);
                    }

                    identity = (long?)existRow.Values[IdentityField];
                }
                else
                {
                    // Log.Debug("Record is not exists");

                    lock (this.GetLockObject())
                    {
                        //
                        // try to get the record again as the record can be already added by the differect thread
                        //
                        result = this.GetRows(clause, parameters, 1);

                        if (result != null && result.Count > 0)
                        {
                            // Log.DebugFormat("Record exists(2):Count:'{0}'",
                            //    result.Count
                            // );

                            ITableRow existRow = result.First();

                            if (beforeRowUpdate != null)
                            {
                                beforeRowUpdate(row);

                                if (row.CopyValues(existRow))
                                {
                                    this.UpdateRow(existRow);
                                }
                            }

                            identity = (long?)existRow.Values[IdentityField];
                        }
                        else
                        {
                            if (beforeRowAdd != null)
                            {
                                beforeRowAdd(row);
                            }

                            identity = this.AddRow(row);
                        }
                    }
                }
            }

            return(identity);
        }
コード例 #6
0
ファイル: Table.cs プロジェクト: saycale/MSSQLServerAuditor
		/// <summary>
		/// Find or create row according values
		/// </summary>
		/// <param name="row">Row to search or create</param>
		/// <param name="beforeRowUpdate">Code to be executed before row update. If null no update executes.</param>
		/// <param name="beforeRowAdd">Code to be executed before row insert</param>
		/// <returns></returns>
		public Int64? InsertOrUpdateRow(
			ITableRow         row,
			Action<ITableRow> beforeRowUpdate = null,
			Action<ITableRow> beforeRowAdd = null
		)
		{
			Int64?                identity   = null;
			string                clause     = null;
			List<SQLiteParameter> parameters = null;
			List<ITableRow>       result     = null;

			this.GetQueryDataForRow(row, out clause, out parameters);

			using (this.Connection.OpenWrapper())
			{
				result = this.GetRows(clause, parameters, 1);

				if (result != null && result.Count > 0)
				{
					// Log.DebugFormat("Record exists(1):Count:'{0}'",
					//    result.Count
					// );

					ITableRow existRow = result.First();

					if (beforeRowUpdate != null)
					{
						beforeRowUpdate(row);
					}

					if (row.CopyValues(existRow))
					{
						this.UpdateRow(existRow);
					}

					identity = (long?) existRow.Values[IdentityField];
				}
				else
				{
					// Log.Debug("Record is not exists");

					lock (this.GetLockObject())
					{
						//
						// try to get the record again as the record can be already added by the differect thread
						//
						result = this.GetRows(clause, parameters, 1);

						if (result != null && result.Count > 0)
						{
							// Log.DebugFormat("Record exists(2):Count:'{0}'",
							//    result.Count
							// );

							ITableRow existRow = result.First();

							if (beforeRowUpdate != null)
							{
								beforeRowUpdate(row);

								if (row.CopyValues(existRow))
								{
									this.UpdateRow(existRow);
								}
							}

							identity = (long?) existRow.Values[IdentityField];
						}
						else
						{
							if (beforeRowAdd != null)
							{
								beforeRowAdd(row);
							}

							identity = this.AddRow(row);
						}
					}
				}
			}

			return identity;
		}
コード例 #7
0
 public static ServerInstanceRow Copy(ITableRow sourceRow)
 {
     ServerInstanceRow row = new ServerInstanceRow();
     sourceRow.CopyValues(row);
     return row;
 }