WriteArrayEnd() public method

public WriteArrayEnd ( ) : void
return void
Exemplo n.º 1
0
    void WriteResponseForPostJson(HttpRequest request, HttpResponse response)
    {
        // read request JSON
        uint requestedCount = ReadCount(request.Body);

        // write response JSON
        var json = new JsonWriter<ResponseFormatter>(response.Body, prettyPrint: false);
        json.WriteObjectStart();
        json.WriteArrayStart();
        for (int i = 0; i < requestedCount; i++) {
            json.WriteString("hello!"); 
        }
        json.WriteArrayEnd();
        json.WriteObjectEnd();

        // write headers
        var headers = response.Headers;
        headers.AppendHttpStatusLine(HttpVersion.V1_1, 200, new Utf8String("OK"));
        headers.Append("Content-Length : ");
        headers.Append(response.Body.CommitedBytes);
        headers.AppendHttpNewLine();
        headers.Append("Content-Type : text/plain; charset=UTF-8");
        headers.AppendHttpNewLine();
        headers.Append("Server : .NET Core Sample Server");
        headers.AppendHttpNewLine();
        headers.Append("Date : ");
        headers.Append(DateTime.UtcNow, 'R');
        headers.AppendHttpNewLine();
        headers.AppendHttpNewLine();
    }
		/// <summary>
		/// Write an array of target descriptors
		/// </summary>
		/// <param name="Writer">The Json writer to output to</param>
		/// <param name="Name">Name of the array</param>
		/// <param name="Targets">Array of targets</param>
		public static void WriteArray(JsonWriter Writer, string Name, LocalizationTargetDescriptor[] Targets)
		{
			if (Targets.Length > 0)
			{
				Writer.WriteArrayStart(Name);
				foreach (LocalizationTargetDescriptor Target in Targets)
				{
					Target.Write(Writer);
				}
				Writer.WriteArrayEnd();
			}
		}
Exemplo n.º 3
0
    // Writer
    public static void JsonSerializer(JsonWriter writer, object instance)
    {
        var scoreEntry = (RankEntry)instance;

        writer.WriteArrayStart();
        writer.WriteNumber(scoreEntry.rankIndex);
        writer.WriteString(scoreEntry.accountId);
        writer.WriteString(scoreEntry.name);
        writer.WriteString(scoreEntry.country);
        writer.WriteNumber(scoreEntry.bestRanking);
        writer.WriteNumber(scoreEntry.totalDamage);
        writer.WriteArrayEnd();
    }
		/// <summary>
		/// Reads a list of build steps from a Json project or plugin descriptor
		/// </summary>
		/// <param name="RawObject">The json descriptor object</param>
		/// <param name="FieldName">Name of the field to read</param>
		/// <param name="OutBuildSteps">Output variable to store the sorted dictionary that was read</param>
		/// <returns>True if the field was read (and OutBuildSteps is set), false otherwise.</returns>
		public void Write(JsonWriter Writer, string FieldName)
		{
			Writer.WriteObjectStart(FieldName);
			foreach(KeyValuePair<UnrealTargetPlatform, string[]> Pair in HostPlatformToCommands)
			{
				Writer.WriteArrayStart(Pair.Key.ToString());
				foreach(string Line in Pair.Value)
				{
					Writer.WriteValue(Line);
				}
				Writer.WriteArrayEnd();
			}
			Writer.WriteObjectEnd();
		}
Exemplo n.º 5
0
    public static void SaveJson()
    {
        string filePath = Application.dataPath + @"/StringAssets/file/pos.txt";
        FileInfo fileInfo = new FileInfo(filePath);
        if (!File.Exists(filePath))
        {
            File.Delete(filePath);
        }

        StreamWriter sw = fileInfo.CreateText();
        StringBuilder sb = new StringBuilder();
        JsonWriter writer = new JsonWriter(sb);

        //从场景中开始一个个的遍历
        foreach (EditorBuildSettingsScene s in EditorBuildSettings.scenes)
        {
            if (s.enabled == true)
            {
                string name = s.path;
                EditorApplication.OpenScene(name);
                GameObject parent = GameObject.Find("PosObj");
                if (parent)
                {
                    writer.WriteArrayStart(); //开始写数据
                    for (int i = 0; i < parent.transform.childCount; i++)
                    {
                        Transform obj = parent.transform.GetChild(i);
                        writer.WriteObjectStart();
                        writer.WritePropertyName(obj.name);
                        writer.Write(obj.position.x.ToString() + "," + obj.position.y.ToString() + "," +
                                     obj.position.z.ToString());
                        writer.WriteObjectEnd();
                    }
                    writer.WriteArrayEnd();
                }
            }
        }

        sw.WriteLine(sb.ToString());
        sw.Close();
        sw.Dispose(); //关闭文件流
        AssetDatabase.Refresh();  //刷新
    }
Exemplo n.º 6
0
 static void Write(JsonWriter json)
 {
     json.WriteObjectStart();
     json.WriteAttribute("age", 30);
     json.WriteAttribute("first", "John");
     json.WriteAttribute("last", "Smith");
     json.WriteMember("phoneNumbers");
     json.WriteArrayStart();
     json.WriteString("425-000-1212");
     json.WriteString("425-000-1213");
     json.WriteArrayEnd();
     json.WriteMember("address");
     json.WriteObjectStart();
     json.WriteAttribute("street", "1 Microsoft Way");
     json.WriteAttribute("city", "Redmond");
     json.WriteAttribute("zip", 98052);
     json.WriteObjectEnd();
     json.WriteObjectEnd();
 }
Exemplo n.º 7
0
    // This method is a bit of a mess. We need to fix many Http and Json APIs
    void WriteResponseForPostJson(BufferFormatter formatter, HttpRequestLine requestLine, ReadOnlySpan<byte> body)
    {
        Console.WriteLine(new Utf8String(body));

        uint requestedCount = ReadCountUsingReader(body).GetValueOrDefault(1);
        //uint requestedCount = ReadCountUsingNonAllocatingDom(body).GetValueOrDefault(1);

        // TODO: this needs to be written directly to the buffer after content length reservation is implemented.
        var buffer = ArrayPool<byte>.Shared.Rent(2048);
        var spanFormatter = new SpanFormatter(buffer.Slice(), FormattingData.InvariantUtf8);
        var json = new JsonWriter<SpanFormatter>(spanFormatter,  prettyPrint: true);
        json.WriteObjectStart();
        json.WriteArrayStart();
        for (int i = 0; i < requestedCount; i++) {
            json.WriteString(DateTime.UtcNow.ToString()); // TODO: this needs to not allocate.
        }
        json.WriteArrayEnd(); ;
        json.WriteObjectEnd();
        var responseBodyText = new Utf8String(buffer, 0, spanFormatter.CommitedByteCount);

        formatter.AppendHttpStatusLine(HttpVersion.V1_1, 200, new Utf8String("OK"));
        formatter.Append(new Utf8String("Content-Length : "));
        formatter.Append(responseBodyText.Length);
        formatter.AppendHttpNewLine();
        formatter.Append("Content-Type : text/plain; charset=UTF-8");
        formatter.AppendHttpNewLine();
        formatter.Append("Server : .NET Core Sample Serve");
        formatter.AppendHttpNewLine();
        formatter.Append(new Utf8String("Date : "));
        formatter.Append(DateTime.UtcNow.ToString("R"));
        formatter.AppendHttpNewLine();
        formatter.AppendHttpNewLine();
        formatter.Append(responseBodyText);

        ArrayPool<byte>.Shared.Return(buffer);
    }
        public IRequest Marshall(CreateJobRequest createJobRequest)
        {
            IRequest request = new DefaultRequest(createJobRequest, "AmazonElasticTranscoder");
            string   target  = "EtsCustomerService.CreateJob";

            request.Headers["X-Amz-Target"] = target;

            request.Headers["Content-Type"] = "application/x-amz-json-1.0";
            request.HttpMethod = "POST";

            string uriResourcePath = "2012-09-25/jobs";

            if (uriResourcePath.Contains("?"))
            {
                int    queryPosition = uriResourcePath.IndexOf("?", StringComparison.OrdinalIgnoreCase);
                string queryString   = uriResourcePath.Substring(queryPosition + 1);
                uriResourcePath = uriResourcePath.Substring(0, queryPosition);

                foreach (string s in queryString.Split('&', ';'))
                {
                    string[] nameValuePair = s.Split('=');
                    if (nameValuePair.Length == 2 && nameValuePair[1].Length > 0)
                    {
                        request.Parameters.Add(nameValuePair[0], nameValuePair[1]);
                    }
                    else
                    {
                        request.Parameters.Add(nameValuePair[0], null);
                    }
                }
            }

            request.ResourcePath = uriResourcePath;


            using (StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture))
            {
                JsonWriter writer = new JsonWriter(stringWriter);
                writer.WriteObjectStart();

                if (createJobRequest != null && createJobRequest.IsSetPipelineId())
                {
                    writer.WritePropertyName("PipelineId");
                    writer.Write(createJobRequest.PipelineId);
                }

                if (createJobRequest != null)
                {
                    JobInput input = createJobRequest.Input;
                    if (input != null)
                    {
                        writer.WritePropertyName("Input");
                        writer.WriteObjectStart();
                        if (input != null && input.IsSetKey())
                        {
                            writer.WritePropertyName("Key");
                            writer.Write(input.Key);
                        }
                        if (input != null && input.IsSetFrameRate())
                        {
                            writer.WritePropertyName("FrameRate");
                            writer.Write(input.FrameRate);
                        }
                        if (input != null && input.IsSetResolution())
                        {
                            writer.WritePropertyName("Resolution");
                            writer.Write(input.Resolution);
                        }
                        if (input != null && input.IsSetAspectRatio())
                        {
                            writer.WritePropertyName("AspectRatio");
                            writer.Write(input.AspectRatio);
                        }
                        if (input != null && input.IsSetInterlaced())
                        {
                            writer.WritePropertyName("Interlaced");
                            writer.Write(input.Interlaced);
                        }
                        if (input != null && input.IsSetContainer())
                        {
                            writer.WritePropertyName("Container");
                            writer.Write(input.Container);
                        }
                        writer.WriteObjectEnd();
                    }
                }

                if (createJobRequest != null)
                {
                    CreateJobOutput output = createJobRequest.Output;
                    if (output != null)
                    {
                        writer.WritePropertyName("Output");
                        writer.WriteObjectStart();
                        if (output != null && output.IsSetKey())
                        {
                            writer.WritePropertyName("Key");
                            writer.Write(output.Key);
                        }
                        if (output != null && output.IsSetThumbnailPattern())
                        {
                            writer.WritePropertyName("ThumbnailPattern");
                            writer.Write(output.ThumbnailPattern);
                        }
                        if (output != null && output.IsSetRotate())
                        {
                            writer.WritePropertyName("Rotate");
                            writer.Write(output.Rotate);
                        }
                        if (output != null && output.IsSetPresetId())
                        {
                            writer.WritePropertyName("PresetId");
                            writer.Write(output.PresetId);
                        }
                        if (output != null && output.IsSetSegmentDuration())
                        {
                            writer.WritePropertyName("SegmentDuration");
                            writer.Write(output.SegmentDuration);
                        }

                        if (output != null && output.Watermarks != null && output.Watermarks.Count > 0)
                        {
                            List <JobWatermark> watermarksList = output.Watermarks;
                            writer.WritePropertyName("Watermarks");
                            writer.WriteArrayStart();

                            foreach (JobWatermark watermarksListValue in watermarksList)
                            {
                                writer.WriteObjectStart();
                                if (watermarksListValue != null && watermarksListValue.IsSetPresetWatermarkId())
                                {
                                    writer.WritePropertyName("PresetWatermarkId");
                                    writer.Write(watermarksListValue.PresetWatermarkId);
                                }
                                if (watermarksListValue != null && watermarksListValue.IsSetInputKey())
                                {
                                    writer.WritePropertyName("InputKey");
                                    writer.Write(watermarksListValue.InputKey);
                                }
                                writer.WriteObjectEnd();
                            }
                            writer.WriteArrayEnd();
                        }

                        if (output != null)
                        {
                            JobAlbumArt albumArt = output.AlbumArt;
                            if (albumArt != null)
                            {
                                writer.WritePropertyName("AlbumArt");
                                writer.WriteObjectStart();
                                if (albumArt != null && albumArt.IsSetMergePolicy())
                                {
                                    writer.WritePropertyName("MergePolicy");
                                    writer.Write(albumArt.MergePolicy);
                                }

                                if (albumArt != null && albumArt.Artwork != null && albumArt.Artwork.Count > 0)
                                {
                                    List <Artwork> artworkList = albumArt.Artwork;
                                    writer.WritePropertyName("Artwork");
                                    writer.WriteArrayStart();

                                    foreach (Artwork artworkListValue in artworkList)
                                    {
                                        writer.WriteObjectStart();
                                        if (artworkListValue != null && artworkListValue.IsSetInputKey())
                                        {
                                            writer.WritePropertyName("InputKey");
                                            writer.Write(artworkListValue.InputKey);
                                        }
                                        if (artworkListValue != null && artworkListValue.IsSetMaxWidth())
                                        {
                                            writer.WritePropertyName("MaxWidth");
                                            writer.Write(artworkListValue.MaxWidth);
                                        }
                                        if (artworkListValue != null && artworkListValue.IsSetMaxHeight())
                                        {
                                            writer.WritePropertyName("MaxHeight");
                                            writer.Write(artworkListValue.MaxHeight);
                                        }
                                        if (artworkListValue != null && artworkListValue.IsSetSizingPolicy())
                                        {
                                            writer.WritePropertyName("SizingPolicy");
                                            writer.Write(artworkListValue.SizingPolicy);
                                        }
                                        if (artworkListValue != null && artworkListValue.IsSetPaddingPolicy())
                                        {
                                            writer.WritePropertyName("PaddingPolicy");
                                            writer.Write(artworkListValue.PaddingPolicy);
                                        }
                                        if (artworkListValue != null && artworkListValue.IsSetAlbumArtFormat())
                                        {
                                            writer.WritePropertyName("AlbumArtFormat");
                                            writer.Write(artworkListValue.AlbumArtFormat);
                                        }
                                        writer.WriteObjectEnd();
                                    }
                                    writer.WriteArrayEnd();
                                }
                                writer.WriteObjectEnd();
                            }
                        }

                        if (output != null && output.Composition != null && output.Composition.Count > 0)
                        {
                            List <Clip> compositionList = output.Composition;
                            writer.WritePropertyName("Composition");
                            writer.WriteArrayStart();

                            foreach (Clip compositionListValue in compositionList)
                            {
                                writer.WriteObjectStart();

                                if (compositionListValue != null)
                                {
                                    TimeSpan timeSpan = compositionListValue.TimeSpan;
                                    if (timeSpan != null)
                                    {
                                        writer.WritePropertyName("TimeSpan");
                                        writer.WriteObjectStart();
                                        if (timeSpan != null && timeSpan.IsSetStartTime())
                                        {
                                            writer.WritePropertyName("StartTime");
                                            writer.Write(timeSpan.StartTime);
                                        }
                                        if (timeSpan != null && timeSpan.IsSetDuration())
                                        {
                                            writer.WritePropertyName("Duration");
                                            writer.Write(timeSpan.Duration);
                                        }
                                        writer.WriteObjectEnd();
                                    }
                                }
                                writer.WriteObjectEnd();
                            }
                            writer.WriteArrayEnd();
                        }
                        writer.WriteObjectEnd();
                    }
                }

                if (createJobRequest != null && createJobRequest.Outputs != null && createJobRequest.Outputs.Count > 0)
                {
                    List <CreateJobOutput> outputsList = createJobRequest.Outputs;
                    writer.WritePropertyName("Outputs");
                    writer.WriteArrayStart();

                    foreach (CreateJobOutput outputsListValue in outputsList)
                    {
                        writer.WriteObjectStart();
                        if (outputsListValue != null && outputsListValue.IsSetKey())
                        {
                            writer.WritePropertyName("Key");
                            writer.Write(outputsListValue.Key);
                        }
                        if (outputsListValue != null && outputsListValue.IsSetThumbnailPattern())
                        {
                            writer.WritePropertyName("ThumbnailPattern");
                            writer.Write(outputsListValue.ThumbnailPattern);
                        }
                        if (outputsListValue != null && outputsListValue.IsSetRotate())
                        {
                            writer.WritePropertyName("Rotate");
                            writer.Write(outputsListValue.Rotate);
                        }
                        if (outputsListValue != null && outputsListValue.IsSetPresetId())
                        {
                            writer.WritePropertyName("PresetId");
                            writer.Write(outputsListValue.PresetId);
                        }
                        if (outputsListValue != null && outputsListValue.IsSetSegmentDuration())
                        {
                            writer.WritePropertyName("SegmentDuration");
                            writer.Write(outputsListValue.SegmentDuration);
                        }

                        if (outputsListValue != null && outputsListValue.Watermarks != null && outputsListValue.Watermarks.Count > 0)
                        {
                            List <JobWatermark> watermarksList = outputsListValue.Watermarks;
                            writer.WritePropertyName("Watermarks");
                            writer.WriteArrayStart();

                            foreach (JobWatermark watermarksListValue in watermarksList)
                            {
                                writer.WriteObjectStart();
                                if (watermarksListValue != null && watermarksListValue.IsSetPresetWatermarkId())
                                {
                                    writer.WritePropertyName("PresetWatermarkId");
                                    writer.Write(watermarksListValue.PresetWatermarkId);
                                }
                                if (watermarksListValue != null && watermarksListValue.IsSetInputKey())
                                {
                                    writer.WritePropertyName("InputKey");
                                    writer.Write(watermarksListValue.InputKey);
                                }
                                writer.WriteObjectEnd();
                            }
                            writer.WriteArrayEnd();
                        }

                        if (outputsListValue != null)
                        {
                            JobAlbumArt albumArt = outputsListValue.AlbumArt;
                            if (albumArt != null)
                            {
                                writer.WritePropertyName("AlbumArt");
                                writer.WriteObjectStart();
                                if (albumArt != null && albumArt.IsSetMergePolicy())
                                {
                                    writer.WritePropertyName("MergePolicy");
                                    writer.Write(albumArt.MergePolicy);
                                }

                                if (albumArt != null && albumArt.Artwork != null && albumArt.Artwork.Count > 0)
                                {
                                    List <Artwork> artworkList = albumArt.Artwork;
                                    writer.WritePropertyName("Artwork");
                                    writer.WriteArrayStart();

                                    foreach (Artwork artworkListValue in artworkList)
                                    {
                                        writer.WriteObjectStart();
                                        if (artworkListValue != null && artworkListValue.IsSetInputKey())
                                        {
                                            writer.WritePropertyName("InputKey");
                                            writer.Write(artworkListValue.InputKey);
                                        }
                                        if (artworkListValue != null && artworkListValue.IsSetMaxWidth())
                                        {
                                            writer.WritePropertyName("MaxWidth");
                                            writer.Write(artworkListValue.MaxWidth);
                                        }
                                        if (artworkListValue != null && artworkListValue.IsSetMaxHeight())
                                        {
                                            writer.WritePropertyName("MaxHeight");
                                            writer.Write(artworkListValue.MaxHeight);
                                        }
                                        if (artworkListValue != null && artworkListValue.IsSetSizingPolicy())
                                        {
                                            writer.WritePropertyName("SizingPolicy");
                                            writer.Write(artworkListValue.SizingPolicy);
                                        }
                                        if (artworkListValue != null && artworkListValue.IsSetPaddingPolicy())
                                        {
                                            writer.WritePropertyName("PaddingPolicy");
                                            writer.Write(artworkListValue.PaddingPolicy);
                                        }
                                        if (artworkListValue != null && artworkListValue.IsSetAlbumArtFormat())
                                        {
                                            writer.WritePropertyName("AlbumArtFormat");
                                            writer.Write(artworkListValue.AlbumArtFormat);
                                        }
                                        writer.WriteObjectEnd();
                                    }
                                    writer.WriteArrayEnd();
                                }
                                writer.WriteObjectEnd();
                            }
                        }

                        if (outputsListValue != null && outputsListValue.Composition != null && outputsListValue.Composition.Count > 0)
                        {
                            List <Clip> compositionList = outputsListValue.Composition;
                            writer.WritePropertyName("Composition");
                            writer.WriteArrayStart();

                            foreach (Clip compositionListValue in compositionList)
                            {
                                writer.WriteObjectStart();

                                if (compositionListValue != null)
                                {
                                    TimeSpan timeSpan = compositionListValue.TimeSpan;
                                    if (timeSpan != null)
                                    {
                                        writer.WritePropertyName("TimeSpan");
                                        writer.WriteObjectStart();
                                        if (timeSpan != null && timeSpan.IsSetStartTime())
                                        {
                                            writer.WritePropertyName("StartTime");
                                            writer.Write(timeSpan.StartTime);
                                        }
                                        if (timeSpan != null && timeSpan.IsSetDuration())
                                        {
                                            writer.WritePropertyName("Duration");
                                            writer.Write(timeSpan.Duration);
                                        }
                                        writer.WriteObjectEnd();
                                    }
                                }
                                writer.WriteObjectEnd();
                            }
                            writer.WriteArrayEnd();
                        }
                        writer.WriteObjectEnd();
                    }
                    writer.WriteArrayEnd();
                }
                if (createJobRequest != null && createJobRequest.IsSetOutputKeyPrefix())
                {
                    writer.WritePropertyName("OutputKeyPrefix");
                    writer.Write(createJobRequest.OutputKeyPrefix);
                }

                if (createJobRequest != null && createJobRequest.Playlists != null && createJobRequest.Playlists.Count > 0)
                {
                    List <CreateJobPlaylist> playlistsList = createJobRequest.Playlists;
                    writer.WritePropertyName("Playlists");
                    writer.WriteArrayStart();

                    foreach (CreateJobPlaylist playlistsListValue in playlistsList)
                    {
                        writer.WriteObjectStart();
                        if (playlistsListValue != null && playlistsListValue.IsSetName())
                        {
                            writer.WritePropertyName("Name");
                            writer.Write(playlistsListValue.Name);
                        }
                        if (playlistsListValue != null && playlistsListValue.IsSetFormat())
                        {
                            writer.WritePropertyName("Format");
                            writer.Write(playlistsListValue.Format);
                        }

                        if (playlistsListValue != null && playlistsListValue.OutputKeys != null && playlistsListValue.OutputKeys.Count > 0)
                        {
                            List <string> outputKeysList = playlistsListValue.OutputKeys;
                            writer.WritePropertyName("OutputKeys");
                            writer.WriteArrayStart();

                            foreach (string outputKeysListValue in outputKeysList)
                            {
                                writer.Write(StringUtils.FromString(outputKeysListValue));
                            }

                            writer.WriteArrayEnd();
                        }
                        writer.WriteObjectEnd();
                    }
                    writer.WriteArrayEnd();
                }

                writer.WriteObjectEnd();

                string snippet = stringWriter.ToString();
                request.Content = System.Text.Encoding.UTF8.GetBytes(snippet);
            }


            return(request);
        }
Exemplo n.º 9
0
        public IRequest Marshall(BatchGetItemRequest batchGetItemRequest)
        {
            IRequest request = new DefaultRequest(batchGetItemRequest, "AmazonDynamoDBv2");
            string   target  = "DynamoDB_20120810.BatchGetItem";

            request.Headers["X-Amz-Target"] = target;

            request.Headers["Content-Type"] = "application/x-amz-json-1.0";


            string uriResourcePath = "";

            if (uriResourcePath.Contains("?"))
            {
                int    queryPosition = uriResourcePath.IndexOf("?", StringComparison.OrdinalIgnoreCase);
                string queryString   = uriResourcePath.Substring(queryPosition + 1);
                uriResourcePath = uriResourcePath.Substring(0, queryPosition);

                foreach (string s in queryString.Split('&', ';'))
                {
                    string[] nameValuePair = s.Split('=');
                    if (nameValuePair.Length == 2 && nameValuePair[1].Length > 0)
                    {
                        request.Parameters.Add(nameValuePair[0], nameValuePair[1]);
                    }
                    else
                    {
                        request.Parameters.Add(nameValuePair[0], null);
                    }
                }
            }

            request.ResourcePath = uriResourcePath;


            using (StringWriter stringWriter = new StringWriter(System.Globalization.CultureInfo.InvariantCulture))
            {
                JsonWriter writer = new JsonWriter(stringWriter);
                writer.WriteObjectStart();

                if (batchGetItemRequest != null)
                {
                    if (batchGetItemRequest.RequestItems != null && batchGetItemRequest.RequestItems.Count > 0)
                    {
                        writer.WritePropertyName("RequestItems");
                        writer.WriteObjectStart();
                        foreach (string batchGetItemRequestRequestItemsKey in batchGetItemRequest.RequestItems.Keys)
                        {
                            KeysAndAttributes requestItemsListValue;
                            bool requestItemsListValueHasValue = batchGetItemRequest.RequestItems.TryGetValue(batchGetItemRequestRequestItemsKey, out requestItemsListValue);
                            writer.WritePropertyName(batchGetItemRequestRequestItemsKey);

                            writer.WriteObjectStart();

                            if (requestItemsListValue != null && requestItemsListValue.Keys != null && requestItemsListValue.Keys.Count > 0)
                            {
                                List <Dictionary <string, AttributeValue> > keysList = requestItemsListValue.Keys;
                                writer.WritePropertyName("Keys");
                                writer.WriteArrayStart();

                                foreach (Dictionary <string, AttributeValue> keysListValue in keysList)
                                {
                                    writer.WriteObjectStart();
                                    foreach (KeyValuePair <string, AttributeValue> memberListValue in keysListValue)
                                    {
                                        if (memberListValue.Key != null)
                                        {
                                            writer.WritePropertyName(memberListValue.Key);

                                            writer.WriteObjectStart();
                                            if (memberListValue.Value != null && memberListValue.Value.IsSetS())
                                            {
                                                writer.WritePropertyName("S");
                                                writer.Write(memberListValue.Value.S);
                                            }
                                            if (memberListValue.Value != null && memberListValue.Value.IsSetN())
                                            {
                                                writer.WritePropertyName("N");
                                                writer.Write(memberListValue.Value.N);
                                            }
                                            if (memberListValue.Value != null && memberListValue.Value.IsSetB())
                                            {
                                                writer.WritePropertyName("B");
                                                writer.Write(StringUtils.FromMemoryStream(memberListValue.Value.B));
                                            }

                                            if (memberListValue.Value != null && memberListValue.Value.SS != null && memberListValue.Value.SS.Count > 0)
                                            {
                                                List <string> sSList = memberListValue.Value.SS;
                                                writer.WritePropertyName("SS");
                                                writer.WriteArrayStart();

                                                foreach (string sSListValue in sSList)
                                                {
                                                    writer.Write(StringUtils.FromString(sSListValue));
                                                }

                                                writer.WriteArrayEnd();
                                            }

                                            if (memberListValue.Value != null && memberListValue.Value.NS != null && memberListValue.Value.NS.Count > 0)
                                            {
                                                List <string> nSList = memberListValue.Value.NS;
                                                writer.WritePropertyName("NS");
                                                writer.WriteArrayStart();

                                                foreach (string nSListValue in nSList)
                                                {
                                                    writer.Write(StringUtils.FromString(nSListValue));
                                                }

                                                writer.WriteArrayEnd();
                                            }

                                            if (memberListValue.Value != null && memberListValue.Value.BS != null && memberListValue.Value.BS.Count > 0)
                                            {
                                                List <MemoryStream> bSList = memberListValue.Value.BS;
                                                writer.WritePropertyName("BS");
                                                writer.WriteArrayStart();

                                                foreach (MemoryStream bSListValue in bSList)
                                                {
                                                    writer.Write(StringUtils.FromMemoryStream(bSListValue));
                                                }

                                                writer.WriteArrayEnd();
                                            }
                                            writer.WriteObjectEnd();
                                        }
                                    }
                                    writer.WriteObjectEnd();
                                }
                                writer.WriteArrayEnd();
                            }

                            if (requestItemsListValue != null && requestItemsListValue.AttributesToGet != null && requestItemsListValue.AttributesToGet.Count > 0)
                            {
                                List <string> attributesToGetList = requestItemsListValue.AttributesToGet;
                                writer.WritePropertyName("AttributesToGet");
                                writer.WriteArrayStart();

                                foreach (string attributesToGetListValue in attributesToGetList)
                                {
                                    writer.Write(StringUtils.FromString(attributesToGetListValue));
                                }

                                writer.WriteArrayEnd();
                            }
                            if (requestItemsListValue != null && requestItemsListValue.IsSetConsistentRead())
                            {
                                writer.WritePropertyName("ConsistentRead");
                                writer.Write(requestItemsListValue.ConsistentRead);
                            }
                            writer.WriteObjectEnd();
                        }
                        writer.WriteObjectEnd();
                    }
                }
                if (batchGetItemRequest != null && batchGetItemRequest.IsSetReturnConsumedCapacity())
                {
                    writer.WritePropertyName("ReturnConsumedCapacity");
                    writer.Write(batchGetItemRequest.ReturnConsumedCapacity);
                }

                writer.WriteObjectEnd();

                string snippet = stringWriter.ToString();
                request.Content = System.Text.Encoding.UTF8.GetBytes(snippet);
            }


            return(request);
        }
        public IRequest Marshall(CreatePresetRequest createPresetRequest)
        {
            IRequest request = new DefaultRequest(createPresetRequest, "AmazonElasticTranscoder");
            string   target  = "EtsCustomerService.CreatePreset";

            request.Headers["X-Amz-Target"] = target;
            request.Headers["Content-Type"] = "application/x-amz-json-1.0";

            request.HttpMethod = "POST";

            string uriResourcePath = "2012-09-25/presets";

            if (uriResourcePath.Contains("?"))
            {
                string queryString = uriResourcePath.Substring(uriResourcePath.IndexOf("?") + 1);
                uriResourcePath = uriResourcePath.Substring(0, uriResourcePath.IndexOf("?"));

                foreach (string s in queryString.Split('&', ';'))
                {
                    string[] nameValuePair = s.Split('=');
                    if (nameValuePair.Length == 2 && nameValuePair[1].Length > 0)
                    {
                        request.Parameters.Add(nameValuePair[0], nameValuePair[1]);
                    }
                    else
                    {
                        request.Parameters.Add(nameValuePair[0], null);
                    }
                }
            }

            request.ResourcePath = uriResourcePath;


            using (StringWriter stringWriter = new StringWriter())
            {
                JsonWriter writer = new JsonWriter(stringWriter);
                writer.WriteObjectStart();

                if (createPresetRequest != null && createPresetRequest.IsSetName())
                {
                    writer.WritePropertyName("Name");
                    writer.Write(createPresetRequest.Name);
                }
                if (createPresetRequest != null && createPresetRequest.IsSetDescription())
                {
                    writer.WritePropertyName("Description");
                    writer.Write(createPresetRequest.Description);
                }
                if (createPresetRequest != null && createPresetRequest.IsSetContainer())
                {
                    writer.WritePropertyName("Container");
                    writer.Write(createPresetRequest.Container);
                }

                if (createPresetRequest != null)
                {
                    VideoParameters video = createPresetRequest.Video;
                    if (video != null)
                    {
                        writer.WritePropertyName("Video");
                        writer.WriteObjectStart();
                        if (video != null && video.IsSetCodec())
                        {
                            writer.WritePropertyName("Codec");
                            writer.Write(video.Codec);
                        }
                        if (video != null)
                        {
                            if (video.CodecOptions != null && video.CodecOptions.Count > 0)
                            {
                                writer.WritePropertyName("CodecOptions");
                                writer.WriteObjectStart();
                                foreach (string videoCodecOptionsKey in video.CodecOptions.Keys)
                                {
                                    string codecOptionsListValue;
                                    bool   codecOptionsListValueHasValue = video.CodecOptions.TryGetValue(videoCodecOptionsKey, out codecOptionsListValue);
                                    writer.WritePropertyName(videoCodecOptionsKey);

                                    writer.Write(codecOptionsListValue);
                                }
                                writer.WriteObjectEnd();
                            }
                        }
                        if (video != null && video.IsSetKeyframesMaxDist())
                        {
                            writer.WritePropertyName("KeyframesMaxDist");
                            writer.Write(video.KeyframesMaxDist);
                        }
                        if (video != null && video.IsSetFixedGOP())
                        {
                            writer.WritePropertyName("FixedGOP");
                            writer.Write(video.FixedGOP);
                        }
                        if (video != null && video.IsSetBitRate())
                        {
                            writer.WritePropertyName("BitRate");
                            writer.Write(video.BitRate);
                        }
                        if (video != null && video.IsSetFrameRate())
                        {
                            writer.WritePropertyName("FrameRate");
                            writer.Write(video.FrameRate);
                        }
                        if (video != null && video.IsSetMaxFrameRate())
                        {
                            writer.WritePropertyName("MaxFrameRate");
                            writer.Write(video.MaxFrameRate);
                        }
                        if (video != null && video.IsSetResolution())
                        {
                            writer.WritePropertyName("Resolution");
                            writer.Write(video.Resolution);
                        }
                        if (video != null && video.IsSetAspectRatio())
                        {
                            writer.WritePropertyName("AspectRatio");
                            writer.Write(video.AspectRatio);
                        }
                        if (video != null && video.IsSetMaxWidth())
                        {
                            writer.WritePropertyName("MaxWidth");
                            writer.Write(video.MaxWidth);
                        }
                        if (video != null && video.IsSetMaxHeight())
                        {
                            writer.WritePropertyName("MaxHeight");
                            writer.Write(video.MaxHeight);
                        }
                        if (video != null && video.IsSetDisplayAspectRatio())
                        {
                            writer.WritePropertyName("DisplayAspectRatio");
                            writer.Write(video.DisplayAspectRatio);
                        }
                        if (video != null && video.IsSetSizingPolicy())
                        {
                            writer.WritePropertyName("SizingPolicy");
                            writer.Write(video.SizingPolicy);
                        }
                        if (video != null && video.IsSetPaddingPolicy())
                        {
                            writer.WritePropertyName("PaddingPolicy");
                            writer.Write(video.PaddingPolicy);
                        }

                        if (video != null && video.Watermarks != null && video.Watermarks.Count > 0)
                        {
                            List <PresetWatermark> watermarksList = video.Watermarks;
                            writer.WritePropertyName("Watermarks");
                            writer.WriteArrayStart();

                            foreach (PresetWatermark watermarksListValue in watermarksList)
                            {
                                writer.WriteObjectStart();
                                if (watermarksListValue != null && watermarksListValue.IsSetId())
                                {
                                    writer.WritePropertyName("Id");
                                    writer.Write(watermarksListValue.Id);
                                }
                                if (watermarksListValue != null && watermarksListValue.IsSetMaxWidth())
                                {
                                    writer.WritePropertyName("MaxWidth");
                                    writer.Write(watermarksListValue.MaxWidth);
                                }
                                if (watermarksListValue != null && watermarksListValue.IsSetMaxHeight())
                                {
                                    writer.WritePropertyName("MaxHeight");
                                    writer.Write(watermarksListValue.MaxHeight);
                                }
                                if (watermarksListValue != null && watermarksListValue.IsSetSizingPolicy())
                                {
                                    writer.WritePropertyName("SizingPolicy");
                                    writer.Write(watermarksListValue.SizingPolicy);
                                }
                                if (watermarksListValue != null && watermarksListValue.IsSetHorizontalAlign())
                                {
                                    writer.WritePropertyName("HorizontalAlign");
                                    writer.Write(watermarksListValue.HorizontalAlign);
                                }
                                if (watermarksListValue != null && watermarksListValue.IsSetHorizontalOffset())
                                {
                                    writer.WritePropertyName("HorizontalOffset");
                                    writer.Write(watermarksListValue.HorizontalOffset);
                                }
                                if (watermarksListValue != null && watermarksListValue.IsSetVerticalAlign())
                                {
                                    writer.WritePropertyName("VerticalAlign");
                                    writer.Write(watermarksListValue.VerticalAlign);
                                }
                                if (watermarksListValue != null && watermarksListValue.IsSetVerticalOffset())
                                {
                                    writer.WritePropertyName("VerticalOffset");
                                    writer.Write(watermarksListValue.VerticalOffset);
                                }
                                if (watermarksListValue != null && watermarksListValue.IsSetOpacity())
                                {
                                    writer.WritePropertyName("Opacity");
                                    writer.Write(watermarksListValue.Opacity);
                                }
                                if (watermarksListValue != null && watermarksListValue.IsSetTarget())
                                {
                                    writer.WritePropertyName("Target");
                                    writer.Write(watermarksListValue.Target);
                                }
                                writer.WriteObjectEnd();
                            }
                            writer.WriteArrayEnd();
                        }
                        writer.WriteObjectEnd();
                    }
                }

                if (createPresetRequest != null)
                {
                    AudioParameters audio = createPresetRequest.Audio;
                    if (audio != null)
                    {
                        writer.WritePropertyName("Audio");
                        writer.WriteObjectStart();
                        if (audio != null && audio.IsSetCodec())
                        {
                            writer.WritePropertyName("Codec");
                            writer.Write(audio.Codec);
                        }
                        if (audio != null && audio.IsSetSampleRate())
                        {
                            writer.WritePropertyName("SampleRate");
                            writer.Write(audio.SampleRate);
                        }
                        if (audio != null && audio.IsSetBitRate())
                        {
                            writer.WritePropertyName("BitRate");
                            writer.Write(audio.BitRate);
                        }
                        if (audio != null && audio.IsSetChannels())
                        {
                            writer.WritePropertyName("Channels");
                            writer.Write(audio.Channels);
                        }
                        writer.WriteObjectEnd();
                    }
                }

                if (createPresetRequest != null)
                {
                    Thumbnails thumbnails = createPresetRequest.Thumbnails;
                    if (thumbnails != null)
                    {
                        writer.WritePropertyName("Thumbnails");
                        writer.WriteObjectStart();
                        if (thumbnails != null && thumbnails.IsSetFormat())
                        {
                            writer.WritePropertyName("Format");
                            writer.Write(thumbnails.Format);
                        }
                        if (thumbnails != null && thumbnails.IsSetInterval())
                        {
                            writer.WritePropertyName("Interval");
                            writer.Write(thumbnails.Interval);
                        }
                        if (thumbnails != null && thumbnails.IsSetResolution())
                        {
                            writer.WritePropertyName("Resolution");
                            writer.Write(thumbnails.Resolution);
                        }
                        if (thumbnails != null && thumbnails.IsSetAspectRatio())
                        {
                            writer.WritePropertyName("AspectRatio");
                            writer.Write(thumbnails.AspectRatio);
                        }
                        if (thumbnails != null && thumbnails.IsSetMaxWidth())
                        {
                            writer.WritePropertyName("MaxWidth");
                            writer.Write(thumbnails.MaxWidth);
                        }
                        if (thumbnails != null && thumbnails.IsSetMaxHeight())
                        {
                            writer.WritePropertyName("MaxHeight");
                            writer.Write(thumbnails.MaxHeight);
                        }
                        if (thumbnails != null && thumbnails.IsSetSizingPolicy())
                        {
                            writer.WritePropertyName("SizingPolicy");
                            writer.Write(thumbnails.SizingPolicy);
                        }
                        if (thumbnails != null && thumbnails.IsSetPaddingPolicy())
                        {
                            writer.WritePropertyName("PaddingPolicy");
                            writer.Write(thumbnails.PaddingPolicy);
                        }
                        writer.WriteObjectEnd();
                    }
                }

                writer.WriteObjectEnd();

                string snippet = stringWriter.ToString();
                request.Content = System.Text.Encoding.UTF8.GetBytes(snippet);
            }


            return(request);
        }
        public IRequest Marshall(DescribeDeploymentsRequest describeDeploymentsRequest)
        {
            IRequest request = new DefaultRequest(describeDeploymentsRequest, "AmazonOpsWorks");
            string   target  = "OpsWorks_20130218.DescribeDeployments";

            request.Headers["X-Amz-Target"] = target;
            request.Headers["Content-Type"] = "application/x-amz-json-1.1";



            string uriResourcePath = "";

            if (uriResourcePath.Contains("?"))
            {
                string queryString = uriResourcePath.Substring(uriResourcePath.IndexOf("?") + 1);
                uriResourcePath = uriResourcePath.Substring(0, uriResourcePath.IndexOf("?"));

                foreach (string s in queryString.Split('&', ';'))
                {
                    string[] nameValuePair = s.Split('=');
                    if (nameValuePair.Length == 2 && nameValuePair[1].Length > 0)
                    {
                        request.Parameters.Add(nameValuePair[0], nameValuePair[1]);
                    }
                    else
                    {
                        request.Parameters.Add(nameValuePair[0], null);
                    }
                }
            }

            request.ResourcePath = uriResourcePath;


            using (StringWriter stringWriter = new StringWriter())
            {
                JsonWriter writer = new JsonWriter(stringWriter);
                writer.WriteObjectStart();

                if (describeDeploymentsRequest != null && describeDeploymentsRequest.IsSetStackId())
                {
                    writer.WritePropertyName("StackId");
                    writer.Write(describeDeploymentsRequest.StackId);
                }
                if (describeDeploymentsRequest != null && describeDeploymentsRequest.IsSetAppId())
                {
                    writer.WritePropertyName("AppId");
                    writer.Write(describeDeploymentsRequest.AppId);
                }

                if (describeDeploymentsRequest != null && describeDeploymentsRequest.DeploymentIds != null && describeDeploymentsRequest.DeploymentIds.Count > 0)
                {
                    List <string> deploymentIdsList = describeDeploymentsRequest.DeploymentIds;
                    writer.WritePropertyName("DeploymentIds");
                    writer.WriteArrayStart();

                    foreach (string deploymentIdsListValue in deploymentIdsList)
                    {
                        writer.Write(StringUtils.FromString(deploymentIdsListValue));
                    }

                    writer.WriteArrayEnd();
                }

                writer.WriteObjectEnd();

                string snippet = stringWriter.ToString();
                request.Content = System.Text.Encoding.UTF8.GetBytes(snippet);
            }


            return(request);
        }
Exemplo n.º 12
0
    /// <summary>
    /// Returns a <see cref="System.String"/> that represents the current <see cref="Recording"/> using JSON
    /// </summary>
    /// <returns>
    /// A <see cref="System.String"/> that represents the current <see cref="Recording"/>.
    /// </returns>
    public override string ToString()
    {
        StringBuilder jsonB  = new StringBuilder();
        JsonWriter    writer = new JsonWriter(jsonB);

        writer.WriteObjectStart();
        //{
        writer.WritePropertyName("frameRate");
        writer.Write(frameRate);

        writer.WritePropertyName("frames");
        writer.WriteArrayStart();
        //[
        foreach (RecordingFrame frame in frames)
        {
            writer.WriteObjectStart();
            //{
            writer.WritePropertyName("recordTime");
            writer.Write((double)frame.recordTime);

            writer.WritePropertyName("inputs");
            writer.WriteArrayStart();
            //[
            foreach (InputInfo input in frame.inputs)
            {
                writer.WriteObjectStart();
                //{
                writer.WritePropertyName("inputName");
                writer.Write(input.inputName);

                writer.WritePropertyName("isAxis");
                writer.Write(input.isAxis);

                writer.WritePropertyName("mouseButtonNum");
                writer.Write(input.mouseButtonNum);

                writer.WritePropertyName("buttonState");
                writer.Write(input.buttonState);

                writer.WritePropertyName("axisValue");
                writer.Write(input.axisValue);
                //}
                writer.WriteObjectEnd();
            }
            //]
            writer.WriteArrayEnd();

            writer.WritePropertyName("syncedProperties");
            writer.WriteArrayStart();
            //[
            foreach (FrameProperty prop in frame.syncedProperties)
            {
                writer.WriteObjectStart();
                //{
                writer.WritePropertyName("name");
                writer.Write(prop.name);

                writer.WritePropertyName("property");
                writer.Write(prop.property);
                //}
                writer.WriteObjectEnd();
            }
            //]
            writer.WriteArrayEnd();
            //}
            writer.WriteObjectEnd();
        }
        //]
        writer.WriteArrayEnd();
        //}
        writer.WriteObjectEnd();

        return(jsonB.ToString());
    }
Exemplo n.º 13
0
        public IRequest Marshall(ListStepsRequest listStepsRequest)
        {
            IRequest request = new DefaultRequest(listStepsRequest, "AmazonElasticMapReduce");
            string   target  = "ElasticMapReduce.ListSteps";

            request.Headers["X-Amz-Target"] = target;

            request.Headers["Content-Type"] = "application/x-amz-json-1.1";


            string uriResourcePath = "";

            if (uriResourcePath.Contains("?"))
            {
                int    queryPosition = uriResourcePath.IndexOf("?", StringComparison.OrdinalIgnoreCase);
                string queryString   = uriResourcePath.Substring(queryPosition + 1);
                uriResourcePath = uriResourcePath.Substring(0, queryPosition);

                foreach (string s in queryString.Split('&', ';'))
                {
                    string[] nameValuePair = s.Split('=');
                    if (nameValuePair.Length == 2 && nameValuePair[1].Length > 0)
                    {
                        request.Parameters.Add(nameValuePair[0], nameValuePair[1]);
                    }
                    else
                    {
                        request.Parameters.Add(nameValuePair[0], null);
                    }
                }
            }

            request.ResourcePath = uriResourcePath;


            using (StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture))
            {
                JsonWriter writer = new JsonWriter(stringWriter);
                writer.WriteObjectStart();

                if (listStepsRequest != null && listStepsRequest.IsSetClusterId())
                {
                    writer.WritePropertyName("ClusterId");
                    writer.Write(listStepsRequest.ClusterId);
                }

                if (listStepsRequest != null && listStepsRequest.StepStates != null && listStepsRequest.StepStates.Count > 0)
                {
                    List <string> stepStatesList = listStepsRequest.StepStates;
                    writer.WritePropertyName("StepStates");
                    writer.WriteArrayStart();

                    foreach (string stepStatesListValue in stepStatesList)
                    {
                        writer.Write(StringUtils.FromString(stepStatesListValue));
                    }

                    writer.WriteArrayEnd();
                }
                if (listStepsRequest != null && listStepsRequest.IsSetMarker())
                {
                    writer.WritePropertyName("Marker");
                    writer.Write(listStepsRequest.Marker);
                }

                writer.WriteObjectEnd();

                string snippet = stringWriter.ToString();
                request.Content = System.Text.Encoding.UTF8.GetBytes(snippet);
            }


            return(request);
        }
Exemplo n.º 14
0
 void WriteJsonToFile(string path,string fileName)
 {
     System.Text.StringBuilder strB = new System.Text.StringBuilder();
     JsonWriter jsWrite = new JsonWriter(strB);
     jsWrite.WriteObjectStart();
     jsWrite.WritePropertyName("Name");
     jsWrite.Write("taotao");
     jsWrite.WritePropertyName("Age");
     jsWrite.Write(25);
     jsWrite.WritePropertyName("MM");
     jsWrite.WriteArrayStart();
     jsWrite.WriteObjectStart();
     jsWrite.WritePropertyName("name");
     jsWrite.Write("xiaomei");
     jsWrite.WritePropertyName("age");
     jsWrite.Write("17");
     jsWrite.WriteObjectEnd();
     jsWrite.WriteObjectStart();
     jsWrite.WritePropertyName("name");
     jsWrite.Write("xiaoli");
     jsWrite.WritePropertyName("age");
     jsWrite.Write("18");
     jsWrite.WriteObjectEnd();
     jsWrite.WriteArrayEnd();
     jsWrite.WriteObjectEnd();
     Debug.Log(strB);
     //创建文件目录
     DirectoryInfo dir = new DirectoryInfo(path);
     if (dir.Exists)
     {
         Debug.Log("This file is already exists");
     }
     else
     {
         Directory.CreateDirectory(path);
         Debug.Log("CreateFile");
     #if UNITY_EDITOR
         AssetDatabase.Refresh();
     #endif
     }
     //把json数据写到txt里
     StreamWriter sw;
     if (File.Exists(fileName))
     {
         //如果文件存在,那么就向文件继续附加(为了下次写内容不会覆盖上次的内容)
         sw = File.AppendText(fileName);
         Debug.Log("appendText");
     }
     else
     {
         //如果文件不存在则创建文件
         sw = File.CreateText(fileName);
         Debug.Log("createText");
     }
     sw.WriteLine(strB);
     sw.Close();
     #if UNITY_EDITOR
     AssetDatabase.Refresh();
     #endif
 }
Exemplo n.º 15
0
	private static void writeObject(GameObject obj, ref JsonWriter cfg) {
		cfg.WriteObjectStart();
		cfg.WritePropertyName("name");
		cfg.Write(obj.name);
		cfg.WritePropertyName("Layer");
		cfg.Write(obj.layer);
		writeMatrix(ref cfg, obj.transform);

		if (obj.renderer) {
			Mesh mesh = obj.renderer.GetComponent<MeshFilter>().sharedMesh;
			if (obj.renderer.material.mainTexture != null) {
				cfg.WritePropertyName("MainTexture");
				cfg.Write(getFileName(AssetDatabase.GetAssetPath(obj.renderer.material.mainTexture.GetInstanceID())));
			}
			if (mesh) {
				cfg.WritePropertyName("Mesh");
				cfg.Write(mesh.name);
			}
			if (obj.renderer.lightmapIndex != -1) {
				cfg.WritePropertyName("lightmap");
				cfg.Write(LightmapSettings.lightmaps[obj.renderer.lightmapIndex].lightmapFar.name);
				cfg.WritePropertyName("tilingOffset");
				cfg.WriteArrayStart();
				cfg.Write(obj.renderer.lightmapTilingOffset.x);
				cfg.Write(obj.renderer.lightmapTilingOffset.y);
				cfg.Write(obj.renderer.lightmapTilingOffset.z);
				cfg.Write(obj.renderer.lightmapTilingOffset.w);
				cfg.WriteArrayEnd();
			}
		}

		cfg.WritePropertyName("children");
		cfg.WriteArrayStart();

		for (int i = 0; i < obj.transform.childCount; i++) {
			writeObject(obj.transform.GetChild(i).gameObject, ref cfg);
		}

		cfg.WriteArrayEnd();
		cfg.WriteObjectEnd();
	}
Exemplo n.º 16
0
        public IRequest Marshall(UpdateInstanceRequest updateInstanceRequest)
        {
            IRequest request = new DefaultRequest(updateInstanceRequest, "AmazonOpsWorks");
            string   target  = "OpsWorks_20130218.UpdateInstance";

            request.Headers["X-Amz-Target"] = target;
            request.Headers["Content-Type"] = "application/x-amz-json-1.1";



            string uriResourcePath = "";

            if (uriResourcePath.Contains("?"))
            {
                string queryString = uriResourcePath.Substring(uriResourcePath.IndexOf("?") + 1);
                uriResourcePath = uriResourcePath.Substring(0, uriResourcePath.IndexOf("?"));

                foreach (string s in queryString.Split('&', ';'))
                {
                    string[] nameValuePair = s.Split('=');
                    if (nameValuePair.Length == 2 && nameValuePair[1].Length > 0)
                    {
                        request.Parameters.Add(nameValuePair[0], nameValuePair[1]);
                    }
                    else
                    {
                        request.Parameters.Add(nameValuePair[0], null);
                    }
                }
            }

            request.ResourcePath = uriResourcePath;


            using (StringWriter stringWriter = new StringWriter())
            {
                JsonWriter writer = new JsonWriter(stringWriter);
                writer.WriteObjectStart();

                if (updateInstanceRequest != null && updateInstanceRequest.IsSetInstanceId())
                {
                    writer.WritePropertyName("InstanceId");
                    writer.Write(updateInstanceRequest.InstanceId);
                }

                if (updateInstanceRequest != null && updateInstanceRequest.LayerIds != null && updateInstanceRequest.LayerIds.Count > 0)
                {
                    List <string> layerIdsList = updateInstanceRequest.LayerIds;
                    writer.WritePropertyName("LayerIds");
                    writer.WriteArrayStart();

                    foreach (string layerIdsListValue in layerIdsList)
                    {
                        writer.Write(StringUtils.FromString(layerIdsListValue));
                    }

                    writer.WriteArrayEnd();
                }
                if (updateInstanceRequest != null && updateInstanceRequest.IsSetInstanceType())
                {
                    writer.WritePropertyName("InstanceType");
                    writer.Write(updateInstanceRequest.InstanceType);
                }
                if (updateInstanceRequest != null && updateInstanceRequest.IsSetAutoScalingType())
                {
                    writer.WritePropertyName("AutoScalingType");
                    writer.Write(updateInstanceRequest.AutoScalingType);
                }
                if (updateInstanceRequest != null && updateInstanceRequest.IsSetHostname())
                {
                    writer.WritePropertyName("Hostname");
                    writer.Write(updateInstanceRequest.Hostname);
                }
                if (updateInstanceRequest != null && updateInstanceRequest.IsSetOs())
                {
                    writer.WritePropertyName("Os");
                    writer.Write(updateInstanceRequest.Os);
                }
                if (updateInstanceRequest != null && updateInstanceRequest.IsSetSshKeyName())
                {
                    writer.WritePropertyName("SshKeyName");
                    writer.Write(updateInstanceRequest.SshKeyName);
                }
                if (updateInstanceRequest != null && updateInstanceRequest.IsSetArchitecture())
                {
                    writer.WritePropertyName("Architecture");
                    writer.Write(updateInstanceRequest.Architecture);
                }

                writer.WriteObjectEnd();

                string snippet = stringWriter.ToString();
                request.Content = System.Text.Encoding.UTF8.GetBytes(snippet);
            }


            return(request);
        }
Exemplo n.º 17
0
    public static void CreateClothes()
    {
        string rootName="DocTexts_ch";
        if(English_Caption){
            rootName="DocTexts_en";
        }
        TextAsset xmlAsset = Resources.Load<TextAsset>(rootName);
        string xmlContent = xmlAsset.text;

        StringBuilder sbuilders = new StringBuilder ();
        JsonWriter writer = new JsonWriter (sbuilders);
        writer.WriteObjectStart ();

        string[] captions = xmlContent.Split('?');
        foreach(string caption in captions)
        {
            writer.WritePropertyName ("captions");
            writer.WriteArrayStart();

            writer.WriteObjectStart ();
            string[] subtitles = caption.Split(';');

            writer.WritePropertyName ("subtitles");
            writer.WriteArrayStart();//[
            foreach (string subtitle in subtitles)
            {
                writer.WriteObjectStart();

                string[] parts=subtitle.Split('/');

                string time_from=parts[0];
                string time_to=parts[1];
                string article=parts[2];

                //1
                writer.WritePropertyName ("time_from");
                writer.Write (time_from);
                sbuilders.Append(System.Environment.NewLine);

                //2
                writer.WritePropertyName ("time_to");
                writer.Write (time_to);
                sbuilders.Append(System.Environment.NewLine);

                //3
                writer.WritePropertyName ("article");
                writer.Write (article);
                sbuilders.Append(System.Environment.NewLine);

                writer.WriteObjectEnd();
            }
            writer.WriteArrayEnd();
            writer.WriteObjectEnd();
            writer.WriteArrayEnd();
        }
        writer.WriteObjectEnd ();

        string clothFile=sbuilders.ToString();
        string desName="captions_ch.xml";
        if(English_Caption){
            desName="captions_en.xml";
        }

        System.IO.File.WriteAllText(Application.persistentDataPath+"/"+desName,clothFile);

        Debug.Log("**********UpdateClothesContent Finish***********");
    }
Exemplo n.º 18
0
        public IRequest Marshall(PutItemRequest putItemRequest)
        {
            IRequest request = new DefaultRequest(putItemRequest, "AmazonDynamoDBv2");
            string   target  = "DynamoDB_20120810.PutItem";

            request.Headers["X-Amz-Target"] = target;

            request.Headers["Content-Type"] = "application/x-amz-json-1.0";


            string uriResourcePath = "";

            if (uriResourcePath.Contains("?"))
            {
                int    queryPosition = uriResourcePath.IndexOf("?", StringComparison.OrdinalIgnoreCase);
                string queryString   = uriResourcePath.Substring(queryPosition + 1);
                uriResourcePath = uriResourcePath.Substring(0, queryPosition);

                foreach (string s in queryString.Split('&', ';'))
                {
                    string[] nameValuePair = s.Split('=');
                    if (nameValuePair.Length == 2 && nameValuePair[1].Length > 0)
                    {
                        request.Parameters.Add(nameValuePair[0], nameValuePair[1]);
                    }
                    else
                    {
                        request.Parameters.Add(nameValuePair[0], null);
                    }
                }
            }

            request.ResourcePath = uriResourcePath;


            using (StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture))
            {
                JsonWriter writer = new JsonWriter(stringWriter);
                writer.WriteObjectStart();

                if (putItemRequest != null && putItemRequest.IsSetTableName())
                {
                    writer.WritePropertyName("TableName");
                    writer.Write(putItemRequest.TableName);
                }
                if (putItemRequest != null)
                {
                    if (putItemRequest.Item != null && putItemRequest.Item.Count > 0)
                    {
                        writer.WritePropertyName("Item");
                        writer.WriteObjectStart();
                        foreach (string putItemRequestItemKey in putItemRequest.Item.Keys)
                        {
                            AttributeValue itemListValue;
                            bool           itemListValueHasValue = putItemRequest.Item.TryGetValue(putItemRequestItemKey, out itemListValue);
                            writer.WritePropertyName(putItemRequestItemKey);

                            writer.WriteObjectStart();
                            if (itemListValue != null && itemListValue.IsSetS())
                            {
                                writer.WritePropertyName("S");
                                writer.Write(itemListValue.S);
                            }
                            if (itemListValue != null && itemListValue.IsSetN())
                            {
                                writer.WritePropertyName("N");
                                writer.Write(itemListValue.N);
                            }
                            if (itemListValue != null && itemListValue.IsSetB())
                            {
                                writer.WritePropertyName("B");
                                writer.Write(StringUtils.FromMemoryStream(itemListValue.B));
                            }

                            if (itemListValue != null && itemListValue.SS != null && itemListValue.SS.Count > 0)
                            {
                                List <string> sSList = itemListValue.SS;
                                writer.WritePropertyName("SS");
                                writer.WriteArrayStart();

                                foreach (string sSListValue in sSList)
                                {
                                    writer.Write(StringUtils.FromString(sSListValue));
                                }

                                writer.WriteArrayEnd();
                            }

                            if (itemListValue != null && itemListValue.NS != null && itemListValue.NS.Count > 0)
                            {
                                List <string> nSList = itemListValue.NS;
                                writer.WritePropertyName("NS");
                                writer.WriteArrayStart();

                                foreach (string nSListValue in nSList)
                                {
                                    writer.Write(StringUtils.FromString(nSListValue));
                                }

                                writer.WriteArrayEnd();
                            }

                            if (itemListValue != null && itemListValue.BS != null && itemListValue.BS.Count > 0)
                            {
                                List <MemoryStream> bSList = itemListValue.BS;
                                writer.WritePropertyName("BS");
                                writer.WriteArrayStart();

                                foreach (MemoryStream bSListValue in bSList)
                                {
                                    writer.Write(StringUtils.FromMemoryStream(bSListValue));
                                }

                                writer.WriteArrayEnd();
                            }
                            writer.WriteObjectEnd();
                        }
                        writer.WriteObjectEnd();
                    }
                }
                if (putItemRequest != null)
                {
                    if (putItemRequest.Expected != null && putItemRequest.Expected.Count > 0)
                    {
                        writer.WritePropertyName("Expected");
                        writer.WriteObjectStart();
                        foreach (string putItemRequestExpectedKey in putItemRequest.Expected.Keys)
                        {
                            ExpectedAttributeValue expectedListValue;
                            bool expectedListValueHasValue = putItemRequest.Expected.TryGetValue(putItemRequestExpectedKey, out expectedListValue);
                            writer.WritePropertyName(putItemRequestExpectedKey);

                            writer.WriteObjectStart();

                            if (expectedListValue != null)
                            {
                                AttributeValue value = expectedListValue.Value;
                                if (value != null)
                                {
                                    writer.WritePropertyName("Value");
                                    writer.WriteObjectStart();
                                    if (value != null && value.IsSetS())
                                    {
                                        writer.WritePropertyName("S");
                                        writer.Write(value.S);
                                    }
                                    if (value != null && value.IsSetN())
                                    {
                                        writer.WritePropertyName("N");
                                        writer.Write(value.N);
                                    }
                                    if (value != null && value.IsSetB())
                                    {
                                        writer.WritePropertyName("B");
                                        writer.Write(StringUtils.FromMemoryStream(value.B));
                                    }

                                    if (value != null && value.SS != null && value.SS.Count > 0)
                                    {
                                        List <string> sSList = value.SS;
                                        writer.WritePropertyName("SS");
                                        writer.WriteArrayStart();

                                        foreach (string sSListValue in sSList)
                                        {
                                            writer.Write(StringUtils.FromString(sSListValue));
                                        }

                                        writer.WriteArrayEnd();
                                    }

                                    if (value != null && value.NS != null && value.NS.Count > 0)
                                    {
                                        List <string> nSList = value.NS;
                                        writer.WritePropertyName("NS");
                                        writer.WriteArrayStart();

                                        foreach (string nSListValue in nSList)
                                        {
                                            writer.Write(StringUtils.FromString(nSListValue));
                                        }

                                        writer.WriteArrayEnd();
                                    }

                                    if (value != null && value.BS != null && value.BS.Count > 0)
                                    {
                                        List <MemoryStream> bSList = value.BS;
                                        writer.WritePropertyName("BS");
                                        writer.WriteArrayStart();

                                        foreach (MemoryStream bSListValue in bSList)
                                        {
                                            writer.Write(StringUtils.FromMemoryStream(bSListValue));
                                        }

                                        writer.WriteArrayEnd();
                                    }
                                    writer.WriteObjectEnd();
                                }
                            }
                            if (expectedListValue != null && expectedListValue.IsSetExists())
                            {
                                writer.WritePropertyName("Exists");
                                writer.Write(expectedListValue.Exists);
                            }
                            writer.WriteObjectEnd();
                        }
                        writer.WriteObjectEnd();
                    }
                }
                if (putItemRequest != null && putItemRequest.IsSetReturnValues())
                {
                    writer.WritePropertyName("ReturnValues");
                    writer.Write(putItemRequest.ReturnValues);
                }
                if (putItemRequest != null && putItemRequest.IsSetReturnConsumedCapacity())
                {
                    writer.WritePropertyName("ReturnConsumedCapacity");
                    writer.Write(putItemRequest.ReturnConsumedCapacity);
                }
                if (putItemRequest != null && putItemRequest.IsSetReturnItemCollectionMetrics())
                {
                    writer.WritePropertyName("ReturnItemCollectionMetrics");
                    writer.Write(putItemRequest.ReturnItemCollectionMetrics);
                }

                writer.WriteObjectEnd();

                string snippet = stringWriter.ToString();
                request.Content = System.Text.Encoding.UTF8.GetBytes(snippet);
            }


            return(request);
        }
Exemplo n.º 19
0
    /// <summary>
    /// Returns a <see cref="System.String"/> that represents the current <see cref="Recording"/> using JSON
    /// </summary>
    /// <returns>
    /// A <see cref="System.String"/> that represents the current <see cref="Recording"/>.
    /// </returns>
    public override string ToString()
    {
        StringBuilder jsonB = new StringBuilder();
        JsonWriter writer = new JsonWriter( jsonB );

        writer.WriteObjectStart();
        //{
        writer.WritePropertyName( "frameRate" );
        writer.Write( frameRate );

        writer.WritePropertyName( "frames" );
        writer.WriteArrayStart();
        //[
        foreach ( RecordingFrame frame in frames )
        {
            writer.WriteObjectStart();
            //{

            writer.WritePropertyName( "inputs" );
            writer.WriteArrayStart();
            //[
            foreach ( InputInfo input in frame.inputs )
            {
                writer.WriteObjectStart();
                //{
                writer.WritePropertyName( "inputName" );
                writer.Write( input.inputName );

                writer.WritePropertyName( "inputType" );
                writer.Write( (int)input.inputType );

                writer.WritePropertyName( "mouseButtonNum" );
                writer.Write( input.mouseButtonNum );

                writer.WritePropertyName( "buttonState" );
                writer.Write( input.buttonState );

                writer.WritePropertyName( "axisValue" );
                writer.Write( input.axisValue );
                //}
                writer.WriteObjectEnd();
            }
            //]
            writer.WriteArrayEnd();

            writer.WritePropertyName( "syncedProperties" );
            writer.WriteObjectStart();
            //[
            foreach ( var prop in frame.syncedProperties )
            {
                writer.WritePropertyName( prop.Key );
                writer.WriteObjectStart();
                //{
                writer.WritePropertyName( "name" );
                writer.Write( prop.Value.name );

                writer.WritePropertyName( "property" );
                writer.Write( prop.Value.property );
                //}
                writer.WriteObjectEnd();
            }
            //]
            writer.WriteObjectEnd();
            //}
            writer.WriteObjectEnd();
        }
        //]
        writer.WriteArrayEnd();
        //}
        writer.WriteObjectEnd();

        return jsonB.ToString();
    }
Exemplo n.º 20
0
	private static void writeMatrix(ref JsonWriter cfg, Transform mt) {
		cfg.WritePropertyName("pos");
		cfg.WriteArrayStart();
		cfg.Write(mt.localPosition.x);
		cfg.Write(mt.localPosition.y);
		cfg.Write(mt.localPosition.z);
		cfg.WriteArrayEnd();

		cfg.WritePropertyName("scale");
		cfg.WriteArrayStart();
		cfg.Write(mt.localScale.x);
		cfg.Write(mt.localScale.y);
		cfg.Write(mt.localScale.z);
		cfg.WriteArrayEnd();

		cfg.WritePropertyName("rotation");
		cfg.WriteArrayStart();
		cfg.Write(mt.localRotation.eulerAngles.x);
		cfg.Write(mt.localRotation.eulerAngles.y);
		cfg.Write(mt.localRotation.eulerAngles.z);
		cfg.WriteArrayEnd();
	}
Exemplo n.º 21
0
    public static void ExportScenesToJSON()
    {
        string path = EditorUtility.SaveFilePanel("SaveJason", Application.dataPath, "Scenes_Config_JSON", "txt");
        FileInfo fileInfo = new FileInfo(path);
        StreamWriter sw = fileInfo.CreateText();

        StringBuilder sb = new StringBuilder();
        JsonWriter writer = new JsonWriter(sb);
        writer.WriteObjectStart();
        writer.WritePropertyName("root");
        writer.WriteArrayStart();

        foreach (EditorBuildSettingsScene S in EditorBuildSettings.scenes)
        {
            if (S.enabled)
            {
                EditorApplication.OpenScene(S.path);
                writer.WriteObjectStart();
                writer.WritePropertyName("Scene");
                writer.WriteArrayStart();
                writer.WriteObjectStart();
                writer.WritePropertyName("SceneName");
                writer.Write(S.path);
                writer.WritePropertyName("GameObjects");
                writer.WriteArrayStart();

                foreach (GameObject obj in Object.FindObjectsOfType(typeof(GameObject)))
                {
                    if (obj.transform.parent == null)
                    {
                        writer.WriteObjectStart();
                        writer.WritePropertyName("GameObjectName");
                        writer.Write(obj.name);

                        writer.WritePropertyName("Position");
                        writer.WriteArrayStart();
                        writer.WriteObjectStart();
                        writer.WritePropertyName("X");
                        writer.Write(obj.transform.position.x.ToString("F5"));
                        writer.WritePropertyName("Y");
                        writer.Write(obj.transform.position.y.ToString("F5"));
                        writer.WritePropertyName("Z");
                        writer.Write(obj.transform.position.z.ToString("F5"));
                        writer.WriteObjectEnd();
                        writer.WriteArrayEnd();

                        writer.WritePropertyName("Rotation");
                        writer.WriteArrayStart();
                        writer.WriteObjectStart();
                        writer.WritePropertyName("X");
                        writer.Write(obj.transform.rotation.eulerAngles.x.ToString("F5"));
                        writer.WritePropertyName("Y");
                        writer.Write(obj.transform.rotation.eulerAngles.y.ToString("F5"));
                        writer.WritePropertyName("Z");
                        writer.Write(obj.transform.rotation.eulerAngles.z.ToString("F5"));
                        writer.WriteObjectEnd();
                        writer.WriteArrayEnd();

                        writer.WritePropertyName("Scale");
                        writer.WriteArrayStart();
                        writer.WriteObjectStart();
                        writer.WritePropertyName("X");
                        writer.Write(obj.transform.localScale.x.ToString("F5"));
                        writer.WritePropertyName("Y");
                        writer.Write(obj.transform.localScale.y.ToString("F5"));
                        writer.WritePropertyName("Z");
                        writer.Write(obj.transform.localScale.z.ToString("F5"));
                        writer.WriteObjectEnd();
                        writer.WriteArrayEnd();

                        writer.WriteObjectEnd();
                    }
                }

                writer.WriteArrayEnd();
                writer.WriteObjectEnd();
                writer.WriteArrayEnd();
                writer.WriteObjectEnd();
            }
        }
        writer.WriteArrayEnd();
        writer.WriteObjectEnd();
        sw.WriteLine(sb.ToString());
        sw.Close();
        sw.Dispose();
        AssetDatabase.Refresh();
    }
Exemplo n.º 22
0
        public IRequest Marshall(CreateLayerRequest createLayerRequest)
        {
            IRequest request = new DefaultRequest(createLayerRequest, "AmazonOpsWorks");
            string   target  = "OpsWorks_20130218.CreateLayer";

            request.Headers["X-Amz-Target"] = target;

            request.Headers["Content-Type"] = "application/x-amz-json-1.1";

            string uriResourcePath = "";

            request.ResourcePath = uriResourcePath;


            using (StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture))
            {
                JsonWriter writer = new JsonWriter(stringWriter);
                writer.WriteObjectStart();

                if (createLayerRequest != null && createLayerRequest.IsSetStackId())
                {
                    writer.WritePropertyName("StackId");
                    writer.Write(createLayerRequest.StackId);
                }
                if (createLayerRequest != null && createLayerRequest.IsSetType())
                {
                    writer.WritePropertyName("Type");
                    writer.Write(createLayerRequest.Type);
                }
                if (createLayerRequest != null && createLayerRequest.IsSetName())
                {
                    writer.WritePropertyName("Name");
                    writer.Write(createLayerRequest.Name);
                }
                if (createLayerRequest != null && createLayerRequest.IsSetShortname())
                {
                    writer.WritePropertyName("Shortname");
                    writer.Write(createLayerRequest.Shortname);
                }
                if (createLayerRequest != null)
                {
                    if (createLayerRequest.Attributes != null && createLayerRequest.Attributes.Count > 0)
                    {
                        writer.WritePropertyName("Attributes");
                        writer.WriteObjectStart();
                        foreach (string createLayerRequestAttributesKey in createLayerRequest.Attributes.Keys)
                        {
                            string attributesListValue;
                            bool   attributesListValueHasValue = createLayerRequest.Attributes.TryGetValue(createLayerRequestAttributesKey, out attributesListValue);
                            writer.WritePropertyName(createLayerRequestAttributesKey);

                            writer.Write(attributesListValue);
                        }
                        writer.WriteObjectEnd();
                    }
                }
                if (createLayerRequest != null && createLayerRequest.IsSetCustomInstanceProfileArn())
                {
                    writer.WritePropertyName("CustomInstanceProfileArn");
                    writer.Write(createLayerRequest.CustomInstanceProfileArn);
                }

                if (createLayerRequest != null && createLayerRequest.CustomSecurityGroupIds != null && createLayerRequest.CustomSecurityGroupIds.Count > 0)
                {
                    List <string> customSecurityGroupIdsList = createLayerRequest.CustomSecurityGroupIds;
                    writer.WritePropertyName("CustomSecurityGroupIds");
                    writer.WriteArrayStart();

                    foreach (string customSecurityGroupIdsListValue in customSecurityGroupIdsList)
                    {
                        writer.Write(StringUtils.FromString(customSecurityGroupIdsListValue));
                    }

                    writer.WriteArrayEnd();
                }

                if (createLayerRequest != null && createLayerRequest.Packages != null && createLayerRequest.Packages.Count > 0)
                {
                    List <string> packagesList = createLayerRequest.Packages;
                    writer.WritePropertyName("Packages");
                    writer.WriteArrayStart();

                    foreach (string packagesListValue in packagesList)
                    {
                        writer.Write(StringUtils.FromString(packagesListValue));
                    }

                    writer.WriteArrayEnd();
                }

                if (createLayerRequest != null && createLayerRequest.VolumeConfigurations != null && createLayerRequest.VolumeConfigurations.Count > 0)
                {
                    List <VolumeConfiguration> volumeConfigurationsList = createLayerRequest.VolumeConfigurations;
                    writer.WritePropertyName("VolumeConfigurations");
                    writer.WriteArrayStart();

                    foreach (VolumeConfiguration volumeConfigurationsListValue in volumeConfigurationsList)
                    {
                        writer.WriteObjectStart();
                        if (volumeConfigurationsListValue != null && volumeConfigurationsListValue.IsSetMountPoint())
                        {
                            writer.WritePropertyName("MountPoint");
                            writer.Write(volumeConfigurationsListValue.MountPoint);
                        }
                        if (volumeConfigurationsListValue != null && volumeConfigurationsListValue.IsSetRaidLevel())
                        {
                            writer.WritePropertyName("RaidLevel");
                            writer.Write(volumeConfigurationsListValue.RaidLevel);
                        }
                        if (volumeConfigurationsListValue != null && volumeConfigurationsListValue.IsSetNumberOfDisks())
                        {
                            writer.WritePropertyName("NumberOfDisks");
                            writer.Write(volumeConfigurationsListValue.NumberOfDisks);
                        }
                        if (volumeConfigurationsListValue != null && volumeConfigurationsListValue.IsSetSize())
                        {
                            writer.WritePropertyName("Size");
                            writer.Write(volumeConfigurationsListValue.Size);
                        }
                        if (volumeConfigurationsListValue != null && volumeConfigurationsListValue.IsSetVolumeType())
                        {
                            writer.WritePropertyName("VolumeType");
                            writer.Write(volumeConfigurationsListValue.VolumeType);
                        }
                        if (volumeConfigurationsListValue != null && volumeConfigurationsListValue.IsSetIops())
                        {
                            writer.WritePropertyName("Iops");
                            writer.Write(volumeConfigurationsListValue.Iops);
                        }
                        writer.WriteObjectEnd();
                    }
                    writer.WriteArrayEnd();
                }
                if (createLayerRequest != null && createLayerRequest.IsSetEnableAutoHealing())
                {
                    writer.WritePropertyName("EnableAutoHealing");
                    writer.Write(createLayerRequest.EnableAutoHealing);
                }
                if (createLayerRequest != null && createLayerRequest.IsSetAutoAssignElasticIps())
                {
                    writer.WritePropertyName("AutoAssignElasticIps");
                    writer.Write(createLayerRequest.AutoAssignElasticIps);
                }
                if (createLayerRequest != null && createLayerRequest.IsSetAutoAssignPublicIps())
                {
                    writer.WritePropertyName("AutoAssignPublicIps");
                    writer.Write(createLayerRequest.AutoAssignPublicIps);
                }

                if (createLayerRequest != null)
                {
                    Recipes customRecipes = createLayerRequest.CustomRecipes;
                    if (customRecipes != null)
                    {
                        writer.WritePropertyName("CustomRecipes");
                        writer.WriteObjectStart();

                        if (customRecipes != null && customRecipes.Setup != null && customRecipes.Setup.Count > 0)
                        {
                            List <string> setupList = customRecipes.Setup;
                            writer.WritePropertyName("Setup");
                            writer.WriteArrayStart();

                            foreach (string setupListValue in setupList)
                            {
                                writer.Write(StringUtils.FromString(setupListValue));
                            }

                            writer.WriteArrayEnd();
                        }

                        if (customRecipes != null && customRecipes.Configure != null && customRecipes.Configure.Count > 0)
                        {
                            List <string> configureList = customRecipes.Configure;
                            writer.WritePropertyName("Configure");
                            writer.WriteArrayStart();

                            foreach (string configureListValue in configureList)
                            {
                                writer.Write(StringUtils.FromString(configureListValue));
                            }

                            writer.WriteArrayEnd();
                        }

                        if (customRecipes != null && customRecipes.Deploy != null && customRecipes.Deploy.Count > 0)
                        {
                            List <string> deployList = customRecipes.Deploy;
                            writer.WritePropertyName("Deploy");
                            writer.WriteArrayStart();

                            foreach (string deployListValue in deployList)
                            {
                                writer.Write(StringUtils.FromString(deployListValue));
                            }

                            writer.WriteArrayEnd();
                        }

                        if (customRecipes != null && customRecipes.Undeploy != null && customRecipes.Undeploy.Count > 0)
                        {
                            List <string> undeployList = customRecipes.Undeploy;
                            writer.WritePropertyName("Undeploy");
                            writer.WriteArrayStart();

                            foreach (string undeployListValue in undeployList)
                            {
                                writer.Write(StringUtils.FromString(undeployListValue));
                            }

                            writer.WriteArrayEnd();
                        }

                        if (customRecipes != null && customRecipes.Shutdown != null && customRecipes.Shutdown.Count > 0)
                        {
                            List <string> shutdownList = customRecipes.Shutdown;
                            writer.WritePropertyName("Shutdown");
                            writer.WriteArrayStart();

                            foreach (string shutdownListValue in shutdownList)
                            {
                                writer.Write(StringUtils.FromString(shutdownListValue));
                            }

                            writer.WriteArrayEnd();
                        }
                        writer.WriteObjectEnd();
                    }
                }
                if (createLayerRequest != null && createLayerRequest.IsSetInstallUpdatesOnBoot())
                {
                    writer.WritePropertyName("InstallUpdatesOnBoot");
                    writer.Write(createLayerRequest.InstallUpdatesOnBoot);
                }
                if (createLayerRequest != null && createLayerRequest.IsSetUseEbsOptimizedInstances())
                {
                    writer.WritePropertyName("UseEbsOptimizedInstances");
                    writer.Write(createLayerRequest.UseEbsOptimizedInstances);
                }

                writer.WriteObjectEnd();

                string snippet = stringWriter.ToString();
                request.Content = System.Text.Encoding.UTF8.GetBytes(snippet);
            }


            return(request);
        }
Exemplo n.º 23
0
            private static void WriteValue(object obj, JsonWriter writer,
                                           bool writer_is_private,
                                           int depth)
            {
                if (depth > max_nesting_depth)
                {
                    throw new JsonException(
                              String.Format("Max allowed object depth reached while " +
                                            "trying to export from type {0}",
                                            obj.GetType()));
                }

                if (obj == null)
                {
                    writer.Write(null);
                    return;
                }

                if (obj is IJsonWrapper)
                {
                    if (writer_is_private)
                    {
                        writer.TextWriter.Write(((IJsonWrapper)obj).ToJson());
                    }
                    else
                    {
                        ((IJsonWrapper)obj).ToJson(writer);
                    }

                    return;
                }

                if (obj is String)
                {
                    writer.Write((string)obj);
                    return;
                }

                if (obj is Double)
                {
                    writer.Write((double)obj);
                    return;
                }

                if (obj is Int32)
                {
                    writer.Write((int)obj);
                    return;
                }

                if (obj is Boolean)
                {
                    writer.Write((bool)obj);
                    return;
                }

                if (obj is Int64)
                {
                    writer.Write((long)obj);
                    return;
                }

                if (obj is Array)
                {
                    writer.WriteArrayStart();

                    foreach (object elem in (Array)obj)
                    {
                        WriteValue(elem, writer, writer_is_private, depth + 1);
                    }

                    writer.WriteArrayEnd();

                    return;
                }

                if (obj is IList)
                {
                    writer.WriteArrayStart();
                    foreach (object elem in (IList)obj)
                    {
                        WriteValue(elem, writer, writer_is_private, depth + 1);
                    }
                    writer.WriteArrayEnd();

                    return;
                }

                if (obj is IDictionary)
                {
                    writer.WriteObjectStart();
                    foreach (DictionaryEntry entry in (IDictionary)obj)
                    {
                        if (entry.Value == null)
                        {
                            continue;
                        }

                        writer.WritePropertyName((string)entry.Key);
                        WriteValue(entry.Value, writer, writer_is_private,
                                   depth + 1);
                    }
                    writer.WriteObjectEnd();

                    return;
                }

                Type obj_type = obj.GetType();

                // See if there's a custom exporter for the object
                if (custom_exporters_table.ContainsKey(obj_type))
                {
                    ExporterFunc exporter = custom_exporters_table[obj_type];
                    exporter(obj, writer);

                    return;
                }

                // If not, maybe there's a base exporter
                if (base_exporters_table.ContainsKey(obj_type))
                {
                    ExporterFunc exporter = base_exporters_table[obj_type];
                    exporter(obj, writer);

                    return;
                }

                // Last option, let's see if it's an enum
                if (obj is Enum)
                {
                    Type e_type = Enum.GetUnderlyingType(obj_type);

                    if (e_type == typeof(long) ||
                        e_type == typeof(uint) ||
                        e_type == typeof(ulong))
                    {
                        writer.Write((ulong)obj);
                    }
                    else
                    {
                        writer.Write((int)obj);
                    }

                    return;
                }

                // Okay, so it looks like the input should be exported as an
                // object
                AddTypeProperties(obj_type);
                IList <PropertyMetadata> props = type_properties[obj_type];

                writer.WriteObjectStart();
                foreach (PropertyMetadata p_data in props)
                {
                    string propertyName  = null;
                    object propertyValue = null;
                    if (p_data.IsField)
                    {
                        propertyName  = p_data.Info.Name;
                        propertyValue = ((FieldInfo)p_data.Info).GetValue(obj);
                    }
                    else
                    {
                        PropertyInfo p_info = (PropertyInfo)p_data.Info;

                        if (p_info.CanRead)
                        {
                            propertyName  = GetPropertyName(p_data.Info);
                            propertyValue = p_info.GetValue(obj, null);
                        }
                    }

                    if (propertyName == null || propertyValue == null)
                    {
                        continue;
                    }

                    writer.WritePropertyName(propertyName);
                    WriteValue(propertyValue,
                               writer, writer_is_private, depth + 1);
                }
                writer.WriteObjectEnd();
            }
Exemplo n.º 24
0
	private static void writeConfig() {
		JsonWriter cfg = new JsonWriter();
		cfg.WriteObjectStart();
		cfg.WritePropertyName("scene");
		cfg.WriteArrayStart();
		GameObject[] arr = Selection.gameObjects;
		foreach (GameObject obj in arr) {
			writeObject(obj, ref cfg);
		}
		cfg.WriteArrayEnd();
		cfg.WriteObjectEnd();

		string filepath = folderName + "/scene.lightmap";
		if (File.Exists(filepath)) {
			File.Delete(filepath);
		}
		FileStream fs = new FileStream(filepath, FileMode.Create);
		BinaryWriter bw = new BinaryWriter(fs);
		bw.Write(cfg.ToString().ToCharArray());
		bw.Close();
		fs.Close();
		Debug.Log("Write Config:" + filepath);
	}
		/// <summary>
		/// Write this module to a JsonWriter
		/// </summary>
		/// <param name="Writer">Writer to output to</param>
		void Write(JsonWriter Writer)
		{
			Writer.WriteObjectStart();
			Writer.WriteValue("Name", Name);
			Writer.WriteValue("Type", Type.ToString());
			Writer.WriteValue("LoadingPhase", LoadingPhase.ToString());
			if (WhitelistPlatforms != null && WhitelistPlatforms.Length > 0)
			{
				Writer.WriteArrayStart("WhitelistPlatforms");
				foreach (UnrealTargetPlatform WhitelistPlatform in WhitelistPlatforms)
				{
					Writer.WriteValue(WhitelistPlatform.ToString());
				}
				Writer.WriteArrayEnd();
			}
			if (BlacklistPlatforms != null && BlacklistPlatforms.Length > 0)
			{
				Writer.WriteArrayStart("BlacklistPlatforms");
				foreach (UnrealTargetPlatform BlacklistPlatform in BlacklistPlatforms)
				{
					Writer.WriteValue(BlacklistPlatform.ToString());
				}
				Writer.WriteArrayEnd();
			}
			if (AdditionalDependencies != null && AdditionalDependencies.Length > 0)
			{
				Writer.WriteArrayStart("AdditionalDependencies");
				foreach (string AdditionalDependency in AdditionalDependencies)
				{
					Writer.WriteValue(AdditionalDependency);
				}
				Writer.WriteArrayEnd();
			}
			Writer.WriteObjectEnd();
		}
        public IRequest Marshall(RunJobFlowRequest runJobFlowRequest)
        {
            IRequest request = new DefaultRequest(runJobFlowRequest, "AmazonElasticMapReduce");
            string   target  = "ElasticMapReduce.RunJobFlow";

            request.Headers["X-Amz-Target"] = target;
            request.Headers["Content-Type"] = "application/x-amz-json-1.1";



            string uriResourcePath = "";

            if (uriResourcePath.Contains("?"))
            {
                string queryString = uriResourcePath.Substring(uriResourcePath.IndexOf("?") + 1);
                uriResourcePath = uriResourcePath.Substring(0, uriResourcePath.IndexOf("?"));

                foreach (string s in queryString.Split('&', ';'))
                {
                    string[] nameValuePair = s.Split('=');
                    if (nameValuePair.Length == 2 && nameValuePair[1].Length > 0)
                    {
                        request.Parameters.Add(nameValuePair[0], nameValuePair[1]);
                    }
                    else
                    {
                        request.Parameters.Add(nameValuePair[0], null);
                    }
                }
            }

            request.ResourcePath = uriResourcePath;


            using (StringWriter stringWriter = new StringWriter())
            {
                JsonWriter writer = new JsonWriter(stringWriter);
                writer.WriteObjectStart();

                if (runJobFlowRequest != null && runJobFlowRequest.IsSetName())
                {
                    writer.WritePropertyName("Name");
                    writer.Write(runJobFlowRequest.Name);
                }
                if (runJobFlowRequest != null && runJobFlowRequest.IsSetLogUri())
                {
                    writer.WritePropertyName("LogUri");
                    writer.Write(runJobFlowRequest.LogUri);
                }
                if (runJobFlowRequest != null && runJobFlowRequest.IsSetAdditionalInfo())
                {
                    writer.WritePropertyName("AdditionalInfo");
                    writer.Write(runJobFlowRequest.AdditionalInfo);
                }
                if (runJobFlowRequest != null && runJobFlowRequest.IsSetAmiVersion())
                {
                    writer.WritePropertyName("AmiVersion");
                    writer.Write(runJobFlowRequest.AmiVersion);
                }

                if (runJobFlowRequest != null)
                {
                    JobFlowInstancesConfig instances = runJobFlowRequest.Instances;
                    if (instances != null)
                    {
                        writer.WritePropertyName("Instances");
                        writer.WriteObjectStart();
                        if (instances != null && instances.IsSetMasterInstanceType())
                        {
                            writer.WritePropertyName("MasterInstanceType");
                            writer.Write(instances.MasterInstanceType);
                        }
                        if (instances != null && instances.IsSetSlaveInstanceType())
                        {
                            writer.WritePropertyName("SlaveInstanceType");
                            writer.Write(instances.SlaveInstanceType);
                        }
                        if (instances != null && instances.IsSetInstanceCount())
                        {
                            writer.WritePropertyName("InstanceCount");
                            writer.Write(instances.InstanceCount);
                        }

                        if (instances != null && instances.InstanceGroups != null && instances.InstanceGroups.Count > 0)
                        {
                            List <InstanceGroupConfig> instanceGroupsList = instances.InstanceGroups;
                            writer.WritePropertyName("InstanceGroups");
                            writer.WriteArrayStart();

                            foreach (InstanceGroupConfig instanceGroupsListValue in instanceGroupsList)
                            {
                                writer.WriteObjectStart();
                                if (instanceGroupsListValue != null && instanceGroupsListValue.IsSetName())
                                {
                                    writer.WritePropertyName("Name");
                                    writer.Write(instanceGroupsListValue.Name);
                                }
                                if (instanceGroupsListValue != null && instanceGroupsListValue.IsSetMarket())
                                {
                                    writer.WritePropertyName("Market");
                                    writer.Write(instanceGroupsListValue.Market);
                                }
                                if (instanceGroupsListValue != null && instanceGroupsListValue.IsSetInstanceRole())
                                {
                                    writer.WritePropertyName("InstanceRole");
                                    writer.Write(instanceGroupsListValue.InstanceRole);
                                }
                                if (instanceGroupsListValue != null && instanceGroupsListValue.IsSetBidPrice())
                                {
                                    writer.WritePropertyName("BidPrice");
                                    writer.Write(instanceGroupsListValue.BidPrice);
                                }
                                if (instanceGroupsListValue != null && instanceGroupsListValue.IsSetInstanceType())
                                {
                                    writer.WritePropertyName("InstanceType");
                                    writer.Write(instanceGroupsListValue.InstanceType);
                                }
                                if (instanceGroupsListValue != null && instanceGroupsListValue.IsSetInstanceCount())
                                {
                                    writer.WritePropertyName("InstanceCount");
                                    writer.Write(instanceGroupsListValue.InstanceCount);
                                }
                                writer.WriteObjectEnd();
                            }
                            writer.WriteArrayEnd();
                        }
                        if (instances != null && instances.IsSetEc2KeyName())
                        {
                            writer.WritePropertyName("Ec2KeyName");
                            writer.Write(instances.Ec2KeyName);
                        }

                        if (instances != null)
                        {
                            PlacementType placement = instances.Placement;
                            if (placement != null)
                            {
                                writer.WritePropertyName("Placement");
                                writer.WriteObjectStart();
                                if (placement != null && placement.IsSetAvailabilityZone())
                                {
                                    writer.WritePropertyName("AvailabilityZone");
                                    writer.Write(placement.AvailabilityZone);
                                }
                                writer.WriteObjectEnd();
                            }
                        }
                        if (instances != null && instances.IsSetKeepJobFlowAliveWhenNoSteps())
                        {
                            writer.WritePropertyName("KeepJobFlowAliveWhenNoSteps");
                            writer.Write(instances.KeepJobFlowAliveWhenNoSteps);
                        }
                        if (instances != null && instances.IsSetTerminationProtected())
                        {
                            writer.WritePropertyName("TerminationProtected");
                            writer.Write(instances.TerminationProtected);
                        }
                        if (instances != null && instances.IsSetHadoopVersion())
                        {
                            writer.WritePropertyName("HadoopVersion");
                            writer.Write(instances.HadoopVersion);
                        }
                        if (instances != null && instances.IsSetEc2SubnetId())
                        {
                            writer.WritePropertyName("Ec2SubnetId");
                            writer.Write(instances.Ec2SubnetId);
                        }
                        writer.WriteObjectEnd();
                    }
                }

                if (runJobFlowRequest != null && runJobFlowRequest.Steps != null && runJobFlowRequest.Steps.Count > 0)
                {
                    List <StepConfig> stepsList = runJobFlowRequest.Steps;
                    writer.WritePropertyName("Steps");
                    writer.WriteArrayStart();

                    foreach (StepConfig stepsListValue in stepsList)
                    {
                        writer.WriteObjectStart();
                        if (stepsListValue != null && stepsListValue.IsSetName())
                        {
                            writer.WritePropertyName("Name");
                            writer.Write(stepsListValue.Name);
                        }
                        if (stepsListValue != null && stepsListValue.IsSetActionOnFailure())
                        {
                            writer.WritePropertyName("ActionOnFailure");
                            writer.Write(stepsListValue.ActionOnFailure);
                        }

                        if (stepsListValue != null)
                        {
                            HadoopJarStepConfig hadoopJarStep = stepsListValue.HadoopJarStep;
                            if (hadoopJarStep != null)
                            {
                                writer.WritePropertyName("HadoopJarStep");
                                writer.WriteObjectStart();

                                if (hadoopJarStep != null && hadoopJarStep.Properties != null && hadoopJarStep.Properties.Count > 0)
                                {
                                    List <KeyValue> propertiesList = hadoopJarStep.Properties;
                                    writer.WritePropertyName("Properties");
                                    writer.WriteArrayStart();

                                    foreach (KeyValue propertiesListValue in propertiesList)
                                    {
                                        writer.WriteObjectStart();
                                        if (propertiesListValue != null && propertiesListValue.IsSetKey())
                                        {
                                            writer.WritePropertyName("Key");
                                            writer.Write(propertiesListValue.Key);
                                        }
                                        if (propertiesListValue != null && propertiesListValue.IsSetValue())
                                        {
                                            writer.WritePropertyName("Value");
                                            writer.Write(propertiesListValue.Value);
                                        }
                                        writer.WriteObjectEnd();
                                    }
                                    writer.WriteArrayEnd();
                                }
                                if (hadoopJarStep != null && hadoopJarStep.IsSetJar())
                                {
                                    writer.WritePropertyName("Jar");
                                    writer.Write(hadoopJarStep.Jar);
                                }
                                if (hadoopJarStep != null && hadoopJarStep.IsSetMainClass())
                                {
                                    writer.WritePropertyName("MainClass");
                                    writer.Write(hadoopJarStep.MainClass);
                                }

                                if (hadoopJarStep != null && hadoopJarStep.Args != null && hadoopJarStep.Args.Count > 0)
                                {
                                    List <string> argsList = hadoopJarStep.Args;
                                    writer.WritePropertyName("Args");
                                    writer.WriteArrayStart();

                                    foreach (string argsListValue in argsList)
                                    {
                                        writer.Write(StringUtils.FromString(argsListValue));
                                    }

                                    writer.WriteArrayEnd();
                                }
                                writer.WriteObjectEnd();
                            }
                        }
                        writer.WriteObjectEnd();
                    }
                    writer.WriteArrayEnd();
                }

                if (runJobFlowRequest != null && runJobFlowRequest.BootstrapActions != null && runJobFlowRequest.BootstrapActions.Count > 0)
                {
                    List <BootstrapActionConfig> bootstrapActionsList = runJobFlowRequest.BootstrapActions;
                    writer.WritePropertyName("BootstrapActions");
                    writer.WriteArrayStart();

                    foreach (BootstrapActionConfig bootstrapActionsListValue in bootstrapActionsList)
                    {
                        writer.WriteObjectStart();
                        if (bootstrapActionsListValue != null && bootstrapActionsListValue.IsSetName())
                        {
                            writer.WritePropertyName("Name");
                            writer.Write(bootstrapActionsListValue.Name);
                        }

                        if (bootstrapActionsListValue != null)
                        {
                            ScriptBootstrapActionConfig scriptBootstrapAction = bootstrapActionsListValue.ScriptBootstrapAction;
                            if (scriptBootstrapAction != null)
                            {
                                writer.WritePropertyName("ScriptBootstrapAction");
                                writer.WriteObjectStart();
                                if (scriptBootstrapAction != null && scriptBootstrapAction.IsSetPath())
                                {
                                    writer.WritePropertyName("Path");
                                    writer.Write(scriptBootstrapAction.Path);
                                }

                                if (scriptBootstrapAction != null && scriptBootstrapAction.Args != null && scriptBootstrapAction.Args.Count > 0)
                                {
                                    List <string> argsList = scriptBootstrapAction.Args;
                                    writer.WritePropertyName("Args");
                                    writer.WriteArrayStart();

                                    foreach (string argsListValue in argsList)
                                    {
                                        writer.Write(StringUtils.FromString(argsListValue));
                                    }

                                    writer.WriteArrayEnd();
                                }
                                writer.WriteObjectEnd();
                            }
                        }
                        writer.WriteObjectEnd();
                    }
                    writer.WriteArrayEnd();
                }

                if (runJobFlowRequest != null && runJobFlowRequest.SupportedProducts != null && runJobFlowRequest.SupportedProducts.Count > 0)
                {
                    List <string> supportedProductsList = runJobFlowRequest.SupportedProducts;
                    writer.WritePropertyName("SupportedProducts");
                    writer.WriteArrayStart();

                    foreach (string supportedProductsListValue in supportedProductsList)
                    {
                        writer.Write(StringUtils.FromString(supportedProductsListValue));
                    }

                    writer.WriteArrayEnd();
                }

                if (runJobFlowRequest != null && runJobFlowRequest.NewSupportedProducts != null && runJobFlowRequest.NewSupportedProducts.Count > 0)
                {
                    List <SupportedProductConfig> newSupportedProductsList = runJobFlowRequest.NewSupportedProducts;
                    writer.WritePropertyName("NewSupportedProducts");
                    writer.WriteArrayStart();

                    foreach (SupportedProductConfig newSupportedProductsListValue in newSupportedProductsList)
                    {
                        writer.WriteObjectStart();
                        if (newSupportedProductsListValue != null && newSupportedProductsListValue.IsSetName())
                        {
                            writer.WritePropertyName("Name");
                            writer.Write(newSupportedProductsListValue.Name);
                        }

                        if (newSupportedProductsListValue != null && newSupportedProductsListValue.Args != null && newSupportedProductsListValue.Args.Count > 0)
                        {
                            List <string> argsList = newSupportedProductsListValue.Args;
                            writer.WritePropertyName("Args");
                            writer.WriteArrayStart();

                            foreach (string argsListValue in argsList)
                            {
                                writer.Write(StringUtils.FromString(argsListValue));
                            }

                            writer.WriteArrayEnd();
                        }
                        writer.WriteObjectEnd();
                    }
                    writer.WriteArrayEnd();
                }
                if (runJobFlowRequest != null && runJobFlowRequest.IsSetVisibleToAllUsers())
                {
                    writer.WritePropertyName("VisibleToAllUsers");
                    writer.Write(runJobFlowRequest.VisibleToAllUsers);
                }
                if (runJobFlowRequest != null && runJobFlowRequest.IsSetJobFlowRole())
                {
                    writer.WritePropertyName("JobFlowRole");
                    writer.Write(runJobFlowRequest.JobFlowRole);
                }

                writer.WriteObjectEnd();

                string snippet = stringWriter.ToString();
                request.Content = System.Text.Encoding.UTF8.GetBytes(snippet);
            }


            return(request);
        }
Exemplo n.º 27
0
        public static string ToJsonDocument(object value, string fullDocumentPath)
        {
            var writer = new JsonWriter();

            writer.PrettyPrint = true;

            writer.WriteObjectStart();
            writer.WritePropertyName("name"); //document name
            writer.Write(fullDocumentPath);

            WriteFields(value);

            /// <summary>
            /// "fields" is not surrounded by object { } after this call
            /// </summary>
            void WriteFields(object v)
            {
                writer.WritePropertyName("fields");
                writer.WriteObjectStart();

                //REFLESIA OF ETERNITY
                if (v == null)
                {
                    throw new FirestormException($"Found null value in the object you are trying to make into a Json!");
                }

                var fields = v.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance);

                foreach (var field in fields)
                {
                    //Debug.Log($"Propp {field.Name}");
                    writer.WritePropertyName(field.Name);

                    bool hasTimestampAttribute = field.GetCustomAttribute <ServerTimestamp>() != null;
                    var  fieldObject           = field.GetValue(v);

                    WriterDecision(fieldObject, hasTimestampAttribute);

                    void WriterDecision(object obj, bool timestampAttribute = false)
                    {
                        writer.WriteObjectStart();
                        var formatted = FormatForValueJson(obj);

                        switch (obj)
                        {
                        case List <object> lo:
                            writer.WritePropertyName(formatted.typeString);
                            writer.WriteObjectStart();
                            writer.WritePropertyName("values");
                            writer.WriteArrayStart();
                            foreach (object fromArray in lo)
                            {
                                //probably explode if you put List<object> in List<object>
                                WriterDecision(fromArray);
                            }

                            writer.WriteArrayEnd();
                            writer.WriteObjectEnd();
                            break;

                        case byte[] by:
                            //UnityEngine.Debug.Log($"WRITING BYTE");
                            writer.WritePropertyName(formatted.typeString);
                            writer.Write(Convert.ToBase64String((byte[])formatted.objectForJson));
                            break;

                        default:
                            if (formatted.typeString == "mapValue")
                            {
                                writer.WritePropertyName(formatted.typeString);
                                writer.WriteObjectStart();
                                WriteFields(formatted.objectForJson);
                                writer.WriteObjectEnd();
                            }
                            else
                            {
                                writer.WritePropertyName(formatted.typeString);
                                writer.WriteSmart(formatted.objectForJson);
                            }

                            break;
                        }

                        writer.WriteObjectEnd();
                    }
                }

                writer.WriteObjectEnd(); //fields
            } //WriteFields

            writer.WriteObjectEnd(); //top
            return(writer.ToString());
        }
        public IRequest Marshall(AddWorkingStorageRequest addWorkingStorageRequest)
        {
            IRequest request = new DefaultRequest(addWorkingStorageRequest, "AmazonStorageGateway");
            string   target  = "StorageGateway_20120630.AddWorkingStorage";

            request.Headers["X-Amz-Target"] = target;
            request.Headers["Content-Type"] = "application/x-amz-json-1.1";



            string uriResourcePath = "";

            if (uriResourcePath.Contains("?"))
            {
                string queryString = uriResourcePath.Substring(uriResourcePath.IndexOf("?") + 1);
                uriResourcePath = uriResourcePath.Substring(0, uriResourcePath.IndexOf("?"));

                foreach (string s in queryString.Split('&', ';'))
                {
                    string[] nameValuePair = s.Split('=');
                    if (nameValuePair.Length == 2 && nameValuePair[1].Length > 0)
                    {
                        request.Parameters.Add(nameValuePair[0], nameValuePair[1]);
                    }
                    else
                    {
                        request.Parameters.Add(nameValuePair[0], null);
                    }
                }
            }

            request.ResourcePath = uriResourcePath;


            using (StringWriter stringWriter = new StringWriter())
            {
                JsonWriter writer = new JsonWriter(stringWriter);
                writer.WriteObjectStart();

                if (addWorkingStorageRequest != null && addWorkingStorageRequest.IsSetGatewayARN())
                {
                    writer.WritePropertyName("GatewayARN");
                    writer.Write(addWorkingStorageRequest.GatewayARN);
                }

                if (addWorkingStorageRequest != null && addWorkingStorageRequest.DiskIds != null && addWorkingStorageRequest.DiskIds.Count > 0)
                {
                    List <string> diskIdsList = addWorkingStorageRequest.DiskIds;
                    writer.WritePropertyName("DiskIds");
                    writer.WriteArrayStart();

                    foreach (string diskIdsListValue in diskIdsList)
                    {
                        writer.Write(StringUtils.FromString(diskIdsListValue));
                    }

                    writer.WriteArrayEnd();
                }

                writer.WriteObjectEnd();

                string snippet = stringWriter.ToString();
                request.Content = System.Text.Encoding.UTF8.GetBytes(snippet);
            }


            return(request);
        }
Exemplo n.º 29
0
        public string SaveToJson(bool bLimitedMode = false)
        {
            JsonWriter jsonWriter = new JsonWriter();

            try
            {
                jsonWriter.WriteObjectStart();

                if (!bLimitedMode)
                {
                    jsonWriter.WriteObjectStart("ui");
                    jsonWriter.WriteBool(useAutoScan, "autoScan");
                    jsonWriter.WriteBool(useFullScreenCapture, "forceFSC");
                    jsonWriter.WriteBool(useXInput, "xInput");

                    jsonWriter.WriteObjectEnd();
                }

                if (!bLimitedMode)
                {
                    jsonWriter.WriteObjectStart("cloud");
                    jsonWriter.WriteBool(useCloudStorage, "use");
                    if (cloudToken != null)
                    {
                        jsonWriter.WriteString(cloudToken, "token");
                    }

                    jsonWriter.WriteObjectEnd();
                }

                {
                    List <int> listIds = new List <int>();
                    foreach (TriadCard card in ownedCards)
                    {
                        listIds.Add(card.Id);
                    }
                    listIds.Sort();

                    jsonWriter.WriteArrayStart("cards");
                    foreach (int id in listIds)
                    {
                        jsonWriter.WriteInt(id);
                    }

                    jsonWriter.WriteArrayEnd();
                }

                {
                    List <int> listIds = new List <int>();
                    foreach (TriadNpc npc in completedNpcs)
                    {
                        listIds.Add(npc.Id);
                    }
                    listIds.Sort();

                    jsonWriter.WriteArrayStart("npcs");
                    foreach (int id in listIds)
                    {
                        jsonWriter.WriteInt(id);
                    }

                    jsonWriter.WriteArrayEnd();
                }

                {
                    jsonWriter.WriteArrayStart("decks");
                    foreach (KeyValuePair <TriadNpc, TriadDeck> kvp in lastDeck)
                    {
                        jsonWriter.WriteObjectStart();
                        jsonWriter.WriteInt(kvp.Key.Id, "id");
                        jsonWriter.WriteArrayStart("cards");
                        for (int Idx = 0; Idx < kvp.Value.knownCards.Count; Idx++)
                        {
                            jsonWriter.WriteInt(kvp.Value.knownCards[Idx].Id);
                        }
                        jsonWriter.WriteArrayEnd();
                        jsonWriter.WriteObjectEnd();
                    }

                    jsonWriter.WriteArrayEnd();
                }

                {
                    jsonWriter.WriteArrayStart("favDecks");
                    foreach (TriadDeckNamed deck in favDecks)
                    {
                        jsonWriter.WriteObjectStart();
                        if (deck != null)
                        {
                            jsonWriter.WriteString(deck.Name, "name");
                            jsonWriter.WriteArrayStart("cards");
                            for (int Idx = 0; Idx < deck.knownCards.Count; Idx++)
                            {
                                jsonWriter.WriteInt(deck.knownCards[Idx].Id);
                            }
                            jsonWriter.WriteArrayEnd();
                        }
                        jsonWriter.WriteObjectEnd();
                    }
                    jsonWriter.WriteArrayEnd();
                }

                if (!bLimitedMode)
                {
                    jsonWriter.WriteObjectStart("images");
                    ImageHashDB.Get().StoreImageHashes(customHashes, jsonWriter);
                    jsonWriter.WriteObjectEnd();

                    jsonWriter.WriteArrayStart("digits");
                    ImageHashDB.Get().StoreDigitHashes(customDigits, jsonWriter);
                    jsonWriter.WriteArrayEnd();
                }

                jsonWriter.WriteObjectEnd();
            }
            catch (Exception ex)
            {
                Logger.WriteLine("Saving failed! Exception:" + ex);
            }

            return(jsonWriter.ToString());
        }
Exemplo n.º 30
0
        public IRequest Marshall(SetVaultNotificationsRequest setVaultNotificationsRequest)
        {
            IRequest request = new DefaultRequest(setVaultNotificationsRequest, "AmazonGlacier");
            string   target  = "Glacier.SetVaultNotifications";

            request.Headers["X-Amz-Target"] = target;

            request.Headers["Content-Type"] = "application/x-amz-json-1.0";
            request.HttpMethod = "PUT";
            string uriResourcePath = "/{accountId}/vaults/{vaultName}/notification-configuration";

            if (setVaultNotificationsRequest.IsSetAccountId())
            {
                uriResourcePath = uriResourcePath.Replace("{accountId}", StringUtils.FromString(setVaultNotificationsRequest.AccountId));
            }
            else
            {
                uriResourcePath = uriResourcePath.Replace("{accountId}", "");
            }
            if (setVaultNotificationsRequest.IsSetVaultName())
            {
                uriResourcePath = uriResourcePath.Replace("{vaultName}", StringUtils.FromString(setVaultNotificationsRequest.VaultName));
            }
            else
            {
                uriResourcePath = uriResourcePath.Replace("{vaultName}", "");
            }
            request.ResourcePath = uriResourcePath;


            using (StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture))
            {
                JsonWriter writer = new JsonWriter(stringWriter);
                writer.WriteObjectStart();

                if (setVaultNotificationsRequest.VaultNotificationConfig != null && setVaultNotificationsRequest.VaultNotificationConfig.IsSetSNSTopic())
                {
                    writer.WritePropertyName("SNSTopic");
                    writer.Write(setVaultNotificationsRequest.VaultNotificationConfig.SNSTopic);
                }

                if (setVaultNotificationsRequest.VaultNotificationConfig != null && setVaultNotificationsRequest.VaultNotificationConfig.Events != null && setVaultNotificationsRequest.VaultNotificationConfig.Events.Count > 0)
                {
                    List <string> eventsList = setVaultNotificationsRequest.VaultNotificationConfig.Events;
                    writer.WritePropertyName("Events");
                    writer.WriteArrayStart();

                    foreach (string eventsListValue in eventsList)
                    {
                        writer.Write(StringUtils.FromString(eventsListValue));
                    }

                    writer.WriteArrayEnd();
                }

                writer.WriteObjectEnd();

                string snippet = stringWriter.ToString();
                request.Content = System.Text.Encoding.UTF8.GetBytes(snippet);
            }


            return(request);
        }
Exemplo n.º 31
0
        /// <summary>
        /// Return a JSON represenation of the current metrics
        /// </summary>
        /// <returns></returns>
        public string ToJSON()
        {
            if (!this.IsEnabled)
            {
                return("{ }");
            }

            var sb = new StringBuilder();
            var jw = new JsonWriter(sb);

            jw.WriteObjectStart();
            jw.WritePropertyName("properties");
            jw.WriteObjectStart();
            foreach (var kvp in this.Properties)
            {
                jw.WritePropertyName(kvp.Key.ToString());
                var properties = kvp.Value;
                if (properties.Count > 1)
                {
                    jw.WriteArrayStart();
                }
                foreach (var obj in properties)
                {
                    if (obj == null)
                    {
                        jw.Write(null);
                    }
                    else
                    {
                        jw.Write(obj.ToString());
                    }
                }
                if (properties.Count > 1)
                {
                    jw.WriteArrayEnd();
                }
            }
            jw.WriteObjectEnd();
            jw.WritePropertyName("timings");
            jw.WriteObjectStart();
            foreach (var kvp in this.Timings)
            {
                jw.WritePropertyName(kvp.Key.ToString());
                var timings = kvp.Value;
                if (timings.Count > 1)
                {
                    jw.WriteArrayStart();
                }
                foreach (var timing in kvp.Value)
                {
                    if (timing.IsFinished)
                    {
                        jw.Write(timing.ElapsedTime.TotalMilliseconds);
                    }
                }
                if (timings.Count > 1)
                {
                    jw.WriteArrayEnd();
                }
            }
            jw.WriteObjectEnd();
            jw.WritePropertyName("counters");
            jw.WriteObjectStart();
            foreach (var kvp in this.Counters)
            {
                jw.WritePropertyName(kvp.Key.ToString());
                jw.Write(kvp.Value);
            }
            jw.WriteObjectEnd();
            jw.WriteObjectEnd();
            return(sb.ToString());
        }
Exemplo n.º 32
0
            protected override IEnumerator ExecuteImpl(Gs2Session gs2Session)
            {
                var stringBuilder = new StringBuilder();
                var jsonWriter    = new JsonWriter(stringBuilder);

                jsonWriter.WriteObjectStart();

                if (_request.namespaceName != null)
                {
                    jsonWriter.WritePropertyName("namespaceName");
                    jsonWriter.Write(_request.namespaceName.ToString());
                }
                if (_request.userId != null)
                {
                    jsonWriter.WritePropertyName("userId");
                    jsonWriter.Write(_request.userId.ToString());
                }
                if (_request.jobs != null)
                {
                    jsonWriter.WritePropertyName("jobs");
                    jsonWriter.WriteArrayStart();
                    foreach (var item in _request.jobs)
                    {
                        if (item == null)
                        {
                            jsonWriter.Write(null);
                        }
                        else
                        {
                            item.WriteJson(jsonWriter);
                        }
                    }
                    jsonWriter.WriteArrayEnd();
                }
                if (_request.contextStack != null)
                {
                    jsonWriter.WritePropertyName("contextStack");
                    jsonWriter.Write(_request.contextStack.ToString());
                }
                if (_request.requestId != null)
                {
                    jsonWriter.WritePropertyName("xGs2RequestId");
                    jsonWriter.Write(_request.requestId);
                }
                if (_request.duplicationAvoider != null)
                {
                    jsonWriter.WritePropertyName("xGs2DuplicationAvoider");
                    jsonWriter.Write(_request.duplicationAvoider);
                }

                jsonWriter.WritePropertyName("xGs2ClientId");
                jsonWriter.Write(gs2Session.Credential.ClientId);
                jsonWriter.WritePropertyName("xGs2ProjectToken");
                jsonWriter.Write(gs2Session.ProjectToken);

                jsonWriter.WritePropertyName("x_gs2");
                jsonWriter.WriteObjectStart();
                jsonWriter.WritePropertyName("service");
                jsonWriter.Write("jobQueue");
                jsonWriter.WritePropertyName("component");
                jsonWriter.Write("job");
                jsonWriter.WritePropertyName("function");
                jsonWriter.Write("pushByUserId");
                jsonWriter.WritePropertyName("contentType");
                jsonWriter.Write("application/json");
                jsonWriter.WritePropertyName("requestId");
                jsonWriter.Write(Gs2SessionTaskId.ToString());
                jsonWriter.WriteObjectEnd();

                jsonWriter.WriteObjectEnd();

                ((Gs2WebSocketSession)gs2Session).Send(stringBuilder.ToString());

                return(new EmptyCoroutine());
            }
Exemplo n.º 33
0
        public IRequest Marshall(AddInstanceGroupsRequest publicRequest)
        {
            IRequest request = new DefaultRequest(publicRequest, "Amazon.ElasticMapReduce");
            string   target  = "ElasticMapReduce.AddInstanceGroups";

            request.Headers["X-Amz-Target"] = target;
            request.Headers["Content-Type"] = "application/x-amz-json-1.1";
            request.HttpMethod = "POST";

            string uriResourcePath = "/";

            request.ResourcePath = uriResourcePath;
            using (StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture))
            {
                JsonWriter writer = new JsonWriter(stringWriter);
                writer.WriteObjectStart();
                if (publicRequest.IsSetInstanceGroups())
                {
                    writer.WritePropertyName("InstanceGroups");
                    writer.WriteArrayStart();
                    foreach (var publicRequestInstanceGroupsListValue in publicRequest.InstanceGroups)
                    {
                        writer.WriteObjectStart();
                        if (publicRequestInstanceGroupsListValue.IsSetBidPrice())
                        {
                            writer.WritePropertyName("BidPrice");
                            writer.Write(publicRequestInstanceGroupsListValue.BidPrice);
                        }

                        if (publicRequestInstanceGroupsListValue.IsSetInstanceCount())
                        {
                            writer.WritePropertyName("InstanceCount");
                            writer.Write(publicRequestInstanceGroupsListValue.InstanceCount);
                        }

                        if (publicRequestInstanceGroupsListValue.IsSetInstanceRole())
                        {
                            writer.WritePropertyName("InstanceRole");
                            writer.Write(publicRequestInstanceGroupsListValue.InstanceRole);
                        }

                        if (publicRequestInstanceGroupsListValue.IsSetInstanceType())
                        {
                            writer.WritePropertyName("InstanceType");
                            writer.Write(publicRequestInstanceGroupsListValue.InstanceType);
                        }

                        if (publicRequestInstanceGroupsListValue.IsSetMarket())
                        {
                            writer.WritePropertyName("Market");
                            writer.Write(publicRequestInstanceGroupsListValue.Market);
                        }

                        if (publicRequestInstanceGroupsListValue.IsSetName())
                        {
                            writer.WritePropertyName("Name");
                            writer.Write(publicRequestInstanceGroupsListValue.Name);
                        }

                        writer.WriteObjectEnd();
                    }
                    writer.WriteArrayEnd();
                }

                if (publicRequest.IsSetJobFlowId())
                {
                    writer.WritePropertyName("JobFlowId");
                    writer.Write(publicRequest.JobFlowId);
                }


                writer.WriteObjectEnd();
                string snippet = stringWriter.ToString();
                request.Content = System.Text.Encoding.UTF8.GetBytes(snippet);
            }


            return(request);
        }
Exemplo n.º 34
0
        public IRequest Marshall(CreatePresetRequest publicRequest)
        {
            IRequest request = new DefaultRequest(publicRequest, "Amazon.ElasticTranscoder");

            request.Headers["Content-Type"] = "application/x-amz-json-";
            request.HttpMethod = "POST";

            string uriResourcePath = "/2012-09-25/presets";

            request.ResourcePath = uriResourcePath;
            using (StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture))
            {
                JsonWriter writer = new JsonWriter(stringWriter);
                writer.WriteObjectStart();
                if (publicRequest.IsSetAudio())
                {
                    writer.WritePropertyName("Audio");
                    writer.WriteObjectStart();
                    if (publicRequest.Audio.IsSetBitRate())
                    {
                        writer.WritePropertyName("BitRate");
                        writer.Write(publicRequest.Audio.BitRate);
                    }

                    if (publicRequest.Audio.IsSetChannels())
                    {
                        writer.WritePropertyName("Channels");
                        writer.Write(publicRequest.Audio.Channels);
                    }

                    if (publicRequest.Audio.IsSetCodec())
                    {
                        writer.WritePropertyName("Codec");
                        writer.Write(publicRequest.Audio.Codec);
                    }

                    if (publicRequest.Audio.IsSetCodecOptions())
                    {
                        writer.WritePropertyName("CodecOptions");
                        writer.WriteObjectStart();
                        if (publicRequest.Audio.CodecOptions.IsSetProfile())
                        {
                            writer.WritePropertyName("Profile");
                            writer.Write(publicRequest.Audio.CodecOptions.Profile);
                        }

                        writer.WriteObjectEnd();
                    }

                    if (publicRequest.Audio.IsSetSampleRate())
                    {
                        writer.WritePropertyName("SampleRate");
                        writer.Write(publicRequest.Audio.SampleRate);
                    }

                    writer.WriteObjectEnd();
                }

                if (publicRequest.IsSetContainer())
                {
                    writer.WritePropertyName("Container");
                    writer.Write(publicRequest.Container);
                }

                if (publicRequest.IsSetDescription())
                {
                    writer.WritePropertyName("Description");
                    writer.Write(publicRequest.Description);
                }

                if (publicRequest.IsSetName())
                {
                    writer.WritePropertyName("Name");
                    writer.Write(publicRequest.Name);
                }

                if (publicRequest.IsSetThumbnails())
                {
                    writer.WritePropertyName("Thumbnails");
                    writer.WriteObjectStart();
                    if (publicRequest.Thumbnails.IsSetAspectRatio())
                    {
                        writer.WritePropertyName("AspectRatio");
                        writer.Write(publicRequest.Thumbnails.AspectRatio);
                    }

                    if (publicRequest.Thumbnails.IsSetFormat())
                    {
                        writer.WritePropertyName("Format");
                        writer.Write(publicRequest.Thumbnails.Format);
                    }

                    if (publicRequest.Thumbnails.IsSetInterval())
                    {
                        writer.WritePropertyName("Interval");
                        writer.Write(publicRequest.Thumbnails.Interval);
                    }

                    if (publicRequest.Thumbnails.IsSetMaxHeight())
                    {
                        writer.WritePropertyName("MaxHeight");
                        writer.Write(publicRequest.Thumbnails.MaxHeight);
                    }

                    if (publicRequest.Thumbnails.IsSetMaxWidth())
                    {
                        writer.WritePropertyName("MaxWidth");
                        writer.Write(publicRequest.Thumbnails.MaxWidth);
                    }

                    if (publicRequest.Thumbnails.IsSetPaddingPolicy())
                    {
                        writer.WritePropertyName("PaddingPolicy");
                        writer.Write(publicRequest.Thumbnails.PaddingPolicy);
                    }

                    if (publicRequest.Thumbnails.IsSetResolution())
                    {
                        writer.WritePropertyName("Resolution");
                        writer.Write(publicRequest.Thumbnails.Resolution);
                    }

                    if (publicRequest.Thumbnails.IsSetSizingPolicy())
                    {
                        writer.WritePropertyName("SizingPolicy");
                        writer.Write(publicRequest.Thumbnails.SizingPolicy);
                    }

                    writer.WriteObjectEnd();
                }

                if (publicRequest.IsSetVideo())
                {
                    writer.WritePropertyName("Video");
                    writer.WriteObjectStart();
                    if (publicRequest.Video.IsSetAspectRatio())
                    {
                        writer.WritePropertyName("AspectRatio");
                        writer.Write(publicRequest.Video.AspectRatio);
                    }

                    if (publicRequest.Video.IsSetBitRate())
                    {
                        writer.WritePropertyName("BitRate");
                        writer.Write(publicRequest.Video.BitRate);
                    }

                    if (publicRequest.Video.IsSetCodec())
                    {
                        writer.WritePropertyName("Codec");
                        writer.Write(publicRequest.Video.Codec);
                    }

                    if (publicRequest.Video.IsSetCodecOptions())
                    {
                        writer.WritePropertyName("CodecOptions");
                        writer.WriteObjectStart();
                        foreach (var publicRequestVideoCodecOptionsKvp in publicRequest.Video.CodecOptions)
                        {
                            writer.WritePropertyName(publicRequestVideoCodecOptionsKvp.Key);
                            var publicRequestVideoCodecOptionsValue = publicRequestVideoCodecOptionsKvp.Value;

                            writer.Write(publicRequestVideoCodecOptionsValue);
                        }
                        writer.WriteObjectEnd();
                    }

                    if (publicRequest.Video.IsSetDisplayAspectRatio())
                    {
                        writer.WritePropertyName("DisplayAspectRatio");
                        writer.Write(publicRequest.Video.DisplayAspectRatio);
                    }

                    if (publicRequest.Video.IsSetFixedGOP())
                    {
                        writer.WritePropertyName("FixedGOP");
                        writer.Write(publicRequest.Video.FixedGOP);
                    }

                    if (publicRequest.Video.IsSetFrameRate())
                    {
                        writer.WritePropertyName("FrameRate");
                        writer.Write(publicRequest.Video.FrameRate);
                    }

                    if (publicRequest.Video.IsSetKeyframesMaxDist())
                    {
                        writer.WritePropertyName("KeyframesMaxDist");
                        writer.Write(publicRequest.Video.KeyframesMaxDist);
                    }

                    if (publicRequest.Video.IsSetMaxFrameRate())
                    {
                        writer.WritePropertyName("MaxFrameRate");
                        writer.Write(publicRequest.Video.MaxFrameRate);
                    }

                    if (publicRequest.Video.IsSetMaxHeight())
                    {
                        writer.WritePropertyName("MaxHeight");
                        writer.Write(publicRequest.Video.MaxHeight);
                    }

                    if (publicRequest.Video.IsSetMaxWidth())
                    {
                        writer.WritePropertyName("MaxWidth");
                        writer.Write(publicRequest.Video.MaxWidth);
                    }

                    if (publicRequest.Video.IsSetPaddingPolicy())
                    {
                        writer.WritePropertyName("PaddingPolicy");
                        writer.Write(publicRequest.Video.PaddingPolicy);
                    }

                    if (publicRequest.Video.IsSetResolution())
                    {
                        writer.WritePropertyName("Resolution");
                        writer.Write(publicRequest.Video.Resolution);
                    }

                    if (publicRequest.Video.IsSetSizingPolicy())
                    {
                        writer.WritePropertyName("SizingPolicy");
                        writer.Write(publicRequest.Video.SizingPolicy);
                    }

                    if (publicRequest.Video.IsSetWatermarks())
                    {
                        writer.WritePropertyName("Watermarks");
                        writer.WriteArrayStart();
                        foreach (var publicRequestVideoWatermarksListValue in publicRequest.Video.Watermarks)
                        {
                            writer.WriteObjectStart();
                            if (publicRequestVideoWatermarksListValue.IsSetHorizontalAlign())
                            {
                                writer.WritePropertyName("HorizontalAlign");
                                writer.Write(publicRequestVideoWatermarksListValue.HorizontalAlign);
                            }

                            if (publicRequestVideoWatermarksListValue.IsSetHorizontalOffset())
                            {
                                writer.WritePropertyName("HorizontalOffset");
                                writer.Write(publicRequestVideoWatermarksListValue.HorizontalOffset);
                            }

                            if (publicRequestVideoWatermarksListValue.IsSetId())
                            {
                                writer.WritePropertyName("Id");
                                writer.Write(publicRequestVideoWatermarksListValue.Id);
                            }

                            if (publicRequestVideoWatermarksListValue.IsSetMaxHeight())
                            {
                                writer.WritePropertyName("MaxHeight");
                                writer.Write(publicRequestVideoWatermarksListValue.MaxHeight);
                            }

                            if (publicRequestVideoWatermarksListValue.IsSetMaxWidth())
                            {
                                writer.WritePropertyName("MaxWidth");
                                writer.Write(publicRequestVideoWatermarksListValue.MaxWidth);
                            }

                            if (publicRequestVideoWatermarksListValue.IsSetOpacity())
                            {
                                writer.WritePropertyName("Opacity");
                                writer.Write(publicRequestVideoWatermarksListValue.Opacity);
                            }

                            if (publicRequestVideoWatermarksListValue.IsSetSizingPolicy())
                            {
                                writer.WritePropertyName("SizingPolicy");
                                writer.Write(publicRequestVideoWatermarksListValue.SizingPolicy);
                            }

                            if (publicRequestVideoWatermarksListValue.IsSetTarget())
                            {
                                writer.WritePropertyName("Target");
                                writer.Write(publicRequestVideoWatermarksListValue.Target);
                            }

                            if (publicRequestVideoWatermarksListValue.IsSetVerticalAlign())
                            {
                                writer.WritePropertyName("VerticalAlign");
                                writer.Write(publicRequestVideoWatermarksListValue.VerticalAlign);
                            }

                            if (publicRequestVideoWatermarksListValue.IsSetVerticalOffset())
                            {
                                writer.WritePropertyName("VerticalOffset");
                                writer.Write(publicRequestVideoWatermarksListValue.VerticalOffset);
                            }

                            writer.WriteObjectEnd();
                        }
                        writer.WriteArrayEnd();
                    }

                    writer.WriteObjectEnd();
                }


                writer.WriteObjectEnd();
                string snippet = stringWriter.ToString();
                request.Content = System.Text.Encoding.UTF8.GetBytes(snippet);
            }


            return(request);
        }
        public IRequest Marshall(DescribeLoadBasedAutoScalingRequest describeLoadBasedAutoScalingRequest)
        {
            IRequest request = new DefaultRequest(describeLoadBasedAutoScalingRequest, "AmazonOpsWorks");
            string   target  = "OpsWorks_20130218.DescribeLoadBasedAutoScaling";

            request.Headers["X-Amz-Target"] = target;

            request.Headers["Content-Type"] = "application/x-amz-json-1.1";


            string uriResourcePath = "";

            if (uriResourcePath.Contains("?"))
            {
                int    queryPosition = uriResourcePath.IndexOf("?", StringComparison.OrdinalIgnoreCase);
                string queryString   = uriResourcePath.Substring(queryPosition + 1);
                uriResourcePath = uriResourcePath.Substring(0, queryPosition);

                foreach (string s in queryString.Split('&', ';'))
                {
                    string[] nameValuePair = s.Split('=');
                    if (nameValuePair.Length == 2 && nameValuePair[1].Length > 0)
                    {
                        request.Parameters.Add(nameValuePair[0], nameValuePair[1]);
                    }
                    else
                    {
                        request.Parameters.Add(nameValuePair[0], null);
                    }
                }
            }

            request.ResourcePath = uriResourcePath;


            using (StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture))
            {
                JsonWriter writer = new JsonWriter(stringWriter);
                writer.WriteObjectStart();


                if (describeLoadBasedAutoScalingRequest != null && describeLoadBasedAutoScalingRequest.LayerIds != null && describeLoadBasedAutoScalingRequest.LayerIds.Count > 0)
                {
                    List <string> layerIdsList = describeLoadBasedAutoScalingRequest.LayerIds;
                    writer.WritePropertyName("LayerIds");
                    writer.WriteArrayStart();

                    foreach (string layerIdsListValue in layerIdsList)
                    {
                        writer.Write(StringUtils.FromString(layerIdsListValue));
                    }

                    writer.WriteArrayEnd();
                }

                writer.WriteObjectEnd();

                string snippet = stringWriter.ToString();
                request.Content = System.Text.Encoding.UTF8.GetBytes(snippet);
            }


            return(request);
        }
        public IRequest Marshall(StartWorkflowExecutionRequest startWorkflowExecutionRequest)
        {
            IRequest request = new DefaultRequest(startWorkflowExecutionRequest, "AmazonSimpleWorkflow");
            string   target  = "SimpleWorkflowService.StartWorkflowExecution";

            request.Headers["X-Amz-Target"] = target;

            request.Headers["Content-Type"] = "application/x-amz-json-1.0";

            string uriResourcePath = "";

            request.ResourcePath = uriResourcePath;


            using (StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture))
            {
                JsonWriter writer = new JsonWriter(stringWriter);
                writer.WriteObjectStart();

                if (startWorkflowExecutionRequest != null && startWorkflowExecutionRequest.IsSetDomain())
                {
                    writer.WritePropertyName("domain");
                    writer.Write(startWorkflowExecutionRequest.Domain);
                }
                if (startWorkflowExecutionRequest != null && startWorkflowExecutionRequest.IsSetWorkflowId())
                {
                    writer.WritePropertyName("workflowId");
                    writer.Write(startWorkflowExecutionRequest.WorkflowId);
                }

                if (startWorkflowExecutionRequest != null)
                {
                    WorkflowType workflowType = startWorkflowExecutionRequest.WorkflowType;
                    if (workflowType != null)
                    {
                        writer.WritePropertyName("workflowType");
                        writer.WriteObjectStart();
                        if (workflowType != null && workflowType.IsSetName())
                        {
                            writer.WritePropertyName("name");
                            writer.Write(workflowType.Name);
                        }
                        if (workflowType != null && workflowType.IsSetVersion())
                        {
                            writer.WritePropertyName("version");
                            writer.Write(workflowType.Version);
                        }
                        writer.WriteObjectEnd();
                    }
                }

                if (startWorkflowExecutionRequest != null)
                {
                    TaskList taskList = startWorkflowExecutionRequest.TaskList;
                    if (taskList != null)
                    {
                        writer.WritePropertyName("taskList");
                        writer.WriteObjectStart();
                        if (taskList != null && taskList.IsSetName())
                        {
                            writer.WritePropertyName("name");
                            writer.Write(taskList.Name);
                        }
                        writer.WriteObjectEnd();
                    }
                }
                if (startWorkflowExecutionRequest != null && startWorkflowExecutionRequest.IsSetInput())
                {
                    writer.WritePropertyName("input");
                    writer.Write(startWorkflowExecutionRequest.Input);
                }
                if (startWorkflowExecutionRequest != null && startWorkflowExecutionRequest.IsSetExecutionStartToCloseTimeout())
                {
                    writer.WritePropertyName("executionStartToCloseTimeout");
                    writer.Write(startWorkflowExecutionRequest.ExecutionStartToCloseTimeout);
                }

                if (startWorkflowExecutionRequest != null && startWorkflowExecutionRequest.TagList != null && startWorkflowExecutionRequest.TagList.Count > 0)
                {
                    List <string> tagListList = startWorkflowExecutionRequest.TagList;
                    writer.WritePropertyName("tagList");
                    writer.WriteArrayStart();

                    foreach (string tagListListValue in tagListList)
                    {
                        writer.Write(StringUtils.FromString(tagListListValue));
                    }

                    writer.WriteArrayEnd();
                }
                if (startWorkflowExecutionRequest != null && startWorkflowExecutionRequest.IsSetTaskStartToCloseTimeout())
                {
                    writer.WritePropertyName("taskStartToCloseTimeout");
                    writer.Write(startWorkflowExecutionRequest.TaskStartToCloseTimeout);
                }
                if (startWorkflowExecutionRequest != null && startWorkflowExecutionRequest.IsSetChildPolicy())
                {
                    writer.WritePropertyName("childPolicy");
                    writer.Write(startWorkflowExecutionRequest.ChildPolicy);
                }

                writer.WriteObjectEnd();

                string snippet = stringWriter.ToString();
                request.Content = System.Text.Encoding.UTF8.GetBytes(snippet);
            }


            return(request);
        }
        public IRequest Marshall(DescribeJobFlowsRequest describeJobFlowsRequest)
        {
            IRequest request = new DefaultRequest(describeJobFlowsRequest, "AmazonElasticMapReduce");
            string   target  = "ElasticMapReduce.DescribeJobFlows";

            request.Headers["X-Amz-Target"] = target;
            request.Headers["Content-Type"] = "application/x-amz-json-1.1";



            string uriResourcePath = "";

            if (uriResourcePath.Contains("?"))
            {
                string queryString = uriResourcePath.Substring(uriResourcePath.IndexOf("?") + 1);
                uriResourcePath = uriResourcePath.Substring(0, uriResourcePath.IndexOf("?"));

                foreach (string s in queryString.Split('&', ';'))
                {
                    string[] nameValuePair = s.Split('=');
                    if (nameValuePair.Length == 2 && nameValuePair[1].Length > 0)
                    {
                        request.Parameters.Add(nameValuePair[0], nameValuePair[1]);
                    }
                    else
                    {
                        request.Parameters.Add(nameValuePair[0], null);
                    }
                }
            }

            request.ResourcePath = uriResourcePath;


            using (StringWriter stringWriter = new StringWriter())
            {
                JsonWriter writer = new JsonWriter(stringWriter);
                writer.WriteObjectStart();

                if (describeJobFlowsRequest != null && describeJobFlowsRequest.IsSetCreatedAfter())
                {
                    writer.WritePropertyName("CreatedAfter");
                    writer.Write(describeJobFlowsRequest.CreatedAfter);
                }
                if (describeJobFlowsRequest != null && describeJobFlowsRequest.IsSetCreatedBefore())
                {
                    writer.WritePropertyName("CreatedBefore");
                    writer.Write(describeJobFlowsRequest.CreatedBefore);
                }

                if (describeJobFlowsRequest != null && describeJobFlowsRequest.JobFlowIds != null && describeJobFlowsRequest.JobFlowIds.Count > 0)
                {
                    List <string> jobFlowIdsList = describeJobFlowsRequest.JobFlowIds;
                    writer.WritePropertyName("JobFlowIds");
                    writer.WriteArrayStart();

                    foreach (string jobFlowIdsListValue in jobFlowIdsList)
                    {
                        writer.Write(StringUtils.FromString(jobFlowIdsListValue));
                    }

                    writer.WriteArrayEnd();
                }

                if (describeJobFlowsRequest != null && describeJobFlowsRequest.JobFlowStates != null && describeJobFlowsRequest.JobFlowStates.Count > 0)
                {
                    List <string> jobFlowStatesList = describeJobFlowsRequest.JobFlowStates;
                    writer.WritePropertyName("JobFlowStates");
                    writer.WriteArrayStart();

                    foreach (string jobFlowStatesListValue in jobFlowStatesList)
                    {
                        writer.Write(StringUtils.FromString(jobFlowStatesListValue));
                    }

                    writer.WriteArrayEnd();
                }

                writer.WriteObjectEnd();

                string snippet = stringWriter.ToString();
                request.Content = System.Text.Encoding.UTF8.GetBytes(snippet);
            }


            return(request);
        }
        public IRequest Marshall(DescribeTapesRequest describeTapesRequest)
        {
            IRequest request = new DefaultRequest(describeTapesRequest, "AmazonStorageGateway");
            string   target  = "StorageGateway_20130630.DescribeTapes";

            request.Headers["X-Amz-Target"] = target;

            request.Headers["Content-Type"] = "application/x-amz-json-1.1";


            string uriResourcePath = "";

            if (uriResourcePath.Contains("?"))
            {
                int    queryPosition = uriResourcePath.IndexOf("?", StringComparison.OrdinalIgnoreCase);
                string queryString   = uriResourcePath.Substring(queryPosition + 1);
                uriResourcePath = uriResourcePath.Substring(0, queryPosition);

                foreach (string s in queryString.Split('&', ';'))
                {
                    string[] nameValuePair = s.Split('=');
                    if (nameValuePair.Length == 2 && nameValuePair[1].Length > 0)
                    {
                        request.Parameters.Add(nameValuePair[0], nameValuePair[1]);
                    }
                    else
                    {
                        request.Parameters.Add(nameValuePair[0], null);
                    }
                }
            }

            request.ResourcePath = uriResourcePath;


            using (StringWriter stringWriter = new StringWriter(System.Globalization.CultureInfo.InvariantCulture))
            {
                JsonWriter writer = new JsonWriter(stringWriter);
                writer.WriteObjectStart();

                if (describeTapesRequest != null && describeTapesRequest.IsSetGatewayARN())
                {
                    writer.WritePropertyName("GatewayARN");
                    writer.Write(describeTapesRequest.GatewayARN);
                }

                if (describeTapesRequest != null && describeTapesRequest.TapeARNs != null && describeTapesRequest.TapeARNs.Count > 0)
                {
                    List <string> tapeARNsList = describeTapesRequest.TapeARNs;
                    writer.WritePropertyName("TapeARNs");
                    writer.WriteArrayStart();

                    foreach (string tapeARNsListValue in tapeARNsList)
                    {
                        writer.Write(StringUtils.FromString(tapeARNsListValue));
                    }

                    writer.WriteArrayEnd();
                }
                if (describeTapesRequest != null && describeTapesRequest.IsSetMarker())
                {
                    writer.WritePropertyName("Marker");
                    writer.Write(describeTapesRequest.Marker);
                }
                if (describeTapesRequest != null && describeTapesRequest.IsSetLimit())
                {
                    writer.WritePropertyName("Limit");
                    writer.Write(describeTapesRequest.Limit);
                }

                writer.WriteObjectEnd();

                string snippet = stringWriter.ToString();
                request.Content = System.Text.Encoding.UTF8.GetBytes(snippet);
            }


            return(request);
        }
        public IRequest Marshall(QueryRequest queryRequest)
        {
            IRequest request = new DefaultRequest(queryRequest, "AmazonDynamoDBv2");
            string   target  = "DynamoDB_20120810.Query";

            request.Headers["X-Amz-Target"] = target;

            request.Headers["Content-Type"] = "application/x-amz-json-1.0";


            string uriResourcePath = "";

            if (uriResourcePath.Contains("?"))
            {
                int    queryPosition = uriResourcePath.IndexOf("?", StringComparison.OrdinalIgnoreCase);
                string queryString   = uriResourcePath.Substring(queryPosition + 1);
                uriResourcePath = uriResourcePath.Substring(0, queryPosition);

                foreach (string s in queryString.Split('&', ';'))
                {
                    string[] nameValuePair = s.Split('=');
                    if (nameValuePair.Length == 2 && nameValuePair[1].Length > 0)
                    {
                        request.Parameters.Add(nameValuePair[0], nameValuePair[1]);
                    }
                    else
                    {
                        request.Parameters.Add(nameValuePair[0], null);
                    }
                }
            }

            request.ResourcePath = uriResourcePath;


            using (StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture))
            {
                JsonWriter writer = new JsonWriter(stringWriter);
                writer.WriteObjectStart();

                if (queryRequest != null && queryRequest.IsSetTableName())
                {
                    writer.WritePropertyName("TableName");
                    writer.Write(queryRequest.TableName);
                }
                if (queryRequest != null && queryRequest.IsSetIndexName())
                {
                    writer.WritePropertyName("IndexName");
                    writer.Write(queryRequest.IndexName);
                }
                if (queryRequest != null && queryRequest.IsSetSelect())
                {
                    writer.WritePropertyName("Select");
                    writer.Write(queryRequest.Select);
                }

                if (queryRequest != null && queryRequest.AttributesToGet != null && queryRequest.AttributesToGet.Count > 0)
                {
                    List <string> attributesToGetList = queryRequest.AttributesToGet;
                    writer.WritePropertyName("AttributesToGet");
                    writer.WriteArrayStart();

                    foreach (string attributesToGetListValue in attributesToGetList)
                    {
                        writer.Write(StringUtils.FromString(attributesToGetListValue));
                    }

                    writer.WriteArrayEnd();
                }
                if (queryRequest != null && queryRequest.IsSetLimit())
                {
                    writer.WritePropertyName("Limit");
                    writer.Write(queryRequest.Limit);
                }
                if (queryRequest != null && queryRequest.IsSetConsistentRead())
                {
                    writer.WritePropertyName("ConsistentRead");
                    writer.Write(queryRequest.ConsistentRead);
                }
                if (queryRequest != null)
                {
                    if (queryRequest.KeyConditions != null && queryRequest.KeyConditions.Count > 0)
                    {
                        writer.WritePropertyName("KeyConditions");
                        writer.WriteObjectStart();
                        foreach (string queryRequestKeyConditionsKey in queryRequest.KeyConditions.Keys)
                        {
                            Condition keyConditionsListValue;
                            bool      keyConditionsListValueHasValue = queryRequest.KeyConditions.TryGetValue(queryRequestKeyConditionsKey, out keyConditionsListValue);
                            writer.WritePropertyName(queryRequestKeyConditionsKey);

                            writer.WriteObjectStart();

                            if (keyConditionsListValue != null && keyConditionsListValue.AttributeValueList != null && keyConditionsListValue.AttributeValueList.Count > 0)
                            {
                                List <AttributeValue> attributeValueListList = keyConditionsListValue.AttributeValueList;
                                writer.WritePropertyName("AttributeValueList");
                                writer.WriteArrayStart();

                                foreach (AttributeValue attributeValueListListValue in attributeValueListList)
                                {
                                    writer.WriteObjectStart();
                                    if (attributeValueListListValue != null && attributeValueListListValue.IsSetS())
                                    {
                                        writer.WritePropertyName("S");
                                        writer.Write(attributeValueListListValue.S);
                                    }
                                    if (attributeValueListListValue != null && attributeValueListListValue.IsSetN())
                                    {
                                        writer.WritePropertyName("N");
                                        writer.Write(attributeValueListListValue.N);
                                    }
                                    if (attributeValueListListValue != null && attributeValueListListValue.IsSetB())
                                    {
                                        writer.WritePropertyName("B");
                                        writer.Write(StringUtils.FromMemoryStream(attributeValueListListValue.B));
                                    }

                                    if (attributeValueListListValue != null && attributeValueListListValue.SS != null && attributeValueListListValue.SS.Count > 0)
                                    {
                                        List <string> sSList = attributeValueListListValue.SS;
                                        writer.WritePropertyName("SS");
                                        writer.WriteArrayStart();

                                        foreach (string sSListValue in sSList)
                                        {
                                            writer.Write(StringUtils.FromString(sSListValue));
                                        }

                                        writer.WriteArrayEnd();
                                    }

                                    if (attributeValueListListValue != null && attributeValueListListValue.NS != null && attributeValueListListValue.NS.Count > 0)
                                    {
                                        List <string> nSList = attributeValueListListValue.NS;
                                        writer.WritePropertyName("NS");
                                        writer.WriteArrayStart();

                                        foreach (string nSListValue in nSList)
                                        {
                                            writer.Write(StringUtils.FromString(nSListValue));
                                        }

                                        writer.WriteArrayEnd();
                                    }

                                    if (attributeValueListListValue != null && attributeValueListListValue.BS != null && attributeValueListListValue.BS.Count > 0)
                                    {
                                        List <MemoryStream> bSList = attributeValueListListValue.BS;
                                        writer.WritePropertyName("BS");
                                        writer.WriteArrayStart();

                                        foreach (MemoryStream bSListValue in bSList)
                                        {
                                            writer.Write(StringUtils.FromMemoryStream(bSListValue));
                                        }

                                        writer.WriteArrayEnd();
                                    }
                                    writer.WriteObjectEnd();
                                }
                                writer.WriteArrayEnd();
                            }
                            if (keyConditionsListValue != null && keyConditionsListValue.IsSetComparisonOperator())
                            {
                                writer.WritePropertyName("ComparisonOperator");
                                writer.Write(keyConditionsListValue.ComparisonOperator);
                            }
                            writer.WriteObjectEnd();
                        }
                        writer.WriteObjectEnd();
                    }
                }
                if (queryRequest != null && queryRequest.IsSetScanIndexForward())
                {
                    writer.WritePropertyName("ScanIndexForward");
                    writer.Write(queryRequest.ScanIndexForward);
                }
                if (queryRequest != null)
                {
                    if (queryRequest.ExclusiveStartKey != null && queryRequest.ExclusiveStartKey.Count > 0)
                    {
                        writer.WritePropertyName("ExclusiveStartKey");
                        writer.WriteObjectStart();
                        foreach (string queryRequestExclusiveStartKeyKey in queryRequest.ExclusiveStartKey.Keys)
                        {
                            AttributeValue exclusiveStartKeyListValue;
                            bool           exclusiveStartKeyListValueHasValue = queryRequest.ExclusiveStartKey.TryGetValue(queryRequestExclusiveStartKeyKey, out exclusiveStartKeyListValue);
                            writer.WritePropertyName(queryRequestExclusiveStartKeyKey);

                            writer.WriteObjectStart();
                            if (exclusiveStartKeyListValue != null && exclusiveStartKeyListValue.IsSetS())
                            {
                                writer.WritePropertyName("S");
                                writer.Write(exclusiveStartKeyListValue.S);
                            }
                            if (exclusiveStartKeyListValue != null && exclusiveStartKeyListValue.IsSetN())
                            {
                                writer.WritePropertyName("N");
                                writer.Write(exclusiveStartKeyListValue.N);
                            }
                            if (exclusiveStartKeyListValue != null && exclusiveStartKeyListValue.IsSetB())
                            {
                                writer.WritePropertyName("B");
                                writer.Write(StringUtils.FromMemoryStream(exclusiveStartKeyListValue.B));
                            }

                            if (exclusiveStartKeyListValue != null && exclusiveStartKeyListValue.SS != null && exclusiveStartKeyListValue.SS.Count > 0)
                            {
                                List <string> sSList = exclusiveStartKeyListValue.SS;
                                writer.WritePropertyName("SS");
                                writer.WriteArrayStart();

                                foreach (string sSListValue in sSList)
                                {
                                    writer.Write(StringUtils.FromString(sSListValue));
                                }

                                writer.WriteArrayEnd();
                            }

                            if (exclusiveStartKeyListValue != null && exclusiveStartKeyListValue.NS != null && exclusiveStartKeyListValue.NS.Count > 0)
                            {
                                List <string> nSList = exclusiveStartKeyListValue.NS;
                                writer.WritePropertyName("NS");
                                writer.WriteArrayStart();

                                foreach (string nSListValue in nSList)
                                {
                                    writer.Write(StringUtils.FromString(nSListValue));
                                }

                                writer.WriteArrayEnd();
                            }

                            if (exclusiveStartKeyListValue != null && exclusiveStartKeyListValue.BS != null && exclusiveStartKeyListValue.BS.Count > 0)
                            {
                                List <MemoryStream> bSList = exclusiveStartKeyListValue.BS;
                                writer.WritePropertyName("BS");
                                writer.WriteArrayStart();

                                foreach (MemoryStream bSListValue in bSList)
                                {
                                    writer.Write(StringUtils.FromMemoryStream(bSListValue));
                                }

                                writer.WriteArrayEnd();
                            }
                            writer.WriteObjectEnd();
                        }
                        writer.WriteObjectEnd();
                    }
                }
                if (queryRequest != null && queryRequest.IsSetReturnConsumedCapacity())
                {
                    writer.WritePropertyName("ReturnConsumedCapacity");
                    writer.Write(queryRequest.ReturnConsumedCapacity);
                }

                writer.WriteObjectEnd();

                string snippet = stringWriter.ToString();
                request.Content = System.Text.Encoding.UTF8.GetBytes(snippet);
            }


            return(request);
        }
Exemplo n.º 40
0
        public static ReplayData Parse(ReplayDetail detail)
        {
            var w = new JsonWriter();

            w.WriteObjectStart();
            w.WritePropertyName("battle_id");
            w.Write(detail.battle_id);
            w.WritePropertyName("seed");
            w.Write(detail.seed);
            w.WritePropertyName("field_id");
            w.Write(detail.field_id);
            w.WritePropertyName("first_turn");
            w.Write(detail.first_turn);

            w.WritePropertyName("play_list");
            w.WriteObjectStart();
            foreach (var key in detail.play_list.Keys)
            {
                if (detail.play_list[key].GetType() == typeof(string))
                {
                    w.WritePropertyName(key);
                    w.Write(detail.play_list[key] as string);
                }
                else
                {
                    w.WritePropertyName(key);
                    w.WriteArrayStart();
                    var list = detail.play_list[key] as List <object>;
                    foreach (Dictionary <string, object> item in list)
                    {
                        w.WriteObjectStart();
                        foreach (var k in item.Keys)
                        {
                            if (item[k].GetType() == typeof(JsonData))
                            {
                                w.WritePropertyName(k);
                                var d = item[k] as JsonData;
                                switch (d.GetJsonType())
                                {
                                case JsonType.Int:
                                    w.Write(d.ToInt());
                                    break;

                                case JsonType.Long:
                                    w.Write(d.ToLong());
                                    break;

                                case JsonType.Double:
                                    w.Write(d.ToDouble());
                                    break;

                                case JsonType.Boolean:
                                    w.Write(d.ToBoolean());
                                    break;

                                default:
                                    w.Write(d.ToString());
                                    break;
                                }
                            }
                            else
                            {
                                w.WritePropertyName(k);
                                w.WriteArrayStart();
                                var l = item[k] as List <object>;
                                foreach (Dictionary <string, object> i in l)
                                {
                                    w.WriteObjectStart();

                                    foreach (var k2 in i.Keys)
                                    {
                                        w.WritePropertyName(k2);
                                        var d = i[k2] as JsonData;
                                        switch (d.GetJsonType())
                                        {
                                        case JsonType.Int:
                                            w.Write(d.ToInt());
                                            break;

                                        case JsonType.Long:
                                            w.Write(d.ToLong());
                                            break;

                                        case JsonType.Double:
                                            w.Write(d.ToDouble());
                                            break;

                                        case JsonType.Boolean:
                                            w.Write(d.ToBoolean());
                                            break;

                                        default:
                                            w.Write(d.ToString());
                                            break;
                                        }
                                    }
                                    w.WriteObjectEnd();
                                }
                                w.WriteArrayEnd();
                            }
                        }
                        w.WriteObjectEnd();
                    }
                    w.WriteArrayEnd();
                }
            }
            w.WriteObjectEnd();

            w.WritePropertyName("viewer_id");
            w.Write(detail.viewer_id);
            w.WritePropertyName("name");
            w.Write(detail.name);
            w.WritePropertyName("chara_id");
            w.Write(detail.chara_id);
            w.WritePropertyName("emblem_id");
            w.Write(detail.emblem_id);
            w.WritePropertyName("degree_id");
            w.Write(detail.degree_id);
            w.WritePropertyName("country_code");
            w.Write(detail.country_code);
            w.WritePropertyName("sleeve_id");
            w.Write(detail.sleeve_id);
            w.WritePropertyName("battle_point");
            w.Write(detail.battle_point);
            w.WritePropertyName("master_point");
            w.Write(detail.master_point);
            w.WritePropertyName("rank");
            w.Write(detail.rank);

            w.WritePropertyName("deck");
            w.WriteArrayStart();
            foreach (Dictionary <string, object> item in detail.deck)
            {
                w.WriteObjectStart();
                w.WritePropertyName("idx");
                w.Write(item["idx"] as string);
                w.WritePropertyName("card_id");
                w.Write(item["card_id"] as string);
                w.WriteObjectEnd();
            }
            w.WriteArrayEnd();

            w.WritePropertyName("opponent_viewer_id");
            w.Write(detail.opponent_viewer_id);
            w.WritePropertyName("opponent_name");
            w.Write(detail.opponent_name);
            w.WritePropertyName("opponent_chara_id");
            w.Write(detail.opponent_chara_id);
            w.WritePropertyName("opponent_emblem_id");
            w.Write(detail.opponent_emblem_id);
            w.WritePropertyName("opponent_degree_id");
            w.Write(detail.opponent_degree_id);
            w.WritePropertyName("opponent_country_code");
            w.Write(detail.opponent_country_code);
            w.WritePropertyName("opponent_sleeve_id");
            w.Write(detail.opponent_sleeve_id);
            w.WritePropertyName("opponent_battle_point");
            w.Write(detail.opponent_battle_point);
            w.WritePropertyName("opponent_master_point");
            w.Write(detail.opponent_master_point);
            w.WritePropertyName("opponent_rank");
            w.Write(detail.opponent_rank);

            w.WritePropertyName("opponent_deck");
            w.WriteArrayStart();
            foreach (Dictionary <string, object> item in detail.opponent_deck)
            {
                w.WriteObjectStart();
                w.WritePropertyName("idx");
                w.Write(item["idx"] as string);
                w.WritePropertyName("card_id");
                w.Write(item["card_id"] as string);
                w.WriteObjectEnd();
            }
            w.WriteArrayEnd();

            w.WritePropertyName("is_two_pick");
            w.Write(detail.is_two_pick);
            w.WritePropertyName("is_win");
            w.Write(detail.is_win);

            w.WriteObjectEnd();

            return(new ReplayData
            {
                Data = JsonMapper.ToObject(w.ToString())
            });
        }
Exemplo n.º 41
0
    //保存所有修改后的值
    void SaveValueChange()
    {
        //文件输出流
        StreamWriter file = File.CreateText(s_FilePath);

        JsonWriter writer = new JsonWriter(file);

        writer.WriteArrayStart();
        for (int i = 0; i < SoundValue.Length; i++)
        {
            JsonMapper.ToJson(SoundValue[i], writer);
        }
        writer.WriteArrayEnd();

        file.Close();
    }
Exemplo n.º 42
0
    void WriteJsonToFile(string path, string fileName)
    {
        System.Text.StringBuilder strB = new System.Text.StringBuilder();
        JsonWriter jsWrite = new JsonWriter(strB);
        jsWrite.WriteObjectStart();
        jsWrite.WritePropertyName("Monster");

        jsWrite.WriteArrayStart();

        jsWrite.WriteObjectStart();
        jsWrite.WritePropertyName("MonsterName");
        jsWrite.Write("Person");
        jsWrite.WritePropertyName("attack");
        jsWrite.Write(10);
        jsWrite.WritePropertyName("defense");
        jsWrite.Write(10);
        jsWrite.WritePropertyName("weapon");
        jsWrite.Write("Sword");
        jsWrite.WriteObjectEnd();
        jsWrite.WriteObjectStart();
        jsWrite.WritePropertyName("MonsterName");
        jsWrite.Write("Animal");
        jsWrite.WritePropertyName("attack");
        jsWrite.Write(8);
        jsWrite.WritePropertyName("defense");
        jsWrite.Write(15);
        jsWrite.WritePropertyName("weapon");
        jsWrite.Write("tooth");
        jsWrite.WriteObjectEnd();
        jsWrite.WriteObjectStart();
        jsWrite.WritePropertyName("MonsterName");
        jsWrite.Write("Dragon");
        jsWrite.WritePropertyName("attack");
        jsWrite.Write(100);
        jsWrite.WritePropertyName("defense");
        jsWrite.Write(200);
        jsWrite.WritePropertyName("weapon");
        jsWrite.Write("fire breath");
        jsWrite.WriteObjectEnd();

        jsWrite.WriteArrayEnd();
        jsWrite.WriteObjectEnd();
        Debug.Log(strB);
        //创建文件目录
        DirectoryInfo dir = new DirectoryInfo(path);
        if (dir.Exists)
        {
            Debug.Log("This file is already exists");
        }
        else
        {
            Directory.CreateDirectory(path);
            Debug.Log("CreateFile");
        #if UNITY_EDITOR
            AssetDatabase.Refresh();
        #endif
        }
        //把json数据写到txt里
        StreamWriter sw;
        if (File.Exists(fileName))
        {
            //如果文件存在,那么就向文件继续附加(为了下次写内容不会覆盖上次的内容)
            sw = File.AppendText(fileName);
            Debug.Log("appendText");
        }
        else
        {
            //如果文件不存在则创建文件
            sw = File.CreateText(fileName);
            Debug.Log("createText");
        }
        sw.WriteLine(strB);
        sw.Close();
        #if UNITY_EDITOR
        AssetDatabase.Refresh();
        #endif
    }
Exemplo n.º 43
0
        /// <summary>
        /// Export the build graph to a Json file, for parallel execution by the build system
        /// </summary>
        /// <param name="File">Output file to write</param>
        /// <param name="Trigger">The trigger whose nodes to run. Null for the default nodes.</param>
        /// <param name="CompletedNodes">Set of nodes which have been completed</param>
        public void Export(FileReference File, ManualTrigger Trigger, HashSet <Node> CompletedNodes)
        {
            // Find all the nodes which we're actually going to execute. We'll use this to filter the graph.
            HashSet <Node> NodesToExecute = new HashSet <Node>();

            foreach (Node Node in Agents.SelectMany(x => x.Nodes))
            {
                if (!CompletedNodes.Contains(Node) && Node.IsBehind(Trigger))
                {
                    NodesToExecute.Add(Node);
                }
            }

            // Open the output file
            using (JsonWriter JsonWriter = new JsonWriter(File.FullName))
            {
                JsonWriter.WriteObjectStart();

                // Write all the agents
                JsonWriter.WriteArrayStart("Groups");
                foreach (Agent Agent in Agents)
                {
                    Node[] Nodes = Agent.Nodes.Where(x => NodesToExecute.Contains(x) && x.ControllingTrigger == Trigger).ToArray();
                    if (Nodes.Length > 0)
                    {
                        JsonWriter.WriteObjectStart();
                        JsonWriter.WriteValue("Name", Agent.Name);
                        JsonWriter.WriteArrayStart("Agent Types");
                        foreach (string AgentType in Agent.PossibleTypes)
                        {
                            JsonWriter.WriteValue(AgentType);
                        }
                        JsonWriter.WriteArrayEnd();
                        JsonWriter.WriteArrayStart("Nodes");
                        foreach (Node Node in Nodes)
                        {
                            JsonWriter.WriteObjectStart();
                            JsonWriter.WriteValue("Name", Node.Name);
                            JsonWriter.WriteValue("DependsOn", String.Join(";", Node.GetDirectOrderDependencies().Where(x => NodesToExecute.Contains(x) && x.ControllingTrigger == Trigger)));
                            JsonWriter.WriteObjectStart("Notify");
                            JsonWriter.WriteValue("Default", String.Join(";", Node.NotifyUsers));
                            JsonWriter.WriteValue("Submitters", String.Join(";", Node.NotifySubmitters));
                            JsonWriter.WriteValue("Warnings", Node.bNotifyOnWarnings);
                            JsonWriter.WriteObjectEnd();
                            JsonWriter.WriteObjectEnd();
                        }
                        JsonWriter.WriteArrayEnd();
                        JsonWriter.WriteObjectEnd();
                    }
                }
                JsonWriter.WriteArrayEnd();

                // Write all the badges
                JsonWriter.WriteArrayStart("Badges");
                foreach (Badge Badge in Badges)
                {
                    Node[] Dependencies = Badge.Nodes.Where(x => NodesToExecute.Contains(x) && x.ControllingTrigger == Trigger).ToArray();
                    if (Dependencies.Length > 0)
                    {
                        // Reduce that list to the smallest subset of direct dependencies
                        HashSet <Node> DirectDependencies = new HashSet <Node>(Dependencies);
                        foreach (Node Dependency in Dependencies)
                        {
                            DirectDependencies.ExceptWith(Dependency.OrderDependencies);
                        }

                        JsonWriter.WriteObjectStart();
                        JsonWriter.WriteValue("Name", Badge.Name);
                        if (!String.IsNullOrEmpty(Badge.Project))
                        {
                            JsonWriter.WriteValue("Project", Badge.Project);
                        }
                        if (Badge.Change != 0)
                        {
                            JsonWriter.WriteValue("Change", Badge.Change);
                        }
                        JsonWriter.WriteValue("AllDependencies", String.Join(";", Agents.SelectMany(x => x.Nodes).Where(x => Dependencies.Contains(x)).Select(x => x.Name)));
                        JsonWriter.WriteValue("DirectDependencies", String.Join(";", DirectDependencies.Select(x => x.Name)));
                        JsonWriter.WriteObjectEnd();
                    }
                }
                JsonWriter.WriteArrayEnd();

                // Write all the triggers and reports.
                JsonWriter.WriteArrayStart("Reports");
                foreach (Report Report in NameToReport.Values)
                {
                    Node[] Dependencies = Report.Nodes.Where(x => NodesToExecute.Contains(x) && x.ControllingTrigger == Trigger).ToArray();
                    if (Dependencies.Length > 0)
                    {
                        // Reduce that list to the smallest subset of direct dependencies
                        HashSet <Node> DirectDependencies = new HashSet <Node>(Dependencies);
                        foreach (Node Dependency in Dependencies)
                        {
                            DirectDependencies.ExceptWith(Dependency.OrderDependencies);
                        }

                        JsonWriter.WriteObjectStart();
                        JsonWriter.WriteValue("Name", Report.Name);
                        JsonWriter.WriteValue("AllDependencies", String.Join(";", Agents.SelectMany(x => x.Nodes).Where(x => Dependencies.Contains(x)).Select(x => x.Name)));
                        JsonWriter.WriteValue("DirectDependencies", String.Join(";", DirectDependencies.Select(x => x.Name)));
                        JsonWriter.WriteValue("Notify", String.Join(";", Report.NotifyUsers));
                        JsonWriter.WriteValue("IsTrigger", false);
                        JsonWriter.WriteObjectEnd();
                    }
                }
                foreach (ManualTrigger DownstreamTrigger in NameToTrigger.Values)
                {
                    if (DownstreamTrigger.Parent == Trigger)
                    {
                        // Find all the nodes that this trigger is dependent on
                        HashSet <Node> Dependencies = new HashSet <Node>();
                        foreach (Node NodeToExecute in NodesToExecute)
                        {
                            if (NodeToExecute.IsBehind(DownstreamTrigger))
                            {
                                Dependencies.UnionWith(NodeToExecute.OrderDependencies.Where(x => x.ControllingTrigger == Trigger));
                            }
                        }

                        // Reduce that list to the smallest subset of direct dependencies
                        HashSet <Node> DirectDependencies = new HashSet <Node>(Dependencies);
                        foreach (Node Dependency in Dependencies)
                        {
                            DirectDependencies.ExceptWith(Dependency.OrderDependencies);
                        }

                        // Write out the object
                        JsonWriter.WriteObjectStart();
                        JsonWriter.WriteValue("Name", DownstreamTrigger.Name);
                        JsonWriter.WriteValue("AllDependencies", String.Join(";", Agents.SelectMany(x => x.Nodes).Where(x => Dependencies.Contains(x)).Select(x => x.Name)));
                        JsonWriter.WriteValue("DirectDependencies", String.Join(";", Dependencies.Where(x => DirectDependencies.Contains(x)).Select(x => x.Name)));
                        JsonWriter.WriteValue("Notify", String.Join(";", DownstreamTrigger.NotifyUsers));
                        JsonWriter.WriteValue("IsTrigger", true);
                        JsonWriter.WriteObjectEnd();
                    }
                }
                JsonWriter.WriteArrayEnd();

                JsonWriter.WriteObjectEnd();
            }
        }
Exemplo n.º 44
0
 void WriteJsonAndPrint()
 {
     System.Text.StringBuilder strB = new System.Text.StringBuilder();
     JsonWriter jsWrite = new JsonWriter(strB);
     jsWrite.WriteObjectStart();
     jsWrite.WritePropertyName("Name");
     jsWrite.Write("taotao");
     jsWrite.WritePropertyName("Age");
     jsWrite.Write(25);
     jsWrite.WritePropertyName("MM");
     jsWrite.WriteArrayStart();
     jsWrite.WriteObjectStart();
     jsWrite.WritePropertyName("name");
     jsWrite.Write("xiaomei");
     jsWrite.WritePropertyName("age");
     jsWrite.Write("17");
     jsWrite.WriteObjectEnd();
     jsWrite.WriteObjectStart();
     jsWrite.WritePropertyName("name");
     jsWrite.Write("xiaoli");
     jsWrite.WritePropertyName("age");
     jsWrite.Write("18");
     jsWrite.WriteObjectEnd();
     jsWrite.WriteArrayEnd();
     jsWrite.WriteObjectEnd();
     Debug.Log(strB);
     JsonData jd = JsonMapper.ToObject(strB.ToString());
     Debug.Log("name=" + jd["Name"]);
     Debug.Log("age=" + jd["Age"]);
     JsonData jdItems = jd["MM"];
     for (int i = 0; i < jdItems.Count; i++)
     {
         Debug.Log("MM name=" + jdItems["name"]);
         Debug.Log("MM age=" + jdItems["age"]);
     }
 }
Exemplo n.º 45
0
        public IRequest Marshall(AllocatePublicVirtualInterfaceRequest allocatePublicVirtualInterfaceRequest)
        {
            IRequest request = new DefaultRequest(allocatePublicVirtualInterfaceRequest, "AmazonDirectConnect");
            string   target  = "OvertureService.AllocatePublicVirtualInterface";

            request.Headers["X-Amz-Target"] = target;
            request.Headers["Content-Type"] = "application/x-amz-json-1.1";



            string uriResourcePath = "";

            if (uriResourcePath.Contains("?"))
            {
                string queryString = uriResourcePath.Substring(uriResourcePath.IndexOf("?") + 1);
                uriResourcePath = uriResourcePath.Substring(0, uriResourcePath.IndexOf("?"));

                foreach (string s in queryString.Split('&', ';'))
                {
                    string[] nameValuePair = s.Split('=');
                    if (nameValuePair.Length == 2 && nameValuePair[1].Length > 0)
                    {
                        request.Parameters.Add(nameValuePair[0], nameValuePair[1]);
                    }
                    else
                    {
                        request.Parameters.Add(nameValuePair[0], null);
                    }
                }
            }

            request.ResourcePath = uriResourcePath;


            using (StringWriter stringWriter = new StringWriter())
            {
                JsonWriter writer = new JsonWriter(stringWriter);
                writer.WriteObjectStart();

                if (allocatePublicVirtualInterfaceRequest != null && allocatePublicVirtualInterfaceRequest.IsSetConnectionId())
                {
                    writer.WritePropertyName("connectionId");
                    writer.Write(allocatePublicVirtualInterfaceRequest.ConnectionId);
                }
                if (allocatePublicVirtualInterfaceRequest != null && allocatePublicVirtualInterfaceRequest.IsSetOwnerAccount())
                {
                    writer.WritePropertyName("ownerAccount");
                    writer.Write(allocatePublicVirtualInterfaceRequest.OwnerAccount);
                }

                if (allocatePublicVirtualInterfaceRequest != null)
                {
                    NewPublicVirtualInterfaceAllocation newPublicVirtualInterfaceAllocation = allocatePublicVirtualInterfaceRequest.NewPublicVirtualInterfaceAllocation;
                    if (newPublicVirtualInterfaceAllocation != null)
                    {
                        writer.WritePropertyName("newPublicVirtualInterfaceAllocation");
                        writer.WriteObjectStart();
                        if (newPublicVirtualInterfaceAllocation != null && newPublicVirtualInterfaceAllocation.IsSetVirtualInterfaceName())
                        {
                            writer.WritePropertyName("virtualInterfaceName");
                            writer.Write(newPublicVirtualInterfaceAllocation.VirtualInterfaceName);
                        }
                        if (newPublicVirtualInterfaceAllocation != null && newPublicVirtualInterfaceAllocation.IsSetVlan())
                        {
                            writer.WritePropertyName("vlan");
                            writer.Write(newPublicVirtualInterfaceAllocation.Vlan);
                        }
                        if (newPublicVirtualInterfaceAllocation != null && newPublicVirtualInterfaceAllocation.IsSetAsn())
                        {
                            writer.WritePropertyName("asn");
                            writer.Write(newPublicVirtualInterfaceAllocation.Asn);
                        }
                        if (newPublicVirtualInterfaceAllocation != null && newPublicVirtualInterfaceAllocation.IsSetAuthKey())
                        {
                            writer.WritePropertyName("authKey");
                            writer.Write(newPublicVirtualInterfaceAllocation.AuthKey);
                        }
                        if (newPublicVirtualInterfaceAllocation != null && newPublicVirtualInterfaceAllocation.IsSetAmazonAddress())
                        {
                            writer.WritePropertyName("amazonAddress");
                            writer.Write(newPublicVirtualInterfaceAllocation.AmazonAddress);
                        }
                        if (newPublicVirtualInterfaceAllocation != null && newPublicVirtualInterfaceAllocation.IsSetCustomerAddress())
                        {
                            writer.WritePropertyName("customerAddress");
                            writer.Write(newPublicVirtualInterfaceAllocation.CustomerAddress);
                        }

                        if (newPublicVirtualInterfaceAllocation != null && newPublicVirtualInterfaceAllocation.RouteFilterPrefixes != null && newPublicVirtualInterfaceAllocation.RouteFilterPrefixes.Count > 0)
                        {
                            List <RouteFilterPrefix> routeFilterPrefixesList = newPublicVirtualInterfaceAllocation.RouteFilterPrefixes;
                            writer.WritePropertyName("routeFilterPrefixes");
                            writer.WriteArrayStart();

                            foreach (RouteFilterPrefix routeFilterPrefixesListValue in routeFilterPrefixesList)
                            {
                                writer.WriteObjectStart();
                                if (routeFilterPrefixesListValue != null && routeFilterPrefixesListValue.IsSetCidr())
                                {
                                    writer.WritePropertyName("cidr");
                                    writer.Write(routeFilterPrefixesListValue.Cidr);
                                }
                                writer.WriteObjectEnd();
                            }
                            writer.WriteArrayEnd();
                        }
                        writer.WriteObjectEnd();
                    }
                }

                writer.WriteObjectEnd();

                string snippet = stringWriter.ToString();
                request.Content = System.Text.Encoding.UTF8.GetBytes(snippet);
            }


            return(request);
        }
Exemplo n.º 46
0
 public void WriteJson(JsonWriter writer)
 {
     writer.WriteObjectStart();
     if (this.rateModelId != null)
     {
         writer.WritePropertyName("rateModelId");
         writer.Write(this.rateModelId);
     }
     if (this.name != null)
     {
         writer.WritePropertyName("name");
         writer.Write(this.name);
     }
     if (this.metadata != null)
     {
         writer.WritePropertyName("metadata");
         writer.Write(this.metadata);
     }
     if (this.consumeActions != null)
     {
         writer.WritePropertyName("consumeActions");
         writer.WriteArrayStart();
         foreach (var item in this.consumeActions)
         {
             item.WriteJson(writer);
         }
         writer.WriteArrayEnd();
     }
     if (this.timingType != null)
     {
         writer.WritePropertyName("timingType");
         writer.Write(this.timingType);
     }
     if (this.lockTime.HasValue)
     {
         writer.WritePropertyName("lockTime");
         writer.Write(this.lockTime.Value);
     }
     if (this.enableSkip.HasValue)
     {
         writer.WritePropertyName("enableSkip");
         writer.Write(this.enableSkip.Value);
     }
     if (this.skipConsumeActions != null)
     {
         writer.WritePropertyName("skipConsumeActions");
         writer.WriteArrayStart();
         foreach (var item in this.skipConsumeActions)
         {
             item.WriteJson(writer);
         }
         writer.WriteArrayEnd();
     }
     if (this.acquireActions != null)
     {
         writer.WritePropertyName("acquireActions");
         writer.WriteArrayStart();
         foreach (var item in this.acquireActions)
         {
             item.WriteJson(writer);
         }
         writer.WriteArrayEnd();
     }
     writer.WriteObjectEnd();
 }
Exemplo n.º 47
0
    public void MergerJson()
    {
        StringBuilder sb = new StringBuilder ();
        JsonWriter writer = new JsonWriter (sb);

        writer.WriteObjectStart ();

        writer.WritePropertyName ("Name");
        writer.Write ("yusong");

        writer.WritePropertyName ("Age");
        writer.Write (26);

        writer.WritePropertyName ("Girl");

        writer.WriteArrayStart ();

        writer.WriteObjectStart();
        writer.WritePropertyName("name");
        writer.Write("ruoruo");
        writer.WritePropertyName("age");
        writer.Write(24);
        writer.WriteObjectEnd ();

        writer.WriteObjectStart();
        writer.WritePropertyName("name");
        writer.Write("momo");
        writer.WritePropertyName("age");
        writer.Write(26);
        writer.WriteObjectEnd ();

        writer.WriteArrayEnd();

        writer.WriteObjectEnd ();
        Debug.Log(sb.ToString ());

        JsonData jd = JsonMapper.ToObject(sb.ToString ());
        Debug.Log("name = " + (string)jd["Name"]);
        Debug.Log("Age = " + (int)jd["Age"]);
        JsonData jdItems = jd["Girl"];
        for (int i = 0; i < jdItems.Count; i++)
        {
            Debug.Log("Girl name = " + jdItems[i]["name"]);
            Debug.Log("Girl age = " + (int)jdItems[i]["age"]);
        }
    }
Exemplo n.º 48
0
        public IRequest Marshall(GetItemRequest getItemRequest)
        {
            IRequest request = new DefaultRequest(getItemRequest, "AmazonDynamoDBv2");
            string   target  = "DynamoDB_20120810.GetItem";

            request.Headers["X-Amz-Target"] = target;
            request.Headers["Content-Type"] = "application/x-amz-json-1.0";



            string uriResourcePath = "";

            if (uriResourcePath.Contains("?"))
            {
                string queryString = uriResourcePath.Substring(uriResourcePath.IndexOf("?") + 1);
                uriResourcePath = uriResourcePath.Substring(0, uriResourcePath.IndexOf("?"));

                foreach (string s in queryString.Split('&', ';'))
                {
                    string[] nameValuePair = s.Split('=');
                    if (nameValuePair.Length == 2 && nameValuePair[1].Length > 0)
                    {
                        request.Parameters.Add(nameValuePair[0], nameValuePair[1]);
                    }
                    else
                    {
                        request.Parameters.Add(nameValuePair[0], null);
                    }
                }
            }

            request.ResourcePath = uriResourcePath;


            using (StringWriter stringWriter = new StringWriter())
            {
                JsonWriter writer = new JsonWriter(stringWriter);
                writer.WriteObjectStart();

                if (getItemRequest != null && getItemRequest.IsSetTableName())
                {
                    writer.WritePropertyName("TableName");
                    writer.Write(getItemRequest.TableName);
                }
                if (getItemRequest != null)
                {
                    if (getItemRequest.Key != null && getItemRequest.Key.Count > 0)
                    {
                        writer.WritePropertyName("Key");
                        writer.WriteObjectStart();
                        foreach (string getItemRequestKeyKey in getItemRequest.Key.Keys)
                        {
                            AttributeValue keyListValue;
                            bool           keyListValueHasValue = getItemRequest.Key.TryGetValue(getItemRequestKeyKey, out keyListValue);
                            writer.WritePropertyName(getItemRequestKeyKey);

                            writer.WriteObjectStart();
                            if (keyListValue != null && keyListValue.IsSetS())
                            {
                                writer.WritePropertyName("S");
                                writer.Write(keyListValue.S);
                            }
                            if (keyListValue != null && keyListValue.IsSetN())
                            {
                                writer.WritePropertyName("N");
                                writer.Write(keyListValue.N);
                            }
                            if (keyListValue != null && keyListValue.IsSetB())
                            {
                                writer.WritePropertyName("B");
                                writer.Write(StringUtils.FromMemoryStream(keyListValue.B));
                            }

                            if (keyListValue != null && keyListValue.SS != null && keyListValue.SS.Count > 0)
                            {
                                List <string> sSList = keyListValue.SS;
                                writer.WritePropertyName("SS");
                                writer.WriteArrayStart();

                                foreach (string sSListValue in sSList)
                                {
                                    writer.Write(StringUtils.FromString(sSListValue));
                                }

                                writer.WriteArrayEnd();
                            }

                            if (keyListValue != null && keyListValue.NS != null && keyListValue.NS.Count > 0)
                            {
                                List <string> nSList = keyListValue.NS;
                                writer.WritePropertyName("NS");
                                writer.WriteArrayStart();

                                foreach (string nSListValue in nSList)
                                {
                                    writer.Write(StringUtils.FromString(nSListValue));
                                }

                                writer.WriteArrayEnd();
                            }

                            if (keyListValue != null && keyListValue.BS != null && keyListValue.BS.Count > 0)
                            {
                                List <MemoryStream> bSList = keyListValue.BS;
                                writer.WritePropertyName("BS");
                                writer.WriteArrayStart();

                                foreach (MemoryStream bSListValue in bSList)
                                {
                                    writer.Write(StringUtils.FromMemoryStream(bSListValue));
                                }

                                writer.WriteArrayEnd();
                            }
                            writer.WriteObjectEnd();
                        }
                        writer.WriteObjectEnd();
                    }
                }

                if (getItemRequest != null && getItemRequest.AttributesToGet != null && getItemRequest.AttributesToGet.Count > 0)
                {
                    List <string> attributesToGetList = getItemRequest.AttributesToGet;
                    writer.WritePropertyName("AttributesToGet");
                    writer.WriteArrayStart();

                    foreach (string attributesToGetListValue in attributesToGetList)
                    {
                        writer.Write(StringUtils.FromString(attributesToGetListValue));
                    }

                    writer.WriteArrayEnd();
                }
                if (getItemRequest != null && getItemRequest.IsSetConsistentRead())
                {
                    writer.WritePropertyName("ConsistentRead");
                    writer.Write(getItemRequest.ConsistentRead);
                }
                if (getItemRequest != null && getItemRequest.IsSetReturnConsumedCapacity())
                {
                    writer.WritePropertyName("ReturnConsumedCapacity");
                    writer.Write(getItemRequest.ReturnConsumedCapacity);
                }

                writer.WriteObjectEnd();

                string snippet = stringWriter.ToString();
                request.Content = System.Text.Encoding.UTF8.GetBytes(snippet);
            }


            return(request);
        }
    public static void BuildTable()
    {
        /*
        IDictionary<string, FiniteStateMachine> npcFSM = new Dictionary<string, FiniteStateMachine>();
        GameObject npcsGameObject = GameObject.Find("NPCs");
        Transform[] npcs = npcsGameObject.GetComponentsInChildren<Transform>();
        foreach (Transform npc in npcs) {
            try {
                // All the NPCs names start with "My"
                if(npc.gameObject.name.StartsWith("My")) {
                    npcsList.Add(npc.gameObject.name, npc.gameObject.GetComponent<FiniteStateMachine>());
                    //Debug.Log(node.gameObject.name + " found.");
                }
            } catch {
                // Hashtable launches an exception when we try to add an object that is already in the Hashtable
                // If the node we are trying to insert is already in the hashtable, we simply don't add it again
            }
        }
        */

        Debug.Log ("Building the Action Lookup Table...");

        StringBuilder sb = new StringBuilder();
        JsonWriter writer = new JsonWriter(sb);

        FiniteStateMachine mechFSM = GameObject.Find("MyEnemyMech").GetComponent<FiniteStateMachine>();
        FiniteStateMachine mineBotFSM = GameObject.Find("MyEnemyMineBot").GetComponent<FiniteStateMachine>();
        FiniteStateMachine mineBot1FSM = GameObject.Find("MyEnemyMineBot1").GetComponent<FiniteStateMachine>();

        //Debug.Log ("Trying to fetch FSM...");
        IList<FSMNodeWithTransitions> mechStates = mechFSM.ReadNodes;
        IList<FSMNodeWithTransitions> mineBotStates = mineBotFSM.ReadNodes;
        IList<FSMNodeWithTransitions> mineBot1States = mineBot1FSM.ReadNodes;
        //Debug.Log ("Trying to fetch FSM... DONE!");

        writer.WriteObjectStart();
        writer.WritePropertyName("table");
        writer.WriteArrayStart();

        foreach (FSMNodeWithTransitions mechState in mechStates) {
            mechFSM.CurrentState = mechState.NodeName;
            IList<FSMTransition> mechNextActions = mechFSM.NextActions;

            foreach (FSMNodeWithTransitions mineBotState in mineBotStates) {
                mineBotFSM.CurrentState = mineBotState.NodeName;
                IList<FSMTransition> mineBotNextActions = mineBotFSM.NextActions;

                foreach (FSMNodeWithTransitions mineBot1State in mineBot1States) {
                    mineBot1FSM.CurrentState = mineBot1State.NodeName;
                    IList<FSMTransition> mineBot1NextActions = mineBot1FSM.NextActions;

                    writer.WriteObjectStart();
                    writer.WritePropertyName("currentState");
                    writer.WriteArrayStart(); //Modified
                    writer.WriteObjectStart();
                    writer.WritePropertyName("npc");
                    writer.Write(mechFSM.gameObject.name);
                    writer.WritePropertyName("state");
                    writer.Write(mechFSM.CurrentState);
                    writer.WriteObjectEnd();
                    writer.WriteObjectStart();
                    writer.WritePropertyName("npc");
                    writer.Write(mineBotFSM.gameObject.name);
                    writer.WritePropertyName("state");
                    writer.Write(mineBotFSM.CurrentState);
                    writer.WriteObjectEnd();
                    writer.WriteObjectStart();
                    writer.WritePropertyName("npc");
                    writer.Write(mineBot1FSM.gameObject.name);
                    writer.WritePropertyName("state");
                    writer.Write(mineBot1FSM.CurrentState);
                    writer.WriteObjectEnd();
                    writer.WriteArrayEnd(); //Modified
                    writer.WritePropertyName("nextActions");
                    writer.WriteArrayStart();

                    foreach (FSMTransition nextAction in mechNextActions) {
                        writer.WriteObjectStart();
                        writer.WritePropertyName("actionName");
                        writer.Write(nextAction.ActionName);
                        writer.WritePropertyName("argument");
                        writer.Write(nextAction.Argument);
                        writer.WritePropertyName("npc");
                        writer.Write (mechFSM.gameObject.name);
                        writer.WriteObjectEnd();
                    }

                    foreach (FSMTransition nextAction in mineBotNextActions) {
                        writer.WriteObjectStart();
                        writer.WritePropertyName("actionName");
                        writer.Write(nextAction.ActionName);
                        writer.WritePropertyName("argument");
                        writer.Write(nextAction.Argument);
                        writer.WritePropertyName("npc");
                        writer.Write (mineBotFSM.gameObject.name);
                        writer.WriteObjectEnd();
                    }

                    foreach (FSMTransition nextAction in mineBot1NextActions) {
                        writer.WriteObjectStart();
                        writer.WritePropertyName("actionName");
                        writer.Write(nextAction.ActionName);
                        writer.WritePropertyName("argument");
                        writer.Write(nextAction.Argument);
                        writer.WritePropertyName("npc");
                        writer.Write (mineBot1FSM.gameObject.name);
                        writer.WriteObjectEnd();
                    }

                    writer.WriteArrayEnd();
                    writer.WriteObjectEnd();

                }
            }
        }

        writer.WriteArrayEnd();
        writer.WriteObjectEnd();
        StreamWriter sw = new StreamWriter(@"Assets/Composition/ActionLookupTable.json");
        Debug.Log ("Writing the JSON file...");
        sw.Write(sb.ToString());
        Debug.Log ("Writing the JSON file... DONE!");
        sw.Close();
    }
        public IRequest Marshall(ModifyInstanceGroupsRequest modifyInstanceGroupsRequest)
        {
            IRequest request = new DefaultRequest(modifyInstanceGroupsRequest, "AmazonElasticMapReduce");
            string   target  = "ElasticMapReduce.ModifyInstanceGroups";

            request.Headers["X-Amz-Target"] = target;

            request.Headers["Content-Type"] = "application/x-amz-json-1.1";

            string uriResourcePath = "";

            request.ResourcePath = uriResourcePath;


            using (StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture))
            {
                JsonWriter writer = new JsonWriter(stringWriter);
                writer.WriteObjectStart();


                if (modifyInstanceGroupsRequest != null && modifyInstanceGroupsRequest.InstanceGroups != null && modifyInstanceGroupsRequest.InstanceGroups.Count > 0)
                {
                    List <InstanceGroupModifyConfig> instanceGroupsList = modifyInstanceGroupsRequest.InstanceGroups;
                    writer.WritePropertyName("InstanceGroups");
                    writer.WriteArrayStart();

                    foreach (InstanceGroupModifyConfig instanceGroupsListValue in instanceGroupsList)
                    {
                        writer.WriteObjectStart();
                        if (instanceGroupsListValue != null && instanceGroupsListValue.IsSetInstanceGroupId())
                        {
                            writer.WritePropertyName("InstanceGroupId");
                            writer.Write(instanceGroupsListValue.InstanceGroupId);
                        }
                        if (instanceGroupsListValue != null && instanceGroupsListValue.IsSetInstanceCount())
                        {
                            writer.WritePropertyName("InstanceCount");
                            writer.Write(instanceGroupsListValue.InstanceCount);
                        }

                        if (instanceGroupsListValue != null && instanceGroupsListValue.EC2InstanceIdsToTerminate != null && instanceGroupsListValue.EC2InstanceIdsToTerminate.Count > 0)
                        {
                            List <string> eC2InstanceIdsToTerminateList = instanceGroupsListValue.EC2InstanceIdsToTerminate;
                            writer.WritePropertyName("EC2InstanceIdsToTerminate");
                            writer.WriteArrayStart();

                            foreach (string eC2InstanceIdsToTerminateListValue in eC2InstanceIdsToTerminateList)
                            {
                                writer.Write(StringUtils.FromString(eC2InstanceIdsToTerminateListValue));
                            }

                            writer.WriteArrayEnd();
                        }
                        writer.WriteObjectEnd();
                    }
                    writer.WriteArrayEnd();
                }

                writer.WriteObjectEnd();

                string snippet = stringWriter.ToString();
                request.Content = System.Text.Encoding.UTF8.GetBytes(snippet);
            }


            return(request);
        }
		/// <summary>
		/// Write an array of module descriptors
		/// </summary>
		/// <param name="Writer">The Json writer to output to</param>
		/// <param name="Name">Name of the array</param>
		/// <param name="Modules">Array of modules</param>
		public static void WriteArray(JsonWriter Writer, string Name, ModuleDescriptor[] Modules)
		{
			if (Modules.Length > 0)
			{
				Writer.WriteArrayStart(Name);
				foreach (ModuleDescriptor Module in Modules)
				{
					Module.Write(Writer);
				}
				Writer.WriteArrayEnd();
			}
		}
Exemplo n.º 52
0
		/// <summary>
		/// Export the build graph to a Json file, for parallel execution by the build system
		/// </summary>
		/// <param name="File">Output file to write</param>
		/// <param name="Trigger">The trigger whose nodes to run. Null for the default nodes.</param>
		/// <param name="CompletedNodes">Set of nodes which have been completed</param>
		public void Export(FileReference File, ManualTrigger Trigger, HashSet<Node> CompletedNodes)
		{
			// Find all the nodes which we're actually going to execute. We'll use this to filter the graph.
			HashSet<Node> NodesToExecute = new HashSet<Node>();
			foreach(Node Node in Agents.SelectMany(x => x.Nodes))
			{
				if(!CompletedNodes.Contains(Node) && Node.IsBehind(Trigger))
				{
					NodesToExecute.Add(Node);
				}
			}

			// Open the output file
			using(JsonWriter JsonWriter = new JsonWriter(File.FullName))
			{
				JsonWriter.WriteObjectStart();

				// Write all the agents
				JsonWriter.WriteArrayStart("Groups");
				foreach(Agent Agent in Agents)
				{
					Node[] Nodes = Agent.Nodes.Where(x => NodesToExecute.Contains(x) && x.ControllingTrigger == Trigger).ToArray();
					if(Nodes.Length > 0)
					{
						JsonWriter.WriteObjectStart();
						JsonWriter.WriteValue("Name", Agent.Name);
						JsonWriter.WriteArrayStart("Agent Types");
						foreach(string AgentType in Agent.PossibleTypes)
						{
							JsonWriter.WriteValue(AgentType);
						}
						JsonWriter.WriteArrayEnd();
						JsonWriter.WriteArrayStart("Nodes");
						foreach(Node Node in Nodes)
						{
							JsonWriter.WriteObjectStart();
							JsonWriter.WriteValue("Name", Node.Name);
							JsonWriter.WriteValue("DependsOn", String.Join(";", Node.GetDirectOrderDependencies().Where(x => NodesToExecute.Contains(x) && x.ControllingTrigger == Trigger)));
							JsonWriter.WriteObjectStart("Notify");
							JsonWriter.WriteValue("Default", String.Join(";", Node.NotifyUsers));
							JsonWriter.WriteValue("Submitters", String.Join(";", Node.NotifySubmitters));
							JsonWriter.WriteValue("Warnings", Node.bNotifyOnWarnings);
							JsonWriter.WriteObjectEnd();
							JsonWriter.WriteObjectEnd();
						}
						JsonWriter.WriteArrayEnd();
						JsonWriter.WriteObjectEnd();
					}
				}
				JsonWriter.WriteArrayEnd();

				// Write all the badges
				JsonWriter.WriteArrayStart("Badges");
				foreach (Badge Badge in Badges)
				{
					Node[] Dependencies = Badge.Nodes.Where(x => NodesToExecute.Contains(x)).ToArray();
					if (Dependencies.Length > 0)
					{
						// Reduce that list to the smallest subset of direct dependencies
						HashSet<Node> DirectDependencies = new HashSet<Node>(Dependencies);
						foreach (Node Dependency in Dependencies)
						{
							DirectDependencies.ExceptWith(Dependency.OrderDependencies);
						}

						JsonWriter.WriteObjectStart();
						JsonWriter.WriteValue("Name", Badge.Name);
						if (!String.IsNullOrEmpty(Badge.Project))
						{
							JsonWriter.WriteValue("Project", Badge.Project);
						}
						JsonWriter.WriteValue("AllDependencies", String.Join(";", Agents.SelectMany(x => x.Nodes).Where(x => Dependencies.Contains(x)).Select(x => x.Name)));
						JsonWriter.WriteValue("DirectDependencies", String.Join(";", DirectDependencies.Select(x => x.Name)));
						JsonWriter.WriteObjectEnd();
					}
				}
				JsonWriter.WriteArrayEnd();

				// Write all the triggers and reports. 
				JsonWriter.WriteArrayStart("Reports");
				foreach (Report Report in NameToReport.Values)
				{
					Node[] Dependencies = Report.Nodes.Where(x => NodesToExecute.Contains(x)).ToArray();
					if (Dependencies.Length > 0)
					{
						// Reduce that list to the smallest subset of direct dependencies
						HashSet<Node> DirectDependencies = new HashSet<Node>(Dependencies);
						foreach (Node Dependency in Dependencies)
						{
							DirectDependencies.ExceptWith(Dependency.OrderDependencies);
						}

						JsonWriter.WriteObjectStart();
						JsonWriter.WriteValue("Name", Report.Name);
						JsonWriter.WriteValue("AllDependencies", String.Join(";", Agents.SelectMany(x => x.Nodes).Where(x => Dependencies.Contains(x)).Select(x => x.Name)));
						JsonWriter.WriteValue("DirectDependencies", String.Join(";", DirectDependencies.Select(x => x.Name)));
						JsonWriter.WriteValue("Notify", String.Join(";", Report.NotifyUsers));
						JsonWriter.WriteValue("IsTrigger", false);
						JsonWriter.WriteObjectEnd();
					}
				}
				foreach (ManualTrigger DownstreamTrigger in NameToTrigger.Values)
				{
					if(DownstreamTrigger.Parent == Trigger)
					{
						// Find all the nodes that this trigger is dependent on
						HashSet<Node> Dependencies = new HashSet<Node>();
						foreach(Node NodeToExecute in NodesToExecute)
						{
							if(NodeToExecute.IsBehind(DownstreamTrigger))
							{
								Dependencies.UnionWith(NodeToExecute.OrderDependencies.Where(x => x.ControllingTrigger == Trigger));
							}
						}

						// Reduce that list to the smallest subset of direct dependencies
						HashSet<Node> DirectDependencies = new HashSet<Node>(Dependencies);
						foreach(Node Dependency in Dependencies)
						{
							DirectDependencies.ExceptWith(Dependency.OrderDependencies);
						}

						// Write out the object
						JsonWriter.WriteObjectStart();
						JsonWriter.WriteValue("Name", DownstreamTrigger.Name);
						JsonWriter.WriteValue("AllDependencies", String.Join(";", Agents.SelectMany(x => x.Nodes).Where(x => Dependencies.Contains(x)).Select(x => x.Name)));
						JsonWriter.WriteValue("DirectDependencies", String.Join(";", Dependencies.Where(x => DirectDependencies.Contains(x)).Select(x => x.Name)));
						JsonWriter.WriteValue("Notify", String.Join(";", DownstreamTrigger.NotifyUsers));
						JsonWriter.WriteValue("IsTrigger", true);
						JsonWriter.WriteObjectEnd();
					}
				}
				JsonWriter.WriteArrayEnd();

				JsonWriter.WriteObjectEnd();
			}
		}