/// <summary> /// Function: Add an object /// </summary> /// <param name="data">object to be added</param> public string Add(object data) { lock (editLock) { if (data == null) { Console.WriteLine("M not null"); return(null); } if (group == null) { group = Group.FindGroup(ID); } if (group != null && !string.IsNullOrEmpty(QuantApp.Kernel.User.ContextUser.ID) && group.List(QuantApp.Kernel.User.CurrentUser, typeof(QuantApp.Kernel.User), false).Count > 0) { var permission = group.PermissionContext(); if (permission != AccessType.Write) { return(null); } } var invKey = data; if (!singularity_inverse.ContainsKey(invKey)) { string key = System.Guid.NewGuid().ToString(); singularity.TryAdd(key, data); singularity_inverse.TryAdd(invKey, key); if (singularity.Count != singularity_inverse.Count) { Console.WriteLine("ERROR"); } EntryChange change = new EntryChange() { Command = 1, ID = key, Data = data, MID = ID, Type = data.GetType().ToString(), Assembly = data.GetType().Assembly.GetName().Name }; changes.Add(change); var data_str = ""; if ( data.GetType().ToString().ToLower() == "system.string" || data.GetType().ToString().ToLower() == "newtonsoft.json.linq.jobject" || (data is string) ) { string filtered_string = data.ToString().Replace((char)27, '"').Replace((char)26, '\''); if (filtered_string.StartsWith("\"") && filtered_string.EndsWith("\"")) { filtered_string = filtered_string.Substring(1, filtered_string.Length - 2).Replace("\\\"", "\""); } data_str = filtered_string; } else { data_str = Newtonsoft.Json.JsonConvert.SerializeObject(data); } RTDMessage.CRUDMessage crud = new RTDMessage.CRUDMessage() { TopicID = ID, ID = key, Type = RTDMessage.CRUDType.Create, Class = CRUDClass, Value = data_str, ValueType = data.GetType() == typeof(System.Dynamic.ExpandoObject) || data.GetType() == typeof(System.Dynamic.DynamicObject) ? typeof(string).ToString() : data.GetType().ToString(), ValueAssembly = data.GetType().Assembly.GetName().Name }; RTDEngine.Send(new RTDMessage() { Type = RTDMessage.MessageType.CRUD, Content = crud }); if (add_fdb.Count > 0) { foreach (var func in add_fdb.Values.ToList()) { if (_dic.ContainsKey(func)) { try { (_dic[func] as MCallback)(key, data); } catch {} } } } return(key); } if (singularity.Count != singularity_inverse.Count) { Console.WriteLine("ERROR"); } return(null); } }