public static void emailLogUpdater(ClarifyDataRow record, HistoryItem historyItem, ISchemaCache schemaCache) { var log = new StringBuilder(); var from = record.AsString("sender"); var to = record.AsString("recipient"); var cclist = record.AsTrimmedString("cc_list"); var subject = doesEmailLogSubjectExist(schemaCache) ? record.AsTrimmedString("x_subject") : ""; var message = record.AsString("message"); var isoDate = record.AsDateTime("creation_time").ToString("s", CultureInfo.InvariantCulture); log.Append(HistoryParsers.BEGIN_EMAIL_LOG_HEADER); log.AppendLine("{0}: {1}{2}".ToFormat(HistoryBuilderTokens.LOG_EMAIL_DATE, HistoryParsers.BEGIN_ISODATE_HEADER, isoDate)); const string headerFormat = "{0}: {1}"; log.AppendLine(headerFormat.ToFormat(HistoryBuilderTokens.LOG_EMAIL_FROM, from)); log.AppendLine(headerFormat.ToFormat(HistoryBuilderTokens.LOG_EMAIL_TO, to)); if (cclist.IsNotEmpty()) log.AppendLine(headerFormat.ToFormat(HistoryBuilderTokens.LOG_EMAIL_CC, cclist)); if (subject.IsNotEmpty()) log.AppendLine(headerFormat.ToFormat(HistoryBuilderTokens.LOG_EMAIL_SUBJECT, subject)); log.Append(HistoryParsers.END_EMAIL_LOG_HEADER); log.AppendLine(message); historyItem.Detail = log.ToString(); }
public HistoryItemEmployee Assemble(ClarifyDataRow actEntryRecord, IHistoryContactAssembler contactAssembler) { var userRows = actEntryRecord.RelatedRows(_userGeneric); if (userRows.Length == 0) return new HistoryItemEmployee(); var userRecord = userRows[0]; var login = userRecord.AsString("login_name"); var employeeRows = userRecord.RelatedRows(_employeeGeneric); if (employeeRows.Length == 0) return new HistoryItemEmployee { Login = login }; var employeeRecord = employeeRows[0]; var name = "{0} {1}".ToFormat(employeeRecord.AsString("first_name"), employeeRecord.AsString("last_name")); var email = employeeRecord.AsString("e_mail"); var id = employeeRecord.DatabaseIdentifier(); return new HistoryItemEmployee { Name = name, Firstname = employeeRecord.AsString("first_name"), Lastname = employeeRecord.AsString("last_name"), Id = id, Login = login, Email = email, PerformedByContact = contactAssembler.Assemble(actEntryRecord) }; }
public void beforeEach() { var dataSet = AdministratorClarifySession.CreateDataSet(); var emailLogGeneric = dataSet.CreateGeneric("email_log"); emailLogGeneric.Filter(f => f.Equals("objid", _logEmailObjid)); emailLogGeneric.Query(); _dataRow = emailLogGeneric[0]; _historyItem = new HistoryItem(); CommonActEntryBuilderDSLExtensions.emailLogUpdater(_dataRow, _historyItem, _schemaCache); }
protected void ApplyFields(ClarifyDataRow row) { foreach(FieldProtocol field in this.Fields) { if(!ClarifyApplication.Instance.SchemaCache.IsValidField( this.Table, field.Name )) throw new InvalidOperationException(string.Format("Field '{0}' is not valid for object '{1}'", field.Name, this.Table)); SchemaFieldBase schemaField = ClarifyApplication.Instance.SchemaCache.GetField( this.Table, field.Name ); object fieldValue = null; try { switch( schemaField.CommonType ) { case (int)SchemaCommonType.String: fieldValue = field.Value; break; case (int)SchemaCommonType.Date: fieldValue = DateTime.Parse( field.Value ); break; case (int)SchemaCommonType.Float: fieldValue = float.Parse( field.Value ); break; case (int)SchemaCommonType.Double: fieldValue = double.Parse( field.Value ); break; case (int)SchemaCommonType.Decimal: fieldValue = decimal.Parse( field.Value ); break; case (int)SchemaCommonType.Integer: fieldValue = int.Parse( field.Value ); break; default: throw new InvalidOperationException(string.Format("Parse logic not implemented for SchemaCommonType.{0}", schemaField.CommonType)); } } catch(FormatException ex) { throw new InvalidOperationException(string.Format("Could not parse field value '{0}' for field '{1}' on object '{2}'.", field.Value, field.Name, this.Table), ex); } row[field.Name] = fieldValue; } }
public HistoryItemContact Assemble(ClarifyDataRow actEntryRecord) { var contactRows = actEntryRecord.RelatedRows(_contactGeneric); if (contactRows.Length == 0) return null; var contactRecord = contactRows[0]; var name = "{0} {1}".ToFormat(contactRecord.AsString("first_name"), contactRecord.AsString("last_name")); var email = contactRecord.AsString("e_mail"); var id = contactRecord.DatabaseIdentifier(); return new HistoryItemContact { Name = name, Firstname = contactRecord.AsString("first_name"), Lastname = contactRecord.AsString("last_name"), Id = id, Email = email }; }
private static string[] GetGenericFieldValues(FieldMap fieldMap, ClarifyDataRow record) { return(fieldMap.FieldNames.Select(fieldName => record[fieldName].ToString()).ToArray()); }
private void populateDTOWithFieldValues(ClarifyGenericMapEntry genericMap, ClarifyDataRow record, ModelData model) { populateDataWithFieldValues(genericMap.FieldMaps, record, model); populateDataWithFieldValues(genericMap.Model.FieldMaps, record, model); }
private static void timeAndExpensesUpdater(ClarifyDataRow record, HistoryItem historyItem) { var timeDescribed = TimeSpan.FromSeconds(record.AsInt("total_time")); var expense = Convert.ToDecimal(record["total_exp"]).ToString("C"); var notes = record.AsString("notes"); var detail = HistoryBuilderTokens.LOG_EXPENSES_DETAIL.ToFormat(Environment.NewLine, timeDescribed, expense, notes); historyItem.Detail = detail; }
private static void setInternalLog(ClarifyDataRow row, HistoryItem dto, string noteField) { var isNewInternalNote = row.AsInt("x_is_internal") == 1; var notes = row.AsString(noteField); var @internal = row.AsString("internal"); dto.Detail = isNewInternalNote ? "" : notes; dto.Internal = isNewInternalNote ? notes : @internal; }
private static void timeAndExpensesUpdater(ClarifyDataRow record, HistoryItem historyItem) { var timeDescribed = TimeSpan.FromSeconds(Convert.ToInt32(record["total_time"])); var expense = Convert.ToDecimal(record["total_exp"]); var detail = "Time: {1}{0}Expense: {2}{0}{3}".ToFormat(Environment.NewLine, timeDescribed, expense.ToString("C"), record["notes"]); historyItem.Detail = detail; }
public static int AsInt(this ClarifyDataRow row, string fieldName) { return(row[fieldName] == DBNull.Value ? 0 : Convert.ToInt32(row[fieldName])); }
public static string AsTrimmedString(this ClarifyDataRow row, string fieldName) { var result = AsString(row, fieldName); return((result ?? "").Trim()); }
public static string AsString(this ClarifyDataRow row, string fieldName) { return(row[fieldName] == DBNull.Value ? null : row[fieldName].ToString()); }
public static int DatabaseIdentifier(this ClarifyDataRow row) { return(Convert.ToInt32(row.UniqueID)); }
protected void ApplyRelations(ClarifyDataRow row) { foreach(RelationProtocol relation in this.Relations) { ReferenceModifierProtocol reference = relation.ReferenceInstance as ReferenceModifierProtocol; if( reference != null ) row.RelateByID( reference.GetRecordObjID(), relation.Name ); else { relation.ReferenceInstance.PreProcess(); row.RelateRecord( relation.ReferenceInstance.ClarifyGeneric.Rows[0], relation.Name ); } } }
private void FillDataTables(DataSet ds, QueryProtocol[] queryItems, ClarifyDataRow parentClarifyRow, DataRow parentRow) { foreach (QueryProtocol queryItem in queryItems) { FillDataTable(ds, queryItem, parentClarifyRow, parentRow); } }
public static DateTime AsDateTime(this ClarifyDataRow row, string fieldName) { return(row[fieldName] == DBNull.Value ? FCGeneric.MIN_DATE : Convert.ToDateTime(row[fieldName].ToString())); }
private void FillDataTable(DataSet ds, QueryProtocol queryItem, ClarifyDataRow parentClarifyRow, DataRow parentRow) { IEnumerator clarifyRowEnumerator; if (parentClarifyRow == null) { clarifyRowEnumerator = queryItem.ClarifyGeneric.Rows.GetEnumerator(); } else { clarifyRowEnumerator = parentClarifyRow.RelatedRows(queryItem.ClarifyGeneric).GetEnumerator(); } while (clarifyRowEnumerator.MoveNext()) { ClarifyDataRow clarifyRow = (ClarifyDataRow) clarifyRowEnumerator.Current; DataRow row = queryItem.ResultDataTable.NewRow(); queryItem.ResultDataTable.Rows.Add(row); for (int t = 0; t < row.Table.Columns.Count; t++) { if (row.Table.Columns[t].ColumnName == "_parentid") row[t] = parentRow["_id"]; else if (row.Table.Columns[t].ColumnName != "_id") row[t] = clarifyRow[row.Table.Columns[t].ColumnName]; } if (queryItem.ChildGenerics != null) FillDataTables(ds, queryItem.ChildGenerics, clarifyRow, row); } }
private void populateDTOWithRelatedDTOs(ClarifyGenericMapEntry parentGenericMap, ClarifyDataRow parentRecord, ModelData parentModel) { var childMapsForChildDtos = parentGenericMap.ChildGenericMaps.Where(child => parentModel.Name != child.Model.ModelName); foreach (var childMap in childMapsForChildDtos) { if (childMap.Model.IsCollection) { var children = new List <ModelData>(); foreach (var childRecord in parentRecord.RelatedRows(childMap.ClarifyGeneric)) { var childModel = new ModelData { Name = childMap.Model.ModelName }; populateDTOForGenericRecord(childMap, childRecord, childModel); if (!childModel.IsEmpty()) { children.Add(childModel); } } parentModel[childMap.Model.ParentProperty] = children; } else if (parentGenericMap.ClarifyGeneric == childMap.ClarifyGeneric) { var childModel = new ModelData { Name = childMap.Model.ModelName }; populateDTOForGenericRecord(childMap, parentRecord, childModel); if (!childModel.IsEmpty()) { parentModel[childMap.Model.ParentProperty] = childModel; } else if (childMap.Model.AllowEmpty) { parentModel[childMap.Model.ParentProperty] = null; } } else { var relatedChildRows = parentRecord.RelatedRows(childMap.ClarifyGeneric); if (relatedChildRows.Any()) { var childRecord = relatedChildRows.First(); var childModel = new ModelData { Name = childMap.Model.ModelName }; populateDTOForGenericRecord(childMap, childRecord, childModel); if (!childModel.IsEmpty()) { parentModel[childMap.Model.ParentProperty] = childModel; } else if (childMap.Model.AllowEmpty) { parentModel[childMap.Model.ParentProperty] = null; } } else { parentModel[childMap.Model.ParentProperty] = null; } } } }
private static void emailLogUpdater(ClarifyDataRow record, HistoryItem historyItem) { var detail = "Send to: {1}{0}".ToFormat(Environment.NewLine, record["recipient"]); var cclist = record["cc_list"].ToString(); if (cclist.IsNotEmpty()) { detail += "CC: {1}{0}".ToFormat(Environment.NewLine, cclist); } detail += record["message"].ToString(); historyItem.Detail = detail; }
private void populateDTOWithRelatedDTOs(ClarifyGenericMapEntry parentGenericMap, ClarifyDataRow parentRecord, object parentDto) { var childMapsForChildDtos = parentGenericMap.ChildGenericMaps.Where(child => parentDto.GetType() != child.Model.ModelType); foreach (var childMap in childMapsForChildDtos) { var parentProperty = new SingleProperty(childMap.Model.ParentProperty); var childModelType = childMap.Model.ModelType; if (typeof(IEnumerable).IsAssignableFrom(parentProperty.PropertyType)) { var propertyDTOs = new ArrayList(); foreach (var childRecord in parentRecord.RelatedRows(childMap.ClarifyGeneric)) { var propertyDTO = Activator.CreateInstance(childModelType); populateDTOForGenericRecord(childMap, childRecord, propertyDTO); propertyDTOs.Add(propertyDTO); } parentProperty.SetValue(parentDto, propertyDTOs.ToArray(childModelType)); } else //dto is not enumerable just get the first child row { var relatedChildRows = parentRecord.RelatedRows(childMap.ClarifyGeneric); if (relatedChildRows.Any()) { var propertyDTO = Activator.CreateInstance(childModelType); var childRecord = relatedChildRows.First(); populateDTOForGenericRecord(childMap, childRecord, propertyDTO); parentProperty.SetValue(parentDto, propertyDTO); } else { parentProperty.SetValue(parentDto, null); } } } }
private static void statusChangeUpdater(ClarifyDataRow record, HistoryItem historyItem) { var notes = record["notes"].ToString(); var notesHeader = (notes.Length > 0) ? Environment.NewLine + "Notes: " : String.Empty; var detail = "{0} {1}{2}{3}".ToFormat(HistoryBuilderTokens.STATUS_CHANGE, historyItem.Detail, notesHeader, notes); historyItem.Detail = detail; }
private void populateSubRootMaps(ModelData dto, IEnumerable <ClarifyGenericMapEntry> childMapsForDtoType, ClarifyDataRow parentRecord) { var childSubRootMaps = childMapsForDtoType.Where(map => map.IsNewRoot()); foreach (var childMap in childSubRootMaps) { var subRootGeneric = childMap.ClarifyGeneric; var rootKeyField = childMap.NewRoot.RootKeyField; var parentKeyField = childMap.NewRoot.ParentKeyField; var childRecord = findRelatedSubRecord(parentRecord, parentKeyField, subRootGeneric, rootKeyField); if (childRecord == null) { continue; } populateDTOForGenericRecord(childMap, childRecord, dto); } }
private void populateDTOWithRelatedGenericRecords(ClarifyGenericMapEntry genericMap, ClarifyDataRow record, ModelData model) { var childMapsForDtoType = genericMap.ChildGenericMaps.Where(child => model.Name == child.Model.ModelName).ToArray(); populateSubRootMaps(model, childMapsForDtoType, record); populateBasedOnRelatedGenerics(model, childMapsForDtoType, record); }
private void populateDTOWithRelatedGenericRecords(ClarifyGenericMapEntry genericMap, ClarifyDataRow record, object dto) { var childMapsForDtoType = genericMap.ChildGenericMaps.Where(child => dto.GetType() == child.Model.ModelType).ToArray(); populateSubRootMaps(dto, childMapsForDtoType, record); populateBasedOnRelatedGenerics(dto, childMapsForDtoType, record); }