Exemple #1
0
        public static string GetAttributeValue(string userName, int entityId, string attrName, int attrType)
        {
            DersaSqlManager DM = new DersaSqlManager();

            System.Data.DataTable T = DM.ExecuteSPWithParams("ENTITY$GetAttribute", new object[] { entityId, attrName, userName, Util.GetPassword(userName) });
            if (T == null || T.Rows.Count < 1)
            {
                return(null);
            }
            if (attrType <= 0)
            {
                attrType = (int)T.Rows[0]["Type"];
            }
            string result = T.Rows[0]["Value"].ToString();

            if (attrType == 5)
            {
                try
                {
                    result = Cryptor.Decrypt(result, userName);
                }
                catch { }
            }
            return(result);
        }
Exemple #2
0
        public static string SetAttributeValue(DersaSqlManager DM, string userName, AttributeOwnerType ownerType, string entityId, string attrName, int attrType, string attrValue)
        {
            string procName = "";

            switch (ownerType)
            {
            case AttributeOwnerType.Entity:
                procName = "ENTITY$SetAttribute";
                break;

            case AttributeOwnerType.Relation:
                procName = "RELATION$SetAttribute";
                break;
            }
            IParameterCollection Params = new ParameterCollection();

            Params.Add("@entity", entityId);
            Params.Add("@attr_name", attrName);
            Params.Add("@attr_value", attrValue);
            Params.Add("@login", userName);
            Params.Add("@password", Util.GetPassword(userName));
            Params.Add("@attr_type", attrType);
            int res = DM.ExecuteSPWithResult(procName, false, Params);

            if (res == 5)
            {
                Params["@attr_type"].Value  = 5;
                Params["@attr_value"].Value = Cryptor.Encrypt(attrValue, userName);
                res = DM.ExecuteSPWithResult(procName, false, Params);
            }
            return("");
        }
Exemple #3
0
        public static int GetUserPermissions(string userName)
        {
            DersaSqlManager      M          = new DersaSqlManager();
            IParameterCollection UserParams = new ParameterCollection();

            UserParams.Add("@login", userName);
            UserParams.Add("@password", Util.GetPassword(userName));
            return(M.ExecuteSPWithResult("DERSA_USER$GetPermissions", false, UserParams));
        }
 public void Reinitialize()
 {
     Dersa.Common.DersaSqlManager M = new Dersa.Common.DersaSqlManager();
     System.Data.DataTable        T = M.GetEntity(this.Id.ToString());
     this._object     = new Dersa.Common.Entity(T, M);
     this._parent     = null;
     this._aRelations = null;
     this._bRelations = null;
     this._children   = null;
     ClearCache();
 }
Exemple #5
0
 public static void EntitySetStereotype(string userName, int entity, string stereotype_name)
 {
     try
     {
         DersaSqlManager DM = new DersaSqlManager();
         DM.ExecuteSPWithParams("ENTITY$SetStereotype", new object[] { entity, stereotype_name, userName, Util.GetPassword(userName) });
     }
     catch
     {
     }
 }
Exemple #6
0
 public static string SetGuid(string userName, string entityId, string guid)
 {
     try
     {
         DersaSqlManager DM = new DersaSqlManager();
         DM.ExecuteSPWithParams("ENTITY$SetGuid", new object[] { entityId, guid, Util.GetPassword(userName) });
         return("");
     }
     catch (Exception exc)
     {
         return(exc.Message);
     }
 }
Exemple #7
0
 public static string EntityAddChild(string userName, string src, string dst, int options)
 {
     try
     {
         DersaSqlManager DM     = new DersaSqlManager();
         DataTable       T      = DM.ExecuteSPWithParams("ENTITY$OnDnD", new object[] { src, dst, options, userName, GetPassword(userName) });
         string          result = JsonConvert.SerializeObject(T);
         return(result);
     }
     catch
     {
         return("");
     }
 }
Exemple #8
0
        public static string GetUserSetting(string userName, string settingName)
        {
            DersaSqlManager      DM         = new DersaSqlManager();
            IParameterCollection UserParams = new ParameterCollection();

            UserParams.Add("@login", userName);
            UserParams.Add("@password", Util.GetPassword(userName));
            UserParams.Add("@user_setting_name", settingName);
            System.Data.DataTable VT = DM.ExecuteSPWithParams("DERSA_USER$GetUserSetting", UserParams);
            if (VT == null || VT.Rows.Count < 1)
            {
                throw new Exception(string.Format("Не задано значение для параметра {0}", settingName));
            }
            return(VT.Rows[0][0].ToString());
        }
Exemple #9
0
 public static string EntityAddRelation(string userName, int entity, int entity_b, string stereotype_name, string relation_name, string source_class, int source_ref)
 {
     try
     {
         DersaSqlManager       DM = new DersaSqlManager();
         System.Data.DataTable T  = DM.ExecuteSPWithParams("ENTITY$AddRelation", new object[] { entity, entity_b, stereotype_name, relation_name, source_class, source_ref, userName, Util.GetPassword(userName) });
         if (T.Rows.Count > 0)
         {
             return(T.Rows[0][0].ToString());
         }
         return("");
     }
     catch
     {
         return("");
     }
 }
Exemple #10
0
 public static string EntitySetAttribute(string userName, int entity, string prop_name, string prop_value)
 {
     try
     {
         DersaSqlManager       DM = new DersaSqlManager();
         System.Data.DataTable T  = DM.ExecuteSPWithParams("ENTITY$SetAttribute", new object[] { entity, prop_name, prop_value, userName, Util.GetPassword(userName) });
         if (T.Rows.Count > 0)
         {
             return(T.Rows[0][0].ToString());
         }
         return("");
     }
     catch
     {
         return("");
     }
 }
Exemple #11
0
 public Relation(System.Data.DataRow r, Entity _AEntity, Entity _BEntity, DersaSqlManager M)
     : this(ObjectClass.GetObjectClass(r), M)
 {
     if (r != null)
     {
         string a_id = r["a"].ToString();
         string b_id = r["b"].ToString();
         // = new SqlManager();
         if (_AEntity != null)
         {
             this.A = _AEntity;
         }
         else
         {
             if (a_id != "")
             {
                 this.A = new Entity(M.GetEntity(a_id), null, M, AddChildrenMode.Never, false);
             }
         }
         if (_BEntity != null)
         {
             this.B = _BEntity;
         }
         else
         {
             if (b_id != "")
             {
                 //throw new Exception(b_id);
                 if (CachedObjects.CachedEntities[r["b"]] != null)
                 {
                     this.B = (Entity)CachedObjects.CachedEntities[r["b"]];
                 }
                 else
                 {
                     this.B = new Entity(M.GetEntity(b_id), null, M, AddChildrenMode.Always, a_id != b_id);
                 }
             }
         }
         string StereotypeID = r["stereotype"].ToString();
         if (StereotypeID != "")
         {
             this.Stereotype = M.GetStereotype(StereotypeID);
         }
         this.Id = (int)r["relation"];
     }
 }
Exemple #12
0
 public Relation(ObjectClass objectClass, DersaSqlManager sm) : base(objectClass, sm)
 {
 }
Exemple #13
0
        public static ICompiled CreateInstance(IStereotypedObject obj, DersaSqlManager M)
        {
            if (obj == null)
            {
                throw new Exception("obj == null");
            }
            if (CachedObjects.CachedCompiledInstances[obj.Stereotype.Name + obj.Id.ToString()] != null)
            {
                return((ICompiled)CachedObjects.CachedCompiledInstances[obj.Stereotype.Name + obj.Id.ToString()]);
            }
            if (obj.Stereotype == null)
            {
                throw new Exception("obj.Stereotype == null, obj.name = " + obj.Name);
            }
            Type      nType = GetDynamicType("DersaStereotypes." + obj.Stereotype.Name);
            ICompiled res   = (ICompiled)Activator.CreateInstance(nType, new object[] { obj });

            System.Data.DataTable t = null;
            if (res is ICompiledRelation)
            {
                t = M.GetAttributesForRelation(obj.Id.ToString());
            }
            else if (res is ICompiledEntity)
            {
                t = M.GetAttributesForEntity(obj.Id.ToString());
            }
            if (t == null)
            {
                throw new Exception("Не смогли определиться между E и R");
            }
            foreach (System.Data.DataRow r in t.Rows)
            {
                //res[r["name"].ToString()] = r["value"].ToString();
                System.Reflection.FieldInfo[] fis = nType.GetFields();
                foreach (System.Reflection.FieldInfo fi in fis)
                {
                    if (fi.Name == r["name"].ToString())
                    {
                        object value_type = r["value_type"];
                        object value      = null;
                        if (value_type == null || value_type.ToString() == "1")
                        {
                            value = r["value"];
                        }
                        else
                        {
                            value = r["text_value"];
                        }
                        if (value == null || value is System.DBNull)
                        {
                            value = "";
                        }
                        if (value != null)
                        {
                            object ConvertedValue = DIOS.Common.TypeUtil.Convert(value, fi.FieldType);
                            fi.SetValue(res, ConvertedValue);
                        }
                    }
                }
            }
            CachedObjects.CachedCompiledInstances[obj.Stereotype.Name + obj.Id.ToString()] = res;
            return(res);

            /*
             * if (obj.Stereotype.Name == "Attribute")
             * {
             *  Type nType = Type.GetType("DersaStereotypes." + obj.Stereotype.Name);
             *  //Type type = typeof(DersaStereotypes.Attribute);
             *  SqlManager M = new SqlManager();
             *  DersaStereotypes.Attribute res = new DersaStereotypes.Attribute((IEntity)obj);
             *  System.Data.DataTable t = M.GetAttributesForEntity(obj.Id.ToString());
             *  foreach (System.Data.DataRow r in t.Rows)
             *  {
             *      //res[r["name"].ToString()] = r["value"].ToString();
             *      System.Reflection.FieldInfo[] fis = type.GetFields();
             *      foreach (System.Reflection.FieldInfo fi in fis)
             *      {
             *          if (fi.Name == r["name"].ToString())
             *          {
             *              object value = r["value"];
             *              if (value != null)
             *              {
             *                  object ConvertedValue = Dersa.Common.Util.Convert(value, fi.FieldType);
             *                  fi.SetValue(res, ConvertedValue);
             *              }
             *          }
             *      }
             *  }
             *  return res;
             * }
             * if (obj.Stereotype.Name == "Entity")
             * {
             *  Type type = typeof(DersaStereotypes.Entity);
             *  SqlManager M = new SqlManager();
             *  DersaStereotypes.Entity res = new DersaStereotypes.Entity((IEntity)obj);
             *  System.Data.DataTable t = M.GetAttributesForEntity(obj.Id.ToString());
             *  foreach (System.Data.DataRow r in t.Rows)
             *  {
             *      //res[r["name"].ToString()] = r["value"].ToString();
             *      System.Reflection.FieldInfo[] fis = type.GetFields();
             *      foreach (System.Reflection.FieldInfo fi in fis)
             *      {
             *          if (fi.Name == r["name"].ToString())
             *          {
             *              object value = r["value"];
             *              if (value != null)
             *              {
             *                  object ConvertedValue = Dersa.Common.Util.Convert(value, fi.FieldType);
             *                  fi.SetValue(res, ConvertedValue);
             *              }
             *          }
             *      }
             *  }
             *  return res;
             * }*/
            return(null);

            //////////////////////////////////////////////////////////////////////
            //if (_stereotypesAssembly == null)
            //    throw new NullReferenceException("Библиотека стереотипов не скомпилирована");
            //Type type = _stereotypesAssembly.GetType("DersaStereotypes." + obj.Stereotype.Name);
            //ICompiled cs = (ICompiled)Activator.CreateInstance(type, new object[] { obj });
            //System.Reflection.FieldInfo[] fis = type.GetFields();
            //try
            //{
            //    foreach (System.Reflection.FieldInfo fi in fis)
            //    {
            //        object value = obj.GetAttribute(fi.Name).GetValue();
            //        if (value != null)
            //        {
            //            fi.SetValue(cs, value);
            //        }
            //    }
            //    return cs;
            //}
            //catch (Exception ex)
            //{
            //    throw new Exception("Ошибка создания экземпляра объекта " + obj.Stereotype.Name + " : " + obj.Name + " : " + obj.Id + "\n" + ex.Message, ex);
            //}
        }
Exemple #14
0
 public Entity(ObjectClass objectClass, DersaSqlManager sm) : base(objectClass, sm)
 {
 }
Exemple #15
0
        public Entity(System.Data.DataTable t, Entity _Parent, DersaSqlManager M, AddChildrenMode AddChildren, bool AddRelations)
            : this(ObjectClass.GetObjectClass(t), M)
        {
            if (t != null && t.Rows.Count > 0)
            {
                // = new DersaSqlManager();
                System.Data.DataRow r = t.Rows[0];
                if (_Parent != null)
                {
                    this.Parent = _Parent;
                }
                else
                {
                    string ParentID = r["parent"].ToString();
                    if (ParentID != "")
                    {
                        if (CachedObjects.CachedEntities[r["parent"]] != null)
                        {
                            this.Parent = (Entity)CachedObjects.CachedEntities[r["parent"]];
                        }
                        else
                        {
                            this.Parent = new Entity(M.GetEntity(ParentID), null, M, AddChildrenMode.NotPackage, false);
                        }
                    }
                }
                string StereotypeID = r["stereotype"].ToString();
                if (StereotypeID != "")
                {
                    this.Stereotype = M.GetStereotype(StereotypeID);
                }
                this.Id = (int)r["entity"];

                if (AddChildren == AddChildrenMode.Always || (AddChildren == AddChildrenMode.NotPackage && this.Stereotype.Name != "Package"))
                {
                    if (this._children == null)
                    {
                        this._children = new EntityChildrenCollection();
                    }
                    if (this._children.Count < 1)
                    {
                        System.Data.DataTable ChildrenTable = M.GetEntityChildren(this.Id.ToString());
                        if (ChildrenTable.Rows.Count > 0)
                        {
                            foreach (System.Data.DataRow cr in ChildrenTable.Rows)
                            {
                                this._children.Add(new Entity(M.GetEntity(cr["entity"].ToString()), this, M, AddChildrenMode.NotPackage, false));
                            }
                        }
                    }
                }
                if (AddRelations)
                {
                    if (this._aRelations == null)
                    {
                        this._aRelations = new ChildrenCollection();
                    }
                    if (this._aRelations.Count < 1)
                    {
                        System.Data.DataTable ARelationsTable = M.GetEntityARelations(this.Id.ToString());
                        if (ARelationsTable.Rows.Count > 0)
                        {
                            foreach (System.Data.DataRow cr in ARelationsTable.Rows)
                            {
                                this._aRelations.Add(new Relation(cr, this, null, M));
                            }
                        }
                    }
                    if (this._bRelations == null)
                    {
                        this._bRelations = new ChildrenCollection();
                    }
                    if (this._bRelations.Count < 1)
                    {
                        System.Data.DataTable BRelationsTable = M.GetEntityBRelations(this.Id.ToString());
                        if (BRelationsTable.Rows.Count > 0)
                        {
                            foreach (System.Data.DataRow cr in BRelationsTable.Rows)
                            {
                                this._bRelations.Add(new Relation(cr, null, this, M));
                            }
                        }
                    }
                }
            }
            CachedObjects.CachedEntities[this.Id] = this;
        }
Exemple #16
0
 public Entity(System.Data.DataTable t, DersaSqlManager sm)
     : this(t, null, sm, AddChildrenMode.Always, true)
 {
 }
 public StereotypedObject(ObjectClass objectClass, DersaSqlManager sm) : base(objectClass)
 {
     _SM = sm;
 }
Exemple #18
0
        public static List <ICompiledEntity> Range(string[] ids_str, DersaSqlManager M)
        {
            List <ICompiledEntity> entities = new List <ICompiledEntity>();

            ICompiledEntity[] eArr = new ICompiledEntity[ids_str.Length];
            for (int i = 0; i < ids_str.Length; i++)
            {
                int entId = int.Parse(ids_str[i]);
                CachedObjects.CachedEntities[entId] = null;
                System.Data.DataTable t = M.GetEntity(ids_str[i]);
                if (t == null)
                {
                    throw new Exception(string.Format("Table is null for entity {0}", ids_str[i]));
                }
                if (t.Rows.Count < 1)
                {
                    throw new Exception(string.Format("Table is empty for entity {0}", ids_str[i]));
                }
                Entity ent = new Entity(t, M);
                CachedObjects.CachedCompiledInstances[ent.Stereotype.Name + ids_str[i]] = null;
                ICompiledEntity cInst = (ICompiledEntity)ent.GetCompiledInstance();
                eArr[i] = cInst;
                entities.Add(cInst);
            }
            Type sUtilType = Util.GetDynamicType("DersaStereotypes.StereotypeUtil"); //typeof(DersaStereotypes.StereotypeUtil);

            if (sUtilType == null)
            {
                throw new Exception("Class StereotypeUtil not found");
            }
            IEntityComparerProvider CP = System.Activator.CreateInstance(sUtilType) as IEntityComparerProvider;

            if (CP == null)
            {
                throw new Exception("Class StereotypeUtil is not IEntityComparerProvider");
            }
            IComparer <ICompiledEntity> eCmpr = CP.GetEntityComparer();
            //entities.Sort(eCmpr);
            //entities.Sort(new EntityComparer());  //быстрая сортировка иногда дает сбой, т.к. не проверяет все сочетания, заменяем ее на "пузырек"
            IComparer <ICompiledEntity> cmp = CP.GetEntityComparer();

            for (int i = 0; i < eArr.Length; i++)
            {
                for (int j = i; j < eArr.Length; j++)
                {
                    if (cmp.Compare(eArr[i], eArr[j]) > 0)
                    {
                        ICompiledEntity tmp = eArr[i];
                        eArr[i] = eArr[j];
                        eArr[j] = tmp;
                    }
                }
            }

            entities.Clear();
            for (int i = 0; i < ids_str.Length; i++)
            {
                entities.Add(eArr[i]);
            }
            return(entities);
        }