public void GetStandardValues()
        {
            ReferenceConverter converter = new ReferenceConverter(typeof(TestComponent));

            TestComponent        component1       = new TestComponent();
            TestComponent        component2       = new TestComponent();
            TestReferenceService referenceService = new TestReferenceService();

            referenceService.AddReference("reference name 1", component1);
            referenceService.AddReference("reference name 2", component2);
            ITypeDescriptorContext context = new TestTypeDescriptorContext(referenceService);

            TypeConverter.StandardValuesCollection values = converter.GetStandardValues(context);
            Assert.IsNotNull(values, "#1");
            // 2 components + 1 null value
            Assert.AreEqual(3, values.Count, "#2");
        }
Beispiel #2
0
        public static void Unload()
        {
            foreach (var watch in _watchers)
            {
                watch.Dispose();
            }
            _watchers.Clear();

            _importers = null;
            Importers  = null;

            _processors = null;
            Processors  = null;

            ImportersStandardValuesCollection  = null;
            ProcessorsStandardValuesCollection = null;
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            //ListAttribute listAttribute = (ListAttribute)context.PropertyDescriptor.Attributes[typeof(ListAttribute)];
            //StandardValuesCollection vals = new TypeConverter.StandardValuesCollection(listAttribute._lst);

            //Dictionary<object, string> dic = GetEnumValueDesDic(typeof(PKGenerator));

            //StandardValuesCollection vals = new TypeConverter.StandardValuesCollection(dic.Keys);

            if (dic == null || dic.Count <= 0)
            {
                LoadDic(context);
            }

            StandardValuesCollection vals = new TypeConverter.StandardValuesCollection(dic.Keys);

            return(vals);
        }
 public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
 {
     if (this.values == null)
     {
         FontFamily[] families  = FontFamily.Families;
         Hashtable    hashtable = new Hashtable();
         for (int i = 0; i < families.Length; i++)
         {
             string name = families[i].Name;
             hashtable[name.ToLower(CultureInfo.InvariantCulture)] = name;
         }
         object[] array = new object[hashtable.Values.Count];
         hashtable.Values.CopyTo(array, 0);
         Array.Sort(array, Comparer.Default);
         this.values = new TypeConverter.StandardValuesCollection(array);
     }
     return(this.values);
 }
        //scanning for RadItems
        //RadControl --> RootElement --> Children --> RootElement --> RadItemCollection Items

        public static List <IComponent> DiscoverCommandsSources(ICommand command, TypeConverter.StandardValuesCollection collection)
        {
            List <IComponent> commandSources         = DiscoverCommandsSources(collection);
            List <IComponent> filteredCommandSources = new List <IComponent>(1);

            for (int i = 0; i < commandSources.Count; i++)
            {
                if ((commandSources[i].GetType()).IsAssignableFrom(command.ContextType))
                {
                    filteredCommandSources.Add(commandSources[i]);
                }
            }
            if (filteredCommandSources.Count > 0)
            {
                return(filteredCommandSources);
            }
            return(null);
        }
Beispiel #6
0
 public SqlFileConnectionProperties(string defaultInstanceName)
 {
     _defaultDataSource = ".";
     if (defaultInstanceName != null && defaultInstanceName.Length > 0)
     {
         _defaultDataSource += "\\" + defaultInstanceName;
     }
     else
     {
         DataSourceConverter conv = new DataSourceConverter();
         TypeConverter.StandardValuesCollection coll = conv.GetStandardValues(null);
         if (coll.Count > 0)
         {
             _defaultDataSource = coll[0] as string;
         }
     }
     LocalReset();
 }
 public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
 {
     if (this.values == null)
     {
         object[] objArray;
         if (types != null)
         {
             objArray = new object[types.Length];
             Array.Copy(types, objArray, types.Length);
         }
         else
         {
             objArray = null;
         }
         this.values = new TypeConverter.StandardValuesCollection(objArray);
     }
     return(this.values);
 }
Beispiel #8
0
            public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
            {
                //if (this.simpleTypeConverter != null)
                //{
                //    TypeConverter.StandardValuesCollection standardValues = this.simpleTypeConverter.GetStandardValues(context);
                //    if (this.GetStandardValuesSupported(context) && standardValues != null)
                //    {
                //        object[] objArray1 = new object[standardValues.Count + 1];
                //        int num1 = 0;
                //        object[] objArray2 = objArray1;
                //        int index = num1;
                //        int num2 = 1;
                //        int num3 = index + num2;
                //        // ISSUE: variable of the null type
                //        __Null local = null;
                //        objArray2[index] = (object)local;
                //        foreach (object obj in standardValues)
                //            objArray1[num3++] = obj;
                //        return new TypeConverter.StandardValuesCollection((ICollection)objArray1);
                //    }
                //}
                //return base.GetStandardValues(context);

                if (this.simpleTypeConverter != null)
                {
                    TypeConverter.StandardValuesCollection standardValues = this.simpleTypeConverter.GetStandardValues(context);
                    if (this.GetStandardValuesSupported(context) && standardValues != null)
                    {
                        object[] objArray = new object[standardValues.Count + 1];
                        int      num      = 0;
                        int      num1     = num;
                        num            = num1 + 1;
                        objArray[num1] = null;
                        foreach (object standardValue in standardValues)
                        {
                            int num2 = num;
                            num            = num2 + 1;
                            objArray[num2] = standardValue;
                        }
                        return(new TypeConverter.StandardValuesCollection(objArray));
                    }
                }
                return(base.GetStandardValues(context));
            }
        public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            TypeConverter.StandardValuesCollection standardValues = base.GetStandardValues(context);
            object instance = context.Instance;
            int    num      = 0;
            int    index    = 0;

            object[] values = new object[standardValues.Count - 1];
            while (num < standardValues.Count)
            {
                if (standardValues[num] != instance)
                {
                    values[index] = standardValues[num];
                    index++;
                }
                num++;
            }
            return(new TypeConverter.StandardValuesCollection(values));
        }
Beispiel #10
0
        public override TypeConverter.StandardValuesCollection GetStandardValuesCore(
            ITypeDescriptorContext context,
            TypeConverter.StandardValuesCollection collection)
        {
            List <IComponent> componentList = CommandBaseConverter.DiscoverCommandsContexts(collection);

            if (context != null && componentList != null && context.GetService(typeof(IDesignerHost)) != null)
            {
                for (int index = componentList.Count - 1; index >= 0; --index)
                {
                    if (componentList[index].Site == null)
                    {
                        componentList.RemoveAt(index);
                    }
                }
                componentList.Insert(0, (IComponent)null);
            }
            return(new TypeConverter.StandardValuesCollection((ICollection)componentList));
        }
        public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            TypeConverter.StandardValuesCollection result = null;

            if (context.PropertyDescriptor.Name == "Parameterization")
            {
                ResourceManager manager        = new ResourceManager("Microsoft.SqlTools.ServiceLayer.Localization.SR", typeof(DatabasePrototype).GetAssembly());
                List <string>   standardValues = new List <string>();
                standardValues.Add(manager.GetString("prototype_db_prop_parameterization_value_forced"));
                standardValues.Add(manager.GetString("prototype_db_prop_parameterization_value_simple"));
                result = new TypeConverter.StandardValuesCollection(standardValues);
            }
            else
            {
                result = base.GetStandardValues(context);
            }

            return(result);
        }
        public void GetStandardValues_IReferenceService_ReturnsExpected()
        {
            var converter = new ReferenceConverter(typeof(TestComponent));

            var component1 = new TestComponent();
            var component2 = new TestComponent();
            var component3 = new Component();

            var referenceService = new TestReferenceService();

            referenceService.AddReference("reference name 1", component1);
            referenceService.AddReference("reference name 2", component2);
            referenceService.AddReference("reference name 3", component3);

            var context = new TestTypeDescriptorContext(referenceService);

            TypeConverter.StandardValuesCollection values = converter.GetStandardValues(context);
            Assert.Equal(new object[] { component1, component2, null }, values.Cast <object>());
        }
Beispiel #13
0
        public override TypeConverter.StandardValuesCollection GetStandardValues(
            ITypeDescriptorContext context)
        {
            ArrayList arrayList = new ArrayList();

            TypeConverter.StandardValuesCollection standardValues = base.GetStandardValues(context);
            if (standardValues != null)
            {
                for (int index = 0; index < standardValues.Count; ++index)
                {
                    if (index > 0)
                    {
                        object obj = standardValues[index];
                        arrayList.Add(obj);
                    }
                }
            }
            return(new TypeConverter.StandardValuesCollection((ICollection)arrayList));
        }
        public static List <IComponent> DiscoverCommandsContexts(TypeConverter.StandardValuesCollection collection)
        {
            List <IComponent> tempList   = new List <IComponent>(1);
            List <IComponent> returnList = new List <IComponent>(1);

            for (int i = 0; i < collection.Count; i++)
            {
                IComponent component = collection[i] as IComponent;
                if (component != null)
                {
                    tempList.Add(component);
                }
            }
            returnList = DiscoverCommandsContexts(tempList);
            if (returnList != null && returnList.Count > 0)
            {
                return(returnList);
            }
            return(null);
        }
Beispiel #15
0
        private void changeService_ComponentAdded(object sender, ComponentEventArgs e)
        {
            Control control = e.Component as Control;

            if (control is IDetailsTemplateControlBound)
            {
                DetailsTemplateControl detailsTemplateControl = (control as IDetailsTemplateControlBound).DetailsTemplateControl;
                PropertyDescriptor     propertyDescriptor     = TypeDescriptor.GetProperties(control)["AttributeName"];
                if (propertyDescriptor != null)
                {
                    TypeDescriptorContext context = new TypeDescriptorContext(this, control, propertyDescriptor);
                    TypeConverter.StandardValuesCollection standardValues = propertyDescriptor.Converter.GetStandardValues(context);
                    if (standardValues != null && standardValues.Count > 0)
                    {
                        propertyDescriptor.SetValue(control, standardValues[0]);
                    }
                }
            }
            this.DataContext.IsDirty = true;
        }
Beispiel #16
0
        public virtual void SetKeyValue(Dictionary <string, string> keyValue)
        {
            Key2Value = keyValue;

            if (Key2Value != null)
            {
                Values = new TypeConverter.StandardValuesCollection(Key2Value.Values);

                Value2Key = new Dictionary <string, string>(Key2Value.Count);
                foreach (KeyValuePair <string, string> kvp in Key2Value)
                {
                    Value2Key[kvp.Value] = kvp.Key;
                }
            }
            else
            {
                Values    = new TypeConverter.StandardValuesCollection(new ArrayList());
                Value2Key = null;
            }
        }
Beispiel #17
0
        public void GetStandardValues_ITypeDescriptorContext_ReturnEnumValues()
        {
            // Setup
            var mockRepository        = new MockRepository();
            var typeDescriptorContext = mockRepository.Stub <ITypeDescriptorContext>();

            mockRepository.ReplayAll();

            var converter = new NullableEnumConverter(typeof(SimpleEnum?));

            // Call
            TypeConverter.StandardValuesCollection result = converter.GetStandardValues(typeDescriptorContext);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(SimpleEnum.FirstValue, result[0]);
            Assert.AreEqual(SimpleEnum.SecondValue, result[1]);
            mockRepository.VerifyAll();
        }
        public static List <IComponent> DiscoverCommandsSources(
            ICommand command,
            TypeConverter.StandardValuesCollection collection)
        {
            List <IComponent> componentList1 = CommandBaseConverter.DiscoverCommandsSources(collection);
            List <IComponent> componentList2 = new List <IComponent>(1);

            for (int index = 0; index < componentList1.Count; ++index)
            {
                if (componentList1[index].GetType().IsAssignableFrom(command.ContextType))
                {
                    componentList2.Add(componentList1[index]);
                }
            }
            if (componentList2.Count > 0)
            {
                return(componentList2);
            }
            return((List <IComponent>)null);
        }
        public void GetStandardValues_IContainer_ReturnsExpected()
        {
            var component1 = new TestComponent();
            var component2 = new TestComponent();
            var component3 = new Component();

            var container = new Container();

            container.Add(component1);
            container.Add(component2);
            container.Add(component3);

            var converter = new ReferenceConverter(typeof(TestComponent));
            var context   = new TestTypeDescriptorContext {
                Container = container
            };

            TypeConverter.StandardValuesCollection values = converter.GetStandardValues(context);
            Assert.Equal(new object[] { component1, component2, null }, values.Cast <object>());
        }
Beispiel #20
0
 public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
 {
     TypeConverter.StandardValuesCollection supportedCultures = null;
     if (context.PropertyDescriptor != null)
     {
         ExtenderProvidedPropertyAttribute attribute = context.PropertyDescriptor.Attributes[typeof(ExtenderProvidedPropertyAttribute)] as ExtenderProvidedPropertyAttribute;
         if (attribute != null)
         {
             CodeDomLocalizationProvider.LanguageExtenders provider = attribute.Provider as CodeDomLocalizationProvider.LanguageExtenders;
             if (provider != null)
             {
                 supportedCultures = provider.SupportedCultures;
             }
         }
     }
     if (supportedCultures == null)
     {
         supportedCultures = base.GetStandardValues(context);
     }
     return(supportedCultures);
 }
        public static List <IComponent> DiscoverCommandsSources(
            TypeConverter.StandardValuesCollection collection)
        {
            List <IComponent> list = new List <IComponent>(1);

            for (int index = 0; index < collection.Count; ++index)
            {
                IComponent component = collection[index] as IComponent;
                if (component != null)
                {
                    list.Add(component);
                }
            }
            List <IComponent> componentList = CommandBaseConverter.DiscoverCommandsSources(list);

            if (componentList != null && componentList.Count > 0)
            {
                return(componentList);
            }
            return((List <IComponent>)null);
        }
        public void GetStandardValues_IReferenceServiceInvalid_ReturnsExpected(object referenceService)
        {
            var converter = new ReferenceConverter(typeof(TestComponent));
            int callCount = 0;
            var context   = new MockTypeDescriptorContext
            {
                GetServiceAction = (serviceType) =>
                {
                    callCount++;
                    Assert.Equal(typeof(IReferenceService), serviceType);
                    return(referenceService);
                }
            };

            TypeConverter.StandardValuesCollection values1 = converter.GetStandardValues(context);
            Assert.Equal(1, callCount);
            Assert.Equal(new object[] { null }, values1.Cast <object>());

            // Call again to test caching behavior.
            TypeConverter.StandardValuesCollection values2 = converter.GetStandardValues(context);
            Assert.Equal(2, callCount);
            Assert.NotSame(values1, values2);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            if (this.values == null)
            {
                this.values = new TypeConverter.StandardValuesCollection(new string[] {
                    "AbsoluteLayout",
                    "AccordionLayout",
                    "AnchorLayout",
                    "BorderLayout",
                    "CardLayout",
                    "ColumnLayout",
                    "AutoLayout",
                    "FitLayout",
                    "HBoxLayout",
                    "MenuLayout",
                    "TableLayout",
                    "ToolbarLayout",
                    "VBoxLayout"
                });
            }

            return(this.values);
        }
        public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            ArrayList list = new ArrayList(base.GetStandardValues(context));

            TypeConverter.StandardValuesCollection standardValues = this.listConverter.GetStandardValues(context);
            ArrayList     values   = new ArrayList();
            BindingSource instance = context.Instance as BindingSource;

            foreach (object obj2 in list)
            {
                if (obj2 != null)
                {
                    ListBindableAttribute attribute = (ListBindableAttribute)TypeDescriptor.GetAttributes(obj2)[typeof(ListBindableAttribute)];
                    if (((attribute == null) || attribute.ListBindable) && ((instance == null) || (instance != obj2)))
                    {
                        DataTable table = obj2 as DataTable;
                        if ((table == null) || !list.Contains(table.DataSet))
                        {
                            values.Add(obj2);
                        }
                    }
                }
            }
            foreach (object obj3 in standardValues)
            {
                if (obj3 != null)
                {
                    ListBindableAttribute attribute2 = (ListBindableAttribute)TypeDescriptor.GetAttributes(obj3)[typeof(ListBindableAttribute)];
                    if (((attribute2 == null) || attribute2.ListBindable) && ((instance == null) || (instance != obj3)))
                    {
                        values.Add(obj3);
                    }
                }
            }
            values.Add(null);
            return(new TypeConverter.StandardValuesCollection(values));
        }
        public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            INuGenCounter counter = (context == null) ? null : (context.Instance as INuGenCounter);

            String machineName = ".";

            if (context != null)
            {
                machineName = counter.MachineName;
            }

            if (machineName != _previousMachineName)
            {
                _previousMachineName = machineName;

                try
                {
                    PerformanceCounter.CloseSharedResources();
                    PerformanceCounterCategory[] categories = PerformanceCounterCategory.GetCategories(machineName);
                    String[] categoryNames = new String[categories.Length];

                    for (Int32 categoryIndex = 0; categoryIndex < categories.Length; categoryIndex++)
                    {
                        categoryNames[categoryIndex] = categories[categoryIndex].CategoryName;
                    }

                    Array.Sort(categoryNames, Comparer.Default);
                    _previousStandardValues = new TypeConverter.StandardValuesCollection(categoryNames);
                }
                catch
                {
                    _previousStandardValues = null;
                }
            }

            return(_previousStandardValues);
        }
        public void GetStandardValues_IContainerNullType_ReturnsExpected()
        {
            var component1 = new TestComponent();
            var component2 = new TestComponent();
            var component3 = new Component();

            var container = new Container();

            container.Add(component1);
            container.Add(component2);
            container.Add(component3);

            var converter = new ReferenceConverter(null);
            var context   = new MockTypeDescriptorContext {
                Container = container
            };

            TypeConverter.StandardValuesCollection values1 = converter.GetStandardValues(context);
            Assert.Equal(new object[] { null }, values1.Cast <object>());

            // Call again to test caching behavior.
            TypeConverter.StandardValuesCollection values2 = converter.GetStandardValues(context);
            Assert.NotSame(values1, values2);
        }
        public override TypeConverter.StandardValuesCollection GetStandardValuesCore(ITypeDescriptorContext context, TypeConverter.StandardValuesCollection collection)
        {
            List <IComponent> list = CommandBaseConverter.DiscoverCommandsSources(collection);

            list.Insert(0, null);
            return(new TypeConverter.StandardValuesCollection(list));
        }
Beispiel #28
0
 public void TestGetStandardValues()
 {
     TypeConverter.StandardValuesCollection stdVals = ic.GetStandardValues(null);
     Assert.AreEqual(1, stdVals.Count, "StandardValues count must be 1.");
     Assert.AreEqual(-1, stdVals [0], "Standard Value count must be -1.");
 }
Beispiel #29
0
        public override TypeConverter.StandardValuesCollection GetStandardValuesCore(ITypeDescriptorContext context, TypeConverter.StandardValuesCollection collection)
        {
            List <CommandBase> list = CommandBaseConverter.DiscoverCommands(collection);

            if (list != null)
            {
                list.Insert(0, null);
            }
            return(new TypeConverter.StandardValuesCollection(list));
        }
Beispiel #30
0
        public static void Load(PipelineProject project)
        {
            Unload();

            var assemblyPaths = new List <string>();

            var projectRoot = project.Location;

            foreach (var i in project.References)
            {
                var path = Path.Combine(projectRoot, i);

                if (string.IsNullOrEmpty(path))
                {
                    throw new ArgumentException("assemblyFilePath cannot be null!");
                }
                if (!Path.IsPathRooted(path))
                {
                    throw new ArgumentException("assemblyFilePath must be absolute!");
                }

                // Make sure we're not adding the same assembly twice.
                path = PathHelper.Normalize(path);
                if (!assemblyPaths.Contains(path))
                {
                    assemblyPaths.Add(path);
                }
            }

            ResolveAssemblies(assemblyPaths);

            var importerDescriptions = new ImporterTypeDescription[_importers.Count];
            var cur = 0;

            foreach (var item in _importers)
            {
                // Find the abstract base class ContentImporter<T>.
                var baseType = item.Type.BaseType;
                while (!baseType.IsAbstract)
                {
                    baseType = baseType.BaseType;
                }

                var outputType = baseType.GetGenericArguments()[0];
                var name       = item.Attribute.DisplayName;
                if (string.IsNullOrEmpty(name))
                {
                    name = item.GetType().Name;
                }
                var desc = new ImporterTypeDescription()
                {
                    TypeName         = item.Type.Name,
                    DisplayName      = name,
                    DefaultProcessor = item.Attribute.DefaultProcessor,
                    FileExtensions   = item.Attribute.FileExtensions,
                    OutputType       = outputType,
                };
                importerDescriptions[cur] = desc;
                cur++;
            }

            Importers = importerDescriptions;
            ImportersStandardValuesCollection = new TypeConverter.StandardValuesCollection(Importers);

            var processorDescriptions = new ProcessorTypeDescription[_processors.Count];

            const BindingFlags bindings = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static;

            cur = 0;
            foreach (var item in _processors)
            {
                var obj            = Activator.CreateInstance(item.Type);
                var typeProperties = item.Type.GetProperties(bindings);
                var properties     = new List <ProcessorTypeDescription.Property>();
                foreach (var i in typeProperties)
                {
                    var attrs     = i.GetCustomAttributes(true);
                    var name      = i.Name;
                    var browsable = true;
                    var defvalue  = i.GetValue(obj, null);

                    foreach (var a in attrs)
                    {
                        if (a is BrowsableAttribute)
                        {
                            browsable = (a as BrowsableAttribute).Browsable;
                        }
                        else if (a is DisplayNameAttribute)
                        {
                            name = (a as DisplayNameAttribute).DisplayName;
                        }
                    }

                    var p = new ProcessorTypeDescription.Property()
                    {
                        Name         = i.Name,
                        DisplayName  = name,
                        Type         = i.PropertyType,
                        DefaultValue = defvalue,
                        Browsable    = browsable
                    };
                    properties.Add(p);
                }

                var inputType = (obj as IContentProcessor).InputType;
                var desc      = new ProcessorTypeDescription()
                {
                    TypeName    = item.Type.Name,
                    DisplayName = item.Attribute.DisplayName,
                    Properties  = new ProcessorTypeDescription.ProcessorPropertyCollection(properties),
                    InputType   = inputType,
                };
                if (string.IsNullOrEmpty(desc.DisplayName))
                {
                    desc.DisplayName = desc.TypeName;
                }

                processorDescriptions[cur] = desc;
                cur++;
            }

            Processors = processorDescriptions;
            ProcessorsStandardValuesCollection = new TypeConverter.StandardValuesCollection(Processors);
        }