Esempio n. 1
0
        /// <inheritdoc />
        public IPluginDescriptor RegisterPlugin(PluginRegistration pluginRegistration)
        {
            if (pluginRegistration == null)
            {
                throw new ArgumentNullException("pluginRegistration");
            }
            if (pluginRegistration.AssemblyBindings.Contains(null))
            {
                throw new ArgumentException("The assembly references must not contain a null reference.", "pluginRegistration");
            }
            if (pluginRegistration.PluginDependencies.Contains(null))
            {
                throw new ArgumentException("The plugin dependencies must not contain a null reference.", "pluginRegistration");
            }
            if (pluginRegistration.ProbingPaths.Contains(null))
            {
                throw new ArgumentException("The probing paths must not contain a null reference.", "pluginRegistration");
            }

            return(dataBox.Write(data =>
            {
                if (data.GetPluginById(pluginRegistration.PluginId) != null)
                {
                    throw new ArgumentException(string.Format("There is already a plugin registered with id '{0}'.", pluginRegistration.PluginId), "pluginRegistration");
                }

                List <IPluginDescriptor> pluginDependencies = new List <IPluginDescriptor>(pluginRegistration.PluginDependencies);

                foreach (IPluginDescriptor pluginDependency in pluginRegistration.PluginDependencies)
                {
                    if (data.GetPluginById(pluginDependency.PluginId) != pluginDependency)
                    {
                        throw new ArgumentException(
                            "One of the plugin dependencies does not belong to this registry.", "pluginRegistration");
                    }

                    foreach (IPluginDescriptor secondOrderPluginDependency in pluginDependency.PluginDependencies)
                    {
                        if (!pluginDependencies.Contains(secondOrderPluginDependency))
                        {
                            pluginDependencies.Add(secondOrderPluginDependency);
                        }
                    }
                }

                PluginDescriptor plugin = new PluginDescriptor(this, pluginRegistration, pluginDependencies);
                data.RegisterPlugin(plugin);
                return plugin;
            }));
        }
Esempio n. 2
0
        public void Write_WithFunc_ProvidesContents()
        {
            LockBox <int> box = new LockBox <int>(11);

            int actualValue = box.Write(value => value);

            Assert.AreEqual(11, actualValue);
        }
Esempio n. 3
0
        public void Write_WithAction_ProvidesContents()
        {
            LockBox<int> box = new LockBox<int>(11);

            int actualValue = 0;
            box.Write(value => actualValue = value);
            Assert.AreEqual(11, actualValue);
        }
Esempio n. 4
0
        /// <inheritdoc />
        public void RunTask(string queueId)
        {
            currentWorkerTasks.Write(tasks =>
            {
                if (tasks.ContainsKey(queueId))
                {
                    return;
                }

                var command = taskQueue.GetNextTask(queueId);

                if (command == null)
                {
                    return;
                }

                BeginNextTask(queueId, command, tasks);
            });
        }
Esempio n. 5
0
        public void ReadersAndWritersDoNotInterfere()
        {
            LockBox <StringBuilder> box = new LockBox <StringBuilder>(new StringBuilder());

            int  writeCount = 0;
            bool done       = false;

            for (int i = 0; i < 10; i++)
            {
                if (i % 3 != 0)
                {
                    Tasks.StartThreadTask("Reader", () =>
                    {
                        while (!done)
                        {
                            box.Read(value => Assert.IsTrue(value.Length % 2 == 0));
                            Thread.Sleep(0);
                        }
                    });
                }
                else
                {
                    Tasks.StartThreadTask("Writer", () =>
                    {
                        while (!done)
                        {
                            box.Write(value =>
                            {
                                Assert.IsTrue(value.Length % 2 == 0);
                                value.Append('x');

                                Thread.Sleep(1);

                                Assert.IsTrue(value.Length % 2 == 1);
                                value.Append('x');

                                writeCount += 1;
                            });
                        }
                    });
                }
            }

            Thread.Sleep(200);
            done = true;
            Tasks.JoinAndVerify(new TimeSpan(0, 0, 1));

            box.Read(value => Assert.AreEqual(writeCount * 2, value.Length));
        }
Esempio n. 6
0
        public void Write_WhenFuncIsNull_Throws()
        {
            LockBox <int> box = new LockBox <int>(11);

            Assert.Throws <ArgumentNullException>(() => box.Write <object>(null));
        }
Esempio n. 7
0
 public static void Log(CorrelatedExceptionEventArgs e)
 {
     Logger.Write(bl => LogImpl(e));
 }
Esempio n. 8
0
        public void Write_WhenFuncIsNull_Throws()
        {
            LockBox<int> box = new LockBox<int>(11);

            Assert.Throws<ArgumentNullException>(() => box.Write<object>(null));
        }
Esempio n. 9
0
        public void ReadersAndWritersDoNotInterfere()
        {
            LockBox<StringBuilder> box = new LockBox<StringBuilder>(new StringBuilder());

            int writeCount = 0;
            bool done = false;
            for (int i = 0; i < 10; i++)
            {
                if (i % 3 != 0)
                {
                    Tasks.StartThreadTask("Reader", () =>
                    {
                        while (! done)
                        {
                            box.Read(value => Assert.IsTrue(value.Length%2 == 0));
                            Thread.Sleep(0);
                        }
                    });
                }
                else
                {
                    Tasks.StartThreadTask("Writer", () =>
                    {
                        while (!done)
                        {
                            box.Write(value =>
                            {
                                Assert.IsTrue(value.Length%2 == 0);
                                value.Append('x');

                                Thread.Sleep(1);

                                Assert.IsTrue(value.Length%2 == 1);
                                value.Append('x');

                                writeCount += 1;
                            });
                        }
                    });
                }
            }

            Thread.Sleep(200);
            done = true;
            Tasks.JoinAndVerify(new TimeSpan(0, 0, 1));

            box.Read(value => Assert.AreEqual(writeCount * 2, value.Length));
        }