public void Save(IPersistable build) { using (var fileStream = new FileStream(Source, FileMode.Open, FileAccess.ReadWrite)) { if (fileStream.Length > 0) //remove ] if we have content in file { fileStream.Seek(-1, SeekOrigin.End); } using (var sw = new StreamWriter(fileStream)) //add item to array { using (JsonWriter writer = new JsonTextWriter(sw)) { if (sw.BaseStream.Position == 0) //begin array if this is first item { writer.WriteRawValue("["); } else //we are adding item to existing array { writer.WriteRawValue(","); } serializer.Serialize(writer, build.Data()); writer.WriteRawValue("]"); } } } }
public void Save(IPersistable build) { if (build as ISolutionBuild != null) // Only solution builds { var buildData = build.Data(); Type t = buildData.GetType(); PropertyInfo p = t.GetProperty("Time"); long solutionBuildTimeMs = (long)(p.GetValue(buildData, null)); if (solutionBuildTimeMs > 100) { using (StringWriter sw = new StringWriter()) { using (JsonWriter writer = new JsonTextWriter(sw)) { serializer.Serialize(writer, buildData); } PtrackClient.SendJsonDocument("visualStudioReport", sw.ToString()); } } } //using (var fileStream = new FileStream(Source, FileMode.Open, FileAccess.ReadWrite)) //{ // if (fileStream.Length > 0) //remove ] if we have content in file // { // fileStream.Seek(-1, SeekOrigin.End); // } // using (var sw = new StreamWriter(fileStream)) //add item to array // { // using (JsonWriter writer = new JsonTextWriter(sw)) // { // if (sw.BaseStream.Position == 0) //begin array if this is first item // { // writer.WriteRawValue("["); // } // else //we are adding item to existing array // { // writer.WriteRawValue(","); // } // serializer.Serialize(writer, build.Data()); // writer.WriteRawValue("]"); // } // } //} }