Пример #1
0
        /// <summary>
        /// Function: Remove an object
        /// </summary>
        /// <param name="data">object to be removed</param>
        public void RemoveID(string key, bool update = true)
        {
            lock (editLock)
            {
                if (singularity.ContainsKey(key))
                {
                    object data = singularity[key];

                    object oo = null;
                    singularity.TryRemove(key, out oo);
                    string tt = "";
                    singularity_type.TryRemove(key, out tt);
                    singularity_assembly.TryRemove(key, out tt);

                    string ooo    = null;
                    var    invKey = data;
                    singularity_inverse.TryRemove(invKey, out ooo);

                    if (singularity.Count != singularity_inverse.Count)
                    {
                        Console.WriteLine("ERROR");
                    }

                    var res = changes.Where(x => x != null && (x as EntryChange).ID == key).ToList();
                    foreach (var x in res)
                    {
                        changes.Remove(x);
                    }

                    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);

                    if (remove_fdb.Count > 0)
                    {
                        foreach (var func in remove_fdb.Values.ToList())
                        {
                            if (_dic.ContainsKey(func))
                            {
                                try
                                {
                                    (_dic[func] as MCallback)(key, data);
                                }
                                catch {}
                            }
                        }
                    }

                    if (update)
                    {
                        RTDMessage.CRUDMessage crud = new RTDMessage.CRUDMessage()
                        {
                            TopicID = ID, ID = key, Type = RTDMessage.CRUDType.Delete, Class = CRUDClass, Value = data.GetType() == typeof(string) ? data : Newtonsoft.Json.JsonConvert.SerializeObject(data), 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
                        });
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Function: Exchange an object
        /// </summary>
        /// <param name="data">object to be removed</param>
        public void ExchangeID(string key, object dataNew, string type, string assembly, bool update = true)
        {
            lock (editLock)
            {
                if (singularity.ContainsKey(key))
                {
                    object dataOld   = singularity[key];
                    var    invKeyOld = dataOld;

                    object oo = null;
                    singularity.TryRemove(key, out oo);
                    string tt = "";
                    singularity_type.TryRemove(key, out tt);
                    singularity_assembly.TryRemove(key, out tt);
                    string ooo = null;
                    singularity_inverse.TryRemove(invKeyOld, out ooo);

                    if (singularity.Count != singularity_inverse.Count)
                    {
                        Console.WriteLine("ERROR");
                    }

                    var invKeyNew = dataNew;
                    if (!singularity_inverse.ContainsKey(invKeyNew))
                    {
                        singularity.TryAdd(key, dataNew);
                        singularity_type.TryAdd(key, type);
                        singularity_assembly.TryAdd(key, assembly);
                        singularity_inverse.TryAdd(invKeyNew, key);
                    }

                    var res = changes.Where(x => x != null && (x as EntryChange).ID == key).ToList();
                    foreach (var x in res)
                    {
                        changes.Remove(x);
                    }

                    EntryChange changeRemove = new EntryChange()
                    {
                        Command = -1, ID = key, Data = dataOld, MID = ID, Type = dataOld.GetType().ToString(), Assembly = dataOld.GetType().Assembly.GetName().Name
                    };
                    changes.Add(changeRemove);

                    EntryChange changeAdd = new EntryChange()
                    {
                        Command = 1, ID = key, Data = dataNew, MID = ID, Type = type != null ? type : dataNew.GetType().ToString(), Assembly = assembly != null ? assembly : dataNew.GetType().Assembly.GetName().Name
                    };
                    changes.Add(changeAdd);

                    if (exchange_fdb.Count > 0)
                    {
                        foreach (var func in exchange_fdb.Values.ToList())
                        {
                            if (_dic.ContainsKey(func))
                            {
                                try
                                {
                                    (_dic[func] as MCallback)(key, dataNew);
                                }
                                catch {}
                            }
                        }
                    }



                    if (update)
                    {
                        var data_str = "";

                        if (dataNew.GetType().ToString().ToLower() == "system.string" || dataNew.GetType().ToString().ToLower() == "newtonsoft.json.linq.jobject" || (dataNew is string))
                        {
                            string filtered_string = dataNew.ToString().Replace((char)27, '"').Replace((char)26, '\'');
                            if (filtered_string.StartsWith("\"") && filtered_string.EndsWith("\""))
                            {
                                filtered_string = filtered_string.Substring(1, filtered_string.Length - 2);
                            }
                            data_str = filtered_string;
                        }
                        else
                        {
                            data_str = Newtonsoft.Json.JsonConvert.SerializeObject(dataNew);
                        }
                        RTDMessage.CRUDMessage crud = new RTDMessage.CRUDMessage()
                        {
                            TopicID = ID, ID = key, Type = RTDMessage.CRUDType.Update, Class = CRUDClass, Value = data_str, ValueType = type != null ? type : dataNew.GetType() == typeof(System.Dynamic.ExpandoObject) || dataNew.GetType() == typeof(System.Dynamic.DynamicObject) ? typeof(string).ToString() :  dataNew.GetType().ToString(), ValueAssembly = assembly != null ? assembly : dataNew.GetType().Assembly.GetName().Name
                        };
                        RTDEngine.Send(new RTDMessage()
                        {
                            Type = RTDMessage.MessageType.CRUD, Content = crud
                        });
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Function: Remove an object
        /// </summary>
        /// <param name="data">object to be removed</param>
        public void Remove(object data)
        {
            lock (editLock)
            {
                var invKey = data;
                if (singularity_inverse.ContainsKey(invKey))
                {
                    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;
                        }
                    }

                    string key = singularity_inverse[invKey];

                    object oo = null;
                    singularity.TryRemove(key, out oo);
                    string tt = "";
                    singularity_type.TryRemove(key, out tt);
                    singularity_assembly.TryRemove(key, out tt);

                    string ooo = null;
                    singularity_inverse.TryRemove(invKey, out ooo);


                    if (singularity.Count != singularity_inverse.Count)
                    {
                        Console.WriteLine("ERROR");
                    }

                    var res = changes.Where(x => x != null && (x as EntryChange).ID == key).ToList();
                    foreach (var x in res)
                    {
                        changes.Remove(x);
                    }

                    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);

                    RTDMessage.CRUDMessage crud = new RTDMessage.CRUDMessage()
                    {
                        TopicID = ID, ID = key, Type = RTDMessage.CRUDType.Delete, Class = CRUDClass, Value = data.GetType() == typeof(string) ? data : Newtonsoft.Json.JsonConvert.SerializeObject(data), 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 (remove_fdb.Count > 0)
                    {
                        foreach (var func in remove_fdb.Values.ToList())
                        {
                            if (_dic.ContainsKey(func))
                            {
                                try
                                {
                                    (_dic[func] as MCallback)(key, data);
                                }
                                catch {}
                            }
                        }
                    }
                }
            }
        }
Пример #4
0
        /// <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);
                }

                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);
            }
        }
Пример #5
0
        /// <summary>
        /// Function: Exchange an object
        /// </summary>
        /// <param name="data">object to be removed</param>
        public void Exchange(object dataOld, object dataNew)
        {
            lock (editLock)
            {
                var invKeyOld = dataOld;
                if (singularity_inverse.ContainsKey(invKeyOld))
                {
                    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;
                        }
                    }
                    string key = singularity_inverse[invKeyOld];
                    object oo  = null;
                    singularity.TryRemove(key, out oo);
                    string ooo = null;
                    singularity_inverse.TryRemove(invKeyOld, out ooo);

                    if (singularity.Count != singularity_inverse.Count)
                    {
                        Console.WriteLine("ERROR");
                    }

                    var invKeyNew = dataNew;
                    if (!singularity_inverse.ContainsKey(invKeyNew))
                    {
                        singularity.TryAdd(key, dataNew);
                        singularity_inverse.TryAdd(invKeyNew, key);
                    }


                    if (singularity.Count != singularity_inverse.Count)
                    {
                        Console.WriteLine("ERROR");
                    }


                    var res = changes.Where(x => x != null && (x as EntryChange).ID == key).ToList();
                    foreach (var x in res)
                    {
                        changes.Remove(x);
                    }


                    EntryChange changeRemove = new EntryChange()
                    {
                        Command = -1, ID = key, Data = dataOld, MID = ID, Type = dataOld.GetType().ToString(), Assembly = dataOld.GetType().Assembly.GetName().Name
                    };
                    changes.Add(changeRemove);

                    EntryChange changeAdd = new EntryChange()
                    {
                        Command = 1, ID = key, Data = dataNew, MID = ID, Type = dataNew.GetType().ToString(), Assembly = dataNew.GetType().Assembly.GetName().Name
                    };
                    changes.Add(changeAdd);

                    var data_str = "";

                    if (dataNew.GetType().ToString().ToLower() == "system.string" || dataNew.GetType().ToString().ToLower() == "newtonsoft.json.linq.jobject" || (dataNew is string))
                    {
                        string filtered_string = dataNew.ToString().Replace((char)27, '"').Replace((char)26, '\'');
                        if (filtered_string.StartsWith("\"") && filtered_string.EndsWith("\""))
                        {
                            filtered_string = filtered_string.Substring(1, filtered_string.Length - 2);
                        }
                        data_str = filtered_string;
                    }
                    else
                    {
                        data_str = Newtonsoft.Json.JsonConvert.SerializeObject(dataNew);
                    }

                    RTDMessage.CRUDMessage crud = new RTDMessage.CRUDMessage()
                    {
                        TopicID = ID, ID = key, Type = RTDMessage.CRUDType.Update, Class = CRUDClass, Value = data_str, ValueType = dataNew.GetType() == typeof(System.Dynamic.ExpandoObject) || dataNew.GetType() == typeof(System.Dynamic.DynamicObject) ? typeof(string).ToString() :  dataNew.GetType().ToString(), ValueAssembly = dataNew.GetType().Assembly.GetName().Name
                    };
                    RTDEngine.Send(new RTDMessage()
                    {
                        Type = RTDMessage.MessageType.CRUD, Content = crud
                    });

                    if (exchange_fdb.Count > 0)
                    {
                        foreach (var func in exchange_fdb.Values.ToList())
                        {
                            if (_dic.ContainsKey(func))
                            {
                                try
                                {
                                    (_dic[func] as MCallback)(key, dataNew);
                                }
                                catch {}
                            }
                        }
                    }
                }
            }
        }