Example #1
0
        private void SyncProfiles()
        {
            try
            {
                var localProfiles   = _sqLiteDbService.GetProfilesSuperficially(_mmeCode);
                var centralProfiles = _msSqlDbService.GetProfilesDeepByMmeCode(_mmeCode);
                if (!_sqLiteDbService.GetMmeCodes().ContainsKey(_mmeCode))
                {
                    _sqLiteDbService.InsertMmeCode(_mmeCode);
                }

                List <MyProfile> deletingProfiles;
                List <MyProfile> addingProfiles;

                if (_sqLiteDbService.Migrate())
                {
                    deletingProfiles = localProfiles;
                    addingProfiles   = centralProfiles;
                }
                else
                {
                    deletingProfiles = localProfiles.Except(centralProfiles, new MyProfile.ProfileByVersionTimeEqualityComparer()).ToList();
                    addingProfiles   = centralProfiles.Except(localProfiles, new MyProfile.ProfileByVersionTimeEqualityComparer()).ToList();
                }

                foreach (var i in deletingProfiles)
                {
                    _sqLiteDbService.RemoveProfile(i, _mmeCode);
                }

                foreach (var i in addingProfiles)
                {
                    //i.DeepData = _msSqlDbService.LoadProfileDeepData(i);
                    _sqLiteDbService.InsertUpdateProfile(null, i, _mmeCode);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error while syncing profiles from local database with a master: {0}", ex.ToString()));
            }
        }