/// <summary> /// Constructor to reconstruct a comment object based on the content of the index. /// </summary> /// <param name="cursor">The cursor from which to retrieve the comment data</param> /// <param name="currentUserId">Current user requesting this comment</param> public Comment(Cursor cursor, string currentUserId) { commentid = cursor.GetColumn("id"); docid = cursor.GetColumn("docid"); message = cursor.GetColumn("message"); userid = cursor.GetColumn("userid"); username = cursor.GetColumn("username"); creation = Sys.ToDat(cursor.GetColumn("creation")); // Dates in the index are UTC dates! modified = Sys.ToDat(cursor.GetColumn("modified")); likes = ListStr.ListFromStr(cursor.GetColumn("likes"), ';'); likedByUser = likes.Contains(currentUserId); replyto = cursor.GetColumn("replyto") ?? ""; deleted = Sys.ToBoo(cursor.GetColumn("deleted")); }
public bool LoadConfig() { string value = Str.Empty; string dataTag = Str.Empty; Sys.Log2(20, "----------------------------------------------------"); Sys.Log2(20, "Load configuration"); Sys.Log2(20, "----------------------------------------------------"); if (_XMLConf == null) { Sys.LogError("Cannot read configuration"); return(false); } //index list dataTag = "CMD_INDEX_LIST"; if (!DatatagExist(dataTag)) { return(false); } listIndexes = CC.Current.Indexes.CleanAliasList(_XMLConf.Value(dataTag, Str.Empty)); if (String.IsNullOrEmpty(listIndexes)) { Sys.LogError("Invalid configuration property: index list is empty"); return(false); } //list columns dataTag = "CMD_SELECT"; if (!DatatagExist(dataTag)) { return(false); } value = _XMLConf.Value(dataTag, "*"); //if only one index and index type is audit => do not resolve column aliases CCIndex idx = CC.Current.Indexes.Get(listIndexes); isAuditIndex = idx != null && (idx.IndexType == CCIndexType.Audit || idx.IndexType == CCIndexType.AuditReplicated) ? true : false; ListStr lcolunmOrColumnAlias = ListStr.ListFromStr(value, ','); foreach (string s in lcolunmOrColumnAlias) { string colunmOrColumnAlias = s.Trim(); if (!isAuditIndex) { dColumnColumnAlias.Add(colunmOrColumnAlias, CC.Current.Global.ResolveColumn(colunmOrColumnAlias)); } else { dColumnColumnAlias.Add(colunmOrColumnAlias, colunmOrColumnAlias); } } //where clause dataTag = "CMD_WHERE"; if (!DatatagExist(dataTag)) { return(false); } whereCluase = _XMLConf.Value(dataTag, ""); whereCluase = IDocHelper.GetValuePattern(_ctxt, whereCluase); //group by dataTag = "CMD_GROUPBY"; if (!DatatagExist(dataTag)) { return(false); } grouBy = _XMLConf.Value(dataTag, ""); //order by dataTag = "CMD_ORDERBY"; if (!DatatagExist(dataTag)) { return(false); } orderBy = _XMLConf.Value(dataTag, ""); //count dataTag = "CMD_COUNT"; if (!DatatagExist(dataTag)) { return(false); } count = _XMLConf.ValueInt(dataTag, -1); //Engine dataTag = "CMD_ENGINE"; if (!DatatagExist(dataTag)) { return(false); } engine = CC.Current.Engines.CleanAlias(_XMLConf.Value(dataTag, "")); //add headers dataTag = "CMD_HEADERS"; if (!DatatagExist(dataTag)) { return(false); } addHeaders = _XMLConf.ValueBoo(dataTag, false); //Field separator dataTag = "CMD_SEPARATOR"; if (!DatatagExist(dataTag)) { return(false); } separator = _XMLConf.ValueChar(dataTag, ','); //override headers dataTag = "CMD_HEADERS_OVERRIDE"; if (!DatatagExist(dataTag)) { return(false); } overrideHeaders = _XMLConf.ValueBoo(dataTag, false); //custom headers dataTag = "CMD_HEADERS_CUSTOM"; if (!DatatagExist(dataTag)) { return(false); } string sCustomHeaders = _XMLConf.Value(dataTag, ""); if (addHeaders && overrideHeaders) //check override header has same number of elements than select statement { lCustomHeaders = ListStr.ListFromStr2(sCustomHeaders, separator); if (lCustomHeaders.Count != dColumnColumnAlias.Count) { Sys.LogError("Override headers does not have the same number of elements as select statement"); return(false); } } //use replace separator dataTag = "CMD_USE_REPLACE"; if (!DatatagExist(dataTag)) { return(false); } useReplaceSeparator = _XMLConf.ValueBoo(dataTag, false); //Replace separator in values dataTag = "CMD_SEPARATOR_REPLACE"; if (!DatatagExist(dataTag)) { return(false); } replaceSeparator = _XMLConf.ValueChar(dataTag, '/'); //Enclose fields in double quote dataTag = "CMD_DBL_QUOTES"; if (!DatatagExist(dataTag)) { return(false); } useDblQuote = _XMLConf.ValueBoo(dataTag, false); //Destination file path dataTag = "CMD_FILE_PATH"; if (!DatatagExist(dataTag)) { return(false); } destinationFilePath = CC.Current.EnvVars.Resolve(_XMLConf.Value(dataTag, "")); destinationFilePath = IDocHelper.GetValuePattern(_ctxt, destinationFilePath); if (Str.IsEmpty(destinationFilePath)) { Sys.LogError("Export file path is empty"); return(false); } //Remove duplicate lines dataTag = "CMD_DEDUPLICATE"; if (!DatatagExist(dataTag)) { return(false); } removeDuplicates = _XMLConf.ValueBoo(dataTag, false); //Remove empty lines dataTag = "CMD_REMOVE_EMPTY_LINES"; if (!DatatagExist(dataTag)) { return(false); } removeEmptyLines = _XMLConf.ValueBoo(dataTag, false); //Enable simulate mode dataTag = "CMD_SIMULATE"; if (!DatatagExist(dataTag)) { return(false); } simulate = _XMLConf.ValueBoo(dataTag, false); //Simulate count dataTag = "CMD_NB_LINE_SIMULATE"; if (!DatatagExist(dataTag)) { return(false); } simulateCount = _XMLConf.ValueInt(dataTag, 1000); //Mapping Grid - do not check if DatatagExist - grid is optionnal dataTag = "CMD_MAPPING"; ListOf <XDoc> mappingGridElts = _XMLConf.EltList("CMD_MAPPING"); for (int i = 0; i < mappingGridElts.Count; i++) { XDoc mappingElt = mappingGridElts.Get(i); string columnOrAliasColumn = mappingElt.Value("Column"); if (String.IsNullOrEmpty(columnOrAliasColumn) || String.IsNullOrWhiteSpace(columnOrAliasColumn)) { Sys.LogError("Column Mapping - Column cannot be empty"); return(false); } string val = mappingElt.Value("Value"); if (String.IsNullOrEmpty(val) || String.IsNullOrWhiteSpace(val)) { Sys.LogError("Column Mapping - Value Pattern cannot be empty for column [" + columnOrAliasColumn + "]"); return(false); } string squery = mappingElt.Value("SelectionQuery"); SelectionQuery selectionQuery = SelectionQuery.FromStr(squery, out string errorMessage); if (!Str.IsEmpty(errorMessage)) { Sys.LogError("Column Mapping - Invalid selection query [" + squery + "] for column [" + columnOrAliasColumn + "] - ", errorMessage); return(false); } if (!dColumnColumnAlias.TryGetValue(columnOrAliasColumn, out string columnName)) { columnName = null; } ColumnMapping columnMapping = new ColumnMapping(columnName, columnOrAliasColumn, val, selectionQuery); lColumnMapping.AddUnique(columnMapping); } Sys.Log2(20, "Load configuration OK"); LogConfig(); return(true); }