コード例 #1
0
ファイル: SectionSizes.cs プロジェクト: EmilZhou/dnlib
		public SectionSizes(uint fileAlignment, uint sectionAlignment, uint headerLen, MFunc<IEnumerable<SectionSizeInfo>> getSectionSizeInfos) {
			SizeOfHeaders = Utils.AlignUp(headerLen, fileAlignment);
			SizeOfImage = Utils.AlignUp(SizeOfHeaders, sectionAlignment);
			BaseOfData = 0;
			BaseOfCode = 0;
			SizeOfCode = 0;
			SizeOfInitdData = 0;
			SizeOfUninitdData = 0;
			foreach (var section in getSectionSizeInfos()) {
				uint sectAlignedVs = Utils.AlignUp(section.length, sectionAlignment);
				uint fileAlignedVs = Utils.AlignUp(section.length, fileAlignment);

				bool isCode = (section.characteristics & 0x20) != 0;
				bool isInitdData = (section.characteristics & 0x40) != 0;
				bool isUnInitdData = (section.characteristics & 0x80) != 0;

				if (BaseOfCode == 0 && isCode)
					BaseOfCode = SizeOfImage;
				if (BaseOfData == 0 && (isInitdData || isUnInitdData))
					BaseOfData = SizeOfImage;
				if (isCode)
					SizeOfCode += fileAlignedVs;
				if (isInitdData)
					SizeOfInitdData += fileAlignedVs;
				if (isUnInitdData)
					SizeOfUninitdData += fileAlignedVs;

				SizeOfImage += sectAlignedVs;
			}
		}
コード例 #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="length">Length of the list</param>
 /// <param name="readElementByRID">Delegate instance that lazily reads an element. It might
 /// be called more than once for each <c>rid</c>. It must never return <c>null</c>.</param>
 public SimpleLazyList2(uint length, MFunc <uint, GenericParamContext, T> readElementByRID)
 {
     this.length           = length;
     this.readElementByRID = readElementByRID;
     this.elements         = new T[length];
 }
コード例 #3
0
        public SectionSizes(uint fileAlignment, uint sectionAlignment, uint headerLen, MFunc <IEnumerable <SectionSizeInfo> > getSectionSizeInfos)
        {
            sizeOfHeaders     = Utils.AlignUp(headerLen, fileAlignment);
            sizeOfImage       = Utils.AlignUp(sizeOfHeaders, sectionAlignment);
            baseOfData        = 0;
            baseOfCode        = 0;
            sizeOfCode        = 0;
            sizeOfInitdData   = 0;
            sizeOfUninitdData = 0;
            foreach (var section in getSectionSizeInfos())
            {
                uint sectAlignedVs = Utils.AlignUp(section.length, sectionAlignment);
                uint fileAlignedVs = Utils.AlignUp(section.length, fileAlignment);

                bool isCode        = (section.characteristics & 0x20) != 0;
                bool isInitdData   = (section.characteristics & 0x40) != 0;
                bool isUnInitdData = (section.characteristics & 0x80) != 0;

                if (baseOfCode == 0 && isCode)
                {
                    baseOfCode = sizeOfImage;
                }
                if (baseOfData == 0 && (isInitdData || isUnInitdData))
                {
                    baseOfData = sizeOfImage;
                }
                if (isCode)
                {
                    sizeOfCode += fileAlignedVs;
                }
                if (isInitdData)
                {
                    sizeOfInitdData += fileAlignedVs;
                }
                if (isUnInitdData)
                {
                    sizeOfUninitdData += fileAlignedVs;
                }

                sizeOfImage += sectAlignedVs;
            }
        }
コード例 #4
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="length">Initial length of the list</param>
 /// <param name="context">Context passed to <paramref name="readOriginalValue"/></param>
 /// <param name="readOriginalValue">Delegate instance that returns original values</param>
 public CustomAttributeCollection(int length, object context, MFunc <object, uint, CustomAttribute> readOriginalValue)
     : base(length, context, readOriginalValue)
 {
 }
コード例 #5
0
        protected XmlNode Definition(string name, MEDMSql model, XmlNode xrequest, XmlNode xresponse, string sectiontype = "", bool addExpand = false, bool addToString = false, bool isReadOnly = false)
        {
            MEDMDefClass dc = MEDMDefModel.MainDef.Find(name);

            if (sectiontype != "")
            {
                dc = MEDMDefModel.MainDef.Find(sectiontype);
            }

            bool isdefultsection = false;

            if (name == "empty")
            {
                XmlNode xrowset   = XFunc.AppendWithFind(xresponse, "rowset", "rowset", "empty", "datasource", "empty");
                XmlNode xsection  = XFunc.Append(xrowset, "section", "row.type", sectiontype);
                XmlNode xrequests = XFunc.Append(xsection, "requests");
                XFunc.Append(xrequests, "request", "name", "refresh");
                return(xsection);
            }
            else if (dc != null)
            {
                isReadOnly = isReadOnly || dc.IsReadOnly;
                if (sectiontype.ToLower() == "default")
                {
                    isdefultsection = true;
                    sectiontype     = "";
                }
                XmlNode xrowset  = XFunc.AppendWithFind(xresponse, "rowset", "rowset", name.ToLower(), "datasource", name.ToLower(), "readonly", isReadOnly ? "1" : "0");
                XmlNode xsection = XFunc.Append(xrowset, "section", "row.type", sectiontype);

                XmlNode xrequests = XFunc.Append(xsection, "requests");
                XFunc.Append(xrequests, "request", "name", "refresh");
                if (addExpand)
                {
                    XFunc.Append(xrequests, "request", "name", "expand");
                }
                if (isdefultsection)
                {
                    return(xsection);
                }
                if (dc != null && dc.BaseClass == "MEDMObj" && !isReadOnly)
                {
                    XFunc.Append(xrequests, "request", "name", "save");
                    XFunc.Append(xrequests, "request", "name", "append");
                    XFunc.Append(xrequests, "request", "name", "delete");
                }
                if (dc.IsMark)
                {
                    XFunc.Append(xrequests, "request", "name", "mark");
                    XFunc.Append(xrequests, "request", "name", "markclear");
                    XmlNode xparams = XFunc.AppendWithFind(xrequests, "params");
                    XFunc.Append(xparams, "param", "name", "markmode", "value", name.ToLower());
                    XFunc.Append(xparams, "param", "name", "markfield", "value", name.ToLower() + "list");
                }
                if (dc.IsJoin && !isReadOnly)
                {
                    XmlNode xr = XFunc.Append(xrequests, "request", "name", "join");
                    if (dc.CaptionJoin == "*")
                    {
                        XFunc.SetAttr(xr, "caption", "Объединить отмеченные строки...");
                    }
                    else if (dc.CaptionJoin != "")
                    {
                        XFunc.SetAttr(xr, "caption", dc.CaptionJoin);
                    }
                    if (dc.ConfirmJoin == "*")
                    {
                        XFunc.SetAttr(xr, "confirm", "Отмеченные строки будут объединены с текущей строкой...");
                    }
                    else if (dc.ConfirmJoin != "")
                    {
                        XFunc.SetAttr(xr, "confirm", dc.ConfirmJoin);
                    }
                }
                if (dc.IsCopy && !isReadOnly)
                {
                    XmlNode xr = XFunc.Append(xrequests, "request", "name", "copy");
                    if (dc.CaptionCopy == "*")
                    {
                        XFunc.SetAttr(xr, "caption", "Копировать отмеченные строки...");
                    }
                    else if (dc.CaptionCopy != "")
                    {
                        XFunc.SetAttr(xr, "caption", dc.CaptionCopy);
                    }
                    if (dc.ConfirmCopy == "*")
                    {
                        XFunc.SetAttr(xr, "confirm", "Отмеченные строки будут скопированы...");
                    }
                    else if (dc.ConfirmCopy != "")
                    {
                        XFunc.SetAttr(xr, "confirm", dc.ConfirmCopy);
                    }
                }
                if (dc.IsMove && !isReadOnly)
                {
                    XmlNode xr = XFunc.Append(xrequests, "request", "name", "move");
                    if (dc.CaptionMove == "*")
                    {
                        XFunc.SetAttr(xr, "caption", "Перенести отмеченные строки...");
                    }
                    else if (dc.CaptionMove != "")
                    {
                        XFunc.SetAttr(xr, "caption", dc.CaptionMove);
                    }
                    if (dc.ConfirmMove == "*")
                    {
                        XFunc.SetAttr(xr, "confirm", "Отмеченные строки будут перенесены...");
                    }
                    else if (dc.ConfirmMove != "")
                    {
                        XFunc.SetAttr(xr, "confirm", dc.ConfirmMove);
                    }
                }
                if (dc.IsLink && !isReadOnly)
                {
                    XmlNode xr = XFunc.Append(xrequests, "request", "name", "link");
                    if (dc.CaptionLink == "*")
                    {
                        XFunc.SetAttr(xr, "caption", "Присоединить отмеченные строки...");
                    }
                    else if (dc.CaptionLink != "")
                    {
                        XFunc.SetAttr(xr, "caption", dc.CaptionLink);
                    }
                    if (dc.ConfirmLink == "*")
                    {
                        XFunc.SetAttr(xr, "confirm", "Отмеченные строки будут присоединены...");
                    }
                    else if (dc.ConfirmLink != "")
                    {
                        XFunc.SetAttr(xr, "confirm", dc.ConfirmLink);
                    }
                }
                if (dc.IsClone && !isReadOnly)
                {
                    XmlNode xr = XFunc.Append(xrequests, "request", "name", "clone");
                    if (dc.CaptionClone == "*")
                    {
                        XFunc.SetAttr(xr, "caption", "Клонировать отмеченные строки...");
                    }
                    else if (dc.CaptionClone != "")
                    {
                        XFunc.SetAttr(xr, "caption", dc.CaptionClone);
                    }
                    if (dc.ConfirmClone == "*")
                    {
                        XFunc.SetAttr(xr, "confirm", "Отмеченные строки будут клонированы...");
                    }
                    else if (dc.ConfirmClone != "")
                    {
                        XFunc.SetAttr(xr, "confirm", dc.ConfirmClone);
                    }
                }
                XmlNode xfields = XFunc.Append(xsection, "fields");
                foreach (MEDMDefProperty dp in dc.Properties)
                {
                    if (dp.IsVisible)
                    {
                        if (dp.IsInterval)
                        {
                            XFunc.Append(xfields, "field", "name", (dp.Name + ".Min").ToLower(), "type", dp.GetDataTypeFor740(), "caption", dp.Header + " от", "len", GetLen(dp));
                            XFunc.Append(xfields, "field", "name", (dp.Name + ".Max").ToLower(), "type", dp.GetDataTypeFor740(), "caption", "до", "len", GetLen(dp));
                        }
                        else
                        {
                            string t    = dp.GetDataTypeFor740();
                            string list = "";
                            if (!string.IsNullOrEmpty(dp.Items))
                            {
                                foreach (string item in dp.Items.Split(itemd, StringSplitOptions.RemoveEmptyEntries))
                                {
                                    string item1 = item.Replace(";", ",").Trim();
                                    if (!string.IsNullOrEmpty(item1))
                                    {
                                        if (!string.IsNullOrEmpty(list))
                                        {
                                            list += ";";
                                        }
                                        list += item1;
                                    }
                                }
                            }
                            if (list != "")
                            {
                                t = "list";
                            }
                            XmlNode xfield = XFunc.Append(xfields, "field", "name", dp.Name.ToLower(), "type", t, "caption", dp.Header, "len", GetLen(dp), "list", list);
                            if (t == "radio")
                            {
                                if (dp.DataType == "int" || dp.DataType == "long" || dp.DataType == "short" || dp.DataType == "byte")
                                {
                                    XFunc.SetAttr(xfield, "basetype", "num");
                                    XFunc.SetAttr(xfield, "default", MFunc.StringToInt(dp.DefValue, 1).ToString());
                                }
                                else
                                {
                                }
                            }
                            if (!MEDMObj.IsEmptyId(dp.RefClassId))
                            {
                                XFunc.Append(xfield, "ref", "datasource", dp.RefClass.Name.ToLower());
                                XFunc.SetAttr(xfield, "type", "ref");
                                XFunc.SetAttr(xfield, "visible", "0");
                                XmlNode xreffield = XFunc.Append(xfields, "field", "name", (dp.GetRefName() + "_tostring_").ToLower(), "type", "string", "refid", dp.Name.ToLower(), "refname", "_tostring_", "caption", dp.Header, "len", GetLen(dp));
                            }
                        }
                    }
                }
                if (addToString)
                {
                    XFunc.SetAttr(xfields, "name", "_tostring_");
                    XFunc.Append(xfields, "field", "name", "_tostring_", "type", "string", "caption", "", "len", "255");
                }
                return(xsection);
            }
            return(null);
        }
コード例 #6
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="length">Length of the list</param>
 /// <param name="readElementByRID">Delegate instance that lazily reads an element. It might
 /// be called more than once for each <c>rid</c> in rare cases. It must never return
 /// <c>null</c>.</param>
 public SimpleLazyList(uint length, MFunc <uint, T> readElementByRID)
 {
     this.length           = length;
     this.readElementByRID = readElementByRID;
     this.elements         = new T[length];
 }
コード例 #7
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="length">Initial length of the list</param>
 /// <param name="context">Context passed to <paramref name="readOriginalValue"/></param>
 /// <param name="readOriginalValue">Delegate instance that returns original values</param>
 public ResourceCollection(int length, object context, MFunc <object, uint, Resource> readOriginalValue)
     : base(length, context, readOriginalValue)
 {
 }
コード例 #8
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="length">Initial length of the list</param>
 /// <param name="listener">List listener</param>
 /// <param name="context">Context passed to <paramref name="readOriginalValue"/></param>
 /// <param name="readOriginalValue">Delegate instance that returns original values</param>
 internal LazyList(int length, IListListener <TValue> listener, object context, MFunc <object, uint, TValue> readOriginalValue)
 {
     this.listener          = listener;
     this.context           = context;
     this.readOriginalValue = readOriginalValue;
     this.list = new List <Element>(length);
     for (int i = 0; i < length; i++)
     {
         list.Add(new LazyElement(i, this));
     }
 }
コード例 #9
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="length">Initial length of the list</param>
 /// <param name="context">Context passed to <paramref name="readOriginalValue"/></param>
 /// <param name="readOriginalValue">Delegate instance that returns original values</param>
 internal LazyList(int length, object context, MFunc <object, uint, TValue> readOriginalValue)
     : this(length, null, context, readOriginalValue)
 {
 }
コード例 #10
0
 public static void CallDelegate(MFunc <IntWrapper, StringWrapper> a)
 {
     TestLog.Log(a(new IntWrapper {
         Value = 123
     }).Value);
 }
コード例 #11
0
ファイル: MEDMObj.cs プロジェクト: PANKOVAN/TEST
 public override string ToString()
 {
     return($"{MFunc.DateToString(Min)};{MFunc.DateToString(Max)}");
 }
コード例 #12
0
ファイル: MEDMObj.cs プロジェクト: PANKOVAN/TEST
 public new static object StringToIdType(string id)
 {
     return(MFunc.StringToInt(id));
 }
コード例 #13
0
ファイル: MEDMObj.cs プロジェクト: PANKOVAN/TEST
        public static object GetTypeValue(Type pt, object value)
        {
            TypeInfo ti = pt.GetTypeInfo();

            if (pt == typeof(bool))
            {
                if (!(value is bool))
                {
                    value = (value.ToString() == "1" || value.ToString().ToLower() == "true");
                }
            }
            else if (pt == typeof(short))
            {
                if (!(value is short))
                {
                    try
                    {
                        value = Convert.ToInt16(value);
                    }
                    catch
                    {
                        value = default(short);
                    }
                }
            }
            else if (pt == typeof(int))
            {
                if (!(value is int))
                {
                    try
                    {
                        value = Convert.ToInt32(value);
                    }
                    catch
                    {
                        value = default(int);
                    }
                }
            }
            else if (pt == typeof(long))
            {
                if (!(value is long))
                {
                    try
                    {
                        value = Convert.ToInt64(value);
                    }
                    catch
                    {
                        value = default(long);
                    }
                }
            }
            else if (pt == typeof(byte))
            {
                if (!(value is byte))
                {
                    try
                    {
                        value = Convert.ToByte(value);
                    }
                    catch
                    {
                        value = default(byte);
                    }
                }
            }
            else if (pt == typeof(double))
            {
                if (!(value is double))
                {
                    try
                    {
                        value = MFunc.StringToDouble(value.ToString());
                    }
                    catch
                    {
                        value = default(double);
                    }
                }
            }
            else if (pt == typeof(decimal))
            {
                if (!(value is decimal))
                {
                    try
                    {
                        value = MFunc.StringToDecimal(value.ToString());
                    }
                    catch
                    {
                        value = default(decimal);
                    }
                }
            }
            else if (pt == typeof(DateTime))
            {
                if (!(value is DateTime))
                {
                    try
                    {
                        value = Convert.ToDateTime(value);
                    }
                    catch
                    {
                        value = default(DateTime);
                    }
                }
                if ((DateTime)value < NULLDateTime1)
                {
                    value = NULLDateTime;
                }
            }
            else if (pt == typeof(string))
            {
                if (!(value is string))
                {
                    value = value.ToString();
                }
            }
            else if (pt == typeof(Guid))
            {
                if (!(value is Guid))
                {
                    try
                    {
                        value = new Guid(value.ToString());
                    }
                    catch
                    {
                        value = default(Guid);
                    }
                }
            }
            else if (ti.IsEnum)
            {
                value = Enum.Parse(pt, value.ToString(), true);
            }
            else
            {
                value = null;
            }
            return(value);
        }
コード例 #14
0
        public IActionResult Login(MBuilderModel model, string login, string password)
        {
            try
            {
                if (login == null)
                {
                    login = "";
                }
                if (password == null)
                {
                    password = "";
                }

                if (login == "" && password == "")
                {
                    login    = "******";
                    password = "******";
                }

                MEntity   user = model.SelectFirst <MEntity>($"select * from [MEntity] (nolock) where EntityTypeId='USR' and Code={model.AddParam(login)}");
                MPassword pass = model.SelectFirst <MPassword>($"select * from [MPassword] (nolock) where Id={model.AddParam(login)} and PassCode={model.AddParam(MFunc.GetSecurityHash(password))}");
                if (user != null)
                {
                    if (pass != null)
                    {
                        model.AddUser(new MUser(user), login);
                        SetAuth(login);
                    }
                    else
                    {
                        throw new NotAuthException($@"Неправильный пароль...");
                    }
                }
                else
                {
                    throw new NotAuthException($@"Пользователь ""{login}"" не найден...");
                }

                return(Json(new MJsonResult(MJsonResultType.OK, null)));
            }
            catch (Exception e)
            {
                return(Json(new MJsonResult(MJsonResultType.Error, e.Message)));
            }
        }