Example #1
0
        public static object CreateObject(Type type)
        {
            AtawDebug.AssertArgumentNull(type, "type", null);

            try
            {
                return(Activator.CreateInstance(type));
            }
            catch (MissingMethodException ex)
            {
                AtawDebug.ThrowAtawException(string.Format(ObjectUtil.SysCulture,
                                                           "没有找到类型{0}的默认构造函数,请确认", type), ex, null);
            }
            catch (TargetInvocationException ex)
            {
                AtawDebug.ThrowAtawException(string.Format(ObjectUtil.SysCulture,
                                                           "调用类型{0}的默认构造函数时,发生例外,请调试你的代码", type), ex, null);
            }
            catch (MethodAccessException ex)
            {
                AtawDebug.ThrowAtawException(string.Format(ObjectUtil.SysCulture,
                                                           "类型{0}的默认构造函数访问权限不够", type), ex, null);
            }
            catch (MemberAccessException ex)
            {
                AtawDebug.ThrowAtawException(string.Format(ObjectUtil.SysCulture,
                                                           "类型{0}可能是一个抽象类型,无法创建", type), ex, null);
            }
            catch (Exception ex)
            {
                AtawDebug.ThrowAtawException(string.Format(ObjectUtil.SysCulture,
                                                           "调用类型{0}的默认构造函数是发生例外", type), ex, null);
            }
            return(null);
        }
Example #2
0
        public static void SetValue(PropertyInfo info, object obj, object value)
        {
            AtawDebug.AssertArgumentNull(info, "info", null);
            AtawDebug.AssertArgumentNull(obj, "obj", null);

            try
            {
                info.SetValue(obj, value, null);
            }
            catch (System.ArgumentException ex)
            {
                AtawDebug.ThrowAtawException(string.Format(ObjectUtil.SysCulture,
                                                           "对象{0}未找到属性{1}的 set 访问器或者数组不包含所需类型的参数",
                                                           obj.GetType(), info.Name), ex, null);
            }
            catch (TargetException ex)
            {
                AtawDebug.ThrowAtawException(string.Format(ObjectUtil.SysCulture,
                                                           "对象{0}中可能不存在属性{1},请检查",
                                                           obj.GetType(), info.Name), ex, null);
            }
            catch (MethodAccessException ex)
            {
                AtawDebug.ThrowAtawException(string.Format(ObjectUtil.SysCulture,
                                                           "无法设置对象{0}中属性{1}的值,请检查set的访问权限",
                                                           obj.GetType(), info.Name), ex, null);
            }
        }
Example #3
0
        public static XmlReader GetXmlReader(Stream stream)
        {
            AtawDebug.AssertArgumentNull(stream, "stream", null);

            XmlReader reader = XmlReader.Create(stream, ReaderSetting);

            return(reader);
        }
Example #4
0
        public AtawException(string message, Exception innerException, object errorObject)
            : base(message, innerException)
        {
            AtawDebug.AssertArgumentNullOrEmpty(message, "message", null);
            AtawDebug.AssertArgumentNull(innerException, "innerException", null);

            fErrorObject = errorObject;
        }
Example #5
0
        //public static string getFileUploadInfo(string fileUploadName)
        //{
        //    var fileUpload = FileManagementConfig.FileUploads.FirstOrDefault(a => a.Name == fileUploadName);
        //    int fileMaxSize = fileUpload.MaxSize;
        //    string Extensions = fileUpload.Extensions;
        //    string filePath = fileUpload.FilePath;
        //    if (fileUploadName == "ImageUpload")
        //    {
        //        int ImageSizeWidth = fileUpload.ImageSizeWidth;
        //        int ImageSizeHeight = fileUpload.ImageSizeHeight;
        //        return fileMaxSize + " " + Extensions + " " + filePath + " " + ImageSizeWidth + " " + ImageSizeHeight;
        //    }
        //    return fileMaxSize + " " + Extensions + " " + filePath;
        //}

        public static FileUploadConfig GetFileUploadConfig(string uploadName)
        {
            var _res = FileManagementConfig.FileUploads.FirstOrDefault(a => a.Name == uploadName);

            AtawDebug.AssertArgumentNull(_res,
                                         string.Format(ObjectUtil.SysCulture, "名称为{0}的上传配置节点不能为空", uploadName),
                                         AtawAppContext.Current);
            return(_res);
        }
Example #6
0
        public static string GetXml(XmlReader reader)
        {
            AtawDebug.AssertArgumentNull(reader, "reader", null);

            using (MemoryStream stream = GetXmlStream(reader))
            {
                return(Encoding.UTF8.GetString(stream.ToArray()));
            }
        }
Example #7
0
        int IList.Add(object value)
        {
            AtawDebug.AssertArgumentNull(value, "value", this);

            int index = Count;

            Add((T)value);
            return(index);
        }
        public static T Convert<T>(this object objValue) where T : class
        {
            AtawDebug.AssertArgumentNull(objValue, "objValue", null);

            T result = objValue as T;
            AtawDebug.AssertNotNull(result, string.Format(ObjectUtil.SysCulture,
                "将类型{0}转换为类型{1}失败,请确认代码", objValue.GetType(), typeof(T)), objValue);
            return result;
        }
Example #9
0
        public static string GetAtawControlUnitsProductValue(string fControlUnitID, ProductsType databaseType, string key)
        {
            string productName = databaseType.ToString();
            var    database    = AtawAppContext.Current.DBConfigXml.Databases.Where(a => a.IsDefault).FirstOrDefault();

            AtawDebug.AssertArgumentNull(database, "默认的数据库配置不能为空", AtawAppContext.Current);
            string strDefaultConnstring = database.ConnectionString;

            if (fControlUnitID.IsEmpty())
            {
                return(strDefaultConnstring);
            }

            var xml   = AtawAppContext.Current.ProductsXml.ControlUnits;
            var cList = xml.Where(a => a.FControlUnitID == fControlUnitID);

            //IList<ControlUnitItemInfo> m = q.AsQueryable<ControlUnitItemInfo>().ToList();
            if (cList.Count() == 0)
            {
                return(strDefaultConnstring);
            }

            string va = "";

            foreach (var item in cList)
            {
                if (!string.IsNullOrEmpty(va))
                {
                    break;
                }
                foreach (var item2 in item.Products)
                {
                    if (item2.Name == productName && item2.Key == key)
                    {
                        va = item2.Value;
                        if (key == "DB")
                        {
                            va = GetAtawDatabaseValue(va); //返回数据库的字符串
                        }
                        break;
                    }
                }
            }
            if (!string.IsNullOrEmpty(va))
            {
                return(va);
            }
            else
            {
                return(strDefaultConnstring);
            }
            //}
            //catch (Exception)
            //{
            //    return strDefaultConnstring;
            //}
        }
        protected virtual void Assign(BasePlugInAttribute attribute)
        {
            AtawDebug.AssertArgumentNull(attribute, "attribute", this);

            RegName     = attribute.RegName;
            Description = attribute.Description;
            Author      = attribute.Author;
            CreateDate  = attribute.CreateDate;
        }
Example #11
0
        public void Add(IEnumerable <string> values)
        {
            AtawDebug.AssertArgumentNull(values, "values", this);

            foreach (string id in values)
            {
                Add(id);
            }
        }
Example #12
0
        public static object GetFirstEnumValue(Type enumType)
        {
            AtawDebug.AssertArgumentNull(enumType, "enumType", null);

            Array values = Enum.GetValues(enumType);

            AtawDebug.Assert(values.Length > 0, string.Format(ObjectUtil.SysCulture,
                                                              "枚举类型{0}中没有枚举值", enumType), null);
            return((values as IList)[0]);
        }
Example #13
0
        protected void CopyTo(Array array, int index)
        {
            AtawDebug.AssertArgumentNull(array, "array", this);
            AssertIndex(index, array.Length);
            AtawDebug.AssertArgument(array.Length - index >= Count, "arrayIndex", string.Format(
                                         ObjectUtil.SysCulture, "当前有{0}个元素,而数组的空间为{1},空间不够",
                                         Count, array.Length - index), this);

            fList.CopyTo(array, index);
        }
Example #14
0
        public static string ReadVersion(XmlReader reader)
        {
            AtawDebug.AssertArgumentNull(reader, "reader", null);

            if (reader.ReadToFollowing("Ataw"))
            {
                return(reader.GetAttribute("version"));
            }
            return(string.Empty);
        }
Example #15
0
        /// <summary>
        /// 将数据保存到相应的文件中
        /// </summary>
        /// <param name="fileName">文件名</param>
        /// <param name="content">需要保存的数据</param>
        /// <param name="encoding">文件的编码形式</param>
        public static void SaveFile(string fileName, string content, Encoding encoding)
        {
            AtawDebug.AssertArgumentNullOrEmpty(fileName, "fileName", null);
            AtawDebug.AssertArgumentNull(content, "content", null);
            AtawDebug.AssertArgumentNull(encoding, "encoding", null);

            FileStream file = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.Read);

            using (TextWriter writer = new StreamWriter(file, encoding))
            {
                writer.Write(content);
            }
        }
Example #16
0
        public static void JoinStringItem(StringBuilder builder, int index, string value, string joinStr)
        {
            AtawDebug.AssertArgumentNull(builder, "builder", null);
            AtawDebug.AssertArgumentNullOrEmpty(value, "value", null);
            AtawDebug.AssertArgumentNull(joinStr, "joinStr", null);
            AtawDebug.AssertArgument(index >= 0, "index", string.Format(ObjectUtil.SysCulture,
                                                                        "index的值不能为负数,现在是{0}", index), null);

            if (index > 0)
            {
                builder.Append(joinStr);
            }
            builder.Append(value);
        }
Example #17
0
        public void Insert(int index, T item)
        {
            AssertIndex(index, Count);
            AtawDebug.AssertArgumentNull(item, "item", this);

            if (!fDictionary.ContainsKey(item.RegName))
            {
                ListNode <T> node    = fList.GetIndexNode(index);
                var          newNode = fList.AddAfter(node, item);
                fDictionary.Add(item.RegName, newNode);
                checked
                {
                    OnAdded(item, index + 1);
                }
            }
        }
Example #18
0
        public bool Remove(T item)
        {
            AtawDebug.AssertArgumentNull(item, "item", this);

            ListNode <T> node;

            if (fDictionary.TryGetValue(item.RegName, out node))
            {
                int index = fList.IndexOf(node);
                fDictionary.Remove(item.RegName);
                fList.Remove(node);
                OnRemoved(item, index);
                node = null;
                return(true);
            }
            return(false);
        }
 public static void MergeColumns(FormConfig form, DataFormConfig dataForm, ModuleConfig moduleConfig)
 {
     if (form.FormColumnRight != null)
     {
         ColumnRightConfig columnRight     = null;
         string            columnRightname = form.FormColumnRight.Name;
         if (form.FormColumnRight.RegName.IsEmpty())
         {
             AtawDebug.AssertArgumentNullOrEmpty(columnRightname, "FormColumnRight中若没指定RegName,Name属性不能为空", moduleConfig);
             columnRight = moduleConfig.Right.ColumnRights.FirstOrDefault(a => a.Name == columnRightname);
             AtawDebug.AssertArgumentNull(columnRight, string.Format("ModuleXml中必须配置名为'{0}'的ColumnRight", columnRightname), moduleConfig);
         }
         else
         {
             IColumnRight columnRightPlug = form.FormColumnRight.RegName.CodePlugIn <IColumnRight>();
             columnRightname = columnRightPlug.GetColumnRightName();
             columnRight     = moduleConfig.Right.ColumnRights.FirstOrDefault(a => a.Name == columnRightname);
             AtawDebug.AssertArgumentNull(columnRight, string.Format("ModuleXml中必须配置名为'{0}'的ColumnRight", columnRightname), moduleConfig);
         }
         //if (columnRight.Delete != null)
         //{
         //    columnRight.Delete.ForEach(dCol =>
         //    {
         //        var col = dataForm.Columns.FirstOrDefault(baseCol => baseCol.Name.Equals(dCol.Name, StringComparison.OrdinalIgnoreCase));
         //        if (col != null)
         //            dataForm.Columns.Remove(col);
         //    });
         //}
         if (columnRight.Override != null)
         {
             columnRight.Override.ForEach(oCol =>
             {
                 var col = dataForm.Columns.FirstOrDefault(baseCol => baseCol.Name.Equals(oCol.BaseColumnName, StringComparison.OrdinalIgnoreCase));
                 if (col != null)
                 {
                     AssignColumn(oCol, col);
                 }
             });
         }
         if (columnRight.Add != null)
         {
             dataForm.Columns.AddRange(columnRight.Add);
         }
     }
 }
Example #20
0
        public static MemoryStream GetXmlStream(XmlReader reader)
        {
            AtawDebug.AssertArgumentNull(reader, "reader", null);

            MemoryStream      stream  = new MemoryStream();
            XmlWriterSettings setting = new XmlWriterSettings
            {
                Encoding = AtawConst.UTF8,
                Indent   = true
            };
            XmlWriter writer = XmlWriter.Create(stream, setting);

            using (writer)
            {
                WriteXmlUseXmlWriter(reader, writer);
            }
            return(stream);
        }
Example #21
0
        public static string EscapeString(string source, string[] replaceString, Func <char, int> escapeFunc)
        {
            if (string.IsNullOrEmpty(source))
            {
                return(string.Empty);
            }
            AtawDebug.AssertArgumentNull(escapeFunc, "escapeFunc", null);
            AtawDebug.AssertEnumerableArgumentNull <string>(replaceString, "replaceString", null);

            StringBuilder cachedStringBuilder = null;
            int           start = 0;
            int           pos   = 0;
            int           count = source.Length;

            for (int i = 0; i < count; ++i)
            {
                pos = escapeFunc(source[i]);
                if (pos < 0)
                {
                    continue;
                }
                if (cachedStringBuilder == null)
                {
                    cachedStringBuilder = new StringBuilder();
                }
                cachedStringBuilder.Append(source.Substring(start, i - start));
                AtawDebug.Assert(pos < replaceString.Length, string.Format(ObjectUtil.SysCulture,
                                                                           "参数escapeFunc返回的值有误,replaceString的长度为{0},但是返回值却是{1},越界了",
                                                                           replaceString.Length, pos), null);
                cachedStringBuilder.Append(replaceString[pos]);
                start = i + 1;
            }
            if (start == 0)
            {
                return(source);
            }
            else if (start < count)
            {
                cachedStringBuilder.Append(source.Substring(start, count - start));
            }
            string s = cachedStringBuilder.ToString();

            return(s);
        }
Example #22
0
        /// <summary>
        /// 格式化SQL语句中的WHERE条件
        /// </summary>
        /// <param name="sql">SQL字符串</param>
        /// <param name="whereClause">where子句</param>
        /// <returns>被替换where子句的sql</returns>
        internal static string ReplaceWhereClause(string sql, string whereClause)
        {
            AtawDebug.AssertArgumentNullOrEmpty(sql, "sql", null);
            AtawDebug.AssertArgumentNull(whereClause, "whereClause", null);

            int    index = sql.IndexOf("WHERE", StringComparison.OrdinalIgnoreCase);
            string result;

            if (index > 0)
            {
                result = sql.Substring(0, index - 1);
            }
            else
            {
                result = sql;
            }
            result += " " + whereClause;
            return(result);
        }
Example #23
0
        /// <summary>
        /// Determines whether the string is all white space. Empty string will return false.
        /// </summary>
        /// <param name="str">The string to test whether it is all white space.</param>
        /// <returns>
        ///     <c>true</c> if the string is all white space; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsWhiteSpace(string str)
        {
            AtawDebug.AssertArgumentNull(str, "str", null);

            if (str.Length == 0)
            {
                return(false);
            }

            for (int i = 0; i < str.Length; i++)
            {
                if (!char.IsWhiteSpace(str[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
        private static ColumnRightConfig GetColumnRight(FormConfig form, DataFormConfig dataForm, ModuleConfig moduleConfig)
        {
            ColumnRightConfig columnRight     = null;
            string            columnRightname = form.FormColumnRight.Name;

            if (form.FormColumnRight.RegName.IsEmpty())
            {
                AtawDebug.AssertArgumentNullOrEmpty(columnRightname, "FormColumnRight中若没指定RegName,Name属性不能为空", moduleConfig);
                columnRight = moduleConfig.Right.ColumnRights.FirstOrDefault(a => a.Name == columnRightname);
                AtawDebug.AssertArgumentNull(columnRight, string.Format("ModuleXml中必须配置名为'{0}'的ColumnRight", columnRightname), moduleConfig);
            }
            else
            {
                IColumnRight columnRightPlug = form.FormColumnRight.RegName.CodePlugIn <IColumnRight>();
                columnRightname = columnRightPlug.GetColumnRightName();
                columnRight     = moduleConfig.Right.ColumnRights.FirstOrDefault(a => a.Name == columnRightname);
                AtawDebug.AssertArgumentNull(columnRight, string.Format("ModuleXml中必须配置名为'{0}'的ColumnRight", columnRightname), moduleConfig);
            }
            return(columnRight);
        }
Example #25
0
        public static object GetValue(object sender, Type type, string strValue,
                                      object defaultValue)
        {
            AtawDebug.AssertArgumentNull(type, "type", sender);

            TypeConverter converter = TypeDescriptor.GetConverter(type);

            AtawDebug.AssertNotNull(converter, string.Format(ObjectUtil.SysCulture,
                                                             "无法获取类型{0}的TypeConverter,请确认是否为其配置TypeConverterAttribute",
                                                             type), sender);
            try
            {
                return(strValue == null?GetDefaultValue(type, defaultValue, converter)
                           : converter.ConvertFromString(strValue));
            }
            catch
            {
                return(GetDefaultValue(type, defaultValue, converter));
            }
        }
Example #26
0
        public static void AddExceptionInfo(XElement parent, Exception ex)
        {
            AtawDebug.AssertArgumentNull(parent, "parent", null);
            AtawDebug.AssertArgumentNull(ex, "ex", null);

            XElement element = new XElement("Exception",
                                            new XElement("Message", ex.Message),
                                            new XElement("ErrorSource", ex.Source),
                                            new XElement("StackTrace", ex.StackTrace),
                                            new XElement("Type", ex.GetType().ToString()));

            if (ex.TargetSite != null)
            {
                XElement target = new XElement("TargetSite", ex.TargetSite.ToString());
                element.Add(target);
            }
            AtawException tkEx = ex as AtawException;

            if (tkEx != null && tkEx.ErrorObject != null)
            {
                XElement error = new XElement("ErrorObjType",
                                              tkEx.ErrorObject.GetType().ToString());
                element.Add(error);
                error = new XElement("ErrorObj", tkEx.ErrorObject.ToString());
                element.Add(error);
            }
            AtawArgumentException argEx = ex as AtawArgumentException;

            if (argEx != null)
            {
                XElement error = new XElement("Argument", argEx.Argument);
                element.Add(error);
            }
            parent.Add(element);
            if (ex.InnerException != null)
            {
                AddExceptionInfo(parent, ex.InnerException);
            }
        }
Example #27
0
        public static Dictionary <string, string> GetEnumFields(Type Enumtype)
        {
            AtawDebug.AssertArgumentNull(Enumtype, "Enumtype", null);

            if (!Enumtype.IsEnum)
            {
                throw new AtawException("参数类型不正确", Enumtype);
            }

            var dict = new Dictionary <string, string>();

            FieldInfo[] fieldinfo = Enumtype.GetFields();
            foreach (FieldInfo item in fieldinfo)
            {
                Object[] obj = item.GetCustomAttributes(typeof(DescriptionAttribute), false);
                if (obj != null && obj.Length != 0)
                {
                    DescriptionAttribute des = (DescriptionAttribute)obj[0];
                    dict.Add(item.Name, des.Description);
                }
            }
            return(dict);
        }
Example #28
0
        bool IList.Contains(object value)
        {
            AtawDebug.AssertArgumentNull(value, "value", this);

            return(Contains((T)value));
        }
Example #29
0
        void IList.Insert(int index, object value)
        {
            AtawDebug.AssertArgumentNull(value, "value", this);

            Insert(index, (T)value);
        }
Example #30
0
        void IList.Remove(object value)
        {
            AtawDebug.AssertArgumentNull(value, "value", this);

            Remove((T)value);
        }