コード例 #1
0
        /// <summary>
        /// Save a message in the database
        /// </summary>
        /// <param name="message"></param>
        public void SaveMessage(DataAccessLayer.User sender, Message message)
        {
            message.Validate(sender);
            ITableRow tableRow = message.ConvertToTableRow();

            MessageTable.Instance.InsertRow(tableRow);
        }
コード例 #2
0
        public void ReadParameter(
            ConnectionGroupInfo connectionGroup,
            Int64 queryId,
            TemplateNodeQueryInfo query,
            ParameterValue paramValue
            )
        {
            Int64?parameterId = GetParameterId(connectionGroup, query, paramValue.Name);

            if (parameterId != null)
            {
                List <ITableRow> rows = this.GetRows(
                    QueryIdFn + " = " + queryId + " AND " + ParameterIdFn + " = " + parameterId
                    );

                if (rows != null)
                {
                    if (rows.Count != 0)
                    {
                        ITableRow paramRow = rows.ElementAt(0);

                        paramValue.UserValue = paramRow.GetValue <string>(ValueFn);
                    }
                }
            }
        }
コード例 #3
0
 public NewRowItemViewModel(Authentication authentication, ITableRow row, ColumnInfo columnInfo)
 {
     this.authentication = authentication;
     this.row            = row;
     this.columnInfo     = columnInfo;
     this.value          = row[columnInfo.Name];
 }
コード例 #4
0
 public void MoveLeft(ITableRow row, TaskContext context)
 {
     if (object.Equals(context.State, System.Data.DataRowState.Detached) == true)
     {
         return;
     }
 }
コード例 #5
0
        public static ServerInstanceRow Copy(ITableRow sourceRow)
        {
            ServerInstanceRow row = new ServerInstanceRow();

            sourceRow.CopyValues(row);
            return(row);
        }
コード例 #6
0
        private bool?GetChildrenNotYetProcessed(Int64 nodeInstanceId)
        {
            ITableRow row = this.GetRowByIdentity(nodeInstanceId);

            return(row != null
                                ? (bool)row.Values[ChildrenNotYetProcessedFn]
                                : (bool?)null);
        }
コード例 #7
0
		public static void ModifyTableRow(ITableRow row, Int64 queryId, Int64 sessionId, Int64 rowOrder, string rowhash)
		{
			row.Values.Add(QueryDirectory.TableName.AsFk(),    queryId);
			row.Values.Add(MetaResultTable.SessionIdFieldName, sessionId);
			row.Values.Add(RowOrderFieldName,                  rowOrder);

			row.Values[RowHashFieldName] = rowhash;
		}
コード例 #8
0
        public static void ModifyTableRow(ITableRow row, Int64 queryId, Int64 sessionId, Int64 rowOrder, string rowhash)
        {
            row.Values.Add(QueryDirectory.TableName.AsFk(), queryId);
            row.Values.Add(MetaResultTable.SessionIdFieldName, sessionId);
            row.Values.Add(RowOrderFieldName, rowOrder);

            row.Values[RowHashFieldName] = rowhash;
        }
コード例 #9
0
        public static TRow Convert <TRow>(ITableRow sourceRow) where TRow : ITableRow, new()
        {
            TRow row = new TRow();

            sourceRow.CopyValues(row);

            return(row);
        }
コード例 #10
0
 public async Task MoveLeftAsync(ITableRow row, TaskContext context)
 {
     if (object.Equals(context.State, System.Data.DataRowState.Detached) == true)
     {
         return;
     }
     await Task.Delay(0);
 }
コード例 #11
0
        public ITableRow NewRow()
        {
            ITableRow row = CreateRow();

            AddRow(row);

            return(row);
        }
コード例 #12
0
        internal int?GetRowCount(TemplateNodeInfo node)
        {
            Debug.Assert(node.IsInstance);

            int cachedValue = 0;
            int?rowsTotal   = null;

            if (node.TemplateNodeId == null)
            {
                return(null);
            }

            if (this._nodesRowCountCache.TryGetValue(node.TemplateNodeId.Value, out cachedValue))
            {
                return(cachedValue);
            }

            foreach (InstanceInfo serverInstance in node.ConnectionGroup.Connections)
            {
                foreach (TemplateNodeQueryInfo tqi in node.Queries)
                {
                    Int64?queryId = this.QueryDirectory.GetQueryId(
                        node,
                        tqi,
                        serverInstance,
                        new DateTime(),
                        true
                        );

                    if (queryId == null)
                    {
                        continue;
                    }

                    if (rowsTotal == null)
                    {
                        rowsTotal = 0;
                    }

                    ITableRow lastMetaRow = this.ReadLastMeta(queryId.Value);

                    rowsTotal += lastMetaRow != null
                                                ? (int)(Int64)lastMetaRow.Values[MetaResultTable.RowCountFieldName]
                                                : 0;
                }
            }

            if (rowsTotal == null)
            {
                return(null);
            }

            this._nodesRowCountCache.AddOrUpdate(node.TemplateNodeId.Value, id => rowsTotal.Value, (id, old) => rowsTotal.Value);

            //NodeInstances.SetReportsRowCountTotal(node.PrimaryKey.Value, rowsTotal.Value);

            return(rowsTotal.Value);
        }
コード例 #13
0
        protected void ExportToPdfButton_Click(object sender, EventArgs e)
        {
            ReportFactory.SetStyle1ForPDF();
            PdfDocument document = new PdfDocument(PageSize.A4);

            document.PageOrientation = PageOrientation.Landscape;

            ITable table = document.NewTable(2);

            ITableRow row1 = table.NewRow();

            row1.BackgoundColor = ReportColor.Red;
            row1.TextColor      = ReportColor.While;

            ITableCell cell11 = row1.NewCell();

            cell11.Value = "Tiêu đề báo cáo";
            cell11.HorizontalAlignment = HorizontalAlignment.Center;
            cell11.Colspan             = 2;

            ITableCell cell21 = row1.NewCell();

            cell21.Value = "Tiêu đề báo cáo 2";
            cell21.HorizontalAlignment = HorizontalAlignment.Left;


            ITableRow row2 = table.NewRow();

            ITableCell cell12 = row2.NewCell();

            cell12.Value = "Tiêu đề báo cáo dòng 2";
            cell12.HorizontalAlignment = HorizontalAlignment.Right;

            IParagraph p1 = new Paragraph("Hướng dẫn sử dụng thư viện xuất ra tệp PDF.");

            IText textBold = new Text(" Bold");

            textBold.Style = FontStyle.Bold;
            p1.AddText(textBold);

            document.AddElement(p1);

            IParagraph p2 = new Paragraph("Hướng dẫn sử dụng thư viện xuất ra tệp PDF.");

            p2.PaddingBottom = 10f;

            IText textBold2 = new Text(" Bold");

            textBold2.Style = FontStyle.Bold;
            p2.AddText(textBold);

            document.AddElement(p2);

            document.InsertFromExcel(MapPath("~/Uploads/data_empty.xlsx"));
            document.InsertFromExcel(MapPath("~/Uploads/data.xlsx"));

            document.Save(MapPath("~/Uploads/b.pdf"));
        }
コード例 #14
0
 public NewRowItemViewModel(Authentication authentication, ITableRow row, ColumnInfo columnInfo, TypeInfo typeInfo)
 {
     this.authentication = authentication;
     this.row            = row;
     this.columnInfo     = columnInfo;
     this.typeInfo       = typeInfo;
     this.Items          = typeInfo.Members.Select(item => (object)item).ToArray();
     this.value          = row[columnInfo.Name];
 }
コード例 #15
0
        private void PopulateUserInfo(ITableRow row)
        {
            TimetableUserEntry userEntry = _userRepository.GetByUsername(row.UserId);

            if (userEntry != null)
            {
                PopulateUserInfo(row, userEntry);
            }
        }
コード例 #16
0
ファイル: Word.cs プロジェクト: jdaomilang/report-generator
        private void RenderTableRow(TableRowLayout layout, ITable table)
        {
            ITableRow row = table.AddRow((s.TableRowStyle)layout.Style, layout.TrackingInfo);

            foreach (TableCellLayout cell in layout.SubLayouts)
            {
                RenderTableCell(cell, row);
            }
        }
コード例 #17
0
        public void SendRow(string routerName, ITableRow row, string action)
        {
            var socket = RouterNameToSocket[routerName];

            byte[] data = Encoding.ASCII.GetBytes($"{action} {row.Serialize()}");
            socket.Send(data);
            Thread.Sleep(100);
            AddLog($"Sending to {routerName}: {action} {row}", LogType.Information);
        }
コード例 #18
0
 private void NotifyOfEvent(DatabaseEvent.EAction action, ITableRow row)
 {
     ion.PostToMain(() => {
         if (onDatabaseEvent != null)
         {
             onDatabaseEvent(this, new DatabaseEvent(action, row.GetType(), row._id));
         }
     });
 }
コード例 #19
0
ファイル: Word.cs プロジェクト: jdaomilang/report-generator
        private void RenderTableCell(TableCellLayout layout, ITableRow row)
        {
            ITableCell cell = row.AddCell(layout.ColumnSpan, (s.TableCellStyle)layout.Style, layout.TrackingInfo);

            foreach (Layout sublayout in layout.SubLayouts)
            {
                Render(sublayout, cell);
            }
        }
コード例 #20
0
        /// <summary>
        /// Get row id of row according values
        /// </summary>
        /// <param name="row">Row to search</param>
        /// <returns></returns>
        protected Int64?GetRow(ITableRow row)
        {
            string clause = null;
            List <SQLiteParameter> parameters = null;

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

            return(this.GetRowIdentity(clause, parameters));
        }
コード例 #21
0
ファイル: DataReceiver.cs プロジェクト: lonelu/MealTimeMS
        private ITable CreateReplacementTable()
        {
            WriterClass.writeln("Exclusion Table Info:");
            // Show possible columns, their names, help and value options
            ITable replacementTable = m_methods.CreateTable(typeof(IExclusionTable));

            foreach (ITableColumnDescription col in replacementTable.ColumnInfo)
            {
                log.Info("{0,-12} {1,-25} {2}", col.Name, col.Selection, (col.Help ?? "").Trim().Replace("\r", "").Replace("\n", "; "));
                WriterClass.writeln(String.Format("{0,-12} {1,-25} {2}", col.Name, col.Selection, (col.Help ?? "").Trim().Replace("\r", "").Replace("\n", "; ")));
                if (col.AcceptedHeaderNames.Length > 0)
                {
                    log.Info("{0,38} alternative names: {1}", "", string.Join(", ", col.AcceptedHeaderNames));
                    WriterClass.writeln(String.Format("{0,38} alternative names: {1}", "", string.Join(", ", col.AcceptedHeaderNames)));
                }
            }
            WriterClass.Flush();
            WriterClass.writeln("======================================\n");
            WriterClass.writeln("Now attempting to write default value\n");



            foreach (ITableColumnDescription col in replacementTable.ColumnInfo)
            {
                log.Info("{0,-12} {1,-25} {2} Default Value: {3}; Optional: {4}", col.Name, col.Selection, (col.Help ?? "").Trim().Replace("\r", "").Replace("\n", "; "), col.DefaultValue, col.Optional.ToString());
                WriterClass.writeln(String.Format("{0,-12} {1,-25} {2} Default Value: {3}; Optional: {4}", col.Name, col.Selection, (col.Help ?? "").Trim().Replace("\r", "").Replace("\n", "; "), col.DefaultValue, col.Optional.ToString()));
                if (col.AcceptedHeaderNames.Length > 0)
                {
                    log.Info("{0,38} alternative names: {1}", "", string.Join(", ", col.AcceptedHeaderNames));
                    WriterClass.writeln(String.Format("{0,38} alternative names: {1}", "", string.Join(", ", col.AcceptedHeaderNames)));
                }
            }

            WriterClass.Flush();

            if (GlobalVar.SetExclusionTable)
            {
                log.Info("Attempting to set exclusio table values");
                //// Create a new table with two rows.
                ITableRow row = replacementTable.CreateRow();
                row.ColumnValues["Polarity"]   = "Positive"; // must match, PRM has a polarity setting
                row.ColumnValues["Mass [m/z]"] = "700";
                replacementTable.Rows.Add(row);
                row = replacementTable.CreateRow();
                row.ColumnValues["Polarity"]   = "Negative";
                row.ColumnValues["Mass [m/z]"] = "1600";
                replacementTable.Rows.Add(row);
            }
            else
            {
                replacementTable = null;
            }


            return(replacementTable);
        }
コード例 #22
0
        public ServerProperties GetServerProperties(
            InstanceInfo instance
            )
        {
            ConnectionGroupInfo connectionGroup = instance.ConnectionGroup;

            connectionGroup.ReadGroupIdFrom(Storage.ConnectionGroupDirectory);

            Int64?loginId = Storage.LoginDirectory.GetId(instance);

            string clause = string.Join(" AND ",
                                        new List <string>
            {
                ConnectionGroupIdFn.AsSqlClausePair(),
                LoginIdFn.AsSqlClausePair(),
                ConnectionNameFn.AsSqlClausePair(),
                DbTypeFn.AsSqlClausePair(),
                IsDynamicConnectionFn.AsSqlClausePair()
            }
                                        );

            List <ITableRow> rows = this.GetRows(
                clause,
                new List <SQLiteParameter>
            {
                SQLiteHelper.GetParameter(ConnectionGroupIdFn, connectionGroup.Identity),
                SQLiteHelper.GetParameter(LoginIdFn, loginId),
                SQLiteHelper.GetParameter(ConnectionNameFn, instance.Name),
                SQLiteHelper.GetParameter(DbTypeFn, instance.DbType),
                SQLiteHelper.GetParameter(IsDynamicConnectionFn, instance.IsDynamicConnection)
            },
                1
                );

            if (rows != null)
            {
                if (rows.Count != 0)
                {
                    ITableRow row     = rows.ElementAt(0);
                    string    version = row.GetValue <string>(ServerInstanceVersionFn);
                    string    name    = row.GetValue <string>(ServerInstanceNameFn);

                    if (!string.IsNullOrEmpty(version))
                    {
                        return(new ServerProperties(
                                   new InstanceVersion(version),
                                   name,
                                   DateTime.Now
                                   ));
                    }
                }
            }

            return(null);
        }
コード例 #23
0
        public LastConnectionProtocolRow GetRow(long lastConnectionId)
        {
            ITableRow row = GetRowByIdentity(lastConnectionId);

            if (row == null)
            {
                return(null);
            }

            return(RowConverter.Convert <LastConnectionProtocolRow>(row));
        }
コード例 #24
0
        public TemplateRow GetTemplate(long templateId)
        {
            ITableRow row = GetRowByIdentity(templateId);

            if (row != null)
            {
                return(RowConverter.Convert <TemplateRow>(row));
            }

            return(null);
        }
コード例 #25
0
        public async Task SetTagsAsync(ITableRow row, TaskContext context)
        {
            var authentication = context.Authentication;

            if (object.Equals(context.State, System.Data.DataRowState.Detached) == true)
            {
                return;
            }
            var tags = TagInfoUtility.Names.Random();
            await row.SetTagsAsync(authentication, (TagInfo)tags);
        }
コード例 #26
0
        public async Task SetIsEnabledAsync(ITableRow row, TaskContext context)
        {
            var authentication = context.Authentication;

            if (object.Equals(context.State, System.Data.DataRowState.Detached) == true)
            {
                return;
            }
            var isEnabled = RandomUtility.NextBoolean();
            await row.SetIsEnabledAsync(authentication, isEnabled);
        }
コード例 #27
0
        public ConnectionGroupRow GetGroupById(long id)
        {
            ITableRow row = this._storage.ConnectionGroupDirectory.GetRowByIdentity(id);

            if (row == null)
            {
                return(null);
            }

            return(RowConverter.Convert <ConnectionGroupRow>(row));
        }
コード例 #28
0
ファイル: TableContent.cs プロジェクト: teize001/Crema
 void ITableContent.EndNew(Authentication authentication, ITableRow row)
 {
     if (row == null)
     {
         throw new ArgumentNullException(nameof(row));
     }
     if (row is TableRow == false)
     {
         throw new ArgumentException(Resources.Exception_InvalidObject, nameof(row));
     }
     this.EndNew(authentication, row as TableRow);
 }
コード例 #29
0
        protected void ExportToPdfMergeRowButton_Click(object sender, EventArgs e)
        {
            ReportFactory.SetStyle1ForPDF();
            PdfDocument document = new PdfDocument(PageSize.A0);

            document.PageOrientation = PageOrientation.Landscape;

            document.InsertFromExcel(MapPath("~/Uploads/Report_4_TongHopCallReport.xlsx"));

            ReportColor green    = ReportColor.Create(0, 100, 45);
            ReportColor textHong = ReportColor.Create(230, 184, 183);
            ReportColor textKhds = ReportColor.Create(99, 37, 35);
            ReportColor textKhln = ReportColor.Create(118, 147, 60);
            ReportColor textThds = ReportColor.Create(96, 73, 122);
            ReportColor textThln = ReportColor.Create(49, 134, 155);

            document.Save(MapPath("~/Uploads/Report_4_TongHopCallReport.pdf"), (paragraphs) =>
            {
                foreach (IElementRoot paragraph in paragraphs)
                {
                    if (paragraph is ITable)
                    {
                        ITable table   = paragraph as ITable;
                        ITableRow row1 = table.Rows[0];

                        for (int i = 1; i <= row1.Cells.Count; i++)
                        {
                            ITableCell cell     = row1.Cells[i - 1];
                            cell.BackgoundColor = green;

                            if (i > 3)
                            {
                                cell.TextColor = textHong;
                            }
                            else
                            {
                                cell.TextColor = ReportColor.While;
                            }
                        }

                        ITableRow row3 = table.Rows[2];
                        for (int i = 1; i <= row3.Cells.Count; i++)
                        {
                            ITableCell cell     = row3.Cells[i - 1];
                            cell.TextColor      = ReportColor.While;
                            cell.BackgoundColor = green;
                        }
                    }
                }

                return(paragraphs);
            });
        }
コード例 #30
0
 public void Delete(ITableRow row, TaskContext context)
 {
     row.Dispatcher.Invoke(() =>
     {
         if (object.Equals(context.State, System.Data.DataRowState.Detached) == false)
         {
             row.Delete(context.Authentication);
             context.State = System.Data.DataRowState.Deleted;
             context.Complete(row);
         }
     });
 }
コード例 #31
0
        public async Task DeleteAsync(ITableRow row, TaskContext context)
        {
            var authentication = context.Authentication;

            if (object.Equals(context.State, System.Data.DataRowState.Detached) == false)
            {
                await row.DeleteAsync(authentication);

                context.State = System.Data.DataRowState.Deleted;
                context.Pop(row);
            }
        }
コード例 #32
0
		public RowUpdateByHashCommand(
			SQLiteConnection connection,
			TableDefinition  tableDefinition
		) : base(
				connection,
				tableDefinition
			)
		{
			this._clause      = null;
			this._setString   = null;
			this._updateTable = false;
			this._parameters  = null;
			this._row         = null;
			this._transaction = null;
		}
コード例 #33
0
		public void SetCommandConstraints(
			string                clause,
			List<SQLiteParameter> parameters,
			string                setString,
			bool                  updateTable,
			ITableRow             row,
			SQLiteTransaction     transaction = null
		)
		{
			this._clause      = clause;
			this._parameters  = parameters;
			this._setString   = setString;
			this._updateTable = updateTable;
			this._row         = row;
			this._transaction = transaction;
		}
コード例 #34
0
        public static Message ConvertToMessage(ITable table, ITableRow tableRow)
        {
            Message message = null;
            if (table.BlobValueColumn != null)
            {
                byte[] value = (byte[])tableRow.ColumnValues[table.BlobValueColumn];
                message = MessageSerializer.DeSerializeFromProtocolBuffer(value);
            }
            else
            {
                message = new Message();
            }

            DataContractToTableRowConverter.SetYapperColumnValues(message, tableRow);

            return message;
        }
コード例 #35
0
ファイル: DatabaseInsertOperator.cs プロジェクト: nrag/yapper
        internal object Execute(ITableRow row)
        {
            this.connection.StartTransaction(System.Data.IsolationLevel.ReadCommitted);

            // Save the blob first
            if (table.BlobValueColumn != null && table.BlobNameColumn != null)
            {
                object guidObject = null;
                Guid blobName = Guid.Empty;
                if (!row.ColumnValues.TryGetValue(table.BlobNameColumn, out guidObject))
                {
                    blobName = Guid.NewGuid();
                    row.ColumnValues.Add(table.BlobNameColumn, blobName);
                }
                else
                {
                    blobName = (Guid)guidObject;
                }

                object blobValue = null;
                if (!row.ColumnValues.TryGetValue(table.BlobValueColumn, out blobValue))
                {
                    row.ColumnValues[table.BlobNameColumn] = Guid.Empty;
                    blobName = Guid.Empty;
                }

                IBlobStore blobStore = BlobStoreFactory.Instance.GetBlobStore();
                blobStore.SaveBlob(row.BlobContainer, blobName.ToString(), (byte[])blobValue);
            }

            // Save the row in the table
            DbCommand command = this.BuildInsertCommand(row);

            if (table.Identity != null)
            {
                SqlParameter outParameter = new SqlParameter(string.Format("@{0}", table.Identity.Name), DatabaseInsertOperator.GetSqlType(table.Identity.Type));
                outParameter.Direction = ParameterDirection.Output;
                command.Parameters.Add(outParameter);
            }

            object outParam = command.ExecuteScalar();
            this.connection.CommitTransaction();

            return null;
        }
コード例 #36
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);
					}
				}
			}
		}
コード例 #37
0
ファイル: DatabaseTable.cs プロジェクト: nrag/yapper
        public ITableRow InsertRow(ITableRow row)
        {
            // Validate that we are attempting to insert only the columns that
            // exist in the table
            foreach (IColumn column in row.ColumnValues.Keys)
            {
                if (!this.Columns.Contains(column))
                {
                    throw new Exception("Attempting to insert a column that doesn't exist in the table");
                }
            }

            foreach (IColumn column in this.Columns)
            {
                if (column.IsRequired && !row.ColumnValues.ContainsKey(column))
                {
                    throw new Exception("Value for required column not present");
                }
            }

            if (this.Identity != null && row.ColumnValues.ContainsKey(this.Identity))
            {
                throw new Exception("Value should not be set for identity column");
            }

            using (DatabaseInsertOperator insertOp = new DatabaseInsertOperator(this))
            {
                object identity = insertOp.Execute(row);

                if (this.Identity != null)
                {
                    row.ColumnValues.Add(this.Identity, identity);
                }
            }

            return row;
        }
コード例 #38
0
ファイル: Table.cs プロジェクト: saycale/MSSQLServerAuditor
		/// <summary>
		/// Update one row by row identity
		/// </summary>
		/// <param name="row">Row to update</param>
		public void UpdateRow(ITableRow row)
		{
			this.UpdateRows(new[] { row });
		}
コード例 #39
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;
		}
コード例 #40
0
ファイル: Table.cs プロジェクト: saycale/MSSQLServerAuditor
		public Int64? InsertOrUpdateRowForSure(ITableRow row)
		{
			//
			// without r => { } the records can't be updated
			//
			return this.InsertOrUpdateRow(row, r => { });
		}
コード例 #41
0
ファイル: Table.cs プロジェクト: saycale/MSSQLServerAuditor
		/// <summary>
		/// Get row id of row according values
		/// </summary>
		/// <param name="row">Row to search</param>
		/// <returns></returns>
		protected Int64? GetRow(ITableRow row)
		{
			string                clause     = null;
			List<SQLiteParameter> parameters = null;

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

			return this.GetRowIdentity(clause, parameters);
		}
コード例 #42
0
ファイル: Table.cs プロジェクト: saycale/MSSQLServerAuditor
		/// <summary>
		/// Add row to table
		/// </summary>
		/// <param name="row">Row to add</param>
		/// <returns></returns>
		public Int64? AddRow(ITableRow row)
		{
			return this.AddRows(new[] { row });
		}
コード例 #43
0
        public void ComposeTableRow(TemplateNodeInfo node, out ITableRow nodeRow, out List<ITableRow> attributesRows)
        {
            Debug.Assert(node.IsInstance);

            Int64? parentNodeId = null;

            if (node.Parent != null)
            {
                if (node.Parent.TemplateNodeId == null)
                {
                    throw new InvalidOperationException(node + ": it's parent is not saved (has no id)");
                }

                parentNodeId = node.Parent.TemplateNodeId;
            }

            nodeRow = new TableRow(this.TableDefinition);
            node.ConnectionGroup.ReadGroupIdFrom(this._storage.ConnectionGroupDirectory);

            nodeRow.Values.Add(
                ConnectionIdFn,
                node.ConnectionGroup.Identity
            );

            nodeRow.Values.Add(
                TemplateNodeIdFn,
                this._storage.TemplateNodeDirectory.GetId(node.ConnectionGroup, node.Template)
            );

            nodeRow.Values.Add(ParentIdFn,      parentNodeId);
            nodeRow.Values.Add(NodeUIdFn,       node.UId);
            nodeRow.Values.Add(NodeUNameFn,     node.UName);
            nodeRow.Values.Add(NodeUIconFn,     node.IconImageReferenceName);
            nodeRow.Values.Add(NodeEnabledFn,  !node.IsDisabled);
            nodeRow.Values.Add(NodeFontColorFn, node.FontColor);
            nodeRow.Values.Add(NodeFontStyleFn, node.FontStyle);

            if (node.CounterValue != null)
            {
                nodeRow.Values.Add(NodeCounterValue, node.CounterValue);
            }

            nodeRow.Values.Add(
                NodeSequenceNumberFn,
                node.Parent != null ? node.Parent.Childs.IndexOf(node) : 0
            );

            List<TemplateNodeUpdateJob> jobs = node.GetRefreshJob(true);

            foreach (TemplateNodeUpdateJob job in jobs)
            {
                if (job != null && job.LastRan != null)
                {
                    nodeRow.Values.Add(NodeScheduledUpdateFn, job.LastRan);
                }
            }

            attributesRows = new List<ITableRow>();

            foreach (KeyValuePair<string, string> pair in node.Attributes.Values)
            {
                ITableRow row = new TableRow(NodeInstanceAttributeTable.CreateTableDefinition());

                row.Values.Add(NodeInstanceAttributeTable.NameFn, pair.Key);
                row.Values.Add(NodeInstanceAttributeTable.ValueFn, pair.Value);

                attributesRows.Add(row);
            }
        }
コード例 #44
0
		public void AddRowForReplacing(ITableRow row)
		{
			this._rows.Add(row);
		}
コード例 #45
0
ファイル: DatabaseInsertOperator.cs プロジェクト: nrag/yapper
        private DbCommand BuildInsertCommand(ITableRow row)
        {
            StringBuilder columns = new StringBuilder();
            StringBuilder columnParameters = new StringBuilder();

            foreach (IColumn column in row.ColumnValues.Keys)
            {
                if (column.ColumnLocation == ColumnLocation.Database)
                {
                    columns.AppendFormat("{0},", column.Name);
                    columnParameters.AppendFormat("@{0},", column.Name);
                }
            }

            columns.Remove(columns.Length - 1, 1);
            columnParameters.Remove(columnParameters.Length - 1, 1);

            string query = string.Format(
                DatabaseInsertOperator.InsertQueryFormat,
                this.table.Name,
                columns.ToString(),
                columnParameters.ToString(),
                this.table.Identity == null ? string.Empty : DatabaseInsertOperator.ScopeIdentity);

            DbCommand command = this.connection.CreateCommand(query);

            // Add the parameters to the SQL command
            foreach (IColumn column in row.ColumnValues.Keys)
            {
                if (column.ColumnLocation == ColumnLocation.Database)
                {
                    command.Parameters.Add(this.connection.CreateParameter(string.Format("@{0}", column.Name), row.ColumnValues[column]));
                }
            }

            return command;
        }
コード例 #46
0
ファイル: DatabaseTable.cs プロジェクト: nrag/yapper
 public bool DeleteRow(ITableRow row)
 {
     return false;
 }
コード例 #47
0
		public LoginRow Encrypt(ITableRow row, ICryptoService cipher)
		{
			base.EncryptFrom(row, cipher);

			return this;
		}
コード例 #48
0
 public static ServerInstanceRow Copy(ITableRow sourceRow)
 {
     ServerInstanceRow row = new ServerInstanceRow();
     sourceRow.CopyValues(row);
     return row;
 }
コード例 #49
0
ファイル: Table.cs プロジェクト: saycale/MSSQLServerAuditor
		/// <summary>
		/// Prepare the query to the table data
		/// </summary>
		/// <param name="row">table row</param>
		/// <returns></returns>
		private void GetQueryDataForRow(ITableRow row, out string clause, out List<SQLiteParameter> parameters)
		{
			List<string> clauses = new List<string>();

			parameters = new List<SQLiteParameter>();

			foreach (FieldDefinition field in this.TableDefinition.Fields.Values)
			{
				if (field.Unique)
				{
					if (row.Values[field.Name] != null)
					{
						clauses.Add(field.Name.AsSqlClausePair());

						SQLiteParameter param = new SQLiteParameter(field.Name.AsParamName(), field.SqlType.ToDbType())
						{
							Value = row.Values[field.Name] ?? DBNull.Value
						};

						parameters.Add(param);
					}
					else
					{
						clauses.Add(string.Format("{0} IS NULL", field.Name));
					}
				}
			}

			// the code bellow is needed to support the calculation of the "clause" based on unique
			// indexes composed from 2 or more fields
			if (clauses.Count == 0)
			{
				foreach (IndexDefinition indDef in this.TableDefinition.Indexes)
				{
					if (indDef.IsComposedUnique)
					{
						foreach (string fieldName in indDef.FieldNames)
						{
							FieldDefinition field = this.TableDefinition.Fields[fieldName];

							if (row.Values[field.Name] != null)
							{
								clauses.Add(field.Name.AsSqlClausePair());

								SQLiteParameter param = new SQLiteParameter(field.Name.AsParamName(), field.SqlType.ToDbType())
								{
									Value = row.Values[field.Name] ?? DBNull.Value
								};

								parameters.Add(param);
							}
							else
							{
								clauses.Add(string.Format("{0} IS NULL", field.Name));
							}
						}
					}
				}
			}

			clause = clauses.Join(" AND ");
		}
コード例 #50
0
		public void AddRowForUpdating(ITableRow row)
		{
			this._rows.Add(row);
		}
コード例 #51
0
 protected virtual void BeforeRowUpdate(ITableRow row)
 {
 }
コード例 #52
0
        private static void SetYapperColumnValues(Message message, ITableRow row)
        {
            PropertyInfo[] propertyInfoArray = message.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);

            foreach (PropertyInfo propInfo in propertyInfoArray)
            {
                IEnumerable<Attribute> attrs = propInfo.GetCustomAttributes();
                if (attrs == null)
                {
                    continue;
                }

                IColumn column = null;
                bool isDbColumn = false;
                bool isInBlob = false; ;
                foreach (Attribute a in attrs)
                {
                    if (a is YapperColumnAttribute && ((YapperColumnAttribute)a).ColumnLocation == ColumnLocation.Database)
                    {
                        isDbColumn = true;
                        YapperColumnAttribute yapperColumn = a as YapperColumnAttribute;
                        column = MessageTable.GetColumnFromName(yapperColumn.Name);
                    }

                    if (a is ProtoBuf.ProtoMemberAttribute)
                    {
                        isInBlob = true;
                    }
                }

                if (column != null && isDbColumn && !isInBlob)
                {
                    propInfo.SetValue(message, row.ColumnValues[column]);
                }
            }
        }
コード例 #53
0
		public void AddRowForInserting(ITableRow row)
		{
			this._rows.Add(row);
		}
コード例 #54
0
		public RowUpdateInput(string oldHash, ITableRow row)
		{
			this.Row     = row;
			this.OldHash = oldHash;
		}
コード例 #55
0
 protected virtual void BeforeRowAdd(ITableRow row)
 {
 }