コード例 #1
0
 public AutoUpdatePropAttribute(string db_field, data_type data_type, bool nullable)
 {
     DBField  = db_field;
     DataType = data_type;
     Nullable = nullable;
     ReadOnly = false;
 }
コード例 #2
0
ファイル: Convert.cs プロジェクト: karthi1015/RevitTool
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            string text = "";

            //if (values[1] != null)
            //{
            //    if (CollectionViewSource.GetDefaultView(values[1]) != null)
            //    {
            //        if (CollectionViewSource.GetDefaultView(values[1]).Cast<data_parameters>().ToList().Count > 0)
            //        {

            //            text = string.Join("x",CollectionViewSource.GetDefaultView(values[1]).Cast<data_parameters>().OrderByDescending(x => x.ten_parameter).ToList().Where(x => x.group_parameter == "Dimensions").Select(x => x.gia_tri_parameter));
            //        }
            //    }
            //}
            if (values[0] != null)
            {
                if (values[0] is data_type)
                {
                    data_type type      = (data_type)values[0];
                    var       list_name = type.element_type.Name.Split('_').ToList();
                    list_name.RemoveRange(0, 3);
                    text += string.Join("_", list_name);
                }
            }
            return(text);
        }
コード例 #3
0
ファイル: Convert.cs プロジェクト: karthi1015/RevitTool
        public int Compare(object x, object y)
        {
            data_type a = (data_type)x;
            data_type b = (data_type)y;

            return(StrCmpLogicalW(a.type_name, b.type_name));
        }
コード例 #4
0
        public void Write2File(byte[] buffer, int sequence_num, data_type dataType)
        {
            //FileStream 操作字节的
            //1.创建FileStream类对象
            //string fullfilename =  "C:\\testResults\\mask.mc";
            string     fullfilename = Environment.CurrentDirectory + "\\testResults\\mask.mc";
            FileStream fsWrite      = new FileStream(fullfilename, FileMode.OpenOrCreate, FileAccess.Write);

            fsWrite.Write(buffer, 0, buffer.Length);    //每次读取2M放到字节数组里面
            fsWrite.Close();
            fsWrite.Dispose();
        }
コード例 #5
0
        //读取数据, sequence_num读取的数据序列,data_type读取的数据类型,包括全局整像素坐标,全局亚像素
        public string ReadFile(int sequence_num, data_type dataType)
        {
            string     fullfilename = Environment.CurrentDirectory + "\\testResults\\mask.mc";
            FileStream fsread       = new FileStream(fullfilename, FileMode.OpenOrCreate, FileAccess.Read);

            byte[] buffer = new byte[1024 * 1024 * 2];     //定义一个2M的字节数组
            //返回本次实际读取到的有效字节数
            int r = fsread.Read(buffer, 0, buffer.Length); //每次读取2M放到字节数组里面
            //将字节数组中每一个元素按照指定的编码格式解码成字符串
            string s = Encoding.Default.GetString(buffer, 0, r);

            //关闭流
            fsread.Close();
            //释放流所占用的资源
            fsread.Dispose();
            return(s);
        }
コード例 #6
0
ファイル: F_ViewDetail.cs プロジェクト: karthi1015/RevitTool
    {//----------------------------------------------------------
        public static void view_detail(Document doc, data_type type, ObservableCollection <data_parameters> my_parameters, ObservableCollection <data_materials> my_materials,
                                       ObservableCollection <data_material> my_material, ListView thong_tin_kich_thuoc, ListView thong_tin_cong_tac_vat_lieu, string unit_length)
        {
            try
            {
                var elements = new FilteredElementCollector(doc).OfClass(typeof(Material)).ToList();
                my_material.Add(new data_material()
                {
                    name     = "<By Category>",
                    vat_lieu = null
                });
                foreach (Material material in elements)
                {
                    my_material.Add(new data_material()
                    {
                        name     = material.Name,
                        vat_lieu = material
                    });
                }
                var a = my_material.OrderBy(x => x.name).ToList();
                my_material.Clear();
                a.ForEach(x => my_material.Add(x));

                if (type.type_type == Source.type_symbol)
                {
                    F_ParameterSymbol.parameter_symbol(doc, type.element_type, thong_tin_kich_thuoc, my_parameters, unit_length);
                    F_MaterialSymbol.material_symbol(doc, type.element_type, thong_tin_cong_tac_vat_lieu, my_materials, my_material);
                }
                else
                {
                    F_ParameterAndMaterialType.parameter_and_material_type(doc, type.element_type, thong_tin_kich_thuoc, my_parameters, thong_tin_cong_tac_vat_lieu, my_materials, my_material, unit_length);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #7
0
 //--------------------------------------------------------------------------------------------------------------------------------------------------------------
 private void Xem_Thong_Tin_Element_Type(object sender, MouseButtonEventArgs e)
 {
     try
     {
         if (thong_tin_family_type.SelectedItem != null)
         {
             my_parameters = new ObservableCollection <data_parameters>();
             my_materials  = new ObservableCollection <data_materials>();
             my_material   = new ObservableCollection <data_material>();
             thong_tin_kich_thuoc.ItemsSource        = new ObservableCollection <data_parameters>();
             thong_tin_cong_tac_vat_lieu.ItemsSource = new ObservableCollection <data_materials>();
             if (thong_tin_family_type.SelectedItem is data_type)
             {
                 data_type type = (data_type)thong_tin_family_type.SelectedItem;
                 F_ViewDetail.view_detail(doc, type, my_parameters, my_materials, my_material, thong_tin_kich_thuoc, thong_tin_cong_tac_vat_lieu, unit_length);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
コード例 #8
0
        public void CheckItemType()
        {
            if (methodInfo != null)
            {
                datatype = data_type.method;
                return;
            }

            data_type dt = data_type.none;

            if (obj == null)
            {
                //Console.WriteLine("Object was null when checking inspector.item obj type.");
            }
            else if (obj is int)
            {
                dt = data_type.integer;
            }
            else if (obj is Single)
            {
                dt = data_type.single;
            }
            else if (obj is String)
            {
                dt = data_type.str;
            }
            else if (obj is bool)
            {
                dt = data_type.boolean;
            }
            else if (obj is byte)
            {
                dt = data_type.tbyte;
            }
            else if (obj.GetType().IsSubclassOf(typeof(Enum)))
            {
                dt = data_type.enm;
            }
            //else if (obj.GetType().IsGenericType && obj.GetType().GetGenericTypeDefinition() == typeof(Dictionary<,>))
            else if (obj.GetType().GetInterface("IDictionary") != null)
            {
                //System.Console.WriteLine("Dictionary found.");
                dt = data_type.dict;

                //Type keyType = t.GetGenericArguments()[0];
                //Type valueType = t.GetGenericArguments()[1];
            }
            else if (obj is Array)
            {
                dt = data_type.array;
            }
            else if (obj.GetType().GetInterfaces()
                     .Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IEnumerable <>)))
            {
                dt = data_type.collection;
            }
            //might need to be more specific than List
            else if (obj.GetType().IsGenericType&& obj.GetType().GetGenericTypeDefinition() == typeof(List <>))
            {
                Console.WriteLine("List(What?)");
                //System.Console.WriteLine("List found.");
                dt = data_type.list;

                //Type valueType = t.GetGenericArguments()[0];
            }
            else if (obj is Component)
            {
                dt = data_type.obj;
            }
            else
            {
                //foreach (Type type in ValidTypes)
                //{
                //    if (obj.GetType() == type)
                //    {
                //        dt = data_type.obj;
                //    }
                //}
                dt = data_type.obj; //this should be ok (we don't need to specific validtypes anymore)


                //datatype = data_type.none; //support more types in the future
            }

            datatype = dt;
        }
コード例 #9
0
        public static List <InspectorInfo> GenerateList(object parent, InspectorInfo parentItem = null,
                                                        bool GenerateFields = false, UserLevel?userLevel = null)
        {
            UserLevel userlevel = UserLevel.Debug;

            if (userLevel != null)
            {
                userlevel = (UserLevel)userLevel;
            }

            List <InspectorInfo> list = new List <InspectorInfo>();
            //char a = (char)164;
            //System.Console.WriteLine(a);
            //string space = "|";
            //if (parentItem != null) space += parentItem.whitespace;
            //List<FieldInfo> fieldInfos = o.GetType().GetFields().ToList(); //just supporting properties for now
            data_type dt = data_type.obj;

            //if this item is the root, we should give it it's real type in.steam of assuming it's an object
            if (parentItem != null)
            {
                dt = parentItem.datatype;
            }

            if (dt == data_type.collection)
            {
                dynamic collection = parent;
                foreach (object o in collection)
                {
                    InspectorInfo iitem = new InspectorInfo(parentItem.masterList, parentItem, o);
                    if (iitem.CheckForChildren())
                    {
                        iitem.prefix = "+";
                    }
                    InsertItemSorted(list, iitem);
                }
            }
            else if (dt == data_type.array)
            {
                dynamic array = parent;
                foreach (object o in array)
                {
                    InspectorInfo iitem = new InspectorInfo(parentItem.masterList, parentItem, o);
                    if (iitem.CheckForChildren())
                    {
                        iitem.prefix = "+";
                    }
                    InsertItemSorted(list, iitem);
                }
            }
            else if (dt == data_type.dict)
            {
                //dynamic dict = iitem.fpinfo.GetValue(iitem.parentItem);
                dynamic dict = parent;
                foreach (dynamic key in dict.Keys)
                {
                    //System.Console.WriteLine(key.ToString());
                    InspectorInfo iitem = new InspectorInfo(parentItem.masterList, parentItem, dict[key], key);
                    //iitem.GenerateChildren();
                    //list.Add(iitem);
                    if (iitem.CheckForChildren())
                    {
                        iitem.prefix = "+";
                    }
                    InsertItemSorted(list, iitem);
                }
            }
            else if (dt == data_type.obj)
            {
                ///// PROPERTIES
                List <PropertyInfo> propertyInfos;
                //if the object isn't a component, then we only want to see the 'declared' properties (not inherited)
                if (!(parent is Component || parent is Player)) // || parent is Process))
                {
                    propertyInfos =
                        parent.GetType()
                        .GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)
                        .ToList();
                }
                else
                {
                    propertyInfos = parent.GetType().GetProperties().ToList();
                }

                foreach (PropertyInfo pinfo in propertyInfos)
                {
                    string   tooltip      = "";
                    object[] attributes   = pinfo.GetCustomAttributes(false);
                    var      abstractions = pinfo.GetCustomAttributes(typeof(Info), false);
                    if (abstractions.Length > 0)
                    {
                        Info info = (Info)abstractions[0];
                        if ((int)info.userLevel > (int)userlevel)
                        {
                            continue;
                        }
                        tooltip = info.summary;
                    }
                    else if (userlevel != UserLevel.Debug)
                    {
                        continue;
                    }
                    //if (pinfo.Name.Equals("Item")) continue;
                    InspectorInfo iitem = new InspectorInfo(parentItem.masterList, parentItem, pinfo.GetValue(parent, null), pinfo);
                    if (tooltip.Length > 0)
                    {
                        iitem.ToolTip = tooltip;
                    }
                    if (iitem.CheckForChildren())
                    {
                        iitem.prefix = "+";
                    }
                    InsertItemSorted(list, iitem);
                }
                ////// FIELDS
                List <FieldInfo> fieldInfos;
                //if the object isn't a component, then we only want to see the 'declared' properties (not inherited)
                if (!(parent is Component || parent is Player)) // || parent is Process))
                {
                    fieldInfos =
                        parent.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).ToList();
                }
                else
                {
                    fieldInfos = parent.GetType().GetFields().ToList();
                }

                foreach (FieldInfo finfo in fieldInfos)
                {
                    //if (finfo.GetCustomAttributes(typeof(DoNotInspect), false).Length > 0) continue;
                    var abstractions = finfo.GetCustomAttributes(typeof(Info), false);
                    if (abstractions.Length > 0)
                    {
                        if ((int)(abstractions[0] as Info).userLevel > (int)userlevel)
                        {
                            continue;
                        }
                    }
                    else if (userlevel != UserLevel.Debug)
                    {
                        continue;
                    }
                    InspectorInfo iitem = new InspectorInfo(parentItem.masterList, parentItem, finfo.GetValue(parent), finfo);
                    if (iitem.CheckForChildren())
                    {
                        iitem.prefix = "+";
                    }
                    InsertItemSorted(list, iitem);
                }
                ////METHODS
                List <MethodInfo> methodInfos;
                //if the object isn't a component, then we only want to see the 'declared' properties (not inherited)
                if (!(parent is Component || parent is Player)) // || parent is Process))
                {
                    methodInfos =
                        parent.GetType()
                        .GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)
                        .ToList();
                }
                else
                {
                    methodInfos = parent.GetType().GetMethods().ToList();
                }

                foreach (MethodInfo minfo in methodInfos)
                {
                    //if (finfo.GetCustomAttributes(typeof(DoNotInspect), false).Length > 0) continue;
                    var abstractions = minfo.GetCustomAttributes(typeof(Clickable), false);
                    if (abstractions.Length == 0)
                    {
                        continue;
                    }
                    InspectorInfo iitem = new InspectorInfo(parentItem.masterList, parentItem, minfo);
                    InsertItemSorted(list, iitem);
                }
            }
            //if it's just a normal primitive, it will return an empty list
            if (list.Count > 0)
            {
                parentItem.prefix = "+";
            }
            return(list);
        }
コード例 #10
0
        public void CheckItemType()
        {
            if (methodInfo != null)
            {
                datatype = data_type.method;
                return;
            }

            data_type dt = data_type.none;

            if (obj == null)
            {
                //Console.WriteLine("Object was null when checking inspector.item obj type.");
            }
            else if (obj is int)
            {
                dt = data_type.integer;
            }
            else if (obj is Single)
            {
                dt = data_type.single;
            }
            else if (obj is String)
            {
                dt = data_type.str;
            }
            else if (obj is bool)
            {
                dt = data_type.boolean;
            }
            else if (obj is byte)
            {
                dt = data_type.tbyte;
            }
            else if (obj.GetType().IsSubclassOf(typeof(Enum)))
            {
                dt = data_type.enm;
            }
            //else if (obj.GetType().IsGenericType && obj.GetType().GetGenericTypeDefinition() == typeof(Dictionary<,>))
            else if (obj.GetType().GetInterface("IDictionary") != null)
            {
                //System.Console.WriteLine("Dictionary found.");
                dt = data_type.dict;

                //Type keyType = t.GetGenericArguments()[0];
                //Type valueType = t.GetGenericArguments()[1];
            }
            else if (obj is Array)
            {
                dt = data_type.array;
            }
            else if (obj.GetType().GetInterfaces()
                .Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IEnumerable<>)))
            {
                dt = data_type.collection;
            }
            //might need to be more specific than List
            else if (obj.GetType().IsGenericType && obj.GetType().GetGenericTypeDefinition() == typeof(List<>))
            {
                Console.WriteLine("List(What?)");
                //System.Console.WriteLine("List found.");
                dt = data_type.list;

                //Type valueType = t.GetGenericArguments()[0];

            }
            else if (obj is Component)
            {
                dt = data_type.obj;
            }
            else
            {

                //foreach (Type type in ValidTypes)
                //{
                //    if (obj.GetType() == type)
                //    {
                //        dt = data_type.obj;
                //    }
                //}
                dt = data_type.obj; //this should be ok (we don't need to specific validtypes anymore)

                //datatype = data_type.none; //support more types in the future
            }

            datatype = dt;
        }
コード例 #11
0
        internal static int convert_from_db_datatype(
            data_type target_type, object original_value, out object out_value)
        {
            out_value = null;
            if (original_value == null)
            {
                return(0);
            }

            switch (target_type)
            {
            default:
            case data_type.text:
                out_value = original_value.ToString();
                return(0);

            case data_type.number:
                try
                {
                    if (original_value.ToString() == "")
                    {
                        return(0);
                    }
                    out_value = Convert.ToInt32(original_value.ToString());
                    return(0);
                }
                catch (Exception e)
                {
                    throw e;
                    Debug.HandleException(new Exception(string.Format(
                                                            "Cannot convert {0} from string to number",
                                                            original_value.ToString()), e));
                    return(1);
                }

            case data_type.boolean:
                if (original_value is bool)
                {
                    out_value = original_value;
                    return(0);
                }
                else
                {
                    object num;
                    int    result = convert_from_db_datatype(data_type.number,
                                                             original_value, out num);
                    if (result == 0)
                    {
                        out_value = ((int)num == 0) ? false : true;
                    }
                    return(result);
                }

            case data_type.number_array:
                string[] s = ((string)original_value).Split(new string[] { "," },
                                                            StringSplitOptions.RemoveEmptyEntries);
                ArrayList nums = new ArrayList();

                for (int i = 0; i < s.Length; i++)
                {
                    nums.Add(Convert.ToInt32(s[i]));
                }
                out_value = nums.ToArray(typeof(int));
                return(0);
            }
        }
コード例 #12
0
        internal static int convert_to_db_datatype(
            data_type target_type, object original_value, out object out_value)
        {
            out_value = null;
            if (original_value == null)
            {
                return(0);
            }

            switch (target_type)
            {
            default:
            case data_type.text:
                out_value = Database.Quote(original_value.ToString());
                return(0);

            case data_type.number:
                try
                {
                    if (original_value.GetType().IsSubclassOf(typeof(System.Enum)))
                    {
                        out_value = Convert.ToInt32(original_value);
                    }
                    else
                    {
                        out_value = Convert.ToInt32(original_value.ToString());
                    }
                    if ((int)out_value == 0)
                    {
                        throw new Exception("debug only... you sure 0 here is fine?");
                    }
                    return(0);
                }
                catch (Exception e)
                {
                    throw e;
                    Debug.HandleException(new Exception(string.Format(
                                                            "Cannot convert {0} from string to number",
                                                            original_value.ToString()), e));
                    return(1);
                }

            case data_type.boolean:
                if (original_value is bool)
                {
                    out_value = ((bool)original_value) ? 1 : 0;
                    return(0);
                }
                else
                {
                    object num;
                    int    result = convert_to_db_datatype(data_type.number,
                                                           original_value, out num);
                    if (result == 0)
                    {
                        out_value = ((int)num == 0) ? 0 : 1;
                    }
                    return(result);
                }

            case data_type.number_array:
                if (original_value is int[])
                {
                    int[] nums = (int[])original_value;
                    if (nums.Length == 0)
                    {
                        return(0);
                    }

                    StringBuilder s = new StringBuilder();
                    for (int i = 0; i < nums.Length; i++)
                    {
                        s.Append(nums[i].ToString() + ",");
                    }
                    out_value = Database.Quote(s.ToString());
                    return(0);
                }
                else
                {
                    return(1);
                }
            }
        }
コード例 #13
0
        internal static bool is_same(data_type target_type, object v1, object v2)
        {
            if (v1 == null && v2 == null)
            {
                return(true);
            }
            else if (v1 == null || v2 == null)
            {
                return(false);
            }

            switch (target_type)
            {
            default:
            case data_type.text:
                return(v1.ToString() == v2.ToString());

            case data_type.number:
                try
                {
                    int i1 = Convert.ToInt32(v1.GetType().IsSubclassOf(typeof(System.Enum)) ? v1 : v1.ToString());
                    int i2 = Convert.ToInt32(v2.GetType().IsSubclassOf(typeof(System.Enum)) ? v2 : v2.ToString());
                    return(i1 == i2);
                }
                catch (Exception e)
                {
                    throw new Exception(string.Format("Cannot compare {0} and {1} as number",
                                                      v1.ToString(), v2.ToString()), e);
                }

            case data_type.boolean:
                if (v1 is bool && v2 is bool)
                {
                    return((bool)v1 == (bool)v2);
                }
                else
                {
                    return(is_same(data_type.number, v1, v2));
                }

            case data_type.number_array:
                if (v1 is int[] && v2 is int[])
                {
                    if (((int[])v1).Length != ((int[])v2).Length)
                    {
                        return(false);
                    }

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

                    return(true);
                }
                else
                {
                    throw new Exception(string.Format("Cannot compare {0} and {1} as number array!",
                                                      v1.ToString(), v2.ToString()));
                }
            }
        }
コード例 #14
0
ファイル: E_Create.cs プロジェクト: karthi1015/RevitTool
        //----------------------------------------------------------
        public string Tao_Type_Project(UIApplication uiapp, Document doc)
        {
            string result = "F";

            try
            {
                data_type type = (data_type)thong_tin_family_type.SelectedItem;
                if (my_family.First(x => x.ten_family_type == type.element_type.FamilyName).Children.Any(x => x.ten_element_type == name.Text) == false)
                {
                    if (type.type_type == Source.type_symbol)
                    {
                        FamilySymbol symbol = type.element_type.Duplicate(name.Text) as FamilySymbol;

                        foreach (data_parameters parameters in my_parameters)
                        {
                            if (symbol.LookupParameter(parameters.parameter.Definition.Name).StorageType == StorageType.Integer)
                            {
                                symbol.LookupParameter(parameters.parameter.Definition.Name).Set(parameters.gia_tri_parameter == "False" ? 0 : (parameters.gia_tri_parameter == "True" ? 1 : (Convert.ToInt32(parameters.gia_tri_parameter))));
                            }
                            else
                            {
                                if (parameters.parameter.DisplayUnitType.ToString() == "DUT_DECIMAL_DEGREES")
                                {
                                    symbol.LookupParameter(parameters.parameter.Definition.Name).Set(Convert.ToDouble(parameters.gia_tri_parameter) / Source.units_convert.First(x => x.name == "deg").value);
                                }
                                else
                                {
                                    symbol.LookupParameter(parameters.parameter.Definition.Name).Set(Convert.ToDouble(parameters.gia_tri_parameter) / Source.units_document.First(x => x.name == unit_length).value);
                                }
                            }
                        }
                        foreach (data_materials material in my_materials)
                        {
                            if (material.ten_vat_lieu.name != "<By Category>")
                            {
                                symbol.LookupParameter(material.parameter.Definition.Name).Set(material.ten_vat_lieu.vat_lieu.Id);
                            }
                            else
                            {
                                symbol.LookupParameter(material.parameter.Definition.Name).Set(new ElementId(-1));
                            }
                        }
                        data_type element_Type = new data_type()
                        {
                            ten_element_type = name.Text,
                            element_type     = symbol,
                            type_type        = Source.type_symbol,
                            delete_type      = false
                        };

                        my_family.First(x => x.ten_family_type == symbol.FamilyName).Children.Add(element_Type);
                        result = "S";
                    }
                    else
                    {
                        ElementType elementType = type.element_type as ElementType;

                        ElementType elementType_new = F_SetParameterAndMaterialType.set_elementtype(null, my_materials, my_parameters, elementType, Source.Duplicate, name.Text, unit_length);

                        data_type element_Type = new data_type()
                        {
                            ten_element_type = name.Text,
                            element_type     = elementType_new,
                            type_type        = Source.type_element,
                            delete_type      = false,
                            ValueIsSelect    = true
                        };

                        my_family.First(x => x.ten_family_type == elementType.FamilyName).Children.Add(element_Type);
                        result = "S";
                    }
                    thong_tin_family_type.Items.Refresh();
                }
                else
                {
                    MessageBox.Show("The type name you supplied is already in use. Enter a unique name.", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(result);
        }