WriteArrayStart() public method

public WriteArrayStart ( ) : void
return void
Example #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();
			}
		}
Example #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();
		}
Example #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();  //刷新
    }
Example #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();
 }
Example #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(CreatePublicVirtualInterfaceRequest createPublicVirtualInterfaceRequest)
        {
            IRequest request = new DefaultRequest(createPublicVirtualInterfaceRequest, "AmazonDirectConnect");
            string   target  = "OvertureService.CreatePublicVirtualInterface";

            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 (createPublicVirtualInterfaceRequest != null && createPublicVirtualInterfaceRequest.IsSetConnectionId())
                {
                    writer.WritePropertyName("connectionId");
                    writer.Write(createPublicVirtualInterfaceRequest.ConnectionId);
                }

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

                        if (newPublicVirtualInterface != null && newPublicVirtualInterface.RouteFilterPrefixes != null && newPublicVirtualInterface.RouteFilterPrefixes.Count > 0)
                        {
                            List <RouteFilterPrefix> routeFilterPrefixesList = newPublicVirtualInterface.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);
        }
        public IRequest Marshall(DescribeVolumesRequest describeVolumesRequest)
        {
            IRequest request = new DefaultRequest(describeVolumesRequest, "AmazonOpsWorks");
            string   target  = "OpsWorks_20130218.DescribeVolumes";

            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 (describeVolumesRequest != null && describeVolumesRequest.IsSetInstanceId())
                {
                    writer.WritePropertyName("InstanceId");
                    writer.Write(describeVolumesRequest.InstanceId);
                }
                if (describeVolumesRequest != null && describeVolumesRequest.IsSetStackId())
                {
                    writer.WritePropertyName("StackId");
                    writer.Write(describeVolumesRequest.StackId);
                }
                if (describeVolumesRequest != null && describeVolumesRequest.IsSetRaidArrayId())
                {
                    writer.WritePropertyName("RaidArrayId");
                    writer.Write(describeVolumesRequest.RaidArrayId);
                }

                if (describeVolumesRequest != null && describeVolumesRequest.VolumeIds != null && describeVolumesRequest.VolumeIds.Count > 0)
                {
                    List <string> volumeIdsList = describeVolumesRequest.VolumeIds;
                    writer.WritePropertyName("VolumeIds");
                    writer.WriteArrayStart();

                    foreach (string volumeIdsListValue in volumeIdsList)
                    {
                        writer.Write(StringUtils.FromString(volumeIdsListValue));
                    }

                    writer.WriteArrayEnd();
                }

                writer.WriteObjectEnd();

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


            return(request);
        }
Example #10
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();
    }
Example #11
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);
        }
        public IRequest Marshall(CreateAppRequest createAppRequest)
        {
            IRequest request = new DefaultRequest(createAppRequest, "AmazonOpsWorks");
            string   target  = "OpsWorks_20130218.CreateApp";

            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 (createAppRequest != null && createAppRequest.IsSetStackId())
                {
                    writer.WritePropertyName("StackId");
                    writer.Write(createAppRequest.StackId);
                }
                if (createAppRequest != null && createAppRequest.IsSetShortname())
                {
                    writer.WritePropertyName("Shortname");
                    writer.Write(createAppRequest.Shortname);
                }
                if (createAppRequest != null && createAppRequest.IsSetName())
                {
                    writer.WritePropertyName("Name");
                    writer.Write(createAppRequest.Name);
                }
                if (createAppRequest != null && createAppRequest.IsSetDescription())
                {
                    writer.WritePropertyName("Description");
                    writer.Write(createAppRequest.Description);
                }
                if (createAppRequest != null && createAppRequest.IsSetType())
                {
                    writer.WritePropertyName("Type");
                    writer.Write(createAppRequest.Type);
                }

                if (createAppRequest != null)
                {
                    Source appSource = createAppRequest.AppSource;
                    if (appSource != null)
                    {
                        writer.WritePropertyName("AppSource");
                        writer.WriteObjectStart();
                        if (appSource != null && appSource.IsSetType())
                        {
                            writer.WritePropertyName("Type");
                            writer.Write(appSource.Type);
                        }
                        if (appSource != null && appSource.IsSetUrl())
                        {
                            writer.WritePropertyName("Url");
                            writer.Write(appSource.Url);
                        }
                        if (appSource != null && appSource.IsSetUsername())
                        {
                            writer.WritePropertyName("Username");
                            writer.Write(appSource.Username);
                        }
                        if (appSource != null && appSource.IsSetPassword())
                        {
                            writer.WritePropertyName("Password");
                            writer.Write(appSource.Password);
                        }
                        if (appSource != null && appSource.IsSetSshKey())
                        {
                            writer.WritePropertyName("SshKey");
                            writer.Write(appSource.SshKey);
                        }
                        if (appSource != null && appSource.IsSetRevision())
                        {
                            writer.WritePropertyName("Revision");
                            writer.Write(appSource.Revision);
                        }
                        writer.WriteObjectEnd();
                    }
                }

                if (createAppRequest != null && createAppRequest.Domains != null && createAppRequest.Domains.Count > 0)
                {
                    List <string> domainsList = createAppRequest.Domains;
                    writer.WritePropertyName("Domains");
                    writer.WriteArrayStart();

                    foreach (string domainsListValue in domainsList)
                    {
                        writer.Write(StringUtils.FromString(domainsListValue));
                    }

                    writer.WriteArrayEnd();
                }
                if (createAppRequest != null && createAppRequest.IsSetEnableSsl())
                {
                    writer.WritePropertyName("EnableSsl");
                    writer.Write(createAppRequest.EnableSsl);
                }

                if (createAppRequest != null)
                {
                    SslConfiguration sslConfiguration = createAppRequest.SslConfiguration;
                    if (sslConfiguration != null)
                    {
                        writer.WritePropertyName("SslConfiguration");
                        writer.WriteObjectStart();
                        if (sslConfiguration != null && sslConfiguration.IsSetCertificate())
                        {
                            writer.WritePropertyName("Certificate");
                            writer.Write(sslConfiguration.Certificate);
                        }
                        if (sslConfiguration != null && sslConfiguration.IsSetPrivateKey())
                        {
                            writer.WritePropertyName("PrivateKey");
                            writer.Write(sslConfiguration.PrivateKey);
                        }
                        if (sslConfiguration != null && sslConfiguration.IsSetChain())
                        {
                            writer.WritePropertyName("Chain");
                            writer.Write(sslConfiguration.Chain);
                        }
                        writer.WriteObjectEnd();
                    }
                }
                if (createAppRequest != null)
                {
                    if (createAppRequest.Attributes != null && createAppRequest.Attributes.Count > 0)
                    {
                        writer.WritePropertyName("Attributes");
                        writer.WriteObjectStart();
                        foreach (string createAppRequestAttributesKey in createAppRequest.Attributes.Keys)
                        {
                            string attributesListValue;
                            bool   attributesListValueHasValue = createAppRequest.Attributes.TryGetValue(createAppRequestAttributesKey, out attributesListValue);
                            writer.WritePropertyName(createAppRequestAttributesKey);

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

                writer.WriteObjectEnd();

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


            return(request);
        }
        public IRequest Marshall(GetItemRequest getItemRequest)
        {
            IRequest request = new DefaultRequest(getItemRequest, "AmazonDynamoDB");
            string   target  = "DynamoDB_20111205.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)
                {
                    Key key = getItemRequest.Key;
                    if (key != null)
                    {
                        writer.WritePropertyName("Key");
                        writer.WriteObjectStart();

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

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

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

                                    writer.WriteArrayEnd();
                                }

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

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

                                    writer.WriteArrayEnd();
                                }

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

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

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

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

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

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

                                    writer.WriteArrayEnd();
                                }

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

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

                                    writer.WriteArrayEnd();
                                }

                                if (rangeKeyElement != null && rangeKeyElement.BS != null && rangeKeyElement.BS.Count > 0)
                                {
                                    List <MemoryStream> bSList = rangeKeyElement.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);
                }

                writer.WriteObjectEnd();

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


            return(request);
        }
Example #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
 }
Example #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();
	}
        public IRequest Marshall(TestRoleRequest testRoleRequest)
        {
            IRequest request = new DefaultRequest(testRoleRequest, "AmazonElasticTranscoder");
            string   target  = "EtsCustomerService.TestRole";

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

            request.HttpMethod = "POST";

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

            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 (testRoleRequest != null && testRoleRequest.IsSetRole())
                {
                    writer.WritePropertyName("Role");
                    writer.Write(testRoleRequest.Role);
                }
                if (testRoleRequest != null && testRoleRequest.IsSetInputBucket())
                {
                    writer.WritePropertyName("InputBucket");
                    writer.Write(testRoleRequest.InputBucket);
                }
                if (testRoleRequest != null && testRoleRequest.IsSetOutputBucket())
                {
                    writer.WritePropertyName("OutputBucket");
                    writer.Write(testRoleRequest.OutputBucket);
                }

                if (testRoleRequest != null && testRoleRequest.Topics != null && testRoleRequest.Topics.Count > 0)
                {
                    List <string> topicsList = testRoleRequest.Topics;
                    writer.WritePropertyName("Topics");
                    writer.WriteArrayStart();

                    foreach (string topicsListValue in topicsList)
                    {
                        writer.Write(StringUtils.FromString(topicsListValue));
                    }

                    writer.WriteArrayEnd();
                }

                writer.WriteObjectEnd();

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


            return(request);
        }
Example #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***********");
    }
Example #18
0
        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";

            request.ResourcePath = uriResourcePath;


            using (StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture))
            {
                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);
                        }

                        if (audio != null)
                        {
                            AudioCodecOptions codecOptions = audio.CodecOptions;
                            if (codecOptions != null)
                            {
                                writer.WritePropertyName("CodecOptions");
                                writer.WriteObjectStart();
                                if (codecOptions != null && codecOptions.IsSetProfile())
                                {
                                    writer.WritePropertyName("Profile");
                                    writer.Write(codecOptions.Profile);
                                }
                                writer.WriteObjectEnd();
                            }
                        }
                        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);
        }
Example #19
0
        public static void LitJsonOutputFile()
        {
            using (FileStream fs = new FileStream("litjson_out.txt",
                                                  FileMode.Create)) {
                StreamWriter out_stream = new StreamWriter(fs);

                JsonReader reader = new JsonReader(Common.JsonText);

                out_stream.WriteLine("*** Reading with LitJson.JsonReader");

                while (reader.Read())
                {
                    out_stream.Write("Token: {0}", reader.Token);

                    if (reader.Value != null)
                    {
                        out_stream.WriteLine(" Value: {0}", reader.Value);
                    }
                    else
                    {
                        out_stream.WriteLine("");
                    }
                }


                out_stream.WriteLine(
                    "\n*** Writing with LitJson.JsonWriter");

                JsonWriter writer = new JsonWriter(out_stream);
                int        n      = Common.SampleObject.Length;
                for (int i = 0; i < n; i += 2)
                {
                    switch ((char)Common.SampleObject[i])
                    {
                    case '{':
                        writer.WriteObjectStart();
                        break;

                    case '}':
                        writer.WriteObjectEnd();
                        break;

                    case '[':
                        writer.WriteArrayStart();
                        break;

                    case ']':
                        writer.WriteArrayEnd();
                        break;

                    case 'P':
                        writer.WritePropertyName(
                            (string)Common.SampleObject[i + 1]);
                        break;

                    case 'I':
                        writer.Write(
                            (int)Common.SampleObject[i + 1]);
                        break;

                    case 'D':
                        writer.Write(
                            (double)Common.SampleObject[i + 1]);
                        break;

                    case 'S':
                        writer.Write(
                            (string)Common.SampleObject[i + 1]);
                        break;

                    case 'B':
                        writer.Write(
                            (bool)Common.SampleObject[i + 1]);
                        break;

                    case 'N':
                        writer.Write(null);
                        break;
                    }
                }


                out_stream.WriteLine(
                    "\n\n*** Data imported with " +
                    "LitJson.JsonMapper\n");

                Person art = JsonMapper.ToObject <Person> (Common.PersonJson);

                out_stream.Write(art.ToString());


                out_stream.WriteLine(
                    "\n\n*** Object exported with " +
                    "LitJson.JsonMapper\n");

                out_stream.Write(JsonMapper.ToJson(Common.SamplePerson));


                out_stream.WriteLine(
                    "\n\n*** Generic object exported with " +
                    "LitJson.JsonMapper\n");

                JsonData person = JsonMapper.ToObject(Common.PersonJson);

                out_stream.Write(JsonMapper.ToJson(person));


                out_stream.WriteLine(
                    "\n\n*** Hashtable exported with " +
                    "LitJson.JsonMapper\n");

                out_stream.Write(JsonMapper.ToJson(Common.HashtablePerson));

                out_stream.Close();
            }
        }
Example #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();
	}
Example #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();
    }
Example #22
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 = "";

            request.ResourcePath = uriResourcePath;


            using (StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture))
            {
                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.IsSetAmiId())
                {
                    writer.WritePropertyName("AmiId");
                    writer.Write(updateInstanceRequest.AmiId);
                }
                if (updateInstanceRequest != null && updateInstanceRequest.IsSetSshKeyName())
                {
                    writer.WritePropertyName("SshKeyName");
                    writer.Write(updateInstanceRequest.SshKeyName);
                }
                if (updateInstanceRequest != null && updateInstanceRequest.IsSetArchitecture())
                {
                    writer.WritePropertyName("Architecture");
                    writer.Write(updateInstanceRequest.Architecture);
                }
                if (updateInstanceRequest != null && updateInstanceRequest.IsSetInstallUpdatesOnBoot())
                {
                    writer.WritePropertyName("InstallUpdatesOnBoot");
                    writer.Write(updateInstanceRequest.InstallUpdatesOnBoot);
                }

                writer.WriteObjectEnd();

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


            return(request);
        }
Example #23
0
        private static void WriteTransform(GameObject go, JsonWriter writer)
        {
            if (go)
            {
                var tran = go.GetComponent <RectTransform>();
                if (!tran)
                {
                    return;
                }

                writer.WriteObjectStart();

                writer.WritePropertyName("name");
                writer.Write(go.name);

                writer.WritePropertyName("position");
                writer.WriteObjectStart();
                writer.WritePropertyName("x");
                writer.Write(tran.anchoredPosition.x.ToString());
                writer.WritePropertyName("y");
                writer.Write(tran.anchoredPosition.y.ToString());
                writer.WritePropertyName("w");
                writer.Write(tran.rect.width.ToString());
                writer.WritePropertyName("h");
                writer.Write(tran.rect.height.ToString());
                writer.WriteObjectEnd();

                var img = go.GetComponent <Image>();
                if (img && img.sprite)
                {
                    writer.WritePropertyName("image");
                    writer.Write(img.sprite.name);
                }

                var nodeInfo = go.GetComponent <NodeInfo>();
                if (nodeInfo)
                {
                    writer.WritePropertyName("node");
                    writer.WriteObjectStart();
                    writer.WritePropertyName("oneScreenTime");
                    writer.Write(nodeInfo.OneScreenTime.ToString());
                    writer.WritePropertyName("loopUnit");
                    writer.Write(nodeInfo.LoopUnit.ToString());
                    writer.WriteObjectEnd();
                }

                if (tran.childCount > 0)
                {
                    writer.WritePropertyName("children");
                    writer.WriteArrayStart();

                    for (int i = 0; i < tran.childCount; ++i)
                    {
                        WriteTransform(tran.GetChild(i).gameObject, writer);
                    }

                    writer.WriteArrayEnd();
                }

                writer.WriteObjectEnd();
            }
        }
Example #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();
		}
        /// <summary>
        ///  记录所有资源的信息;将被托管的物体记录为 Json 文件,以便于将信息保存到服务器;
        ///
        ///  程序启动时,自动记录一次;
        /// </summary>
        public void RecordAllGameObjectsInfo()
        {
            // 要还原资源的状态,首先要保存资源的状态。并将以上获得物体持久化到文件;

            // {物体名:“  ”, 父物体:“” , 标签:“” , 层级:“” , 位置:“” , 旋转:“” , 缩放: “” ,…… }

            StringBuilder strBuilder = new StringBuilder();

            JsonWriter jsonWriter = new JsonWriter(strBuilder);

            jsonWriter.WriteArrayStart();

            foreach (var gameObjectAsset in gameObjectsList)
            {
                jsonWriter.WriteObjectStart();

                jsonWriter.WritePropertyName("name");

                jsonWriter.Write(gameObjectAsset.name);

                jsonWriter.WritePropertyName("parent");

                jsonWriter.Write(gameObjectAsset.transform.parent != null ? gameObjectAsset.transform.parent.name : "");

                jsonWriter.WritePropertyName("active");

                jsonWriter.Write(gameObjectAsset.activeSelf);

                jsonWriter.WritePropertyName("tag");

                jsonWriter.Write(gameObjectAsset.tag);

                jsonWriter.WritePropertyName("layer");

                jsonWriter.Write(gameObjectAsset.layer);

                jsonWriter.WritePropertyName("pos");

                jsonWriter.Write(gameObjectAsset.transform.position.x + "," + gameObjectAsset.transform.position.y + "," +
                                 gameObjectAsset.transform.position.z);

                jsonWriter.WritePropertyName("rot");

                jsonWriter.Write(gameObjectAsset.transform.eulerAngles.x + "," + gameObjectAsset.transform.eulerAngles.y + "," +
                                 gameObjectAsset.transform.eulerAngles.z);

                jsonWriter.WritePropertyName("scale");

                jsonWriter.Write(gameObjectAsset.transform.localScale.x + "," + gameObjectAsset.transform.localScale.y + "," +
                                 gameObjectAsset.transform.localScale.z);

                jsonWriter.WriteObjectEnd();

                strBuilder.AppendLine();
            }

            jsonWriter.WriteArrayEnd();

            // 记录数据;

            RecordJsonData(strBuilder);
        }
        public IRequest Marshall(UpdateLayerRequest updateLayerRequest)
        {
            IRequest request = new DefaultRequest(updateLayerRequest, "AmazonOpsWorks");
            string   target  = "OpsWorks_20130218.UpdateLayer";

            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 (updateLayerRequest != null && updateLayerRequest.IsSetLayerId())
                {
                    writer.WritePropertyName("LayerId");
                    writer.Write(updateLayerRequest.LayerId);
                }
                if (updateLayerRequest != null && updateLayerRequest.IsSetName())
                {
                    writer.WritePropertyName("Name");
                    writer.Write(updateLayerRequest.Name);
                }
                if (updateLayerRequest != null && updateLayerRequest.IsSetShortname())
                {
                    writer.WritePropertyName("Shortname");
                    writer.Write(updateLayerRequest.Shortname);
                }
                if (updateLayerRequest != null)
                {
                    if (updateLayerRequest.Attributes != null && updateLayerRequest.Attributes.Count > 0)
                    {
                        writer.WritePropertyName("Attributes");
                        writer.WriteObjectStart();
                        foreach (string updateLayerRequestAttributesKey in updateLayerRequest.Attributes.Keys)
                        {
                            string attributesListValue;
                            bool   attributesListValueHasValue = updateLayerRequest.Attributes.TryGetValue(updateLayerRequestAttributesKey, out attributesListValue);
                            writer.WritePropertyName(updateLayerRequestAttributesKey);

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

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

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

                    writer.WriteArrayEnd();
                }

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

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

                    writer.WriteArrayEnd();
                }

                if (updateLayerRequest != null && updateLayerRequest.VolumeConfigurations != null && updateLayerRequest.VolumeConfigurations.Count > 0)
                {
                    List <VolumeConfiguration> volumeConfigurationsList = updateLayerRequest.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 (updateLayerRequest != null && updateLayerRequest.IsSetEnableAutoHealing())
                {
                    writer.WritePropertyName("EnableAutoHealing");
                    writer.Write(updateLayerRequest.EnableAutoHealing);
                }
                if (updateLayerRequest != null && updateLayerRequest.IsSetAutoAssignElasticIps())
                {
                    writer.WritePropertyName("AutoAssignElasticIps");
                    writer.Write(updateLayerRequest.AutoAssignElasticIps);
                }
                if (updateLayerRequest != null && updateLayerRequest.IsSetAutoAssignPublicIps())
                {
                    writer.WritePropertyName("AutoAssignPublicIps");
                    writer.Write(updateLayerRequest.AutoAssignPublicIps);
                }

                if (updateLayerRequest != null)
                {
                    Recipes customRecipes = updateLayerRequest.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 (updateLayerRequest != null && updateLayerRequest.IsSetInstallUpdatesOnBoot())
                {
                    writer.WritePropertyName("InstallUpdatesOnBoot");
                    writer.Write(updateLayerRequest.InstallUpdatesOnBoot);
                }
                if (updateLayerRequest != null && updateLayerRequest.IsSetUseEbsOptimizedInstances())
                {
                    writer.WritePropertyName("UseEbsOptimizedInstances");
                    writer.Write(updateLayerRequest.UseEbsOptimizedInstances);
                }

                writer.WriteObjectEnd();

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


            return(request);
        }
        public IRequest Marshall(DescribeServicesRequest describeServicesRequest)
        {
            IRequest request = new DefaultRequest(describeServicesRequest, "AmazonAWSSupport");
            string   target  = "AWSSupport_20130415.DescribeServices";

            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 (describeServicesRequest != null && describeServicesRequest.ServiceCodeList != null && describeServicesRequest.ServiceCodeList.Count > 0)
                {
                    List <string> serviceCodeListList = describeServicesRequest.ServiceCodeList;
                    writer.WritePropertyName("serviceCodeList");
                    writer.WriteArrayStart();

                    foreach (string serviceCodeListListValue in serviceCodeListList)
                    {
                        writer.Write(StringUtils.FromString(serviceCodeListListValue));
                    }

                    writer.WriteArrayEnd();
                }
                if (describeServicesRequest != null && describeServicesRequest.IsSetLanguage())
                {
                    writer.WritePropertyName("language");
                    writer.Write(describeServicesRequest.Language);
                }

                writer.WriteObjectEnd();

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


            return(request);
        }
Example #29
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());
        }
Example #30
0
        public IRequest Marshall(UpdateTableRequest updateTableRequest)
        {
            IRequest request = new DefaultRequest(updateTableRequest, "AmazonDynamoDBv2");
            string   target  = "DynamoDB_20120810.UpdateTable";

            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 (updateTableRequest != null && updateTableRequest.IsSetTableName())
                {
                    writer.WritePropertyName("TableName");
                    writer.Write(updateTableRequest.TableName);
                }

                if (updateTableRequest != null)
                {
                    ProvisionedThroughput provisionedThroughput = updateTableRequest.ProvisionedThroughput;
                    if (provisionedThroughput != null)
                    {
                        writer.WritePropertyName("ProvisionedThroughput");
                        writer.WriteObjectStart();
                        if (provisionedThroughput != null && provisionedThroughput.IsSetReadCapacityUnits())
                        {
                            writer.WritePropertyName("ReadCapacityUnits");
                            writer.Write(provisionedThroughput.ReadCapacityUnits);
                        }
                        if (provisionedThroughput != null && provisionedThroughput.IsSetWriteCapacityUnits())
                        {
                            writer.WritePropertyName("WriteCapacityUnits");
                            writer.Write(provisionedThroughput.WriteCapacityUnits);
                        }
                        writer.WriteObjectEnd();
                    }
                }

                if (updateTableRequest != null && updateTableRequest.GlobalSecondaryIndexUpdates != null && updateTableRequest.GlobalSecondaryIndexUpdates.Count > 0)
                {
                    List <GlobalSecondaryIndexUpdate> globalSecondaryIndexUpdatesList = updateTableRequest.GlobalSecondaryIndexUpdates;
                    writer.WritePropertyName("GlobalSecondaryIndexUpdates");
                    writer.WriteArrayStart();

                    foreach (GlobalSecondaryIndexUpdate globalSecondaryIndexUpdatesListValue in globalSecondaryIndexUpdatesList)
                    {
                        writer.WriteObjectStart();

                        if (globalSecondaryIndexUpdatesListValue != null)
                        {
                            UpdateGlobalSecondaryIndexAction update = globalSecondaryIndexUpdatesListValue.Update;
                            if (update != null)
                            {
                                writer.WritePropertyName("Update");
                                writer.WriteObjectStart();
                                if (update != null && update.IsSetIndexName())
                                {
                                    writer.WritePropertyName("IndexName");
                                    writer.Write(update.IndexName);
                                }

                                if (update != null)
                                {
                                    ProvisionedThroughput provisionedThroughput = update.ProvisionedThroughput;
                                    if (provisionedThroughput != null)
                                    {
                                        writer.WritePropertyName("ProvisionedThroughput");
                                        writer.WriteObjectStart();
                                        if (provisionedThroughput != null && provisionedThroughput.IsSetReadCapacityUnits())
                                        {
                                            writer.WritePropertyName("ReadCapacityUnits");
                                            writer.Write(provisionedThroughput.ReadCapacityUnits);
                                        }
                                        if (provisionedThroughput != null && provisionedThroughput.IsSetWriteCapacityUnits())
                                        {
                                            writer.WritePropertyName("WriteCapacityUnits");
                                            writer.Write(provisionedThroughput.WriteCapacityUnits);
                                        }
                                        writer.WriteObjectEnd();
                                    }
                                }
                                writer.WriteObjectEnd();
                            }
                        }
                        writer.WriteObjectEnd();
                    }
                    writer.WriteArrayEnd();
                }

                writer.WriteObjectEnd();

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


            return(request);
        }
        public IRequest Marshall(CreateInstanceRequest publicRequest)
        {
            IRequest request = new DefaultRequest(publicRequest, "Amazon.OpsWorks");
            string   target  = "OpsWorks_20130218.CreateInstance";

            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.IsSetAmiId())
                {
                    writer.WritePropertyName("AmiId");
                    writer.Write(publicRequest.AmiId);
                }

                if (publicRequest.IsSetArchitecture())
                {
                    writer.WritePropertyName("Architecture");
                    writer.Write(publicRequest.Architecture);
                }

                if (publicRequest.IsSetAutoScalingType())
                {
                    writer.WritePropertyName("AutoScalingType");
                    writer.Write(publicRequest.AutoScalingType);
                }

                if (publicRequest.IsSetAvailabilityZone())
                {
                    writer.WritePropertyName("AvailabilityZone");
                    writer.Write(publicRequest.AvailabilityZone);
                }

                if (publicRequest.IsSetEbsOptimized())
                {
                    writer.WritePropertyName("EbsOptimized");
                    writer.Write(publicRequest.EbsOptimized);
                }

                if (publicRequest.IsSetHostname())
                {
                    writer.WritePropertyName("Hostname");
                    writer.Write(publicRequest.Hostname);
                }

                if (publicRequest.IsSetInstallUpdatesOnBoot())
                {
                    writer.WritePropertyName("InstallUpdatesOnBoot");
                    writer.Write(publicRequest.InstallUpdatesOnBoot);
                }

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

                if (publicRequest.IsSetLayerIds())
                {
                    writer.WritePropertyName("LayerIds");
                    writer.WriteArrayStart();
                    foreach (var publicRequestLayerIdsListValue in publicRequest.LayerIds)
                    {
                        writer.Write(publicRequestLayerIdsListValue);
                    }
                    writer.WriteArrayEnd();
                }

                if (publicRequest.IsSetOs())
                {
                    writer.WritePropertyName("Os");
                    writer.Write(publicRequest.Os);
                }

                if (publicRequest.IsSetRootDeviceType())
                {
                    writer.WritePropertyName("RootDeviceType");
                    writer.Write(publicRequest.RootDeviceType);
                }

                if (publicRequest.IsSetSshKeyName())
                {
                    writer.WritePropertyName("SshKeyName");
                    writer.Write(publicRequest.SshKeyName);
                }

                if (publicRequest.IsSetStackId())
                {
                    writer.WritePropertyName("StackId");
                    writer.Write(publicRequest.StackId);
                }

                if (publicRequest.IsSetSubnetId())
                {
                    writer.WritePropertyName("SubnetId");
                    writer.Write(publicRequest.SubnetId);
                }

                if (publicRequest.IsSetVirtualizationType())
                {
                    writer.WritePropertyName("VirtualizationType");
                    writer.Write(publicRequest.VirtualizationType);
                }


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


            return(request);
        }
        public IRequest Marshall(AddInstanceGroupsRequest addInstanceGroupsRequest)
        {
            IRequest request = new DefaultRequest(addInstanceGroupsRequest, "AmazonElasticMapReduce");
            string   target  = "ElasticMapReduce.AddInstanceGroups";

            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 (addInstanceGroupsRequest != null && addInstanceGroupsRequest.InstanceGroups != null && addInstanceGroupsRequest.InstanceGroups.Count > 0)
                {
                    List <InstanceGroupConfig> instanceGroupsList = addInstanceGroupsRequest.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 (addInstanceGroupsRequest != null && addInstanceGroupsRequest.IsSetJobFlowId())
                {
                    writer.WritePropertyName("JobFlowId");
                    writer.Write(addInstanceGroupsRequest.JobFlowId);
                }

                writer.WriteObjectEnd();

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


            return(request);
        }
        public IRequest Marshall(AddJobFlowStepsRequest addJobFlowStepsRequest)
        {
            IRequest request = new DefaultRequest(addJobFlowStepsRequest, "AmazonElasticMapReduce");
            string   target  = "ElasticMapReduce.AddJobFlowSteps";

            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 (addJobFlowStepsRequest != null && addJobFlowStepsRequest.IsSetJobFlowId())
                {
                    writer.WritePropertyName("JobFlowId");
                    writer.Write(addJobFlowStepsRequest.JobFlowId);
                }

                if (addJobFlowStepsRequest != null && addJobFlowStepsRequest.Steps != null && addJobFlowStepsRequest.Steps.Count > 0)
                {
                    List <StepConfig> stepsList = addJobFlowStepsRequest.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();
                }

                writer.WriteObjectEnd();

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


            return(request);
        }
        public IRequest Marshall(CloneStackRequest cloneStackRequest)
        {
            IRequest request = new DefaultRequest(cloneStackRequest, "AmazonOpsWorks");
            string   target  = "OpsWorks_20130218.CloneStack";

            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 (cloneStackRequest != null && cloneStackRequest.IsSetSourceStackId())
                {
                    writer.WritePropertyName("SourceStackId");
                    writer.Write(cloneStackRequest.SourceStackId);
                }
                if (cloneStackRequest != null && cloneStackRequest.IsSetName())
                {
                    writer.WritePropertyName("Name");
                    writer.Write(cloneStackRequest.Name);
                }
                if (cloneStackRequest != null && cloneStackRequest.IsSetRegion())
                {
                    writer.WritePropertyName("Region");
                    writer.Write(cloneStackRequest.Region);
                }
                if (cloneStackRequest != null)
                {
                    if (cloneStackRequest.Attributes != null && cloneStackRequest.Attributes.Count > 0)
                    {
                        writer.WritePropertyName("Attributes");
                        writer.WriteObjectStart();
                        foreach (string cloneStackRequestAttributesKey in cloneStackRequest.Attributes.Keys)
                        {
                            string attributesListValue;
                            bool   attributesListValueHasValue = cloneStackRequest.Attributes.TryGetValue(cloneStackRequestAttributesKey, out attributesListValue);
                            writer.WritePropertyName(cloneStackRequestAttributesKey);

                            writer.Write(attributesListValue);
                        }
                        writer.WriteObjectEnd();
                    }
                }
                if (cloneStackRequest != null && cloneStackRequest.IsSetServiceRoleArn())
                {
                    writer.WritePropertyName("ServiceRoleArn");
                    writer.Write(cloneStackRequest.ServiceRoleArn);
                }
                if (cloneStackRequest != null && cloneStackRequest.IsSetDefaultInstanceProfileArn())
                {
                    writer.WritePropertyName("DefaultInstanceProfileArn");
                    writer.Write(cloneStackRequest.DefaultInstanceProfileArn);
                }
                if (cloneStackRequest != null && cloneStackRequest.IsSetDefaultOs())
                {
                    writer.WritePropertyName("DefaultOs");
                    writer.Write(cloneStackRequest.DefaultOs);
                }
                if (cloneStackRequest != null && cloneStackRequest.IsSetHostnameTheme())
                {
                    writer.WritePropertyName("HostnameTheme");
                    writer.Write(cloneStackRequest.HostnameTheme);
                }
                if (cloneStackRequest != null && cloneStackRequest.IsSetDefaultAvailabilityZone())
                {
                    writer.WritePropertyName("DefaultAvailabilityZone");
                    writer.Write(cloneStackRequest.DefaultAvailabilityZone);
                }
                if (cloneStackRequest != null && cloneStackRequest.IsSetCustomJson())
                {
                    writer.WritePropertyName("CustomJson");
                    writer.Write(cloneStackRequest.CustomJson);
                }

                if (cloneStackRequest != null)
                {
                    StackConfigurationManager configurationManager = cloneStackRequest.ConfigurationManager;
                    if (configurationManager != null)
                    {
                        writer.WritePropertyName("ConfigurationManager");
                        writer.WriteObjectStart();
                        if (configurationManager != null && configurationManager.IsSetName())
                        {
                            writer.WritePropertyName("Name");
                            writer.Write(configurationManager.Name);
                        }
                        if (configurationManager != null && configurationManager.IsSetVersion())
                        {
                            writer.WritePropertyName("Version");
                            writer.Write(configurationManager.Version);
                        }
                        writer.WriteObjectEnd();
                    }
                }
                if (cloneStackRequest != null && cloneStackRequest.IsSetUseCustomCookbooks())
                {
                    writer.WritePropertyName("UseCustomCookbooks");
                    writer.Write(cloneStackRequest.UseCustomCookbooks);
                }

                if (cloneStackRequest != null)
                {
                    Source customCookbooksSource = cloneStackRequest.CustomCookbooksSource;
                    if (customCookbooksSource != null)
                    {
                        writer.WritePropertyName("CustomCookbooksSource");
                        writer.WriteObjectStart();
                        if (customCookbooksSource != null && customCookbooksSource.IsSetType())
                        {
                            writer.WritePropertyName("Type");
                            writer.Write(customCookbooksSource.Type);
                        }
                        if (customCookbooksSource != null && customCookbooksSource.IsSetUrl())
                        {
                            writer.WritePropertyName("Url");
                            writer.Write(customCookbooksSource.Url);
                        }
                        if (customCookbooksSource != null && customCookbooksSource.IsSetUsername())
                        {
                            writer.WritePropertyName("Username");
                            writer.Write(customCookbooksSource.Username);
                        }
                        if (customCookbooksSource != null && customCookbooksSource.IsSetPassword())
                        {
                            writer.WritePropertyName("Password");
                            writer.Write(customCookbooksSource.Password);
                        }
                        if (customCookbooksSource != null && customCookbooksSource.IsSetSshKey())
                        {
                            writer.WritePropertyName("SshKey");
                            writer.Write(customCookbooksSource.SshKey);
                        }
                        if (customCookbooksSource != null && customCookbooksSource.IsSetRevision())
                        {
                            writer.WritePropertyName("Revision");
                            writer.Write(customCookbooksSource.Revision);
                        }
                        writer.WriteObjectEnd();
                    }
                }
                if (cloneStackRequest != null && cloneStackRequest.IsSetDefaultSshKeyName())
                {
                    writer.WritePropertyName("DefaultSshKeyName");
                    writer.Write(cloneStackRequest.DefaultSshKeyName);
                }
                if (cloneStackRequest != null && cloneStackRequest.IsSetClonePermissions())
                {
                    writer.WritePropertyName("ClonePermissions");
                    writer.Write(cloneStackRequest.ClonePermissions);
                }

                if (cloneStackRequest != null && cloneStackRequest.CloneAppIds != null && cloneStackRequest.CloneAppIds.Count > 0)
                {
                    List <string> cloneAppIdsList = cloneStackRequest.CloneAppIds;
                    writer.WritePropertyName("CloneAppIds");
                    writer.WriteArrayStart();

                    foreach (string cloneAppIdsListValue in cloneAppIdsList)
                    {
                        writer.Write(StringUtils.FromString(cloneAppIdsListValue));
                    }

                    writer.WriteArrayEnd();
                }
                if (cloneStackRequest != null && cloneStackRequest.IsSetDefaultRootDeviceType())
                {
                    writer.WritePropertyName("DefaultRootDeviceType");
                    writer.Write(cloneStackRequest.DefaultRootDeviceType);
                }

                writer.WriteObjectEnd();

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


            return(request);
        }
Example #35
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);
        }
Example #36
0
        public IRequest Marshall(DescribeCasesRequest describeCasesRequest)
        {
            IRequest request = new DefaultRequest(describeCasesRequest, "AmazonAWSSupport");
            string   target  = "AWSSupport_20130415.DescribeCases";

            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 (describeCasesRequest != null && describeCasesRequest.CaseIdList != null && describeCasesRequest.CaseIdList.Count > 0)
                {
                    List <string> caseIdListList = describeCasesRequest.CaseIdList;
                    writer.WritePropertyName("caseIdList");
                    writer.WriteArrayStart();

                    foreach (string caseIdListListValue in caseIdListList)
                    {
                        writer.Write(StringUtils.FromString(caseIdListListValue));
                    }

                    writer.WriteArrayEnd();
                }
                if (describeCasesRequest != null && describeCasesRequest.IsSetDisplayId())
                {
                    writer.WritePropertyName("displayId");
                    writer.Write(describeCasesRequest.DisplayId);
                }
                if (describeCasesRequest != null && describeCasesRequest.IsSetAfterTime())
                {
                    writer.WritePropertyName("afterTime");
                    writer.Write(describeCasesRequest.AfterTime);
                }
                if (describeCasesRequest != null && describeCasesRequest.IsSetBeforeTime())
                {
                    writer.WritePropertyName("beforeTime");
                    writer.Write(describeCasesRequest.BeforeTime);
                }
                if (describeCasesRequest != null && describeCasesRequest.IsSetIncludeResolvedCases())
                {
                    writer.WritePropertyName("includeResolvedCases");
                    writer.Write(describeCasesRequest.IncludeResolvedCases);
                }
                if (describeCasesRequest != null && describeCasesRequest.IsSetNextToken())
                {
                    writer.WritePropertyName("nextToken");
                    writer.Write(describeCasesRequest.NextToken);
                }
                if (describeCasesRequest != null && describeCasesRequest.IsSetMaxResults())
                {
                    writer.WritePropertyName("maxResults");
                    writer.Write(describeCasesRequest.MaxResults);
                }
                if (describeCasesRequest != null && describeCasesRequest.IsSetLanguage())
                {
                    writer.WritePropertyName("language");
                    writer.Write(describeCasesRequest.Language);
                }

                writer.WriteObjectEnd();

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


            return(request);
        }
Example #37
0
        public IRequest Marshall(TerminateJobFlowsRequest terminateJobFlowsRequest)
        {
            IRequest request = new DefaultRequest(terminateJobFlowsRequest, "AmazonElasticMapReduce");
            string   target  = "ElasticMapReduce.TerminateJobFlows";

            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 (terminateJobFlowsRequest != null && terminateJobFlowsRequest.JobFlowIds != null && terminateJobFlowsRequest.JobFlowIds.Count > 0)
                {
                    List <string> jobFlowIdsList = terminateJobFlowsRequest.JobFlowIds;
                    writer.WritePropertyName("JobFlowIds");
                    writer.WriteArrayStart();

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

                    writer.WriteArrayEnd();
                }

                writer.WriteObjectEnd();

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


            return(request);
        }
 public void WriteJson(JsonWriter writer)
 {
     writer.WriteObjectStart();
     if (this.itemSetGroupId != null)
     {
         writer.WritePropertyName("itemSetGroupId");
         writer.Write(this.itemSetGroupId);
     }
     if (this.inventoryName != null)
     {
         writer.WritePropertyName("inventoryName");
         writer.Write(this.inventoryName);
     }
     if (this.userId != null)
     {
         writer.WritePropertyName("userId");
         writer.Write(this.userId);
     }
     if (this.itemName != null)
     {
         writer.WritePropertyName("itemName");
         writer.Write(this.itemName);
     }
     if (this.sortValue.HasValue)
     {
         writer.WritePropertyName("sortValue");
         writer.Write(this.sortValue.Value);
     }
     if (this.itemSetItemSetIdList != null)
     {
         writer.WritePropertyName("itemSetItemSetIdList");
         writer.WriteArrayStart();
         foreach (var item in this.itemSetItemSetIdList)
         {
             writer.Write(item);
         }
         writer.WriteArrayEnd();
     }
     if (this.itemSetNameList != null)
     {
         writer.WritePropertyName("itemSetNameList");
         writer.WriteArrayStart();
         foreach (var item in this.itemSetNameList)
         {
             writer.Write(item);
         }
         writer.WriteArrayEnd();
     }
     if (this.itemSetCountList != null)
     {
         writer.WritePropertyName("itemSetCountList");
         writer.WriteArrayStart();
         foreach (var item in this.itemSetCountList)
         {
             writer.Write(item.Value);
         }
         writer.WriteArrayEnd();
     }
     if (this.itemSetExpiresAtList != null)
     {
         writer.WritePropertyName("itemSetExpiresAtList");
         writer.WriteArrayStart();
         foreach (var item in this.itemSetExpiresAtList)
         {
             writer.Write(item.Value);
         }
         writer.WriteArrayEnd();
     }
     if (this.itemSetCreatedAtList != null)
     {
         writer.WritePropertyName("itemSetCreatedAtList");
         writer.WriteArrayStart();
         foreach (var item in this.itemSetCreatedAtList)
         {
             writer.Write(item.Value);
         }
         writer.WriteArrayEnd();
     }
     if (this.itemSetUpdatedAtList != null)
     {
         writer.WritePropertyName("itemSetUpdatedAtList");
         writer.WriteArrayStart();
         foreach (var item in this.itemSetUpdatedAtList)
         {
             writer.Write(item.Value);
         }
         writer.WriteArrayEnd();
     }
     if (this.createdAt.HasValue)
     {
         writer.WritePropertyName("createdAt");
         writer.Write(this.createdAt.Value);
     }
     if (this.updatedAt.HasValue)
     {
         writer.WritePropertyName("updatedAt");
         writer.Write(this.updatedAt.Value);
     }
     writer.WriteObjectEnd();
 }
Example #39
0
        public IRequest Marshall(DescribeElasticIpsRequest describeElasticIpsRequest)
        {
            IRequest request = new DefaultRequest(describeElasticIpsRequest, "AmazonOpsWorks");
            string   target  = "OpsWorks_20130218.DescribeElasticIps";

            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 (describeElasticIpsRequest != null && describeElasticIpsRequest.IsSetInstanceId())
                {
                    writer.WritePropertyName("InstanceId");
                    writer.Write(describeElasticIpsRequest.InstanceId);
                }

                if (describeElasticIpsRequest != null && describeElasticIpsRequest.Ips != null && describeElasticIpsRequest.Ips.Count > 0)
                {
                    List <string> ipsList = describeElasticIpsRequest.Ips;
                    writer.WritePropertyName("Ips");
                    writer.WriteArrayStart();

                    foreach (string ipsListValue in ipsList)
                    {
                        writer.Write(StringUtils.FromString(ipsListValue));
                    }

                    writer.WriteArrayEnd();
                }

                writer.WriteObjectEnd();

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


            return(request);
        }
Example #40
0
        public IRequest Marshall(AddCacheRequest addCacheRequest)
        {
            IRequest request = new DefaultRequest(addCacheRequest, "AmazonStorageGateway");
            string   target  = "StorageGateway_20120630.AddCache";

            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 (addCacheRequest != null && addCacheRequest.IsSetGatewayARN())
                {
                    writer.WritePropertyName("GatewayARN");
                    writer.Write(addCacheRequest.GatewayARN);
                }

                if (addCacheRequest != null && addCacheRequest.DiskIds != null && addCacheRequest.DiskIds.Count > 0)
                {
                    List <string> diskIdsList = addCacheRequest.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);
        }
Example #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();
    }
    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
    }
        public IRequest Marshall(BatchWriteItemRequest batchWriteItemRequest)
        {
            IRequest request = new DefaultRequest(batchWriteItemRequest, "AmazonDynamoDB");
            string   target  = "DynamoDB_20111205.BatchWriteItem";

            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 (batchWriteItemRequest != null)
                {
                    if (batchWriteItemRequest.RequestItems != null)
                    {
                        writer.WritePropertyName("RequestItems");
                        writer.WriteObjectStart();
                        foreach (string batchWriteItemRequestRequestItemsKey in batchWriteItemRequest.RequestItems.Keys)
                        {
                            List <WriteRequest> requestItemsListValue;
                            bool requestItemsListValueHasValue = batchWriteItemRequest.RequestItems.TryGetValue(batchWriteItemRequestRequestItemsKey, out requestItemsListValue);
                            writer.WritePropertyName(batchWriteItemRequestRequestItemsKey);

                            writer.WriteArrayStart();
                            if (requestItemsListValue != null)
                            {
                                foreach (WriteRequest valueListValue in requestItemsListValue)
                                {
                                    writer.WriteObjectStart();

                                    if (valueListValue != null)
                                    {
                                        PutRequest putRequest = valueListValue.PutRequest;
                                        if (putRequest != null)
                                        {
                                            writer.WritePropertyName("PutRequest");
                                            writer.WriteObjectStart();
                                            if (putRequest != null)
                                            {
                                                if (putRequest.Item != null)
                                                {
                                                    writer.WritePropertyName("Item");
                                                    writer.WriteObjectStart();
                                                    foreach (string putRequestItemKey in putRequest.Item.Keys)
                                                    {
                                                        AttributeValue itemListValue;
                                                        bool           itemListValueHasValue = putRequest.Item.TryGetValue(putRequestItemKey, out itemListValue);
                                                        writer.WritePropertyName(putRequestItemKey);

                                                        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();
                                                }
                                            }
                                            writer.WriteObjectEnd();
                                        }
                                    }

                                    if (valueListValue != null)
                                    {
                                        DeleteRequest deleteRequest = valueListValue.DeleteRequest;
                                        if (deleteRequest != null)
                                        {
                                            writer.WritePropertyName("DeleteRequest");
                                            writer.WriteObjectStart();

                                            if (deleteRequest != null)
                                            {
                                                Key key = deleteRequest.Key;
                                                if (key != null)
                                                {
                                                    writer.WritePropertyName("Key");
                                                    writer.WriteObjectStart();

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

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

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

                                                                writer.WriteArrayEnd();
                                                            }

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

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

                                                                writer.WriteArrayEnd();
                                                            }

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

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

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

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

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

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

                                                                writer.WriteArrayEnd();
                                                            }

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

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

                                                                writer.WriteArrayEnd();
                                                            }

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

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

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

                writer.WriteObjectEnd();

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


            return(request);
        }
Example #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"]);
     }
 }
Example #45
0
        // Writes a JSON representation of the given DynamoDBEntry
        private static void WriteJson(DynamoDBEntry entry, JsonWriter writer, DynamoDBEntryConversion conversion)
        {
            entry = entry.ToConvertedEntry(conversion);

            var document = entry as Document;

            if (document != null)
            {
                writer.WriteObjectStart();

                // Both item attributes and entries in M type are unordered, so sorting by key
                // http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DataModel.html#DataModel.DataTypes
                foreach (var kvp in document)
                {
                    var name  = kvp.Key;
                    var value = kvp.Value;

                    writer.WritePropertyName(name);
                    WriteJson(value, writer, conversion);
                }
                writer.WriteObjectEnd();
                return;
            }

            var primitive = entry as Primitive;

            if (primitive != null)
            {
                var type  = primitive.Type;
                var value = primitive.Value;
                WritePrimitive(writer, type, value);
                return;
            }

            var primitiveList = entry as PrimitiveList;

            if (primitiveList != null)
            {
                var itemType = primitiveList.Type;

                writer.WriteArrayStart();
                foreach (var item in primitiveList.Entries)
                {
                    var itemValue = item.Value;
                    WritePrimitive(writer, itemType, itemValue);
                }
                writer.WriteArrayEnd();
                return;
            }

            var ddbList = entry as DynamoDBList;

            if (ddbList != null)
            {
                writer.WriteArrayStart();
                foreach (var item in ddbList.Entries)
                {
                    WriteJson(item, writer, conversion);
                }
                writer.WriteArrayEnd();
                return;
            }

            var ddbBool = entry as DynamoDBBool;

            if (ddbBool != null)
            {
                writer.Write(ddbBool.Value);
                return;
            }

            var ddbNull = entry as DynamoDBNull;

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

            throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
                                                              "Unable to convert entry of type {0} to JSON", entry.GetType().FullName));
        }
        public IRequest Marshall(DescribeObjectsRequest describeObjectsRequest)
        {
            IRequest request = new DefaultRequest(describeObjectsRequest, "AmazonDataPipeline");
            string   target  = "DataPipeline.DescribeObjects";

            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 (describeObjectsRequest != null && describeObjectsRequest.IsSetPipelineId())
                {
                    writer.WritePropertyName("pipelineId");
                    writer.Write(describeObjectsRequest.PipelineId);
                }

                if (describeObjectsRequest != null && describeObjectsRequest.ObjectIds != null && describeObjectsRequest.ObjectIds.Count > 0)
                {
                    List <string> objectIdsList = describeObjectsRequest.ObjectIds;
                    writer.WritePropertyName("objectIds");
                    writer.WriteArrayStart();

                    foreach (string objectIdsListValue in objectIdsList)
                    {
                        writer.Write(StringUtils.FromString(objectIdsListValue));
                    }

                    writer.WriteArrayEnd();
                }
                if (describeObjectsRequest != null && describeObjectsRequest.IsSetEvaluateExpressions())
                {
                    writer.WritePropertyName("evaluateExpressions");
                    writer.Write(describeObjectsRequest.EvaluateExpressions);
                }
                if (describeObjectsRequest != null && describeObjectsRequest.IsSetMarker())
                {
                    writer.WritePropertyName("marker");
                    writer.Write(describeObjectsRequest.Marker);
                }

                writer.WriteObjectEnd();

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


            return(request);
        }
Example #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"]);
        }
    }
Example #48
0
        public static void WriteData()
        {
            stringBuilder = new StringBuilder();
            writer        = new JsonWriter(stringBuilder);
            writer.WriteObjectStart();

            writer.WritePropertyName("spot_id");
            writer.Write(spot_id);
            writer.WritePropertyName("if_enemy_die");
            writer.Write(if_enemy_die);
            writer.WritePropertyName("current_time");
            writer.Write(GameData.GetCurrentTimeStamp());
            writer.WritePropertyName("boss_hp");
            writer.Write(boss_hp);
            writer.WritePropertyName("mvp");
            writer.Write(mvp);
            writer.WritePropertyName("last_battle_info");
            writer.Write("");

            writer.WritePropertyName("guns");
            writer.WriteArrayStart();
            foreach (var item in Teams[teamLoc].teaminfo)
            {
                writer.WriteObjectStart();
                writer.WritePropertyName("id");
                writer.Write(item.Value.id);
                writer.WritePropertyName("life");
                writer.Write(item.Value.life);
                writer.WriteObjectEnd();
            }
            writer.WriteArrayEnd();

            writer.WritePropertyName("user_rec");
            StringBuilder stringBuilder1 = new StringBuilder();
            JsonWriter    jsonWriter1    = new JsonWriter(stringBuilder1);

            jsonWriter1.WriteObjectStart();
            jsonWriter1.WritePropertyName("seed");
            jsonWriter1.Write(Teams[teamLoc].getSeed(user_exp));
            jsonWriter1.WritePropertyName("record");
            jsonWriter1.WriteArrayStart();
            //foreach (var current in user_rec.listRecord)
            //{
            //    jsonWriter1.Write(current.ToString());
            //}
            jsonWriter1.WriteArrayEnd();
            jsonWriter1.WriteObjectEnd();
            writer.Write(stringBuilder1.ToString());


            Random random = new Random();

            writer.WritePropertyName("1000");
            writer.WriteObjectStart();
            writer.WritePropertyName("10");
            writer.Write(Teams[teamLoc].TeamEffect);
            writer.WritePropertyName("11");
            writer.Write(Teams[teamLoc].TeamEffect - life_reduce);
            writer.WritePropertyName("12");
            writer.Write(Teams[teamLoc].TeamEffect);
            writer.WritePropertyName("13");
            writer.Write(Teams[teamLoc].TeamEffect);
            writer.WritePropertyName("15");
            writer.Write(enemy_effect_client);

            writer.WritePropertyName("16");
            writer.Write(0);

            writer.WritePropertyName("17");
            writer.Write(truetime * 29.7);//要 4场战斗 不同的时间 总帧数

            writer.WritePropertyName("33");
            writer.Write(enemy_character_type_id);//改

            writer.WritePropertyName("40");
            writer.Write(128);//我也不知道是什么

            writer.WritePropertyName("18");
            writer.Write(life_reduce);
            writer.WritePropertyName("19");
            writer.Write((int)(life_reduce * (double)random.Next(10, 20) / 10));


            writer.WritePropertyName("20");
            writer.Write(0);
            writer.WritePropertyName("21");
            writer.Write(0);
            writer.WritePropertyName("22");
            writer.Write(0);
            writer.WritePropertyName("23");
            writer.Write(0);
            writer.WritePropertyName("24");
            writer.Write(life_enemy);//要 damage_enemy 4场战斗不同的数据
            writer.WritePropertyName("25");
            writer.Write(0);
            writer.WritePropertyName("26");
            writer.Write(life_enemy);       //要 life_enemy 4场战斗不同的数据
            writer.WritePropertyName("27");
            writer.Write(truetime);         // 要 实际时间 4场战斗不同的数据

            writer.WritePropertyName("34"); //  min_damage_armor = "34";
            writer.Write(0);
            writer.WritePropertyName("35"); //  min_damage_no_armor = "35";
            writer.Write(0);
            writer.WritePropertyName("41"); //max_damage;
            writer.Write(0);
            writer.WritePropertyName("42");
            writer.Write(0);
            writer.WritePropertyName("43");
            writer.Write(0);
            writer.WritePropertyName("44");
            writer.Write(0);
            writer.WriteObjectEnd();

            writer.WritePropertyName("1001");
            writer.WriteObjectStart();
            writer.WriteObjectEnd();
            writer.WritePropertyName("1002");
            writer.WriteObjectStart();

            foreach (var item in Teams[teamLoc].teaminfo)
            {
                writer.WritePropertyName(item.Value.id.ToString());
                writer.WriteObjectStart();
                writer.WritePropertyName("47");
                writer.Write(2);
                writer.WriteObjectEnd();
            }
            writer.WriteObjectEnd();
            writer.WritePropertyName("1003");
            writer.WriteObjectStart();
            writer.WriteObjectEnd();

            writer.WritePropertyName("battle_damage");
            writer.WriteObjectStart();
            writer.WriteObjectEnd();
            writer.WriteObjectEnd();
        }
    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();
    }
Example #50
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();
            }
        }
		/// <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();
			}
		}
Example #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();
			}
		}