Пример #1
0
        bool areaControl_CanConvert(string arg1, string arg2)
        {
            Type from = FlowSourceDumper.GetTypeFromString(arg1),
                 to   = FlowSourceDumper.GetTypeFromString(arg2);

            if (from == null || to == null)
            {
                return(false);
            }
            return(TypeConverterManager.CanConvert(from, to));
        }
 /// <summary>
 /// All information are loaded with reflection on demand, thus dynamic.
 /// </summary>
 public DynamicSerializationContext()
 {
     Activator   = new ConstructorManager();
     Converters  = new TypeConverterManager(this);
     Serializers = new TypedSerializerManager(this);
 }
Пример #3
0
        private void FlowDrawPanel_Load(object sender, EventArgs e)
        {
            if (sourceCache == null)
            {
                sourceCache = new Dictionary <string, AssemblyAndTypeAndSource[]>();
                foreach (IGrouping <string, AssemblyAndTypeAndSource> ss in flowSources.Select(a => new AssemblyAndTypeAndSource(a)).GroupBy(a => a.Source.Name).ToArray())
                {
                    var sources = ss.ToArray();
                    Array.Sort(sources, (a1, a2) =>
                    {
                        int count1 = a1.Source.InProperties.Count + a1.Source.InMethods.Count + a1.Source.OutProperties.Count + a1.Source.OutMethods.Count;
                        int count2 = a2.Source.InProperties.Count + a2.Source.InMethods.Count + a2.Source.OutProperties.Count + a2.Source.OutMethods.Count;
                        if (count1 > count2)
                        {
                            return(1);
                        }
                        if (count1 < count2)
                        {
                            return(-1);
                        }

                        if (a1.Source.InProperties.Count > a2.Source.InProperties.Count)
                        {
                            return(1);
                        }
                        if (a1.Source.InProperties.Count < a2.Source.InProperties.Count)
                        {
                            return(-1);
                        }

                        if (a1.Source.OutProperties.Count > a2.Source.OutProperties.Count)
                        {
                            return(1);
                        }
                        if (a1.Source.OutProperties.Count < a2.Source.OutProperties.Count)
                        {
                            return(-1);
                        }

                        if (a1.Source.InMethods.Count > a2.Source.InMethods.Count)
                        {
                            return(1);
                        }
                        if (a1.Source.InMethods.Count < a2.Source.InMethods.Count)
                        {
                            return(-1);
                        }

                        if (a1.Source.OutMethods.Count > a2.Source.OutMethods.Count)
                        {
                            return(1);
                        }
                        if (a1.Source.OutMethods.Count < a2.Source.OutMethods.Count)
                        {
                            return(-1);
                        }

                        int point = 0;
                        foreach (CustomMemberInfo <PropertyInfo> propertyInfo1 in a1.Source.InProperties)
                        {
                            var propertyInfo2 = a2.Source.InProperties.FirstOrDefault(c => c.MemberInfo.Name == propertyInfo1.MemberInfo.Name);
                            if (propertyInfo2 != null && propertyInfo1.MemberInfo.PropertyType != propertyInfo2.MemberInfo.PropertyType)
                            {
                                if (TypeConverterManager.CanConvert(propertyInfo2.MemberInfo.PropertyType, propertyInfo1.MemberInfo.PropertyType))
                                {
                                    point--;
                                }
                                else
                                {
                                    point++;
                                }
                            }
                        }

                        return(point);
                    });
                    sourceCache.Add(ss.Key, sources);
                }
            }

            foreach (KeyValuePair <string, AssemblyAndTypeAndSource[]> group in sourceCache)
            {
                foreach (AssemblyAndTypeAndSource source in group.Value)
                {
                    try
                    {
                        CreateToolStripMenuItem(source);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
#if DEBUG
                        MessageBox.Show(ex.StackTrace);
#endif
                    }
                }
            }

            areaControl                   = new FlowAreaControl();
            areaControl.DragEnter        += areaControl_DragEnter;
            areaControl.Drop             += areaControl_Drop;
            elementHost1.Child            = areaControl;
            areaControl.SelectionChanged += areaControl_SelectionChanged;
            areaControl.CanConvert       += areaControl_CanConvert;
            areaControl.Modified         += areaControl_Modified;
            areaControl.GetSource        += areaControl_GetSource;

            FinishInitialize();
        }