Beispiel #1
0
 public void Initialize(TypeSystem system, ITypeSystemController controller)
 {
     TypeSystem = system;
     Controller = controller;
     Cache = new MetadataCache();
     Loader = new MetadataLoader(this);
     Resolver = new MetadataResolver(this);
 }
Beispiel #2
0
        protected ServiceEndpoint GetEndPointFromExchange <TContract>(string metadataExchange)
        {
            var serviceInfo = MetadataResolver.Resolve(typeof(TContract), new Uri(metadataExchange),
                                                       MetadataExchangeClientMode.HttpGet);

            if (serviceInfo.Count == 0)
            {
                throw new ServiceClientException(string.Format("No service endpoints defined for {0}",
                                                               metadataExchange));
            }

            return(serviceInfo.First());
        }
Beispiel #3
0
        public void ErrResolve6()
        {
            ContractDescription        contract  = ContractDescription.GetContract(typeof(IEchoService));
            List <ContractDescription> contracts = new List <ContractDescription> ();

            //FIXME: What is the 'client' param used for?
            //TODO: Write test cases for the related overloads of Resolve
            MetadataResolver.Resolve(
                contracts,
                new Uri(url),
                MetadataExchangeClientMode.HttpGet,
                new MetadataExchangeClient(new EndpointAddress("http://localhost")));
        }
Beispiel #4
0
        public static Task DumpAsync(IConsole console, DirectoryInfo directory)
        {
            var assemblyFiles = directory.EnumerateFiles("*.dll", new EnumerationOptions()
            {
                RecurseSubdirectories = true,
            });

            var assemblyResolver = new AssemblyResolver();
            var metadataResolver = new MetadataResolver(assemblyResolver);

            var parameters = new ReaderParameters()
            {
                AssemblyResolver = assemblyResolver,
                MetadataResolver = metadataResolver,
                ReadSymbols      = false,
            };

            var assemblies = new List <AssemblyDefinition>();

            assemblies.AddRange(assemblyFiles.Select(f => AssemblyDefinition.ReadAssembly(f.FullName, parameters)));

            foreach (var assembly in assemblies)
            {
                assemblyResolver.Add(assembly);
            }

            var pnse = FindType(assemblies, "System.PlatformNotSupportedException");

            if (pnse == null)
            {
                throw new CommandException("Cannot find PlatformNotSupportedException.");
            }

            var visitor = new PNSEUsageVisitor();

            foreach (var assembly in assemblies)
            {
                visitor.Visit(assembly);
            }

            foreach (var kvp in visitor.Visited)
            {
                if (kvp.Value)
                {
                    console.Out.WriteLine(kvp.Key.FullName);
                }
            }

            return(Task.CompletedTask);
        }
Beispiel #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            Uri uri = new Uri(textBox1.Text);
            ServiceEndpointCollection endpts = MetadataResolver.Resolve(typeof(IEmployeeService), uri, MetadataExchangeClientMode.HttpGet);

            foreach (ServiceEndpoint obj in endpts)
            {
                IEmployeeService proxy = new ChannelFactory <IEmployeeService>(obj.Binding, obj.Address).CreateChannel();
                DataSet          ds    = proxy.GetEmployees();
                listBox1.DataSource    = ds.Tables[0].DefaultView;
                listBox1.DisplayMember = "FirstName";
                listBox1.ValueMember   = "EmployeeID";
                ((IChannel)proxy).Close();
            }
        }
Beispiel #6
0
        public void ErrResolve4()
        {
            ContractDescription        contract  = ContractDescription.GetContract(typeof(IEchoService));
            List <ContractDescription> contracts = new List <ContractDescription> ();

            contracts.Add(contract);
            contracts.Add(ContractDescription.GetContract(typeof(NonExistantContract)));

            //FIXME: What is the 'client' param used for?
            //TODO: Write test cases for the related overloads of Resolve
            MetadataResolver.Resolve(
                contracts,
                new EndpointAddress("http://doesnotexist"),
                new MetadataExchangeClient(new EndpointAddress(url)));
        }
Beispiel #7
0
        public TableExistsQuery(Func <NpgsqlConnection> getConnection)
        {
            _getConnection = getConnection ?? throw new ArgumentNullException(nameof(getConnection));

            var fullTableIdentifier = MetadataResolver.TableName <TEntity>();

            var split     = fullTableIdentifier.Split('.');
            var schema    = split[0];
            var tableName = split[1];

            var innerQuery = "SELECT 1 FROM pg_tables "
                             + $"WHERE schemaname = '{schema}' AND tablename = '{tableName}'";

            _sqlBuilder.Append($"SELECT EXISTS({innerQuery})");
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            ServiceEndpointCollection serviceEndpointCollection =
                MetadataResolver.Resolve(typeof(IMachine),
                                         new EndpointAddress("http://localhost:8080/ServiceMachine/mex"));

            foreach (var endpoint in serviceEndpointCollection)
            {
                var    channel     = new MachineClient(endpoint.Binding, endpoint.Address);
                string machineName = channel.GetMachineName(new MachineDTO {
                    MachineID = "1", MachineName = "test"
                });
                Console.WriteLine(machineName);
                Console.WriteLine(endpoint.Binding);
            }
        }
Beispiel #9
0
        public InsertCommand(
            Func <NpgsqlConnection> getConnection,
            List <TEntity> entities)
        {
            _getConnection = getConnection ?? throw new ArgumentNullException(nameof(getConnection));

            if (entities.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(entities), "At least one entity must be provided for an Insert command.");
            }

            List <TableColumn> columns = MetadataResolver.TableColumns <TEntity>();

            AppendInsertInto(columns);
            AppendEntityValues(entities, columns);
        }
    public static MethodReference GetBaseMethodInstance(this MethodDefinition target)
    {
        MethodDefinition baseMethodDef = null;
        var baseType = target.DeclaringType.BaseType;
        Collection <TypeReference> availableArgs = null;

        while (baseType != null)
        {
            if (baseType.MetadataToken.TokenType == TokenType.TypeRef)
            {
                break;
            }
            GenericInstanceType baseTypeInstance = null;
            if (baseType.IsGenericInstance)
            {
                baseTypeInstance = (GenericInstanceType)baseType;
                bool bGenericArgumentsAvailable = !baseTypeInstance
                                                  .GenericArguments
                                                  .Any(arg => arg.MetadataType == MetadataType.Var);
                if (bGenericArgumentsAvailable)
                {
                    availableArgs = baseTypeInstance.GenericArguments;
                }
            }

            var baseTypeDef = baseType.Resolve();
            baseMethodDef = MetadataResolver.GetMethod(baseTypeDef.Methods, target);
            if (baseMethodDef != null && !baseMethodDef.IsAbstract)
            {
                if (baseType.IsGenericInstance)
                {
                    MethodReference baseMethodRef = baseType.Module.Import(baseMethodDef);
                    return(baseMethodRef.MakeGenericMethod(availableArgs.ToArray()));
                }
                break;
            }
            else
            {
                baseMethodDef = null;
            }

            baseType = baseTypeDef.BaseType;
        }

        return(baseMethodDef);
    }
Beispiel #11
0
        public static void Main(string[] args)
        {
            // var cf = new ChannelFactory<IEvalServiceChannel>("NetNamedPipeBinding_IEvalService");
            // var channel = cf.CreateChannel();
            var endpoints = MetadataResolver.Resolve(
                typeof(IEvalService),
                new EndpointAddress("http://localhost:8080/evals/mex"));

            foreach (var se in endpoints)
            {
                var channel = new EvalServiceClient(se.Binding, se.Address);

                // var channel = new EvalServiceClient("WSHttpBinding_IEvalService");
                try
                {
                    var eval = new Eval();
                    eval.Submitter = "Howard";
                    eval.Timesent  = DateTime.Now;
                    eval.Comments  = "I'm thinking this...";

                    channel.SubmitEval(eval);
                    channel.SubmitEval(eval);
                    var evals = channel.GetEvals();
                    Console.WriteLine("Number of evals: {0}", evals.Count);
                    channel.Close();
                }
                catch (FaultException fe)
                {
                    Console.WriteLine("FaultException handler: {0}", fe.GetType());
                    channel.Abort();
                }
                catch (CommunicationException ce)
                {
                    Console.WriteLine("CommunicationException handler: {0}", ce.GetType());
                    channel.Abort();
                }
                catch (TimeoutException te)
                {
                    Console.WriteLine("TimeoutException handler: {0}", te.GetType());
                    channel.Abort();
                }
            }

            Console.ReadLine();
        }
Beispiel #12
0
        public async Task AddAsync(List <Team> teams)
        {
            if (teams == null)
            {
                throw new ArgumentNullException(nameof(teams), "Teams must be provided.");
            }

            if (!teams.Any())
            {
                return;
            }

            var sqlEntries = teams.Select(TeamSql.FromCoreEntity).ToList();

            Logger.LogDebug($"Adding {sqlEntries.Count} teams to '{MetadataResolver.TableName<TeamSql>()}' table.");

            await DbConnection.InsertMany(sqlEntries).ExecuteAsync();
        }
Beispiel #13
0
    Binding DiscoverBinding <T>()
    {
        Binding binding = null;

        DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());
        FindResponse    discovered      = discoveryClient.Find(FindCriteria.CreateMexEndpointCriteria());

        foreach (EndpointDiscoveryMetadata mexEndpoint in discovered.Endpoints)
        {
            Debug.Assert(binding == null);

            ServiceEndpointCollection endpoints = MetadataResolver.Resolve(typeof(IMyContract), mexEndpoint.Address.Uri, MetadataExchangeClientMode.MetadataExchange);
            Debug.Assert(endpoints.Count == 1);

            binding = endpoints[0].Binding;
        }
        return(binding);
    }
Beispiel #14
0
            public string BuildQuery()
            {
                var table     = MetadataResolver.TableName <TEntity>();
                var selection = PropertySelectionResolver.GetSelectionFromProperty(_selection);

                string selectFrom = $"SELECT {selection} FROM {table}";

                _sqlBuilder.Append(selectFrom);

                if (_where != null)
                {
                    var whereCondition = WhereConditionBuilder <TEntity> .FromExpression(_where);

                    _sqlBuilder.Append($"WHERE {whereCondition}");
                }

                return(_sqlBuilder.GetResult(omitTerminatingSemiColon: true));
            }
Beispiel #15
0
        private void listBox1_Click(object sender, EventArgs e)
        {
            //Comment one of the URLs
            //Uri uri = new Uri("http://localhost:8000/EmployeeService?wsdl");
            //Uri uri = new Uri("http://Localhost/EmployeeServiceHostWeb/EmployeeServicerHost.svc?wsdl");

            Uri uri = new Uri(textBox1.Text);
            ServiceEndpointCollection endpts = MetadataResolver.Resolve(typeof(IEmployeeService), uri, MetadataExchangeClientMode.HttpGet);

            foreach (ServiceEndpoint obj in endpts)
            {
                IEmployeeService proxy = new ChannelFactory <IEmployeeService>(obj.Binding, obj.Address).CreateChannel();
                Employee         emp   = proxy.GetEmployee(int.Parse(listBox1.SelectedValue.ToString()));
                label5.Text = emp.EmployeeID.ToString();
                label6.Text = emp.FirstName;
                label7.Text = emp.LastName;
                ((IChannel)proxy).Close();
            }
        }
Beispiel #16
0
    T[] CreateChannelsFromMex <T>()
    {
        DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());
        FindResponse    discovered      = discoveryClient.Find(FindCriteria.CreateMexEndpointCriteria());

        List <T> list = new List <T>();

        foreach (EndpointDiscoveryMetadata mexEndpoint in discovered.Endpoints)
        {
            ServiceEndpointCollection endpoints = MetadataResolver.Resolve(typeof(IMyContract), mexEndpoint.Address.Uri, MetadataExchangeClientMode.MetadataExchange);
            foreach (ServiceEndpoint endpoint in endpoints)
            {
                T proxy = ChannelFactory <T> .CreateChannel(endpoint.Binding, endpoint.Address);

                list.Add(proxy);
            }
        }
        return(list.ToArray());
    }
Beispiel #17
0
        public Task UpdateAsync(Guid id, PlayerUpdate update)
        {
            if (id == Guid.Empty)
            {
                throw new ArgumentException("Player id must be provided.", nameof(id));
            }
            if (update == null)
            {
                throw new ArgumentNullException(nameof(update), "Update must be provided.");
            }

            Logger.LogDebug($"Updating player '{id}' in '{MetadataResolver.TableName<PlayerSql>()}' table.");

            return(DbConnection.Update <PlayerSql>()
                   .Where(p => p.Id == id)
                   .Set(p => p.Number, update.Number)
                   .Set(p => p.Position, update.Position)
                   .Set(p => p.Status, update.Status)
                   .ExecuteAsync());
        }
Beispiel #18
0
        public async Task UpdateRosterMappingsAsync(List <Roster> rosters)
        {
            if (rosters == null)
            {
                throw new ArgumentNullException(nameof(rosters), "Rosters must be provided.");
            }

            Logger.LogDebug($"Updating roster mappings for players in '{MetadataResolver.TableName<PlayerTeamMapSql>()}'.");

            await DbConnection.Truncate <PlayerTeamMapSql>().ExecuteAsync();

            List <PlayerSql> players = await DbConnection.Select <PlayerSql>(p => p.Id, p => p.NflId).ExecuteAsync();

            Dictionary <string, Guid> nflIdMap = players.ToDictionary(p => p.NflId, p => p.Id);

            foreach (Roster roster in rosters)
            {
                await UpdateForRosterAsync(roster, nflIdMap);
            }
        }
Beispiel #19
0
        void Run()
        {
            // Picks up configuration from the config file.
            this.wcfClient = new StatefulServiceClient();
            try
            {
                //<snippet10>
                // Download all metadata.
                ServiceEndpointCollection endpoints
                    = MetadataResolver.Resolve(
                          typeof(IStatefulService),
                          new EndpointAddress("http://localhost:8080/StatefulService/mex")
                          );
                //</snippet10>

                Console.WriteLine("Calling 5 times: ");

                for (int i = 0; i < 5; i++)
                {
                    string response = this.wcfClient.GetSessionID();
                    Console.WriteLine(response);
                }
                Console.WriteLine("Press ENTER to exit...");
                Console.ReadLine();
            }
            catch (TimeoutException timeProblem)
            {
                Console.WriteLine("The service operation timed out. " + timeProblem.Message);
            }
            catch (CommunicationException commProblem)
            {
                Console.WriteLine("There was a communication problem. " + commProblem.Message);
            }
            finally
            {
                if (wcfClient.State != CommunicationState.Closed)
                {
                    wcfClient.Close();
                }
            }
        }
Beispiel #20
0
        static void Main()
        {
            // Get all serviceEndpoints from the MEX endpoint of the service.
            ServiceEndpointCollection serviceEndpoints = MetadataResolver.Resolve(typeof(ICalculator), new EndpointAddress("http://localhost:8000/ServiceModelSamples/service/mex"));

            foreach (ServiceEndpoint endpoint in serviceEndpoints)
            {
                try
                {
                    Console.WriteLine("Creating a client with connecting to endpoint address {0}.", endpoint.Address.ToString());

                    CalculatorClient client = new CalculatorClient(endpoint.Binding, endpoint.Address);

                    // Add the InternetClientValidatorBehavior to the endpoint.
                    // The behaviors are evaluated when the client creates a ChannelFactory.
                    client.Endpoint.Behaviors.Add(new InternetClientValidatorBehavior());

                    client.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.CurrentUser, StoreName.My, X509FindType.FindBySubjectName, "client.com");
                    client.ClientCredentials.ServiceCertificate.SetDefaultCertificate(StoreLocation.CurrentUser, StoreName.TrustedPeople, X509FindType.FindBySubjectName, "localhost");
                    client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.PeerOrChainTrust;

                    // Call operations
                    // All invalid enpoints will fail when this is called.
                    DoCalculations(client);

                    client.Close();
                }
                catch (InvalidOperationException ex)
                {
                    // This exception is thrown in InternetClientValidatorBehavior.
                    Console.WriteLine(ex.Message);
                }
                Console.WriteLine();
            }

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }