public void TestHelloResponse()
        {
            Exception ex = new Exception("foo");
            IDictionary <string, object> serverInfo = new Dictionary <string, object>(1);

            serverInfo.Add(HelloResponse.SERVER_START_TIME, DateTimeUtil.GetCurrentUtcTimeMillis());
            ConnectorKey            key  = new ConnectorKey("my bundle", "my version", "my connector");
            RemoteConnectorInfoImpl info = new RemoteConnectorInfoImpl();

            info.Messages     = (new ConnectorMessagesImpl());
            info.ConnectorKey = (key);
            ConfigurationPropertiesImpl configProperties = new ConfigurationPropertiesImpl();

            configProperties.Properties = (new List <ConfigurationPropertyImpl>());
            APIConfigurationImpl apiImpl = new APIConfigurationImpl();

            apiImpl.ConfigurationProperties = (configProperties);
            info.DefaultAPIConfiguration    = (apiImpl);
            info.ConnectorDisplayNameKey    = ("mykey");
            info.ConnectorCategoryKey       = ("");


            HelloResponse v1 = new HelloResponse(ex, serverInfo, CollectionUtil.NewReadOnlyList <ConnectorKey>(key), CollectionUtil.NewReadOnlyList <RemoteConnectorInfoImpl>(info));
            HelloResponse v2 = (HelloResponse)CloneObject(v1);

            Assert.IsNotNull(v2.Exception);
            Assert.IsNotNull(v2.ServerInfo[HelloResponse.SERVER_START_TIME]);
            Assert.IsNotNull(v2.ConnectorKeys.First());
            Assert.IsNotNull(v2.ConnectorInfos.First());
        }
        public void TestRemoteConnectorInfo()
        {
            RemoteConnectorInfoImpl v1 = new RemoteConnectorInfoImpl();

            v1.Messages     = (new ConnectorMessagesImpl());
            v1.ConnectorKey = (new ConnectorKey("my bundle",
                                                "my version",
                                                "my connector"));
            ConfigurationPropertiesImpl configProperties = new ConfigurationPropertiesImpl();

            configProperties.Properties = (new List <ConfigurationPropertyImpl>());
            APIConfigurationImpl apiImpl = new APIConfigurationImpl();

            apiImpl.ConfigurationProperties = (configProperties);
            v1.DefaultAPIConfiguration      = (apiImpl);
            v1.ConnectorDisplayNameKey      = ("mykey");
            v1.ConnectorCategoryKey         = ("LDAP");

            RemoteConnectorInfoImpl v2 = (RemoteConnectorInfoImpl)
                                         CloneObject(v1);

            Assert.IsNotNull(v2.Messages);
            Assert.AreEqual("my bundle", v2.ConnectorKey.BundleName);
            Assert.AreEqual("my version", v2.ConnectorKey.BundleVersion);
            Assert.AreEqual("my connector", v2.ConnectorKey.ConnectorName);
            Assert.AreEqual("mykey", v2.ConnectorDisplayNameKey);
            Assert.AreEqual("LDAP", v2.ConnectorCategoryKey);
            Assert.IsNotNull(v2.DefaultAPIConfiguration);
        }
        public void TestOperationRequest()
        {
            ConfigurationPropertiesImpl configProperties = new ConfigurationPropertiesImpl();

            configProperties.Properties = (new List <ConfigurationPropertyImpl>());
            APIConfigurationImpl apiImpl = new APIConfigurationImpl();

            apiImpl.ConfigurationProperties = (configProperties);

            IList <object> args = new List <object>();

            args.Add("my arg");
            OperationRequest v1 = new
                                  OperationRequest(new ConnectorKey("my bundle",
                                                                    "my version",
                                                                    "my connector"),
                                                   SerializerUtil.SerializeBase64Object(apiImpl),
                                                   SafeType <APIOperation> .Get <CreateApiOp>(),
                                                   "mymethodName",
                                                   args);
            OperationRequest v2 = (OperationRequest)CloneObject(v1);

            Assert.AreEqual("my bundle", v2.ConnectorKey.BundleName);
            Assert.AreEqual("my version", v2.ConnectorKey.BundleVersion);
            Assert.AreEqual("my connector", v2.ConnectorKey.ConnectorName);
            Assert.IsNotNull(v2.ConnectorFacadeKey);
            Assert.AreEqual(SafeType <APIOperation> .Get <CreateApiOp>(), v2.Operation);
            Assert.AreEqual("mymethodName", v2.OperationMethodName);
            Assert.IsTrue(
                CollectionUtil.Equals(
                    args, v2.Arguments));
        }
Ejemplo n.º 4
0
        MergeIntoBean(ConfigurationPropertiesImpl properties,
                      Configuration config)
        {
            SafeType <Configuration> configType =
                SafeType <Configuration> .Get(config);

            IDictionary <string, PropertyInfo> descriptors =
                GetFilteredProperties(configType);

            foreach (ConfigurationPropertyImpl property in properties.Properties)
            {
                String       name = property.Name;
                PropertyInfo desc =
                    CollectionUtil.GetValue(descriptors, name, null);
                if (desc == null)
                {
                    String FMT =
                        "Class ''{0}'' does not have a property ''{1}''.";
                    String MSG = String.Format(FMT,
                                               configType.RawType.Name,
                                               name);
                    throw new ArgumentException(MSG);
                }
                object val = property.Value;
                //some value types such as arrays
                //are mutable. make sure the config object
                //has its own copy
                val = SerializerUtil.CloneObject(val);
                desc.SetValue(config, val, null);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Method for convenient testing of local connectors.
        /// </summary>
        public APIConfiguration CreateTestConfiguration(SafeType <Connector> clazz,
                                                        Configuration config)
        {
            LocalConnectorInfoImpl info = new LocalConnectorInfoImpl();

            info.ConnectorConfigurationClass = SafeType <Configuration> .Get(config);

            info.ConnectorClass          = (clazz);
            info.ConnectorDisplayNameKey = ("DUMMY_DISPLAY_NAME");
            info.ConnectorKey            = (
                new ConnectorKey(clazz.RawType.Name + ".bundle",
                                 "1.0",
                                 clazz.RawType.Name));
            info.Messages = (this.CreateDummyMessages());
            APIConfigurationImpl rv = new APIConfigurationImpl();

            rv.IsConnectorPoolingSupported = (
                IsConnectorPoolingSupported(clazz));
            ConfigurationPropertiesImpl properties =
                CSharpClassProperties.CreateConfigurationProperties(config);

            rv.ConfigurationProperties = (properties);
            rv.ConnectorInfo           = (info);
            rv.SupportedOperations     = (
                FrameworkUtil.GetDefaultSupportedOperations(clazz));
            info.DefaultAPIConfiguration = (
                rv);
            return(rv);
        }
Ejemplo n.º 6
0
 public ConnectorPoolKey(ConnectorKey connectorKey,
                         ConfigurationPropertiesImpl configProperties,
                         ObjectPoolConfiguration poolingConfig)
 {
     _connectorKey     = connectorKey;
     _configProperties = configProperties;
     _poolingConfig    = poolingConfig;
 }
Ejemplo n.º 7
0
        CreateBean(ConfigurationPropertiesImpl properties,
                   SafeType <Configuration> configType)
        {
            Configuration rv = configType.CreateInstance();

            rv.ConnectorMessages = properties.Parent.ConnectorInfo.Messages;
            MergeIntoBean(properties, rv);
            return(rv);
        }
        public void TestAPIConfiguration()
        {
            ConfigurationPropertyImpl prop1 = new ConfigurationPropertyImpl();

            prop1.Order             = (1);
            prop1.IsConfidential    = (true);
            prop1.Name              = ("foo");
            prop1.HelpMessageKey    = ("help key");
            prop1.DisplayMessageKey = ("display key");
            prop1.GroupMessageKey   = ("group key");
            prop1.Value             = ("bar");
            prop1.ValueType         = (typeof(string));
            prop1.Operations        = null;

            ConfigurationPropertiesImpl props1 = new ConfigurationPropertiesImpl();

            props1.Properties = (CollectionUtil.NewReadOnlyList <ConfigurationPropertyImpl>(prop1));

            APIConfigurationImpl v1 = new APIConfigurationImpl();

            v1.ConnectorPoolConfiguration  = (new ObjectPoolConfiguration());
            v1.ConfigurationProperties     = (props1);
            v1.IsConnectorPoolingSupported = (true);
            v1.ProducerBufferSize          = (200);
            v1.SupportedOperations         = (FrameworkUtil.AllAPIOperations());
            IDictionary <SafeType <APIOperation>, int> map =
                CollectionUtil.NewDictionary <SafeType <APIOperation>, int>(SafeType <APIOperation> .Get <CreateApiOp>(), 6);

            v1.TimeoutMap = (map);

            APIConfigurationImpl v2 = (APIConfigurationImpl)
                                      CloneObject(v1);

            Assert.IsTrue(!Object.ReferenceEquals(v1, v2));
            Assert.IsNotNull(v2.ConnectorPoolConfiguration);
            Assert.IsNotNull(v2.ConfigurationProperties);
            Assert.AreEqual(v1.ConnectorPoolConfiguration, v2.ConnectorPoolConfiguration);
            Assert.AreEqual(v1.ConfigurationProperties, v2.ConfigurationProperties);
            Assert.IsTrue(v2.IsConnectorPoolingSupported);
            Assert.AreEqual(200, v2.ProducerBufferSize);
            Assert.IsTrue(CollectionUtil.SetsEqual(
                              FrameworkUtil.AllAPIOperations(),
                              v2.SupportedOperations));
            Assert.AreEqual(map, v2.TimeoutMap);
        }
Ejemplo n.º 9
0
        public void TestConfigurationProperties()
        {
            ConfigurationPropertyImpl prop1 = new ConfigurationPropertyImpl();

            prop1.Order             = (1);
            prop1.IsConfidential    = (true);
            prop1.Name              = ("foo");
            prop1.HelpMessageKey    = ("help key");
            prop1.DisplayMessageKey = ("display key");
            prop1.Value             = ("bar");
            prop1.ValueType         = (typeof(string));
            prop1.Operations        = null;

            ConfigurationPropertiesImpl v1 = new ConfigurationPropertiesImpl();

            v1.Properties = (CollectionUtil.NewReadOnlyList <ConfigurationPropertyImpl>(prop1));
            v1.SetPropertyValue("foo", "bar");

            ConfigurationPropertiesImpl v2 = (ConfigurationPropertiesImpl)
                                             CloneObject(v1);

            Assert.AreEqual("bar", v2.GetProperty("foo").Value);
        }
Ejemplo n.º 10
0
        public void FillConfiguration(Configuration config, IDictionary <string, object> configData)
        {
            IDictionary <string, object> configDataCopy = new Dictionary <string, object>(configData);
            ConfigurationPropertiesImpl  configProps    =
                CSharpClassProperties.CreateConfigurationProperties(config);

            foreach (string propName in configProps.PropertyNames)
            {
                object value;
                if (configDataCopy.TryGetValue(propName, out value))
                {
                    // Remove the entry from the config map, so that at the end
                    // the map only contains entries that were not assigned to a config property.
                    configDataCopy.Remove(propName);
                    configProps.SetPropertyValue(propName, value);
                }
            }
            // The config map now contains entries that were not assigned to a config property.
            foreach (string propName in configDataCopy.Keys)
            {
                Trace.TraceWarning("Configuration property {0} does not exist!", propName);
            }
            CSharpClassProperties.MergeIntoBean(configProps, config);
        }
Ejemplo n.º 11
0
        public void TestHelloResponse()
        {
            RemoteConnectorInfoImpl info = new RemoteConnectorInfoImpl();

            info.Messages     = (new ConnectorMessagesImpl());
            info.ConnectorKey = (new ConnectorKey("my bundle",
                                                  "my version",
                                                  "my connector"));
            ConfigurationPropertiesImpl configProperties = new ConfigurationPropertiesImpl();

            configProperties.Properties = (new List <ConfigurationPropertyImpl>());
            APIConfigurationImpl apiImpl = new APIConfigurationImpl();

            apiImpl.ConfigurationProperties = (configProperties);
            info.DefaultAPIConfiguration    = (apiImpl);
            info.ConnectorDisplayNameKey    = ("mykey");

            Exception     ex = new Exception("foo");
            HelloResponse v1 = new HelloResponse(ex, CollectionUtil.NewReadOnlyList <RemoteConnectorInfoImpl>(info));
            HelloResponse v2 = (HelloResponse)CloneObject(v1);

            Assert.IsNotNull(v2.Exception);
            Assert.IsNotNull(v2.ConnectorInfos.First());
        }
Ejemplo n.º 12
0
        CreateConfigurationProperties(Configuration defaultObject)
        {
            SafeType <Configuration> config = SafeType <Configuration> .Get(defaultObject);

            ConfigurationPropertiesImpl properties =
                new ConfigurationPropertiesImpl();
            IList <ConfigurationPropertyImpl> temp =
                new List <ConfigurationPropertyImpl>();
            IDictionary <string, PropertyInfo> descs = GetFilteredProperties(config);

            foreach (PropertyInfo desc in descs.Values)
            {
                String name = desc.Name;

                // get the configuration options..
                ConfigurationPropertyAttribute options =
                    GetPropertyOptions(desc);
                // use the options to set internal properties..
                int    order        = 0;
                String helpKey      = name + ".help";
                String displKey     = name + ".display";
                bool   confidential = false;
                bool   required     = false;
                if (options != null)
                {
                    // determine the display and help keys..
                    if (!StringUtil.IsBlank(options.HelpMessageKey))
                    {
                        helpKey = options.HelpMessageKey;
                    }
                    if (!StringUtil.IsBlank(options.DisplayMessageKey))
                    {
                        displKey = options.DisplayMessageKey;
                    }
                    // determine the order..
                    order        = options.Order;
                    required     = options.Required;
                    confidential = options.Confidential;
                }
                Type type = desc.PropertyType;
                if (!FrameworkUtil.IsSupportedConfigurationType(type))
                {
                    const String MSG = "Property type ''{0}'' is not supported.";
                    throw new ArgumentException(String.Format(MSG, type));
                }

                Object value = desc.GetValue(defaultObject, null);

                ConfigurationPropertyImpl prop = new ConfigurationPropertyImpl();
                prop.IsConfidential    = confidential;
                prop.IsRequired        = required;
                prop.DisplayMessageKey = displKey;
                prop.HelpMessageKey    = helpKey;
                prop.Name       = name;
                prop.Order      = order;
                prop.Value      = value;
                prop.ValueType  = type;
                prop.Operations = options == null ? null : TranslateOperations(options.Operations);

                temp.Add(prop);
            }
            properties.Properties = (temp);
            return(properties);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Method for convenient testing of local connectors.
        /// </summary>
        public APIConfiguration CreateTestConfiguration(SafeType <Connector> connectorClass, PropertyBag configData, string prefix)
        {
            Debug.Assert(null != connectorClass);
            Type rawConnectorClass = connectorClass.RawType;

            Object[] attributes = connectorClass.RawType.GetCustomAttributes(
                typeof(ConnectorClassAttribute),
                false);
            if (attributes.Length > 0)
            {
                ConnectorClassAttribute attribute =
                    (ConnectorClassAttribute)attributes[0];

                Assembly assembly = IOUtil.GetAssemblyContainingType(rawConnectorClass.FullName);

                String fileName = assembly.Location;
                SafeType <Configuration> connectorConfigurationClass = attribute.ConnectorConfigurationType;
                if (connectorConfigurationClass == null)
                {
                    String MSG = ("File " + fileName +
                                  " contains a ConnectorInfo attribute " +
                                  "with no connector configuration class.");
                    throw new ConfigurationException(MSG);
                }
                String connectorDisplayNameKey =
                    attribute.ConnectorDisplayNameKey;
                if (connectorDisplayNameKey == null)
                {
                    String MSG = ("File " + fileName +
                                  " contains a ConnectorInfo attribute " +
                                  "with no connector display name.");
                    throw new ConfigurationException(MSG);
                }
                LocalConnectorInfoImpl rv = new LocalConnectorInfoImpl();
                rv.ConnectorClass = connectorClass;
                rv.ConnectorConfigurationClass = connectorConfigurationClass;
                rv.ConnectorDisplayNameKey     = connectorDisplayNameKey;
                rv.ConnectorCategoryKey        = attribute.ConnectorCategoryKey;
                rv.ConnectorKey = (
                    new ConnectorKey(rawConnectorClass.Name + ".bundle",
                                     "1.0",
                                     rawConnectorClass.Name));;
                APIConfigurationImpl impl = LocalConnectorInfoManagerImpl.CreateDefaultAPIConfiguration(rv);
                rv.DefaultAPIConfiguration = impl;
//                if (false)
//                {
//                    rv.Messages = CreateDummyMessages();
//                }
//                else
                {
                    rv.Messages = LocalConnectorInfoManagerImpl.LoadMessages(assembly, rv, attribute.MessageCatalogPaths);
                }
                ConfigurationPropertiesImpl configProps = (ConfigurationPropertiesImpl)impl.ConfigurationProperties;

                string fullPrefix = StringUtil.IsBlank(prefix) ? null : prefix + ".";

                foreach (ConfigurationPropertyImpl property in configProps.Properties)
                {
                    object value = configData.GetProperty(null != fullPrefix ? fullPrefix + property.Name : property.Name, property.ValueType, property.Value);
                    if (value != null)
                    {
                        property.Value = value;
                    }
                }
                return(impl);
            }
            throw new ArgumentException("ConnectorClass does not define ConnectorClassAttribute");
        }