protected bool GetResource(out T resource, string message,
                                   LanguageGender gender = LanguageGender.Neutral, int pluralCount = 1)
        {
            var cached_string = new CachedString {
                Message     = message,
                Gender      = gender,
                PluralOrder = GetPluralOrder(CurrentIsoLanguageCode, pluralCount)
            };

            if (string_cache.TryGetValue(cached_string, out resource))
            {
                return(true);
            }

            var id    = GetResourceId(message, gender, cached_string.PluralOrder);
            var field = reflection_type.GetField(id);

            if (field == null)
            {
                return(false);
            }

            resource = (T)field.GetValue(null);
            string_cache.Add(cached_string, resource);

            return(true);
        }
        public void TestBasicRoundtripCachedString()
        {
            var cf = new ConnectionFactory();

            using (IConnection c = cf.CreateConnection())
                using (IModel m = c.CreateModel())
                {
                    CachedString exchangeName = new CachedString(string.Empty);
                    CachedString queueName    = new CachedString(m.QueueDeclare().QueueName);
                    byte[]       sendBody     = System.Text.Encoding.UTF8.GetBytes("hi");
                    byte[]       consumeBody  = null;
                    var          consumer     = new EventingBasicConsumer(m);
                    var          are          = new AutoResetEvent(false);
                    consumer.Received += async(o, a) =>
                    {
                        consumeBody = a.Body.ToArray();
                        are.Set();
                        await Task.Yield();
                    };
                    string tag = m.BasicConsume(queueName.Value, true, consumer);

                    m.BasicPublish(exchangeName, queueName, sendBody);
                    bool waitResFalse = are.WaitOne(2000);
                    m.BasicCancel(tag);

                    Assert.True(waitResFalse);
                    Assert.Equal(sendBody, consumeBody);
                }
        }
        protected bool GetResource(out T resource, string context, string message = null,
                                   LanguageGender gender = LanguageGender.Neutral, int pluralCount = 1)
        {
            var cached_string = new CachedString {
                Message     = message,
                Gender      = gender,
                PluralOrder = PluralRules.GetOrder(CurrentIsoLanguageCode, pluralCount)
            };

            if (string_cache.TryGetValue(cached_string, out resource))
            {
                return(true);
            }

            var id = GetResourceId(ResourceIdType.ComprehensibleIdentifier,
                                   context, message, gender, cached_string.PluralOrder);
            var field = reflection_type.GetTypeInfo().GetDeclaredField(id);

            if (field == null)
            {
                if (gender != LanguageGender.Neutral)
                {
                    return(GetResource(out resource, context, message, LanguageGender.Neutral, pluralCount));
                }
                return(false);
            }

            resource = (T)field.GetValue(null);
            string_cache.Add(cached_string, resource);

            return(true);
        }
Esempio n. 4
0
        public IEnumerator Launch()
        {
            int          cacheValidity = RequestKindCacheValidity();
            CachedString cache         = new CachedString(this.queryStr);

            if (cacheValidity > 0 && cache.IsValid())
            {
                Debug.Log("*** Using cache result for " + queryStr + " ; remaining validity: " + cache.RemainingValidity());
                this.result = cache.GetString();
            }
            else
            {
                string          host    = Noco.Configuration.baseUrl;
                string          urlStr  = String.Format("https://{0}/1.1{1}", host, this.queryStr);
                UnityWebRequest request = null;
                request                 = new UnityWebRequest();
                request.url             = urlStr;
                request.downloadHandler = new DownloadHandlerBuffer();
                request.SetRequestHeader("Authorization", "Basic " + this.api.oauthAccessToken.authorizationString());
                Debug.Log("--- Fetching: " + request.url);
                yield return(request.Send());

                this.result = request.downloadHandler.text;
                if (this.result != null && cacheValidity > 0 && this.result.IndexOf("\"error\"") == -1)
                {
                    cache.Save(this.result, cacheValidity);
                }
            }
            if (this.result != null)
            {
                Parse();
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Save this token to user preference (for caching)
 /// </summary>
 public void Save()
 {
     if (this.access_token != null)
     {
         CachedString cache = new CachedString("NocoAccessToken");
         cache.Save(this.ToString(), this.expires_in);
     }
 }
Esempio n. 6
0
        public void Print(string text, Vector2d position, Color backColor)
        {
            CachedString cached = cachedStrings.FirstOrDefault(x => x.String == text && x.BackColor == backColor);

            if (cached == null)
            {
                cached = new CachedString(text, this.font, backColor);
                cachedStrings.Add(cached);
            }

            cached.RefreshClientRect(parentGlControl.ClientRectangle);
            cached.LastUsedAgo += 0.01f;
            cached.Print(position);
        }
 private MessageBox(Rectangle rect, string caption, string text, bool visible = true)
     : base(null, null, visible)
 {
     BorderSize = 4;
     _text      = CachedString.Create(_font, text);
     _caption   = CachedString.Create(_font, caption);
     SetRect(rect);
     _draggable = new Draggable(MouseButton.Left, 1);
     _draggable.SetRect(_mBoxCaptionBarRect);
     _button = new SmallButton(null, null, new Rectangle(0, 0, 40, ButtonHeight - 2), "OK")
     {
         OnClick = Close
     };
     IsDirty = true;
 }
Esempio n. 8
0
        public void Initialize()
        {
            if (this.myInitialized)
            {
                return;
            }

            if (this.Spells.Length == 1)
            {
                this.mySpells = SpellBook.GenerateForGuild();
            }
            else
            {
                this.mySpells = SpellBook.FromDatabase(this.Spells);
            }



            if (this.Stats != string.Empty)
            {
                this.ParseStats();
            }

            this.myFightStats.AddBase(EffectEnum.AddForce, this.Level);
            this.myFightStats.AddBase(EffectEnum.AddSagesse, this.myStats.GetTotal(EffectEnum.AddSagesse));
            this.myFightStats.AddBase(EffectEnum.AddIntelligence, this.Level);
            this.myFightStats.AddBase(EffectEnum.AddChance, this.Level);
            this.myFightStats.AddBase(EffectEnum.AddAgilite, this.Level);
            this.myFightStats.AddBase(EffectEnum.AddReduceDamagePourcentNeutre, (int)Math.Floor((double)this.Level / 2));
            this.myFightStats.AddBase(EffectEnum.AddReduceDamagePourcentFeu, (int)Math.Floor((double)this.Level / 2));
            this.myFightStats.AddBase(EffectEnum.AddReduceDamagePourcentEau, (int)Math.Floor((double)this.Level / 2));
            this.myFightStats.AddBase(EffectEnum.AddReduceDamagePourcentAir, (int)Math.Floor((double)this.Level / 2));
            this.myFightStats.AddBase(EffectEnum.AddReduceDamagePourcentTerre, (int)Math.Floor((double)this.Level / 2));
            this.myFightStats.AddBase(EffectEnum.AddEsquivePA, (int)Math.Floor((double)this.Level / 2));
            this.myFightStats.AddBase(EffectEnum.AddEsquivePM, (int)Math.Floor((double)this.Level / 2));

            this.PatternSpells = new CachedString(new Func <String>(() =>
            {
                return(string.Join("|", this.mySpells.GetMySpells().Values.Select(x => x.Id + ";" + x.Level)));
            }));

            /*
             * SpellBook.SpellInfo curSpell in mySpells.GetSpellInfos()*/

            this.myInitialized = true;
        }
Esempio n. 9
0
        public DialogWindow(Point size, string caption) : base(null, null)
        {
            BorderSize   = 4;
            _spriteSheet = Ui.SpriteSheet;
            SetRect(new Rectangle(Point.Zero, size));
            _caption     = CachedString.Create(IoC.Get <IFont>(), caption);
            _closeButton = new SmallButton(IoC.Get <IWindow>(), this, Ui.Button.CloseButtonNormal, Ui.Button.CloseButtonPressed,
                                           new Rectangle(), null)
            {
                OnClick = Close,
            };
            var cbWidth  = Ui.Button.CloseButtonNormal.Width;
            var cbHeight = Ui.Button.CloseButtonNormal.Height;

            _closeButton.SetRect(new Rectangle(CleanRect.Width - cbWidth - (BorderSize * 2), -Ui.CaptionHeight, cbWidth, cbHeight));
            _draggable = new Draggable(MouseButton.Left, 1);
            IsDirty    = true;
        }
Esempio n. 10
0
        public IEnumerator LoadArchivedAccessToken()
        {
            CachedString cache            = new CachedString("NocoAccessToken");
            string       tokenDescription = cache.GetString();

            if (tokenDescription != null)
            {
                AccessTokenDescriptor previousTokenDescriptor = JsonUtility.FromJson <AccessTokenDescriptor> (tokenDescription);
                if (cache.IsValid())
                {
                    if (debugAuthentification)
                    {
                        Debug.Log("Access token still valid for " + cache.RemainingValidity() + " seconds");
                    }
                    this.oauthAccessToken = previousTokenDescriptor;
                }
                else if (previousTokenDescriptor != null)
                {
                    if (debugAuthentification)
                    {
                        Debug.Log("Trying to use refresh token after access token lapsing " + tokenDescription);
                    }
                    NocoOAuthAccessTokenRequest request = new NocoOAuthAccessTokenRequest(this.clientId, this.clientSecret);
                    yield return(request.FetchAccessTokenFromRefreshToken(previousTokenDescriptor.refresh_token));

                    if (debugAuthentification)
                    {
                        Debug.Log("Refresh token call result:" + request.result);
                    }
                    this.oauthAccessToken = request.oauthAccessToken;
                    if (IsAuthenticated())
                    {
                        if (debugAuthentification)
                        {
                            Debug.Log("Refresh token succed: new access token found: " + this.oauthAccessToken);
                        }
                        this.oauthAccessToken.Save();
                    }
                }
            }
        }
 private ConfirmationBox(Rectangle rect, string caption, string text, Action onYes, bool visible = true)
     : base(null, null, visible)
 {
     BorderSize          = 4;
     _mBoxCaptionBarRect = new Rectangle(rect.X, rect.Y, rect.Width, CaptionHeight);
     _mBoxMainRect       = new Rectangle(rect.X, rect.Y + CaptionHeight, rect.Width, rect.Height - CaptionHeight);
     _text    = CachedString.Create(_font, text);
     _caption = CachedString.Create(_font, caption);
     SetRect(rect);
     _draggable = new Draggable(MouseButton.Left, 1);
     _draggable.SetRect(_mBoxCaptionBarRect);
     IsDirty    = true;
     _buttonYes = new SmallButton(_mBoxWindow, null,
                                  new Rectangle(0, 0, 40, ButtonHeight - 2), "Yes");
     _buttonYes.OnClick = () =>
     {
         Close();
         onYes?.Invoke();
     };
     _buttonNo = new SmallButton(_mBoxWindow, null,
                                 new Rectangle(0, 0, 40, ButtonHeight - 2), "No");
     _buttonNo.OnClick = Close;
 }
Esempio n. 12
0
        public void Print(string text, Vector2d position, Color backColor)
        {
            CachedString cached = cachedStrings.FirstOrDefault(x => x.String == text && x.BackColor == backColor);

            if (cached == null)
            {
                cached = new CachedString(text, this.font, backColor);
                cachedStrings.Add(cached);
            }

            cached.RefreshClientRect(parentGlControl.ClientRectangle);
            cached.LastUsedAgo += 0.01f;
            cached.Print(position);
        }
Esempio n. 13
0
 protected bool Equals(CachedString other)
 {
     return(other != null && string.Equals(Value, other.Value));
 }
        public void Add(CachedString exchange, CachedString routingKey, bool mandatory, IBasicProperties basicProperties, ReadOnlyMemory <byte> body)
        {
            var method = new BasicPublishMemory(exchange.Bytes, routingKey.Bytes, mandatory, default);

            _commands.Add(new OutgoingCommand(method, (ContentHeaderBase)(basicProperties ?? _model._emptyBasicProperties), body));
        }