Beispiel #1
0
        public Settings readSettings()
        {
            SqliteCommand command = new SqliteCommand();

            command.Connection  = this.sqliteConnection;
            command.CommandText = Constants.database_table_settings_read;
            SqliteDataReader dataReader = command.ExecuteReader();

            System.Object[] values = new System.Object[dataReader.FieldCount];
            dataReader.Read();
            dataReader.GetValues(values);

            Settings settings = new Settings();

            settings.projectName        = values.GetValue(0).ToString();
            settings.testServerHostname = values.GetValue(1).ToString();
            settings.testServerPort     = int.Parse(values.GetValue(2).ToString());
            settings.ftpServerAddress   = values.GetValue(3).ToString();
            settings.ftpServerPort      = int.Parse(values.GetValue(4).ToString());
            settings.ftpServerBaseDir   = values.GetValue(5).ToString();
            settings.ftpServerUsername  = values.GetValue(6).ToString();
            settings.ftpServerPassword  = values.GetValue(7).ToString();

            int force = int.Parse(values.GetValue(8).ToString());

            settings.ftpForceCompleteUpload = System.Convert.ToBoolean(force);

            return(settings);
        }
Beispiel #2
0
        /// <summary>找到所引用的参考字段</summary>
        /// <param name="target">目标对象</param>
        /// <param name="member">目标对象的成员</param>
        /// <param name="value">数值</param>
        /// <returns></returns>
        MemberInfo FindReference(Object target, MemberInfo member, out Object value)
        {
            value = null;

            if (member == null) return null;
            if (String.IsNullOrEmpty(ReferenceName)) return null;

            // 考虑ReferenceName可能是圆点分隔的多重结构
            MemberInfo mi = null;
            Type type = member.DeclaringType;
            value = target;
            var ss = ReferenceName.Split(".");
            for (int i = 0; i < ss.Length; i++)
            {
                var pi = type.GetPropertyEx(ss[i]);
                if (pi != null)
                {
                    mi = pi;
                    type = pi.PropertyType;
                }
                else
                {
                    var fi = type.GetFieldEx(ss[i]);
                    if (fi != null)
                    {
                        mi = fi;
                        type = fi.FieldType;
                    }
                }

                // 最后一个不需要计算
                if (i < ss.Length - 1)
                {
                    if (mi != null) value = value.GetValue(mi);
                }
            }

            // 目标字段必须是整型
            var tc = Type.GetTypeCode(type);
            if (tc >= TypeCode.SByte && tc <= TypeCode.UInt64) return mi;

            return null;
        }
Beispiel #3
0
        /// <summary>设置目标对象的引用大小值</summary>
        /// <param name="target">目标对象</param>
        /// <param name="member"></param>
        /// <param name="encoding"></param>
        internal void SetReferenceSize(Object target, MemberInfo member, Encoding encoding)
        {
            Object v = null;
            var mi = FindReference(target, member, out v);
            if (mi == null) return;

            // 获取当前成员(加了特性)的值
            var value = target.GetValue(member);
            if (value == null) return;

            // 尝试计算大小
            Int32 size = 0;
            if (value is String)
            {
                if (encoding == null) encoding = Encoding.UTF8;

                size = encoding.GetByteCount("" + value);
            }
            else if (value.GetType().IsArray)
            {
                size = (value as Array).Length;
            }
            else if (value is IEnumerable)
            {
                foreach (var item in value as IEnumerable)
                {
                    size++;
                }
            }

            // 给参考字段赋值
            v.SetValue(mi, size - Size);
        }
Beispiel #4
0
 public static UIElementCollection GetMyProperty(NativeDependencyObject obj)
 {
     return((UIElementCollection)obj.GetValue(MyPropertyProperty));
 }
Beispiel #5
0
 private static String getParamsAsString(Object [] pParams, String pClassName, String pMethodName)
 {
     StringBuilder buffer = new StringBuilder();
     try
     {
         if (pParams != null)
         {
             bool tFistTime = true;
             buffer.Append("[");
             for (int i = 0; i < pParams.Length; i++)
             {
                 if (!tFistTime)
                 {
                     buffer.Append(", ");
                 }
                 buffer.Append("" + pParams.GetValue(i));
                 tFistTime = false;
             }
             buffer.Append("]");
         }
     }
     catch (Exception externalException)
     {
         String message = "Unable to get arguments of class=[" + pClassName + "] and method=[" + pMethodName + "]";
         throw new NMonitoringException(message,externalException);
     }
     return buffer.ToString();
 }
Beispiel #6
0
        /// <summary>
        /// Asserts that two objects are not equal. If they are equal
        /// an <see cref="AssertionException"/> is thrown.
        /// </summary>
        /// <param name="expected">The expected object</param>
        /// <param name="actual">The actual object</param>
        /// <param name="message">The message to be displayed when the two objects are the same object.</param>
        /// <param name="args">Arguments to be used in formatting the message</param>
        public static void AreNotEqual(Object[] expected, Object[] actual, string message, params object[] args)
        {
            bool fail = false;

            if (expected != null && actual != null)
            {
                if (expected.GetLength(0) == actual.GetLength(0))
                {
                    fail = true;
                }

                if (!fail)
                {
                    int position = 0;
                    bool same = true;
                    foreach (object o in expected)
                    {
                        if (!o.Equals(actual.GetValue(position)))
                        {
                            same = false;
                        }
                        position++;
                    }

                    if (same)
                        fail = true;
                }
            }
            else
            {
                fail = true;
            }

            if (fail)
            {
                if (args != null)
                    Assert.FailSame(expected, actual, message, args);
                else
                    Assert.FailSame(expected, actual, message);
            }
        }
Beispiel #7
0
 public static int GetPriority(DependencyObject obj)
 {
     return((int)obj.GetValue(PriorityProperty));
 }
Beispiel #8
0
        private void WriteObject(Object obj)
        {
            Int32 i = 0;
            if (!_cirobj.TryGetValue(obj, out i)) _cirobj.Add(obj, _cirobj.Count + 1);

            _Builder.Append('{');
            _depth++;
            if (_depth > 5) throw new Exception("超过了序列化最大深度 " + 5);

            var map = new Dictionary<String, String>();
            var t = obj.GetType();

            var first = true;
            foreach (var pi in t.GetProperties(true))
            {
                var value = obj.GetValue(pi);
                if (NullValue || value != null && !(value is DBNull))
                {
                    if (!first) _Builder.Append(',');
                    first = false;

                    var name = pi.Name;
                    if (LowerCaseName) name = name.ToLower();
                    WritePair(name, value);
                }
            }
            _Builder.Append('}');
            _depth--;
        }
 /// <summary>
 /// Method to save details to database
 /// </summary>
 public Boolean Save(Object[,] par, String Command, out String Message)
 {
     try
     {
         effectedRows = DPBaseClass.ExecuteNonQuery(Command, par);
         if ((TransactionType)(par.GetValue((par.Length / 2) - 1, (par.Length / 2) - 1)) == TransactionType.INSERT)
             Message = CustomMessages.INSERT_SUCESS.ToString();
         else
             Message = CustomMessages.UPDATE_SUCESS.ToString();
         if (effectedRows > 0)
             return true;
     }
     catch (Exception ex)
     {
         DPBaseClass.LogException(ex);
         if ((TransactionType)(par.GetValue((par.Length / 2) - 1, (par.Length / 2) - 1)) == TransactionType.INSERT)
             Message = CustomMessages.INSERT_FAILED.ToString();
         else
             Message = CustomMessages.UPDATE_FAILED.ToString();
     }
     return false;
 }
Beispiel #10
0
        private Boolean WriteObject(Object value, Type type)
        {
            var ims = Host.IgnoreMembers;

            var ms = GetMembers(type).Where(e => !ims.Contains(e.Name)).ToList();
            WriteLog("BinaryWrite类{0} 共有成员{1}个", type.Name, ms.Count);

            Host.Hosts.Push(value);

            // 获取成员
            foreach (var member in ms)
            {
                var mtype = GetMemberType(member);
                Host.Member = member;

                var v = value.GetValue(member);
                WriteLog("    {0}.{1} {2}", type.Name, member.Name, v);

                var name = member.Name;
                var att = member.GetCustomAttribute<XmlElementAttribute>();
                if (att != null) name = att.ElementName;

                // 特殊处理写入名值对
                if (!WritePair(name, v))
                {
                    Host.Hosts.Pop();
                    return false;
                }
            }
            Host.Hosts.Pop();

            return true;
        }
Beispiel #11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ouputList"></param>
        /// <param name="targetList"></param>
        /// <returns></returns>
        protected string CompareData(Hashtable ouputList, Hashtable targetList)
        {
            Object[] keys = new Object[ouputList.Count];
            //Array keys = new Array; // = null;
            ouputList.Keys.CopyTo(keys, 0);
            //ICollection keys = ouputList.Keys;
            string outputString = string.Empty;

            for (int i = 0; i < keys.Length; i++)
            {
                if (keys.GetValue(i).ToString().IndexOf("Date") != -1)
                {
                    if (!Convert.ToDateTime(targetList[keys.GetValue(i)]).Date.Equals(Convert.ToDateTime(ouputList[keys.GetValue(i)]).Date))
                    {
                        outputString = outputString + "Source Value:" + ouputList[keys.GetValue(i)].ToString() + "and Target Value: " + targetList[keys.GetValue(i)].ToString() + Environment.NewLine;
                    }
                }
                else
                {
                    if (!targetList[keys.GetValue(i)].ToString().Equals(ouputList[keys.GetValue(i)].ToString()))
                    {
                        outputString = outputString + "Source Value:" + ouputList[keys.GetValue(i)].ToString() + " and Target Value: " + targetList[keys.GetValue(i)].ToString() + Environment.NewLine;
                    }
                }
            }
            return outputString;
        }
Beispiel #12
0
        /// <summary>写入对象</summary>
        /// <param name="value">目标对象</param>
        /// <param name="type">类型</param>
        /// <returns></returns>
        public override Boolean Write(Object value, Type type)
        {
            if (value == null) return false;

            // 不支持基本类型
            if (Type.GetTypeCode(type) != TypeCode.Object) return false;

            var ms = GetMembers(type);
            WriteLog("JsonWrite类{0} 共有成员{1}个", type.Name, ms.Count);

            Host.Hosts.Push(value);

            // 获取成员
            foreach (var member in ms)
            {
                if (IgnoreMembers != null && IgnoreMembers.Contains(member.Name)) continue;

                var mtype = GetMemberType(member);
                Host.Member = member;

                var v = value.GetValue(member);
                WriteLog("    {0}.{1} {2}", type.Name, member.Name, v);

                if (!Host.Write(v, mtype))
                {
                    Host.Hosts.Pop();
                    return false;
                }
            }
            Host.Hosts.Pop();

            return true;
        }