aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/NotifyMachineDataDownloadCompletedResponse.cs
blob: 6d5769885dea4a33ad28b1520651bf95e266ff02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using Tango.BL.DTO;
using Tango.Transport.Web;

namespace Tango.PPC.Common.Web
{
    public class NotifyMachineDataDownloadCompletedResponse : WebResponseMessage
    {
        
    }
}
ld } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Tango.Core;
using Tango.Core.CustomAttributes;

/// <summary>
/// Contains extension methods for <see cref="IParameterized"/>.
/// </summary>
public static class IParameterizedExtensions
{
    /// <summary>
    /// Creates an observable collection of the parameterized object.
    /// </summary>
    /// <param name="instance">The instance.</param>
    /// <param name="mode">The parameters update mode.</param>
    /// <returns></returns>
    public static ObservableCollection<ParameterItem> CreateParametersCollection(this IParameterized instance, ParameterItemMode mode)
    {
        var ps = new ObservableCollection<ParameterItem>();

        int index = 0;

        List<Type> types = new List<Type>();
        Type currentType = instance.GetType();

        while (true)
        {
            if (typeof(IParameterized).IsAssignableFrom(currentType) && currentType != typeof(IParameterized))
            {
                types.Add(currentType);
                currentType = currentType.BaseType;
            }
            else
            {
                break;
            }
        }

        List<PropertyInfo> properties = new List<PropertyInfo>();

        foreach (var type in types)
        {
            foreach (var prop in type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).Where(x => x.SetMethod != null))
            {
                if (prop.PropertyType.IsPrimitive || prop.PropertyType == typeof(String) || prop.PropertyType == typeof(DateTime))
                {
                    var paramAtt = prop.GetCustomAttributes(typeof(ParameterItemAttribute), false).Cast<ParameterItemAttribute>().FirstOrDefault();
                    var ignore = prop.GetCustomAttributes(typeof(ParameterIgnoreAttribute), false).Cast<ParameterIgnoreAttribute>().FirstOrDefault();
                    var indexAttr = prop.GetCustomAttributes(typeof(PropertyIndexAttribute), false).Cast<PropertyIndexAttribute>().FirstOrDefault();

                    if (ignore == null && !properties.Exists(x => x.Name == prop.Name))
                    {
                        var item = instance.CreateParameterItem(prop, paramAtt,indexAttr != null ? indexAttr.Index : index++, mode);
                        ps.Add(item);
                        properties.Add(prop);
                    }
                }
            }
        }

        return ps.OrderBy(x => x.Index).ToObservableCollection();
    }

    /// <summary>
    /// Creates the parameter item.
    /// </summary>
    /// <param name="instance">The instance.</param>
    /// <param name="propertyInfo">The property information.</param>
    /// <param name="attribute">The attribute.</param>
    /// <param name="index">The index.</param>
    /// <param name="mode">The mode.</param>
    /// <returns></returns>
    public static ParameterItem CreateParameterItem(this IParameterized instance, PropertyInfo propertyInfo, ParameterItemAttribute attribute, int index, ParameterItemMode mode)
    {
        ParameterItem item = new ParameterItem();
        item.Name = propertyInfo.Name.ToTitle();
        item.Index = index;
        item.Type = propertyInfo.PropertyType;
        item.ParameterizedObject = instance;

        if (attribute != null)
        {
            item.Value = attribute.Default;
            item.Minimum = attribute.Minimum;
            item.Maximum = attribute.Maximum;
            item.CustomEditorTypeName = attribute.CustomEditorTypeName;
            item.ExtraObject = attribute.ExtraObject;

            if (attribute.Name != null)
            {
                item.Name = attribute.Name;
            }
        }
        else
        {
            //Try get description and range attributes
            DescriptionAttribute desAtt = propertyInfo.GetCustomAttribute<DescriptionAttribute>();
            if (desAtt != null)
            {
                item.Description = desAtt.Description;
            }

            RangeAttribute rangeAtt = propertyInfo.GetCustomAttribute<RangeAttribute>();
            if (rangeAtt != null)
            {
                item.Minimum = rangeAtt.Minimum;
                item.Maximum = rangeAtt.Maximum;
            }

            StringFormatAttribute formatAtt = propertyInfo.GetCustomAttribute<StringFormatAttribute>();
            if (formatAtt != null)
            {
                item.StringFormat = formatAtt.Format;
            }

            PropertyIndexAttribute indexAtt = propertyInfo.GetCustomAttribute<PropertyIndexAttribute>();
            if (indexAtt != null)
            {
                item.Index = indexAtt.Index;
            }
        }

        if (mode == ParameterItemMode.Event)
        {
            item.ParameterValueChanged += (sender, e) =>
            {
                propertyInfo.SetValue(instance, e.Value);
            };
        }
        else if (mode == ParameterItemMode.Binding)
        {
            item.Bind(ParameterItem.ValueProperty, instance, propertyInfo.Name, System.Windows.Data.BindingMode.TwoWay);
        }


        return item;
    }

    /// <summary>
    /// Creates the parameter item.
    /// </summary>
    /// <param name="instance">The instance.</param>
    /// <param name="propertyName">Name of the property.</param>
    /// <param name="attribute">The attribute.</param>
    /// <param name="index">The index.</param>
    /// <param name="mode">The mode.</param>
    /// <returns></returns>
    public static ParameterItem CreateParameterItem(this IParameterized instance, String propertyName, ParameterItemAttribute attribute, int index, ParameterItemMode mode)
    {
        return instance.CreateParameterItem(instance.GetType().GetProperty(propertyName), attribute, index, mode);
    }
}