コード例 #1
0
        // ReSharper disable once RedundantAssignment
        public override List <ExplorerItem> GetSchemaAndBuildAssembly(IConnectionInfo connectionInfo, AssemblyName assemblyToBuild, ref string nameSpace, ref string typeName)
        {
            var properties = connectionInfo.GetConnectionProperties();

            var codeGenerator = new ODataT4CodeGenerator
            {
                MetadataDocumentUri      = properties.Uri,
                NamespacePrefix          = nameSpace,
                TargetLanguage           = ODataT4CodeGenerator.LanguageOption.CSharp,
                UseDataServiceCollection = false,
                EnableNamingAlias        = false,
                IgnoreUnexpectedElementsAndAttributes = true,
                Properties = properties,
            };
            var code = codeGenerator.TransformText();

            BuildAssembly(code, assemblyToBuild);

            var model = properties.GetModel();

            typeName = GetContainerName(model);
            var schema = model.GetSchema();

            return(schema);
        }
コード例 #2
0
        public override void InitializeContext(IConnectionInfo connectionInfo, object context, QueryExecutionManager executionManager)
        {
            var dsContext = (DataServiceContext)context;

            var properties = connectionInfo.GetConnectionProperties();

            dsContext.Credentials = properties.GetCredentials();

            dsContext.Configurations.RequestPipeline.OnMessageCreating += args =>
            {
                var message = new CustomizedRequestMessage(args, properties.GetWebProxy());
                return(message);
            };

            dsContext.SendingRequest2 += (s, e) =>
            {
                executionManager.SqlTranslationWriter.WriteLine($"URL:\t\t{e.RequestMessage.Url}");

                if (properties.LogMethod)
                {
                    executionManager.SqlTranslationWriter.WriteLine($"Method:\t{e.RequestMessage.Method}");
                }

                if (properties.LogHeaders)
                {
                    executionManager.SqlTranslationWriter.WriteLine("Headers:");
                    var headers = string.Join("\r\n", e.RequestMessage.Headers.Select(o => $"\t{o.Key}:{o.Value}"));
                    executionManager.SqlTranslationWriter.WriteLine(headers);
                }
            };
        }
コード例 #3
0
        public override bool ShowConnectionDialog(IConnectionInfo connectionInfo, bool isNewConnection)
        {
            var connectionProperties = connectionInfo.GetConnectionProperties();

            // Populate the default URI with a demo data:
            if (isNewConnection)
            {
                connectionProperties.Uri = "http://services.odata.org/TripPinRESTierService";
            }

            return(new ConnectionDialog(connectionProperties).ShowDialog() == true);
        }
コード例 #4
0
        public override IEnumerable <string> GetNamespacesToAdd(IConnectionInfo connectionInfo)
        {
            if (_namespaces == null || _namespaces.Count == 0)
            {
                var model      = connectionInfo.GetConnectionProperties().GetModel();
                var namespaces = model.DeclaredNamespaces.Select(o => BaseNamespacePrefix + "." + o).ToList();
                _namespaces = namespaces.Count > 1 ? namespaces.ToList() : new List <string>(1);
                _namespaces.Add("Microsoft.OData.Client");
            }

            return(_namespaces);
        }
コード例 #5
0
        public override List <ExplorerItem> GetSchemaAndBuildAssembly(IConnectionInfo connectionInfo, AssemblyName assemblyToBuild, ref string nameSpace, ref string typeName)
        {
            var properties = connectionInfo.GetConnectionProperties();

            // using code from Microsoft's OData v4 Client Code Generator. see https://visualstudiogallery.msdn.microsoft.com/9b786c0e-79d1-4a50-89a5-125e57475937
            var client = new ODataClient(new Configuration(properties.Uri, nameSpace, properties));
            var code   = client.GenerateCode();

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

            var model = properties.GetModel();

            typeName = GetContainerName(model);
            var schema = model.GetSchema();

            return(schema);
        }
コード例 #6
0
 public override object[] GetContextConstructorArguments(IConnectionInfo connectionInfo)
 {
     // We need to pass the chosen URI into the DataServiceContext's constructor:
     return(new object[] { new Uri(connectionInfo.GetConnectionProperties().Uri) });
 }
コード例 #7
0
 public override string GetConnectionDescription(IConnectionInfo connectionInfo)
 {
     return(connectionInfo.GetConnectionProperties().Uri);
 }
コード例 #8
0
        public override List<ExplorerItem> GetSchemaAndBuildAssembly(IConnectionInfo connectionInfo, AssemblyName assemblyToBuild, ref string nameSpace, ref string typeName)
        {
            var properties = connectionInfo.GetConnectionProperties();

            // using code from Microsoft's OData v4 Client Code Generator. see https://visualstudiogallery.msdn.microsoft.com/9b786c0e-79d1-4a50-89a5-125e57475937
            var client = new ODataClient(new Configuration(properties.Uri, nameSpace, properties));
            var code = client.GenerateCode();

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

            var model = properties.GetModel();

            typeName = GetContainerName(model);
            var schema = model.GetSchema();

            return schema;
        }
コード例 #9
0
        public override IEnumerable<string> GetNamespacesToAdd(IConnectionInfo connectionInfo)
        {
            if (_namespaces == null || _namespaces.Count == 0)
            {
                var model = connectionInfo.GetConnectionProperties().GetModel();
                var namespaces = model.DeclaredNamespaces.Select(o => BaseNamespacePrefix + "." + o).ToList();
                _namespaces = namespaces.Count > 1 ? namespaces.ToList() : new List<string>(1);
                _namespaces.Add("Microsoft.OData.Client");
            }

            return _namespaces;
        }
コード例 #10
0
 public override object[] GetContextConstructorArguments(IConnectionInfo connectionInfo)
 {
     // We need to pass the chosen URI into the DataServiceContext's constructor:
     return new object[] { new Uri(connectionInfo.GetConnectionProperties().Uri) };
 }
コード例 #11
0
 public override string GetConnectionDescription(IConnectionInfo connectionInfo)
 {
     return connectionInfo.GetConnectionProperties().Uri;
 }
コード例 #12
0
        public override bool ShowConnectionDialog(IConnectionInfo connectionInfo, bool isNewConnection)
        {
            var connectionProperties = connectionInfo.GetConnectionProperties();

            // Populate the default URI with a demo data:
            if (isNewConnection)
                connectionProperties.Uri = "http://services.odata.org/V4/OData/OData.svc/";

            return new ConnectionDialog(connectionProperties).ShowDialog() == true;
        }
コード例 #13
0
        public override void InitializeContext(IConnectionInfo connectionInfo, object context, QueryExecutionManager executionManager)
        {
            var dsContext = (DataServiceContext)context;

            var properties = connectionInfo.GetConnectionProperties();
            dsContext.Credentials = properties.GetCredentials();

            dsContext.Configurations.RequestPipeline.OnMessageCreating += args =>
            {
                var message = new CustomizedRequestMessage(args, properties);
                return message;
            };

            dsContext.SendingRequest2 += (s, e) =>
            {
                executionManager.SqlTranslationWriter.WriteLine($"URL:\t\t{e.RequestMessage.Url}");

                if (properties.LogMethod)
                    executionManager.SqlTranslationWriter.WriteLine($"Method:\t{e.RequestMessage.Method}");

                if (properties.LogHeaders)
                {
                    executionManager.SqlTranslationWriter.WriteLine("Headers:");
                    var headers = string.Join("\r\n", e.RequestMessage.Headers.Select(o => $"\t{o.Key}:{o.Value}"));
                    executionManager.SqlTranslationWriter.WriteLine(headers);
                }
            };
        }