public static void InsertActivityEvent(ChatActivityEvent activityEvent) { if (activityEvent != null && string.IsNullOrWhiteSpace(activityEvent._id)) { activityEvent._id = ObjectId.GenerateNewId().ToString(); } var coll = ChatDB.GetCollection <ChatActivityEvent>(Settings.ActivityEventLogCollectionName); coll.InsertOne(activityEvent); }
public void SaveNodeLocations(Dictionary <string, Point> nodeLocations) { if (nodeLocations.Count > 0) { var coll = ChatDB.GetCollection <Dictionary <string, LayoutPoint> >(_connection.LayoutCollectionName); coll.DeleteMany(new BsonDocument()); //Clear All coll.InsertOne(nodeLocations.ToDictionary(x => x.Key, x => new LayoutPoint { X = x.Value.X, Y = x.Value.Y })); } }
public static void InsertActivityEvent(ChatActivityEvent activityEvent) { try { if (activityEvent != null && string.IsNullOrWhiteSpace(activityEvent._id)) { activityEvent._id = ObjectId.GenerateNewId().ToString(); } var coll = ChatDB.GetCollection <ChatActivityEvent>(Settings.ActivityEventLogCollectionName); coll.InsertOne(activityEvent); } catch (Exception ex) { Logger.LogError(new EventId((int)LoggerEventId.MONGO_HELPER_ERROR), ex, "InsertActivityEvent: {0}", ex.Message); } }
public void SaveChatContent() { if (Contents.Count > 0) { var coll = ChatDB.GetCollection <BaseContent>(_connection.ContentCollectionName); coll.DeleteMany(new BsonDocument()); //Clear All coll.InsertMany(Contents); try { if (!Directory.Exists("backup")) { Directory.CreateDirectory("backup"); } File.WriteAllText("backup/nodes-content-" + ObjectId.GenerateNewId().ToString() + ".json", JsonConvert.SerializeObject(Contents, new StringEnumConverter())); } catch { } } }
public static List <ChatNode> RetrieveRecordsFromChatNode() { try { var nodeTemplateCollection = ChatDB.GetCollection <BsonDocument>(Settings.TemplateCollectionName); // Creating Filter for Date Range Greater than Equal to Start Date and Less than End Date FilterDefinitionBuilder <BsonDocument> builder = Builders <BsonDocument> .Filter; var filter = new BsonDocument(); List <BsonDocument> nodeList; // Retrieving records, if no/invalid limit is specified then all records are retrieved otherwise records as per specified limit and offset are retrieved nodeList = nodeTemplateCollection.Find(filter).Project(Builders <BsonDocument> .Projection.Exclude("Sections._t").Exclude("Buttons._t")).ToList(); List <ChatNode> chatNodes = new List <ChatNode>(); foreach (BsonDocument node in nodeList) { try { var chatNode = BsonSerializer.Deserialize <ChatNode>(node); chatNode.Sections = new List <Section>(); chatNode.Buttons = new List <Button>(); //Adding Header Text Content nodeContent = Contents.GetFor(chatNode); BsonArray sectionBsonArray = node.GetValue("Sections").AsBsonArray; foreach (BsonDocument sectionBsonDocument in sectionBsonArray) { Section sectObj = GetSection(sectionBsonDocument); chatNode.Sections.Add(sectObj); } BsonArray buttonBsonArray = node.GetValue("Buttons").AsBsonArray; foreach (BsonDocument buttonBsonDocument in buttonBsonArray) { Button btn = BsonSerializer.Deserialize <Button>(buttonBsonDocument); Content buttonContent = Contents.GetFor(btn); btn.ButtonName = buttonContent?.ButtonName; btn.ButtonText = buttonContent?.ButtonText; chatNode.Buttons.Add(btn); } if (node.Contains("IsStartNode") && node["IsStartNode"] != null && (bool)node["IsStartNode"]) { chatNodes.Insert(0, chatNode); } else { chatNodes.Add(chatNode); } } catch (Exception e) { Debug.WriteLine(e); } } return(chatNodes); } catch (Exception e) { Debug.WriteLine(e.Message + "\n" + e.StackTrace); } return(null); }
public static List <Content> GetContentCollection() => ChatDB.GetCollection <Content>(Settings.ContentCollectionName).Find(new BsonDocument()).ToList();
public static List <ChatNode> RetrieveRecordsFromChatNode() { try { if (!Settings.CacheContent) { RefreshContentInMemory(); } var nodeTemplateCollection = ChatDB.GetCollection <BsonDocument>(Settings.TemplateCollectionName); // Retrieving records, if no/invalid limit is specified then all records are retrieved otherwise records as per specified limit and offset are retrieved var nodeList = nodeTemplateCollection.Find(new BsonDocument()).Project(Builders <BsonDocument> .Projection.Exclude("Sections._t").Exclude("Buttons._t")).ToList(); var chatNodes = new ConcurrentBag <ChatNode>(); Parallel.ForEach(nodeList, node => { try { var chatNode = BsonSerializer.Deserialize <ChatNode>(node); chatNode.Sections = new List <Section>(); chatNode.Buttons = new List <Button>(); BsonArray sectionBsonArray = node.GetValue("Sections").AsBsonArray; foreach (BsonDocument sectionBsonDocument in sectionBsonArray) { Section sectObj = GetSection(sectionBsonDocument); chatNode.Sections.Add(sectObj); } BsonArray buttonBsonArray = node.GetValue("Buttons").AsBsonArray; foreach (BsonDocument buttonBsonDocument in buttonBsonArray) { Button btn = BsonSerializer.Deserialize <Button>(buttonBsonDocument); Content buttonContent = Contents.GetFor(btn); btn.ButtonName = buttonContent?.ButtonName; btn.ButtonText = buttonContent?.ButtonText; chatNode.Buttons.Add(btn); } chatNodes.Add(chatNode); } catch (Exception ex) { Logger.LogError(new EventId((int)LoggerEventId.MONGO_HELPER_ERROR), ex, "RetrieveRecordsFromChatNode Error: {0}", ex.Message); } }); var startNode = chatNodes.FirstOrDefault(x => x.IsStartNode); if (startNode != null) //If start chat node is present, move it up { var result = chatNodes.Where(x => x != startNode).ToList(); result.Insert(0, startNode); return(result); } return(chatNodes.ToList()); } catch (Exception ex) { Logger.LogError(new EventId((int)LoggerEventId.MONGO_HELPER_ERROR), ex, "RetrieveRecordsFromChatNode Error: {0}", ex.Message); } return(null); }