void ChooseType(object sender, RoutedEventArgs e)
        {
            if (_model != null)
            {
                var oldCursor = Cursor;

                try
                {
                    Cursor = Cursors.Wait;

                    _model.CustomAssemblyPath = _model.CustomAssemblyPath.Trim();

                    var assembly    = DataContextDriver.LoadAssemblySafely(_model.CustomAssemblyPath);
                    var customTypes = assembly.GetExportedTypes().Where(IsDataConnection).Select(t => t.FullName).Cast <object>().ToArray();

                    Cursor = oldCursor;

                    var result = (string)Dialogs.PickFromList("Choose Custom Type", customTypes);

                    if (result != null)
                    {
                        _model.CustomTypeName = result;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Assembly load error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                finally
                {
                    Cursor = oldCursor;
                }
            }
        }
예제 #2
0
        private static Assembly AssemblyResolve(object sender, ResolveEventArgs args)
        {
            try
            {
                string assemblyname             = args.Name.Substring(0, args.Name.IndexOf(',')) + ".dll";
                string driverDir                = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                IEnumerable <string> assemblies = Directory.EnumerateFiles(driverDir, assemblyname);
                foreach (string path in assemblies)
                {
                    return(DataContextDriver.LoadAssemblySafely(path));
                }

                string root = Path.Combine(Path.GetTempPath(), @"LINQPad\");
                assemblies = Directory.EnumerateFiles(root, assemblyname, SearchOption.AllDirectories);
                foreach (string path in assemblies)
                {
                    return(DataContextDriver.LoadAssemblySafely(path));
                }
            }
            catch (Exception error)
            {
                TxEventSource.Log.TraceError(error.ToString());
            }

            return(null);
        }
예제 #3
0
파일: TypeCache.cs 프로젝트: yyjdelete/Tx
        public Type[] GetAvailableTypes(string targetDir, string[] traces, string[] metadaFiles)
        {
            Assembly[] assemblies = (from file in GetAssemblies(targetDir, traces, metadaFiles)
                                     select DataContextDriver.LoadAssemblySafely(file)).ToArray();

            var types = (from a in assemblies
                         from t in a.GetTypes()
                         where t.IsPublic
                         select t).ToArray();

            return(types);
        }
예제 #4
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));
        }
예제 #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);
        }
예제 #6
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);
        }
예제 #7
0
        public ParserRegistry()
        {
            string dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            IEnumerable <Type> types = from file in Directory.GetFiles(dir, "Tx*.dll")
                                       from t in DataContextDriver.LoadAssemblySafely(file).GetTypes()
                                       where t.IsPublic
                                       select t;

            IEnumerable <MethodInfo> methods = from t in types
                                               from m in t.GetMethods()
                                               where m.GetCustomAttribute <FileParserAttribute>() != null
                                               select m;

            _addFiles = methods.ToArray();

            methods = from t in types
                      from m in t.GetMethods()
                      where m.GetCustomAttribute <RealTimeFeedAttribute>() != null
                      select m;

            _addSessions = methods.ToArray();
        }
        //public static List<ExplorerItem> GetSchemaAndBuildAssembly(ConnectionData connectionData, AssemblyName assemblyName,
        //    ref string nameSpace, ref string typeName)
        //{
        //    var code = GenerateCode(connectionData);
        //    CompileCode(code, assemblyName);

        //}
        internal static List <ExplorerItem> GetSchemaAndBuildAssembly(IConnectionInfo cxInfo, AssemblyName name,
                                                                      ref string nameSpace, ref string typeName)
        {
            //using (var progress = new ProgressIndicatorHost( 5, true))
            {
                //progress.SetStatus(1, "Fetching entities (slow)...");
                // Generate the code using the ADO.NET Data Services classes:
                var code = GenerateCode(new ConnectionData(cxInfo), nameSpace);

                //progress.SetStatus(2, "Compiling assemblies...");
                // Compile the code into the assembly, using the assembly name provided:
                BuildAssembly(code, name);

                //progress.SetStatus(3, "Loading assemblies...");
                var assembly = DataContextDriver.LoadAssemblySafely(name.CodeBase);
                var a        = assembly.GetType(nameSpace + ".TypedDataContext");

                //progress.SetStatus(4, "Calculating schema...");
                // Use the schema to populate the Schema Explorer:
                List <ExplorerItem> schema = GetSchema(cxInfo, a);

                return(schema);
            }
        }