private void button1_Click(object sender, EventArgs e)
        {
            if ( textBox1.Text.Trim() == "")
            {
                MessageBox.Show("You must enter a managers email for approval");
                return;
            }

            button1.Enabled = false;
            button2.Enabled = true;

            this._watchTimer = new Timer();
            this._watchTimer.Interval = 15000;
            this._watchTimer.Tick += async (timer_sender, eventargs) =>
            {
                IEnumerable<SubInfo> _subs = null;
                if ( _queriedInitialSubscriptions == false)
                {
                    //query all subscriptions
                    _subs = _store.GetAllSubscriptions();
                    _queriedInitialSubscriptions = true;
                }
                else
                {
                    // only grab the new subscriptions since the last time we queried. (The dll handles this)
                    _subs = _store.GetNewSubscriptions();
                }

                foreach (var _subInfo in _subs)
                {
                    if (_subInfo.Status == SubscriptionStatus.pending)
                    {
                        this.textBox1.Text = string.Format("{0}\r\n{1}", "Found subscription", this.textBox1.Text);

                        //call the octoblu workflow
                        string _user = _subInfo.User;
                        string _resourceName = _subInfo.Resource;
                        string _status = _subInfo.Status.ToString();

                        this.textBox1.Text = string.Format("Subscription Info: {0}\r\n{1}", _subInfo.Sid, this.textBox1.Text);

                        Classes.WorkflowApplicationRequest _wfInfo = new Classes.WorkflowApplicationRequest
                        {
                            type = "request",
                            user = _user.Replace("\\", "//"),
                            application = HttpUtility.HtmlEncode(_resourceName),
                            monitordeviceid = _deviceUUID,
                            manageremail = txtManagerEmail.Text
                        };

                        this.textBox1.Text = string.Format("{0}\r\n{1}", "Posting to the Octoblu endpoint", this.textBox1.Text);
                        this.textBox1.Text = string.Format("{0}\r\n{1}\r\n{2}", "Data to endpoint:", Newtonsoft.Json.JsonConvert.SerializeObject(_wfInfo), this.textBox1.Text);
                        //post to the endpoint
                        HttpClient _client = new HttpClient();
                        StringContent _bodyJson = new StringContent(
                            Newtonsoft.Json.JsonConvert.SerializeObject(_wfInfo),
                            UTF8Encoding.UTF8,
                            "application/json");

                        HttpResponseMessage _postResp = await _client.PostAsync(_workflowEndpoint, _bodyJson);
                        if (_postResp.StatusCode == System.Net.HttpStatusCode.Created)
                        {
                            this.textBox1.Text = string.Format("{0}\r\n{1}", "Post was successful", this.textBox1.Text);
                        }
                        else
                        {
                            this.textBox1.Text = string.Format("{0}\r\n{1}\r\n{2}", "Something happened - Message:", _postResp.ReasonPhrase, this.textBox1.Text);
                        }
                    }
                }
            };

            //start the timer
            this._watchTimer.Start();
        }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Trim() == "")
            {
                MessageBox.Show("You must enter a managers email for approval");
                return;
            }

            button1.Enabled = false;
            button2.Enabled = true;

            this._watchTimer          = new Timer();
            this._watchTimer.Interval = 15000;
            this._watchTimer.Tick    += async(timer_sender, eventargs) =>
            {
                IEnumerable <SubInfo> _subs = null;
                if (_queriedInitialSubscriptions == false)
                {
                    //query all subscriptions
                    _subs = _store.GetAllSubscriptions();
                    _queriedInitialSubscriptions = true;
                }
                else
                {
                    // only grab the new subscriptions since the last time we queried. (The dll handles this)
                    _subs = _store.GetNewSubscriptions();
                }

                foreach (var _subInfo in _subs)
                {
                    if (_subInfo.Status == SubscriptionStatus.pending)
                    {
                        this.textBox1.Text = string.Format("{0}\r\n{1}", "Found subscription", this.textBox1.Text);

                        //call the octoblu workflow
                        string _user         = _subInfo.User;
                        string _resourceName = _subInfo.Resource;
                        string _status       = _subInfo.Status.ToString();

                        this.textBox1.Text = string.Format("Subscription Info: {0}\r\n{1}", _subInfo.Sid, this.textBox1.Text);

                        Classes.WorkflowApplicationRequest _wfInfo = new Classes.WorkflowApplicationRequest
                        {
                            type            = "request",
                            user            = _user.Replace("\\", "//"),
                            application     = HttpUtility.HtmlEncode(_resourceName),
                            monitordeviceid = _deviceUUID,
                            manageremail    = txtManagerEmail.Text
                        };

                        this.textBox1.Text = string.Format("{0}\r\n{1}", "Posting to the Octoblu endpoint", this.textBox1.Text);
                        this.textBox1.Text = string.Format("{0}\r\n{1}\r\n{2}", "Data to endpoint:", Newtonsoft.Json.JsonConvert.SerializeObject(_wfInfo), this.textBox1.Text);
                        //post to the endpoint
                        HttpClient    _client   = new HttpClient();
                        StringContent _bodyJson = new StringContent(
                            Newtonsoft.Json.JsonConvert.SerializeObject(_wfInfo),
                            UTF8Encoding.UTF8,
                            "application/json");

                        HttpResponseMessage _postResp = await _client.PostAsync(_workflowEndpoint, _bodyJson);

                        if (_postResp.StatusCode == System.Net.HttpStatusCode.Created)
                        {
                            this.textBox1.Text = string.Format("{0}\r\n{1}", "Post was successful", this.textBox1.Text);
                        }
                        else
                        {
                            this.textBox1.Text = string.Format("{0}\r\n{1}\r\n{2}", "Something happened - Message:", _postResp.ReasonPhrase, this.textBox1.Text);
                        }
                    }
                }
            };

            //start the timer
            this._watchTimer.Start();
        }