public static System.ComponentModel.AttributeCollection FromExisting(System.ComponentModel.AttributeCollection existing, Attribute[] newAttributes)
        {
            Contract.Ensures((newAttributes.Length - Contract.OldValue(newAttributes.Length)) <= 0);
            Contract.Ensures(Contract.Result <System.ComponentModel.AttributeCollection>() != null);

            return(default(System.ComponentModel.AttributeCollection));
        }
        internal static TResult GetAttributePropertyValue <TAttribute, TResult>(this System.ComponentModel.AttributeCollection attributes, Func <TAttribute, TResult> propertyGetter, TResult defaultValue)
            where TAttribute : Attribute
        {
            var attribute = attributes.FirstOrDefault <TAttribute>();

            return(attribute.GetPropertyValue <TAttribute, TResult>(propertyGetter, defaultValue));
        }
        public static void Clear(this System.ComponentModel.AttributeCollection ac)
        {
            var fi = ac.GetType().GetField("_attributes", BindingFlags.NonPublic | BindingFlags.Instance);

            if (fi != null)
            {
                fi.SetValue(ac, null);
            }
        }
        public static Attribute[] ToArray(this System.ComponentModel.AttributeCollection ac)
        {
            var fi = ac.GetType().GetField("_attributes", BindingFlags.NonPublic | BindingFlags.Instance);

            if (fi == null)
            {
                return(null);
            }
            var arrAttr = (Attribute[])fi.GetValue(ac);

            return(arrAttr);
        }
        public static Attribute Get(this System.ComponentModel.AttributeCollection ac, Type attributeType)
        {
            var fi = ac.GetType().GetField("_attributes", BindingFlags.NonPublic | BindingFlags.Instance);

            if (fi == null)
            {
                return(null);
            }
            var arrAttr   = (Attribute[])fi.GetValue(ac);
            var attrFound = arrAttr.FirstOrDefault(a => a.GetType() == attributeType);

            return(attrFound);
        }
Exemplo n.º 6
0
    public static void Main()
    {
        System.ComponentModel.AttributeCollection myAttributes =
            TypeDescriptor.GetAttributes(typeof(SimpleWebControl));

        DataBindingHandlerAttribute myDataBindingHandlerAttribute =
            myAttributes[typeof(DataBindingHandlerAttribute)] as DataBindingHandlerAttribute;

        if (myDataBindingHandlerAttribute != null)
        {
            Console.Write("DataBindingHandlerAttribute's HandlerTypeName is : " +
                          myDataBindingHandlerAttribute.HandlerTypeName);
        }
    }
        public static void Add(this System.ComponentModel.AttributeCollection ac, Attribute attribute)
        {
            var fi = ac.GetType().GetField("_attributes", BindingFlags.NonPublic | BindingFlags.Instance);

            if (fi == null)
            {
                return;
            }

            var arrAttr  = (Attribute[])fi.GetValue(ac);
            var listAttr = new List <Attribute>();

            if (arrAttr != null)
            {
                listAttr.AddRange(arrAttr);
            }
            listAttr.Add(attribute);
            fi.SetValue(ac, listAttr.ToArray());
        }
        public static Attribute Get(this System.ComponentModel.AttributeCollection ac, Type attributeType, bool derivedType)
        {
            var fi = ac.GetType().GetField("_attributes", BindingFlags.NonPublic | BindingFlags.Instance);

            if (fi == null)
            {
                return(null);
            }
            var       arrAttr = (Attribute[])fi.GetValue(ac);
            Attribute attrFound;

            if (!derivedType)
            {
                attrFound = arrAttr.FirstOrDefault(a => a.GetType() == attributeType);
            }
            else
            {
                attrFound = arrAttr.FirstOrDefault(a => a.GetType() == attributeType || a.GetType().IsSubclassOf(attributeType));
            }
            return(attrFound);
        }
        public static List <Attribute> Get(this System.ComponentModel.AttributeCollection ac, params Type[] attributeTypes)
        {
            var fi = ac.GetType().GetField("_attributes", BindingFlags.NonPublic | BindingFlags.Instance);

            if (fi == null)
            {
                return(new List <Attribute>());
            }
            var arrAttr = (Attribute[])fi.GetValue(ac);

            if (arrAttr == null)
            {
                return(null);
            }
            var listAttr = new List <Attribute>();

            listAttr.AddRange(arrAttr);
            // ReSharper disable once PossibleMistakenCallToGetType.2
            var listAttrFound = listAttr.FindAll(a => a.GetType() == attributeTypes.FirstOrDefault(b => b.GetType() == a.GetType()));

            return(listAttrFound);
        }
        public static void Add(this System.ComponentModel.AttributeCollection ac, Attribute attribute, Type typeToRemoveBeforeAdd)
        {
            var fi = ac.GetType().GetField("_attributes", BindingFlags.NonPublic | BindingFlags.Instance);

            if (fi == null)
            {
                return;
            }

            var arrAttr  = (Attribute[])fi.GetValue(ac);
            var listAttr = new List <Attribute>();

            if (arrAttr != null)
            {
                listAttr.AddRange(arrAttr);
            }
            if (typeToRemoveBeforeAdd != null)
            {
                listAttr.RemoveAll(a => a.GetType() == typeToRemoveBeforeAdd || a.GetType().IsSubclassOf(typeToRemoveBeforeAdd));
            }
            listAttr.Add(attribute);
            fi.SetValue(ac, listAttr.ToArray());
        }
        public static List <Attribute> Get(this System.ComponentModel.AttributeCollection ac, params Attribute[] attributes)
        {
            var fi = ac.GetType().GetField("_attributes", BindingFlags.NonPublic | BindingFlags.Instance);

            if (fi == null)
            {
                return(new List <Attribute>());
            }

            var arrAttr = (Attribute[])fi.GetValue(ac);

            if (arrAttr == null)
            {
                return(null);
            }
            var listAttr = new List <Attribute>();

            listAttr.AddRange(arrAttr);
            var ac2           = new System.ComponentModel.AttributeCollection(attributes);
            var listAttrFound = listAttr.FindAll(a => ac2.Matches(a));

            return(listAttrFound);
        }
Exemplo n.º 12
0
        public static void DescribeComponent(object instance, ScriptComponentDescriptor descriptor, IUrlResolutionService urlResolver, IControlResolver controlResolver)
        {
            // validate preconditions
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }
            if (descriptor == null)
            {
                throw new ArgumentNullException("descriptor");
            }
            if (urlResolver == null)
            {
                urlResolver = instance as IUrlResolutionService;
            }
            if (controlResolver == null)
            {
                controlResolver = instance as IControlResolver;
            }

            // describe properties
            // PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(instance);

            PropertyInfo[] properties = instance.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

            foreach (PropertyInfo prop in properties)
            {
                ScriptControlPropertyAttribute propAttr  = null;
                ScriptControlEventAttribute    eventAttr = null;
                string propertyName = prop.Name;

                System.ComponentModel.AttributeCollection attribs = new System.ComponentModel.AttributeCollection(Attribute.GetCustomAttributes(prop, false));

                // Try getting a property attribute
                propAttr = (ScriptControlPropertyAttribute)attribs[typeof(ScriptControlPropertyAttribute)];
                if (propAttr == null || !propAttr.IsScriptProperty)
                {
                    // Try getting an event attribute
                    eventAttr = (ScriptControlEventAttribute)attribs[typeof(ScriptControlEventAttribute)];
                    if (eventAttr == null || !eventAttr.IsScriptEvent)
                    {
                        continue;
                    }
                }

                // attempt to rename the property/event
                ClientPropertyNameAttribute nameAttr = (ClientPropertyNameAttribute)attribs[typeof(ClientPropertyNameAttribute)];
                if (nameAttr != null && !string.IsNullOrEmpty(nameAttr.PropertyName))
                {
                    propertyName = nameAttr.PropertyName;
                }

                // determine whether to serialize the value of a property.  readOnly properties should always be serialized
                //bool serialize = true;// prop.ShouldSerializeValue(instance) || prop.IsReadOnly;
                //if (serialize)
                //{
                // get the value of the property, skip if it is null
                Control c     = null;
                object  value = prop.GetValue(instance, new object[0] {
                });
                if (value == null)
                {
                    continue;
                }

                // convert and resolve the value
                if (eventAttr != null && prop.PropertyType != typeof(String))
                {
                    throw new InvalidOperationException("ScriptControlEventAttribute can only be applied to a property with a PropertyType of System.String.");
                }
                else
                {
                    if (!prop.PropertyType.IsPrimitive && !prop.PropertyType.IsEnum)
                    {
                        if (prop.PropertyType == typeof(Color))
                        {
                            value = ColorTranslator.ToHtml((Color)value);
                        }
                        else
                        {
                            // TODO: Determine if we should let ASP.NET AJAX handle this type of conversion, as it supports JSON serialization
                            //TypeConverter conv = prop.Converter;
                            //value = conv.ConvertToString(null, CultureInfo.InvariantCulture, value);

                            //if (prop.PropertyType == typeof(CssStyleCollection))
                            //    value = (new CssStyleCollectionJSCoverter()).Serialize(value, new JavaScriptSerializer());
                            //if (prop.PropertyType == typeof(Style))
                            //    value = (new CssStyleCollectionJSCoverter()).Serialize(((Style)value).GetStyleAttributes(null), new JavaScriptSerializer());

                            Type valueType = value.GetType();

                            JavaScriptConverterAttribute attr      = (JavaScriptConverterAttribute)attribs[typeof(JavaScriptConverterAttribute)];
                            JavaScriptConverter          converter = attr != null ?
                                                                     (JavaScriptConverter)TypeCreator.CreateInstance(attr.ConverterType) :
                                                                     JsonSerializerFactory.GetJavaScriptConverter(valueType);

                            if (converter != null)
                            {
                                value = converter.Serialize(value, JsonSerializerFactory.GetJavaScriptSerializer());
                            }
                            else
                            {
                                value = JsonHelper.PreSerializeObject(value);
                            }

                            //Dictionary<string, object> dict = value as Dictionary<string, object>;
                            //if (dict != null && !dict.ContainsKey("__type"))
                            //    dict["__type"] = valueType.AssemblyQualifiedName;
                        }
                    }
                    if (attribs[typeof(IDReferencePropertyAttribute)] != null && controlResolver != null)
                    {
                        c = controlResolver.ResolveControl((string)value);
                    }
                    if (attribs[typeof(UrlPropertyAttribute)] != null && urlResolver != null)
                    {
                        value = urlResolver.ResolveClientUrl((string)value);
                    }
                }

                // add the value as an appropriate description
                if (eventAttr != null)
                {
                    if (!string.IsNullOrEmpty((string)value))
                    {
                        descriptor.AddEvent(propertyName, (string)value);
                    }
                }
                else if (attribs[typeof(ElementReferenceAttribute)] != null)
                {
                    if (c == null && controlResolver != null)
                    {
                        c = controlResolver.ResolveControl((string)value);
                    }
                    if (c != null)
                    {
                        value = c.ClientID;
                    }
                    descriptor.AddElementProperty(propertyName, (string)value);
                }
                else if (attribs[typeof(ComponentReferenceAttribute)] != null)
                {
                    if (c == null && controlResolver != null)
                    {
                        c = controlResolver.ResolveControl((string)value);
                    }
                    if (c != null)
                    {
                        //ExtenderControlBase ex = c as ExtenderControlBase;
                        //if (ex != null && ex.BehaviorID.Length > 0)
                        //    value = ex.BehaviorID;
                        //else
                        value = c.ClientID;
                    }
                    descriptor.AddComponentProperty(propertyName, (string)value);
                }
                else
                {
                    if (c != null)
                    {
                        value = c.ClientID;
                    }
                    descriptor.AddProperty(propertyName, value);
                }
            }
            //}

            // determine if we should describe methods
            foreach (MethodInfo method in instance.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public))
            {
                ScriptControlMethodAttribute methAttr = (ScriptControlMethodAttribute)Attribute.GetCustomAttribute(method, typeof(ScriptControlMethodAttribute));
                if (methAttr == null || !methAttr.IsScriptMethod)
                {
                    continue;
                }

                // We only need to support emitting the callback target and registering the WebForms.js script if there is at least one valid method
                Control control = instance as Control;
                if (control != null)
                {
                    // Force WebForms.js
                    control.Page.ClientScript.GetCallbackEventReference(control, null, null, null);

                    // Add the callback target
                    descriptor.AddProperty("_callbackTarget", control.UniqueID);
                }
                break;
            }
        }
Exemplo n.º 13
0
        private void Form1_Load(object sender, EventArgs e)
        {
            // Add event handler for settings changes
            appSettings.SettingChanging += new SettingChangingEventHandler(appSettings_SettingChanging);
            propertyGrid1.SelectedObject = appSettings;
            System.Configuration.UserScopedSettingAttribute userAttr = new System.Configuration.UserScopedSettingAttribute();
            System.ComponentModel.AttributeCollection       attrs    = new System.ComponentModel.AttributeCollection(userAttr);
            propertyGrid1.BrowsableAttributes = attrs;

            // Add event handler for summary grid
            this.dgvStatusSummary.CellContentClick += new DataGridViewCellEventHandler(dgvStatusSummary_CellContentClick);

            // Add data grid views to process objects
            _loadIBIProcess.AddGridView(eDWWfResultsTableDataGridView, _loadIBIProcess.GetEDWWorkflowData);
            _loadIBIProcess.AddGridView(dgvLatestEDWLoad, _loadIBIProcess.GetLatestEDWLoad);
            _loadIBIProcess.AddGridView(dgvLatestODSLoad, _loadIBIProcess.GetLatestODSLoad);
            _loadIBIProcess.AddGridView(dgvEDWMetrics, _loadIBIProcess.GetEDWMetrics);
            _loadIBIProcess.AddGridView(dgvODSMetrics, _loadIBIProcess.GetODSMetrics);
            _loadIBIProcess.AddGridView(dgvC8ReportsRan, _loadIBIProcess.GetNumberC8ReportsRan);
            _projectionsProcess.AddGridView(dgvProjections, _projectionsProcess.GetProjectionsRuns);
            _projectionsProcess.AddGridView(dgvProjectionsLoads, _projectionsProcess.GetLatestDataLoads);
            _cinciDataTransferProcess.AddGridView(dgvCinciDataLoads, _cinciDataTransferProcess.GetLatestCinciDataLoad);
            _cinciSavingsTransferProcess.AddGridView(dgvCinciSavingsLoads, _cinciSavingsTransferProcess.GetLatestCinciSavingsLoad);
            _ELECReportFilesProcess.AddGridView(dgvELECFiles, _ELECReportFilesProcess.UpdateELECFilesListView);
            _PPEDataLoadProcess.AddGridView(dgvPPEDataLoad, _PPEDataLoadProcess.GetLatestDataLoads);
            _Infa80ProdStats.AddGridView(dgvWFLastWeek, _Infa80ProdStats.GetWFPast7Days);
            _Infa80ProdStats.AddGridView(dgvProdWFScheduled, _Infa80ProdStats.GetWFScheduled);
            _Infa80ProdStats.AddGridView(dgvProdWFRunning, _Infa80ProdStats.GetWFRunning);
            _Infa80DevStats.AddGridView(dgvDevWFPast7Days, _Infa80DevStats.GetWFPast7Days);
            _Infa80DevStats.AddGridView(dgvDevWFScheduled, _Infa80DevStats.GetWFScheduled);
            _Infa80DevStats.AddGridView(dgvDevWFRunning, _Infa80DevStats.GetWFRunning);
            _Infa86ProdStats.AddGridView(dgvProd86WFLastWeek, _Infa86ProdStats.GetWFPast7Days);
            _Infa86ProdStats.AddGridView(dgvProd86WFScheduled, _Infa86ProdStats.GetWFScheduled);
            _Infa86ProdStats.AddGridView(dgvProd86WFRunning, _Infa86ProdStats.GetWFRunning);
            _Infa86DevStats.AddGridView(dgvDev86WFLastWeek, _Infa86DevStats.GetWFPast7Days);
            _Infa86DevStats.AddGridView(dgvDev86WFScheduled, _Infa86DevStats.GetWFScheduled);
            _Infa86DevStats.AddGridView(dgvDev86WFRunning, _Infa86DevStats.GetWFRunning);
            _PDSProd.AddGridView(dgvPDSProdLatestestWfs, _PDSProd.GetLatestPDSRun);
            _PDSDev.AddGridView(dgvPDSDevLatestWfs, _PDSDev.GetLatestPDSRun);
            _FIQBIProcess.AddGridView(dgvFIQBISummary, _FIQBIProcess.GetFIQBISummary);

            // Add web pages
            _FIQBIProcess.AddWebPages("ADVBI2", wbADVBI2);
            _FIQBIProcess.AddWebPages("ADVBI3", wbADVBI3);
            _FIQBIProcess.AddWebPages("ADVCOG1", wbADVCOG1);
            _FIQBIProcess.AddWebPages("ADVIBI2", wbADVIBI2);
            _cognos8App.AddWebPages("Cognos 8", webBrowserCognos8);

            _FIQBIProcess.StatusUpdateEvent += new BaseProcess.StatusUpdatedEventHandler(_FIQBIProcess_StatusUpdateEvent);
            _cognos8App.StatusUpdateEvent   += new BaseProcess.StatusUpdatedEventHandler(_cognos8App_StatusUpdateEvent);

            _ELECReportFilesProcess.ELECFilesLogFile = tbELECFilesLogFile;

            // Add processes to process array
            _BIProcesses.Add(_loadIBIProcess);
            _BIProcesses.Add(_ELECReportFilesProcess);
            _BIProcesses.Add(_FIQBIProcess);
            _BIProcesses.Add(_PPEDataLoadProcess);
            _BIProcesses.Add(_projectionsProcess);
            _BIProcesses.Add(_cinciDataTransferProcess);
            _BIProcesses.Add(_cinciSavingsTransferProcess);
            _BIProcesses.Add(_cognos8App);
            _BIProcesses.Add(_Infa86ProdStats);
            //_BIProcesses.Add(_Infa86DevStats);
            //_BIProcesses.Add(_Infa80DevStats);
            _BIProcesses.Add(_PDSProd);
            _BIProcesses.Add(_PDSDev);
            _PDSDev.ShowSummaryStatus = false;  // don't show the process in the summary grid

            // Add scheduled workflows to Infa objects
            //_Infa86ProdStats.AddRequiredScheduledWorkflow("Cincinnati Data Transfer", "wf_DataTransfer_Daily");
            //_Infa86ProdStats.AddRequiredScheduledWorkflow("Cincinnati Data Transfer", "wf_ImageTransfer_Daily");
            _Infa86ProdStats.AddRequiredScheduledWorkflow("Data Warehouse", "wf_EDW_DataLoad");
            _Infa86ProdStats.AddRequiredScheduledWorkflow("Operational Data Store", "wf_ODS_DataLoad_IDL");
            _Infa86ProdStats.AddRequiredScheduledWorkflow("Production Data Subsetting", "wf_RunDataloads");
            _Infa86ProdStats.AddRequiredScheduledWorkflow("Savings Transfer To Cincinnati", "wf_SavingsTransfer_Daily");
            _Infa86ProdStats.AddRequiredScheduledWorkflow("Telecom - Interm", "wf_SiteAccount");

            //_Infa86DevStats.AddRequiredScheduledWorkflow("Production Data Subsetting", "wf_RunDataloads");

            //BuildSummaryStatusDataset();
            timerRefresh.Interval = 60000 * appSettings.RefreshRateMin;
            timerRefresh.Start();

            // Propagate app settings to all processes
            UpdateAppSettings(null);

            RefreshFormData();
        }
Exemplo n.º 14
0
        /// <summary>
        /// Return a List of Variance records representing the differences between two entity objects
        /// </summary>
        /// <typeparam name="T">The Entity Type</typeparam>
        /// <param name="sourceObject">The Source object</param>
        /// <param name="targetObject">The Taget object</param>
        /// <param name="ignoreID">set to true to ensure the ID property is not compared</param>
        /// <returns>Lists of Variance records <see cref="List{T}"/> <seealso cref="Variance"/></returns>
        public static List <Variance> DetailedCompare <T>(this T sourceObject, T targetObject, bool ignoreID = false)
        {
            try
            {
                List <Variance> variances = new List <Variance>();
                if (sourceObject != null && targetObject != null)
                {
                    var properties = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);

                    foreach (var property in properties)
                    {
                        string propertyName = property.Name;
                        bool   isEditable   = true; // used to skip properties
                        var    ComputedATT  = property.GetCustomAttribute(typeof(Dapper.Contrib.Extensions.ComputedAttribute));
                        var    KeyAtt       = property.GetCustomAttribute(typeof(Dapper.Contrib.Extensions.KeyAttribute));
                        var    EditableATT  = property.GetCustomAttribute(typeof(EditableAttribute));
                        if (EditableATT != null)
                        {
                            isEditable = property.GetCustomAttribute <EditableAttribute>().AllowEdit;
                        }
                        if (ComputedATT != null)
                        {
                            isEditable = false;
                        }
                        if (isEditable)
                        {
                            if (property.Name.ToUpper() == "ID" && ignoreID)
                            {
                                continue;
                            }
                            string category = "Misc";
                            System.ComponentModel.AttributeCollection  attributes          = System.ComponentModel.TypeDescriptor.GetProperties(sourceObject)[property.Name].Attributes;
                            System.ComponentModel.CategoryAttribute    propertyCategory    = (System.ComponentModel.CategoryAttribute)attributes[typeof(System.ComponentModel.CategoryAttribute)];
                            System.ComponentModel.DisplayNameAttribute propertyDisplayName = (System.ComponentModel.DisplayNameAttribute)attributes[typeof(System.ComponentModel.DisplayNameAttribute)];
                            System.ComponentModel.DescriptionAttribute propertyDescription = (System.ComponentModel.DescriptionAttribute)attributes[typeof(System.ComponentModel.DescriptionAttribute)];
                            category = propertyCategory.Category;
                            if (property.PropertyType.IsClass)
                            {
                                category = "Class";
                            }
                            var v = new Variance
                            {
                                PropertyName        = property.Name,
                                PropertyType        = property.PropertyType,
                                PropertyCategory    = propertyCategory.Category,
                                PropertyDescription = propertyDescription.Description,
                                PropertyDisplayName = (!string.IsNullOrEmpty(propertyDisplayName.DisplayName) ? propertyDisplayName.DisplayName : property.Name),
                                OldValue            = property.GetValue(sourceObject),
                                NewValue            = property.GetValue(targetObject)
                            };

                            if (v.OldValue == null && v.NewValue == null)
                            {
                                continue;
                            }
                            if ((v.OldValue == null && v.NewValue != null) ||
                                (v.OldValue != null && v.NewValue == null))
                            {
                                variances.Add(v);
                                continue;
                            }
                            if (!v.OldValue.Equals(v.NewValue))
                            {
                                variances.Add(v);
                            }
                            if (v.OldValue.Equals(v.NewValue) && KeyAtt != null)
                            {
                                v.isKeyField = true;
                                variances.Add(v);
                            }
                        }
                    }
                }
                return(variances);
            }
            catch (System.Exception)
            {
                throw;
            }
        }
 internal static TResult GetAttributePropertyValue <TAttribute, TResult>(this System.ComponentModel.AttributeCollection attributes, Func <TAttribute, TResult> propertyGetter)
     where TResult : class
     where TAttribute : Attribute
 {
     return(attributes.GetAttributePropertyValue(propertyGetter, null));
 }
 /// <summary>
 /// Gets the first attribute of a given time on the target AttributeCollection, or null.
 /// </summary>
 /// <typeparam name="TAttribute">The attribute type</typeparam>
 /// <param name="attributes">The AttributeCollection object</param>
 /// <returns></returns>
 internal static TAttribute FirstOrDefault <TAttribute>(this System.ComponentModel.AttributeCollection attributes) where TAttribute : Attribute
 {
     return(attributes.OfType <TAttribute>().FirstOrDefault());
 }