Esempio n. 1
0
        public AtawException(string message, object errorObject)
            : base(message)
        {
            AtawDebug.AssertArgumentNullOrEmpty(message, "message", null);

            fErrorObject = errorObject;
        }
Esempio n. 2
0
        internal static T InternalGetDefaultValue <T>(string strValue, T defaultValue,
                                                      bool throwException)
        {
            Type          type      = typeof(T);
            TypeConverter converter = TypeDescriptor.GetConverter(type);

            if (throwException)
            {
                AtawDebug.AssertNotNull(converter, string.Format(ObjectUtil.SysCulture,
                                                                 "无法获取类型{0}的TypeConverter,请确认是否为其配置TypeConverterAttribute",
                                                                 type), null);
            }
            else
            {
                if (converter == null)
                {
                    return(default(T));
                }
            }
            try
            {
                return(strValue == null?InternalGetDefaultValue(defaultValue)
                           : (T)converter.ConvertFromString(strValue));
            }
            catch
            {
                return(InternalGetDefaultValue(defaultValue));
            }
        }
Esempio n. 3
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);
        }
        public AtawArgumentException(string argument, string message, object errorObject)
            : base(message, errorObject)
        {
            AtawDebug.AssertArgumentNullOrEmpty(argument, "argument", null);

            Argument = argument;
        }
Esempio n. 5
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);
            }
        }
Esempio n. 6
0
 protected void AssertCreateType <T>(Type RegType)
 {
     AtawDebug.Assert(ObjectUtil.IsSubType(typeof(T), RegType),
                      string.Format(ObjectUtil.SysCulture,
                                    "注册类型{0}不是参数T类型{1}的子类,无法进行类型转换,请确认",
                                    RegType, typeof(T)), this);
 }
Esempio n. 7
0
        private string SetTextIndex()
        {
            AtawDebug.Assert(LastNodeIndex >= 0 && LastNodeIndex < 1000, "同一个级的树节点不能超过1000个", this);
            string str = string.Format(ObjectUtil.SysCulture, "{0:000}", LastNodeIndex);

            return(str);
        }
Esempio n. 8
0
        public static XmlReader GetXmlReader(Stream stream)
        {
            AtawDebug.AssertArgumentNull(stream, "stream", null);

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

            return(reader);
        }
Esempio n. 9
0
        public static XmlReader GetXmlReader(string path)
        {
            AtawDebug.AssertArgumentNullOrEmpty(path, "path", null);

            XmlReader reader = XmlReader.Create(new Uri(path).ToString(), ReaderSetting);

            return(reader);
        }
Esempio n. 10
0
        public static Uri FileNameToUri(string fileName)
        {
            AtawDebug.AssertArgumentNullOrEmpty(fileName, "fileName", null);

            Uri uri = new Uri(fileName);

            return(uri);
        }
Esempio n. 11
0
 private void JudgeListContainCurrentException(ListNode <T> current)
 {
     AtawDebug.AssertNotNull(fHead, "该链表为空!", this);
     //判断当前节点是否为当前链表中
     //传送LinkList<T>对象给ListNode<T>构造函数,是为了确定不同的节点对应到各自不同的类节点链表里面
     //判断当前节点是否在this链表中
     AtawDebug.Assert(current.List == this, "您插入的当前链表不匹配!", this);
 }
Esempio n. 12
0
        public AtawException(string message, Exception innerException, object errorObject)
            : base(message, innerException)
        {
            AtawDebug.AssertArgumentNullOrEmpty(message, "message", null);
            AtawDebug.AssertArgumentNull(innerException, "innerException", null);

            fErrorObject = errorObject;
        }
Esempio n. 13
0
        public static void ConfirmPath(string path)
        {
            AtawDebug.AssertArgumentNullOrEmpty(path, "path", null);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
        }
Esempio n. 14
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;
            //}
        }
Esempio n. 15
0
        int IList.Add(object value)
        {
            AtawDebug.AssertArgumentNull(value, "value", this);

            int index = Count;

            Add((T)value);
            return(index);
        }
Esempio n. 16
0
        public static IList <ImageCut> GetImageCutsByCutConfigName(string cutGroupName)
        {
            ImageCutGroup cut = FileManagementConfig.ImageCutGroups.Find(a => a.Name == cutGroupName);

            AtawDebug.Assert(cut != null && cut.ImageCuts.Count > 0, string.Format(ObjectUtil.SysCulture,
                                                                                   "名称为{0}的截图配置不存在,或者没有截图配置项", cutGroupName), AtawAppContext.Current);

            return(cut.ImageCuts);
        }
Esempio n. 17
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);
        }
Esempio n. 18
0
        public static string GetXml(XmlReader reader)
        {
            AtawDebug.AssertArgumentNull(reader, "reader", null);

            using (MemoryStream stream = GetXmlStream(reader))
            {
                return(Encoding.UTF8.GetString(stream.ToArray()));
            }
        }
Esempio n. 19
0
        public static void VerifySaveFile(string fileName, string content, Encoding encoding)
        {
            AtawDebug.AssertArgumentNullOrEmpty(fileName, "fileName", null);

            string path = Path.GetDirectoryName(fileName);

            ConfirmPath(path);
            SaveFile(fileName, content, encoding);
        }
Esempio n. 20
0
        public void Add(IEnumerable <string> values)
        {
            AtawDebug.AssertArgumentNull(values, "values", this);

            foreach (string id in values)
            {
                Add(id);
            }
        }
        protected virtual void Assign(BasePlugInAttribute attribute)
        {
            AtawDebug.AssertArgumentNull(attribute, "attribute", this);

            RegName     = attribute.RegName;
            Description = attribute.Description;
            Author      = attribute.Author;
            CreateDate  = attribute.CreateDate;
        }
Esempio n. 22
0
        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;
        }
Esempio n. 23
0
        public void ParseExpr(string format)
        {
            FormatString = format;

            var ptr    = 0;
            var length = format.Length;

            while (ptr < length)
            {
                var c = format[ptr++];
                if (c == fOpen)
                {
                    // check for escaped open bracket

                    if (format[ptr] == fOpen)
                    {
                        ptr++;
                        continue;
                    }

                    var marcoStart = ptr;

                    while (format[ptr++] != fClose)
                    {
                        if (ptr >= length)
                        {
                            break;
                        }
                    }

                    AtawDebug.Assert(ptr <= length, string.Format(ObjectUtil.SysCulture,
                                                                  "扫描字符串{0}发现,存在只有{1}而没有与之匹配的{2}结束的字符串", format, fOpen, fClose), format);

                    string marco = format.Substring(marcoStart, ptr - marcoStart - 1);
                    AtawDebug.Assert(!string.IsNullOrEmpty(marco), string.Format(ObjectUtil.SysCulture,
                                                                                 "字符串{0}中存在{1}与{2}之间没有任何宏名称,空宏是不被允许的", format, fOpen, fClose), format);
                    fParameters.Add(new AtawExpressionParameter()
                    {
                        ParameterName = marco, StartIndex = marcoStart - 1
                    });

                    //result.Append("{" + (marcoCount++) + "}");
                }
                else if (c == fClose && ptr < length && format[ptr] == fClose)
                {
                    //result.Append(format, start, ptr - start - 1);
                    ptr++;
                    //result.Append("}");
                }
                else if (c == fClose)
                {
                    AtawDebug.Assert(false, string.Format(ObjectUtil.SysCulture,
                                                          "扫描字符串{0}发现,存在单独的{2},如果要显示{2},请写两个{2},否则请与{1}配对", format, fOpen, fClose), format);
                }
            }
        }
Esempio n. 24
0
        public static IList <ImageCut> GetImageCutsByUploadName(string uploadName)
        {
            FileUploadConfig config = GetFileUploadConfig(uploadName);

            AtawDebug.AssertArgumentNullOrEmpty(config.Name,
                                                string.Format(ObjectUtil.SysCulture, "名称为{0}的上传配置节点不存在截图配置", uploadName),
                                                AtawAppContext.Current);

            return(GetImageCutsByCutConfigName(config.ImageCutGroupName));
        }
Esempio n. 25
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);
        }
Esempio n. 26
0
 internal static string GetXmlFilePattern(string pattern)
 {
     if (string.IsNullOrEmpty(pattern))
     {
         return("*.xml");
     }
     AtawDebug.Assert(pattern.EndsWith(".xml", StringComparison.OrdinalIgnoreCase),
                      string.Format(ObjectUtil.SysCulture, "{0}应该是以.xml结束,而现在不是", pattern), null);
     return(pattern);
 }
Esempio n. 27
0
        public static string ReadVersion(XmlReader reader)
        {
            AtawDebug.AssertArgumentNull(reader, "reader", null);

            if (reader.ReadToFollowing("Ataw"))
            {
                return(reader.GetAttribute("version"));
            }
            return(string.Empty);
        }
Esempio n. 28
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]);
        }
Esempio n. 29
0
 public string this[int index]
 {
     get
     {
         AtawDebug.AssertArgument(index >= 0 && index < fIdList.Count, "index",
                                  string.Format(ObjectUtil.SysCulture, "index必须在0和{1}之间,现在值为{0}不在范围内",
                                                index, fIdList.Count), this);
         return(fIdList[index]);
     }
 }
Esempio n. 30
0
        public static void AddPro(this ExpandoObject expando, string name, object obj)
        {
            IDictionary <string, object> oo = (IDictionary <string, object>)expando;
            string mesg = string.Format(ObjectUtil.SysCulture, "已经有成员{0}了,再添加就要覆盖了", name);

            AtawDebug.Assert(!oo.ContainsKey(name), mesg, expando);
            //if (oo.ContainsKey(name)) ;
            oo.Add(name, obj);
            // SetPro();
            // oo.Add(name, obj);
        }