Beispiel #1
0
        public override async Task <SearchOpponentRespons> SearchOpponent(SearchOpponentRequest request, ServerCallContext context)
        {
            try
            {
                BoardGamesOnline.Models.Match match = await this.service.SearchOpponentAsync(new SearchOpponent { GameType = (GameTypes)request.GameType, UserId = request.UserId });

                if (match == null)
                {
                    return(new SearchOpponentRespons {
                        Respons = new ServerResponse {
                            Status = ServiceResponseStatus.Cancel
                        }
                    });
                }

                Match mapMatch = Mapping.Mapper.Map <Match>(match);

                return(new SearchOpponentRespons {
                    Match = mapMatch, Respons = new ServerResponse {
                        Status = ServiceResponseStatus.Ok
                    }
                });
            }
            catch (Exception e)
            {
                MapField <string, string> mf = new MapField <string, string>();
                mf.Add("Exception", e.Message);
                return(new SearchOpponentRespons {
                    Respons = new ServerResponse {
                        Status = ServiceResponseStatus.Error, Messages = { mf }
                    }
                });
            }
        }
        /// <summary>
        /// Convert from <see cref="PropertyBag"/> to a <see cref="MapField{key,value}"/>
        /// </summary>
        /// <param name="propertyBag"><see cref="PropertyBag"/> to convert from</param>
        /// <returns>Converted <see cref="MapField{key,value}"/></returns>
        public static MapField <string, System.Protobuf.Object> ToProtobuf(this PropertyBag propertyBag)
        {
            var mapField = new MapField <string, System.Protobuf.Object>();

            propertyBag.ForEach(keyValue =>
            {
                var obj  = new System.Protobuf.Object();
                var type = keyValue.Value.GetProtobufType();
                obj.Type = (int)type;

                var stream = new MemoryStream();
                using (var outputStream = new CodedOutputStream(stream))
                {
                    keyValue.Value.WriteWithTypeTo(type, outputStream);
                    outputStream.Flush();
                    stream.Flush();
                    stream.Seek(0, SeekOrigin.Begin);
                    obj.Content = ByteString.CopyFrom(stream.ToArray());
                }

                mapField.Add(keyValue.Key, obj);
            });

            return(mapField);
        }
Beispiel #3
0
 private void SetServers(MapField <string, string> res)
 {
     foreach (var s in PupExec.Servs)
     {
         res.Add(s.Key, s.Value.URL);
     }
 }
 private void InternalAdd(TKey key, TValue value)
 {
     _internal.Add(key, value);
     if (_isMessageType)
     {
         SetParent(key, value);
     }
 }
Beispiel #5
0
        public static void AddLabels(this MapField <string, string> map)
        {
            var settings = Properties.Settings.Default;

            if (!string.IsNullOrWhiteSpace(settings.LabelKey))
            {
                map.Add(settings.LabelKey, settings.LabelValue);
            }
        }
Beispiel #6
0
 /// <summary>
 /// Adds a GQL parameter with the specified value.
 /// </summary>
 /// <param name="parameters">The mapping of GQL query parameters to add to. Must not be null.</param>
 /// <param name="parameterName">The name of the parameter. Must not be null.</param>
 /// <param name="value">The value to add.  May be null, which indicates
 /// a value with <see cref="Value.NullValue"/> set.</param>
 public static void Add(this MapField <string, GqlQueryParameter> parameters, string parameterName, Value value)
 {
     GaxPreconditions.CheckNotNull(parameters, nameof(parameters));
     GaxPreconditions.CheckNotNull(parameterName, nameof(parameterName));
     GaxPreconditions.CheckNotNull(value, nameof(value));
     parameters.Add(parameterName, new GqlQueryParameter {
         Value = value ?? Value.ForNull()
     });
 }
Beispiel #7
0
        public MapField <string, float> Convert(IScoring scoring, ResolutionContext context)
        {
            var response = new MapField <string, float>();

            foreach (var(statName, statWeighting) in scoring)
            {
                response.Add(statName, statWeighting);
            }

            return(response);
        }
Beispiel #8
0
    void Start()
    {
        //get transforms of cars
        for (int i = 0; i < cars.Count(); i++)
        {
            var newTrans = new GameObject().transform;
            newTrans.localPosition = cars[i].transform.localPosition;
            newTrans.localRotation = cars[i].transform.localRotation;

            carTransforms.Add(i, newTrans);
        }
    }
Beispiel #9
0
 public void AddField(MapField <string, Value> fields, String fieldName, long fieldValue)
 {
     if (fields.ContainsKey(fieldName))
     {
         fields[fieldName].IntegerValue = fieldValue;
     }
     else
     {
         Value value = new Value();
         value.IntegerValue = fieldValue;
         fields.Add(fieldName, value);
     }
 }
Beispiel #10
0
 public void AddField(MapField <string, Value> fields, String fieldName, String fieldValue)
 {
     if (fields.ContainsKey(fieldName))
     {
         fields[fieldName].StringValue = fieldValue;
     }
     else
     {
         Value strValue = new Value();
         strValue.StringValue = fieldValue;
         fields.Add(fieldName, strValue);
     }
 }
Beispiel #11
0
        public static MapField <string, string> ToMapFields(Dictionary <string, string> tags)
        {
            MapField <string, string> keyValuePairs = new MapField <string, string>();

            if (tags != null)
            {
                foreach (var item in tags)
                {
                    keyValuePairs.Add(item.Key, item.Value);
                }
            }
            return(keyValuePairs);
        }
Beispiel #12
0
        //Create message payload
        public PubsubMessage GetPubSubMessage(bool ruleActionCompleted, MapField <String, String> attributes)
        {
            attributes.Add("RuleActionExecuted", ruleActionCompleted.ToString());

            PubsubMessage message = new PubsubMessage
            {
                // The data is any arbitrary ByteString. Here, we're using text.
                Data = ByteString.CopyFromUtf8("Rule action executed notification"),
                // The attributes provide metadata in a string-to-string dictionary.
                Attributes = { attributes }
            };

            return(message);
        }
Beispiel #13
0
        /// <summary>
        /// Adds all the items contained in <paramref name="items"/> to the given <see cref="MapField{TKey,TValue}" />.
        /// </summary>
        /// <param name="map">The collections items should be added to.</param>
        /// <param name="items">The items to add to the collection.</param>
        /// <typeparam name="TKey">The type of the key of the map.</typeparam>
        /// <typeparam name="TValue">The type of the values of the map.</typeparam>
        public static void Add <TKey, TValue>(this MapField <TKey, TValue> map, IReadOnlyDictionary <TKey, TValue> items)
        {
            _ = map ?? throw new ArgumentNullException(nameof(map));

            if (items is null)
            {
                return;
            }

            foreach (var item in items)
            {
                map.Add(item.Key, item.Value);
            }
        }
Beispiel #14
0
        /// <summary>
        /// Dictionary<string, string> convert MapField<string, ByteString>
        /// </summary>
        /// <param name="map"></param>
        /// <returns></returns>
        public static MapField <string, ByteString> ConvertMapField(Dictionary <string, string> map)
        {
            var res = new MapField <string, ByteString>();

            if (map != null && map.Count > 0)
            {
                foreach (var item in map)
                {
                    res.Add(item.Key, ConvertToByteString(item.Value));
                }
            }

            return(res);
        }
Beispiel #15
0
        private static MapField <string, string> MetadataToMap(Metadata metadata)
        {
            var dict = new MapField <string, string>();

            if (metadata == null)
            {
                return(dict);
            }

            foreach (var e in metadata)
            {
                if (e.IsBinary)
                {
                    dict.Add(e.Key + " (binary)", Convert.ToBase64String(e.ValueBytes));
                }
                else
                {
                    dict.Add(e.Key, e.Value);
                }
            }

            return(dict);
        }
 public void MergeFrom(PlayerStats other)
 {
     if (other != null)
     {
         if (other.PlayerId != 0)
         {
             PlayerId = other.PlayerId;
         }
         if (other.FightId != 0)
         {
             FightId = other.FightId;
         }
         stats_.Add((IDictionary <int, int>)other.stats_);
         titles_.Add((IEnumerable <int>)other.titles_);
         _unknownFields = UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
     }
 }
        internal AzFunctionInfo(RpcFunctionMetadata metadata)
        {
            FunctionName = metadata.Name;
            Directory    = metadata.Directory;
            EntryPoint   = metadata.EntryPoint;
            ScriptPath   = metadata.ScriptFile;

            AllBindings    = new MapField <string, BindingInfo>();
            OutputBindings = new MapField <string, BindingInfo>();

            foreach (var binding in metadata.Bindings)
            {
                string      bindingName = binding.Key;
                BindingInfo bindingInfo = binding.Value;

                AllBindings.Add(bindingName, bindingInfo);

                // PowerShell doesn't support the 'InOut' type binding
                if (bindingInfo.Direction == BindingInfo.Types.Direction.In)
                {
                    switch (bindingInfo.Type)
                    {
                    case OrchestrationTrigger:
                        Type = AzFunctionType.OrchestrationFunction;
                        break;

                    case ActivityTrigger:
                        Type = AzFunctionType.ActivityFunction;
                        break;

                    default:
                        Type = AzFunctionType.RegularFunction;
                        break;
                    }
                    continue;
                }

                if (bindingInfo.Direction == BindingInfo.Types.Direction.Out)
                {
                    OutputBindings.Add(bindingName, bindingInfo);
                }
            }
        }
Beispiel #18
0
        public Cards(IEnumerable <SabberStoneCore.Model.Card> allCards)
        {
            cards_ = new MapField <int, Card>();

            foreach (var card in allCards)
            {
                if (card.Name == null)
                {
                    continue;
                }

                cards_.Add(card.AssetId, new Card
                {
                    Id       = card.AssetId,
                    Name     = card.Name,
                    StringId = card.Id
                });
            }
        }
        public FunctionInfo(RpcFunctionMetadata metadata)
        {
            FunctionName = metadata.Name;
            Directory    = metadata.Directory;
            EntryPoint   = metadata.EntryPoint;
            ScriptPath   = metadata.ScriptFile;

            AllBindings    = new MapField <string, BindingInfo>();
            OutputBindings = new MapField <string, BindingInfo>();

            foreach (var binding in metadata.Bindings)
            {
                AllBindings.Add(binding.Key, binding.Value);

                // PowerShell doesn't support the 'InOut' type binding
                if (binding.Value.Direction == BindingInfo.Types.Direction.Out)
                {
                    OutputBindings.Add(binding.Key, binding.Value);
                }
            }
        }
Beispiel #20
0
 public void MergeFrom(FightSnapshot other)
 {
     if (other != null)
     {
         if (other.FightId != 0)
         {
             FightId = other.FightId;
         }
         entities_.Add((IEnumerable <Types.EntitySnapshot>)other.entities_);
         if (other.TurnIndex != 0)
         {
             TurnIndex = other.TurnIndex;
         }
         if (other.TurnRemainingTimeSec != 0)
         {
             TurnRemainingTimeSec = other.TurnRemainingTimeSec;
         }
         playersCompanions_.Add((IDictionary <int, Types.Companions>)other.playersCompanions_);
         playersCardsCount_.Add((IDictionary <int, int>)other.playersCardsCount_);
         _unknownFields = UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
     }
 }
Beispiel #21
0
        public FieldObject Terminate()
        {
            if (sideEffectStates.Count == 1)
            {
                Tuple <string, IAggregateFunction> tuple = sideEffectStates[0];
                IAggregateFunction sideEffectState       = tuple.Item2;

                return(sideEffectState.Terminate());
            }
            else
            {
                MapField map = new MapField();

                foreach (Tuple <string, IAggregateFunction> tuple in sideEffectStates)
                {
                    string             key             = tuple.Item1;
                    IAggregateFunction sideEffectState = tuple.Item2;

                    map.Add(new StringField(key), sideEffectState.Terminate());
                }

                return(map);
            }
        }
Beispiel #22
0
        internal override List <RawRecord> CrossApply(RawRecord record)
        {
            MapField valueMap = new MapField();

            FieldObject inputTarget = record[this.inputTargetIndex];

            if (inputTarget is VertexField)
            {
                VertexField vertexField = (VertexField)inputTarget;

                if (this.propertyNameList.Any())
                {
                    foreach (string propertyName in this.propertyNameList)
                    {
                        FieldObject property = vertexField[propertyName];
                        if (property == null)
                        {
                            continue;
                        }

                        List <FieldObject>  values = new List <FieldObject>();
                        VertexPropertyField vp     = property as VertexPropertyField;
                        if (vp != null)
                        {
                            foreach (VertexSinglePropertyField vsp in vp.Multiples.Values)
                            {
                                values.Add(vsp);
                            }
                        }

                        valueMap.Add(new StringField(propertyName), new CollectionField(values));
                    }
                }
                else
                {
                    foreach (VertexPropertyField property in vertexField.VertexProperties.Values)
                    {
                        string propertyName = property.PropertyName;
                        Debug.Assert(!VertexField.IsVertexMetaProperty(propertyName));
                        Debug.Assert(!propertyName.Equals(KW_VERTEX_EDGE));
                        Debug.Assert(!propertyName.Equals(KW_VERTEX_REV_EDGE));

                        switch (propertyName)
                        {
                        case "_rid":
                        case "_self":
                        case "_etag":
                        case "_attachments":
                        case "_ts":
                            continue;

                        default:
                            List <FieldObject> values = new List <FieldObject>();
                            foreach (VertexSinglePropertyField singleVp in property.Multiples.Values)
                            {
                                values.Add(singleVp);
                            }
                            valueMap.Add(new StringField(propertyName), new CollectionField(values));
                            break;
                        }
                    }
                }
            }
            else if (inputTarget is EdgeField)
            {
                EdgeField edgeField = (EdgeField)inputTarget;

                if (this.propertyNameList.Any())
                {
                    foreach (string propertyName in this.propertyNameList)
                    {
                        FieldObject property = edgeField[propertyName];
                        if (property == null)
                        {
                            continue;
                        }

                        EdgePropertyField edgePf = property as EdgePropertyField;
                        if (edgePf != null)
                        {
                            valueMap.Add(new StringField(propertyName), edgePf);
                        }
                    }
                }
                else
                {
                    foreach (KeyValuePair <string, EdgePropertyField> propertyPair in edgeField.EdgeProperties)
                    {
                        string            propertyName      = propertyPair.Key;
                        EdgePropertyField edgePropertyField = propertyPair.Value;

                        switch (propertyName)
                        {
                        // Reserved properties for meta-data
                        case KW_EDGE_ID:
                        //case KW_EDGE_OFFSET:
                        case KW_EDGE_SRCV:
                        case KW_EDGE_SINKV:
                        case KW_EDGE_SRCV_LABEL:
                        case KW_EDGE_SINKV_LABEL:
                            continue;

                        default:
                            valueMap.Add(new StringField(propertyName), edgePropertyField);
                            break;
                        }
                    }
                }
            }
            else if (inputTarget is VertexSinglePropertyField)
            {
                VertexSinglePropertyField singleVp = inputTarget as VertexSinglePropertyField;

                if (this.propertyNameList.Any())
                {
                    foreach (string propertyName in this.propertyNameList)
                    {
                        FieldObject property = singleVp[propertyName];
                        if (property == null)
                        {
                            continue;
                        }

                        ValuePropertyField metaPf = property as ValuePropertyField;
                        if (metaPf != null)
                        {
                            valueMap.Add(new StringField(propertyName), metaPf);
                        }
                    }
                }
                else
                {
                    foreach (KeyValuePair <string, ValuePropertyField> kvp in singleVp.MetaProperties)
                    {
                        valueMap.Add(new StringField(kvp.Key), kvp.Value);
                    }
                }
            }
            else
            {
                throw new GraphViewException("The input of valueMap() cannot be a meta or edge property.");
            }

            RawRecord result = new RawRecord();

            result.Append(valueMap);
            return(new List <RawRecord> {
                result
            });
        }
Beispiel #23
0
 public void MergeFrom(EntitySnapshot other)
 {
     if (other == null)
     {
         return;
     }
     if (other.EntityId != 0)
     {
         EntityId = other.EntityId;
     }
     if (other.EntityType != 0)
     {
         EntityType = other.EntityType;
     }
     if (other.name_ != null && (name_ == null || other.Name != ""))
     {
         Name = other.Name;
     }
     if (other.defId_.HasValue && (!defId_.HasValue || other.DefId != 0))
     {
         DefId = other.DefId;
     }
     if (other.weaponId_.HasValue && (!weaponId_.HasValue || other.WeaponId != 0))
     {
         WeaponId = other.WeaponId;
     }
     if (other.genderId_.HasValue && (!genderId_.HasValue || other.GenderId != 0))
     {
         GenderId = other.GenderId;
     }
     if (other.playerIndexInFight_.HasValue && (!playerIndexInFight_.HasValue || other.PlayerIndexInFight != 0))
     {
         PlayerIndexInFight = other.PlayerIndexInFight;
     }
     if (other.ownerId_.HasValue && (!ownerId_.HasValue || other.OwnerId != 0))
     {
         OwnerId = other.OwnerId;
     }
     if (other.teamId_.HasValue && (!teamId_.HasValue || other.TeamId != 0))
     {
         TeamId = other.TeamId;
     }
     if (other.level_.HasValue && (!level_.HasValue || other.Level != 0))
     {
         Level = other.Level;
     }
     properties_.Add((IEnumerable <int>)other.properties_);
     if (other.position_ != null)
     {
         if (position_ == null)
         {
             position_ = new CellCoord();
         }
         Position.MergeFrom(other.Position);
     }
     if (other.direction_.HasValue && (!direction_.HasValue || other.Direction != 0))
     {
         Direction = other.Direction;
     }
     caracs_.Add((IDictionary <int, int>)other.caracs_);
     if (other.customSkin_ != null && (customSkin_ == null || other.CustomSkin != ""))
     {
         CustomSkin = other.CustomSkin;
     }
     if (other.actionDoneThisTurn_.HasValue && (!actionDoneThisTurn_.HasValue || other.ActionDoneThisTurn != false))
     {
         ActionDoneThisTurn = other.ActionDoneThisTurn;
     }
     _unknownFields = UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
 }
Beispiel #24
0
        public async Task <ActionResult> HandleRequest([FromBody] dynamic request)
        {  // Read the request JSON asynchronously, as the Google.Protobuf library
           // doesn't (yet) support asynchronous parsing.
           //string requestJson;
           //using (TextReader reader = new StreamReader(Request.Body))
           //{
           //    requestJson = await reader.ReadToEndAsync();
           //}

            //// Parse the body of the request using the Protobuf JSON parser,
            //// *not* Json.NET.
            //var request = jsonParser.Parse<WebhookRequest>(requestJson);

            // Note: you should authenticate the request here.

            var message = new Message
            {
                Text = new Text
                {
                    Text_ = { "Hello world" }
                }
            };


            var payload = new MapField <string, Value>();

            var responseText = "Hello word";
            var textToSpeech = new Value
            {
                StringValue = responseText
            };

            var simpleResponse = new Struct
            {
            };

            simpleResponse.Fields.Add("textToSpeech", textToSpeech);


            var googlePayload = new Google.Protobuf.WellKnownTypes.Value
            {
                StructValue = new Google.Protobuf.WellKnownTypes.Struct
                {
                }
            };

            payload.Add("google", googlePayload);



            // Populate the response
            var response = new WebhookResponse()
            {
                FulfillmentMessages = { message },
                Payload             = new Google.Protobuf.WellKnownTypes.Struct
                {
                    Fields = { payload }
                }
            };

            // Ask Protobuf to format the JSON to return.
            // Again, we don't want to use Json.NET - it doesn't know how to handle Struct
            // values etc.
            string responseJson = response.ToString();

            return(Content(responseJson, "application/json"));
        }
        public void Null_Capability_Value_Throws_Error()
        {
            MapField <string, string> addedCapabilities = new MapField <string, string>();

            Assert.Throws <ArgumentNullException>(() => addedCapabilities.Add(testCapability2, null));
        }
 internal void Load(FunctionLoadRequest request)
 {
     // TODO: catch "load" issues at "func start" time.
     // ex. Script doesn't exist, entry point doesn't exist
     _loadedFunctions.Add(request.FunctionId, new AzFunctionInfo(request.Metadata));
 }
        public T ReadField <T>(int tag)
        {
            Type type = typeof(T);

            if (type == typeof(ByteField))
            {
                return((T)(object)new ByteField(tag, Read <byte>(tag)));
            }
            else if (type == typeof(ShortField))
            {
                return((T)(object)new ShortField(tag, Read <short>(tag)));
            }
            else if (type == typeof(IntField))
            {
                return((T)(object)new IntField(tag, Read <int>(tag)));
            }
            else if (type == typeof(LongField))
            {
                return((T)(object)new LongField(tag, Read <long>(tag)));
            }
            else if (type == typeof(FloatField))
            {
                return((T)(object)new FloatField(tag, Read <float>(tag)));
            }
            else if (type == typeof(DoubleField))
            {
                return((T)(object)new DoubleField(tag, Read <double>(tag)));
            }
            else if (type == typeof(StringField))
            {
                return((T)(object)new StringField(tag, Read <string>(tag)));
            }
            else
            {
                if (SkipToTag(tag))
                {
                    Header header = ReadHeader();
                    switch (header.Type)
                    {
                    case Type_Map:
                        if (type == typeof(MapField))
                        {
                            int count = Read <int>(0);
                            if (count < 0)
                            {
                                throw new Exception("Count invalid.");
                            }
                            MapField result = new MapField(header.Tag);
                            for (int i = 0; i < count; i++)
                            {
                                result.Add(ReadField(), ReadField());
                            }
                            return((T)(object)result);
                        }
                        break;

                    case Type_List:
                        if (type == typeof(ListField))
                        {
                            int count = Read <int>(0);
                            if (count < 0)
                            {
                                throw new Exception("Count invalid.");
                            }
                            ListField result = new ListField(header.Tag);
                            for (int i = 0; i < count; i++)
                            {
                                result.Add(ReadField());
                            }
                            return((T)(object)result);
                        }
                        break;

                    case Type_StructBegin:
                        if (type == typeof(StructField))
                        {
                            StructField result = new StructField(header.Tag);
                            while (true)
                            {
                                Header test = PeakHeader();
                                if (test.Type == Type_StructEnd)
                                {
                                    Seek(test.Count);
                                    break;
                                }
                                JceField field = ReadField();
                                result.Set(field.Tag, field);
                            }
                            return((T)(object)result);
                        }
                        break;

                    case Type_StructEnd:
                        throw new Exception("Got struct end field without struct begin tag.");

                    case Type_Zero:
                        if (type == typeof(ZeroField))
                        {
                            return((T)(object)new ZeroField(header.Tag));
                        }
                        break;

                    case Type_ByteArray:
                        if (type == typeof(ByteArrayField))
                        {
                            Header check = ReadHeader();
                            if (check.Type != Type_Byte)
                            {
                                throw new Exception("Data incorrect in type " + Type_ByteArray + ",except " + Type_Byte + " but got " + header.Type);
                            }
                            int length = Read <int>(0);
                            if (length < 0)
                            {
                                throw new Exception("Length error.");
                            }
                            return((T)(object)new ByteArrayField(header.Tag, Read(length)));
                        }
                        break;

                    default:
                        throw new ArgumentException("Unknown type " + header.Type + ".");
                    }
                    throw new ArgumentException("Type mismatch.");
                }
                throw new Exception("Tag not exists.");
            }
        }