Beispiel #1
0
 /// <summary>
 /// Constructs a proxy for the time-step with the given
 /// <paramref name="timestepGuid"/> within the given
 /// <paramref name="session"/>.
 /// </summary>
 /// <param name="timestepGuid"></param>
 /// <param name="session"></param>
 public TimestepProxy(Guid timestepGuid, ISessionInfo session)
 {
     this.ID          = timestepGuid;
     this.Session     = session;
     realTimestepInfo = new ExpirableLazy <TimestepInfo>(
         () => session.Database.Controller.DBDriver.LoadTimestepInfo(timestepGuid, session, session.Database),
         t => Utils.GetTimestepFileWriteTime(t) == t.WriteTime);
 }
Beispiel #2
0
 /// <summary>
 /// Creates a proxy for the grid with id <paramref name="gridGuid"/>
 /// within the given <paramref name="database"/>
 /// </summary>
 /// <param name="gridGuid"></param>
 /// <param name="database"></param>
 public GridProxy(Guid gridGuid, IDatabaseInfo database)
 {
     this.ID       = gridGuid;
     this.Database = database;
     realGrid      = new ExpirableLazy <GridCommons>(
         () => database.Controller.DBDriver.LoadGridInfo(gridGuid, database).Cast <GridCommons>(),
         g => Utils.GetGridFileWriteTime(g) == g.WriteTime);
 }
Beispiel #3
0
        public void ProviderOneTimeException()
        {
            int      value              = 0;
            Provider theSame            = new Provider(1);
            ExpirableLazy <Provider> el = new ExpirableLazy <Provider>(
                () => {
                if (value++ == 0)
                {
                    Thread.Sleep(5000);
                    throw new Exception();
                }
                return(theSame);
            }, new TimeSpan(0, 1, 0));
            bool   exception = false;
            Thread a         = new Thread(() =>
            {
                try
                {
                    Provider ret = el.Value;
                }
                catch (Exception)
                {
                    exception = true;
                }
            });

            a.Start();

            Thread b = new Thread(() =>
            {
                try
                {
                    Provider ret = el.Value;
                }
                catch (Exception)
                {
                    exception = true;
                }
            });

            b.Start();
            b.Interrupt();

            Provider[] aux = new Provider[1];
            Thread     c   = new Thread(() =>
            {
                aux[0] = el.Value;
            });

            c.Start();

            a.Join();
            b.Join();
            c.Join();

            Assert.True(exception);
            Assert.Equal(theSame, aux[0]);
        }
Beispiel #4
0
 /// <summary>
 /// Constructs a proxy for the session with id
 /// <paramref name="sessionID"/> within the given
 /// <paramref name="database"/>
 /// </summary>
 /// <param name="sessionID"></param>
 /// <param name="database"></param>
 public SessionProxy(Guid sessionID, IDatabaseInfo database)
 {
     this.ID         = sessionID;
     this.Database   = database;
     realSessionInfo = new ExpirableLazy <SessionInfo>(
         delegate() {
         // Allow graceful handling when loading faulty sessions
         try {
             return(database.Controller.DBDriver.LoadSession(sessionID, database));
         } catch (Exception e) {
             Console.WriteLine(
                 "Loading session {0} failed with message '{1}'", ID, e.Message);
             return(null);
         }
     },
         s => Utils.GetSessionFileWriteTime(s) == s.WriteTime);
 }
Beispiel #5
0
        public void ProviderAlwaysException()
        {
            int      numberOfThreads    = 1000;
            int      value              = 888;
            Provider theSame            = new Provider(value);
            ExpirableLazy <Provider> el = new ExpirableLazy <Provider>(
                () => {
                throw new Exception();
            }, new TimeSpan(0, 1, 0));

            Thread[] allThreads = new Thread[numberOfThreads];
            bool[]   allResults = new bool[numberOfThreads];

            for (int i = 0; i < numberOfThreads; i++)
            {
                int local = i;
                allThreads[i] = new Thread(() =>
                {
                    try
                    {
                        Provider aux = el.Value;
                    }
                    catch (Exception)
                    {
                        allResults[local] = true;
                    }
                });
                allThreads[i].Start();
            }

            foreach (Thread thread in allThreads)
            {
                thread.Join();
            }

            foreach (bool result in allResults)
            {
                Assert.True(result);
            }
        }