Exemple #1
0
        /// <summary>
        /// Gets the namespaces to add to the default list of namespaces added to the generateed class executed.
        /// </summary>
        /// <param name="cxInfo">The cx info.</param>
        /// <returns></returns>
        public override IEnumerable <string> GetNamespacesToAdd(IConnectionInfo cxInfo)
        {
            var defaultNamespaces = new List <string>()
            {
                "SD.LLBLGen.Pro.LinqSupportClasses", "SD.LLBLGen.Pro.ORMSupportClasses", "SD.LLBLGen.Pro.QuerySpec",
            };

            var templateGroup = CxInfoHelper.GetTemplateGroup(cxInfo);

            if (templateGroup == TemplateGroup.Adapter)
            {
                defaultNamespaces.Add("SD.LLBLGen.Pro.QuerySpec.Adapter");
            }
            else
            {
                defaultNamespaces.Add("SD.LLBLGen.Pro.QuerySpec.SelfServicing");
            }

            var toReturn = base.GetNamespacesToAdd(cxInfo).Union(defaultNamespaces);

            var entityAssemblyNamespaces = CxInfoHelper.GetDriverDataElementValue(cxInfo, DriverDataElements.EntityAssemblyNamespacesElement);

            if (!string.IsNullOrEmpty(entityAssemblyNamespaces))
            {
                toReturn = toReturn.Union(entityAssemblyNamespaces.Split(',').Where(s => !string.IsNullOrEmpty(s)));
            }
            return(toReturn);
        }
Exemple #2
0
        /// <summary>
        /// Fills the controls with existing data.
        /// </summary>
        private void FillControlsWithExistingData()
        {
            if ((_cxInfo == null) || _isNewConnection)
            {
                return;
            }
            var templateGroupValue = CxInfoHelper.GetTemplateGroup(_cxInfo);

            switch (templateGroupValue)
            {
            case TemplateGroup.None:
            case TemplateGroup.SelfServicing:
                _selfServicingRadioButton.Checked = true;
                break;

            case TemplateGroup.Adapter:
                _adapterRadioButton.Checked = true;
                break;
            }
            _ssAssemblyTextBox.Text            = CxInfoHelper.GetDriverDataElementValue(_cxInfo, DriverDataElements.SelfServicingAssemblyFilenameElement);
            _aGenAssemblyTextBox.Text          = CxInfoHelper.GetDriverDataElementValue(_cxInfo, DriverDataElements.AdapterDBGenericAssemblyFilenameElement);
            _aSpecAssemblyTextBox.Text         = CxInfoHelper.GetDriverDataElementValue(_cxInfo, DriverDataElements.AdapterDBSpecificAssemblyFilenameElement);
            _connectionStringTextBox.Text      = CxInfoHelper.GetDriverDataElementValue(_cxInfo, DriverDataElements.ConnectionStringElementName);
            _appConfigFileTextBox.Text         = CxInfoHelper.GetDriverDataElementValue(_cxInfo, DriverDataElements.ConfigFileFilenameElement);
            _enableORMProfilerCheckBox.Checked = XmlConvert.ToBoolean(CxInfoHelper.GetDriverDataElementValue(_cxInfo,
                                                                                                             DriverDataElements.EnableORMProfilerElement));
        }
Exemple #3
0
        /// <summary>
        /// Initializes the context for self servicing. The 'context' is an ILinqMetaData instance
        /// </summary>
        /// <param name="cxInfo">The cx info.</param>
        /// <param name="context">The context.</param>
        /// <param name="executionManager">The execution manager.</param>
        private void InitializeContextSelfServicing(IConnectionInfo cxInfo, object context, QueryExecutionManager executionManager)
        {
            string connectionString = CxInfoHelper.GetDriverDataElementValue(cxInfo, DriverDataElements.ConnectionStringElementName);

            if (string.IsNullOrEmpty(connectionString))
            {
                // not specified, nothing further.
                return;
            }
            // set actual connection string on CommonEntityBase.
            var selfServicingAssemblyFilename = CxInfoHelper.GetDriverDataElementValue(cxInfo, DriverDataElements.SelfServicingAssemblyFilenameElement);
            var selfServicingAssembly         = context.GetType().BaseType.Assembly;
            var commonDaoBaseType             = selfServicingAssembly.GetTypes().Where(t => t.Name.EndsWith("CommonDaoBase")).FirstOrDefault();

            if (commonDaoBaseType == null)
            {
                throw new InvalidOperationException(string.Format("Couldn't find type 'CommonEntityBase' in assembly '{0}'", selfServicingAssemblyFilename));
            }
            var actualConnectionStringField = commonDaoBaseType.GetField("ActualConnectionString");

            if (actualConnectionStringField == null)
            {
                throw new InvalidOperationException(string.Format("The type '{0}' doesn't have a static property ActualConnectionString.", commonDaoBaseType.FullName));
            }
            actualConnectionStringField.SetValue(null, connectionString);
        }
Exemple #4
0
        /// <summary>
        /// Gets the template group value from the specified cxInfo
        /// </summary>
        /// <param name="cxInfo">The cx info.</param>
        /// <returns></returns>
        internal static TemplateGroup GetTemplateGroup(IConnectionInfo cxInfo)
        {
            if (cxInfo == null)
            {
                return(TemplateGroup.None);
            }
            string rawValue = CxInfoHelper.GetDriverDataElementValue(cxInfo, DriverDataElements.TemplateGroupElement);

            if (string.IsNullOrEmpty(rawValue))
            {
                return(TemplateGroup.None);
            }
            return((TemplateGroup)XmlConvert.ToInt32(rawValue));
        }
Exemple #5
0
        /// <summary>
        /// Initializes the context for adapter. The 'context' is an ILinqMetaData instance.
        /// </summary>
        /// <param name="cxInfo">The cx info.</param>
        /// <param name="context">The context.</param>
        /// <param name="executionManager">The execution manager.</param>
        private void InitializeContextAdapter(IConnectionInfo cxInfo, object context, QueryExecutionManager executionManager)
        {
            ILinqMetaData contextAsLinqMetaData = context as ILinqMetaData;

            if (contextAsLinqMetaData == null)
            {
                throw new InvalidOperationException("'context' isn't an ILinqMetaData typed object");
            }
            string adapterAssemblyFilename = CxInfoHelper.GetDriverDataElementValue(cxInfo, DriverDataElements.AdapterDBSpecificAssemblyFilenameElement);
            var    adapterAssembly         = DataContextDriver.LoadAssemblySafely(adapterAssemblyFilename);

            if (adapterAssembly == null)
            {
                throw new InvalidOperationException(string.Format("The file '{0}' isn't a valid assembly.", adapterAssemblyFilename));
            }
            var adapterType = adapterAssembly.GetTypes().Where(t => typeof(IDataAccessAdapter).IsAssignableFrom(t)).FirstOrDefault();

            if (adapterType == null)
            {
                throw new InvalidOperationException(string.Format("The assembly '{0}' doesn't contain an implementation of IDataAccessAdapter.", adapterAssemblyFilename));
            }
            IDataAccessAdapter adapterInstance  = null;
            string             connectionString = CxInfoHelper.GetDriverDataElementValue(cxInfo, DriverDataElements.ConnectionStringElementName);

            if (string.IsNullOrEmpty(connectionString))
            {
                // use normal empty ctor
                adapterInstance = Activator.CreateInstance(adapterType) as IDataAccessAdapter;
            }
            else
            {
                // use ctor which specifies the ctor
                adapterInstance = Activator.CreateInstance(adapterType, connectionString) as IDataAccessAdapter;
            }
            if (adapterInstance == null)
            {
                throw new InvalidOperationException(string.Format("Couldn't create an instance of adapter type '{0}' from assembly '{1}'.", adapterType.FullName, adapterAssemblyFilename));
            }
            var adapterToUseProperty = contextAsLinqMetaData.GetType().GetProperty("AdapterToUse");

            if (adapterToUseProperty == null)
            {
                throw new InvalidOperationException(string.Format("The type '{0}' doesn't have a property 'AdapterToUse'.", context.GetType().FullName));
            }
            adapterToUseProperty.SetValue(contextAsLinqMetaData, adapterInstance, null);
        }
Exemple #6
0
        /// <summary>
        /// Gets the entity assembly filename.
        /// </summary>
        /// <param name="cxInfo">The cx info.</param>
        /// <param name="templateGroup">The template group.</param>
        /// <returns></returns>
        internal static string GetEntityAssemblyFilename(IConnectionInfo cxInfo, TemplateGroup templateGroup)
        {
            string assemblyFileNameTouse = string.Empty;

            switch (templateGroup)
            {
            case TemplateGroup.None:
            case TemplateGroup.SelfServicing:
                assemblyFileNameTouse = CxInfoHelper.GetDriverDataElementValue(cxInfo, DriverDataElements.SelfServicingAssemblyFilenameElement);
                break;

            case TemplateGroup.Adapter:
                assemblyFileNameTouse = CxInfoHelper.GetDriverDataElementValue(cxInfo, DriverDataElements.AdapterDBGenericAssemblyFilenameElement);
                break;
            }
            return(assemblyFileNameTouse);
        }
Exemple #7
0
        /// <summary>
        /// Enables the ORM profiler.
        /// </summary>
        /// <param name="cxInfo">The cx info.</param>
        private void EnableORMProfiler(IConnectionInfo cxInfo)
        {
            var interceptorLocation = CxInfoHelper.GetDriverDataElementValue(cxInfo, DriverDataElements.ORMProfilerInterceptorLocationElement);

            if (!File.Exists(interceptorLocation))
            {
                throw new InvalidOperationException(string.Format("The ORM Profiler interceptor isn't found at '{0}'", interceptorLocation));
            }
            var interceptorAssembly = DataContextDriver.LoadAssemblySafely(interceptorLocation);

            if (interceptorAssembly == null)
            {
                throw new InvalidOperationException(string.Format("Couldn't load the ORM Profiler interceptor assembly '{0}'", interceptorLocation));
            }
            Type interceptor = interceptorAssembly.GetType("SD.Tools.OrmProfiler.Interceptor.InterceptorCore");

            interceptor.InvokeMember("Initialize",
                                     System.Reflection.BindingFlags.Public |
                                     System.Reflection.BindingFlags.InvokeMethod |
                                     System.Reflection.BindingFlags.Static,
                                     null, null, new[] { GetConnectionDescription(cxInfo) }, System.Globalization.CultureInfo.CurrentUICulture);
        }