コード例 #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);
        }
コード例 #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));
        }
コード例 #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);
        }
コード例 #4
0
        /// <summary>
        /// Initializes the context.
        /// </summary>
        /// <param name="cxInfo">The cx info.</param>
        /// <param name="context">The context.</param>
        /// <param name="executionManager">The execution manager.</param>
        public override void InitializeContext(IConnectionInfo cxInfo, object context, QueryExecutionManager executionManager)
        {
            if (CxInfoHelper.GetEnableORMProfiler(cxInfo))
            {
                EnableORMProfiler(cxInfo);
            }

            var templateGroup = CxInfoHelper.GetTemplateGroup(cxInfo);

            switch (templateGroup)
            {
            case TemplateGroup.None:
                throw new InvalidOperationException("Template group hasn't been specified.");

            case TemplateGroup.Adapter:
                InitializeContextAdapter(cxInfo, context, executionManager);
                break;

            case TemplateGroup.SelfServicing:
                InitializeContextSelfServicing(cxInfo, context, executionManager);
                break;

            default:
                base.InitializeContext(cxInfo, context, executionManager);
                break;
            }
            var tracer = new ORMPersistenceExecutionListener(executionManager);

            Trace.Listeners.Clear();
            Trace.Listeners.Add(tracer);
            TraceHelper.PersistenceExecutionSwitch.Level = TraceLevel.Verbose;
        }
コード例 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConnectionDialog"/> class.
        /// </summary>
        /// <param name="cxInfo">The cx info.</param>
        /// <param name="isNewConnection">if set to <c>true</c> [is new connection].</param>
        public ConnectionDialog(IConnectionInfo cxInfo, bool isNewConnection)
        {
            _cxInfo          = cxInfo;
            _isNewConnection = isNewConnection;
            InitializeComponent();

            CxInfoHelper.CreateDriverDataElements(_cxInfo);
        }
コード例 #6
0
        /// <summary>
        /// Returns the text to display in the root Schema Explorer node for a given connection info.
        /// </summary>
        /// <param name="cxInfo">The cx info.</param>
        /// <returns></returns>
        public override string GetConnectionDescription(IConnectionInfo cxInfo)
        {
            if (cxInfo == null)
            {
                return("<null>");
            }
            var templateGroup = CxInfoHelper.GetTemplateGroup(cxInfo);

            return(string.Format("{0} - {1}", templateGroup.ToString(),
                                 Path.GetFileNameWithoutExtension(CxInfoHelper.GetEntityAssemblyFilename(cxInfo, templateGroup))));
        }
コード例 #7
0
        /// <summary>
        /// Obtains the and set entity assembly namespaces.
        /// </summary>
        /// <param name="cxInfo">The cx info.</param>
        private void ObtainAndSetEntityAssemblyNamespaces(IConnectionInfo cxInfo)
        {
            var entityAssemblyFilename = CxInfoHelper.GetEntityAssemblyFilename(cxInfo, CxInfoHelper.GetTemplateGroup(cxInfo));

            if (string.IsNullOrEmpty(entityAssemblyFilename))
            {
                return;
            }
            var assembly   = DataContextDriver.LoadAssemblySafely(entityAssemblyFilename);
            var namespaces = assembly.GetTypes().Select(t => t.Namespace).Distinct().ToArray();

            CxInfoHelper.SetDriverDataElement(cxInfo, DriverDataElements.EntityAssemblyNamespacesElement, String.Join(",", namespaces));
        }
コード例 #8
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));
        }
コード例 #9
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);
        }
コード例 #10
0
        /// <summary>
        /// Verifies the version of the entity assembly, whether it's of a version this driver can work with.
        /// </summary>
        private void VerifyEntityAssemblyVersion()
        {
            if (_linqMetaDataType == null)
            {
                throw new InvalidOperationException("No ILinqMetaData type found.");
            }
            var ormSupportClassesAssemblyName = _linqMetaDataType.Assembly.GetReferencedAssemblies()
                                                .Where(an => (an.Name == "SD.LLBLGen.Pro.ORMSupportClasses") &&
                                                       (an.Version.Major == Constants.MajorVersion) &&
                                                       (an.Version.Minor == Constants.MinorVersion)).FirstOrDefault();

            if (ormSupportClassesAssemblyName == null)
            {
                throw new InvalidOperationException(string.Format("The assembly '{0}' is not compiled against the LLBLGen Pro Runtime Framework v{1}.{2}.",
                                                                  CxInfoHelper.GetEntityAssemblyFilename(_cxInfo, CxInfoHelper.GetTemplateGroup(_cxInfo)), Constants.MajorVersion, Constants.MinorVersion));
            }
        }
コード例 #11
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);
        }
コード例 #12
0
        /// <summary>
        /// Validates the entity assembly.
        /// </summary>
        /// <param name="toValidate">To validate.</param>
        /// <param name="e">The <see cref="System.ComponentModel.CancelEventArgs"/> instance containing the event data.</param>
        /// <param name="parentIsEnabled">if set to <c>true</c> [parent is enabled].</param>
        private void ValidateEntityAssembly(TextBox toValidate, CancelEventArgs e, bool parentIsEnabled)
        {
            var    realValue    = toValidate.Text.Trim();
            bool   cancel       = false;
            string errorMessage = string.Empty;

            if (parentIsEnabled)
            {
                var ilinqMetaDataType = CxInfoHelper.GetILinqMetaDataTypeFromEntityAssembly(_cxInfo, realValue);
                if (string.IsNullOrEmpty(ilinqMetaDataType))
                {
                    cancel       = true;
                    errorMessage = string.Format("The assembly '{0}' doesn't contain an ILinqMetaData implementing class.", realValue);
                }
            }
            e.Cancel = cancel;
            _mainErrorProvider.SetError(toValidate, errorMessage);
        }
コード例 #13
0
        /// <summary>
        /// Fills the cx info with the data specified on the form
        /// </summary>
        private void FillCxInfo()
        {
            if (_cxInfo == null)
            {
                return;
            }
            _cxInfo.AppConfigPath = _appConfigFileTextBox.Text.Trim();
            var templateGroupSelected = _selfServicingRadioButton.Checked?TemplateGroup.SelfServicing : TemplateGroup.Adapter;

            CxInfoHelper.SetDriverDataElement(_cxInfo, DriverDataElements.TemplateGroupElement, XmlConvert.ToString((int)templateGroupSelected));
            CxInfoHelper.SetDriverDataElement(_cxInfo, DriverDataElements.AdapterDBGenericAssemblyFilenameElement, _aGenAssemblyTextBox.Text);
            CxInfoHelper.SetDriverDataElement(_cxInfo, DriverDataElements.AdapterDBSpecificAssemblyFilenameElement, _aSpecAssemblyTextBox.Text);
            CxInfoHelper.SetDriverDataElement(_cxInfo, DriverDataElements.SelfServicingAssemblyFilenameElement, _ssAssemblyTextBox.Text);
            CxInfoHelper.SetDriverDataElement(_cxInfo, DriverDataElements.ConfigFileFilenameElement, _appConfigFileTextBox.Text);
            CxInfoHelper.SetDriverDataElement(_cxInfo, DriverDataElements.ConnectionStringElementName, _connectionStringTextBox.Text);
            _cxInfo.DatabaseInfo.CustomCxString = _connectionStringTextBox.Text;
            CxInfoHelper.SetDriverDataElement(_cxInfo, DriverDataElements.EnableORMProfilerElement,
                                              XmlConvert.ToString((_enableORMProfilerCheckBox.Enabled && _enableORMProfilerCheckBox.Checked)));
            CxInfoHelper.SetCustomTypeInfo(_cxInfo, templateGroupSelected);
        }
コード例 #14
0
        /// <summary>
        /// Enables the disable ORM profiler check box.
        /// </summary>
        private void EnableDisableORMProfilerCheckBox()
        {
            // check whether the .opsnapshot extension is registered in the registry. If so, grab the folder location for the interceptor.
            // if not, disable the checkbox.
            bool enableEnableORMProfilerCheckbox = true;
            var  opsnapshotRegistration          = Registry.GetValue("HKEY_CLASSES_ROOT\\.opsnapshot", string.Empty, null);

            if (opsnapshotRegistration == null)
            {
                enableEnableORMProfilerCheckbox = false;
            }
            else
            {
                string realRegistryKey = opsnapshotRegistration as string;
                if (realRegistryKey == null)
                {
                    enableEnableORMProfilerCheckbox = false;
                }
                else
                {
                    var iconPath = Registry.GetValue(string.Format("HKEY_CLASSES_ROOT\\{0}\\DefaultIcon", realRegistryKey), string.Empty, null) as string;
                    if (iconPath == null)
                    {
                        enableEnableORMProfilerCheckbox = false;
                    }
                    else
                    {
                        iconPath = iconPath.Substring(0, iconPath.Length - 2);
                        var interceptorPath = Path.Combine(Path.GetDirectoryName(iconPath), "SD.Tools.OrmProfiler.Interceptor.dll");
                        enableEnableORMProfilerCheckbox = File.Exists(interceptorPath);
                        if (enableEnableORMProfilerCheckbox)
                        {
                            CxInfoHelper.SetDriverDataElement(_cxInfo, DriverDataElements.ORMProfilerInterceptorLocationElement, interceptorPath);
                        }
                    }
                }
            }
            _enableORMProfilerCheckBox.Enabled = enableEnableORMProfilerCheckbox;
        }
コード例 #15
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);
        }