Пример #1
0
 public ActionResult Index()
 {
     StockServiceClient service = new StockServiceClient();
     // Product[] products = service.GetAllProducts();
     List<Product> products = service.GetAllProducts();
     return View(products);
 }
Пример #2
0
        private async void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            TestButton.IsEnabled = false;

            var sb = new StringBuilder();
            StockServiceClient proxy = new StockServiceClient();

            List<Task> tasks = new List<Task>();

            for (int i = 0; i < 5; i++)
            {
                sb.AppendFormat("{0}: Calling GetPrice", System.DateTime.Now);
                sb.AppendLine();

                var task = proxy.GetPriceAsync("MSFT")
                    .ContinueWith(
                        (prevTask) => sb.AppendFormat("{0}: Price:{1}\n", DateTime.Now, prevTask.Result));

                tasks.Add(task);
            }

            await Task.WhenAll(tasks);

            ResTextBox.Text = sb.ToString();

            TestButton.IsEnabled = true;
        }
Пример #3
0
        public static async Task SendCodeMessage(string message, string userName)
        {
            using (var wcfClient = new StockServiceClient())
            {
                await wcfClient.SendMessageAsync(message, "request", "response", userName);

                wcfClient.Close();
            }
        }
Пример #4
0
 public static QueueMessage FromByteArray(byte[] body)
 {
     using (var wcfClient = new StockServiceClient())
     {
         var result = wcfClient.FromByteArray(body);
         wcfClient.Close();
         return(result);
     }
 }
Пример #5
0
        static void Main(string[] args)
        {
            //for (int i = 0; i < 3; i++)
            //{
            //    Console.WriteLine("{0}: Calling GetPrice", System.DateTime.Now);
            //    proxy.BeginGetPrice("MSFT", GetPriceCallBack, proxy);
            //    Thread.Sleep(500);
            //    Interlocked.Increment(ref c);
            //}

            //TaskScheduler scheduler = TaskScheduler.FromCurrentSynchronizationContext();
            StockServiceClient proxy = new StockServiceClient("WSHttpBinding_IStockService");

            while (Console.ReadLine() == "")
            {
                var task = Task.Factory.StartNew(() =>
                {
                    //Invoke Service

                    Console.WriteLine("{0}: Calling GetPrice", System.DateTime.Now);
                    StockPrice res = proxy.GetPrice("test");

                    return(res);
                }).ContinueWith(i =>
                {
                    if (i.Exception != null)
                    {
                        //this.Dispatcher.BeginInvoke(new Action(() =>
                        // {

                        // }),null);
                    }
                    else
                    {
                        // this.Dispatcher.BeginInvoke(new Action(() =>
                        // {
                        Console.WriteLine("Result in : {0}, Price:{1},calls : {2}", System.DateTime.Now, i.Result.price, i.Result.calls);
                        Console.ReadLine();
                        // }),null);
                    }
                } /*scheduler*/);
            }
            Console.ReadLine();

            //while (true)
            //{
            //    Console.WriteLine("{0}: Calling GetPrice", System.DateTime.Now);
            //    StockPrice res = proxy.GetPrice("test");
            //    //proxy.BeginGetPrice("MSFT", GetPriceCallBack, proxy);
            //    Console.WriteLine("Result in : {0}, Price:{1},calls : {2}", System.DateTime.Now,res.price,res.calls);
            //    Console.ReadLine();
            //}

            //Console.ReadLine();
        }
Пример #6
0
        static void Main()
        {
            StockServiceClient proxy = new StockServiceClient();

            double p = proxy.GetPrice("msft");

            Console.WriteLine("Price:{0}", p);
            Console.ReadKey();

            proxy.Close();
        }
Пример #7
0
        static void Main(string[] args)
        {
            StockServiceClient proxy = new StockServiceClient("WSHttpBinding_IStockService");

            while (true)
            {
                Console.WriteLine("{0}: Calling GetPrice", System.DateTime.Now);
                StockPrice res = proxy.GetPrice("test");
                Console.WriteLine("Result in : {0}, Price:{1},calls : {2},\n requested by {3}", System.DateTime.Now, res.price, res.calls, res.RequestedBy);
                Console.ReadLine();
            }
        }
Пример #8
0
 public ActionResult Index()
 {
     try
     {
         StockServiceClient service = new StockServiceClient();
         Product[] products = service.GetAllProducts();
         return View(products);
     }
     catch (Exception ex)
     {
         return null;
     }
 }
Пример #9
0
 private void btnLogin_Click(object sender, EventArgs e)
 {
     StockServiceClient service = new StockServiceClient();
     if (service.AuthenticateUser(txtUserName.Text.Trim(), txtPassword.Text))
     {
         ParentForm.CurrentUser = txtUserName.Text.Trim();
         this.DialogResult = DialogResult.OK;
         BackToParent();
     }
     else
     {
         lblError.Text = "Foutieve Gebruikersnaam/Paswoord";
         lblError.Visible = true;
     }
 }
Пример #10
0
 public static void SendStockMessage(QueueMessage queueMessage, string queue)
 {
     using (var wcfClient = new StockServiceClient())
     {
         var stock = wcfClient.GetStock(queueMessage.Message);
         if (stock.Success)
         {
             wcfClient.SendMessageAsync($"{stock.Symbol} quote is {stock.CloseTyped.ToString("C2")} per share", queue, null, queueMessage.UserName);
         }
         else
         {
             wcfClient.SendMessageAsync(stock.ErrorMessage, queue, null, queueMessage.UserName);
         }
         wcfClient.Close();
     }
 }
Пример #11
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            StockServiceClient service = new StockServiceClient();

            if (service.AuthenticateUser(txtUserName.Text.Trim(), txtPassword.Text))
            {
                ParentForm.CurrentUser = txtUserName.Text.Trim();
                this.DialogResult      = DialogResult.OK;
                BackToParent();
            }
            else
            {
                lblError.Text    = "Foutieve Gebruikersnaam/Paswoord";
                lblError.Visible = true;
            }
        }
Пример #12
0
        static void Main(string[] args)
        {
            string ticker = "IBM";

            Console.WriteLine("Asking for {0}", ticker);
            StockServiceClient proxy = new StockServiceClient();

            Console.ReadLine();
            do
            {
                Info info = proxy.GetStockPrice(ticker);
                Console.WriteLine("Response:  name = {0}  value = {1:F2}", info.name, info.value);
                Console.WriteLine("(A)gain ?");
            } while (Console.ReadKey(true).KeyChar == 'a');
            proxy.Close();
        }
Пример #13
0
        static void Main(string[] args)
        {
            StockServiceClient service = new StockServiceClient();

            Console.WriteLine(service.GetMessage());
            Console.WriteLine("Enter name:");
            var name = Console.ReadLine();
            while (name != "quit")
            {
                try
                {
                    double price=service.GetPrice(name, 0);
                    Console.WriteLine(string.Format("Price: {0}", price));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                Console.WriteLine("Enter name:");
                name = Console.ReadLine();
            }
        }
Пример #14
0
        private static async Task Transmit(CancellationToken cancellation)
        {
            var client = new StockServiceClient();

            client.Endpoint.Address = new EndpointAddress($"soap.udp://{TransmitterAddress}:34197/StockService");

            while (true)
            {
                var stock    = _random.Next(randomMin, randomMax);
                var sendTask = client.SendStockAsync(stock); // no need for await?

                cancellation.ThrowIfCancellationRequested();

                Interlocked.Increment(ref _totalPackages);

                await sendTask;

                var message = $"Packages sent {_totalPackages}";
                Console.SetCursorPosition(Console.WindowWidth - message.Length, 0);
                Console.Write(message);

                cancellation.ThrowIfCancellationRequested();
            }
        }
Пример #15
0
 public ActionResult ZeroAllProducts(int code = 0)
 {
     StockServiceClient service = new StockServiceClient();
     service.ZeroAllProducts(code);
     return RedirectToAction("Index");
 }
Пример #16
0
 private void OpenConn()
 {
     if (client == null || client.State != System.ServiceModel.CommunicationState.Opened)
     {
         client = new StockServiceClient();
         client.ClientCredentials.Windows.ClientCredential.UserName = "******";
         client.ClientCredentials.Windows.ClientCredential.Password = "******";
     }
 }
Пример #17
0
 /// <summary>Initialises an instance of WCFStockRepository</summary>
 public WCFStockRepository()
 {
     Client = new StockServiceClient();
 }
Пример #18
0
 // GET: Home
 public ActionResult Index()
 {
     StockServiceClient service = new StockServiceClient();
     return View(service.GetAllProducts());
 }
Пример #19
0
 public ActionResult DeleteProduct(int productID, int code = 0)
 {
     StockServiceClient service = new StockServiceClient();
     service.DeleteProduct(code, productID);
     return RedirectToAction("Index");
 }
Пример #20
0
 public ActionResult AddNewProduct(string productName, int amount)
 {
     StockServiceClient service = new StockServiceClient();
     service.AddProduct(productName, amount);
     return RedirectToAction("Index");
 }
Пример #21
0
 public ActionResult SubAmount(Product product)
 {
     StockServiceClient service = new StockServiceClient();
     service.SubAmount(product.ProductID, product.Amount);
     return RedirectToAction("Index");
 }
Пример #22
0
 public Form1()
 {
     InitializeComponent();
     ServiceClient = new StockServiceClient();
 }
Пример #23
0
 public ActionResult RenameProduct(int productID, string newName, int code = 0)
 {
     StockServiceClient service = new StockServiceClient();
     service.RenameProduct(code, productID,newName);
     return RedirectToAction("Index");
 }
        protected void Button1_Click(object sender, EventArgs e)
        {
            StockServiceClient myStockSvc = new StockServiceClient();

            lblQuote.Text = myStockSvc.GetQuote(txtSymbol.Text);
        }