Exemple #1
0
        private void ApproveApplication(Classes.WorkflowApplicationResponse ApplicationInfo)
        {
            try
            {
                this.textBox1.Text = string.Format("{0}\r\n{1}\r\n{2}", "Approval Message", ApplicationInfo.application, this.textBox1.Text);

                string _user = ApplicationInfo.user.Replace("//", @"\");
                this.textBox1.Text = string.Format("{0}\r\n{1}\r\n{2}", "Querying SF for app", ApplicationInfo.application, this.textBox1.Text);
                var _applicationSubscription = _store.GetSubscriptionInfo(_user, ApplicationInfo.application);
                if (_applicationSubscription != null)
                {
                    this.textBox1.Text = string.Format("{0}\r\n{1}\r\n{2}", "Subscription is not null", ApplicationInfo.application, this.textBox1.Text);
                    this.textBox1.Text = string.Format("{0}\r\n{1}\r\n{2}", "Found app", ApplicationInfo.application, this.textBox1.Text);
                    this.textBox1.Text = string.Format("{0}\r\n{1}\r\n{2}", "Updating app status", ApplicationInfo.application, this.textBox1.Text);
                    _applicationSubscription.Status = SubscriptionStatus.subscribed;
                    this.textBox1.Text = string.Format("{0}\r\n{1}\r\n{2}", "Saving status", ApplicationInfo.application, this.textBox1.Text);
                    _store.SetSubscriptionInfo(_applicationSubscription);
                    _store.SaveChanges();
                }
            }
            catch (Exception e)
            {
                this.textBox1.Text = string.Format("{0}\r\n{1}", "Error", e.Message);
            }
        }
Exemple #2
0
        private void SetupSocketListener(string UUID, string Token)
        {
            var _socket = IO.Socket(_meshbluEnbpoint, new IO.Options {
                Port = 443
            });

            _socket.On("connect", () =>
            {
                Console.WriteLine("Connect");
                _socket.On("identify", (data) =>
                {
                    Console.WriteLine("Sending device UUID to meshblu");
                    var _identity_data = new JObject();
                    _identity_data.Add("uuid", UUID);
                    _identity_data.Add("socketid", "data.socketid");
                    _identity_data.Add("token", Token);
                    _socket.Emit("identity", _identity_data);
                });
            });
            _socket.On("ready", (dynamic data) =>
            {
                this.textBox1.Invoke(new Action(() =>
                {
                    this.textBox1.Text = string.Format("{0}\r\n{1}", "Device Ready", this.textBox1.Text);
                }), null);

                if (data.status == 201)
                {
                    var _ready_data = new JObject();
                    _ready_data.Add("uuid", UUID);
                    _ready_data.Add("token", Token);
                    _socket.Emit("subscribe", _ready_data);
                }
            });
            _socket.On("notReady", (data) => {
                Console.WriteLine("Not Ready");
            });

            _socket.On("message", (data) =>
            {
                Console.WriteLine(data);

                JObject _meshbluMessage = JObject.Parse(data.ToString());
                Classes.WorkflowApplicationResponse _workflowResponse = JsonConvert.DeserializeObject <Classes.WorkflowApplicationResponse>(_meshbluMessage["payload"].ToString());

                if (_workflowResponse.status != null)
                {
                    this.textBox1.Invoke(new Action(() =>
                    {
                        this.textBox1.Text = string.Format("{0}\r\n{1}\r\n{2}", "Message Received from meshblu", data, this.textBox1.Text);
                    }), null);

                    this.textBox1.Invoke(new Action(() =>
                    {
                        this.textBox1.Text = string.Format("{0}{1}\r\n{2}", "Workflow Message:", _workflowResponse.status, this.textBox1.Text);
                        this.textBox1.Text = string.Format("{0}{1}\r\n{2}", "Workflow Message:", _workflowResponse.user, this.textBox1.Text);
                        this.textBox1.Text = string.Format("{0}{1}\r\n{2}", "Workflow Message:", _workflowResponse.application, this.textBox1.Text);
                    }), null);

                    switch (_workflowResponse.status.ToLower())
                    {
                    case "approved":
                        ApproveApplication(_workflowResponse);
                        break;

                    case "deny":
                        DenyApplication(_workflowResponse);
                        break;

                    default:
                        break;
                    }
                }
            });
        }
Exemple #3
0
        private void DenyApplication(Classes.WorkflowApplicationResponse ApplicationInfo)
        {
            var _applicationSubscription = _store.RemoveSubscriptionInfo(ApplicationInfo.user, ApplicationInfo.application);

            _store.SaveChanges();
        }