Flush() публичный абстрактный Метод

Flushes whatever is in the buffer to the underlying streams and also flushes the underlying stream.
public abstract Flush ( ) : void
Результат void
Пример #1
0
 public static string FromHashtableQueue(Queue<Hashtable> queue)
 {
     StringWriter textWriter = new StringWriter();
     JsonWriter jsonWriter = new JsonWriter(textWriter);
     jsonWriter.WriteStartArray();
     JsonSerializer serializer = new JsonSerializer();
     UUIDConverter UUID = new UUIDConverter();
     serializer.Converters.Add(UUID);
     while (queue.Count > 0)
     {
         try
         {
             Hashtable hashtable = queue.Dequeue();
             serializer.Serialize(jsonWriter, hashtable);
         }
         catch(Exception e)
         {
             AjaxLife.Debug("MakeJson.FromHashTable", e.Message);
         }
     }
     jsonWriter.WriteEndArray();
     jsonWriter.Flush();
     string text = textWriter.ToString();
     jsonWriter.Close();
     textWriter.Dispose();
     return text;
 }
Пример #2
0
        public static void JsonResponse(HttpResponse response, Action<JsonWriter> writeAction)
        {
            response.ClearHeaders();
            response.ClearContent();

            JsonWriter writer = new JsonWriter(response.Output);

            writeAction(writer);

            writer.Flush();
        }
Пример #3
0
        public static void JsonResponse(HttpResponse response, Action <JsonWriter> writeAction)
        {
            response.ClearHeaders();
            response.ClearContent();

            JsonWriter writer = new JsonWriter(response.Output);

            writeAction(writer);

            writer.Flush();
        }
Пример #4
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            writer.WriteStartObject();

            writer.WritePropertyName("value");
            writer.WriteValue((value).ToString());

            writer.WriteEndObject();

            writer.Flush();
        }
Пример #5
0
 public static string FromObject(object obj)
 {
     StringWriter textWriter = new StringWriter();
     JsonWriter jsonWriter = new JsonWriter(textWriter);
     JsonSerializer serializer = new JsonSerializer();
     LLUUIDConverter UUID = new LLUUIDConverter();
     serializer.Converters.Add(UUID);
     serializer.Serialize(jsonWriter, obj);
     jsonWriter.Flush();
     string text = textWriter.ToString();
     jsonWriter.Close();
     textWriter.Dispose();
     return text;
 }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var products = (List<Product>)value;

            foreach (var product in products)
            {
                writer.WriteStartObject();

                writer.WritePropertyName(product.ProductSKU);
                writer.WriteRawValue(JsonConvert.SerializeObject(product.ProductData));

                writer.WriteEndObject();
            }

            writer.Flush();
        }
Пример #7
0
 public static string FromHashtableQueue(Queue<Hashtable> queue)
 {
     StringWriter textWriter = new StringWriter();
     JsonWriter jsonWriter = new JsonWriter(textWriter);
     jsonWriter.WriteStartArray();
     JsonSerializer serializer = new JsonSerializer();
     LLUUIDConverter UUID = new LLUUIDConverter();
     serializer.Converters.Add(UUID);
     while (queue.Count > 0)
     {
         Hashtable hashtable = queue.Dequeue();
         serializer.Serialize(jsonWriter, hashtable);
     }
     jsonWriter.WriteEndArray();
     jsonWriter.Flush();
     string text = textWriter.ToString();
     jsonWriter.Close();
     textWriter.Dispose();
     return text;
 }
Пример #8
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (value == null)
            {
                serializer.Serialize(writer, null);
                return;
            }

            //Get all the properties that contain either the CopernicaField of the CopernicaKeyField attribute.
            var properties = value.GetType().GetProperties().Where(x => x.GetCustomAttributes(false).Any(y => y.GetType() == typeof(CopernicaField) || y.GetType() == typeof(CopernicaKeyField)));
            
            //Loop through the properties and add the CopernicaField name + property value to the JObject.
            //This makes sure the mapping is right when serializing the object.
            JObject obj = new JObject();
            foreach (var property in properties)
            {
                obj.Add(property.GetCustomAttribute<CopernicaField>().Name, property.GetValue(value) == null ? "" : property.GetValue(value).ToString());
            }
            obj.WriteTo(writer);

            writer.Flush();
        }
        public Task Serialize(IResourceCollectionDocument document, JsonWriter writer)
        {
            writer.WriteStartObject();

            writer.WritePropertyName(PrimaryDataKeyName);

            writer.WriteStartArray();
            foreach (var resourceObject in document.PrimaryData)
            {
                _resourceObjectFormatter.Serialize(resourceObject, writer);
            }
            writer.WriteEndArray();

            if (document.RelatedData != null && document.RelatedData.Any())
            {
                writer.WritePropertyName(RelatedDataKeyName);
                writer.WriteStartArray();
                foreach (var resourceObject in document.RelatedData)
                {
                    _resourceObjectFormatter.Serialize(resourceObject, writer);
                }
                writer.WriteEndArray();
            }

            if (document.Metadata != null)
            {
                writer.WritePropertyName(MetaKeyName);
                _metadataFormatter.Serialize(document.Metadata, writer);
            }

            writer.WriteEndObject();

            writer.Flush();

            return Task.FromResult(0);
        }
Пример #10
0
 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     writer.WriteValue(Convert.ToDateTime(value).AddMinutes(_timeZoneOffset).ToString(_dateFormat));
     writer.Flush();
 }
Пример #11
0
        /// <summary>The write json.</summary>
        /// <param name="writer">The writer.</param>
        /// <param name="value">The value.</param>
        /// <param name="serializer">The serializer.</param>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (writer == null)
            {
                return;
            }

            var row = value as OrderRow;
            if (row == null)
            {
                return;
            }

            writer.WriteStartArray();
            writer.WriteRawValue(row.Price.ToInvariantString(2));
            writer.WriteRawValue(row.VolRemaining.ToInvariantString());
            writer.WriteRawValue(row.Range.ToInvariantString());
            writer.WriteRawValue(row.OrderId.ToInvariantString());
            writer.WriteRawValue(row.VolEntered.ToInvariantString());
            writer.WriteRawValue(row.MinVolume.ToInvariantString());
            writer.WriteRawValue(row.Bid.ToInvariantString());
            writer.WriteValue(row.IssueDate);
            writer.WriteRawValue(row.Duration.ToInvariantString());
            writer.WriteRawValue(row.StationId.ToInvariantString());
            writer.WriteRawValue(row.SolarSystemId.ToInvariantString());
            writer.WriteEndArray();

            writer.Flush();
        }
Пример #12
0
        private string GenerateJsonSchema()
        {
            List<string> required = new List<string>();
            MemoryStream stream = new MemoryStream();
            JsonWriter writer = new JsonWriter(stream);
            writer.WriteObject();

            writer.WriteMember("$schema");
            writer.WriteValue("http://json-schema.org/draft-04/schema");

            writer.WriteMember("title");
            writer.WriteValue(Object.Name);

            writer.WriteMember("type");
            writer.WriteValue("object");

            writer.WriteMember("properties");

            AddJsonProperties(writer, Object.GetProperties(), false);

            if (required.Count > 0)
            {
                writer.WriteMember("required");
                writer.WriteArray();
                foreach (string requirement in required)
                {
                    writer.WriteValue(requirement);
                }
                writer.WriteEndArray();
            }

            writer.WriteEndObject();

            writer.Flush();
            stream.Position = 0;

            string unformattedJsonBody = new StreamReader(stream).ReadToEnd();
            object parsedJson = JsonConvert.DeserializeObject(unformattedJsonBody);
            return JsonConvert.SerializeObject(parsedJson, Newtonsoft.Json.Formatting.Indented);
        }
Пример #13
0
         public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
         {
            var searchResult = (CourseCatalogSearchResult)value;
            var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);
            writer.WriteStartObject();

            writer.WritePropertyName("draw");
            writer.WriteValue(searchResult.draw);

            writer.WritePropertyName("recordsTotal");
            writer.WriteValue(searchResult.recordsTotal);

            writer.WritePropertyName("recordsFiltered");
            writer.WriteValue(searchResult.recordsFiltered);

            writer.WritePropertyName("catalog");
            writer.WriteStartArray();
            foreach (var entry in searchResult.catalog)
            {
               writer.WriteStartObject();

               writer.WritePropertyName("trainingProvider");
               var trainingProviderHtmlString =
                  string.Format("<a href='{0}'><img width='75' src='{1}' alt='{2}' /></a>",
                     urlHelper.RouteUrl(AppConstants.RouteNames.TrainingProvider, entry.TrainingProvider.TrainingProviderRouteValuesObject),
                     entry.TrainingProvider.LogoUrl,
                     entry.TrainingProvider.Name);
               writer.WriteValue(trainingProviderHtmlString);

               writer.WritePropertyName("category");
               var categoryHtmlString =
                  string.Format("<a href='{0}'>{1}</a>",
                     urlHelper.RouteUrl(AppConstants.RouteNames.TrainingProviderCategory, entry.Category.CategoryRouteValuesObject),
                     entry.Category.Title);
               writer.WriteValue(categoryHtmlString);

               writer.WritePropertyName("courseTitle");
               var courseTitleHtmlString =
                  string.Format("<span>{0}{1}<a href='{2}'>{3}</a>{4}</span>",
                     HtmlHelperExtensions.GetCourseSubscriptionMarker(entry.Course.LearningState).ToString(),
                     "&nbsp;",
                     urlHelper.RouteUrl(AppConstants.RouteNames.Course, entry.CourseRouteValueObject),
                     entry.Course.Title,
                     entry.Course.HasClosedCaptions ? "&nbsp;<i class='text-info fa fa-cc'></i>" : null);
               writer.WriteValue(courseTitleHtmlString);

               writer.WritePropertyName("authors");
               var authorsHtmlString = HtmlHelperExtensions.GetCourseAuthors(entry.TrainingProvider.Name,
                  entry.Course.Authors);
               writer.WriteValue(authorsHtmlString.ToString());

               writer.WritePropertyName("level");
               writer.WriteValue(entry.Course.Level.ToString());

               writer.WritePropertyName("duration");
               var durationHtmlString = string.Format("<span>{0}<small>h</small>&nbsp;{1}<small>m</small></span>",
                  entry.Course.Duration.Hours, entry.Course.Duration.Minutes);
               writer.WriteValue(durationHtmlString);

               writer.WritePropertyName("releaseDate");
               var releaseDateString = entry.Course.ReleaseDate.ToString("yyyy-MM-dd");
               writer.WriteValue(releaseDateString);

               writer.WritePropertyName("rating");
               var ratingHtmlString = HtmlHelperExtensions.GetCourseRating(entry.Course.Rating);
               writer.WriteValue(ratingHtmlString.ToString());

               writer.WriteEndObject();
            }
            writer.WriteEndArray();

            writer.WriteEndObject();

            writer.Flush();
         }
 public override void WriteJson( JsonWriter writer, object value, JsonSerializer serializer )
 {
     writer.WriteValue( Enum.GetName( value.GetType(), value ) );
     writer.Flush();
 }
Пример #15
0
 public void Serialise(ServiceEventMessage message)
 {
     _Serialiser.Serialize(_JsonWriter, message);
     _JsonWriter.Flush();
 }
Пример #16
0
        public void OnFileRequested(HttpRequest request, IDirectory directory)
        {
            request.Response.ResponseContent = new MemoryStream();
            StreamWriter writer = new StreamWriter(request.Response.ResponseContent);
            try
            {
                StreamReader reader = new StreamReader(request.PostData);
                string post = reader.ReadToEnd();
                reader.Dispose();
                // Decode the POST data.
                Dictionary<string,string> POST = deviMobile.PostDecode(post);
                Guid session = new Guid(POST["sid"]);
                Events eventqueue;
                User user;
                GridClient client;
                // Load in the session data.
                lock (users)
                {
                    user = users[session];
                    eventqueue = user.Events;
                    client = user.Client;
                    user.LastRequest = DateTime.Now;
                }
                bool sent = false;
                double heading = user.Rotation;
                // Check once per second, timing out after 15 seconds.
                for (int i = 0; i < 5; ++i)
                {
                    // Ugly hack - we're riding on the back of the event poll to rotate our camera.
                    if(user.Rotation != -4)
                    {
                        // If we've reached π, having started at -π, we're done. Quit rotating, because it
                        // appears to annoy people and/or make them dizzy.
                        heading += 0.5d;
                        if (heading > Math.PI)
                        {
                            // We use -4 because -4 < -π, so will never occur during normal operation.
                            user.Rotation = -4;
                            heading = Math.PI;
                            // Reset the draw distance to attempt to reduce traffic. Also limits the
                            // nearby list to people within chat range.
                            user.Client.Self.Movement.Camera.Far = 20.0f;
                            user.Client.Self.Movement.SendUpdate();
                        }
                        else
                        {
                            user.Rotation = heading;
                        }
                        client.Self.Movement.UpdateFromHeading(heading, false);
                    }

                    if (eventqueue.GetEventCount() > 0)
                    {
                        writer.WriteLine(eventqueue.GetPendingJson(client));
                        sent = true;
                        break;
                    }
                    else
                    {
                        System.Threading.Thread.Sleep(1000);
                    }
                }
                // If nothing of interest ever came up, we just send the standard footer.
                if (!sent)
                {
                    JsonWriter w = new JsonWriter(writer);
                    w.WriteStartArray();
                    (new JsonSerializer()).Serialize(w, eventqueue.GetFooter(client));
                    w.WriteEndArray();
                    w.Flush();
                }
            }
            catch (Exception e)
            {
                request.Response.ContentType = "text/plain";
                writer.WriteLine(e.Message);
            }
            writer.Flush();
        }
Пример #17
0
 /// <summary>
 /// Método de escrito de objetos JSon
 /// </summary>
 /// <param name="writer"></param>
 /// <param name="value"></param>
 /// <param name="serializer"></param>
 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     writer.WriteValue(((DateTime)value).ToString("dd/MM/yyyy"));
     writer.Flush();
 }