Example #1
0
        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);
        }
Example #2
0
        public void GetSyncTablesProps()
        {
            var connector = ConnectorLocator.Create("Chalkable", "8nA4qU4yG", "http://sandbox.sti-k12.com/chalkable/api/");
            var client    = new WebClientGZip
            {
                Headers =
                {
                    [HttpRequestHeader.Authorization] = "Session " + connector.Token,
                    ["ApplicationKey"]  = $"chalkable {Settings.StiApplicationKey}",
                    ["Accept-Encoding"] = "gzip, deflate"
                },
                Encoding = Encoding.UTF8
            };

            client.Headers.Add("Content-Type", "application/json");
            try
            {
                var url = connector.BaseUrl + $"sync/tables/Homeroom/";

                client.QueryString = new NameValueCollection();
                var data = client.DownloadData(url);

                using (var ms = new MemoryStream(data))
                {
                    StreamReader reader;
                    GZipStream   unzipped = null;
                    if (client.ResponseHeaders[HttpResponseHeader.ContentType].ToLower() == "application/octet-stream")
                    {
                        unzipped = new GZipStream(ms, CompressionMode.Decompress);
                        reader   = new StreamReader(unzipped);
                    }
                    else
                    {
                        reader = new StreamReader(ms);
                    }

                    Debug.WriteLine(reader.ReadToEnd());

                    unzipped?.Dispose();
                }
            }
            catch (WebException ex)
            {
                if (ex.Response is HttpWebResponse &&
                    (ex.Response as HttpWebResponse).StatusCode == HttpStatusCode.NotFound)
                {
                    return;
                }

                string msg    = ex.Message;
                var    stream = ex.Response?.GetResponseStream();
                if (stream != null)
                {
                    var reader = new StreamReader(stream);
                    msg = reader.ReadToEnd();
                }
                throw new Exception(msg);
            }
        }
Example #3
0
        public void TestMealTypeSync()
        {
            var connector = ConnectorLocator.Create("Chalkable", "8nA4qU4yG", "http://sandbox.sti-k12.com/chalkable/api/");

            var mealType = (connector.SyncConnector.GetDiff(typeof(StiConnector.SyncModel.MealType), null) as SyncResult <StiConnector.SyncModel.MealType>).All;

            Debug.WriteLine(JsonConvert.SerializeObject(mealType));
        }
Example #4
0
        public void Resync(string tableName)
        {
            Log.LogInfo("start resync");
            connectorLocator     = ConnectorLocator.Create(ConnectionInfo.SisUserName, ConnectionInfo.SisPassword, ConnectionInfo.SisUrl);
            ServiceLocatorMaster = new ServiceLocatorMaster(sysadminCntx);
            ServiceLocatorSchool = ServiceLocatorMaster.SchoolServiceLocator(districtId, null);
            Log.LogInfo("download data to resync");
            context = new SyncContext(connectorLocator.ApiVersion);

            var tablesToResync = new List <string>
            {
                tableName,
                nameof(Gender),    // We need this tables for mappers
                nameof(SpEdStatus) // inside StudentAdapter/Selector
            };

            var toSync  = context.TablesToSync;
            var results = new List <SyncResultBase <SyncModel> >();

            foreach (var table in toSync)
            {
                var type = context.Types[table.Key];
                SyncResultBase <SyncModel> res;
                var resType = (typeof(SyncResult <>)).MakeGenericType(type);
                if (tablesToResync.Contains(table.Key))
                {
                    Log.LogInfo("Start downloading " + table.Key);
                    res = (SyncResultBase <SyncModel>)connectorLocator.SyncConnector.GetDiff(type, null);
                    Log.LogInfo("Table downloaded: " + table.Key + " " + res.RowCount);
                }
                else
                {
                    res = (SyncResultBase <SyncModel>)Activator.CreateInstance(resType, new object[0]);
                }


                if (table.Key == tableName) //resync table
                {
                    object o = resType.GetProperty("Rows").GetValue(res);
                    resType.GetProperty("Updated").SetValue(res, o);
                    resType.GetProperty("Inserted").SetValue(res, null);
                    resType.GetProperty("Deleted").SetValue(res, null);
                    resType.GetProperty("Rows").SetValue(res, null);
                }

                results.Add(res);
            }
            foreach (var syncResultBase in results)
            {
                context.SetResult(syncResultBase);
            }
            if (!ServiceLocatorSchool.Context.DistrictId.HasValue)
            {
                throw new Exception("District id should be defined for import");
            }
            DoRegularSync(false);
        }
Example #5
0
        public void ResyncAfterRestore()
        {
            Log.LogInfo("start resync after sti DB restore");
            ServiceLocatorMaster = new ServiceLocatorMaster(sysadminCntx);
            ServiceLocatorSchool = ServiceLocatorMaster.SchoolServiceLocator(districtId, null);
            if (!ServiceLocatorSchool.Context.DistrictId.HasValue)
            {
                throw new Exception("District id should be defined for import");
            }

            var d = ServiceLocatorMaster.DistrictService.GetByIdOrNull(ServiceLocatorSchool.Context.DistrictId.Value);

            connectorLocator = ConnectorLocator.Create(ConnectionInfo.SisUserName, ConnectionInfo.SisPassword, ConnectionInfo.SisUrl);
            Log.LogInfo("remove district last sync label");
            d.LastSync = null;
            ServiceLocatorMaster.DistrictService.Update(d);
            Log.LogInfo("performing before restore preparation");
            ServiceLocatorMaster.DbMaintenanceService.BeforeSisRestore(d.Id);
            ServiceLocatorSchool.DbMaintenanceService.BeforeSisRestore();
            Log.LogInfo("download data to restore");
            DownloadSyncData();
            Log.LogInfo("remove user records");
            var all      = ServiceLocatorMaster.UserService.GetAll(districtId);
            var allIds   = new HashSet <int>(all.Select(x => x.SisUserId.Value));
            var newUsers = new List <StiConnector.SyncModel.User>();
            var rows     = context.GetSyncResult <StiConnector.SyncModel.User>().Rows;

            foreach (var r in rows)
            {
                if (!allIds.Contains(r.UserID))
                {
                    newUsers.Add(r);
                }
            }
            context.GetSyncResult <StiConnector.SyncModel.User>().Inserted = null;
            context.GetSyncResult <StiConnector.SyncModel.User>().Rows     = newUsers.ToArray();
            context.GetSyncResult <StiConnector.SyncModel.User>().Updated  = null;
            context.GetSyncResult <StiConnector.SyncModel.User>().Deleted  = null;
            Log.LogInfo("do initial sync");
            DoInitialSync();
            d = ServiceLocatorMaster.DistrictService.GetByIdOrNull(ServiceLocatorSchool.Context.DistrictId.Value);
            Log.LogInfo("performing after restore preparation");
            var logs = ServiceLocatorMaster.DbMaintenanceService.AfterSisRestore(d.Id);

            ServiceLocatorSchool.DbMaintenanceService.AfterSisRestore();
            foreach (var restoreLogItem in logs)
            {
                Log.LogWarning(restoreLogItem.Msg);
            }
            Log.LogInfo("updating district last sync");
            UpdateDistrictLastSync(d, true);
            CreateUserLoginInfos();
            Log.LogInfo("resync after sti DB restore is completed");
        }
Example #6
0
        public ActionResult Register(DistrictRegisterViewData data)
        {
            string name     = data.DistrictGuid.ToString();
            string timeZone = data.DistrictTimeZone ?? "UTC";
            var    sl       = ServiceLocatorFactory.CreateMasterSysAdmin();
            var    context  = sl.UserService.Login(data.UserName, data.Password);

            if (context != null)
            {
                var district = sl.DistrictService.GetByIdOrNull(data.DistrictGuid);
                if (district == null && string.IsNullOrEmpty(data.SisPassword))
                {
                    throw new Exception("SIS password can not be null for a new district");
                }
                var pwd = data.SisPassword;
                if (string.IsNullOrEmpty(pwd))
                {
                    pwd = district.SisPassword;
                }
                var locator = ConnectorLocator.Create(data.SisUserName, pwd, data.ApiUrl);
                if (!locator.LinkConnector.Link(data.LinkKey))
                {
                    throw new Exception("The link keys do not match.");
                }
                if (district == null)
                {
                    sl.DistrictService.Create(data.DistrictGuid, name, data.ApiUrl, data.RedirectUrl, data.SisUserName, data.SisPassword, timeZone, data.DistrictState, data.IsReportCardsEnabled);
                }
                else
                {
                    if (String.Compare(district.SisUrl, data.ApiUrl, StringComparison.OrdinalIgnoreCase) != 0)
                    {
                        throw new Exception("API url can't be changed for existing district");
                    }

                    if (String.IsNullOrEmpty(district.Name))
                    {
                        district.Name = name;
                    }
                    if (!string.IsNullOrEmpty(data.SisPassword))
                    {
                        district.SisPassword = data.SisPassword;
                    }
                    district.SisUrl         = data.ApiUrl;
                    district.SisUserName    = data.SisUserName;
                    district.TimeZone       = timeZone;
                    district.SisRedirectUrl = data.RedirectUrl;
                    district.StateCode      = data.DistrictState;
                    sl.DistrictService.Update(district);
                }
                return(Json(true));
            }
            return(new HttpUnauthorizedResult());
        }
Example #7
0
 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");
     }
 }
Example #8
0
        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);
        }
Example #9
0
        public void Import()
        {
            Log.LogInfo("start import");
            ServiceLocatorMaster = new ServiceLocatorMaster(sysadminCntx);
            ServiceLocatorSchool = ServiceLocatorMaster.SchoolServiceLocator(districtId, null);
            if (!ServiceLocatorSchool.Context.DistrictId.HasValue)
            {
                throw new Exception("District id should be defined for import");
            }

            var d = ServiceLocatorMaster.DistrictService.GetByIdOrNull(ServiceLocatorSchool.Context.DistrictId.Value);

            try
            {
                connectorLocator = ConnectorLocator.Create(ConnectionInfo.SisUserName, ConnectionInfo.SisPassword, ConnectionInfo.SisUrl);
                Log.LogInfo("download data to sync");
                DownloadSyncData();
                if (d.LastSync.HasValue)
                {
                    DoRegularSync(true);
                }
                else
                {
                    DoInitialSync();
                }
                Log.LogInfo("updating district last sync");
                d = ServiceLocatorMaster.DistrictService.GetByIdOrNull(ServiceLocatorSchool.Context.DistrictId.Value);
                UpdateDistrictLastSync(d, true);
            }
            catch (Exception)
            {
                UpdateDistrictLastSync(d, false);
                throw;
            }

            Log.LogInfo("process pictures");
            ProcessPictures();
            Log.LogInfo("setting link status");
            var importedSchoolIds = context.GetSyncResult <School>().All.Select(x => x.SchoolID);

            foreach (var importedSchoolId in importedSchoolIds)
            {
                connectorLocator.LinkConnector.CompleteSync(importedSchoolId);
            }
            CreateUserLoginInfos();
            Log.LogInfo("import is completed");
        }
Example #10
0
 private void SaveSisToken(User user, UnitOfWork uow, ref ConnectorLocator iNowConnector)
 {
     if (user.SisUserName != null)
     {
         if (iNowConnector == null)
         {
             if (user.OriginalPassword == null)
             {
                 throw new ChalkableException(ChlkResources.ERR_SIS_CONNECTION_REQUERED_NOT_ENCRYPED_PASSWORD);
             }
             iNowConnector = ConnectorLocator.Create(user.SisUserName, user.OriginalPassword, user.District.SisUrl);
         }
         if (!string.IsNullOrEmpty(iNowConnector.Token))
         {
             UpdateUserLoginInfo(user, iNowConnector.Token, iNowConnector.TokenExpires, null, uow);
         }
     }
 }
Example #11
0
        public void StudentPanoramaApiTest()
        {
            var studentId     = 3315;
            var connector     = ConnectorLocator.Create("MAGOLDEN-3856695863", "qqqq1111", "http://sandbox.sti-k12.com/chalkable/api/");
            var componentsIds = new List <int>
            {
                1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 6, 7, 7, 7, 7, 7, 7, 8, 10, 11, 12, 13, 14, 15
            };
            var scoreTypeIds = new List <int>
            {
                1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 11, 1, 2, 3, 4, 5, 6, 8, 12, 12, 12, 12, 12, 12
            };
            var acadSessionIds = new List <int> {
                179
            };

            var studentPanorama = connector.PanoramaConnector.GetStudentPanorama(studentId, acadSessionIds, componentsIds, scoreTypeIds);

            if (studentPanorama.StandardizedTests != null)
            {
                Debug.WriteLine("Standardized Tests:");
                Debug.WriteLine(JsonConvert.SerializeObject(studentPanorama.StandardizedTests));
            }

            if (studentPanorama.Infractions != null)
            {
                Debug.WriteLine("Infractions:");
                Debug.WriteLine(JsonConvert.SerializeObject(studentPanorama.Infractions));
            }

            if (studentPanorama.DailyAbsences != null)
            {
                Debug.WriteLine("DailyAbsences:");
                Debug.WriteLine(JsonConvert.SerializeObject(studentPanorama.DailyAbsences));
            }

            if (studentPanorama.PeriodAbsences != null)
            {
                Debug.WriteLine("PeriodAbsences:");
                Debug.WriteLine(JsonConvert.SerializeObject(studentPanorama.PeriodAbsences));
            }
        }
        public static IReportGenerator <TReportSettings> CreateGenerator <TReportSettings>(
            IServiceLocatorSchool serviceLocatorSchool,
            ConnectorLocator connectorLocator
            )
            where TReportSettings : class
        {
            var _generatorDictionary = BuildGaneratorDictionary(serviceLocatorSchool, connectorLocator);

            if (!_generatorDictionary.ContainsKey(typeof(TReportSettings)))
            {
                throw new ChalkableException("Could not find report generator for such input data");
            }
            var res = _generatorDictionary[typeof(TReportSettings)] as IReportGenerator <TReportSettings>;

            if (res == null)
            {
                throw new ChalkableException("Current report generator doesn't implement IReportGenerator");
            }
            return(res);
        }
Example #13
0
        public static void AddMissingSisAttributes(ClassAnnouncement classAnn, IList <AnnouncementAssignedAttribute> attributes, UnitOfWork u
                                                   , ConnectorLocator connectorLocator, IServiceLocatorSchool serviceLocator)
        {
            var missingAttributes = attributes.Where(a => a.Id <= 0).ToList();
            var attrs             = UploadMissingAttachments(classAnn, missingAttributes, u, connectorLocator, serviceLocator);

            if (attributes.Count > 0)
            {
                foreach (var missingAttr in missingAttributes)
                {
                    var attr = attrs.FirstOrDefault(x => x.SisActivityAssignedAttributeId == missingAttr.SisActivityAssignedAttributeId);
                    if (attr == null)
                    {
                        continue;
                    }
                    missingAttr.AttachmentRef = attr.AttachmentRef;
                    missingAttr.Attachment    = attr.Attachment;
                }
            }
            new AnnouncementAssignedAttributeDataAccess(u).Insert(missingAttributes);
        }
        public bool Handle(BackgroundTask task, BackgroundTaskService.BackgroundTaskLog log)
        {
            var sl               = ServiceLocatorFactory.CreateMasterSysAdmin();
            var data             = task.GetData <PictureImportTaskData>();
            var district         = sl.DistrictService.GetByIdOrNull(data.DistrictId);
            var connectorLocator = ConnectorLocator.Create(district.SisUserName, district.SisPassword, district.SisUrl);

            foreach (var person in data.PersonIds)
            {
                var content = connectorLocator.UsersConnector.GetPhoto(person);
                if (content != null)
                {
                    sl.PersonPictureService.UploadPicture(data.DistrictId, person, content);
                }
                else
                {
                    sl.PersonPictureService.DeletePicture(data.DistrictId, person);
                }
            }
            return(true);
        }
Example #15
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);
     }
 }
Example #16
0
        public static Attachment Upload(string name, byte[] content, bool uploadToSti, UnitOfWork unitOfWork, IServiceLocatorSchool serviceLocator,
                                        ConnectorLocator connectorLocator, bool uploadToCrocodoc = true)
        {
            var context = serviceLocator.Context;

            Trace.Assert(context.PersonId.HasValue);
            var res = new Attachment
            {
                Name             = name,
                PersonRef        = context.PersonId.Value,
                Uuid             = null,
                UploadedDate     = context.NowSchoolTime,
                LastAttachedDate = context.NowSchoolTime
            };

            if (uploadToCrocodoc)
            {
                res.Uuid = UploadToCrocodoc(res.Name, content, serviceLocator);
            }

            var da = new AttachmentDataAccess(unitOfWork);

            if (uploadToSti)
            {
                var stiAtt = connectorLocator.AttachmentConnector.UploadAttachment(name, content).Last();

                //TODO : use mapping
                res.Name            = stiAtt.Name;
                res.SisAttachmentId = stiAtt.AttachmentId;
                res.MimeType        = stiAtt.MimeType;
                da.Insert(res);
                return(da.GetLast(context.PersonId.Value));
            }
            da.Insert(res);
            res = da.GetLast(context.PersonId.Value);
            res.RelativeBlobAddress = UploadToBlob(res, content, serviceLocator);
            da.Update(res);
            return(res);
        }
        //private static IDictionary<Type, Object> _generatorDictionary;

        private static IDictionary <Type, Object> BuildGaneratorDictionary(
            IServiceLocatorSchool serviceLocatorSchool,
            ConnectorLocator connectorLocator)
        {
            return(new Dictionary <Type, object>
            {
                { typeof(GradebookReportInputModel), new GradebookReportGenerator(serviceLocatorSchool, connectorLocator) },
                { typeof(WorksheetReportInputModel), new WorksheetReportGenerator(serviceLocatorSchool, connectorLocator) },
                { typeof(ProgressReportInputModel), new ProgressReportGenerator(serviceLocatorSchool, connectorLocator) },
                { typeof(ComprehensiveProgressInputModel), new ComprehensiveProgressReportGenerator(serviceLocatorSchool, connectorLocator) },
                { typeof(StudentComprehensiveReportInputModel), new StudentComprehensiveReportGenerator(serviceLocatorSchool, connectorLocator) },
                { typeof(MissingAssignmentsInputModel), new MissingAssignmentsReportGenerator(serviceLocatorSchool, connectorLocator) },
                { typeof(AttendanceProfileReportInputModel), new AttendanceProfileReportGenerator(serviceLocatorSchool, connectorLocator) },
                { typeof(AttendanceRegisterInputModel), new AttendanceRegisterReportGenerator(serviceLocatorSchool, connectorLocator) },
                { typeof(BirthdayReportInputModel), new BirthdayReportGenerator(serviceLocatorSchool, connectorLocator) },
                { typeof(SeatingChartReportInputModel), new SeatingChartReportGenerator(serviceLocatorSchool, connectorLocator) },
                { typeof(GradeVerificationInputModel), new GradeVerificationReportGenerator(serviceLocatorSchool, connectorLocator) },
                { typeof(LessonPlanReportInputModel), new LessonPlanReportGenerator(serviceLocatorSchool, connectorLocator) },
                { typeof(FeedReportInputModel), new FeedReportGenerator(serviceLocatorSchool, connectorLocator) },
                { typeof(ReportCardsInputModel), new ReportCardGenerator(serviceLocatorSchool, connectorLocator) },
                { typeof(LunchCountReportInputModel), new LunchCountReportGenerator(serviceLocatorSchool, connectorLocator) }
            });
        }
Example #18
0
        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();
            }
        }
Example #19
0
        /// <summary>
        /// </summary>
        /// <returns>Source annAttahcment and new annAttachment</returns>
        public static IList <Pair <AnnouncementAttachment, AnnouncementAttachment> > CopyAnnouncementAttachments(IDictionary <int, int> fromToAnnouncementIds,
                                                                                                                 IList <int> attachmentsOwners, UnitOfWork unitOfWork, IServiceLocatorSchool serviceLocator, ConnectorLocator connectorLocator)
        {
            Trace.Assert(serviceLocator.Context.PersonId.HasValue);

            //var attachmentDA = new AttachmentDataAccess(unitOfWork);

            var annoncementAttachmentDA = new AnnouncementAttachmentDataAccess(unitOfWork);
            var annAttachmentsToCopy    = annoncementAttachmentDA.GetByAnnouncementIds(fromToAnnouncementIds.Select(x => x.Key).ToList(), attachmentsOwners);

            var fromToAnnAttachments = new List <Pair <AnnouncementAttachment, AnnouncementAttachment> >();

            foreach (var announcementPair in fromToAnnouncementIds)
            {
                var announcementAttachmentsToCopy = annAttachmentsToCopy.Where(x => x.AnnouncementRef == announcementPair.Key).ToList();

                foreach (var annAttachmentToCopy in announcementAttachmentsToCopy)
                {
                    //var newAttachment = new Attachment
                    //{
                    //    Name = annAttachmentToCopy.Attachment.Name,
                    //    PersonRef = serviceLocator.Context.PersonId.Value,
                    //    Uuid = null,
                    //    UploadedDate = serviceLocator.Context.NowSchoolTime,
                    //    LastAttachedDate = serviceLocator.Context.NowSchoolTime,
                    //};

                    //newAttachment.Id = attachmentDA.InsertWithEntityId(newAttachment);

                    var newAnnAttachment = new AnnouncementAttachment
                    {
                        AnnouncementRef = announcementPair.Value,
                        AttachedDate    = annAttachmentToCopy.AttachedDate,
                        Order           = annAttachmentToCopy.Order,
                        AttachmentRef   = annAttachmentToCopy.AttachmentRef,
                        Attachment      = annAttachmentToCopy.Attachment
                    };

                    fromToAnnAttachments.Add(new Pair <AnnouncementAttachment, AnnouncementAttachment>(annAttachmentToCopy, newAnnAttachment));
                }
            }

            annoncementAttachmentDA.Insert(fromToAnnAttachments.Select(x => x.Second).ToList());

            return(fromToAnnAttachments);
        }
Example #20
0
        public static IList <AnnouncementAttachment> CopyAnnouncementAttachments(int fromAnnouncementId, IList <int> attachmentsOwners, IList <int> toAnnouncemenIds, UnitOfWork unitOfWork, IServiceLocatorSchool serviceLocator, ConnectorLocator connectorLocator)
        {
            Trace.Assert(serviceLocator.Context.PersonId.HasValue);
            var da = new AnnouncementAttachmentDataAccess(unitOfWork);
            var annAttachmentsForCopying = attachmentsOwners.Count == 0
                ? da.GetLastAttachments(fromAnnouncementId).ToList()
                : da.GetLastAttachments(fromAnnouncementId).Where(x => attachmentsOwners.Contains(x.Attachment.PersonRef)).ToList();

            var annAtts = new List <AnnouncementAttachment>();

            foreach (var annAttForCopy in annAttachmentsForCopying)
            {
                foreach (var toAnnouncemenId in toAnnouncemenIds)
                {
                    //var attForCopy = annAttForCopy.Attachment;
                    //var content = serviceLocator.AttachementService.GetAttachmentContent(attForCopy).Content;
                    //if (content != null)
                    //{
                    //    var att = AttachmentService.Upload(attForCopy.Name, content, attForCopy.IsStiAttachment, unitOfWork, serviceLocator, connectorLocator);
                    //    var annAtt = new AnnouncementAttachment
                    //    {
                    //        AnnouncementRef = toAnnouncemenId,
                    //        AttachedDate = annAttForCopy.AttachedDate,
                    //        Order = annAttForCopy.Order,
                    //        AttachmentRef = att.Id,
                    //        Attachment = att
                    //    };
                    //    annAtts.Add(annAtt);
                    //}

                    var annAtt = new AnnouncementAttachment
                    {
                        AnnouncementRef = toAnnouncemenId,
                        AttachedDate    = annAttForCopy.AttachedDate,
                        Order           = annAttForCopy.Order,
                        AttachmentRef   = annAttForCopy.AttachmentRef,
                        Attachment      = annAttForCopy.Attachment
                    };
                    annAtts.Add(annAtt);
                }
            }
            da.Insert(annAtts);
            return(da.GetLastAttachments(toAnnouncemenIds, annAtts.Count));
        }
Example #21
0
 public WorksheetReportGenerator(IServiceLocatorSchool serviceLocatorSchool, ConnectorLocator connectorLocator) : base(serviceLocatorSchool, connectorLocator)
 {
 }
Example #22
0
        public static IList <Pair <AnnouncementAssignedAttribute, AnnouncementAssignedAttribute> > CopyNonStiAttributes(IDictionary <int, int> fromToAnnouncementIds,
                                                                                                                        UnitOfWork unitOfWork, IServiceLocatorSchool serviceLocator, ConnectorLocator connectorLocator)
        {
            //var attachmentDA = new AttachmentDataAccess(unitOfWork);

            var annAssignedAttributeDA = new AnnouncementAssignedAttributeDataAccess(unitOfWork);
            var attributesForCopying   = annAssignedAttributeDA.GetLastListByAnnIds(fromToAnnouncementIds.Select(x => x.Key).ToList(), int.MaxValue)
                                         .Where(x => !x.SisActivityAssignedAttributeId.HasValue).ToList();

            var fromToAttributes = new List <Pair <AnnouncementAssignedAttribute, AnnouncementAssignedAttribute> >();

            foreach (var announcementPair in fromToAnnouncementIds)
            {
                var assignedAttToCopy = attributesForCopying.Where(x => x.AnnouncementRef == announcementPair.Key).ToList();
                foreach (var attributeToCopy in assignedAttToCopy)
                {
                    var newAttribute = new AnnouncementAssignedAttribute
                    {
                        AnnouncementRef    = announcementPair.Value,
                        AttributeTypeId    = attributeToCopy.AttributeTypeId,
                        Name               = attributeToCopy.Name,
                        Text               = attributeToCopy.Text,
                        VisibleForStudents = attributeToCopy.VisibleForStudents,
                        AttachmentRef      = attributeToCopy.AttachmentRef,
                        Attachment         = attributeToCopy.Attachment
                    };

                    //if (attributeToCopy.Attachment != null)
                    //{
                    //    var attachment = new Attachment
                    //    {
                    //        Name = attributeToCopy.Attachment.Name,
                    //        PersonRef = serviceLocator.Context.PersonId.Value,
                    //        Uuid = null,
                    //        UploadedDate = serviceLocator.Context.NowSchoolTime,
                    //        LastAttachedDate = serviceLocator.Context.NowSchoolTime,
                    //    };

                    //    attachment.Id = attachmentDA.InsertWithEntityId(attachment);

                    //    newAttribute.AttachmentRef = attachment.Id;
                    //    newAttribute.Attachment = attachment;
                    //}
                    fromToAttributes.Add(new Pair <AnnouncementAssignedAttribute, AnnouncementAssignedAttribute>(attributeToCopy, newAttribute));
                }
            }

            annAssignedAttributeDA.Insert(fromToAttributes.Select(x => x.Second).ToList());
            return(fromToAttributes);
        }
Example #23
0
        public static IList <AnnouncementAssignedAttribute> CopyNonStiAttributes(int fromAnnouncementId, IList <int> toAnnouncementIds,
                                                                                 UnitOfWork unitOfWork, IServiceLocatorSchool serviceLocator, ConnectorLocator connectorLocator)
        {
            var da = new AnnouncementAssignedAttributeDataAccess(unitOfWork);
            var attributesForCopying = da.GetListByAnntId(fromAnnouncementId);

            attributesForCopying = attributesForCopying.Where(x => !x.SisActivityAssignedAttributeId.HasValue).ToList();

            var attributes = new List <AnnouncementAssignedAttribute>();

            foreach (var attributeForCopying in attributesForCopying)
            {
                foreach (var toAnnouncementId in toAnnouncementIds)
                {
                    var attribute = new AnnouncementAssignedAttribute
                    {
                        AnnouncementRef    = toAnnouncementId,
                        AttributeTypeId    = attributeForCopying.AttributeTypeId,
                        Name               = attributeForCopying.Name,
                        Text               = attributeForCopying.Text,
                        VisibleForStudents = attributeForCopying.VisibleForStudents,
                        AttachmentRef      = attributeForCopying.AttachmentRef,
                        Attachment         = attributeForCopying.Attachment
                    };
                    //if (attributeForCopying.Attachment != null)
                    //{
                    //    var attContent = serviceLocator.AttachementService.GetAttachmentContent(attributeForCopying.Attachment);
                    //    if (attContent.Content != null)
                    //    {
                    //        var att = AttachmentService.Upload(attContent.Attachment.Name, attContent.Content, attContent.Attachment.IsStiAttachment, unitOfWork, serviceLocator, connectorLocator);
                    //        attribute.AttachmentRef = att.Id;
                    //        attribute.Attachment = att;
                    //    }
                    //}
                    attributes.Add(attribute);
                }
            }
            da.Insert(attributes);
            return(da.GetLastListByAnnIds(toAnnouncementIds, attributes.Count));
        }
Example #24
0
        private static IList <AnnouncementAssignedAttribute> UploadMissingAttachments(ClassAnnouncement classAnn, IList <AnnouncementAssignedAttribute> attributes, UnitOfWork u
                                                                                      , ConnectorLocator connectorLocator, IServiceLocatorSchool serviceLocator)
        {
            var attributesForUpdate = attributes.Where(x => x.Attachment != null && x.Attachment.SisAttachmentId.HasValue && !x.AttachmentRef.HasValue).ToList();

            if (attributesForUpdate.Count == 0)
            {
                return(new List <AnnouncementAssignedAttribute>());
            }
            var da            = new AttachmentDataAccess(u);
            var existingsAtts = da.GetBySisAttachmentIds(attributesForUpdate.Select(x => x.Attachment.SisAttachmentId.Value).ToList());
            var attsForUpload = new List <Attachment>();

            foreach (var attribute in attributesForUpdate)
            {
                var attachment  = attribute.Attachment;
                var existingAtt = existingsAtts.FirstOrDefault(x => x.SisAttachmentId == attachment.SisAttachmentId);
                if (existingAtt == null)
                {
                    var content = connectorLocator.AttachmentConnector.GetAttachmentContent(attribute.Attachment.SisAttachmentId.Value);
                    if (serviceLocator.CrocodocService.IsDocument(attribute.Attachment.Name))
                    {
                        attachment.Uuid = serviceLocator.CrocodocService.UploadDocument(attribute.Attachment.Name, content).uuid;
                    }
                    attachment.UploadedDate     = classAnn.Created;
                    attachment.LastAttachedDate = attachment.UploadedDate;
                    attachment.PersonRef        = classAnn.PrimaryTeacherRef;
                    attsForUpload.Add(attachment);
                }
                else
                {
                    attribute.AttachmentRef = existingAtt.Id;
                }
            }
            if (attsForUpload.Count > 0)
            {
                da.Insert(attsForUpload);
                existingsAtts = da.GetBySisAttachmentIds(attsForUpload.Select(x => x.SisAttachmentId.Value).ToList());
                foreach (var attribute in attributesForUpdate.Where(x => !x.AttachmentRef.HasValue))
                {
                    var att = existingsAtts.First(x => x.SisAttachmentId == attribute.Attachment.SisAttachmentId);
                    attribute.Attachment    = att;
                    attribute.AttachmentRef = att.Id;
                }
            }
            return(attributesForUpdate);
        }
Example #25
0
 public StudentComprehensiveReportGenerator(IServiceLocatorSchool serviceLocatorSchool, ConnectorLocator connectorLocator)
 {
     ConnectorLocator = connectorLocator;
     ServiceLocator   = serviceLocatorSchool;
 }
Example #26
0
 public ReportCardGenerator(IServiceLocatorSchool serviceLocatorSchool, ConnectorLocator connectorLocator) : base(serviceLocatorSchool, connectorLocator)
 {
 }
Example #27
0
 public LunchCountReportGenerator(IServiceLocatorSchool serviceLocatorSchool, ConnectorLocator connectorLocator)
     : base(serviceLocatorSchool, connectorLocator)
 {
 }
Example #28
0
 protected BaseReportGenerator(IServiceLocatorSchool serviceLocatorSchool, ConnectorLocator connectorLocator)
 {
     ConnectorLocator = connectorLocator;
     ServiceLocator   = serviceLocatorSchool;
 }
Example #29
0
 public GradeVerificationReportGenerator(IServiceLocatorSchool serviceLocatorSchool, ConnectorLocator connectorLocator) : base(serviceLocatorSchool, connectorLocator)
 {
 }
Example #30
0
 public static void AttachMissingAttachments(ClassAnnouncement classAnn, IList <AnnouncementAssignedAttribute> attributes, UnitOfWork u
                                             , ConnectorLocator connectorLocator, IServiceLocatorSchool serviceLocator)
 {
     attributes = UploadMissingAttachments(classAnn, attributes, u, connectorLocator, serviceLocator);
     new AnnouncementAssignedAttributeDataAccess(u).Update(attributes);
 }