Beispiel #1
0
        public static void CleanUnUsedServerPhoto()
        {
            try
            {
                var           dir = new DirectoryInfo(PathUtil.GetDestinationPhotoPath());
                IUnitOfWork   destinationUnitOfWork = new UnitOfWorkServer(new ServerDbContextFactory().Create());
                List <string> attachments           = destinationUnitOfWork.Repository <AttachmentDTO>()
                                                      .Query().Get()
                                                      .Select(at => at.AttachmentUrl).ToList();
                destinationUnitOfWork.Dispose();

                DeleteData(dir, attachments);
            }
            catch (Exception ex)
            {
                LogUtil.LogError(ErrorSeverity.Critical, "CleanData.CleanUnUsedServerPhoto",
                                 ex.Message + Environment.NewLine + ex.InnerException, "defaultUser1", "Agency1");
            }
        }
Beispiel #2
0
        private void DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                if (!CheckInternetConnection())
                {
                    _noConnection = true;
                    return;
                }
                _userName   = "";
                _agencyName = "";

                _errorsFound = true; //Reset it Below
                IUnitOfWork sourceUnitOfWork      = new UnitOfWorkServer(new ServerDbContextFactory().Create());
                IUnitOfWork destinationUnitOfWork = new UnitOfWork(new DbContextFactory().Create());

                if (!SyncUsers(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow2(destinationUnitOfWork);
                if (!SyncMemberships(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }

                _errorsFound      = false;
                _updatesCompleted = true;


                sourceUnitOfWork.Dispose();
                destinationUnitOfWork.Dispose();
            }
            catch
            {
            }
        }
Beispiel #3
0
        public void Sync() //(object sender, DoWorkEventArgs e)
        {
            Singleton.SystemVersionDate = DbCommandUtil.GetCurrentDatabaseVersion();

            var productionDbVersion = Convert.ToInt32(DbCommandUtil.GetCurrentDbVersion());
            var systemVersionDate   = Convert.ToInt32(Singleton.SystemVersionDate);

            if (systemVersionDate < productionDbVersion)
            {
                LogUtil.LogError(ErrorSeverity.Critical, "ValidateProduct",
                                 "Higher Database Version", UserName, Agency);
                return;
            }

            LogUtil.LogError(ErrorSeverity.Critical, "Sync", "Started", UserName, Agency);

            AgencyWithAgentsUtility.InsertAgencyNamesonAddressesandAttachments();
            if (!AgencyWithAgentsUtility.InsertAgencyWithAgents(UserName, Agency))
            {
                return;
            }
            if (!AgencyWithAgentsUtility.InsertUserWithAgencyWithAgents(UserName, Agency))
            {
                return;
            }


            IUnitOfWork sourceUnitOfWork = new UnitOfWork(
                new DbContextFactory().Create());
            IUnitOfWork destinationUnitOfWork = new UnitOfWorkServer(
                new ServerDbContextFactory().Create());

            var agency = sourceUnitOfWork.Repository <AgencyDTO>()
                         .Query()
                         .Get()
                         .FirstOrDefault();

            //Setting = sourceUnitOfWork.Repository<SettingDTO>()
            //    .Query()
            //    .Get(1)
            //    .FirstOrDefault();

            try
            {
                //if (Setting != null)
                //{
                //    LastFromServerSyncDate = Setting.LastFromServerSyncDate != null
                //        ? (DateTime) Setting.LastFromServerSyncDate
                //        : DbCommandUtil.GetCurrentSqlDate(false).AddYears(-1);//If it is for first time collect all last one year data
                //    LastToServerSyncDate = Setting.LastToServerSyncDate != null
                //        ? (DateTime) Setting.LastToServerSyncDate
                //        : DbCommandUtil.GetCurrentSqlDate(false).AddYears(-1);
                //}
                //else
                //{
                LastFromServerSyncDate = DbCommandUtil.GetCurrentSqlDate(false).AddYears(-10);
                LastToServerSyncDate   = DbCommandUtil.GetCurrentSqlDate(false).AddYears(-10);
                //}
            }
            catch (Exception ex)
            {
                LogUtil.LogError(ErrorSeverity.Critical, "Sync DbCommandUtil.GetCurrentSqlDate(true)",
                                 ex.Message + Environment.NewLine + ex.InnerException, UserName, Agency);
            }

            LogUtil.LogError(ErrorSeverity.Info, "Sync To Server",
                             "Started", UserName, Agency);

            #region Sync To Server

            ToServerSyncing    = true;
            LastServerSyncDate = LastToServerSyncDate; //.AddMinutes(-10);//-10 Minutes should be syncronized with MonitorTimerElapsed

            try
            {
                if (!SyncUsers2(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);

                if (!SyncAgencies2(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);

                Singleton.Agency = destinationUnitOfWork.Repository <AgencyDTO>()
                                   .Query().Filter(a => a.RowGuid == agency.RowGuid)
                                   .Get()
                                   .FirstOrDefault();

                if (!SyncAddresses(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);

                if (!SyncAttachments(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);
                if (!SyncRequiredDocuments(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);

                if (!SyncVisaSponsors(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);
                if (!SyncVisaConditions(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);

                if (!SyncEducation(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);
                if (!SyncExperiences(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);
                if (!SyncHawala(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);

                if (!SyncInsurance(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);
                if (!SyncLabour(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);
                if (!SyncEmbassy(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);
                if (!SyncFlight(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);

                if (!SyncAgencies(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);
                if (!SyncForeignAgents(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);
                if (!SyncAgencyWithAgents(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);

                if (!SyncSettings(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);
                if (!SyncProductActivations(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);

                if (!SyncVisas(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);

                if (!SyncEmployees(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);
                if (!SyncRelatives(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);

                if (!SyncComplains(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);
                if (!SyncComplainRemarks(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);
                if (!SyncEmployees2(sourceUnitOfWork, destinationUnitOfWork, false))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);

                if (!SyncUsers(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);
                if (!SyncMemberships(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);
                if (!SyncRoles(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);
                if (!SyncUsersInRoles(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);
                if (!SyncUserWithAgencyWithAgentDTO(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }

                //Sync Setting
                try
                {
                    if (!_errorsFound && _updatesFound)
                    {
                        var        setUnitOfWork = new UnitOfWork(new DbContextFactory().Create());
                        SettingDTO set           = setUnitOfWork.Repository <SettingDTO>().Query().Get(1).FirstOrDefault();

                        if (set != null)
                        {
                            set.LastToServerSyncDate = DbCommandUtil.GetCurrentSqlDate(false); //.AddHours(-1);
                        }
                        setUnitOfWork.Repository <SettingDTO>().SimpleUpdate(set);
                        setUnitOfWork.Commit();
                        setUnitOfWork.Dispose();
                    }
                    else
                    {
                        LogUtil.LogError(ErrorSeverity.Critical, "Sync To Server",
                                         "No Updates Found", UserName, Agency);
                    }
                }
                catch (Exception ex)
                {
                    LogUtil.LogError(ErrorSeverity.Critical, "Update Setting.LastToServerSyncDate",
                                     ex.Message + Environment.NewLine + ex.InnerException, UserName, Agency);
                }
            }
            catch (Exception ex)
            {
                LogUtil.LogError(ErrorSeverity.Critical, "Sync General Method",
                                 ex.Message + Environment.NewLine + ex.InnerException, UserName, Agency);
            }
            finally
            {
                try
                {
                    sourceUnitOfWork.Dispose();
                }
                catch (Exception ex)
                {
                    LogUtil.LogError(ErrorSeverity.Critical, "Sync General sourceUnitOfWork.Dispose",
                                     ex.Message + Environment.NewLine + ex.InnerException, UserName, Agency);
                }
            }

            #endregion

            LogUtil.LogError(ErrorSeverity.Info, "Sync To Server", "Completed", UserName, Agency);

            #region Dispose UoW

            try
            {
                sourceUnitOfWork.Dispose();
                destinationUnitOfWork.Dispose();
            }
            catch (Exception ex)
            {
                LogUtil.LogError(ErrorSeverity.Critical, "Dispose Unit of Work Method",
                                 ex.Message + Environment.NewLine + ex.InnerException, UserName, Agency);
            }

            #endregion

            LogUtil.LogError(ErrorSeverity.Info, "Sync From Server", "Started", UserName, Agency);

            #region Sync From Server

            ToServerSyncing  = false;
            Singleton.Agency = agency;
            try
            {
                LastServerSyncDate = LastFromServerSyncDate; //.AddMinutes(-10);
                //-10 Minutes should be syncronized with MonitorTimerElapsed


                sourceUnitOfWork      = new UnitOfWorkServer(new ServerDbContextFactory().Create());
                destinationUnitOfWork = new UnitOfWork(new DbContextFactory().Create());

                if (!SyncSettings(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow2(destinationUnitOfWork);
                if (!SyncProductActivations(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow2(destinationUnitOfWork);

                if (!SyncAddresses(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow2(destinationUnitOfWork);

                if (!SyncVisaSponsors(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow2(destinationUnitOfWork);
                if (!SyncVisaConditions(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow2(destinationUnitOfWork);

                if (!SyncVisas(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow2(destinationUnitOfWork);

                if (!SyncEmployees(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow2(destinationUnitOfWork);

                if (!SyncComplains(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow2(destinationUnitOfWork);
                if (!SyncComplainRemarks(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow2(destinationUnitOfWork);
                if (!SyncEmployees2(sourceUnitOfWork, destinationUnitOfWork, true))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow2(destinationUnitOfWork);

                if (!SyncRoles(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                destinationUnitOfWork = GetNewUow2(destinationUnitOfWork);
                if (!SyncUsersInRoles(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                ////destinationUnitOfWork = GetNewUow(destinationUnitOfWork);

                //Sync Setting
                try
                {
                    if (!_errorsFound && _updatesFound)
                    {
                        var        setUnitOfWork = new UnitOfWork(new DbContextFactory().Create());
                        SettingDTO set           = setUnitOfWork.Repository <SettingDTO>().Query().Get(1).FirstOrDefault();

                        if (set != null)
                        {
                            set.LastFromServerSyncDate = DbCommandUtil.GetCurrentSqlDate(false); //.AddHours(-1);
                        }
                        setUnitOfWork.Repository <SettingDTO>().SimpleUpdate(set);
                        setUnitOfWork.Commit();
                        setUnitOfWork.Dispose();
                    }
                    else
                    {
                        LogUtil.LogError(ErrorSeverity.Critical, "Sync From Server",
                                         "No Updates Found", UserName, Agency);
                    }
                }
                catch (Exception ex)
                {
                    LogUtil.LogError(ErrorSeverity.Critical, "Update Setting.LastFromServerSyncDate",
                                     ex.Message + Environment.NewLine + ex.InnerException, UserName, Agency);
                }
            }
            catch (Exception ex)
            {
                LogUtil.LogError(ErrorSeverity.Critical, "Sync From Server General Method",
                                 ex.Message + Environment.NewLine + ex.InnerException, UserName, Agency);
            }
            finally
            {
                try
                {
                    sourceUnitOfWork.Dispose();
                }
                catch (Exception ex)
                {
                    LogUtil.LogError(ErrorSeverity.Critical, "Sync From Server General sourceUnitOfWork.Dispose()",
                                     ex.Message + Environment.NewLine + ex.InnerException, UserName, Agency);
                }
            }

            #endregion

            LogUtil.LogError(ErrorSeverity.Info, "Sync From Server",
                             "Completed", UserName, Agency);
        }
Beispiel #4
0
 public IUnitOfWork GetNewUow(IUnitOfWork uom)
 {
     uom.Dispose();
     _unitOfWorkServer = new UnitOfWorkServer(new ServerDbContextFactory().Create());
     return(_unitOfWorkServer);
 }
Beispiel #5
0
        public void DeleteSync(object sender, DoWorkEventArgs e)
        {
            if (!CheckInternetConnection())
            {
                //_noConnection = true;
                return;
            }

            IUnitOfWork sourceUnitOfWork      = new UnitOfWork(new DbContextFactory().Create());
            IUnitOfWork destinationUnitOfWork = new UnitOfWorkServer(new ServerDbContextFactory().Create());

            #region Sync Delete

            try
            {
                if (!DeleteAddresses(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                sourceUnitOfWork      = GetNewUow2(sourceUnitOfWork);
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);
                if (!DeleteAttachmentes(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                sourceUnitOfWork      = GetNewUow2(sourceUnitOfWork);
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);
                if (!DeleteRequiredDocumentses(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                sourceUnitOfWork      = GetNewUow2(sourceUnitOfWork);
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);

                if (!DeleteVisaSponsores(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                sourceUnitOfWork      = GetNewUow2(sourceUnitOfWork);
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);
                if (!DeleteVisaConditiones(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                sourceUnitOfWork      = GetNewUow2(sourceUnitOfWork);
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);

                if (!DeleteEmployeeEducationes(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                sourceUnitOfWork      = GetNewUow2(sourceUnitOfWork);
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);
                if (!DeleteEmployeeExperiencees(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                sourceUnitOfWork      = GetNewUow2(sourceUnitOfWork);
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);
                if (!DeleteEmployeeHawalaes(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                sourceUnitOfWork      = GetNewUow2(sourceUnitOfWork);
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);

                if (!DeleteInsuranceProcesses(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                sourceUnitOfWork      = GetNewUow2(sourceUnitOfWork);
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);
                if (!DeleteLabourProcesses(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                sourceUnitOfWork      = GetNewUow2(sourceUnitOfWork);
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);
                if (!DeleteEmbassyProcesses(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                sourceUnitOfWork      = GetNewUow2(sourceUnitOfWork);
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);
                if (!DeleteFlightProcesses(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                sourceUnitOfWork      = GetNewUow2(sourceUnitOfWork);
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);

                if (!DeleteVisaes(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                sourceUnitOfWork      = GetNewUow2(sourceUnitOfWork);
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);

                if (!DeleteEmployeees(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                sourceUnitOfWork      = GetNewUow2(sourceUnitOfWork);
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);
                if (!DeleteEmployeeRelativees(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                sourceUnitOfWork      = GetNewUow2(sourceUnitOfWork);
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);

                if (!DeleteComplaines(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                sourceUnitOfWork      = GetNewUow2(sourceUnitOfWork);
                destinationUnitOfWork = GetNewUow(destinationUnitOfWork);
                if (!DeleteComplainRemarkes(sourceUnitOfWork, destinationUnitOfWork))
                {
                    return;
                }
                //sourceUnitOfWork = GetNewUow2(sourceUnitOfWork);
                //destinationUnitOfWork = GetNewUow(destinationUnitOfWork);
            }
            catch (Exception ex)
            {
                LogUtil.LogError(ErrorSeverity.Critical, "Sync General Method",
                                 ex.Message + Environment.NewLine + ex.InnerException, Tasks.SyncTask.UserName, Tasks.SyncTask.Agency);
            }
            finally
            {
                try
                {
                    sourceUnitOfWork.Dispose();
                }
                catch (Exception ex)
                {
                    LogUtil.LogError(ErrorSeverity.Critical, "Sync General sourceUnitOfWork.Dispose",
                                     ex.Message + Environment.NewLine + ex.InnerException, Tasks.SyncTask.UserName, Tasks.SyncTask.Agency);
                }
            }

            #endregion
        }