public void CreateRawJson(string filePath) { var replay = Replay.Deserialize(filePath); var jsonSerializer = new Serializers.JsonSerializer(); Console.WriteLine(jsonSerializer.SerializeRaw(replay)); }
public void CreateRawJson(string filePath) { var replay = Replay.Deserialize(filePath); var jsonSerializer = new Serializers.JsonSerializer(); jsonSerializer.SerializeRaw(replay); }
static async Task Main(string[] args) { var jsonSerializer = new Serializers.JsonSerializer(new JsonSerializerSettings()); var fileStorageProvider = new LocalStorageProvider(@".\"); var memoryStorageProvider = new MemoryStorageProvider(); var rawFileStorage = new RawStorageClient(fileStorageProvider); var rawMemoryStorage = new RawStorageClient(memoryStorageProvider); var fileStorage = new ObjectStorageClient(rawFileStorage, jsonSerializer); var memoryStorage = new ObjectStorageClient(rawMemoryStorage, jsonSerializer); Console.WriteLine("object memory storage"); await TryStorage("test", memoryStorage); Console.WriteLine("object file storage"); await TryStorage("test", fileStorage); Console.WriteLine("raw file storage"); await TryRawStorage("test", rawFileStorage); Console.WriteLine("raw memory storage"); await TryRawStorage("test", rawMemoryStorage); Console.WriteLine("Concurrent writes and reads"); var tasks = Enumerable.Repeat(Enumerable.Range(1, 3).ToList(), 3) .SelectMany(x => x) .Select(x => TryRawStorage(x.ToString(), rawMemoryStorage)); await Task.WhenAll(tasks); }
public void CreateJson(string filePath) { string log; var replay = Replay.Deserialize(filePath, out log); var jsonSerializer = new Serializers.JsonSerializer(); Console.WriteLine(jsonSerializer.Serialize(replay)); }
public void OpenSerializedJson(string filePath) { var jsonFilePath = Path.Combine(Path.GetTempPath(), "replay.json"); // Prevent accidentially opening hundreds of replays if (File.Exists(jsonFilePath)) { var lastWriteTime = File.GetLastWriteTime(jsonFilePath); Assert.IsTrue(lastWriteTime < (DateTime.Now - TimeSpan.FromSeconds(10))); } var replay = Replay.Deserialize(filePath); var jsonSerializer = new Serializers.JsonSerializer(); File.WriteAllText(jsonFilePath, jsonSerializer.Serialize(replay, false, true)); System.Diagnostics.Process.Start(jsonFilePath); }
/// <summary> /// Adds an object as serialized json string. /// </summary> /// <remarks>Throws exception if the given object is null, or if the /// serialized json string is null or empty.</remarks> /// <param name="obj">The object that will be serialized and added as json string content.</param> /// <param name="name">A name needed when content is a MultipartFormDataContent already.</param> /// <param name="fileName">A file name needed when content is a MultipartFormDataContent already.</param> /// <returns>this.</returns> public static T AddJson <T>(this T request, object obj, bool clrPropertyNameToLower = false, string name = "", string fileName = "") where T : RestRequest { obj.ThrowIfNull("BaseRestRequest"); var serializer = new Serializers.JsonSerializer(); var jsonContent = serializer.Serialize(obj, clrPropertyNameToLower); jsonContent.ThrowIfNullOrEmpty("BaseRestRequest", "jsonStr"); // .net default encoding is UTF-8 if (!String.IsNullOrEmpty(jsonContent)) { #if UNIVERSAL request.AddContent(new HttpStringContent(jsonContent, UnicodeEncoding.Utf8, serializer.ContentType), name, fileName); #else request.AddContent(new StringContent(jsonContent, Encoding.UTF8, serializer.ContentType), name, fileName); #endif } return(request); }
/// <summary> /// Creates a function thats does an action on a RestRequest, /// depending on the given ParameterAttributeInfo. /// </summary> /// <param name="paramInfo">The parameter attribute info.</param> /// <returns>The function.</returns> private static Func <object, RestRequest, RestRequest> createParamAttrFunction(ParameterAttributeInfo paramInfo) { string parameterName = paramInfo.Parameter.Name; Func <object, RestRequest, RestRequest> result = null; foreach (var attr in paramInfo.Attributes) { // This is a QParam, UrlParam or Param attribute. if (attr.AttributeType == typeof(BaseParamAttribute)) { // Check if the BaseParamAttribute ctor first argument (name) was given // if so than use this as parameter name. string tmp = (string)attr.ConstructorArguments.First().Value; if (!String.IsNullOrEmpty(tmp)) { parameterName = tmp; } if (attr.AttributeType == typeof(QParamAttribute)) { result = (object obj, RestRequest req) => req.QParam(parameterName, obj); } else if (attr.AttributeType == typeof(UrlParamAttribute)) { result = (object obj, RestRequest req) => req.UrlParam(parameterName, obj); } else if (attr.AttributeType == typeof(ParamAttribute)) { ParameterType paramType = (ParameterType)attr.ConstructorArguments.Skip(1).First().Value; result = (object obj, RestRequest req) => req.Param(parameterName, obj, paramType); } } else if (attr.AttributeType == typeof(ContentTypeAttribute)) { ContentType contentType = (ContentType)attr.ConstructorArguments.First().Value; string contentTypeStr = ""; Serializers.ISerializer serializer = null; if (contentType == ContentType.Json) { contentTypeStr = "text/json"; serializer = new Serializers.JsonSerializer(); } else if (contentType == ContentType.Xml) { contentTypeStr = "text/xml"; serializer = new Serializers.XmlSerializer(); } // TODO: Handle ContentType.OctetStream // TODO: Handle ContentType.Text // TODO: Handle generic ContentType? MimeDetective? // TODO: AddBinary() ?! result = (object obj, RestRequest req) => req.AddString(serializer.Serialize(obj), System.Text.Encoding.UTF8, contentTypeStr); } else if (attr.AttributeType == typeof(HeaderAttribute)) { // Get the header name this parameter is supposed to set string headerName = (string)attr.ConstructorArguments.First().Value; // create the function that is setting a header on a RestRequest result = (object obj, RestRequest req) => req.Header(headerName, (string)obj); } } return(result); }
private static int Process(Options o) { var serializer = new Serializers.JsonSerializer(); var inputFiles = new List <string>(); if (o.DirectoryMode) { if (!Directory.Exists(o.Input)) { System.Console.Error.WriteLine("Directory does not exist"); return(1); } inputFiles.AddRange(Directory.EnumerateFiles(o.Input, "*.replay")); if (!inputFiles.Any()) { System.Console.Error.WriteLine("No replay files found in the specified directory"); return(1); } inputFiles = inputFiles.Select(f => Path.Combine(o.Input, f)).ToList(); } else { inputFiles.Add(o.Input); } foreach (var file in inputFiles) { if (!File.Exists(file)) { System.Console.Error.WriteLine(string.Format("Specified replay file {0} does not exist", file)); return(1); } if (o.FileOutput) { System.Console.Write("Processing replay " + file + "..."); } var replay = Replay.Deserialize(file); string json; if (o.Raw) { json = serializer.SerializeRaw(replay); } else { json = serializer.Serialize(replay); } if (o.FileOutput) { var filename = Path.GetFileNameWithoutExtension(file) + ".json"; File.WriteAllText(filename, json); System.Console.WriteLine("Complete!"); } else { System.Console.Write(json); } } return(0); }
private static int Process(Options o) { var serializer = new Serializers.JsonSerializer(); var inputFiles = new List<string>(); if (o.DirectoryMode) { if ( !Directory.Exists(o.Input) ) { System.Console.Error.WriteLine("Directory does not exist"); return 1; } inputFiles.AddRange(Directory.EnumerateFiles(o.Input, "*.replay")); if (!inputFiles.Any()) { System.Console.Error.WriteLine("No replay files found in the specified directory"); return 1; } inputFiles = inputFiles.Select(f => Path.Combine(o.Input, f)).ToList(); } else { inputFiles.Add(o.Input); } foreach (var file in inputFiles) { if (!File.Exists(file)) { System.Console.Error.WriteLine(string.Format("Specified replay file {0} does not exist", file)); return 1; } if (o.FileOutput) { System.Console.Write("Processing replay " + file + "..."); } var replay = Replay.Deserialize(file); string json; if (o.Raw) { json = serializer.SerializeRaw(replay); } else { json = serializer.Serialize(replay); } if (o.FileOutput) { var filename = Path.GetFileNameWithoutExtension(file) + ".json"; File.WriteAllText(filename, json); System.Console.WriteLine("Complete!"); } else { System.Console.Write(json); } } return 0; }