コード例 #1
0
ファイル: StiApi.cs プロジェクト: VijayMVC/chalkable
        private SyncResult <T> GetTableData <T>(Guid districtId) where T : SyncModel
        {
            var mcs = "Data Source=yqdubo97gg.database.windows.net;Initial Catalog=ChalkableMaster;UID=chalkableadmin;Pwd=Hellowebapps1!";

            District d;

            using (var uow = new UnitOfWork(mcs, false))
            {
                var da = new DistrictDataAccess(uow);
                d = da.GetById(districtId);
            }
            var  cs = $"Data Source={d.ServerUrl};Initial Catalog={d.Id};UID=chalkableadmin;Pwd=Hellowebapps1!";
            long?version;

            using (var uow = new UnitOfWork(cs, true))
            {
                var name = typeof(T).Name;
                version = (new SyncVersionDataAccess(uow)).GetAll().First(x => x.TableName == name).Version;
            }

            Debug.WriteLine($"version {version}");
            var cl    = ConnectorLocator.Create(d.SisUserName, d.SisPassword, d.SisUrl);
            var items = (cl.SyncConnector.GetDiff(typeof(T), version) as SyncResult <T>);

            return(items);
        }
コード例 #2
0
        public bool IsOnline(Guid id)
        {
            var d = GetByIdOrNull(id);

            using (var unitOfWork = new UnitOfWork(Settings.GetSchoolConnectionString(d.ServerUrl, "Master"), false))
            {
                var da = new DistrictDataAccess(unitOfWork);
                var l  = da.GetOnline(new[] { id });
                return(l.Count > 0);
            }
        }
コード例 #3
0
 public void UpdateReportCardsEnabled(Guid districtId, bool enabled)
 {
     using (var uow = Update())
     {
         var da       = new DistrictDataAccess(uow);
         var district = da.GetByIdOrNull(districtId);
         if (district == null)
         {
             throw new ChalkableException("No district with Id = " + districtId);
         }
         district.IsReportCardsEnabled = enabled;
         da.Update(district);
         uow.Commit();
     }
 }
コード例 #4
0
ファイル: StiApi.common.cs プロジェクト: VijayMVC/chalkable
 void ForEachDistrict(IEnumerable <Guid> districtIds, Action <District, ConnectorLocator> action)
 {
     foreach (var districtId in districtIds)
     {
         var      mcs = "Data Source=yqdubo97gg.database.windows.net;Initial Catalog=ChalkableMaster;UID=chalkableadmin;Pwd=Hellowebapps1!";
         District d;
         using (var uow = new UnitOfWork(mcs, false))
         {
             var da = new DistrictDataAccess(uow);
             d = da.GetById(districtId);
         }
         var cl = ConnectorLocator.Create(d.SisUserName, d.SisPassword, d.SisUrl);
         action(d, cl);
         Debug.WriteLine($"district {d.Id} processing is done");
     }
 }
コード例 #5
0
ファイル: StiApi.cs プロジェクト: VijayMVC/chalkable
        private SyncResult <T> GetTableData <T>(Guid districtId, long?version) where T : SyncModel
        {
            var mcs = "Data Source=yqdubo97gg.database.windows.net;Initial Catalog=ChalkableMaster;UID=chalkableadmin;Pwd=Hellowebapps1!";

            District d;

            using (var uow = new UnitOfWork(mcs, false))
            {
                var da = new DistrictDataAccess(uow);
                d = da.GetById(districtId);
            }
            var cl    = ConnectorLocator.Create(d.SisUserName, d.SisPassword, d.SisUrl);
            var items = (cl.SyncConnector.GetDiff(typeof(T), version) as SyncResult <T>);

            return(items);
        }
コード例 #6
0
ファイル: StiApi.common.cs プロジェクト: VijayMVC/chalkable
 void ForEachDistrict(IEnumerable <Guid> districtIds, Action <District, UnitOfWork> action)
 {
     foreach (var districtId in districtIds)
     {
         var      mcs = "Data Source=yqdubo97gg.database.windows.net;Initial Catalog=ChalkableMaster;UID=chalkableadmin;Pwd=Hellowebapps1!";
         District d;
         using (var uow = new UnitOfWork(mcs, false))
         {
             var da = new DistrictDataAccess(uow);
             d = da.GetById(districtId);
         }
         var cs = $"Data Source={d.ServerUrl};Initial Catalog={d.Id};UID=chalkableadmin;Pwd=Hellowebapps1!";
         using (var uow = new UnitOfWork(cs, true))
         {
             action(d, uow);
             uow.Commit();
         }
         Debug.WriteLine($"district {d.Id} processing is done");
     }
 }
コード例 #7
0
        public District Create(Guid id, string name, string sisUrl, string sisRedirectUrl, string sisUserName, string sisPassword, string timeZone, string stateCode, bool isReportCardsEnabled)
        {
            BaseSecurity.EnsureSysAdminOrDistrictRegistrator(Context);
            string   server;
            District res;

            using (var uow = Update())
            {
                server = FindServer(uow);
                var da = new DistrictDataAccess(uow);
                res = new District
                {
                    ServerUrl            = server,
                    Id                   = id,
                    Name                 = name,
                    SisUrl               = sisUrl,
                    SisRedirectUrl       = sisRedirectUrl,
                    SisUserName          = sisUserName,
                    SisPassword          = sisPassword,
                    TimeZone             = timeZone,
                    MaxSyncTime          = MAX_SYNC_TIME_DEFAULT,
                    SyncLogFlushSize     = SYNC_LOG_FLUSH_SIZE_DEFAULT,
                    SyncHistoryDays      = SYNC_HISTORY_DAYS_DEFAULT,
                    FailCounter          = 0,
                    FailDelta            = 0,
                    IsDemoDistrict       = false,
                    SyncFrequency        = SYNC_FREQUENCY,
                    MaxSyncFrequency     = MAX_SYNC_FREQUENCY,
                    StateCode            = stateCode,
                    IsReportCardsEnabled = isReportCardsEnabled
                };
                da.Insert(res);
                uow.Commit();
            }
            using (var unitOfWork = new UnitOfWork(Settings.GetSchoolConnectionString(server, "Master"), false))
            {
                var da = new DistrictDataAccess(unitOfWork);
                da.CreateDistrictDataBase(res.Id.ToString(), Settings.SchoolTemplateDbName);
            }
            return(res);
        }
コード例 #8
0
 public UserContext SisLogIn(Guid sisDistrictId, string token, DateTime tokenExpiresTime, int?acadSessionId = null, string sisRedirectUrl = null)
 {
     using (var uow = Update(IsolationLevel.ReadUncommitted))
     {
         var         district = new DistrictDataAccess(uow).GetById(sisDistrictId);
         var         sisUrl   = district.SisUrl;
         var         iNowCl   = new ConnectorLocator(token, sisUrl, tokenExpiresTime);
         var         iNowUser = iNowCl.UsersConnector.GetMe();
         UserContext res      = null;
         if (!string.IsNullOrEmpty(iNowUser.Username))
         {
             var chlkUser = new UserDataAccess(uow).GetUser(new AndQueryCondition
             {
                 { User.SIS_USER_ID_FIELD, iNowUser.Id },
                 { User.DISTRICT_REF_FIELD, district.Id }
             });
             res = SisUserLogin(chlkUser, uow, iNowCl, iNowUser, acadSessionId, sisRedirectUrl);
         }
         uow.Commit();
         return(res);
     }
 }
コード例 #9
0
        private static string FindServer(UnitOfWork uow)
        {
            var    da            = new DistrictDataAccess(uow);
            var    serverLoading = da.CalcServersLoading();
            string s             = null;
            int    cnt           = int.MaxValue;

            foreach (var sl in serverLoading)
            {
                if (sl.Value >= cnt)
                {
                    continue;
                }
                cnt = sl.Value;
                s   = sl.Key;
            }
            if (s == null)
            {
                throw new NullReferenceException();
            }
            return(s);
        }
コード例 #10
0
ファイル: StiApi.fixes.cs プロジェクト: VijayMVC/chalkable
        public void FixRoomDelete(Guid districtid)
        {
            District d;
            var      mcs = "Data Source=yqdubo97gg.database.windows.net;Initial Catalog=ChalkableMaster;UID=chalkableadmin;Pwd=Hellowebapps1!";

            using (var uow = new UnitOfWork(mcs, false))
            {
                var da = new DistrictDataAccess(uow);
                d = da.GetById(districtid);
            }

            var cs = String.Format("Data Source={0};Initial Catalog={1};UID=chalkableadmin;Pwd=Hellowebapps1!", d.ServerUrl, d.Id);
            IList <SyncVersion> versions;

            using (var uow = new UnitOfWork(cs, true))
            {
                versions = (new SyncVersionDataAccess(uow)).GetAll();
                uow.Commit();
            }

            var cl           = ConnectorLocator.Create("Chalkable", d.SisPassword, d.SisUrl);
            var deletedRooms = (cl.SyncConnector.GetDiff(typeof(Room), versions.First(x => x.TableName == "Room").Version) as SyncResult <Room>).Deleted;

            using (var uow = new UnitOfWork(cs, true))
            {
                var da      = new ClassDataAccess(uow);
                var all     = da.GetAll();
                var classes = all.Where(x => deletedRooms.Any(y => x.RoomRef == y.RoomID)).ToList();
                foreach (var @class in classes)
                {
                    @class.RoomRef = null;
                }
                da.Update(classes.ToList());
                uow.Commit();
            }
        }
コード例 #11
0
 public DistrictController()
 {
     this.districtDataAccess = DataProviderManager.GetDistrict(DataProvider.MsSql);
 }
コード例 #12
0
ファイル: StiApi.fixes.cs プロジェクト: VijayMVC/chalkable
        public void FixMissingUsersSync(Guid districtid)
        {
            var mcs = "Data Source=yqdubo97gg.database.windows.net;Initial Catalog=ChalkableMaster;UID=chalkableadmin;Pwd=Hellowebapps1!";

            District d;
            IList <Data.Master.Model.User> existingUsers;

            using (var uow = new UnitOfWork(mcs, false))
            {
                var da = new DistrictDataAccess(uow);
                d = da.GetById(districtid);
                var conds = new SimpleQueryCondition("DistrictRef", districtid, ConditionRelation.Equal);
                existingUsers = (new UserDataAccess(uow)).GetAll(conds);
            }
            var cs = String.Format("Data Source={0};Initial Catalog={1};UID=chalkableadmin;Pwd=Hellowebapps1!", d.ServerUrl, d.Id);
            IList <SyncVersion> versions;

            using (var uow = new UnitOfWork(cs, true))
            {
                versions = (new SyncVersionDataAccess(uow)).GetAll();
                uow.Commit();
            }

            var cl           = ConnectorLocator.Create(d.SisUserName, d.SisPassword, d.SisUrl);
            var addedUsers   = (cl.SyncConnector.GetDiff(typeof(User), versions.First(x => x.TableName == "User").Version) as SyncResult <User>).Inserted;
            var allInowUsers = (cl.SyncConnector.GetDiff(typeof(User), null) as SyncResult <User>).All;
            var allUsers     = (cl.SyncConnector.GetDiff(typeof(User), null) as SyncResult <User>).All;
            //var addedUserSchools = (cl.SyncConnector.GetDiff(typeof(UserSchool), versions.First(x => x.TableName == "UserSchool").Version) as SyncResult<UserSchool>).Inserted;

            IList <Data.Master.Model.User> users = new List <Data.Master.Model.User>();
            var ids             = allInowUsers.Select(x => x.UserID).Distinct();
            var existingUserSet = new HashSet <int>(existingUsers.Select(x => x.SisUserId.Value).ToList());

            foreach (var addedUserSchool in ids)
            {
                if (!existingUserSet.Contains(addedUserSchool))
                {
                    if (addedUsers.All(x => x.UserID != addedUserSchool))
                    {
                        var sisu = allUsers.First(x => x.UserID == addedUserSchool);
                        Data.Master.Model.User u = new Data.Master.Model.User
                        {
                            Id          = Guid.NewGuid(),
                            DistrictRef = districtid,
                            FullName    = sisu.FullName,
                            Login       = $"user{sisu.UserID}_{districtid}@chalkable.com",
                            Password    = "******",
                            SisUserName = sisu.UserName,
                            SisUserId   = sisu.UserID
                        };
                        users.Add(u);
                    }
                }
            }


            using (var uow = new UnitOfWork(mcs, true))
            {
                (new UserDataAccess(uow)).Insert(users);
                uow.Commit();
            }
        }