Exemplo n.º 1
0
 /// <summary>
 /// Shifts the list by 1 in a cirular fashion.
 /// </summary>
 /// <param name="oldList">List to shift</param>
 /// <returns>Shifted List</returns>
 public static Google.Protobuf.Collections.RepeatedField <string> Shift(this Google.Protobuf.Collections.RepeatedField <string> oldList)
 {
     Google.Protobuf.Collections.RepeatedField <string> newList = new Google.Protobuf.Collections.RepeatedField <string>();
     for (int i = 0; i < oldList.Count; i++)
     {
         if (i < oldList.Count - 1)
         {
             newList.Add(oldList[i + 1]);
         }
         else
         {
             newList.Add(oldList[0]);
         }
     }
     return(newList);
 }
        /// <summary>
        /// 将list转成RepeatedField集合
        /// </summary>
        /// <typeparam name="T">转换的集合中的数据类型</typeparam>
        /// <param name="list">要转换的集合</param>
        /// <returns></returns>
        public static Google.Protobuf.Collections.RepeatedField <T> ListToRepeatedField <T>(List <T> list)
        {
            Google.Protobuf.Collections.RepeatedField <T> repeatedfieldList = new Google.Protobuf.Collections.RepeatedField <T>();
            foreach (var item in list)
            {
                repeatedfieldList.Add(item);
            }

            return(repeatedfieldList);
        }
        public static Google.Protobuf.Collections.RepeatedField <EntityAnnotation> GetMergedLines(string[] lines, List <EntityAnnotation> rawText)
        {
            var mergedArray = new Google.Protobuf.Collections.RepeatedField <EntityAnnotation>();
            var linesList   = lines.ToList();

            while (linesList.Count != 1)
            {
                var l = linesList.Last();
                linesList.RemoveAt(linesList.Count - 1);

                if (String.IsNullOrEmpty(l))
                {
                    continue;
                }

                var ll     = l;
                var status = true;

                EntityAnnotation mergedElement = new EntityAnnotation();

                while (true)
                {
                    var wElement = rawText.Last();
                    rawText.RemoveAt(rawText.Count - 1);
                    var w = wElement.Description;

                    var index = l.IndexOf(w);

                    if (index >= 0)
                    {
                        // check if the word is inside
                        l = l.Substring(index + w.Length);
                        if (status)
                        {
                            status = false;
                            // set starting coordinates
                            mergedElement = wElement;
                        }

                        if (String.IsNullOrEmpty(l))
                        {
                            // set ending coordinates
                            mergedElement.Description = ll;
                            mergedElement.BoundingPoly.Vertices[1] = wElement.BoundingPoly.Vertices[1];
                            mergedElement.BoundingPoly.Vertices[2] = wElement.BoundingPoly.Vertices[2];
                            mergedArray.Add(mergedElement);
                            break;
                        }
                    }
                }
            }

            return(mergedArray);
        }
        static StackObject *Add_4(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 2);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Int32 @item = ptr_of_this_method->Value;

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            Google.Protobuf.Collections.RepeatedField <System.Int32> instance_of_this_method = (Google.Protobuf.Collections.RepeatedField <System.Int32>) typeof(Google.Protobuf.Collections.RepeatedField <System.Int32>).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            instance_of_this_method.Add(@item);

            return(__ret);
        }
        static StackObject *Add_3(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 2);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Collections.Generic.IEnumerable <System.Single> @values = (System.Collections.Generic.IEnumerable <System.Single>) typeof(System.Collections.Generic.IEnumerable <System.Single>).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 0);
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            Google.Protobuf.Collections.RepeatedField <System.Single> instance_of_this_method = (Google.Protobuf.Collections.RepeatedField <System.Single>) typeof(Google.Protobuf.Collections.RepeatedField <System.Single>).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 0);
            __intp.Free(ptr_of_this_method);

            instance_of_this_method.Add(@values);

            return(__ret);
        }
Exemplo n.º 6
0
        static StackObject *Add_0(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 2);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            Com.Test.Item.one_item @item = (Com.Test.Item.one_item) typeof(Com.Test.Item.one_item).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 0);
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            Google.Protobuf.Collections.RepeatedField <Com.Test.Item.one_item> instance_of_this_method = (Google.Protobuf.Collections.RepeatedField <Com.Test.Item.one_item>) typeof(Google.Protobuf.Collections.RepeatedField <Com.Test.Item.one_item>).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 0);
            __intp.Free(ptr_of_this_method);

            instance_of_this_method.Add(@item);

            return(__ret);
        }
Exemplo n.º 7
0
        public static PutResponse PutContainer(this Channel chan, int size, uint basicACL, uint ttl, ECDsa key, bool debug = false)
        {
            Netmap.PlacementRule rules;

            { // hardcoded placement rule:
                rules = new Netmap.PlacementRule {
                    ReplFactor = 2
                };

                var group     = new Netmap.SFGroup();
                var selectors = new Google.Protobuf.Collections.RepeatedField <Netmap.Select>();

                selectors.Add(
                    new Netmap.Select
                {
                    Count = 3,
                    Key   = "Node",
                });

                group.Selectors.Add(selectors);
                rules.SFGroups.Add(group);
            }

            var req = new PutRequest
            {
                Rules     = rules,
                BasicACL  = basicACL,
                Capacity  = Units.GB * (ulong)size,
                OwnerID   = ByteString.CopyFrom(key.Address()),
                MessageID = ByteString.CopyFrom(new Guid().Bytes()),
            };

            req.SetTTL(ttl);
            req.SignHeader(key, debug);

            return(new Service.ServiceClient(chan).Put(req));
        }
Exemplo n.º 8
0
        private object messageToAllClientsLock = new object();                                             //全局消息锁,保证EndGame消息是最后一个消息
        private void SendMessageToAllClients(MessageType msgType, bool requireGaming = true)               //向所有的客户端发送消息
        {
            var gameObjList = game.GetGameObject();
            var cellColor   = game.GameMap.CellColor;

            var rows = game.GameMap.Cols;
            var cols = game.GameMap.Cols;

            //记录颜色信息,避免重复构造颜色信息
            Google.Protobuf.Collections.RepeatedField <MessageToClient.Types.OneDimVec> msgCellColors = new Google.Protobuf.Collections.RepeatedField <MessageToClient.Types.OneDimVec>();
            for (int x = 0; x < rows; ++x)
            {
                msgCellColors.Add(new MessageToClient.Types.OneDimVec());
                for (int y = 0; y < cols; ++y)
                {
                    msgCellColors[x].RowColors.Add(ConvertTool.ToCommunicationColorType(cellColor[x, y]));
                }
            }

            //记录所有游戏对象信息,避免重复构造游戏对象信息
            Google.Protobuf.Collections.RepeatedField <GameObjInfo> msgGameObjs = new Google.Protobuf.Collections.RepeatedField <GameObjInfo>();
            foreach (var gameObj in gameObjList)
            {
                msgGameObjs.Add(CopyInfo.Auto((GameObject)gameObj));
            }

            //记录所有GUID信息
            Google.Protobuf.Collections.RepeatedField <MessageToClient.Types.OneTeamGUIDs> playerGUIDs = new Google.Protobuf.Collections.RepeatedField <MessageToClient.Types.OneTeamGUIDs>();
            for (int x = 0; x < options.TeamCount; ++x)
            {
                playerGUIDs.Add(new MessageToClient.Types.OneTeamGUIDs());
                for (int y = 0; y < options.PlayerCountPerTeam; ++y)
                {
                    playerGUIDs[x].TeammateGUIDs.Add(communicationToGameID[x, y]);
                }
            }

            lock (messageToAllClientsLock)
            {
                if (!game.GameMap.Timer.IsGaming && requireGaming)
                {
                    return;
                }
                for (int i = 0; i < options.TeamCount; ++i)
                {
                    int teamScore = game.GetTeamScore(i);
                    for (int j = 0; j < options.PlayerCountPerTeam; ++j)
                    {
                        MessageToClient msg = new MessageToClient();
                        msg.TeamID      = i;
                        msg.PlayerID    = j;
                        msg.MessageType = msgType;
                        msg.SelfInfo    = CopyInfo.Player(game.GetPlayerFromTeam(communicationToGameID[i, j]));

                        for (int k = 0; k < options.TeamCount; ++k)
                        {
                            msg.PlayerGUIDs.Add(playerGUIDs[k]);
                        }

                        msg.SelfTeamColor = ConvertTool.ToCommunicationColorType(Map.TeamToColor(i));

                        foreach (var infos in msgGameObjs)
                        {
                            msg.GameObjs.Add(infos);
                        }

                        for (int x = 0; x < rows; ++x)
                        {
                            msg.CellColors.Add(msgCellColors[x]);
                        }

                        msg.TeamScore = teamScore;

                        serverCommunicator.SendMessage(msg);

                        mwr?.WriteOne(msg);
                    }
                }
            }
        }
Exemplo n.º 9
0
        static async Task <object> StreamingMicRecognizeAsync(int seconds)
        {
            if (NAudio.Wave.WaveIn.DeviceCount < 1)
            {
                Console.WriteLine("No microphone!");
                return(-1);
            }
            var speech        = SpeechClient.Create();
            var streamingCall = speech.StreamingRecognize();
            // Write the initial request with the config.
            await streamingCall.WriteAsync(
                new StreamingRecognizeRequest()
            {
                StreamingConfig = new StreamingRecognitionConfig()
                {
                    Config = new RecognitionConfig()
                    {
                        Encoding =
                            RecognitionConfig.Types.AudioEncoding.Linear16,
                        SampleRateHertz = 16000,
                        LanguageCode    = "en",
                    },
                    InterimResults = true,
                }
            });

            // Print responses as they arrive.
            Task printResponses = Task.Run(async() =>
            {
                Google.Protobuf.Collections.RepeatedField <SpeechRecognitionAlternative> list = new Google.Protobuf.Collections.RepeatedField <SpeechRecognitionAlternative>();
                while (await streamingCall.ResponseStream.MoveNext(
                           default(CancellationToken)))
                {
                    foreach (var result in streamingCall.ResponseStream
                             .Current.Results)
                    {
                        foreach (var alternative in result.Alternatives)
                        {
                            list.Add(alternative);
                        }
                    }
                }
                speechResult = list[list.Count - 1].Transcript;
            });
            // Read from the microphone and stream to API.
            object writeLock = new object();
            bool   writeMore = true;
            var    waveIn    = new NAudio.Wave.WaveInEvent();

            waveIn.DeviceNumber   = 0;
            waveIn.WaveFormat     = new NAudio.Wave.WaveFormat(16000, 1);
            waveIn.DataAvailable +=
                (object sender, NAudio.Wave.WaveInEventArgs args) =>
            {
                lock (writeLock)
                {
                    if (!writeMore)
                    {
                        return;
                    }
                    streamingCall.WriteAsync(
                        new StreamingRecognizeRequest()
                    {
                        AudioContent = Google.Protobuf.ByteString
                                       .CopyFrom(args.Buffer, 0, args.BytesRecorded)
                    }).Wait();
                }
            };
            waveIn.StartRecording();
            Console.WriteLine("Speak now.");
            await Task.Delay(TimeSpan.FromSeconds(seconds));

            // Stop recording and shut down.
            waveIn.StopRecording();
            lock (writeLock) writeMore = false;
            await streamingCall.WriteCompleteAsync();

            await printResponses;

            return(0);
        }
Exemplo n.º 10
0
        static private MessageToClient TestMessage(long guid, MessageType msgType)
        {
            var rows = 50;
            var cols = 50;

            //记录颜色信息,避免重复构造颜色信息
            Google.Protobuf.Collections.RepeatedField <MessageToClient.Types.OneDimVec> msgCellColors = new Google.Protobuf.Collections.RepeatedField <MessageToClient.Types.OneDimVec>();
            for (int x = 0; x < rows; ++x)
            {
                msgCellColors.Add(new MessageToClient.Types.OneDimVec());
                for (int y = 0; y < cols; ++y)
                {
                    msgCellColors[x].RowColors.Add(ColorType.Color2);
                }
            }


            //记录所有GUID信息
            Google.Protobuf.Collections.RepeatedField <MessageToClient.Types.OneTeamGUIDs> playerGUIDs = new Google.Protobuf.Collections.RepeatedField <MessageToClient.Types.OneTeamGUIDs>();
            for (int x = 0; x < 2; ++x)
            {
                playerGUIDs.Add(new MessageToClient.Types.OneTeamGUIDs());
                for (int y = 0; y < 4; ++y)
                {
                    playerGUIDs[x].TeammateGUIDs.Add(x * 100 + y);
                }
            }

            MessageToClient msg = new MessageToClient();

            msg.PlayerID                 = 0;
            msg.TeamID                   = 0;
            msg.MessageType              = msgType;
            msg.SelfInfo                 = new GameObjInfo();
            msg.SelfInfo.Ap              = 100;
            msg.SelfInfo.BulletNum       = 12;
            msg.SelfInfo.BulletType      = BulletType.Bullet0;
            msg.SelfInfo.CanMove         = true;
            msg.SelfInfo.CD              = 5;
            msg.SelfInfo.FacingDirection = 0.0;
            msg.SelfInfo.GameObjType     = GameObjType.Character;
            msg.SelfInfo.Hp              = 1000;
            msg.SelfInfo.Guid            = guid;
            msg.SelfInfo.IsDying         = false;
            msg.SelfInfo.IsMoving        = true;
            msg.SelfInfo.JobType         = JobType.Job0;
            msg.SelfInfo.LifeNum         = 10;
            msg.SelfInfo.MaxBulletNum    = 50;
            msg.SelfInfo.MaxHp           = 2500;
            msg.SelfInfo.MoveSpeed       = 10;
            msg.SelfInfo.PropType        = PropType.Null;
            msg.SelfInfo.Radius          = 250;
            msg.SelfInfo.ShapeType       = ShapeType.Circle;
            msg.SelfInfo.TeamID          = 0;
            msg.SelfInfo.X               = 5000;
            msg.SelfInfo.Y               = 5000;
            for (int k = 0; k < 2; ++k)
            {
                msg.PlayerGUIDs.Add(playerGUIDs[k]);
            }
            msg.SelfTeamColor = ColorType.Color3;
            for (int x = 0; x < rows; ++x)
            {
                msg.CellColors.Add(msgCellColors[x]);
            }
            return(msg);
        }