コード例 #1
0
        /// <summary>
        /// Discovers the connection string for the provider.
        /// </summary>
        public static ConnectionStringSettings DiscoverConnectionStringSettings(TaskClerkProvider provider)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }

            string connectionStringName = "BritishMicro.TaskClerk.Properties.Settings.DefaultDataStore";

            if (provider.HasMetaData)
            {
                connectionStringName = provider.ProviderMetaData[0].GetAttribute("name");
            }
            return(ConfigurationManager.ConnectionStrings[connectionStringName]);
        }
コード例 #2
0
        /// <summary>
        /// Tries the get a value from settings.
        /// </summary>
        /// <param name="provider">The provider.</param>
        /// <param name="key">The key.</param>
        /// <param name="defaultValue">The default value.</param>
        /// <returns></returns>
        public static string TryGetFromSettings(TaskClerkProvider provider, string key, string defaultValue)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }

            string foundValue = null;

            if (provider.HasMetaData)
            {
                foundValue = provider.ProviderMetaData[0].GetAttribute(key);
            }
            if (string.IsNullOrEmpty(foundValue))
            {
                foundValue = defaultValue;
            }
            return(foundValue);
        }
コード例 #3
0
        /// <summary>
        /// Creates the specified engine.
        /// </summary>
        /// <param name="engine">The engine.</param>
        /// <returns></returns>
        internal TaskClerkProvider Create(TaskClerkEngine engine)
        {
            Regex expression =
                new Regex(BritishMicro.TaskClerk.Properties.Resources.TypeNameAndAssemblyRegEx);
            Match    m = expression.Match(_providerType);
            Assembly targetAssembly;

            try
            {
                targetAssembly = Assembly.Load(m.Groups["AssemblyName"].Value);
            }
            catch (FileNotFoundException fnf)
            {
                Trace.TraceError(
                    "TaskClerkProvider:Create[Unable to find the file {0}, specified in the providers section of the application configuration file.]",
                    fnf.FileName);
                throw new FileNotFoundException(
                          "Unable to find the file specified in the providers section of the application configuration file.",
                          fnf);
            }
            Type targetType = targetAssembly.GetType(m.Groups["TypeName"].Value);

            if (targetType == null)
            {
                Trace.TraceError("TaskClerkProvider:Create[Could not find type [{0}] in assembly [{1}].]",
                                 m.Groups["TypeName"].Value, targetAssembly.FullName);
                throw new InvalidOperationException(
                          string.Format(CultureInfo.InvariantCulture, "Could not find type [{0}] in assembly [{1}].",
                                        m.Groups["TypeName"].Value,
                                        targetAssembly.FullName));
            }
            TaskClerkProvider provider = Activator.CreateInstance(targetType) as TaskClerkProvider;

            if (provider != null)
            {
                provider._engine   = engine;
                provider._metadata = this._metadata;
                provider.OnInit();
            }
            return(provider);
        }
コード例 #4
0
        /// <summary>
        /// Tries the get a value from settings.
        /// </summary>
        /// <param name="provider">The provider.</param>
        /// <param name="key">The key.</param>
        /// <param name="defaultValue">The default value.</param>
        /// <returns></returns>
        public static string TryGetFromSettings(TaskClerkProvider provider, string key, string defaultValue)
        {
            if(provider == null)
                throw new ArgumentNullException("provider");

            string foundValue = null;
            if (provider.HasMetaData)
            {
                foundValue = provider.ProviderMetaData[0].GetAttribute(key);
            }
            if (string.IsNullOrEmpty(foundValue))
            {
                foundValue = defaultValue;
            }
            return foundValue;
        }
コード例 #5
0
        /// <summary>
        /// Discovers the connection string for the provider.
        /// </summary>
        public static ConnectionStringSettings DiscoverConnectionStringSettings(TaskClerkProvider provider)
        {
            if(provider == null)
                throw new ArgumentNullException("provider");

            string connectionStringName = "BritishMicro.TaskClerk.Properties.Settings.DefaultDataStore";
            if (provider.HasMetaData)
            {
                connectionStringName = provider.ProviderMetaData[0].GetAttribute("name");
            }
            return ConfigurationManager.ConnectionStrings[connectionStringName];
        }