当前位置: 首页>>代码示例>>C#>>正文


C# OSDMap.AsString方法代码示例

本文整理汇总了C#中OSDMap.AsString方法的典型用法代码示例。如果您正苦于以下问题:C# OSDMap.AsString方法的具体用法?C# OSDMap.AsString怎么用?C# OSDMap.AsString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OSDMap的用法示例。


在下文中一共展示了OSDMap.AsString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Deserialize

        /// <summary>
        /// Deserialize the message
        /// </summary>
        /// <param name="map">An <see cref="OSDMap"/> containing the data</param>
        public void Deserialize(OSDMap map)
        {
            if (map.ContainsKey("item_id"))
                Request = new UpdateAgentInventoryRequestMessage();
            else if (map.ContainsKey("state") && map["state"].AsString().Equals("upload"))
                Request = new UploaderRequestUpload();
            else if (map.ContainsKey("state") && map["state"].AsString().Equals("complete"))
                Request = new UploaderRequestComplete();
            else
                Logger.Log("Unable to deserialize UpdateGestureAgentInventory: No message handler exists: " + map.AsString(), Helpers.LogLevel.Warning);

            if (Request != null)
                Request.Deserialize(map);
        }
开发者ID:justincc,项目名称:libopenmetaverse,代码行数:18,代码来源:LindenMessages.cs

示例2: ServiceOSDRequest


//.........这里部分代码省略.........
                int tickstart = Util.EnvironmentTickCount();
                int tickdata = 0;
                int tickserialize = 0;
                byte[] buffer = data != null ? Encoding.UTF8.GetBytes(OSDParser.SerializeJsonString(data, true)) : null;
                HttpWebRequest request = null;
                try
                {
                    request = (HttpWebRequest)WebRequest.Create(url);
                    request.Method = method;
                    request.Timeout = timeout;
                    request.KeepAlive = false;
                    request.MaximumAutomaticRedirections = 10;
                    request.ReadWriteTimeout = timeout / 4;

                    // If there is some input, write it into the request
                    if (buffer != null && buffer.Length > 0)
                    {
                        request.ContentType = "application/json";
                        request.ContentLength = buffer.Length; //Count bytes to send
                        using (Stream requestStream = request.GetRequestStream())
                            requestStream.Write(buffer, 0, buffer.Length); //Send it
                    }

                    // capture how much time was spent writing, this may seem silly
                    // but with the number concurrent requests, this often blocks
                    tickdata = Util.EnvironmentTickCountSubtract(tickstart);

                    using (WebResponse response = request.GetResponse())
                    {
                        using (Stream responseStream = response.GetResponseStream())
                        {
                            // capture how much time was spent writing, this may seem silly
                            // but with the number concurrent requests, this often blocks
                            tickserialize = Util.EnvironmentTickCountSubtract(tickstart) - tickdata;
                            string responseStr = responseStream.GetStreamString();
                            // MainConsole.Instance.DebugFormat("[WEB UTIL]: <{0}> response is <{1}>",reqnum,responseStr);
                            return responseStr;
                        }
                    }
                }
                catch (WebException we)
                {
                    errorMessage = we.Message;
                    if (we.Status == WebExceptionStatus.ProtocolError)
                    {
                        HttpWebResponse webResponse = (HttpWebResponse)we.Response;
                        if (webResponse.StatusCode == HttpStatusCode.BadRequest)
                            MainConsole.Instance.WarnFormat("[WebUtils]: bad request to {0}, data {1}", url,
                                             data != null ? OSDParser.SerializeJsonString(data) : "");
                        else
                            MainConsole.Instance.WarnFormat("[WebUtils]: {0} to {1}, data {2}, response {3}", webResponse.StatusCode, url,
                                             data != null ? OSDParser.SerializeJsonString(data) : "", webResponse.StatusDescription);
                        return "";
                    }
                    if (request != null)
                        request.Abort();
                }
                catch (Exception ex)
                {
                    if (ex is System.UriFormatException)
                        errorMessage = ex.ToString() + " " + new System.Diagnostics.StackTrace().ToString();
                    else
                        errorMessage = ex.Message;
                    if (request != null)
                        request.Abort();
                }
                finally
                {
                    if (MainConsole.Instance != null)
                    {
                        if (errorMessage == "unknown error")
                        {
                            // This just dumps a warning for any operation that takes more than 500 ms
                            int tickdiff = Util.EnvironmentTickCountSubtract(tickstart);
                            if (MainConsole.Instance.IsEnabled(Level.All))
                            {
                                System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace();

                                MainConsole.Instance.TraceFormat(
                                    "[WebUtils]: osd request (URI:{0}, METHOD:{1}, UPSTACK(4):{5}) took {2}ms overall, {3}ms writing, {4}ms deserializing",
                                    url, method, tickdiff, tickdata, tickserialize, stackTrace.GetFrame(4).GetMethod().Name + " @ " + stackTrace.GetFrame(4).GetFileName() + ":" + stackTrace.GetFrame(4).GetFileLineNumber());
                            }
                            else
                                MainConsole.Instance.TraceFormat(
                                    "[WebUtils]: osd request (URI:{0}, METHOD:{1}) took {2}ms overall, {3}ms writing, {4}ms deserializing",
                                    url, method, tickdiff, tickdata, tickserialize);
                            if (tickdiff > 5000)
                                MainConsole.Instance.InfoFormat(
                                    "[WebUtils]: osd request took too long (URI:{0}, METHOD:{1}) took {2}ms overall, {3}ms writing, {4}ms deserializing",
                                    url, method, tickdiff, tickdata, tickserialize);
                        }
                    }
                }

                if (MainConsole.Instance != null)
                    MainConsole.Instance.WarnFormat("[WebUtils] osd request failed: {0} to {1}, data {2}", errorMessage, url,
                                     data != null ? data.AsString() : "");
                return "";
            }
        }
开发者ID:BillyWarrhol,项目名称:Aurora-Sim,代码行数:101,代码来源:WebUtils.cs

示例3: ServiceOSDRequest

        public static OSDMap ServiceOSDRequest(string url, OSDMap data, string method, int timeout)
        {
            int reqnum = m_requestNumber++;
            // m_log.DebugFormat("[WEB UTIL]: <{0}> start osd request for {1}, method {2}",reqnum,url,method);

            string errorMessage = "unknown error";
            int tickstart = Util.EnvironmentTickCount();
            int tickdata = 0;

            if(url == "")
                return ErrorResponseMap("No URL given.");

            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.Method = method;
                request.Timeout = timeout;
                request.KeepAlive = false;
                request.MaximumAutomaticRedirections = 10;
                request.ReadWriteTimeout = timeout / 4;
                request.Headers[OSHeaderRequestID] = reqnum.ToString();

                // If there is some input, write it into the request
                if (data != null)
                {
                    string strBuffer = OSDParser.SerializeJsonString(data);
                    byte[] buffer = System.Text.Encoding.UTF8.GetBytes(strBuffer);

                    if (buffer.Length <= 0)
                    {
                    }
                    else
                    {
                        request.ContentType = "application/json";
                        request.ContentLength = buffer.Length;   //Count bytes to send
                        using (Stream requestStream = request.GetRequestStream())
                            requestStream.Write(buffer, 0, buffer.Length);         //Send it
                    }
                }

                // capture how much time was spent writing, this may seem silly
                // but with the number concurrent requests, this often blocks
                tickdata = Util.EnvironmentTickCountSubtract(tickstart);

                using (WebResponse response = request.GetResponse())
                {
                    using (Stream responseStream = response.GetResponseStream())
                    {
                        string responseStr = null;
                        responseStr = responseStream.GetStreamString();
                        // m_log.DebugFormat("[WEB UTIL]: <{0}> response is <{1}>",reqnum,responseStr);
                        return CanonicalizeResults(responseStr);
                    }
                }
            }
            catch (WebException we)
            {
                errorMessage = we.Message;
                if (we.Status == WebExceptionStatus.ProtocolError)
                {
                    HttpWebResponse webResponse = (HttpWebResponse)we.Response;
                    errorMessage = String.Format("[{0}] {1}", webResponse.StatusCode, webResponse.StatusDescription);
                }
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
            }
            finally
            {
                // This just dumps a warning for any operation that takes more than 100 ms
                int tickdiff = Util.EnvironmentTickCountSubtract(tickstart);
                if (tickdiff > LongCallTime)
                    m_log.InfoFormat("[WebUtils]: osd request <{0}> (URI:{1}, METHOD:{2}) took {3}ms overall, {4}ms writing",
                                     reqnum, url, method, tickdiff, tickdata);
            }

            m_log.WarnFormat("[WebUtils] <{0}> osd request failed: {1} to {2}, data {3}", reqnum, errorMessage, url, data != null ? data.AsString() : "");
            return ErrorResponseMap(errorMessage);
        }
开发者ID:kow,项目名称:Aurora-Sim,代码行数:80,代码来源:WebUtils.cs

示例4: ServiceOSDRequest

        public static string ServiceOSDRequest(string url, OSDMap data, string method, int timeout)
        {
            // MainConsole.Instance.DebugFormat("[WEB UTIL]: <{0}> start osd request for {1}, method {2}",reqnum,url,method);

            string errorMessage = "unknown error";
            int tickstart = Util.EnvironmentTickCount();
            int tickdata = 0;
            int tickserialize = 0;

            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.Method = method;
                request.Timeout = timeout;
                request.KeepAlive = false;
                request.MaximumAutomaticRedirections = 10;
                request.ReadWriteTimeout = timeout / 2;

                // If there is some input, write it into the request
                if (data != null)
                {
                    string strBuffer = OSDParser.SerializeJsonString(data, true);
                    byte[] buffer = Encoding.UTF8.GetBytes(strBuffer);

                    if (buffer.Length <= 0)
                    {
                    }
                    else
                    {
                        request.ContentType = "application/json";
                        request.ContentLength = buffer.Length; //Count bytes to send
                        using (Stream requestStream = request.GetRequestStream())
                            requestStream.Write(buffer, 0, buffer.Length); //Send it
                    }
                }

                // capture how much time was spent writing, this may seem silly
                // but with the number concurrent requests, this often blocks
                tickdata = Util.EnvironmentTickCountSubtract(tickstart);

                using (WebResponse response = request.GetResponse())
                {
                    using (Stream responseStream = response.GetResponseStream())
                    {
                        // capture how much time was spent writing, this may seem silly
                        // but with the number concurrent requests, this often blocks
                        tickserialize = Util.EnvironmentTickCountSubtract(tickstart) - tickdata;
                        string responseStr = responseStream.GetStreamString();
                        // MainConsole.Instance.DebugFormat("[WEB UTIL]: <{0}> response is <{1}>",reqnum,responseStr);
                        return responseStr;
                    }
                }
            }
            catch (WebException we)
            {
                errorMessage = we.Message;
                if (we.Status == WebExceptionStatus.ProtocolError)
                {
                    HttpWebResponse webResponse = (HttpWebResponse)we.Response;
                    errorMessage = String.Format("[{0}] {1}", webResponse.StatusCode, webResponse.StatusDescription);
                }
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
            }
            finally
            {
                if (errorMessage == "unknown error")
                {
                    // This just dumps a warning for any operation that takes more than 500 ms
                    int tickdiff = Util.EnvironmentTickCountSubtract(tickstart);
                    MainConsole.Instance.TraceFormat(
                        "[WebUtils]: osd request took too long (URI:{0}, METHOD:{1}) took {2}ms overall, {3}ms writing, {4}ms deserializing",
                        url, method, tickdiff, tickdata, tickserialize);
                    if (tickdiff > 5000)
                        MainConsole.Instance.InfoFormat(
                            "[WebUtils]: osd request took too long (URI:{0}, METHOD:{1}) took {2}ms overall, {3}ms writing, {4}ms deserializing",
                            url, method, tickdiff, tickdata, tickserialize);
                }
            }

            MainConsole.Instance.WarnFormat("[WebUtils] osd request failed: {0} to {1}, data {2}", errorMessage, url,
                             data != null ? data.AsString() : "");
            return "";
        }
开发者ID:EnricoNirvana,项目名称:Aurora-Sim,代码行数:86,代码来源:ConnectorBase.cs

示例5: ServiceOSDRequest

        public static async Task<string> ServiceOSDRequest(string url, OSDMap data, string method, int timeout)
        {
            string errorMessage = "", response = null;
            int tickstart = Util.EnvironmentTickCount(), tickelapsed = 0;
            byte[] buffer = data != null ? Encoding.UTF8.GetBytes(OSDParser.SerializeJsonString(data, true)) : null;
            try
            {
                HttpClient client = new HttpClient();
                client.Timeout = TimeSpan.FromMilliseconds(timeout);

                HttpResponseMessage httpresponse;
                switch (method)
                {
                    case "PUT":
                        httpresponse = await client.PutAsync(url, new ByteArrayContent(buffer));
                        break;
                    case "DELETE":
                        httpresponse = await client.DeleteAsync(url);
                        break;
                    case "POST":
                        httpresponse = await client.PostAsync(url, new ByteArrayContent(buffer));
                        break;
                    case "GET":
                        httpresponse = await client.GetAsync(url);
                        break;
                    default:
                        httpresponse = await client.SendAsync(new HttpRequestMessage(new HttpMethod(method), url) { Content = new ByteArrayContent(buffer) });
                        break;
                }
                httpresponse.EnsureSuccessStatusCode();

                response = await httpresponse.Content.ReadAsStringAsync();

                tickelapsed = Util.EnvironmentTickCountSubtract(tickstart);

                if (MainConsole.Instance != null)
                {
                    if (errorMessage == "")//No error
                    {
                        // This just dumps a warning for any operation that takes more than 500 ms
                        if (MainConsole.Instance.IsDebugEnabled)
                        {
                            System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace();

                            MainConsole.Instance.Debug(
                                string.Format("[WebUtils]: osd request (URI:{0}, METHOD:{1}, UPSTACK(4):{3}) took {2}ms",
                                url, method, tickelapsed,
                                stackTrace.GetFrame(3).GetMethod().Name));
                        }
                        if (tickelapsed > 5000)
                            MainConsole.Instance.Info(
                                string.Format("[WebUtils]: osd request took too long (URI:{0}, METHOD:{1}) took {2}ms",
                                url, method, tickelapsed));
                    }
                }
            }
            catch (Exception ex)
            {
                if (MainConsole.Instance != null)
                    MainConsole.Instance.WarnFormat("[WebUtils] osd request failed: {0} to {1}, data {2}", ex.ToString(),
                                                    url,
                                                    data != null ? data.AsString() : "");
            }
            return response;
        }
开发者ID:justasabc,项目名称:Aurora-Sim,代码行数:65,代码来源:WebUtils.cs


注:本文中的OSDMap.AsString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。