Esempio n. 1
0
        /// <summary>
        /// Adds a custom update loop.
        /// </summary>
        /// <param name="updateLoop">The custom update loop implementation.</param>
        /// <param name="parentLoop">Which Unity update loop should this be run under?</param>
        /// <param name="priority">A priority that decides whether this update loop runs before or after other custom update loops.</param>
        public static void AddCustomUpdateLoop(ICustomUpdateLoop updateLoop, UpdateLoop parentLoop = UpdateLoop.Update, int priority = 0)
        {
            if (_idToUpdateLoop == null)
            {
                _idToUpdateLoop      = new Dictionary <int, ICustomUpdateLoop>(4);
                _idToUnityUpdateLoop = new Dictionary <int, UpdateLoop>(4);
                _customUpdateLoops   = new Dictionary <int, PrioritizedList <ICustomUpdateLoop> >(3);
            }

            PrioritizedList <ICustomUpdateLoop> customLoops;

            if (!_customUpdateLoops.TryGetValue((int)parentLoop, out customLoops))
            {
                _customUpdateLoops[(int)parentLoop] = customLoops = new PrioritizedList <ICustomUpdateLoop>(4);
            }

            var id = updateLoop.Event.Id;

            if (_idToUpdateLoop.ContainsKey(id))
            {
                Debug.LogErrorFormat("An update loop with ID '{0}' is already registered.", id);
                return;
            }

            _idToUpdateLoop[id]      = updateLoop;
            _idToUnityUpdateLoop[id] = parentLoop;
            customLoops.Add(updateLoop, priority);
        }
 private static void Fill(PrioritizedList <object> list, int startPriority, int endPriority)
 {
     for (var priority = startPriority; priority <= endPriority; priority++)
     {
         list.Add(new object(), priority);
     }
 }
        public void Remove_Empty_NoErrors()
        {
            var item = new object();
            var list = new PrioritizedList <object>();

            Assert.DoesNotThrow(() => list.Remove(item));
        }
        public void Add_ItemIsAdded()
        {
            var item = new object();
            var list = new PrioritizedList <object>();

            list.Add(item);

            Assert.IsTrue(list.Contains(item));
        }
        public void Clear_EverythingIsRemoved()
        {
            var list = new PrioritizedList <object>();

            Fill(list, -5, 5);
            list.Clear();

            Assert.AreEqual(0, list.Count);
        }
        public void Contains_False()
        {
            var item = new object();
            var list = new PrioritizedList <object>();

            Fill(list, -5, 5);

            Assert.IsFalse(list.Contains(item));
        }
        public void Add_Descending_SamePriority_IsAddedAfterOthers()
        {
            var item = new object();
            var list = new PrioritizedList <object>(ListSortDirection.Descending);

            Fill(list, -5, 5);
            list.Add(item, list[3].Priority);

            Assert.AreSame(item, list[4].Item);
        }
        public void Add_Descending_HighestPriority_IsAddedFirst()
        {
            var item = new object();
            var list = new PrioritizedList <object>(ListSortDirection.Descending);

            Fill(list, -5, 5);
            list.Add(item, 100);

            Assert.AreSame(item, list[0].Item);
        }
        public void Add_Descending_LowestPriority_IsAddedLast()
        {
            var item = new object();
            var list = new PrioritizedList <object>(ListSortDirection.Descending);

            Fill(list, -5, 5);
            list.Add(item, -100);

            Assert.AreSame(item, list[list.Count - 1].Item);
        }
        public void IndexOf_FindsItem()
        {
            var item = new object();
            var list = new PrioritizedList <object>();

            Fill(list, -5, 5);
            list.Add(item, list[4].Priority);

            var index = list.IndexOf(item);

            Assert.AreEqual(5, index);
        }
        public void Remove_TargetIsRemoved()
        {
            var item = new object();
            var list = new PrioritizedList <object> {
                item
            };

            Fill(list, -5, 5);
            list.Remove(item);

            Assert.IsFalse(list.Contains(item));
        }
        public static void RegisterTypeVisualizer(string rosMessageName, IVisualFactory visualFactory, int priority = 0, MessageSubtopic subtopic = MessageSubtopic.Default)
        {
            Dictionary <string, PrioritizedList <IVisualFactory> > factoriesTable = (subtopic != MessageSubtopic.Response) ? s_TypeVisualFactories : s_TypeResponseVisualFactories;
            PrioritizedList <IVisualFactory> currentEntry;

            if (!factoriesTable.TryGetValue(rosMessageName, out currentEntry))
            {
                currentEntry = new PrioritizedList <IVisualFactory>();
                currentEntry.Add(s_DefaultVisualFactory, int.MinValue);
                factoriesTable[rosMessageName] = currentEntry;
            }
            currentEntry.Add(visualFactory, priority);
        }
        public static void RegisterTopicVisualizer(string topic, IVisualFactory visualFactory, int priority = 0, MessageSubtopic subtopic = MessageSubtopic.Default)
        {
            if (topic == null)
            {
                Debug.Log("Registered null topic!");
            }
            Dictionary <string, PrioritizedList <IVisualFactory> > factoriesTable = (subtopic != MessageSubtopic.Response) ? s_TopicVisualFactories : s_TopicResponseVisualFactories;
            PrioritizedList <IVisualFactory> currentEntry;

            if (!factoriesTable.TryGetValue(topic, out currentEntry))
            {
                currentEntry          = new PrioritizedList <IVisualFactory>();
                factoriesTable[topic] = currentEntry;
            }
            currentEntry.Add(visualFactory, priority);
        }
Esempio n. 14
0
        public List <T> Sort(List <T> input)
        {
            PrioritizedList list = new PrioritizedList(input);

            foreach (T handle in input)
            {
                if (handle.Dependencies.Count > 0)
                {
                    foreach (string parent in handle.Dependencies)
                    {
                        list.Increment(handle, list.GetRise(parent));
                    }
                }
            }
            return(list.Convert());
        }
Esempio n. 15
0
        public void Reload()
        {
            if (_isLoaded)
            {
                Unload();
                Context = new PluginLoadContext();
            }

            _isLoaded = true;
            bool reloadAfter = false;
            List <PluginDomain> domainCache = new List <PluginDomain>();

            foreach (string pluginPath in Directory.GetFiles(Bridge.PluginsPath))
            {
                if (!Path.GetExtension(pluginPath).ToLower().Contains("dll"))
                {
                    continue;
                }
                PluginDomain domain = new PluginDomain(this, pluginPath);
                domain.Initialize();
                if (domain.Plugin.State == PluginState.Failed)
                {
                    continue;
                }
                if (domain.UpdatingData != null)
                {
                    if (!Bridge.Config.KeepPluginsUpdated)
                    {
                        Bridge.Logger.Warn("There is an update available for {PLUGIN} ({OLD} -> {NEW})!",
                                           domain.Plugin.Display, domain.Plugin.Meta.Version, domain.UpdatingData.Version);
                    }
                    else
                    {
                        Bridge.Logger.Warn("There is an update available for {PLUGIN} ({OLD} -> {NEW})! Starting updater...",
                                           domain.Plugin.Display, domain.Plugin.Meta.Version, domain.UpdatingData.Version);
                        AutoUpdater updater = new AutoUpdater(domain);
                        updater.Start();
                        reloadAfter = true;
                    }
                }

                if (domain.PackageProvider != null)
                {
                    domain.Plugin.Logger.Info("Found a package provider! Exporting package...");
                    domain.PackageProvider.Export(Path.Combine(Bridge.PackagePath, domain.PackageProvider.Name));
                    AddPackage(domain.PackageProvider.Name);
                    domain.Plugin.Logger.Info("Package {NAME} successfully provided!", domain.PackageProvider.Name);
                }

                domainCache.Add(domain);
            }

            if (reloadAfter)
            {
                Reload();
                return;
            }

            File.WriteAllText(Path.Combine(Bridge.ServerPath, "server_config.json"),
                              Bridge.ServerConfig.ToString(Formatting.Indented));

            PrioritizedList list = new PrioritizedList(domainCache);

            foreach (PluginDomain handle in domainCache)
            {
                if (handle.Plugin.Meta.Dependencies.Length > 0)
                {
                    foreach (string parent in handle.Plugin.Meta.Dependencies)
                    {
                        list.Increment(handle, list.GetRise(parent));
                    }
                }
            }

            domainCache = list.Convert();
            Domains     = new List <PluginDomain>();
            foreach (PluginDomain domain in domainCache)
            {
                if (domain.Plugin.Meta.Id == "_global" || domain.Plugin.Meta.Name == "_global")
                {
                    Bridge.Logger.Fatal(
                        "Could not load plugin {ID} on path \"{PATH}\" because either the id or the name has is a blacklisted word!",
                        domain.Plugin.Meta.Id, domain.Path);
                    return;
                }

                Plugin otherPlugin = GetPlugin(domain.Plugin.Meta.Id);
                if (otherPlugin != null)
                {
                    Bridge.Logger.Warn(
                        "Could not loading plugin {ID} on path \"{PATH}\" because the id is already occupied by the plugin {ID2} on the path {PATH2}!",
                        domain.Plugin.Meta.Id, domain.Path, otherPlugin.Meta.Id, otherPlugin.FilePath);
                    continue;
                }

                Domains.Add(domain);
                domain.Start();
            }
        }