Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            InstanceContext site = new InstanceContext(null, new Client());
            ChannelFactory <IPublishData> factory = new ChannelFactory <IPublishData>("server");
            IPublishData client = factory.CreateChannel();

            Console.ReadLine();

            Console.WriteLine("Sending PublishPriceChange(Gold, 400.00D, -0.25D)");
            client.PublishPriceChange("Gold", 400.00D, -0.25D);
            Console.ReadLine();

            Console.WriteLine("Sending PublishPriceChange(Silver, 7.00D, -0.20D)");
            client.PublishPriceChange("Silver", 7.00D, -0.20D);
            Console.ReadLine();

            Console.WriteLine("Sending PublishPriceChange(Platinum, 850.00D, +0.50D)");
            client.PublishPriceChange("Platinum", 850.00D, +0.50D);
            Console.ReadLine();

            Console.WriteLine("Sending PublishPriceChange(Gold, 401.00D, 1.00D)");
            client.PublishPriceChange("Gold", 401.00D, 1.00D);
            Console.ReadLine();

            Console.WriteLine("Sending PublishPriceChange(Silver, 6.60D, -0.40D)");
            client.PublishPriceChange("Silver", 6.60D, -0.40D);
            Console.ReadLine();

            Console.WriteLine();
            Console.WriteLine("Press ENTER to shut down data source");
            Console.ReadLine();

            //Closing the client gracefully closes the connection and cleans up resources
            ((IChannel)client).Close();
        }
Ejemplo n.º 2
0
 private static object ToPublishFormat(IPublishable document, IPublishData data)
 {
     switch (document)
     {
         case OtherDocument otherDocument:
             return otherDocument.ToPublishFormat(data);
         // another documents
         default: throw new ArgumentOutOfRangeException();
     }
 }
Ejemplo n.º 3
0
        public async Task<string> PublishAsync(IPublishable document, IPublishData data, CancellationToken token)
        {
            token.ThrowIfCancellationRequested();
            using (var client = new HttpClient())
            {
                token.ThrowIfCancellationRequested();
                var message = await client.PostAsync("some url",
                    new StringContent(ToPublishFormat(document, data).ToString()), token);

                return message.Content.ToString();
            }
        }
        public static object ToPublishFormat(this OtherDocument document, IPublishData publishData)
        {
            var s = (OtherDocumentPublishData)publishData;

            return(document + s.SomeExtraData);
        }
Ejemplo n.º 5
0
 public void MarkAsPublished(IPublishable document, IPublishData data)
 {
     // mark as published logic
 }