Beispiel #1
0
        public PubSub(Action<PubSub> ready)
        {
            subbed = new JsDictionary<string, Action<string>>();

            var redis = Global.Require<NodeLibraries.Redis.Redis>("redis");
            redis.DebugMode = false;
            subClient = redis.CreateClient(6379, Constants.RedisIP);
            pubClient = redis.CreateClient(6379, Constants.RedisIP);
            subClient.On("subscribe", (string channel, int count) => Logger.Log("subscribed: " + channel + " " + count,LogLevel.Information));
            subClient.On("unsubscribe", (string channel, int count) => Logger.Log("unsubscribed: " + channel + " " + count, LogLevel.Information));

            subClient.On("message",
                         (string channel, string message) => {
                             if (subbed[channel] != null)
                                 subbed[channel](message);
                         });
            subClient.On("ready",
                         () => {
                             sready = true;
                             if (sready && pready)
                                 ready(this);
                         });
            pubClient.On("ready",
                         () => {
                             pready = true;
                             if (sready && pready)
                                 ready(this);
                         });
        }
Beispiel #2
0
        private JsDictionary<string, int?> GetCategoryOrder(List<PropertyItem> items)
        {
            int order = 0;
            var result = new JsDictionary<string, int?>();

            var categoryOrder = options.CategoryOrder.TrimToNull();
            if (categoryOrder != null)
            {
                var split = categoryOrder.Split(";");
                foreach (var s in split)
                {
                    var x = s.TrimToNull();
                    if (x == null)
                        continue;

                    if (result[x] != null)
                        continue;

                    result[x] = order++;
                }
            }

            foreach (var x in items)
            {
                var category = x.Category ?? options.DefaultCategory ?? "";
                if (result[category] == null)
                    result[category] = order++;
            }

            return result;
        }
        protected override List <CheckTreeItem> GetItems()
        {
            var list = new List <CheckTreeItem>();

            var permissions      = Q.GetRemoteData <ListResponse <string> >("Administration.PermissionKeys").Entities;
            var permissionTitles = new JsDictionary <string, string>();

            for (var i = 0; i < permissions.Count; i++)
            {
                string p = permissions[i];
                permissionTitles[p] = Q.TryGetText("Permission." + p) ?? p;
            }

            permissions.Sort((x, y) => Q.Externals.TurkishLocaleCompare(
                                 permissionTitles[x], permissionTitles[y]));

            foreach (var permission in permissions)
            {
                list.Add(new CheckTreeItem
                {
                    Id   = permission,
                    Text = permissionTitles[permission],
                });
            }

            return(list);
        }
Beispiel #4
0
        private void EnsureInitialized()
        {
            if (configObject == null)
            {
                return;
            }

            var npTypes = (string[])configObject["pluginNodeProcessors"];
            var tmTypes = (JsDictionary)configObject["pluginTypedMarkupParsers"];
            var umTypes = (string[])configObject["pluginUntypedMarkupParsers"];

            pluginNodeProcessors       = new INodeProcessor[npTypes.Length];
            pluginTypedMarkupParsers   = new Dictionary <string, ITypedMarkupParserImpl>();
            pluginUntypedMarkupParsers = new IUntypedMarkupParserImpl[umTypes.Length];

            for (int i = 0; i < npTypes.Length; i++)
            {
                pluginNodeProcessors[i] = (INodeProcessor)Container.CreateObjectByTypeName(npTypes[i]);
            }
            foreach (var tm in tmTypes)
            {
                pluginTypedMarkupParsers[tm.Key] = (ITypedMarkupParserImpl)Container.CreateObjectByTypeName((string)tm.Value);
            }
            for (int i = 0; i < umTypes.Length; i++)
            {
                pluginUntypedMarkupParsers[i] = (IUntypedMarkupParserImpl)Container.CreateObjectByTypeName(umTypes[i]);
            }

            docProcessor = new DocumentProcessor(pluginNodeProcessors, new TypedMarkupParser(pluginTypedMarkupParsers), new UntypedMarkupParser(pluginUntypedMarkupParsers));

            configObject = null;
        }
Beispiel #5
0
        public void ConvertingToGenericReturnsSameInstance()
        {
            var d  = JsDictionary.GetDictionary(new { a = "valueA", b = 134 });
            var d2 = (JsDictionary <string, object>)d;

            Assert.AreStrictEqual(d2, d);
        }
Beispiel #6
0
 protected override ListResponse <TItem> OnViewProcessData(ListResponse <TItem> response)
 {
     response = base.OnViewProcessData(response);
     byId     = null;
     SlickTreeHelper.SetIndents(response.Entities, getId: x => x.Id, getParentId: x => x.ParentId, setCollapsed: GetInitialCollapse());
     return(response);
 }
Beispiel #7
0
        protected virtual void SetIncludeColumnsParameter()
        {
            var include = new JsDictionary <string, bool>();

            if (!Script.IsNullOrUndefined(view.Params.IncludeColumns))
            {
                foreach (var key in (string[])view.Params.IncludeColumns)
                {
                    include[key] = true;
                }
            }

            GetIncludeColumns(include);

            List <string> array = null;

            if (include.Count > 0)
            {
                array = new List <string>();
                foreach (var key in include.Keys)
                {
                    array.Add(key);
                }
            }

            view.Params.IncludeColumns = array;
        }
Beispiel #8
0
        public Select2Editor(jQueryObject hidden, TOptions opt)
            : base(hidden, opt)
        {
            items    = new List <Select2Item>();
            itemById = new JsDictionary <string, Select2Item>();

            var emptyItemText = EmptyItemText();

            if (emptyItemText != null)
            {
                hidden.Attribute("placeholder", emptyItemText);
            }

            var select2Options = GetSelect2Options();

            multiple = Q.IsTrue(select2Options.Multiple);
            hidden.Select2(select2Options);

            hidden.Attribute("type", "text"); // jquery validate to work
            hidden.Bind2("change." + this.uniqueName, (e, x) =>
            {
                if (e.HasOriginalEvent() || Q.IsFalse(x))
                {
                    if (hidden.GetValidator() != null)
                    {
                        hidden.Valid();
                    }
                }
            });
        }
Beispiel #9
0
        public void ContainsKeyWorks()
        {
            var d = JsDictionary <string, object> .GetDictionary(new { a = "valueA", b = 134 });

            Assert.IsTrue(d.ContainsKey("a"));
            Assert.IsFalse(d.ContainsKey("c"));
        }
Beispiel #10
0
        public void RemoveWorks()
        {
            var d = JsDictionary <string, object> .GetDictionary(new { a = "valueA", b = 134 });

            d.Remove("a");
            Assert.AreEqual(d.Keys, new[] { "b" });
        }
Beispiel #11
0
        private static List <PlayerCluster> buildPlayerClusters(List <Player> players, Dictionary <Player, PlayerClusterInfo> playerClusterInformations)
        {
            JsDictionary <int, Player> hitPlayers     = players.ToDictionary(a => a.Id);
            List <PlayerCluster>       playerClusters = new List <PlayerCluster>();
            int hitPlayerCount = players.Count;


            var playerClusterInfoHits      = new JsDictionary <int, PlayerClusterInfo>();
            var playerClusterInfoHitsArray = new List <PlayerClusterInfo>();

            while (hitPlayerCount > 0)
            {
                playerClusterInfoHits.Clear();
                playerClusterInfoHitsArray.Clear();

                GetPlayerCluster(playerClusterInfoHits, playerClusterInfoHitsArray, playerClusterInformations, playerClusterInformations[hitPlayers[hitPlayers.Keys.First()]], hitPlayers);
                PlayerCluster cluster = new PlayerCluster();
                for (int index = 0; index < playerClusterInfoHitsArray.Count; index++)
                {
                    var playerClusterInfoHit = playerClusterInfoHitsArray[index];
                    cluster.Players.Add(playerClusterInfoHit.Player);
                    hitPlayers.Remove(playerClusterInfoHit.Player.Id);
                    hitPlayerCount--;
                }

                playerClusters.Add(cluster);

//                Console.WriteLine(string.Format("Players Left: {0}, Clusters Total: {1} ", hitPlayerCount, playerClusters.Count));
            }
            return(playerClusters);
        }
 public void NameValuePairsConstructorWorks()
 {
     var d = new JsDictionary<string, object>("a", "valueA", "b", 134);
     Assert.AreEqual(d.Count, 2);
     Assert.AreEqual(d["a"], "valueA");
     Assert.AreEqual(d["b"], 134);
 }
Beispiel #13
0
        private void SetLocalizationGridCurrentValues()
        {
            var valueByName = new JsDictionary <string, string>();

            this.localizationGrid.EnumerateItems((item, widget) =>
            {
                if (item.Name.IndexOf("$") < 0 && widget.Element.Is(":input"))
                {
                    valueByName[item.Name] = this.ById(item.Name).GetValue();
                    widget.Element.Value(valueByName[item.Name]);
                }
            });

            this.localizationGrid.EnumerateItems((item, widget) =>
            {
                var idx = item.Name.IndexOf("$");
                if (idx >= 0 && (widget.Element.Is(":input")))
                {
                    var hint = valueByName[item.Name.Substr(idx + 1)];
                    if (hint != null && hint.Length > 0)
                    {
                        widget.Element
                        .Attribute("title", hint)
                        .Attribute("placeholder", hint);
                    }
                }
            });
        }
Beispiel #14
0
        public static string Pluralize(string word)
        {
            Initialize();

            if (pluralizeCache != null &&
                pluralizeCache.ContainsKey(word))
                return pluralizeCache[word];

            string result = word;

            foreach (object[] p in plural)
            {
                Regex r = (Regex)p[0];
                if (r.Test(word))
                {
                    result = word.Replace(r, (string)p[1]);
                    break;
                }
            }

            foreach (var c in countable)
            {
                if (word == c)
                {
                    result = c;
                    break;
                }
            }

            pluralizeCache = pluralizeCache ?? new JsDictionary<string, string>();
            pluralizeCache[word] = result;

            return result;
        }
Beispiel #15
0
        private void CreateItems(jQueryObject container, List<PropertyItem> items)
        { 
            var categoryIndexes = new JsDictionary<string, int>();
            var categoriesDiv = container;
            
            var useCategories = options.UseCategories &&
                Q.Any(items, x => !string.IsNullOrEmpty(x.Category));

            if (options.UseCategories)
            {
                var linkContainer = J("<div/>")
                    .AddClass("category-links");

                categoryIndexes = CreateCategoryLinks(linkContainer, items);

                if (categoryIndexes.Count > 1)
                    linkContainer.AppendTo(container);
                else
                    linkContainer.Find("a.category-link").Unbind("click", CategoryLinkClick).Remove();
            }

            categoriesDiv = J("<div/>")
                .AddClass("categories")
                .AppendTo(container);

            jQueryObject fieldContainer;
            if (useCategories)
            {
                fieldContainer = categoriesDiv;
            }
            else
            { 
                fieldContainer = J("<div/>")
                    .AddClass("category")
                    .AppendTo(categoriesDiv);
            }

            string priorCategory = null;

            for (int i = 0; i < items.Count; i++)
            {
                var item = items[i];
                var category = (item.Category ?? options.DefaultCategory ?? "");
                if (useCategories && priorCategory != category)
                {
                    var categoryDiv = CreateCategoryDiv(categoriesDiv, categoryIndexes, category, 
                        item.Collapsible != true ? (bool?)null : item.Collapsed ?? false);

                    if (priorCategory == null)
                        categoryDiv.AddClass("first-category");

                    priorCategory = category;
                    fieldContainer = categoryDiv;
                }

                var editor = CreateField(fieldContainer, item);

                editors.Add(editor);
            }
        }
        internal static void Initialize()
        {
            if (knownTypes != null)
                return;

            knownTypes = new JsDictionary<string, Type>();
            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (var type in assembly.GetTypes())
                {
                    if (!typeof(ISlickFormatter).IsAssignableFrom(type))
                        continue;

                    if (type.IsGenericTypeDefinition)
                        continue;

                    var fullName = type.FullName.ToLower();
                    knownTypes[fullName] = type;

                    foreach (var k in Q.Config.RootNamespaces)
                    {
                        if (fullName.StartsWith(k.ToLower() + "."))
                        {
                            var kx = fullName.Substr(k.Length + 1).ToLower();
                            if (knownTypes[kx] == null)
                                knownTypes[kx] = type;
                        }
                    }
                }
            }

            SetTypeKeysWithoutFormatterSuffix();
        }
Beispiel #17
0
        static HtmlNode()
        {
            HtmlNode.HtmlNodeTypeNameComment  = "#comment";
            HtmlNode.HtmlNodeTypeNameDocument = "#document";
            HtmlNode.HtmlNodeTypeNameText     = "#text";
#if SALTARELLE
            HtmlNode.ElementsFlags = new JsDictionary <string, HtmlElementFlag>();
#else
            HtmlNode.ElementsFlags = new Dictionary <string, HtmlElementFlag>();
#endif
            HtmlNode.ElementsFlags["script"]   = HtmlElementFlag.CData;
            HtmlNode.ElementsFlags["style"]    = HtmlElementFlag.CData;
            HtmlNode.ElementsFlags["noxhtml"]  = HtmlElementFlag.CData;
            HtmlNode.ElementsFlags["base"]     = HtmlElementFlag.Empty;
            HtmlNode.ElementsFlags["link"]     = HtmlElementFlag.Empty;
            HtmlNode.ElementsFlags["meta"]     = HtmlElementFlag.Empty;
            HtmlNode.ElementsFlags["isindex"]  = HtmlElementFlag.Empty;
            HtmlNode.ElementsFlags["hr"]       = HtmlElementFlag.Empty;
            HtmlNode.ElementsFlags["col"]      = HtmlElementFlag.Empty;
            HtmlNode.ElementsFlags["img"]      = HtmlElementFlag.Empty;
            HtmlNode.ElementsFlags["param"]    = HtmlElementFlag.Empty;
            HtmlNode.ElementsFlags["embed"]    = HtmlElementFlag.Empty;
            HtmlNode.ElementsFlags["frame"]    = HtmlElementFlag.Empty;
            HtmlNode.ElementsFlags["wbr"]      = HtmlElementFlag.Empty;
            HtmlNode.ElementsFlags["bgsound"]  = HtmlElementFlag.Empty;
            HtmlNode.ElementsFlags["source"]   = HtmlElementFlag.Empty;
            HtmlNode.ElementsFlags["track"]    = HtmlElementFlag.Empty;
            HtmlNode.ElementsFlags["spacer"]   = HtmlElementFlag.Empty;
            HtmlNode.ElementsFlags["keygen"]   = HtmlElementFlag.Empty;
            HtmlNode.ElementsFlags["area"]     = HtmlElementFlag.Empty;
            HtmlNode.ElementsFlags["input"]    = HtmlElementFlag.Empty;
            HtmlNode.ElementsFlags["command"]  = HtmlElementFlag.Empty;
            HtmlNode.ElementsFlags["basefont"] = HtmlElementFlag.Empty;
            HtmlNode.ElementsFlags["br"]       = (HtmlElementFlag.Empty | HtmlElementFlag.Closed);
        }
Beispiel #18
0
        public void ClearWorks()
        {
            var d = JsDictionary <string, object> .GetDictionary(new { a = "valueA", b = 134 });

            d.Clear();
            Assert.AreEqual(d.Count, 0);
        }
Beispiel #19
0
        private jQueryObject CreateCategoryDiv(jQueryObject categoriesDiv, JsDictionary <string, int> categoryIndexes, string category,
                                               bool?collapsed)
        {
            var categoryDiv = J("<div/>")
                              .AddClass("category")
                              .AppendTo(categoriesDiv);

            var title = J("<div/>")
                        .AddClass("category-title")
                        .Append(J("<a/>")
                                .AddClass("category-anchor")
                                .Text(DetermineText(category, prefix => prefix + "Categories." + category))
                                .Attribute("name", options.IdPrefix + "Category" + categoryIndexes[category].ToString()))
                        .AppendTo(categoryDiv);

            if (collapsed != null)
            {
                categoryDiv.AddClass(collapsed == true ? "collapsible collapsed" : "collapsible");
                var img = J("<i/>").AddClass(collapsed == true ? "fa fa-plus" : "fa fa-minus").AppendTo(title);

                title.Click(e =>
                {
                    categoryDiv.ToggleClass("collapsed");
                    img.ToggleClass("fa-plus").ToggleClass("fa-minus");
                });
            }

            return(categoryDiv);
        }
Beispiel #20
0
        public void IndexingWorks()
        {
            var d = JsDictionary <string, object> .GetDictionary(new { a = "valueA", b = 134 });

            Assert.AreEqual(d["a"], "valueA");
            Assert.AreEqual(d["b"], 134);
        }
Beispiel #21
0
        protected virtual void UpdateItems()
        {
            var items    = GetItems();
            var itemById = new JsDictionary <string, TItem>();

            for (var i = 0; i < items.Count; i++)
            {
                var item = items[i];
                item.Children = new List <CheckTreeItem>();
                if (!item.Id.IsEmptyOrNull())
                {
                    itemById[item.Id] = item;
                }

                if (!item.ParentId.IsEmptyOrNull())
                {
                    var parent = itemById[item.ParentId];
                    if (parent != null)
                    {
                        parent.Children.Add(item);
                    }
                }
            }

            view.AddData(new ListResponse <TItem>
            {
                Entities   = items,
                Skip       = 0,
                Take       = 0,
                TotalCount = items.Count
            });

            UpdateSelectAll();
            UpdateFlags();
        }
 public QueueManager(string name)
 {
     Name = name;
     channels = new JsDictionary<string, ChannelListenTrigger>();
     qwCollection = new QueueItemCollection();
     qpCollection = new QueueItemCollection();
 }
Beispiel #23
0
        public void Update(IEnumerable <TItem> newItems)
        {
            items    = new List <TItem>();
            itemById = new JsDictionary <object, TItem>();

            if (newItems != null)
            {
                items.AddRange(newItems);
            }

            var idField = options.IdField;

            if (!idField.IsEmptyOrNull())
            {
                for (var i = 0; i < this.items.Count; i++)
                {
                    var r = this.items[i];
                    var v = r.As <JsDictionary>()[idField];// ?? Type.GetProperty(r, idField);
                    if (v != null)
                    {
                        this.itemById[v] = r;
                    }
                }
            }
        }
Beispiel #24
0
        public static Type Get(string key)
        {
            if (knownTypes == null)
            {
                knownTypes = new JsDictionary<string, Type>();
                foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
                {
                    foreach (var type in assembly.GetTypes())
                    {
                        if (type.IsEnum)
                        {
                            var fullName = type.FullName;
                            knownTypes[fullName] = type;

                            var enumKeyAttr = type.GetCustomAttributes(typeof(EnumKeyAttribute), false);
                            if (enumKeyAttr != null && enumKeyAttr.Length > 0)
                                knownTypes[((EnumKeyAttribute)enumKeyAttr[0]).Value] = type;

                            foreach (var k in Q.Config.RootNamespaces)
                            {
                                if (fullName.StartsWith(k + "."))
                                {
                                    knownTypes[fullName.Substr(k.Length + 1)] = type;
                                }
                            }
                        }
                    }
                }
            }

            if (!knownTypes.ContainsKey(key))
                throw new Exception(String.Format("Can't find {0} enum type!", key));

            return knownTypes[key];
        }
Beispiel #25
0
        public PermissionCheckEditor(jQueryObject div, PermissionCheckEditorOptions opt)
            : base(div, opt)
        {
            rolePermissions = new JsDictionary <string, bool>();

            JsDictionary <string, string> titleByKey;
            var permissionKeys = GetSortedGroupAndPermissionKeys(out titleByKey);
            var items          = new List <PermissionCheckItem>();

            foreach (var key in permissionKeys)
            {
                items.Add(new PermissionCheckItem
                {
                    Key         = key,
                    ParentKey   = GetParentKey(key),
                    Title       = titleByKey[key],
                    GrantRevoke = null,
                    IsGroup     = key.EndsWith(":")
                });
            }

            byParentKey = items.ToLookup(x => x.ParentKey);

            SetItems(items);
        }
Beispiel #26
0
        public PhoneListController(Scope _scope, Http _http)
        {
            what = "main";

            /*
             * http.Get("hello.html").Success((data,status)=> {
             * Window.Alert(data.ToString());
             * }).Error((data,status)=>{
             * Window.Alert("errore!");
             * });
             */

            var risp = _http.Get("data.json");

            risp.Success((data, status, header) =>
            {
                person = (JsDictionary)data;
                // Window.Alert(person["name"].ToString());
            });

            risp.Error((data, status) =>
            {
                //   Window.Alert("errore!");
            });
        }
Beispiel #27
0
        public void DefaultConstructorWorks()
        {
            var d = new JsDictionary <string, object>();

            Assert.IsTrue(d != null);
            Assert.AreEqual(d.Count, 0);
        }
        public static void ChangeCSS(string classToChange, JsDictionary<string, string> values)
        {
            var myClass = "." + classToChange;
            string CSSRules = "";
            var document = (dynamic) Window.Document;
            if (document.all)
                CSSRules = "rules";
            else if (document.getElementById)
                CSSRules = "cssRules";
            for (var a = 0; a < document.styleSheets.length; a++)
            {
                var ruleSet = document.styleSheets[a][CSSRules];
                if (ruleSet == null) continue;
                for (var i = 0; i < ruleSet.length; i++)
                {
                    var rule = ruleSet[i];
                    if (rule.selectorText == myClass)
                    {

                        foreach (var m in Object.Keys(values))
                        {
                            rule.style[m] = values[m];
                        }
                    }
                }
            }
        }
Beispiel #29
0
        public static object GetValue(Widget editor)
        {
            var target = new JsDictionary();

            SaveValue(editor, dummy, target);
            return(target["_"]);
        }
        public static void Set(object target, JsDictionary <string, object> options)
        {
            if (options == null)
            {
                return;
            }

            var props = target.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);

            var propList = props.Where(x => x.CanWrite &&
                                       (x.GetCustomAttributes(typeof(OptionAttribute)).Length > 0 ||
                                        x.GetCustomAttributes(typeof(DisplayNameAttribute)).Length > 0));

            var propByName = new JsDictionary <string, PropertyInfo>();

            foreach (var k in propList)
            {
                propByName[ReflectionUtils.MakeCamelCase(k.Name)] = k;
            }

            foreach (var k in options.Keys)
            {
                PropertyInfo p = propByName[ReflectionUtils.MakeCamelCase(k)];
                if (p != null)
                {
                    p.SetValue(target, options[k]);
                }
            }
        }
        protected LampServer(int region, IServerManager manager)
        {
            myRegion = region;
            myManager = manager;

            Actions = new JsDictionary<int, List<LampAction>>();
        }
Beispiel #32
0
        public static JsDictionary <string, int?> IndexByKey(this TabsObject tabs)
        {
            var indexByKey = tabs.As <jQueryObject>().GetDataValue("indexByKey").As <JsDictionary <string, int?> >();

            if (indexByKey == null)
            {
                indexByKey = new JsDictionary <string, int?>();

                tabs.As <jQueryObject>().Children("ul").Children("li").Children("a")
                .Each((index, el) =>
                {
                    var href      = el.GetAttribute("href").ToString();
                    var prefix    = "_Tab";
                    var lastIndex = href.LastIndexOf(prefix);
                    if (lastIndex >= 0)
                    {
                        href = href.Substr(lastIndex + prefix.Length);
                    }

                    indexByKey[href] = index;
                });

                tabs.As <jQueryObject>().Data("indexByKey", indexByKey);
            }

            return(indexByKey);
        }
Beispiel #33
0
        public Game()
        {
            Instance = this;
            DebugText = new object[0];
            WaypointMaps = new List<WaypointMap>();
            WaypointMaps.Add(new WaypointMap(Color.Red, Color.Green, new Waypoint[] {new Waypoint(4, 4), new Waypoint(40 - 4, 4)}, Scale));
            WaypointMaps.Add(new WaypointMap(Color.Red, Color.Yellow, new Waypoint[] {new Waypoint(4, 4), new Waypoint(20 - 4, 4), new Waypoint(20 - 4, 30 - 4), new Waypoint(40 - 4, 30 - 4)}, Scale));
            WaypointMaps.Add(new WaypointMap(Color.Red, Color.Blue, new Waypoint[] {new Waypoint(4, 4), new Waypoint(4, 30 - 4)}, Scale));
            WaypointMaps.Add(new WaypointMap(Color.Green, Color.Yellow, new Waypoint[] {new Waypoint(40 - 4, 4), new Waypoint(40 - 4, 30 - 4)}, Scale));
            WaypointMaps.Add(new WaypointMap(Color.Green, Color.Blue, new Waypoint[] {new Waypoint(40 - 4, 4), new Waypoint(4, 30 - 4)}, Scale));
            WaypointMaps.Add(new WaypointMap(Color.Yellow, Color.Blue, new Waypoint[] {new Waypoint(40 - 4, 30 - 4), new Waypoint(4, 30 - 4)}, Scale));

            Kingdoms = new JsDictionary<string, Kingdom>();
            Kingdoms["Mike"] = new Kingdom() {
                                                     Color = Color.Red,
                                                     Towers = new List<Tower>() {new KingdomTower(Color.Red, 4, 4)},
                                                     Waypoints = new List<Waypoint>() {
                                                                                              WaypointMaps[0].First(),
                                                                                              WaypointMaps[1].First(),
                                                                                              WaypointMaps[2].First(),
                                                                                      },
                                             };
            Kingdoms["Joe"] = new Kingdom() {
                                                    Color = Color.Green,
                                                    Towers = new List<Tower>() {new KingdomTower(Color.Green, 40 - 4, 4)},
                                                    Waypoints = new List<Waypoint>() {
                                                                                             WaypointMaps[0].Last(),
                                                                                             WaypointMaps[3].First(),
                                                                                             WaypointMaps[4].First(),
                                                                                     }
                                            };
            Kingdoms["Steve"] = new Kingdom() {
                                                      Color = Color.Yellow,
                                                      Towers = new List<Tower>() {
                                                                                         new KingdomTower(Color.Yellow, 40 - 4, 30 - 4),
                                                                                         new SingeShotTower(Color.Yellow, 40 - 6, 30 - 3)
                                                                                 },
                                                      Waypoints = new List<Waypoint>() {
                                                                                               WaypointMaps[1].Last(),
                                                                                               WaypointMaps[3].Last(),
                                                                                               WaypointMaps[5].First(),
                                                                                       }
                                              };
            Kingdoms["Chris"] = new Kingdom() {
                                                      Color = Color.Blue,
                                                      Towers = new List<Tower>() {new KingdomTower(Color.Blue, 4, 30 - 4)},
                                                      Waypoints = new List<Waypoint>() {
                                                                                               WaypointMaps[2].Last(),
                                                                                               WaypointMaps[4].Last(),
                                                                                               WaypointMaps[5].Last(),
                                                                                       }
                                              };
            /*
            KeyboardJS.Instance().Bind.Key("space",
                                           () => {
                                           },
                                           () => { });
            */
        }
		public void GetEnumeratorWorks() {
			var d = JsDictionary<string, object>.GetDictionary(new { a = "valueA", b = 134 });
			var d2 = new JsDictionary<string, object>();
			foreach (var kvp in d) {
				d2[kvp.Key] = kvp.Value;
			}
			Assert.AreEqual(d, d2);
		}
        public static void AddCSSRule(dynamic sheet, string selector, JsDictionary<string, object> css)
        {


            var propText = Keys(css).Map((p) => { return p + ":" + css[p]; }).Join(";");
            sheet.insertRule(selector + "{" + propText + "}", sheet.cssRules.length);

        }
Beispiel #36
0
        public void KeysWorks()
        {
            var d    = JsDictionary.GetDictionary(new { a = "valueA", b = 134 });
            var keys = d.Keys;

            Assert.IsTrue(keys.Contains("a"));
            Assert.IsTrue(keys.Contains("b"));
        }
Beispiel #37
0
 public static void SetRegisteredScripts(JsDictionary <string, string> scripts)
 {
     registered.Clear();
     foreach (var k in scripts)
     {
         Q.ScriptData.registered[k.Key] = k.Value.ToString();
     }
 }
Beispiel #38
0
        public void NameValuePairsConstructorWorks()
        {
            var d = new JsDictionary <string, object>("a", "valueA", "b", 134);

            Assert.AreEqual(d.Count, 2);
            Assert.AreEqual(d["a"], "valueA");
            Assert.AreEqual(d["b"], 134);
        }
Beispiel #39
0
        public void CollectionInitializerWorks()
        {
            var d = new JsDictionary <string, object> {
                { "a", "valueA" }, { "b", 134 }
            };

            Assert.AreEqual(d["a"], "valueA");
            Assert.AreEqual(d["b"], 134);
        }
 private void Init()
 {
     Animations = new JsDictionary<int, TileAnimation>();
     for (int animatedTileIndex = 0; animatedTileIndex < SonicManager.SonicLevel.TileAnimations.Count; animatedTileIndex++)
     {
         Animations[animatedTileIndex] = new TileAnimation(this, SonicManager.SonicLevel.TileAnimations[animatedTileIndex]);
         Animations[animatedTileIndex].Init();
     }
 }
Beispiel #41
0
 static FilterOperators()
 {
     ToCriteriaOperator = new JsDictionary <string, string>();
     ToCriteriaOperator[FilterOperators.EQ] = "=";
     ToCriteriaOperator[FilterOperators.GT] = ">";
     ToCriteriaOperator[FilterOperators.GE] = ">=";
     ToCriteriaOperator[FilterOperators.LT] = "<";
     ToCriteriaOperator[FilterOperators.LE] = "<=";
 }
 protected virtual void InitConfig(JsDictionary config)
 {
     id             = (string)config["id"];
     tabCaptions    = (string[])config["tabCaptions"];
     position       = (Position)config["position"];
     selectedTab    = (int)config["selectedTab"];
     rightAlignTabs = (bool)config["rightAlignTabs"];
     Attach();
 }
        public static void Set(object target, JsDictionary<string, object> options)
        {
            if (options == null)
                return;

            var type = target.GetType();

            if (type == typeof(Object))
                return;

            var propByName = (JsDictionary<string, PropertyInfo>)(type.As<dynamic>().__propByName);
            var fieldByName = (JsDictionary<string, FieldInfo>)(type.As<dynamic>().__fieldByName);

            if (propByName == null)
            {
                var props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);

                var propList = props.Where(x => x.CanWrite &&
                        (x.GetCustomAttributes(typeof(OptionAttribute)).Length > 0 ||
                            x.GetCustomAttributes(typeof(DisplayNameAttribute)).Length > 0));

                propByName = new JsDictionary<string, PropertyInfo>();
                foreach (var k in propList)
                    propByName[ReflectionUtils.MakeCamelCase(k.Name)] = k;

                type.As<dynamic>().__propByName = propByName;
            }

            if (fieldByName == null)
            {
                var fields = type.GetFields(BindingFlags.Public | BindingFlags.Instance);
                var fieldList = fields.Where(x =>
                        (x.GetCustomAttributes(typeof(OptionAttribute)).Length > 0 ||
                            x.GetCustomAttributes(typeof(DisplayNameAttribute)).Length > 0));

                fieldByName = new JsDictionary<string, FieldInfo>();
                foreach (var k in fieldList)
                    fieldByName[ReflectionUtils.MakeCamelCase(k.Name)] = k;

                type.As<dynamic>().__fieldByName = fieldByName;
            }

            foreach (var k in options.Keys)
            {
                var v = options[k];
                var cc = ReflectionUtils.MakeCamelCase(k);
                PropertyInfo p = propByName[cc] ?? propByName[k];
                if (p != null)
                    p.SetValue(target, v);
                else
                {
                    FieldInfo f = fieldByName[cc] ?? fieldByName[k];
                    if (f != null)
                        f.SetValue(target, v);
                }
            }
        }
 public void Room_GetRoomByUser(UserLogicModel user, Action<RoomDataModel> results)
 {
     manager.client.Collection("Room",
         (err, collection) =>
         {
             JsDictionary<string, object> j = new JsDictionary<string, object>();
             j["players.userName"] = user.UserName;
             MongoHelper.Where<RoomDataModel>(collection, j, (a, b) => results(b.Count > 0 ? b[0] : null));
         });
 }
 public void FromWorksForArrayLikeObject()
 {
     var d = new JsDictionary<string, object>();
     d["length"] = 5;
     d["0"] = "A";
     d["1"] = "B";
     d["2"] = "C";
     d["3"] = "D";
     d["4"] = "E";
     Assert.AreEqual(Enumerable.From(d).ToArray(), new[] { "A", "B", "C", "D", "E" });
 }
		void SetNameAndCityAndColorAndCars() {

			var values = new JsDictionary<string,object>();
			values["cars.quantity"]=person.Cars.Quantity+1;
			values["cars.price"]=person.Cars.Price-3;
			values["lastName"]=person.LastName + "Plus";
			values["address.city"]= person.Address.City + "More";
			values["roleColor"]= person.RoleColor == "yellow" ? "#8DD" : "yellow";
			Observable.ToObjectObservable( person )
				.SetProperty(values);
		}
Beispiel #47
0
 public SpriteCache()
 {
     Rings = new List<CanvasInformation>();
     TileChunks = new List<CanvasInformation>();
     Tilepieces = new JsDictionary<string, CanvasInformation>();
     Tiles = new List<ImageElement>();
     SonicSprites = new JsDictionary<string, ImageElement>();
     HeightMaps = new List<CanvasInformation>();
     HeightMapChunks = new JsDictionary<string, CanvasInformation>();
     Indexes = new SpriteCacheIndexes();
 }
Beispiel #48
0
 public GameDrawer()
 {
     cardImages = new JsDictionary<string, ImageElement>();
     for (var i = 101; i < 153; i++) {
         var img = new ImageElement();
         var domain = BuildSite.TopLevelURL + "assets";
         var src = domain + "/cards/" + i;
         string jm;
         img.Src = jm = src + ".gif";
         cardImages[jm] = img;
     }
 }
 private void handler(ServerRequest request, ServerResponse response)
 {
     var dict = new JsDictionary<string, string>();
     dict["Content-Type"] = "text/html";
     dict["Access-Control-Allow-Origin"] = "*";
     if (oldIndex.Count > 0) {
         response.WriteHead(200, dict);
         var inj = ( siteIndex++ ) % oldIndex.Count;
         response.End(oldIndex[inj]);
     } else {
         response.WriteHead(200, dict);
         response.End();
     }
 }
        public GameManager(string gameServerIndex)
        {
            myServerManager = new GameClientManager(gameServerIndex);
            myServerManager.OnGameCreate += CreateGame;
            myServerManager.OnUserAnswerQuestion += UserAnswerQuestion;
            myServerManager.OnUserDisconnect += UserDisconnect;
            myServerManager.OnUserLeave += UserLeave;

            rooms = new List<GameRoom>();
            cachedGames = new JsDictionary<string, GameObject>();
            gameData = new GameData();
            dataManager = new DataManager();
            Global.SetInterval(flushQueue, 50);
        }
 public void DeserializeFromJson_SimpleObject_ShouldWork()
 {
     var json = new JsDictionary<string, object>();
     json["Id"] = 1;
     json["Email"] = "*****@*****.**";
     json["FirstName"] = "John";
     json["LastName"] = "Doe";
     var user = new UserViewModel();
     user.SetFromJSON(json, null);
     Assert.AreEqual(user.Id, json["Id"]);
     Assert.AreEqual(user.Email, json["Email"]);
     Assert.AreEqual(user.FirstName, json["FirstName"]);
     Assert.AreEqual(user.LastName, json["LastName"]);
 }
        public LevelObjectAssetFrame(string name)
        {
            Image = new JsDictionary<int, CanvasInformation>();

            Name = name;
            CollisionMap = new int[100][];
            HurtSonicMap = new int[100][];

            for (var i = 0; i < 100; i++)
            {
                CollisionMap[i] = new int[100];
                HurtSonicMap[i] = new int[100];
            }
        }
        public MapManager(GameManager gameManager, int totalRegionWidth, int totalRegionHeight)
        {
            myGameManager = gameManager;
            myTotalRegionWidth = totalRegionWidth;
            myTotalRegionHeight = totalRegionHeight;
            GameMaps = new JsDictionary<string, GameMap>();
            GameMapLayouts = new List<GameMapLayout>();

            CollisionMap = new CollisionType[myTotalRegionWidth][];
            for (int x = 0; x < myTotalRegionWidth; x++) {
                CollisionMap[x] = new CollisionType[myTotalRegionHeight];
                for (int y = 0; y < myTotalRegionHeight; y++) {
                    CollisionMap[x][y] = 0;
                }
            }
        }
        public void AddUser(ChatRoomModel room, UserLogicModel user, Action<ChatRoomModel> complete)
        {
            manager.client.Collection("ChatRoom",
                                      (err, collection) => {
                                          JsDictionary<string, object> query = new JsDictionary<string, object>();

                                          query["$push"] = new {users = user};

                                          collection.Update(new { _id = MongoDocument.GetID(room.ID) },
                                                            query,
                                                            (err2) => {
                                                                if (err2 != null) Logger.Log("Data Error: " + err2,LogLevel.Error);
                                                                room.Users.Add(user);

                                                                complete(room);
                                                            });
                                      });
        }
        public static void Set(object target, JsDictionary<string, object> options)
        {
            if (options == null)
                return;

            var props = target.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);

            var propByName = props.Where(x => x.CanWrite &&
                    (x.GetCustomAttributes(typeof(OptionAttribute)).Length > 0 ||
                        x.GetCustomAttributes(typeof(DisplayNameAttribute)).Length > 0))
                .ToDictionary(x => ReflectionUtils.MakeCamelCase(x.Name));

            foreach (var k in options.Keys)
            {
                PropertyInfo p;
                if (propByName.TryGetValue(ReflectionUtils.MakeCamelCase(k), out p))
                    p.SetValue(target, options[k]);
            }
        }
        public void AddChatLine(UserLogicModel user, ChatRoomModel room, string message, Action<ChatMessageRoomModel> complete)
        {
            manager.client.Collection("ChatRoom",
                                      (err, collection) => {
                                          ChatMessageRoomModel messageModel = new ChatMessageRoomModel(user, message, DateTime.Now);

                                          JsDictionary<string, object> query = new JsDictionary<string, object>();

                                          query["$push"] = new {messages = messageModel};

                                          collection.Update(new { _id = MongoDocument.GetID(room.ID )},
                                                            query,
                                                            (err2) => {
                                                                if (err2 != null)
                                                                    Logger.Log("Data Error: " + err2,LogLevel.Error);
                                                                room.Messages.Add(messageModel);
                                                                complete(messageModel);
                                                            });
                                      });
        }
Beispiel #57
0
        internal static void Initialize()
        {
            if (knownTypes != null)
                return;

            knownTypes = new JsDictionary<string, Type>();
            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (var type in assembly.GetTypes())
                {
                    if (!type.IsSubclassOf(typeof(Widget)))
                        continue;

                    if (type.IsGenericTypeDefinition)
                        continue;

                    var fullName = type.FullName.ToLower();
                    knownTypes[fullName] = type;

                    var editorAttr = type.GetCustomAttributes(typeof(EditorAttribute), false);
                    if (editorAttr != null && editorAttr.Length > 0)
                    {
                        var attrKey = ((EditorAttribute)editorAttr[0]).Key;
                        if (!attrKey.IsEmptyOrNull())
                            knownTypes[attrKey.ToLower()] = type;
                    }

                    foreach (var k in Q.Config.RootNamespaces)
                    {
                        if (fullName.StartsWith(k.ToLower() + "."))
                        {
                            var kx = fullName.Substr(k.Length + 1).ToLower();
                            if (knownTypes[kx] == null)
                                knownTypes[kx] = type;
                        }
                    }
                }
            }

            SetTypeKeysWithoutEditorSuffix();
        }
        public void RemoveUser(ChatRoomDataModel roomData, UserLogicModel user, Action<ChatRoomDataModel> complete)
        {
            manager.client.Collection("ChatRoom",
                                      (err, collection) =>
                                      {
                                          JsDictionary<string, object> query = new JsDictionary<string, object>();

                                          query["$pop"] = new { users = user };

                                          collection.Update(new { _id = MongoDocument.GetID(roomData.ID) },
                                                            query,
                                                            (err2) =>
                                                            {
                                                                if (err2 != null)
                                                                    ServerLogger.LogError("Data Error: " + err2, user);
                                                                roomData.Users.Remove(user);

                                                                complete(roomData);
                                                            });
                                      });
        }
        public GameServer()
        {
            fs = Global.Require<FS>("fs");
            childProcess = Global.Require<ChildProcess>("child_process");

            dataManager = new DataManager();

            gameServerIndex = "GameServer" + Guid.NewGuid();
            cachedGames = new JsDictionary<string, GameObject>();
            Global.Require<NodeModule>("fibers");
            rooms = new List<GameRoom>();
            gameData = new GameData();
            Global.Process.On("exit", () => Console.Log("exi"));
            /*qManager.AddChannel("Area.Game.Create", (arg1, arg2) =>
                {
                    GameRoom room;
                    rooms.Add(room = new GameRoom());
                });*/

            qManager = new QueueManager(gameServerIndex, new QueueManagerOptions(new[]
                {
                    new QueueWatcher("GameServer", null),
                    new QueueWatcher(gameServerIndex, null),
                }, new[]
                    {
                        "GameServer",
                        "GatewayServer",
                        "Gateway*"
                    }));

            qManager.AddChannel<SomeModel>("SomeNamespaceOrEnum??",
                                                        (user, data) =>
                                                        {
                                                            EmitAll(room, "Area.Game.UpdateState", new Compressor().CompressText(Json.Stringify(room.Game.CardGame.CleanUp())));

            var user = getPlayerByUsername(room, answ.User.UserName);
                                                            qManager.SendMessage(user, user.Gateway, "Area.Game.AskQuestion", gameAnswer.CleanUp());
                                                        });
        }
Beispiel #60
0
        public static JsDictionary<string, int?> IndexByKey(this TabsObject tabs)
        {
            var indexByKey = tabs.As<jQueryObject>().GetDataValue("indexByKey").As<JsDictionary<string, int?>>();
            if (indexByKey == null)
            {
                indexByKey = new JsDictionary<string, int?>();

                tabs.As<jQueryObject>().Children("ul").Children("li").Children("a")
                    .Each((index, el) =>
                    {
                        var href = el.GetAttribute("href").ToString();
                        var prefix = "_Tab";
                        var lastIndex = href.LastIndexOf(prefix);
                        if (lastIndex >= 0)
                            href = href.Substr(lastIndex + prefix.Length);

                        indexByKey[href] = index;
                    });

                tabs.As<jQueryObject>().Data("indexByKey", indexByKey);
            }

            return indexByKey;
        }