예제 #1
0
        internal static List<ExplorerItem> GetSchemaAndBuildAssembly(AstoriaProperties props, AssemblyName name,
			ref string nameSpace, ref string typeName)
        {
            // Read the EDM schema into an XDocument:
            XDocument data;
            using (XmlReader reader = GetSchemaReader (props))
                data = XDocument.Load (reader);

            // Generate the code using the ADO.NET Data Services classes:
            string code;
            using (XmlReader reader = data.CreateReader ())
                code = GenerateCode (reader, nameSpace);

            // Compile the code into the assembly, using the assembly name provided:
            BuildAssembly (code, name);

            // Use the schema to populate the Schema Explorer:
            List<ExplorerItem> schema = GetSchema (data, out typeName);

            return schema;
        }
예제 #2
0
        public override void InitializeContext(IConnectionInfo cxInfo, object context, QueryExecutionManager executionManager)
        {
            // This method gets called after a DataServiceContext has been instantiated. It gives us a chance to
            // perform further initialization work.
            //
            // And as it happens, we have an interesting problem to solve! The typed data service context class
            // that Astoria's EntityClassGenerator generates handles the ResolveType delegate as follows:
            //
            //   return this.GetType().Assembly.GetType (string.Concat ("<namespace>", typeName.Substring (19)), true);
            //
            // Because LINQPad subclasses the typed data context when generating a query, GetType().Assembly returns
            // the assembly of the user query rather than the typed data context! To work around this, we must take
            // over the ResolveType delegate and resolve using the context's base type instead:

            var dsContext = (DataServiceContext)context;
            var typedDataServiceContextType = context.GetType ().BaseType;

            dsContext.ResolveType = name => typedDataServiceContextType.Assembly.GetType
                (typedDataServiceContextType.Namespace + "." + name.Split ('.').Last ());

            // The next step is to feed any supplied credentials into the Astoria service.
            // (This could be enhanced to support other authentication modes, too).
            var props = new AstoriaProperties (cxInfo);
            dsContext.Credentials = props.GetCredentials ();

            // Finally, we handle the SendingRequest event so that it writes the request text to the SQL translation window:
            dsContext.SendingRequest += (sender, e) => executionManager.SqlTranslationWriter.WriteLine (e.Request.RequestUri);
        }
예제 #3
0
 public ConnectionDialog(IConnectionInfo cxInfo)
 {
     DataContext = _properties = new AstoriaProperties (cxInfo);
     Background = SystemColors.ControlBrush;
     InitializeComponent ();
 }
예제 #4
0
        static XmlReader GetSchemaReader(AstoriaProperties props)
        {
            var uri = new DataServiceContext (new Uri (props.Uri)).GetMetadataUri ();

            var settings = new XmlReaderSettings ();
            XmlResolver resolver = new XmlUrlResolver ();

            // If credentials have been supplied, feed these in as we're querying the schema:
            resolver.Credentials = props.GetCredentials ();

            settings.XmlResolver = resolver;

            return XmlReader.Create (uri.ToString (), settings);
        }