Пример #1
0
        private void AddToLog(C_Log logItem)
        {
            var db = UnityInstance.Resolve <IDbContextFactory>().GetNewDbContext;

            logItem.AsOf = DateTime.Now;
            db.C_Log.Add(logItem);
            db.SaveChanges();
        }
        protected override bool AuthorizeCore(System.Web.HttpContextBase httpContext)
        {
            var authorized = base.AuthorizeCore(httpContext) && (UserSession.IsGuestTeller || UserSession.IsKnownTeller);

            if (!authorized)
            {
                // The user is not authenticated
                return(false);
            }

            var electionModel = new ElectionModel();

            if (UserSession.IsGuestTeller)
            {
                if (!electionModel.GuestsAllowed())
                {
                    UserSession.ProcessLogout();
                    return(false);
                }
                return(true);
            }

            // only update visit every 5 minutes. Lasts for 1 hour, so could be only 45 minutes.
            var currentElection = UserSession.CurrentElection;
            var delayTime       = TimeSpan.FromMinutes(5);

            if (currentElection != null && currentElection.ListForPublic.AsBoolean())
            {
                LogTime("init");
                var db = UnityInstance.Resolve <IDbContextFactory>().GetNewDbContext;
                LogTime("resolve");

                db.Election.Attach(currentElection);
                LogTime("attach");

                currentElection.ListedForPublicAsOf = DateTime.Now;

                LogTime("listed");
                var electionCacher = new ElectionCacher(db);
                LogTime("cacher");

                electionCacher.UpdateItemAndSaveCache(currentElection);
                LogTime("update cache");

                if (currentElection.ListForPublic.AsBoolean() &&
                    (DateTime.Now - currentElection.ListedForPublicAsOf.GetValueOrDefault(DateTime.Now.AddMinutes(-60))).TotalMinutes > delayTime.TotalMinutes)
                {
                    db.SaveChanges();

                    LogTime("db save");
                }

                new PublicHub().TellPublicAboutVisibleElections();
                LogTime("notify");
            }

            return(true);
        }
Пример #3
0
 /// <summary>
 /// 添加权限
 /// </summary>
 /// <param name="permission"></param>
 /// <returns></returns>
 public static int AddPermission(PermissionEntity permission)
 {
     try
     {
         var dao    = UnityInstance.GetInstanceDAL <IRoleDao>();
         var result = dao.AddPermission(permission);
         return(result);
     }
     catch (Exception ex)
     {
         return(-1);
     }
 }
Пример #4
0
 /// <summary>
 /// 添加账户
 /// </summary>
 /// <param name="role"></param>
 /// <returns></returns>
 public static int AddRole(RoleEntity role)
 {
     try
     {
         var dao    = UnityInstance.GetInstanceDAL <IRoleDao>();
         var result = dao.AddRole(role);
         return(result);
     }
     catch (Exception ex)
     {
         return(-1);
     }
 }
Пример #5
0
        /// <Summary>Erase all ballots and results</Summary>
        public static void EraseBallotsAndResults(Guid electionGuid)
        {
            var db = UnityInstance.Resolve <IDbContextFactory>().GetNewDbContext;

            db.Result.Where(r => r.ElectionGuid == electionGuid).Delete();
            db.ResultTie.Where(r => r.ElectionGuid == electionGuid).Delete();
            db.ResultSummary.Where(r => r.ElectionGuid == electionGuid).Delete();

            // delete ballots in all locations... cascading will delete votes
            db.Ballot.Where(b =>
                            db.Location.Where(x => x.ElectionGuid == electionGuid).Select(l => l.LocationGuid)
                            .Contains(b.LocationGuid)).Delete();
        }
Пример #6
0
 /// <summary>
 /// 添加账户
 /// </summary>
 /// <param name="account"></param>
 /// <returns></returns>
 public static int AddAccount(AdminEntity account)
 {
     try
     {
         var dao    = UnityInstance.GetInstanceDAL <IAdminDao>();
         var result = dao.AddAdmin(account);
         return(result);
     }
     catch (Exception ex)
     {
         return(-1);
     }
 }
Пример #7
0
 public static AdminEntity GetAccountByName(string name)
 {
     try
     {
         var dao    = UnityInstance.GetInstanceDAL <IAdminDao>();
         var result = dao.GetAdminByName(name);
         return(result);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Пример #8
0
 int GetCleanServer(out UnityInstance instance)
 {
     for (int i = 0; i < cleanServers.Length; i++)
     {
         if (cleanServers[i])
         {
             cleanServers[i] = false;
             instance        = unityInstances[i];
             return(0);
         }
     }
     instance = new UnityInstance();
     return(-1);//tells them no instance available
 }
Пример #9
0
        public static int GetUserId()
        {
            int result = 0;

            try
            {
                var dao = UnityInstance.GetInstanceDAL <IUserDao>();
                result = dao.GetUserId();
            }
            catch (Exception ex)
            {
                return(-1);
            }
            return(result);
        }
Пример #10
0
        private static void Main()
        {
            var unity = UnityInstance.Initialize();

            unity.OnTick = () =>
            {
                var shouldContinue = unity.Update();
                if (shouldContinue == false)
                {
                    unity.Deinitialize();
                }
                return(shouldContinue);
            };

            RunLoop.EnterMainLoop(unity.OnTick);
        }
Пример #11
0
        public void Init()
        {
            _fakes = new AnalyzerFakes();
            Db     = _fakes.DbContext;
            Db.ForTests();
            UnityInstance.Offer(Db);

            _electionGuid = Guid.NewGuid();

            SessionKey.CurrentElectionGuid.SetInSession(_electionGuid);
            BallotTestHelper.SaveElectionGuidForTests(_electionGuid);

            SessionKey.CurrentComputer.SetInSession(new Computer
            {
                ComputerGuid = Guid.NewGuid(),
                ComputerCode = "TEST",
                ElectionGuid = _electionGuid
            });

            SamplePeople = new List <Person>
            {
                new Person {
                    FirstName = "a0", CombinedInfo = "abc", CombinedInfoAtStart = "abc", VotingMethod = VotingMethodEnum.InPerson
                }.ForTests(),
                new Person {
                    FirstName = "a1",
                }.ForTests(),
                new Person {
                    FirstName = "a2",
                }.ForTests(),
                new Person {
                    FirstName = "a3",
                }.ForTests(),
                new Person {
                    FirstName = "a4",
                }.ForTests(),
                new Person {
                    FirstName = "a5", IneligibleReasonGuid = IneligibleReasonEnum.Ineligible_Moved_elsewhere_recently
                }.ForTests(),
                new Person {
                    FirstName = "a6", IneligibleReasonGuid = IneligibleReasonEnum.IneligiblePartial1_Older_Youth
                }.ForTests(),
                new Person {
                    FirstName = "a7", IneligibleReasonGuid = IneligibleReasonEnum.Ineligible_Resides_elsewhere
                }.ForTests(),
            };
        }
Пример #12
0
        public void Init()
        {
            _fakes = new AnalyzerFakes();
            Db     = _fakes.DbContext;
            Db.ForTests();
            UnityInstance.Offer(Db);

            _electionGuid = Guid.NewGuid();
            SessionKey.CurrentElectionGuid.SetInSession(_electionGuid);
            BallotTestHelper.SaveElectionGuidForTests(_electionGuid);

            SessionKey.CurrentComputer.SetInSession(new Computer
            {
                ComputerGuid = Guid.NewGuid(),
                ComputerCode = "TEST",
                ElectionGuid = _electionGuid
            });

            _samplePeople = new List <Person>
            {// 0 - 7
                new Person {
                    FirstName = "x0", CombinedInfo = "person", VotingMethod = VotingMethodEnum.InPerson
                }.ForTests(),
                new Person {
                    FirstName = "x1", CombinedInfo = "person"
                }.ForTests(),
                new Person {
                    FirstName = "x2", CombinedInfo = "person"
                }.ForTests(),
                new Person {
                    FirstName = "x3", CombinedInfo = "person"
                }.ForTests(),
                new Person {
                    FirstName = "x4", CombinedInfo = "person"
                }.ForTests(),
                new Person {
                    FirstName = "x5", CombinedInfo = "person"
                }.ForTests(),
                new Person {
                    FirstName = "x6", CombinedInfo = "person"
                }.ForTests(),
                new Person {
                    FirstName = "x7", CombinedInfo = "person"
                }.ForTests(),
            };
        }
Пример #13
0
        public static int AddUser()
        {
            int result = 0;

            try
            {
                var dao = UnityInstance.GetInstanceDAL <IUserDao>();
                result = dao.AddUser(new Common.Entities.AccountUser()
                {
                    Name = "Test", Age = 23, Sex = false
                });
            }
            catch (Exception ex)
            {
                return(-1);
            }
            return(result);
        }
Пример #14
0
    public static int Main(string[] args)
    {
        // Not using UnityInstance.Initialize here because it also creates a world, and some tests exist
        // that expect to handle their own world life cycle which currently conflicts with our world design
        UnityInstance.BurstInit();

        DotsRuntime.Initialize();

        TempMemoryScope.EnterScope();
        // Static storage used for the whole lifetime of the process. Create it once here
        // so heap tracking tests won't fight over the storage causing alloc/free mismatches
        WordStorage.Initialize();

        // TypeManager initialization uses temp memory, so let's free it before creating a global scope
        Unity.Entities.TypeManager.Initialize();
        TempMemoryScope.ExitScope();

        // Should have stack trace with tests
        NativeLeakDetection.Mode = NativeLeakDetectionMode.EnabledWithStackTrace;

        int result = 0;

#if UNITY_PORTABLE_TEST_RUNNER
        double start = Time.timeAsDouble;
        UnitTestRunner.Run();
        double end = Time.timeAsDouble;
        PrintResults(end - start);
#else
        result = new AutoRun().Execute(args);
#endif

        TempMemoryScope.EnterScope();
        Unity.Entities.TypeManager.Shutdown();
        WordStorage.Shutdown();
        TempMemoryScope.ExitScope();

        DotsRuntime.Shutdown();

        return(result);
    }
Пример #15
0
        /// <summary>From the layout page, this is called to inject links to CSS and JS files for this view</summary>
        /// <param name="extension"></param>
        /// <param name="secondaryExtensions"></param>
        public IHtmlString CreateTagsToReferenceContentFiles(string extension, params string[] secondaryExtensions)
        {
            var cachedPaths = UnityInstance.Resolve <IViewResourcesCache>();

            // make a local copy, so we can clear the ones we've done
            var list = _list.ToList();

            //_list.Clear();
            // --> is an included View creates tags, other ones will be re-injected too... should find way to stop this
            //     however, browsers are forgiving, and only call for the resource once!

            var alreadySent = ItemKey.ClientFilesSent.FromPageItems(new List <string>(), true);

            var htmlString =
                list
                .SelectMany(s => cachedPaths.GetTag(s, extension, secondaryExtensions))
                .Where(s => s.HasContent() && !alreadySent.Contains(s))
                .AddTo(alreadySent)
                .JoinedAsString("\n");

            return(htmlString.AsRawHtml());
        }
Пример #16
0
 /// <summary>
 /// 获取用户列表
 /// </summary>
 /// <param name="pageIndex"></param>
 /// <param name="pageSize"></param>
 /// <returns></returns>
 public static List <UserData> GetUserDataList(int pageIndex, int pageSize)
 {
     try
     {
         var dao        = UnityInstance.GetInstanceDAL <IAdminDao>();
         var adminiList = dao.GetAdminEntityList(pageIndex, pageSize);
         var result     = new List <UserData>();
         if (adminiList != null && adminiList.Count > 0)
         {
             foreach (var admin in adminiList)
             {
                 var user = new UserData();
                 user.UserId   = admin.ID;
                 user.UserName = admin.Name;
                 result.Add(user);
             }
         }
         return(result);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Пример #17
0
 private void OnEndRequest(object sender, EventArgs eventArgs)
 {
     UnityInstance.Resolve <IDbContextFactory>().CloseAll();
 }
Пример #18
0
 public ViewResourcesCache()
 {
     _linkedResourcesHelper = UnityInstance.Resolve <ILinkedResourcesHelper>();
     _dict = new Dictionary <string, bool>();
 }
Пример #19
0
 private void DeactivateUnityWindow(UnityInstance ui)
 {
     SendMessage(ui.handle, WM_ACTIVATE, WA_INACTIVE, IntPtr.Zero);
 }