Example #1
0
            private static void LoadScriptData(string name)
            {
                if (!registered.ContainsKey(name))
                {
                    throw new Exception(String.Format("Script data {0} is not found in registered script list!", name));
                }

                name = name + ".js?" + registered[name];

                SyncLoadScript(Q.ResolveUrl("~/DynJS.axd/") + name);
            }
Example #2
0
        public CreatedUI <T> CreateSingleton <T>(string ui, Action <T, jQueryObject> populateScope) where T : ManagedScope
        {
            T scope;

            if (singltons.ContainsKey(ui))
            {
                var html = singltons[ui];
                if (html.Parent().Length == 0)
                {
                    singltons.Remove(ui);
                }
            }

            if (singltons.ContainsKey(ui))
            {
                var html = singltons[ui];
                if (html[0].NodeType == XmlNodeType.Comment)
                {
                    singltons[ui] = html = (AngularElement)html.Next();
                }

                scope = myRootScopeService.New <T>();
                populateScope(scope, html);
                var item = myCompileService(html)(scope);
                if (scope.Phase == null)
                {
                    scope.Apply();
                }

                scope = angular.Element(item.Children()[0]).Scope <T>() ?? scope;
                return(new CreatedUI <T>(scope, html));
            }
            else
            {
                scope = myRootScopeService.New <T>();
                var html = jQuery.FromHtml(string.Format("<div ng-include src=\"'{1}partials/UIs/{0}.html'\"></div>", ui, Constants.ContentAddress));
                populateScope(scope, html);
                var item = myCompileService(html)(scope);
                item.AppendTo(Window.Document.Body);
                if (scope.Phase == null)
                {
                    scope.Apply();
                }

                scope         = angular.Element(item.Children()[0]).Scope <T>() ?? scope;
                singltons[ui] = item;

                return(new CreatedUI <T>(scope, item));
            }
        }
Example #3
0
        public static Type Get(string key)
        {
            if (!knownTypes.ContainsKey(key))
            {
                string typeName = key + "Dialog";

                Type dialogType = null;
                foreach (var ns in Q.Config.RootNamespaces)
                {
                    dialogType = Type.GetType(ns + "." + typeName);
                    if (dialogType != null && typeof(IDialog).IsAssignableFrom(dialogType))
                    {
                        break;
                    }
                }

                if (dialogType == null)
                {
                    throw new Exception(typeName + " dialog class is not found!");
                }

                knownTypes[key] = dialogType;
            }

            return(knownTypes[key]);
        }
Example #4
0
 public JsDictionary <TKey, TValue> d;      // = new Dictionary<TKey,TValue>();
 public TValue this[TKey key] {
     get{
         return(d.ContainsKey(key)? d[key] : default(TValue));
     }
     set{
         d[key] = value;
     }
 }
Example #5
0
        public static bool Option(OptionType option)
        {
            bool result = false;

            if (Options.ContainsKey(option))
            {
                result = Options[option];
            }
            return(result);
        }
Example #6
0
        private List <string> GetSortedGroupAndPermissionKeys(out JsDictionary <string, string> titleByKey)
        {
            var keys = Q.GetRemoteData <ListResponse <string> >("Administration.PermissionKeys").Entities;

            titleByKey = new JsDictionary <string, string>();
            var titleWithGroup = new JsDictionary <string, string>();

            foreach (var k in keys)
            {
                var s = k;
                if (string.IsNullOrEmpty(s))
                {
                    continue;
                }

                if (s.EndsWith(":")) // permission keys can't end with ':'
                {
                    s = s.Substr(0, s.Length - 1);
                    if (s.Length == 0)
                    {
                        continue;
                    }
                }

                if (titleByKey.ContainsKey(s))
                {
                    continue;
                }

                titleByKey[s] = Q.TryGetText("Permission." + s) ?? s;

                var parts      = s.Split(':');
                var group      = "";
                var groupTitle = "";
                for (var i = 0; i < parts.Length - 1; i++)
                {
                    group                 = group + parts[i] + ":";
                    titleByKey[group]     = Q.TryGetText("Permission." + group) ?? parts[i];
                    groupTitle            = groupTitle + titleByKey[group] + ":";
                    titleWithGroup[group] = groupTitle;
                }

                titleWithGroup[s] = groupTitle + titleByKey[s];
            }

            keys = titleByKey.Keys.ToList();
            keys.Sort((x, y) => Q.Externals.TurkishLocaleCompare(
                          titleWithGroup[x], titleWithGroup[y]));

            return(keys);
        }
Example #7
0
 /// <summary>
 /// On the server, an easier way to obtain a parser is through the SaltarelleParserFactory class.
 /// </summary>
 public SaltarelleParser(INodeProcessor[] pluginNodeProcessors, IDictionary <string, ITypedMarkupParserImpl> pluginTypedMarkupParsers, IUntypedMarkupParserImpl[] pluginUntypedMarkupParsers)
 {
                 #if CLIENT
     JsDictionary cfg = JsDictionary.GetDictionary(pluginNodeProcessors);
     if (!Script.IsNullOrUndefined(cfg) && cfg.ContainsKey("pluginNodeProcessors"))
     {
         // We have an [AlternateSignature] constructor which can cause us to be called with a config object instead of real parameters
         configObject = cfg;
         return;
     }
                 #endif
     docProcessor = new DocumentProcessor(pluginNodeProcessors, new TypedMarkupParser(pluginTypedMarkupParsers), new UntypedMarkupParser(pluginUntypedMarkupParsers));
     this.pluginNodeProcessors       = pluginNodeProcessors ?? new INodeProcessor[0];
     this.pluginTypedMarkupParsers   = pluginTypedMarkupParsers ?? new Dictionary <string, ITypedMarkupParserImpl>();
     this.pluginUntypedMarkupParsers = pluginUntypedMarkupParsers ?? new IUntypedMarkupParserImpl[0];
 }
Example #8
0
        public static void SetIndents <TEntity>(IList <TEntity> items, Func <TEntity, object> getId, Func <TEntity, object> getParentId,
                                                bool?setCollapsed = true)
        {
            var depth  = 0;
            var depths = new JsDictionary <object, int>();

            for (var line = 0; line < items.Count; line++)
            {
                var item = items[line];
                if (line > 0)
                {
                    var parentId = getParentId(item);

                    if (parentId != null &&
                        parentId == getId(items[line - 1]))
                    {
                        depth += 1;
                    }
                    else if (parentId == null)
                    {
                        depth = 0;
                    }
                    else if (parentId != getParentId(items[line - 1]))
                    {
                        if (depths.ContainsKey(parentId))
                        {
                            depth = depths[parentId] + 1;
                        }
                        else
                        {
                            depth = 0;
                        }
                    }
                }
                depths[getId(item)]     = depth;
                ((dynamic)item)._indent = depth;
                if (setCollapsed != null)
                {
                    ((dynamic)item)._collapsed = setCollapsed.Value;
                }
            }
        }
Example #9
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! If you have recently defined this enum type in server side code, " +
                                                  "make sure your project builds successfully and transform T4 templates. Also make sure that enum is under your project root namespace, " +
                                                  "and your namespace parts starts with capital letters, e.g. MyProject.Pascal.Cased namespace", key));
            }

            return(knownTypes[key]);
        }
Example #10
0
        private static Type GetEditorType(string editorTypeKey)
        {
            if (editorTypeKey == null)
            {
                throw new ArgumentNullException("editorTypeKey");
            }

            if (!KnownEditorTypes.ContainsKey(editorTypeKey))
            {
                Type editorType = null;
                foreach (var ns in Q.Config.RootNamespaces)
                {
                    editorType = Type.GetType(ns + "." + editorTypeKey) ?? Type.GetType(ns + "." + editorTypeKey + "Editor");
                    if (editorType != null)
                    {
                        break;
                    }
                }

                if (editorType != null)
                {
                    if (!typeof(Widget).IsAssignableFrom(editorType))
                    {
                        throw new Exception(String.Format("{0} editor type is not a subclass of Widget", editorType.FullName));
                    }

                    KnownEditorTypes[editorTypeKey] = editorType;

                    return(editorType);
                }
                else
                {
                    throw new Exception(String.Format("PropertyGrid: Can't find {0} editor type!", editorTypeKey));
                }
            }
            else
            {
                return(KnownEditorTypes[editorTypeKey]);
            }
        }
Example #11
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]);
        }
        public static Type Get(string key)
        {
            if (!knownTypes.ContainsKey(key))
            {
                var typeName   = key;
                var dialogType = Search(typeName);

                if (dialogType == null && !key.EndsWith("Dialog"))
                {
                    typeName   = key + "Dialog";
                    dialogType = Search(typeName);
                }

                if (dialogType == null)
                {
                    throw new Exception(typeName + " dialog class is not found!");
                }

                knownTypes[key] = dialogType;
            }

            return(knownTypes[key]);
        }
Example #13
0
        private static void GetPlayerCluster(JsDictionary <int, PlayerClusterInfo> playerClusterInfoHits, List <PlayerClusterInfo> playerClusterInfoHitsArray, Dictionary <Player, PlayerClusterInfo> allPlayerClusterInformations, PlayerClusterInfo currentPlayerClusterInfo, JsDictionary <int, Player> hitPlayers)
        {
            List <Tuple <double, PlayerClusterInfo> > neighbors = new List <Tuple <double, PlayerClusterInfo> >();

            neighbors.Add(new Tuple <double, PlayerClusterInfo>(0, currentPlayerClusterInfo));
            int totalPlayers = 0;

            while (neighbors.Count > 0)
            {
                var activePlayerClusterInfo = neighbors[0];


                if (!hitPlayers.ContainsKey(activePlayerClusterInfo.Item2.Player.Id) || playerClusterInfoHits.ContainsKey(activePlayerClusterInfo.Item2.Player.Id))
                {
                    neighbors.Remove(activePlayerClusterInfo);
                    continue;
                }
                playerClusterInfoHits[activePlayerClusterInfo.Item2.Player.Id] = activePlayerClusterInfo.Item2;
                playerClusterInfoHitsArray.Add(activePlayerClusterInfo.Item2);
                totalPlayers++;
                if (totalPlayers == MaxClusterSize)
                {
                    return;
                }
                foreach (Tuple <double, Player> playerNeighbor in activePlayerClusterInfo.Item2.Neighbors)
                {
                    neighbors.Add(new Tuple <double, PlayerClusterInfo>(playerNeighbor.Item1, allPlayerClusterInformations[playerNeighbor.Item2]));
                }
                neighbors.Remove(activePlayerClusterInfo);

                neighbors.Sort((a, b) => (int)(a.Item1 - b.Item1));
                if (neighbors.Count > 100)
                {
                    neighbors.RemoveRange(100, neighbors.Count - 100);
                }
            }
        }
Example #14
0
        public static Type TryGet(string key)
        {
            if (!knownTypes.ContainsKey(key))
            {
                var typeName   = key;
                var dialogType = Search(typeName);

                if (dialogType == null && !key.EndsWith("Dialog"))
                {
                    typeName   = key + "Dialog";
                    dialogType = Search(typeName);
                }

                if (dialogType == null)
                {
                    return(null);
                }

                knownTypes[key] = dialogType;
                return(dialogType);
            }

            return(knownTypes[key]);
        }
Example #15
0
        public static string Singularize(string word)
        {
            Initialize();

            if (singularizeCache != null &&
                singularizeCache.ContainsKey(word))
            {
                return(singularizeCache[word]);
            }

            string result = word;

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

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

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

            return(result);
        }
Example #16
0
        private static void GetPlayerCluster(JsDictionary<int, PlayerClusterInfo> playerClusterInfoHits, List<PlayerClusterInfo> playerClusterInfoHitsArray, Dictionary<Player, PlayerClusterInfo> allPlayerClusterInformations, PlayerClusterInfo currentPlayerClusterInfo, JsDictionary<int, Player> hitPlayers)
        {

            List<Tuple<double, PlayerClusterInfo>> neighbors = new List<Tuple<double, PlayerClusterInfo>>();
            neighbors.Add(new Tuple<double, PlayerClusterInfo>(0, currentPlayerClusterInfo));
            int totalPlayers = 0;
            while (neighbors.Count > 0)
            {
                var activePlayerClusterInfo = neighbors[0];


                if (!hitPlayers.ContainsKey(activePlayerClusterInfo.Item2.Player.Id) || playerClusterInfoHits.ContainsKey(activePlayerClusterInfo.Item2.Player.Id))
                {
                    neighbors.Remove(activePlayerClusterInfo);
                    continue;
                }
                playerClusterInfoHits[activePlayerClusterInfo.Item2.Player.Id] = activePlayerClusterInfo.Item2;
                playerClusterInfoHitsArray.Add(activePlayerClusterInfo.Item2);
                totalPlayers++;
                if (totalPlayers == MaxClusterSize) return;
                foreach (Tuple<double, Player> playerNeighbor in activePlayerClusterInfo.Item2.Neighbors)
                {
                    neighbors.Add(new Tuple<double, PlayerClusterInfo>(playerNeighbor.Item1,allPlayerClusterInformations[playerNeighbor.Item2]));
                }
                neighbors.Remove(activePlayerClusterInfo);

                neighbors.Sort((a, b) => (int)(a.Item1 - b.Item1));
                if (neighbors.Count > 100)
                {
                    neighbors.RemoveRange(100, neighbors.Count - 100);
                }

                
            }


        }
Example #17
0
        private JsDictionary <string, int> CreateCategoryLinks(jQueryObject container, List <PropertyItem> items)
        {
            int idx       = 0;
            var itemIndex = new JsDictionary <string, int>();

            foreach (var x in items)
            {
                x.Category        = x.Category ?? options.DefaultCategory ?? "";
                itemIndex[x.Name] = idx++;
            }

            var self          = this;
            var categoryOrder = GetCategoryOrder(items);

            items.Sort((x, y) =>
            {
                var c = 0;

                if (x.Category != y.Category)
                {
                    var c1 = categoryOrder[x.Category];
                    var c2 = categoryOrder[y.Category];
                    if (c1 != null && c2 != null)
                    {
                        c = c1.Value - c2.Value;
                    }
                    else if (c1 != null)
                    {
                        c = -1;
                    }
                    else if (c2 != null)
                    {
                        c = 1;
                    }
                }

                if (c == 0)
                {
                    c = String.Compare(x.Category, y.Category);
                }

                if (c == 0)
                {
                    c = itemIndex[x.Name].CompareTo(itemIndex[y.Name]);
                }

                return(c);
            });

            var categoryIndexes = new JsDictionary <string, int>();

            for (int i = 0; i < items.Count; i++)
            {
                var item = items[i];

                if (!categoryIndexes.ContainsKey(item.Category))
                {
                    int index = categoryIndexes.Count + 1;
                    categoryIndexes[item.Category] = index;

                    if (index > 1)
                    {
                        J("<span/>")
                        .AddClass("separator")
                        .Text("|")
                        .PrependTo(container);
                    }

                    J("<a/>")
                    .AddClass("category-link")
                    .Text(DetermineText(item.Category, prefix => prefix + "Categories." + item.Category))
                    .Attribute("tabindex", "-1")
                    .Attribute("href", "#" + options.IdPrefix + "Category" + index.ToString())
                    .Click(CategoryLinkClick)
                    .PrependTo(container);
                }
            }

            J("<div/>")
            .AddClass("clear")
            .AppendTo(container);

            return(categoryIndexes);
        }
Example #18
0
        public GridRowSelectionMixin(IDataGrid grid)
        {
            this.grid    = grid;
            this.idField = grid.GetView().IdField;

            grid.GetGrid().OnClick.Subscribe((e, p) => {
                if (J(e.Target).HasClass("select-item"))
                {
                    e.PreventDefault();

                    var item = grid.GetView().GetItem(p.row);
                    var id   = item[idField].toString();

                    if (include.ContainsKey(id))
                    {
                        include.Remove(id);
                    }
                    else
                    {
                        include[id] = true;
                    }

                    for (var i = 0; i < grid.GetView().GetLength(); i++)
                    {
                        grid.GetGrid().UpdateRow(i);
                    }

                    UpdateSelectAll();
                }
            });

            grid.GetGrid().OnHeaderClick.Subscribe((e, u) =>
            {
                if (e.IsDefaultPrevented())
                {
                    return;
                }

                if (J(e.Target).HasClass("select-all-items"))
                {
                    e.PreventDefault();
                    var view = grid.GetView();

                    if (include.Count > 0)
                    {
                        include.Clear();
                    }
                    else
                    {
                        foreach (var x in grid.GetView().GetItems())
                        {
                            var id = x[idField];
                            include[id.toString()] = true;
                        }
                    }
                    UpdateSelectAll();
                    grid.GetView().SetItems(grid.GetView().GetItems(), true);
                }
            });

            grid.GetView().OnRowsChanged.Subscribe((e, u) => UpdateSelectAll());
        }