Ejemplo n.º 1
0
        private void AddMethodToData(MethodInfo mi)
        {
            Type methodType = mi.ReturnType;

            try
            {
                object returnValue;
                if (mi.Name == "ConvertToStableRepresentation")
                {
                    returnValue = mi.Invoke(elem, new object[] { application.ActiveUIDocument.Document });
                }
                else
                {
                    returnValue = mi.Invoke(elem, new object[0]);
                }
                DataTypeInfoHelper.AddDataFromTypeInfo(application, mi, methodType, returnValue, elem, data);
            }
            catch (TargetException ex)
            {
                data.Add(new Snoop.Data.Exception(mi.Name, ex));
            }
            catch (TargetInvocationException ex)
            {
                data.Add(new Snoop.Data.Exception(mi.Name, ex));
            }
            catch (TargetParameterCountException ex)
            {
                data.Add(new Snoop.Data.Exception(mi.Name, ex));
            }
        }
Ejemplo n.º 2
0
        public Data.Data Create(MethodInfo methodInfo)
        {
            var declaringType = methodInfo.DeclaringType;

            if (methodInfo.IsSpecialName || declaringType == null)
            {
                return(null);
            }

#if !V2017 && !V2018
            if (declaringType == typeof(Element) && methodInfo.Name == nameof(Element.GetDependentElements))
            {
                var element = (Element)elem;

                return(DataTypeInfoHelper.CreateFrom(application, methodInfo, element.GetDependentElements(null), element));
            }
#endif
            if (declaringType == typeof(Element) && methodInfo.Name == nameof(Element.GetPhaseStatus))
            {
                return(new ElementPhaseStatuses(methodInfo.Name, (Element)elem));
            }

            if (declaringType == typeof(Reference) && methodInfo.Name == nameof(Reference.ConvertToStableRepresentation))
            {
                var reference = (Reference)elem;

                return(DataTypeInfoHelper.CreateFrom(application, methodInfo, reference.ConvertToStableRepresentation(application.ActiveUIDocument.Document), reference));
            }

            if (declaringType == typeof(View) && methodInfo.Name == nameof(View.GetFilterOverrides))
            {
                return(new ViewFiltersOverrideGraphicSettings(methodInfo.Name, (View)elem));
            }

            if (declaringType == typeof(View) && methodInfo.Name == nameof(View.GetFilterVisibility))
            {
                return(new ViewFiltersVisibilitySettings(methodInfo.Name, (View)elem));
            }

            if (declaringType == typeof(Document) && methodInfo.Name == nameof(Document.Close))
            {
                return(null);
            }

            if (methodInfo.GetParameters().Any() || methodInfo.ReturnType == typeof(void))
            {
                return(null);
            }

            var returnValue = methodInfo.Invoke(elem, new object[0]);

            return(DataTypeInfoHelper.CreateFrom(application, methodInfo, returnValue, elem));
        }
Ejemplo n.º 3
0
        private void AddPropertyToData(PropertyInfo pi)
        {
            Type propertyType = pi.PropertyType;

            try
            {
                object propertyValue;
                if (pi.Name == "Geometry")
                {
                    propertyValue = pi.GetValue(elem, new object[1] {
                        new Options()
                    });
                }
                else if (pi.Name == "BoundingBox")
                {
                    propertyValue = pi.GetValue(elem, new object[1] {
                        application.ActiveUIDocument.ActiveView
                    });
                }
                else if (pi.Name == "Parameter")
                {
                    return;
                }
                else
                {
                    propertyValue = pi.GetValue(elem);
                }

                DataTypeInfoHelper.AddDataFromTypeInfo(application, pi, propertyType, propertyValue, elem, data);

                var category = elem as Category;
                if (category != null && pi.Name == "Id" && category.Id.IntegerValue < 0)
                {
                    var bic = (BuiltInCategory)category.Id.IntegerValue;

                    data.Add(new Snoop.Data.String("BuiltInCategory", bic.ToString()));
                }
            }
            catch (TargetException ex)
            {
                data.Add(new Snoop.Data.Exception(pi.Name, ex));
            }
            catch (TargetInvocationException ex)
            {
                data.Add(new Snoop.Data.Exception(pi.Name, ex));
            }
            catch (TargetParameterCountException ex)
            {
                data.Add(new Snoop.Data.Exception(pi.Name, ex));
            }
        }
Ejemplo n.º 4
0
        public Data.Data Create(MethodInfo methodInfo)
        {
            var declaringType = methodInfo.DeclaringType;

            if (methodInfo.IsSpecialName || declaringType == null)
                return null;

            if (declaringType == typeof(Element) && methodInfo.Name == nameof(Element.GetDependentElements))
            {
                var element = (Element) elem;

                try
                {
                    return DataTypeInfoHelper.CreateFrom(application, methodInfo, element.GetDependentElements(null), element);
                }
                catch (Autodesk.Revit.Exceptions.ArgumentNullException ex)
                {
                    return new Data.Exception(methodInfo.Name, ex);
                }
            }

            if (declaringType == typeof (Element) && methodInfo.Name == nameof(Element.GetPhaseStatus))
                return new ElementPhaseStatuses(methodInfo.Name, (Element) elem);

            if (declaringType == typeof(Reference) && methodInfo.Name == nameof(Reference.ConvertToStableRepresentation))
            {
                var reference = (Reference)elem;

                return DataTypeInfoHelper.CreateFrom(application, methodInfo, reference.ConvertToStableRepresentation(application.ActiveUIDocument.Document), reference);
            }

            if (declaringType == typeof (View) && methodInfo.Name == nameof(View.GetFilterOverrides))
               return new ViewFiltersOverrideGraphicSettings(methodInfo.Name, (View) elem);

            if (declaringType == typeof(View) && methodInfo.Name == nameof(View.GetFilterVisibility))
                return new ViewFiltersVisibilitySettings(methodInfo.Name, (View) elem);

            if (declaringType == typeof (Document) && methodInfo.Name == nameof(Document.Close))
                return null;

            if (methodInfo.GetParameters().Any() || methodInfo.ReturnType == typeof (void))
                return null;

            var returnValue = methodInfo.Invoke(elem, new object[0]);

            return DataTypeInfoHelper.CreateFrom(application, methodInfo, returnValue, elem);
        }
Ejemplo n.º 5
0
        private void AddMethodToData(MethodInfo mi)
        {
            Type methodType = mi.ReturnType;

            try
            {
                var returnValue = mi.Invoke(elem, new object[0]);
                DataTypeInfoHelper.AddDataFromTypeInfo(application, mi, methodType, returnValue, elem, data);
            }
            catch (TargetException ex)
            {
                data.Add(new Snoop.Data.Exception(mi.Name, ex));
            }
            catch (TargetInvocationException ex)
            {
                data.Add(new Snoop.Data.Exception(mi.Name, ex));
            }
            catch (TargetParameterCountException ex)
            {
                data.Add(new Snoop.Data.Exception(mi.Name, ex));
            }
        }
Ejemplo n.º 6
0
        public Data.Data Create(MethodInfo mi)
        {
            var methodInfo = mi.ContainsGenericParameters ? elem.GetType().GetMethod(mi.Name, mi.GetParameters().Select(x => x.ParameterType).ToArray()) : mi;

            if (methodInfo == null)
            {
                return(null);
            }

            var declaringType = methodInfo.DeclaringType;

            if (methodInfo.IsSpecialName || declaringType == null)
            {
                return(null);
            }

            if (declaringType == typeof(Element) && methodInfo.Name == nameof(Element.GetDependentElements))
            {
                var element = (Element)elem;

                return(DataTypeInfoHelper.CreateFrom(application, methodInfo, element.GetDependentElements(null), element));
            }

            if (declaringType == typeof(Element) && methodInfo.Name == nameof(Element.GetPhaseStatus))
            {
                return(new ElementPhaseStatuses(methodInfo.Name, (Element)elem));
            }

            if (declaringType == typeof(Reference) && methodInfo.Name == nameof(Reference.ConvertToStableRepresentation))
            {
                var reference = (Reference)elem;

                return(DataTypeInfoHelper.CreateFrom(application, methodInfo, reference.ConvertToStableRepresentation(application.ActiveUIDocument.Document), reference));
            }

            if (declaringType == typeof(View) && methodInfo.Name == nameof(View.GetFilterOverrides))
            {
                return(new ViewFiltersOverrideGraphicSettings(methodInfo.Name, (View)elem));
            }

            if (declaringType == typeof(View) && methodInfo.Name == nameof(View.GetFilterVisibility))
            {
                return(new ViewFiltersVisibilitySettings(methodInfo.Name, (View)elem));
            }

            if (declaringType == typeof(View) && methodInfo.Name == nameof(View.GetNonControlledTemplateParameterIds))
            {
                return(new ViewGetNonControlledTemplateParameterIds(methodInfo.Name, (View)elem));
            }

            if (declaringType == typeof(View) && methodInfo.Name == nameof(View.GetTemplateParameterIds))
            {
                return(new ViewGetTemplateParameterIds(methodInfo.Name, (View)elem));
            }

            if (declaringType == typeof(ScheduleDefinition) && methodInfo.Name == nameof(ScheduleDefinition.GetField))
            {
                var parameters = methodInfo.GetParameters();
                if (parameters[0].ParameterType == typeof(int))
                {
                    return(new ScheduleDefinitionGetFields(methodInfo.Name, (ScheduleDefinition)elem));
                }
            }

            if (declaringType == typeof(ViewCropRegionShapeManager) && methodInfo.Name == nameof(ViewCropRegionShapeManager.GetSplitRegionOffset))
            {
                return(new ViewCropRegionShapeManagerGetSplitRegionOffsets(methodInfo.Name, (ViewCropRegionShapeManager)elem));
            }

            if (declaringType == typeof(Curve) && methodInfo.Name == nameof(Curve.GetEndPoint))
            {
                return(new CurveGetEndPoint(methodInfo.Name, (Curve)elem));
            }

            if (declaringType == typeof(TableData) && methodInfo.Name == nameof(TableData.GetSectionData))
            {
                var parameters = methodInfo.GetParameters();
                if (parameters[0].ParameterType == typeof(SectionType))
                {
                    return(new TableDataSectionData(methodInfo.Name, (TableData)elem));
                }
            }

            if (declaringType == typeof(PlanViewRange) && methodInfo.Name == nameof(PlanViewRange.GetLevelId))
            {
                return(new PlanViewRangeGetLevelId(methodInfo.Name, (PlanViewRange)elem, application.ActiveUIDocument.Document));
            }

            if (declaringType == typeof(PlanViewRange) && methodInfo.Name == nameof(PlanViewRange.GetOffset))
            {
                return(new PlanViewRangeGetOffset(methodInfo.Name, (PlanViewRange)elem));
            }

            if (declaringType == typeof(Document) && methodInfo.Name == nameof(Document.Close))
            {
                return(null);
            }

            if (methodInfo.GetParameters().Any() || methodInfo.ReturnType == typeof(void))
            {
                return(null);
            }

            var returnValue = methodInfo.Invoke(elem, new object[0]);

            return(DataTypeInfoHelper.CreateFrom(application, methodInfo, returnValue, elem));
        }
Ejemplo n.º 7
0
        public Data.Data Create(MethodInfo methodInfo)
        {
            var declaringType = methodInfo.DeclaringType;

            if (methodInfo.IsSpecialName || declaringType == null)
            {
                return(null);
            }

            if (declaringType == typeof(Element) && methodInfo.Name == nameof(Element.GetDependentElements))
            {
                var element = (Element)elem;

                return(DataTypeInfoHelper.CreateFrom(application, methodInfo, element.GetDependentElements(null), element));
            }

            if (declaringType == typeof(Element) && methodInfo.Name == nameof(Element.GetPhaseStatus))
            {
                return(new ElementPhaseStatuses(methodInfo.Name, (Element)elem));
            }

            if (declaringType == typeof(Reference) && methodInfo.Name == nameof(Reference.ConvertToStableRepresentation))
            {
                var reference = (Reference)elem;

                return(DataTypeInfoHelper.CreateFrom(application, methodInfo, reference.ConvertToStableRepresentation(application.ActiveUIDocument.Document), reference));
            }

            if (declaringType == typeof(View) && methodInfo.Name == nameof(View.GetFilterOverrides))
            {
                return(new ViewFiltersOverrideGraphicSettings(methodInfo.Name, (View)elem));
            }

            if (declaringType == typeof(View) && methodInfo.Name == nameof(View.GetFilterVisibility))
            {
                return(new ViewFiltersVisibilitySettings(methodInfo.Name, (View)elem));
            }

            if (declaringType == typeof(View) && methodInfo.Name == nameof(View.GetNonControlledTemplateParameterIds))
            {
                return(new ViewGetNonControlledTemplateParameterIds(methodInfo.Name, (View)elem));
            }

            if (declaringType == typeof(View) && methodInfo.Name == nameof(View.GetTemplateParameterIds))
            {
                return(new ViewGetTemplateParameterIds(methodInfo.Name, (View)elem));
            }

            if (declaringType == typeof(ScheduleDefinition) && methodInfo.Name == nameof(ScheduleDefinition.GetField))
            {
                var parameters = methodInfo.GetParameters();
                if (parameters[0].ParameterType == typeof(int))
                {
                    return(new ScheduleDefinitionGetFields(methodInfo.Name, (ScheduleDefinition)elem));
                }
            }

            if (declaringType == typeof(ViewCropRegionShapeManager) && methodInfo.Name == nameof(ViewCropRegionShapeManager.GetSplitRegionOffset))
            {
                return(new ViewCropRegionShapeManagerGetSplitRegionOffsets(methodInfo.Name, (ViewCropRegionShapeManager)elem));
            }

            if (declaringType == typeof(Document) && methodInfo.Name == nameof(Document.Close))
            {
                return(null);
            }

            if (methodInfo.GetParameters().Any() || methodInfo.ReturnType == typeof(void))
            {
                return(null);
            }

            var returnValue = methodInfo.Invoke(elem, new object[0]);

            return(DataTypeInfoHelper.CreateFrom(application, methodInfo, returnValue, elem));
        }
Ejemplo n.º 8
0
        private void AddPropertyToData(PropertyInfo pi)
        {
            var propertyInfo = pi.PropertyType.ContainsGenericParameters ? elem.GetType().GetProperty(pi.Name) : pi;

            if (propertyInfo == null)
            {
                return;
            }

            var propertyType = propertyInfo.PropertyType;

            try
            {
                object propertyValue;
                if (propertyInfo.Name == "Geometry")
                {
                    propertyValue = propertyInfo.GetValue(elem, new object[1] {
                        new Options()
                    });
                }
                else if (propertyInfo.Name == "BoundingBox")
                {
                    propertyValue = propertyInfo.GetValue(elem, new object[1] {
                        application.ActiveUIDocument.ActiveView
                    });
                }
                else if (propertyInfo.Name == "Item")
                {
                    propertyValue = propertyInfo.GetValue(elem, new object[1] {
                        0
                    });
                }
                else if (propertyInfo.Name == "Parameter")
                {
                    return;
                }
                else if (propertyInfo.Name == "PlanTopology")
                {
                    return;
                }
                else if (propertyInfo.Name == "PlanTopologies" && propertyInfo.GetMethod.GetParameters().Length != 0)
                {
                    return;
                }
                else if (propertyType.ContainsGenericParameters)
                {
                    propertyValue = elem.GetType().GetProperty(propertyInfo.Name)?.GetValue(elem);
                }
                else
                {
                    propertyValue = propertyInfo.GetValue(elem);
                }

                DataTypeInfoHelper.AddDataFromTypeInfo(application, propertyInfo, propertyType, propertyValue, elem, data);

                var category = elem as Category;
                if (category != null && propertyInfo.Name == "Id" && category.Id.IntegerValue < 0)
                {
                    var bic = (BuiltInCategory)category.Id.IntegerValue;

                    data.Add(new Snoop.Data.String("BuiltInCategory", bic.ToString()));
                }
            }
            catch (ArgumentException ex)
            {
                data.Add(new Snoop.Data.Exception(propertyInfo.Name, ex));
            }
            catch (TargetException ex)
            {
                data.Add(new Snoop.Data.Exception(propertyInfo.Name, ex));
            }
            catch (TargetInvocationException ex)
            {
                data.Add(new Snoop.Data.Exception(propertyInfo.Name, ex));
            }
            catch (TargetParameterCountException ex)
            {
                data.Add(new Snoop.Data.Exception(propertyInfo.Name, ex));
            }
        }