示例#1
0
        protected override void GetParametersLocked(Parameters Parameters, Language UserLanguage, bool IncludeJoins)
        {
            base.GetParametersLocked(Parameters, UserLanguage, IncludeJoins);

            bool InProduction = this.Phase >= LifecyclePhase.Production;

            if (UserLanguage == null)
            {
                Parameters.AddStringParameter("folder", "Communication", "Communication",
                                              "Folder:",
                                              "CoAP folder",
                                              !InProduction, null, this.folder);

                /*Parameters.AddBooleanParameter("composite", "Communication", "Communication",
                 *  "Composite folder",
                 *  "If checked, the current folder consists of data of its child nodes.",
                 *  !InProduction, false, this.composite);*/
            }
            else
            {
                LanguageModule Module   = UserLanguage.GetModule(LanguageModuleName);
                string         Category = Module.String(26, "Communication");

                Parameters.AddStringParameter("folder", "Communication", Category,
                                              Module.String(3, "Folder:"),
                                              Module.String(4, "CoAP folder"),
                                              !InProduction, null, this.folder);

                /*Parameters.AddBooleanParameter("composite", "Communication", Category,
                 *  Module.String(5, "Composite folder"),
                 *  Module.String(6, "If checked, the current folder consists of data of its child nodes."),
                 *  !InProduction, false, this.composite);*/
            }
        }
示例#2
0
 private FunctionNode Set(ExpressionNode input, Context context)
 => new FunctionNode(
     (v, c) => SetVariable(LanguageModule.ToString(input, context).StringValue, v, context)
     )
 {
     Parameter = new VariableNode("right")
 };
示例#3
0
        protected override void GetParametersLocked(Parameters Parameters, Language UserLanguage, bool IncludeJoins)
        {
            base.GetParametersLocked(Parameters, UserLanguage, IncludeJoins);

            bool InProduction = this.Phase >= LifecyclePhase.Production;

            if (UserLanguage == null)
            {
                Parameters.AddStringParameter("resource", "Communication", "Communication",
                                              "Resource Name:",
                                              "Local resource name of content.",
                                              !InProduction, null, this.resource);

                Parameters.AddStringParameter("query", "Communication", "Communication",
                                              "Query String:",
                                              "Optional query string used in the request for data.",
                                              !InProduction, string.Empty, this.query);
            }
            else
            {
                LanguageModule Module   = UserLanguage.GetModule(LanguageModuleName);
                string         Category = Module.String(26, "Communication");

                Parameters.AddStringParameter("resource", "Communication", Category,
                                              Module.String(7, "Resource Name:"),
                                              Module.String(8, "Local resource name of content."),
                                              !InProduction, null, this.resource);

                Parameters.AddStringParameter("query", "Communication", Category,
                                              Module.String(53, "Query String:"),
                                              Module.String(54, "Optional query string used in the request for data."),
                                              !InProduction, string.Empty, this.query);
            }
        }
示例#4
0
 private void Start()
 {
     mou = Framework.env0.modules.CreateModule <LanguageModule>();
     mou.Load(new TestLoader().Load());
     observer = mou.CreateDelegateObserver(key, SystemLanguage.English)
                .Listen((val) => { Log.E(val); });
 }
示例#5
0
 public FunctionNode Set(ExpressionNode input, Context context)
 => new FunctionNode(
     (v, c) => c.SetVariable(LanguageModule.ToString(input, c).StringValue, v),
     false, false
     )
 {
     Parameter = new VariableNode("right"), Context = context
 };
示例#6
0
 public ShiritoriPreload()
 {
     if (!File.Exists("Saves/Game/ShiritoriJapanese.txt"))
     {
         File.WriteAllBytes("Saves/Game/ShiritoriJapanese.txt", StaticObjects.HttpClient.GetByteArrayAsync("https://files.zirk.eu/Sanara/ShiritoriJapanese.txt").GetAwaiter().GetResult());
     }
     string[] lines = File.ReadAllLines("Saves/Game/ShiritoriJapanese.txt");
     _preload = new ShiritoriPreloadResult[lines.Length];
     for (int i = 0; i < lines.Length; i++)
     {
         string[] curr = lines[i].Split('$');
         string   word = curr[0];
         _preload[i] = new ShiritoriPreloadResult(word, LanguageModule.ToRomaji(word), curr[1]);
     }
 }
        protected override void GetParametersLocked(Parameters Parameters, Language UserLanguage, bool IncludeJoins)
        {
            base.GetParametersLocked(Parameters, UserLanguage, IncludeJoins);

            bool InProduction = this.Phase >= LifecyclePhase.Production;

            if (UserLanguage == null)
            {
                Parameters.AddInt32Parameter("port", "Communication", "Communication",
                                             "CoAP Port:",
                                             "Port to use on the local machine for incoming CoAP messages.",
                                             !InProduction, null, this.port, 1, 65535);

                Parameters.AddInt32Parameter("ttl", "Communication", "Communication",
                                             "Time to live (TTL):",
                                             "Number of router hops to allow, before messages are discarded.",
                                             !InProduction, null, this.ttl, 1, 255);

                Parameters.AddIdReferenceParameter("userId", "Communication", "Communication",
                                                   "User ID:",
                                                   "Access to the server will be made using the access rights of this user account.",
                                                   !InProduction, string.Empty, this.userId, Users.Source, typeof(User), false);
            }
            else
            {
                LanguageModule Module   = UserLanguage.GetModule(CoapNode.LanguageModuleName);
                string         Category = Module.String(26, "Communication");

                Parameters.AddInt32Parameter("port", "Communication", Category,
                                             Module.String(10, "CoAP Port:"),
                                             Module.String(11, "Port to use on the local machine for incoming CoAP messages."),
                                             !InProduction, null, this.port, 1, 65535);

                Parameters.AddInt32Parameter("ttl", "Communication", Category,
                                             Module.String(12, "Time to live (TTL):"),
                                             Module.String(13, "Number of router hops to allow, before messages are discarded."),
                                             !InProduction, null, this.ttl, 1, 255);

                Parameters.AddIdReferenceParameter("userId", "Communication", Category,
                                                   Module.String(55, "User ID:"),
                                                   Module.String(56, "Access to the server will be made using the access rights of this user account."),
                                                   !InProduction, string.Empty, this.userId, Users.Source, typeof(User), false);
            }
        }
示例#8
0
        static void Main(string[] args)
        {
            try
            {
                //Check that a port number was specified
                if (args.Length < 1)
                {
                    throw new Exception("must specify port number to listen on.");
                }

                //Check that a template directory was specified
                if (args.Length < 2)
                {
                    throw new Exception("must specify template directory path.");
                }

                //Verify that the specified port number is valid
                int port = Program.parsePort(args[0]);

                //Attempt to start the gRPC server
                Server server = new Server
                {
                    Services = { LanguageModule.BindService(new LanguageModuleImp(args[1])) },
                    Ports    = { new ServerPort("localhost", port, ServerCredentials.Insecure) }
                };
                server.Start();

                //Debug output
                Console.WriteLine("Starting gRPC server on port " + port + "...");

                //Block the main thread until the server terminates
                while (true)
                {
                    Thread.Sleep(1000);
                }
            }
            catch (Exception e) {
                Console.Error.WriteLine("Error: " + e.Message);
            }
        }
示例#9
0
 private void Start()
 {
     mou = Framework.env1.modules.CreateModule <LanguageModule>();
     mou.Load(() =>
     {
         return(new List <LanPair>()
         {
             new LanPair()
             {
                 Lan = SystemLanguage.Chinese,
                 Value = "哈哈",
                 key = "77"
             },
             new LanPair()
             {
                 Lan = SystemLanguage.English,
                 Value = "haha",
                 key = "77"
             }
         });
     });
     observer = mou.CreatObserver(key, SystemLanguage.English).ObserveEvent((lan, val) => { Log.E(val); });
 }
        protected override void GetParametersLocked(Parameters Parameters, Language UserLanguage, bool IncludeJoins)
        {
            base.GetParametersLocked(Parameters, UserLanguage, IncludeJoins);

            bool InProduction = this.Phase >= LifecyclePhase.Production;

            if (UserLanguage == null)
            {
                Parameters.AddStringParameter("fieldName", "Communication", "Communication",
                                              "Field Name:",
                                              "Field name to use when reporting content.",
                                              !InProduction, null, this.fieldName);
            }
            else
            {
                LanguageModule Module   = UserLanguage.GetModule(LanguageModuleName);
                string         Category = Module.String(2, "Communication");

                Parameters.AddStringParameter("fieldName", "Communication", Category,
                                              Module.String(29, "Field Name:"),
                                              Module.String(30, "Field name to use when reporting content."),
                                              !InProduction, null, this.fieldName);
            }
        }
示例#11
0
 public ExpressionNode Get(ExpressionNode input, Context context)
 => GetVariable(LanguageModule.ToString(input, context).StringValue, context);
示例#12
0
 private void Start()
 {
     mou = Framework.env1.modules.CreateModule <LanguageModule>();
     mou.Load(new TestLoader().Load());
     observer = mou.CreatObserver(key, SystemLanguage.English).ObserveEvent((lan, val) => { Log.E(val); });
 }
示例#13
0
        protected override async Task CheckAnswerInternalAsync(string answer)
        {
            // We convert to hiragana so it's then easier to check if the word really exist
            // Especially for some edge case, like りゅう (ryuu) is starting by "ri" and not by "ry"
            string hiraganaAnswer = LanguageModule.ToHiragana(answer);

            if (hiraganaAnswer.Any(c => c < 0x0041 || (c > 0x005A && c < 0x0061) || (c > 0x007A && c < 0x3041) || (c > 0x3096 && c < 0x30A1) || c > 0x30FA))
            {
                throw new InvalidGameAnswer("Your answer must be in hiragana, katakana or romaji");
            }

            JObject json = JsonConvert.DeserializeObject <JObject>(await StaticObjects.HttpClient.GetStringAsync("http://jisho.org/api/v1/search/words?keyword=" + HttpUtility.UrlEncode(string.Join("%20", hiraganaAnswer))));
            var     data = (JArray)json["data"];

            if (data.Count == 0)
            {
                throw new InvalidGameAnswer("This word doesn't exist.");
            }

            bool   isCorrect = false, isNoun = false;
            string reading;

            string[] meanings = new string[0];
            // For each answer we check if it match our answer
            foreach (var d in data)
            {
                foreach (var jp in d["japanese"])
                {
                    var readingObj = jp["reading"];
                    if (readingObj == null)
                    {
                        continue;
                    }
                    reading = LanguageModule.ToHiragana(readingObj.Value <string>());
                    if (reading == hiraganaAnswer)
                    {
                        isCorrect = true;
                        // For each meaning we check if the word is a noun
                        foreach (var meaning in d["senses"])
                        {
                            foreach (var partSpeech in meaning["parts_of_speech"])
                            {
                                if (partSpeech.Value <string>() == "Noun")
                                {
                                    isNoun   = true;
                                    meanings = ((JArray)meaning["english_definitions"]).Select(x => (string)x).ToArray();
                                    goto ContinueCheck; // The word is valid, we are done with the basic checks
                                }
                            }
                        }
                    }
                }
            }
ContinueCheck:
            if (!isCorrect)
            {
                throw new InvalidGameAnswer("This word doesn't exist.");
            }
            var ending = GetWordEnding(_currWord);

            if (!hiraganaAnswer.StartsWith(ending))
            {
                throw new InvalidGameAnswer($"Your word must begin by {ending} ({LanguageModule.ToRomaji(ending)}).");
            }
            if (!isNoun)
            {
                throw new InvalidGameAnswer("Your word must be a noun.");
            }
            if (hiraganaAnswer == GetWordEnding(hiraganaAnswer)) // We can't just check the word count since しゃ would count as only one character
            {
                throw new InvalidGameAnswer("Your word must be at least 2 characters.");
            }
            if (_alreadySaid.Contains(hiraganaAnswer))
            {
                throw new GameLost("This word was already said.");
            }
            if (hiraganaAnswer.Last() == 'ん')
            {
                throw new GameLost("Your word is finishing with a ん (n).");
            }
            if (_words.Any(x => x.Word == hiraganaAnswer))
            {
                _words.Remove(_words.Where(x => x.Word == hiraganaAnswer).First());
            }
            _alreadySaid.Add(hiraganaAnswer);
            _currWord = hiraganaAnswer;
        }