public static ServerInstanceRow Copy(ITableRow sourceRow)
        {
            ServerInstanceRow row = new ServerInstanceRow();

            sourceRow.CopyValues(row);
            return(row);
        }
Exemplo n.º 2
0
        public static TRow Convert <TRow>(ITableRow sourceRow) where TRow : ITableRow, new()
        {
            TRow row = new TRow();

            sourceRow.CopyValues(row);

            return(row);
        }
		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);
					}
				}
			}
		}
        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);
                    }
                }
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 6
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;
		}
 public static ServerInstanceRow Copy(ITableRow sourceRow)
 {
     ServerInstanceRow row = new ServerInstanceRow();
     sourceRow.CopyValues(row);
     return row;
 }