コード例 #1
0
ファイル: TextDialog.cs プロジェクト: Metibor/ualbion
        public TextDialog(IText text, SmallPortraitId?portraitId = null, int depth = 0) : base(DialogPositioning.Top, depth)
        {
            On <DismissMessageEvent>(_ => Close());
            On <UiLeftClickEvent>(e => { Close(); e.Propagating = false; });
            On <UiRightClickEvent>(e => { Close(); e.Propagating = false; });
            On <CloseWindowEvent>(e => Close());

            var textSection = new UiText(text);
            var padding     = new Padding(textSection, 3, 7);

            UiElement content;

            if (portraitId.HasValue)
            {
                var portrait = new FixedSize(36, 38,
                                             new ButtonFrame(new UiSpriteElement <SmallPortraitId>(portraitId.Value))
                {
                    State   = ButtonState.Pressed,
                    Padding = 0
                });
                content = new HorizontalStack(new CentreContent(portrait), padding);
            }
            else
            {
                content = padding;
            }

            var stack = new FixedWidth(320, content);

            AttachChild(new DialogFrame(stack)
            {
                Background = DialogFrameBackgroundStyle.DarkTint
            });
        }
コード例 #2
0
 public void FixedSizeManyTest(int howMany)
 {
     using (var session = new SessionNoServer(systemDir))
     {
         session.BeginUpdate();
         FixedSize fixedSize;
         FixedSize fixedSizePrior = new FixedSize();
         for (int i = 0; i < howMany; i++)
         {
             fixedSize = new FixedSize();
             fixedSize.Persist(session, fixedSizePrior);
             fixedSizePrior = fixedSize;
         }
         session.Commit();
     }
     using (var session = new SessionNoServerShared(systemDir))
     {
         session.BeginRead();
         Database db = session.OpenDatabase(FixedSize.PlaceInDatabase);
         foreach (Page page in db)
         {
             if (page.PageNumber > 0)
             {
                 foreach (FixedSize fixedSize in page)
                 {
                     --howMany;
                     Assert.NotNull(fixedSize);
                 }
             }
         }
         session.Commit();
     }
 }
コード例 #3
0
        public ConversationTextWindow() : base(DialogPositioning.Bottom)
        {
            On <UiLeftClickEvent>(e => Clicked?.Invoke());
            On <DismissMessageEvent>(e => Clicked?.Invoke());

            var content = new FixedSize(248, 159,
                                        new Padding(
                                            new UiText(_text)
                                            .Scrollable()
                                            .Filter(0),
                                            3));

            // Transparent background, scrollable
            var frame = new DialogFrame(content)
            {
                Background = DialogFrameBackgroundStyle.DarkTint
            };

            AttachChild(frame);
        }
コード例 #4
0
        public void FixedSizeTest()
        {
            UInt64 id;

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                FixedSize fixedSize = new FixedSize();
                fixedSize.Persist(session, fixedSize);
                id = fixedSize.Id;
                session.Commit();
                session.Compact();
            }
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginRead();
                FixedSize fixedSize = (FixedSize)session.Open(id);
                Assert.NotNull(fixedSize);
                session.Commit();
                session.Compact();
            }
        }
コード例 #5
0
 public void ConcurrentUpdates(bool serverSession, int numberofThreads)
 {
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
         session.BeginUpdate();
         FixedSize fixedSize = new FixedSize();
         session.Persist(fixedSize);
         session.Commit();
     }
     Thread[] threads = new Thread[numberofThreads];
     for (int i = 0; i < numberofThreads; i++)
     {
         threads[i] = new Thread(() =>
         {
             SessionBase session;
             if (serverSession)
             {
                 session = new ServerClientSession(systemDir, null, 500);
             }
             else
             {
                 session = new SessionNoServer(systemDir, 500);
             }
             try
             {
                 for (int j = 0; j < 30; j++)
                 {
                     try
                     {
                         session.BeginUpdate();
                         session.SetTraceDbActivity(878);
                         session.CrossTransactionCacheAllDatabases();
                         for (int k = 0; k < 5000; k++)
                         {
                             FixedSize fixedSize = new FixedSize();
                             session.Persist(fixedSize);
                             if (k == 9000 && Thread.CurrentThread.ManagedThreadId % 3 != 0)
                             {
                                 session.FlushUpdates();
                             }
                         }
                         session.Commit();
                         if (!serverSession)
                         {
                             session.Compact();
                         }
                         Console.WriteLine("Commit OK for thread " + Thread.CurrentThread.ManagedThreadId + " Transaction: " + j);
                     }
                     catch (OptimisticLockingFailed ex)
                     {
                         session.Abort();
                         Console.WriteLine("Commit failed (OptimisticLockingFailed) for thread " + Thread.CurrentThread.ManagedThreadId + " Transaction: " + j);
                         Console.WriteLine(ex.ToString());
                     }
                 }
                 catch (Exception ex)
                 {
                     session.Abort();
                     Console.WriteLine("Commit failed for thread " + Thread.CurrentThread.ManagedThreadId + " Transaction: " + j);
                     Console.WriteLine(ex.ToString());
                 }
             }
             finally
             {
                 session.Dispose();
             }
         });
コード例 #6
0
    /*---------------- item name (yellow) ---------------\
    |/--------------\ Type        Normal                 |
    ||              | Weight      1100 g                 |
    ||              | Damage      0                      |
    ||   ITEM PIC   | Protection  1                      |
    ||              | -----------------------------------|
    ||              | Can be used by:                    |
    |\--------------/ Pilot               Oqulo Kamulos  |
    |                 Scientist           Warrior        |
    |                 Druid                              |
    |                 Enlightened One                    |
    |                 Technician                         |
    \---------------------------------------------------*/
    public InventoryDetailsDialog(ItemData item) : base(DialogPositioning.Center, 1)
    {
        if (item == null)
        {
            throw new ArgumentNullException(nameof(item));
        }

        var heading = new Header(item.Name);
        var itemPic = new UiSpriteElement(item.Icon)
        {
            SubId = item.IconSubId,
            Flags = SpriteFlags.GradientPixels
        };

        var picFrame = new FixedSize(64, 64, new GroupingFrame(itemPic))
        {
            Position = DialogPositioning.Top
        };

        var attribStack = new HorizontalStack(
            new VerticalStack(
                new UiTextBuilder(Base.SystemText.Examine1_Type).NoWrap(),
                new UiTextBuilder(Base.SystemText.Examine1_Weight).NoWrap(),
                new UiTextBuilder(Base.SystemText.Examine1_Damage).NoWrap(),
                new UiTextBuilder(Base.SystemText.Examine1_Protection).NoWrap()
                ),
            new Spacing(2, 0),
            new VerticalStack(
                new UiTextBuilder(Describe.DescribeItemType(item.TypeId)).NoWrap(),
                new SimpleText($"{item.Weight} g").NoWrap(),                                    // i18n Literal String
                new SimpleText(item.Damage.ToString(CultureInfo.InvariantCulture)).NoWrap(),    // i18n
                new SimpleText(item.Protection.ToString(CultureInfo.InvariantCulture)).NoWrap() // i18n
                )
            );

        var classElements =
            Enum.GetValues(typeof(PlayerClass))
            .Cast <PlayerClass>()
            .Where(x => item.Class.IsAllowed(x))
            .Select(x => (IUiElement) new UiTextBuilder(Describe.DescribePlayerClass(x)).NoWrap());

        var classStack = new HorizontalStack(
            new VerticalStack(classElements.Take(5).ToArray()),
            new Spacing(2, 0),
            new VerticalStack(classElements.Skip(5).ToArray())
            );

        var stack = new VerticalStack(
            heading,
            new Spacing(0, 2),
            new HorizontalStack(
                picFrame,
                new Spacing(4, 0),
                new VerticalStack(
                    attribStack,
                    new Spacing(0, 2),
                    new Divider(CommonColor.Yellow4),
                    new Spacing(0, 2),
                    new UiTextBuilder((TextId)Base.SystemText.Misc_CanBeUsedBy),
                    classStack
                    )
                ),
            new Spacing(0, 2),
            new FixedSize(52, 13,
                          new Button(Base.SystemText.MsgBox_OK)
        {
            DoubleFrame = true
        }.OnClick(Close))
            );

        AttachChild(new DialogFrame(new Padding(stack, 6))
        {
            Background = DialogFrameBackgroundStyle.MainMenuPattern
        });
    }
コード例 #7
0
        public void ConcurrentUpdates(bool serverSession, int numberofThreads, bool optimisticLocking)
        {
            using (SessionBase session = new SessionNoServer(systemDir))
            {
                session.BeginRead();
                Database db = session.OpenDatabase(FixedSize.PlaceInDatabase, false, false);
                if (db != null)
                {
                    Console.WriteLine("ConcurrentUpdates start, Number of FixedSize objects: " + db.AllObjects <FixedSize>().Count);
                }
            }

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                FixedSize fixedSize = new FixedSize();
                session.Persist(fixedSize);
                session.Commit();
            }
            Thread[] threads = new Thread[numberofThreads];
            for (int i = 0; i < numberofThreads; i++)
            {
                threads[i] = new Thread(() =>
                {
                    SessionBase session;
                    if (serverSession)
                    {
                        session = new ServerClientSession(systemDir, null, 500, optimisticLocking);
                    }
                    else
                    {
                        session = new SessionNoServer(systemDir, 500, optimisticLocking);
                    }
                    try
                    {
                        for (int j = 0; j < 10; j++)
                        {
                            try
                            {
                                using (var transaction = session.BeginUpdate())
                                {
                                    session.SetTraceDbActivity(FixedSize.PlaceInDatabase);
                                    session.SetTraceDbActivity(2);
                                    Trace.Listeners.Add(new ConsoleTraceListener());
                                    session.CrossTransactionCacheAllDatabases();
                                    for (int k = 0; k < 4200; k++)
                                    {
                                        FixedSize fixedSize = new FixedSize();
                                        session.Persist(fixedSize);
                                        if (k == 4000 && Thread.CurrentThread.ManagedThreadId % 3 != 0)
                                        {
                                            session.FlushUpdates();
                                        }
                                    }
                                    transaction.Commit();
                                }
                                if (!serverSession)
                                {
                                    session.Compact();
                                }
                                Console.WriteLine("Commit OK for thread " + Thread.CurrentThread.ManagedThreadId + " Transaction: " + j);
                            }
                            catch (PageUpdateLockException ex)
                            {
                                Console.WriteLine("Commit failed (OptimisticLockingFailed) for thread " + Thread.CurrentThread.ManagedThreadId + " Transaction: " + j);
                                Console.WriteLine(ex.ToString());
                            }
                        }
                        catch (OptimisticLockingFailed ex)
                        {
                            Console.WriteLine("Commit failed (OptimisticLockingFailed) for thread " + Thread.CurrentThread.ManagedThreadId + " Transaction: " + j);
                            Console.WriteLine(ex.ToString());
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Commit failed for thread " + Thread.CurrentThread.ManagedThreadId + " Transaction: " + j);
                            Console.WriteLine(ex.ToString());
                        }
                    }
                    finally
                    {
                        session.Dispose();
                    }
                });
コード例 #8
0
    public void ConcurrentUpdates(bool serverSession, int numberofThreads, bool optimisticLocking)
    {
      using (SessionBase session = new SessionNoServer(systemDir))
      {
        session.BeginRead();
        Database db = session.OpenDatabase(FixedSize.PlaceInDatabase, false, false);
        if (db != null)
          Console.WriteLine("ConcurrentUpdates start, Number of FixedSize objects: " + db.AllObjects<FixedSize>().Count);
      }

      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.BeginUpdate();
        FixedSize fixedSize = new FixedSize();
        session.Persist(fixedSize);
        session.Commit();
      }
      Thread[] threads = new Thread[numberofThreads];
      for (int i = 0; i < numberofThreads; i++)
        threads[i] = new Thread(() =>
          {
            SessionBase session;
            if (serverSession)
              session = new ServerClientSession(systemDir, null, 500, optimisticLocking);
            else
              session = new SessionNoServer(systemDir, 500, optimisticLocking);
            try
            {
              for (int j = 0; j < 10; j++)
                try
                {
                  using (var transaction = session.BeginUpdate())
                  {
                    session.SetTraceDbActivity(FixedSize.PlaceInDatabase);
                    session.SetTraceDbActivity(2);
                    Trace.Listeners.Add(new ConsoleTraceListener());
                    session.CrossTransactionCacheAllDatabases();
                    for (int k = 0; k < 4200; k++)
                    {
                      FixedSize fixedSize = new FixedSize();
                      session.Persist(fixedSize);
                      if (k == 4000 && Thread.CurrentThread.ManagedThreadId % 3 != 0)
                        session.FlushUpdates();
                    }
                    session.Commit();
                    if (!serverSession)
                      session.Compact();
                    Console.WriteLine("Commit OK for thread " + Thread.CurrentThread.ManagedThreadId + " Transaction: " + j);
                  }
                }
                catch (PageUpdateLockException ex)
                {
                  Console.WriteLine("Commit failed (OptimisticLockingFailed) for thread " + Thread.CurrentThread.ManagedThreadId + " Transaction: " + j);
                  Console.WriteLine(ex.ToString());
                }
                catch (OptimisticLockingFailed ex)
                {
                  Console.WriteLine("Commit failed (OptimisticLockingFailed) for thread " + Thread.CurrentThread.ManagedThreadId + " Transaction: " + j);
                  Console.WriteLine(ex.ToString());
                }
                catch (Exception ex)
                {
                  Console.WriteLine("Commit failed for thread " + Thread.CurrentThread.ManagedThreadId + " Transaction: " + j);
                  Console.WriteLine(ex.ToString());
                }
            }
            finally
            {
              session.Dispose();
            }
          });
      foreach (Thread thread in threads)
        thread.Start();
      bool keepWaiting = true;
      while (keepWaiting)
      {
        keepWaiting = false;
        foreach (Thread thread in threads)
          if (thread.IsAlive)
          {
            keepWaiting = true;
            thread.Join(500);
          }
      }
      using (SessionBase session = new SessionNoServer(systemDir))
      {
        session.BeginRead();
        Database db = session.OpenDatabase(FixedSize.PlaceInDatabase, false, false);
        if (db != null)
          Console.WriteLine("ConcurrentUpdates finished, number of FixedSize objects: " + db.AllObjects<FixedSize>().Count);
      }
    }
コード例 #9
0
 public void ConcurrentUpdates(bool serverSession, int numberofThreads)
 {
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginUpdate();
     FixedSize fixedSize = new FixedSize();
     session.Persist(fixedSize);
     session.Commit();
   }
   Thread[] threads = new Thread[numberofThreads];
   for (int i = 0; i < numberofThreads; i++)
     threads[i] = new Thread(() =>
       {
         SessionBase session;
         if (serverSession)
           session = new ServerClientSession(systemDir, null, 500);
         else
           session = new SessionNoServer(systemDir, 500);
         try
         {
           for (int j = 0; j < 30; j++)
             try
             {
               session.BeginUpdate();
               session.SetTraceDbActivity(878);
               session.CrossTransactionCacheAllDatabases();
               for (int k = 0; k < 5000; k++)
               {
                 FixedSize fixedSize = new FixedSize();
                 session.Persist(fixedSize);
                 if (k == 9000 && Thread.CurrentThread.ManagedThreadId % 3 != 0)
                   session.FlushUpdates();
               }
               session.Commit();
               if (!serverSession)
                 session.Compact();
               Console.WriteLine("Commit OK for thread " + Thread.CurrentThread.ManagedThreadId + " Transaction: " + j);
             }
             catch (OptimisticLockingFailed ex)
             {
               session.Abort();
               Console.WriteLine("Commit failed (OptimisticLockingFailed) for thread " + Thread.CurrentThread.ManagedThreadId + " Transaction: " + j);
               Console.WriteLine(ex.ToString());
             }
             catch (Exception ex)
             {
               session.Abort();
               Console.WriteLine("Commit failed for thread " + Thread.CurrentThread.ManagedThreadId + " Transaction: " + j);
               Console.WriteLine(ex.ToString());
             }
         }
         finally
         {
           session.Dispose();
         }
       });
   foreach (Thread thread in threads)
     thread.Start();
   bool keepWaiting = true;
   while (keepWaiting)
   {
     keepWaiting = false;
     foreach (Thread thread in threads)
       if (thread.IsAlive)
       {
         keepWaiting = true;
         thread.Join(5000);
       }
   } 
 }