Ejemplo n.º 1
0
        protected void Application_Start()
        {
            RouteTable.Routes.MapHubs();
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            if (_configured)
            {
                return;
            }

            var connectionString = ConfigureDatabase();

            Cohort.Initialize(DatabaseType.Sqlite, connectionString, cs => UnitOfWork.Current);
            CohortApi.Register(GlobalConfiguration.Configuration);
            CohortMvc.Register();

            Linger.Backend = () => new DatabaseJobRepository(DatabaseDialect.Sqlite, () => UnitOfWork.Current);
            Schema.Install(UnitOfWork.Current, DatabaseDialect.Sqlite);
            Func <bool> hello = () =>
            {
                Logger.Info("Hello, world!");
                return(true);
            };

            hello.PerformAsync();
            Linger.StartWorker();

            _configured = true;
        }
Ejemplo n.º 2
0
        public void SockOptLinger()
        {
            WithSockets(UnixAddressFamily.AF_INET, UnixSocketType.SOCK_STREAM, UnixSocketProtocol.IPPROTO_TCP, (so1, so2) => {
                Linger linger = new Linger {
                    l_onoff  = 1,
                    l_linger = 42,
                };
                // Set SO_LINGER
                if (Syscall.setsockopt(so1, UnixSocketProtocol.SOL_SOCKET, UnixSocketOptionName.SO_LINGER, linger) < 0)
                {
                    UnixMarshal.ThrowExceptionForLastError();
                }

                // Get and check SO_LINGER
                Linger value;
                if (Syscall.getsockopt(so1, UnixSocketProtocol.SOL_SOCKET, UnixSocketOptionName.SO_LINGER, out value) < 0)
                {
                    UnixMarshal.ThrowExceptionForLastError();
                }
                if (value.l_onoff == 0)
                {
                    Assert.Fail("Linger not enabled");
                }
                Assert.AreEqual(linger.l_linger, value.l_linger);
            });
        }
Ejemplo n.º 3
0
        private static void InstallLinger(DatabaseDialect dialect)
        {
            var repository = new DatabaseJobRepository(dialect, () => UnitOfWork.Current);

            repository.InstallSchema();
            Linger.Backend = repository;
            Linger.StartWorker();
        }
Ejemplo n.º 4
0
        public void Job_is_executed_when_attempted()
        {
            Linger.DelayJobs = false;
            var success = Linger.QueueForExecution(new HelloWorldJob(), 0);

            Assert.IsTrue(success);
            Linger.DelayJobs = true;
        }
Ejemplo n.º 5
0
        private ScheduledJob SaveJob()
        {
            var job       = new HelloWorldJob();
            var scheduled = Linger.CreateScheduledJob(job, 0, null);

            _repository.Save(scheduled);
            Assert.AreEqual(1, scheduled.Id);
            return(scheduled);
        }
Ejemplo n.º 6
0
 // GET linger/jobs
 public ActionResult Jobs()
 {
     return(new ContentResult
     {
         Content = Linger.Dump(),
         ContentEncoding = Encoding.UTF8,
         ContentType = "application/json"
     });
 }
Ejemplo n.º 7
0
        public void Dumps_json_on_request()
        {
            Linger.DelayJobs = true;
            Linger.QueueForExecution(new HelloWorldJob(), runAt: DateTime.Now.AddYears(100));
            var json = Linger.Dump();

            Assert.IsNotNullOrEmpty(json);
            Trace.WriteLine(json);
        }
Ejemplo n.º 8
0
        public void Respects_repeat_information_when_present()
        {
            Linger.DelayJobs = true;
            Linger.QueueForExecution(new HelloWorldJob(), runAt: DateTime.Now.AddYears(100), repeat: job => job.Every().Day());
            var json = Linger.Dump();

            Assert.IsNotNullOrEmpty(json);
            Trace.WriteLine(json);
        }
Ejemplo n.º 9
0
 // GET linger
 public ActionResult Index()
 {
     JsonSerializer.Serialize(new { environment = Environment.MachineName });
     return(new ContentResult
     {
         Content = Linger.Dump(),
         ContentEncoding = Encoding.UTF8,
         ContentType = "application/json"
     });
 }
Ejemplo n.º 10
0
        public void Jobs_in_batches_arent_fetched()
        {
            Assert.DoesNotThrow(() =>
            {
                var scheduled1 = Linger.CreateScheduledJob(new HelloWorldJob(), 0, null);
                _repository.Save(scheduled1);

                var scheduled2 = Linger.CreateScheduledJob(new HelloWorldJob(), 0, null);
                _repository.Save(scheduled2);

                var batch = _repository.CreateBatch("test", new[] { scheduled2 });
                Assert.IsNotNull(batch);
                Assert.IsTrue(batch.Jobs.Contains(scheduled2));

                var all = _repository.GetAll();
                Assert.IsNotNull(all);
                Assert.AreEqual(1, all.Count);

                var available = _repository.GetNextAvailable(2);
                Assert.IsNotNull(available);
                Assert.AreEqual(1, available.Count);
            });
        }
Ejemplo n.º 11
0
		public static bool TryCopy (IntPtr source, out Linger destination)
		{
			return ToLinger (source, out destination) == 0;
		}
Ejemplo n.º 12
0
		private static extern int ToLinger (IntPtr source, out Linger destination);
Ejemplo n.º 13
0
		public static bool TryCopy (ref Linger source, IntPtr destination)
		{
			return FromLinger (ref source, destination) == 0;
		}
Ejemplo n.º 14
0
		private static extern int FromLinger (ref Linger source, IntPtr destination);
Ejemplo n.º 15
0
 public static bool TryCopy(IntPtr source, out Linger destination)
 {
     return(ToLinger(source, out destination) == 0);
 }
Ejemplo n.º 16
0
 private static extern int ToLinger(IntPtr source, out Linger destination);
Ejemplo n.º 17
0
 public static bool TryCopy(ref Linger source, IntPtr destination)
 {
     return(FromLinger(ref source, destination) == 0);
 }
Ejemplo n.º 18
0
 private static extern int FromLinger(ref Linger source, IntPtr destination);
Ejemplo n.º 19
0
 internal static extern SocketError getsockopt(
     [In] SafeCloseSocket socketHandle,
     [In] SocketOptionLevel optionLevel,
     [In] SocketOptionName optionName,
     [Out] out Linger optionValue,
     [In, Out] ref int optionLength);
Ejemplo n.º 20
0
 internal static partial SocketError getsockopt(
     SafeSocketHandle socketHandle,
     SocketOptionLevel optionLevel,
     SocketOptionName optionName,
     out Linger optionValue,
     ref int optionLength);
Ejemplo n.º 21
0
        private void SetLingerOption(LingerOption lref)
        {
            var optionValue = new Linger()
            {
                OnOff = lref.Enabled ? (ushort)1 : (ushort)0,
                Time = (ushort)lref.LingerTime
            };

            if (UnsafeMethods.setsockopt(Handle, SocketOptionLevel.Socket, SocketOptionName.Linger, ref optionValue, 4) ==
                SocketError.SocketError)
            {
                throw new SocketException();
            }
        }
Ejemplo n.º 22
0
 internal static extern SocketError setsockopt(
     [In] SafeSocketHandle socketHandle,
     [In] SocketOptionLevel optionLevel,
     [In] SocketOptionName optionName,
     [In] ref Linger linger,
     [In] int optionLength);
Ejemplo n.º 23
0
 internal static partial SocketError setsockopt(
     SafeSocketHandle socketHandle,
     SocketOptionLevel optionLevel,
     SocketOptionName optionName,
     ref Linger linger,
     int optionLength);