/// <summary> /// Return query for determining which documents are SQLd. /// </summary> /// <param name="schemaCollection"></param> /// <returns></returns> private IMongoQuery GetSQLCollectionConditions(DataTree schemaCollection) { var andQueries = new List <IMongoQuery>(); andQueries.Add(GetSQLCollectionConditionQuery(schemaCollection)); // Get caching limits const int DefaultSQLDays = 240; // Get SQL limits as UTC timestamp var now = DateTime.Now; var dateNowUtc = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0, DateTimeKind.Utc); // Get SQL limits. Use given values if any are specified, if nothing is specified, default to using // modified timestamp and 240 days. if (schemaCollection.Contains("SQLagedayscreated")) { int SQLAgeDaysCreated = (int)schemaCollection["SQLagedayscreated"].GetValueOrDefault(DefaultSQLDays); DateTime SQLDateCreated = dateNowUtc.AddDays(-SQLAgeDaysCreated); andQueries.Add(Query.LT("created", SQLDateCreated)); } if (schemaCollection.Contains("SQLagedaysmodified") || !schemaCollection.Contains("SQLagedayscreated")) { int SQLAgeDaysModified = (int)schemaCollection["SQLagedaysmodified"].GetValueOrDefault(DefaultSQLDays); DateTime SQLDateModified = dateNowUtc.AddDays(-SQLAgeDaysModified); andQueries.Add(Query.LT("modified", SQLDateModified)); } return(Query.And(andQueries.ToArray())); }
private string GetCsvValue(DataTree schema, DataTree dataTreeDoc, string csvField) { string csvValue = (string)dataTreeDoc[csvField]; try { if (dataTreeDoc.Contains("__" + csvField + "__displayname")) { csvValue = dataTreeDoc["__" + csvField + "__displayname"]; } else if ((string)schema["type"] == "datetime") { csvValue = this.formatDate((DateTime)dataTreeDoc[csvField]); } else if ((string)schema["type"] == "int" && schema["inttype"] == "timespan") { csvValue = formatTimespan((int)dataTreeDoc[csvField]); } } catch (Exception e) { logger.LogError("Failed to export csv value", e, csvField, dataTreeDoc.ContentView()); } return(csvValue); }
/// <summary> /// Update relevent parts of bson document to data tree entry. /// </summary> /// <param name="bsonDocument"></param> /// <param name="dataTreeDocument"></param> private void ApplyAuditTrailDocumentToReportDocument(BsonDocument bsonDocument, DataTree dataTreeDocument, string documenType) { foreach (string valueName in supportedDocumentValues[documenType]) { if (bsonDocument.Contains(valueName)) { dataTreeDocument[valueName] = BsonValueToMC2Value(bsonDocument[valueName]); } } if (dataTreeDocument.Contains("user")) { BsonDocument user = GetFromCache(dataTreeDocument["user"], "user", database); dataTreeDocument["user"]["__displayname"] = $"{(string)user.GetValue("firstname", "")} {(string)user.GetValue("lastname", "")}"; dataTreeDocument["user"]["_id"] = (string)dataTreeDocument["user"].Value; } if (dataTreeDocument.Contains("__user")) { BsonDocument user = GetFromCache(dataTreeDocument["__user"], "user", database); dataTreeDocument["__user"]["__displayname"] = $"{(string)user.GetValue("firstname", "")} {(string)user.GetValue("lastname", "")}"; dataTreeDocument["__user"]["_id"] = (string)dataTreeDocument["__user"].Value; } if (dataTreeDocument.Contains("timesheetentrydetailpaytype")) { BsonDocument payType = GetFromCache(dataTreeDocument["timesheetentrydetailpaytype"], "timesheetentrydetailpaytype", database); dataTreeDocument["paytype"]["__displayname"] = (string)payType.GetValue("name", ""); } if (dataTreeDocument.Contains("dayentrytype")) { BsonDocument payType = GetFromCache(dataTreeDocument["dayentrytype"], "dayentrytype", database); dataTreeDocument["paytype"]["__displayname"] = (string)payType.GetValue("name", ""); } if (dataTreeDocument.Contains("article")) { BsonDocument payType = GetFromCache(dataTreeDocument["article"], "article", database); dataTreeDocument["article"]["__displayname"] = (string)payType.GetValue("name", ""); } if (bsonDocument["__type"] == "Delete") { dataTreeDocument["__deleted"] = true; } }
private void BuildSipmlifiedAuditTrail(string documentType, List <BsonDocument> auditDocuments) { string id = auditDocuments[0]["__originalid"].ToString(); DataTree reportDocument = report[documentType][id]; DataTree currentDocument = new DataTree(); foreach (BsonDocument auditDocument in auditDocuments) { ApplyAuditTrailDocumentToReportDocument(auditDocument, currentDocument, documentType); // We assume all changes after manager approval are done by payroll. This is asimplification // and may create confusing results if approval states are switched on and off. if (!reportDocument["manager"].Empty) { reportDocument["payroll"] = (DataTree)currentDocument.Clone(); } else if ((bool)auditDocument.GetValue("approvedbymanager", false)) { reportDocument["manager"] = (DataTree)currentDocument.Clone(); } else if ((bool)auditDocument.GetValue("approvedbyworker", false)) { reportDocument["worker"] = (DataTree)currentDocument.Clone(); } } // Unapproved entries that haven't been deletd are shown. if (!reportDocument.Contains("worker") && !(bool)currentDocument["__deleted"]) { reportDocument["worker"] = (DataTree)currentDocument.Clone(); } // Deleted by manager if (!reportDocument.Contains("manager") && !(bool)reportDocument["worker"]["__deleted"] && (bool)currentDocument["__deleted"]) { reportDocument["manager"] = (DataTree)currentDocument.Clone(); } // Deleted by payroll if (!reportDocument.Contains("payroll") && !(bool)reportDocument["manager"]["__deleted"] && (bool)currentDocument["__deleted"]) { reportDocument["payroll"] = (DataTree)currentDocument.Clone(); } }
private void CacheIndividualEntry(DataTree userTree, DataTree entry) { // Get date primarily from date filed and secondarily from starttimestamp DateTime date; if (entry.Contains("date")) { date = ((DateTime)entry["date"]).Date; } else if (entry.Contains("starttimestamp")) { date = ((DateTime)entry["starttimestamp"]).Date; } else { logger.LogError("Data to be cached didn't contain date or timestamp.", "User: "******"Entry: " + entry); return; } }
/// <summary> /// Defaults to current time and day or day given in selecteddatekey parameter /// </summary> /// <param name="itemSchema"></param> /// <param name="value"></param> /// <returns></returns> public MC2Value duration(DataTree itemSchema) { TimeSpan defaultDuration = new TimeSpan(); if (itemSchema.Contains("defaultdurationminutes")) { defaultDuration = new TimeSpan(0, (int)itemSchema["defaultdurationminutes"], 0); } return((MC2Value)defaultDuration.TotalMilliseconds); }
private DateTime ApplyTimeAccuracy(DateTime date, DataTree itemSchema) { if (itemSchema.Contains("timeaccuracy")) { int timeAccuracy = (int)itemSchema["timeaccuracy"]; date = new DateTime( date.Year, date.Month, date.Day, date.Hour, (int)((decimal)date.Minute / (decimal)timeAccuracy) * timeAccuracy, 0, DateTimeKind.Utc); } return(date); }
private string VerifyUser(DBDocument document, DataTree userTotals) { string userId = document["user"]; if (string.IsNullOrEmpty(userId)) { return(null); } if (!userTotals.Contains(userId)) { userTotals[userId]["__displayname"] = document["user"]["__displayname"]; } return(userId); }
public MC2Value defaultassets( string collection, string valuename, string relationtarget, string itemid, string filtercontroller, string filterblock) { string projectId = Runtime.HistoryManager.GetCurrentHistoryEntryState()["__form_project"]["formvalue"]; if (string.IsNullOrEmpty(projectId)) { // Use default project if nothing else is provided projectId = ((DataTree)this.trocurrentproject(null))[DBQuery.Id]; } if (string.IsNullOrEmpty(projectId)) { logger.LogDebug("No project when looking for default assets."); return(null); } var query = new DBQuery("tro", "assetentry_defaultassets"); query.AddParameter("projectid", new ObjectId(projectId)); var task = query.FindAsync(); DBCollection projects = task.Result["project"]; DataTree root = new DataTree(); DataTree assets = root["asset"]; foreach (DataTree project in projects) { foreach (DataTree allocationEntry in project["allocationentry"]) { if (allocationEntry["asset"].Count > 0 && !assets.Contains(allocationEntry["asset"][DBQuery.Id])) { assets[allocationEntry["asset"][DBQuery.Id]] = allocationEntry["asset"]; } } } return(assets); }
private bool FilterDocumentByDate(DataTree reportDocument) { if (!reportDocument.Contains("date")) { return(false); } DateTime date = (DateTime)reportDocument["date"]; if (start.HasValue && date < start) { return(false); } if (end.HasValue && date > end) { return(false); } return(true); }
public MC2Value getdisplaynameforelation(DataTree element, DataTree itemschema, string relationname) { if (element.Contains("__displayname")) { return(element["__displayname"]); } bool isFirst = true; string ret = string.Empty; // Get the relation DataTree relationSchema = itemschema.Parent.Parent[relationname]; DataTree relationElement = element; if (relationElement.Count == 0) { return(string.Empty); } foreach (DataTree schemaItem in relationSchema) { if ((bool)schemaItem["namefield"]) { if (isFirst) { isFirst = false; } else if (!ret.EndsWith(" ")) { ret += " "; } ret += (string)relationElement[schemaItem.Name]; } } return(ret.Trim()); }
private dynamic GetExcelValue(DataTree schema, DataTree dataTreeDoc, string field) { dynamic excelValue = ""; try { if (dataTreeDoc.Contains("__" + field + "__displayname")) { excelValue = dataTreeDoc["__" + field + "__displayname"]; } else if ((string)schema["type"] == "datetime") { excelValue = this.formatDate((DateTime)dataTreeDoc[field]); } else if ((string)schema["type"] == "int" && schema["inttype"] == "timespan") { int timespan = (int)dataTreeDoc[field]; int hours = timespan / (1000 * 60 * 60); excelValue = hours; } else if ((string)schema["type"] == "int") { excelValue = (int)dataTreeDoc[field]; } else { excelValue = (string)dataTreeDoc[field]; } } catch (Exception e) { logger.LogError("Failed to export csv value", e, field, dataTreeDoc.ContentView()); } return(excelValue); }
public MC2Value contains(DataTree datatree, string name) { return(datatree.Contains(name)); }