public string Remove(int id, string diagram_id, int options)
 {
     try
     {
         string          userName    = HttpContext.Current.User.Identity.Name;
         StereotypeBaseE objToRemove = StereotypeBaseE.GetSimpleInstance(id);
         if (objToRemove != null)
         {
             if (!objToRemove.AllowDrop())
             {
                 return("object can not be dropped");
             }
             objToRemove.Drop(userName, options);
             return("object dropped");
         }
         if (id < 0)
         {
             StereotypeBaseE.DropRelation(id, userName);
             return("relation dropped");
         }
         if (diagram_id != null)
         {
             StereotypeBaseE.DropDiagram(diagram_id, userName);
             return("diagram dropped");
         }
         return("");
     }
     catch
     {
         return("");
     }
 }
        public string DnD(string src, string dst, int options)
        {
            //try
            //{
            //    DersaSqlManager DM = new DersaSqlManager();
            //    string userName = HttpContext.Current.User.Identity.Name;
            //    DataTable T = DM.ExecuteSPWithParams("ENTITY$OnDnD", new object[] { src, dst, options, userName, Util.GetPassword(userName) });
            //    string result = JsonConvert.SerializeObject(T);
            //    return result;
            //}
            //catch
            //{
            //    return "";
            //}
            string userName = HttpContext.Current.User.Identity.Name;

            if (src.Contains("D_"))//диагграммы
            {
                return(Util.EntityAddChild(HttpContext.Current.User.Identity.Name, src, dst, options));
            }
            StereotypeBaseE objFrom = null;
            int             intSrc  = -1;

            try
            {
                intSrc  = int.Parse(src);
                objFrom = StereotypeBaseE.GetSimpleInstance(intSrc);
            }
            catch { }
            StereotypeBaseE objTo  = null;
            int             intDst = -1;

            try
            {
                intDst = int.Parse(dst);
                objTo  = StereotypeBaseE.GetSimpleInstance(intDst);
            }
            catch { }
            if (objFrom != null && objTo != null) //copy or move node
            {
                if ((options & 3) == 0)           //move
                {
                    if (objFrom.Parent == null || !(objFrom.Parent as StereotypeBaseE).AllowModifyChildren())
                    {
                        return("");
                    }
                    return(objTo.MoveChild(userName, src));
                }
                else
                {
                    return(objTo.CopyChild(userName, src, options));
                }
            }
            else if (objTo != null) //child from stereotype
            {
                return(objTo.CopyChild(userName, src, options));
            }

            return("");
        }
        public string Rename(string id, string name)
        {
            int intId = -1;

            try
            {
                intId = int.Parse(id);
            }
            catch { }
            if (intId < 0)//диаграммы и проч.
            {
                try
                {
                    DersaSqlManager DM       = new DersaSqlManager();
                    string          userName = HttpContext.Current.User.Identity.Name;
                    string          result   = JsonConvert.SerializeObject(DM.ExecuteSPWithParams("ENTITY$Rename", new object[] { id, name, userName, Util.GetPassword(userName) }));
                    return(result);
                }
                catch
                {
                    return("");
                }
            }
            //для нормальных объектов используем объектные методы
            try
            {
                string          userName    = HttpContext.Current.User.Identity.Name;
                StereotypeBaseE objToRename = StereotypeBaseE.GetSimpleInstance(intId);
                if (objToRename != null)
                {
                    return(objToRename.Rename(userName, name));
                }
                return("");
            }
            catch
            {
                return("");
            }
            //try
            //{
            //    DersaSqlManager DM = new DersaSqlManager();
            //    string userName = HttpContext.Current.User.Identity.Name;
            //    string result = JsonConvert.SerializeObject(DM.ExecuteSPWithParams("ENTITY$Rename", new object[] { id, name, userName, Util.GetPassword(userName) }));
            //    return result;
            //}
            //catch
            //{
            //    return "";
            //}
        }
        public static void SetImagePath(int id, string fileName)
        {
            string          userName = HttpContext.Current.User.Identity.Name;
            string          path     = "/user_resources/" + userName + "/" + fileName;
            StereotypeBaseE target   = StereotypeBaseE.GetSimpleInstance(id);

            CachedObjects.CachedEntities[id] = null;
            DersaSqlManager M = new DersaSqlManager();

            System.Data.DataTable t = M.GetEntity(id.ToString());
            if (t == null)
            {
                throw new Exception(string.Format("Table is null for entity {0}", id));
            }
            if (t.Rows.Count < 1)
            {
                throw new Exception(string.Format("Table is empty for entity {0}", id));
            }
            Entity ent = new Entity(t, M);

            CachedObjects.CachedCompiledInstances[ent.StereotypeName + id.ToString()] = null;
            foreach (Entity child in ent.Children)
            {
                CachedObjects.CachedCompiledInstances[child.StereotypeName + child.Id.ToString()] = null;
            }

            ICompiled  cInst = ent.GetCompiledInstance();
            MethodInfo mi    = cInst.GetType().GetMethod("SetPath");

            if (mi == null)
            {
                string excMessage = "Method SetPath not found ";
                Logger.LogStatic(excMessage);
                throw new Exception(excMessage);
            }
            object[] callParams = new object[2];
            callParams[0] = userName;
            callParams[1] = path;
            mi.Invoke(cInst, callParams);
        }
        public string GetAction(string MethodName, int id, string paramString = null)
        {//AllowExecuteJSMethod
            string          userName = HttpContext.Current.User.Identity.Name;
            StereotypeBaseE target   = StereotypeBaseE.GetSimpleInstance(id);

            if (!target.AllowExecuteMethod(userName, MethodName))
            {
                return(string.Format("You are not allowed to execute method {0}", MethodName));
            }
            CachedObjects.CachedEntities[id] = null;
            DersaSqlManager M = new DersaSqlManager();

            System.Data.DataTable t = M.GetEntity(id.ToString());
            if (t == null)
            {
                throw new Exception(string.Format("Table is null for entity {0}", id));
            }
            if (t.Rows.Count < 1)
            {
                throw new Exception(string.Format("Table is empty for entity {0}", id));
            }
            Entity ent = new Entity(t, M);

            CachedObjects.CachedCompiledInstances[ent.StereotypeName + id.ToString()] = null;
            foreach (Entity child in ent.Children)
            {
                CachedObjects.CachedCompiledInstances[child.StereotypeName + child.Id.ToString()] = null;
            }

            ICompiled  cInst = ent.GetCompiledInstance();
            MethodInfo mi    = cInst.GetType().GetMethod(MethodName);

            if (mi == null)
            {
                string excMessage = "Method " + MethodName + " not found ";
                Logger.LogStatic(excMessage);
                throw new Exception(excMessage);
            }
            object[] externalParams = new object[0];
            if (paramString != null)
            {
                externalParams = JsonConvert.DeserializeObject <object[]>(paramString);
            }
            object[] callParams = new object[externalParams.Length + 1];
            callParams[0] = userName;
            for (int i = 0; i < externalParams.Length; i++)
            {
                callParams[i + 1] = externalParams[i];
            }
            //Logger.LogStatic(string.Format("method {0}, params count {1}", MethodName, callParams.Length));
            object result = mi.Invoke(cInst, new object[] { callParams });

            if (result == null)
            {
                return(null);
            }
            if (result is string)
            {
                return(result.ToString());
            }
            return(JsonConvert.SerializeObject(result));
        }