Exemplo n.º 1
0
        private void Client_UploadDataCompleted(object sender, UploadDataCompletedEventArgs e)
        {
            if (OnComplete != null && !e.Cancelled)
            {
                if (e.Error == null)
                {
                    LLSD result = LLSDParser.DeserializeXml(e.Result);

                    try { OnComplete(this, result, e.Error); }
                    catch (Exception ex) { SecondLife.LogStatic(ex.ToString(), Helpers.LogLevel.Error); }
                }
                else
                {
                    if (Helpers.StringContains(e.Error.Message, "502"))
                    {
                        // These are normal, retry the request automatically
                        SecondLife.DebugLogStatic("502 error from capability " + _Client.Location);
                        StartRequest(_PostData, _ContentType);
                    }
                    else
                    {
                        try { OnComplete(this, null, e.Error); }
                        catch (Exception ex) { SecondLife.LogStatic(ex.ToString(), Helpers.LogLevel.Error); }
                    }
                }
            }
            else if (e.Cancelled)
            {
                SecondLife.DebugLogStatic("Capability action at " + _Client.Location + " cancelled");
            }
        }
Exemplo n.º 2
0
        public void Stop(bool immediate)
        {
            _Dead = true;

            if (immediate)
            {
                _Running = false;
            }

            if (_Client.IsBusy)
            {
                SecondLife.DebugLogStatic("Stopping a running event queue");
                _Client.CancelAsync();
            }
            else
            {
                SecondLife.DebugLogStatic("Stopping an already dead event queue");
            }
        }
Exemplo n.º 3
0
        public void StartRequest(byte[] postData, string contentType)
        {
            _PostData    = postData;
            _ContentType = contentType;

            if (_Client.IsBusy)
            {
                SecondLife.LogStatic("New CAPS request to " + _Client.Location +
                                     " initiated, closing previous request", Helpers.LogLevel.Warning);
                _Client.CancelAsync();
            }
            else
            {
                SecondLife.DebugLogStatic("New CAPS request to " + _Client.Location + " initiated");
            }

            // Proxy
            if (Proxy != null)
            {
                _Client.Proxy = Proxy;
            }

            // Content-Type
            _Client.Headers.Clear();
            if (!String.IsNullOrEmpty(contentType))
            {
                _Client.Headers.Add(HttpRequestHeader.ContentType, contentType);
            }
            else
            {
                _Client.Headers.Add(HttpRequestHeader.ContentType, "application/xml");
            }

            if (postData == null)
            {
                _Client.DownloadStringAsync(_Client.Location);
            }
            else
            {
                _Client.UploadDataAsync(_Client.Location, postData);
            }
        }
Exemplo n.º 4
0
        private void Client_OpenWriteCompleted(object sender, OpenWriteCompletedEventArgs e)
        {
            bool raiseEvent = false;

            if (!_Dead)
            {
                if (!_Running)
                {
                    raiseEvent = true;
                }

                // We are connected to the event queue
                _Running = true;
            }

            // Create an EventQueueGet request
            LLSDMap request = new LLSDMap();

            request["ack"]  = new LLSD();
            request["done"] = LLSD.FromBoolean(false);

            byte[] postData = LLSDParser.SerializeXmlBytes(request);

            _Client.UploadDataAsync(_Client.Location, postData);

            if (raiseEvent)
            {
                SecondLife.DebugLogStatic("Capabilities event queue connected");

                // The event queue is starting up for the first time
                if (OnConnected != null)
                {
                    try { OnConnected(); }
                    catch (Exception ex) { SecondLife.LogStatic(ex.ToString(), Helpers.LogLevel.Error); }
                }
            }
        }
Exemplo n.º 5
0
        private void Client_UploadDataCompleted(object sender, UploadDataCompletedEventArgs e)
        {
            LLSDArray events = null;
            int       ack    = 0;

            if (e.Error != null)
            {
                // Error occurred
                string message = e.Error.Message.ToLower();

                // Check what kind of exception happened
                if (Helpers.StringContains(message, "404") || Helpers.StringContains(message, "410"))
                {
                    SecondLife.LogStatic("Closing event queue at " + _Client.Location + " due to missing caps URI",
                                         Helpers.LogLevel.Info);

                    _Running = false;
                    _Dead    = true;
                }
                else if (!e.Cancelled && !Helpers.StringContains(message, "502"))
                {
                    SecondLife.LogStatic("Unrecognized caps exception from " + _Client.Location +
                                         ": " + e.Error.Message, Helpers.LogLevel.Warning);
                }
            }
            else if (!e.Cancelled && e.Result != null)
            {
                // Got a response
                LLSD result = LLSDParser.DeserializeXml(e.Result);
                if (result != null && result.Type == LLSDType.Map)
                {
                    // Parse any events returned by the event queue
                    LLSDMap map = (LLSDMap)result;

                    events = (LLSDArray)map["events"];
                    ack    = map["id"].AsInteger();
                }
            }
            else if (e.Cancelled)
            {
                // Connection was cancelled
                SecondLife.DebugLogStatic("Cancelled connection to event queue at " + _Client.Location);
            }

            if (_Running)
            {
                LLSDMap request = new LLSDMap();
                if (ack != 0)
                {
                    request["ack"] = LLSD.FromInteger(ack);
                }
                else
                {
                    request["ack"] = new LLSD();
                }
                request["done"] = LLSD.FromBoolean(_Dead);

                byte[] postData = LLSDParser.SerializeXmlBytes(request);

                _Client.UploadDataAsync(_Client.Location, postData);

                // If the event queue is dead at this point, turn it off since
                // that was the last thing we want to do
                if (_Dead)
                {
                    _Running = false;
                    SecondLife.DebugLogStatic("Sent event queue shutdown message");
                }
            }

            if (OnEvent != null && events != null && events.Count > 0)
            {
                // Fire callbacks for each event received
                foreach (LLSDMap evt in events)
                {
                    string  msg  = evt["message"].AsString();
                    LLSDMap body = (LLSDMap)evt["body"];

                    try { OnEvent(msg, body); }
                    catch (Exception ex) { SecondLife.LogStatic(ex.ToString(), Helpers.LogLevel.Error); }
                }
            }
        }