示例#1
0
 private async void send(Ticket ticket)
 {
     await client.SendTicket(ticket);
 }
示例#2
0
        private void trySend()
        {
            if (!validateEmail())
            {
                return;
            }

            Ticket ticket = new Ticket();
            ticket.Address = address;
            ticket.Content = content;
            ticket.Product = (ProductEnum)selectedProduct;
            ticket.TypeId = selectedType;

            //history.Items.Add(ticket);
            history.Items.Insert(0, ticket);
            History.Items = new List<Ticket>(history.Items);

            send(ticket);

            Address = string.Empty;
        }
示例#3
0
        //bool fail = false;

        public async Task SendTicket(Ticket ticket)
        {
            ticket.IsProcessing = true;
            ticket.SuccessVisibility = Windows.UI.Xaml.Visibility.Collapsed;
            ticket.ErrorVisibility = Windows.UI.Xaml.Visibility.Collapsed;

            HttpWebResponse response = null;
            StreamReader reader = null;
            Stream stream = null;

            try
            {
                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://crm.kromtech.net/?APP=003&MOD=tickets&action=respond_form");
                this.cookies = await storage.ReadCookies();
                request.CookieContainer = this.cookies;
                request.Method = "POST";
                request.ContentType = "application/x-www-form-urlencoded";
                stream = await request.GetRequestStreamAsync();
                string postString = string.Format("message_srv=kromtech.com&message_from=00077&message_to={0}&message_subject={1}&cval_value_Product={2}&cval_value_Language=English&cval_value_Issue=Technical&cval_value_Technical Problem_7977=Other technical&message={3}&send=1", ticket.Address, ticket.Subject, ticket.Product, ticket.Content);
                byte[] buffer = Encoding.UTF8.GetBytes(postString);
                await stream.WriteAsync(buffer, 0, buffer.Length);
                //string content = string.Format("{0}\n{1}\n{2}", ticket.Product, ticket.Subject, ticket.TypeId);
                //await new MessageDialog(content).ShowAsync();

                //await Task.Delay(3000);

                //if (fail)
                //{
                //    fail = false;
                //    throw new Exception("Error");
                //}

                //ticket.Id = ticket.Address.GetHashCode() > 0 ? ticket.Address.GetHashCode() : ticket.Address.GetHashCode() * -1;

                //fail = true;

                //ticket was sent
                response = (HttpWebResponse)await request.GetResponseAsync();

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    reader = new StreamReader(response.GetResponseStream());
                    string content = await reader.ReadToEndAsync();
                    ticket.Id = Convert.ToInt32(content.Substring(content.IndexOf("ticket_id="), 30).Split('=')[1].Split('\'')[0]);
                    ticket.IsSent = true;
                    ticket.SuccessVisibility = Windows.UI.Xaml.Visibility.Visible;
                }

                ticket.ErrorVisibility = Windows.UI.Xaml.Visibility.Collapsed;
                ticket.IsSent = true;
            }
            catch (Exception)
            {
                ticket.IsSent = false;
            }
            finally
            {
                ticket.IsProcessing = false;

                if (response != null)
                {
                    response.Dispose();
                    response = null;
                }

                if (reader != null)
                {
                    reader.Dispose();
                    reader = null;
                }

                if (stream != null)
                {
                    stream.Dispose();
                    stream = null;
                }
            }
        }
示例#4
0
 public bool Equals(Ticket ticket)
 {
     return this.Address == ticket.Address;
 }
示例#5
0
 private async void send(Ticket ticket)
 {
     await client.SendTicket(ticket);
 }