Пример #1
0
        public ServerProductActivationViewModel()
        {
            CleanUp();

            var iDbContext = new ServerDbContextFactory().Create();

            _unitOfWork = new UnitOfWorkServer(iDbContext);

            SelectedProductActivation = new ProductActivationDTO();
            ProductActivations        = new ObservableCollection <ProductActivationDTO>();
            GetLiveProductActivations();
            EditCommandVisibility = false;
        }
Пример #2
0
 private void ExecuteAddNewProductActivationViewCommand()
 {
     SelectedProductActivation = new ProductActivationDTO();
 }
Пример #3
0
        public bool SyncProductActivations(IUnitOfWork sourceUnitOfWork,
                                           IUnitOfWork destinationUnitOfWork)
        {
            Expression <Func <ProductActivationDTO, bool> > filter =
                a => !a.Synced && a.DateLastModified > LastServerSyncDate;

            if (!ToServerSyncing)
            {
                Expression <Func <ProductActivationDTO, bool> > filter2 =
                    a => a.Agency != null &&
                    a.Agency.RowGuid == Singleton.Agency.RowGuid;

                filter = filter.And(filter2);
            }

            var productActivationDtos =
                sourceUnitOfWork.Repository <ProductActivationDTO>().Query()
                .Include(a => a.Agency)
                .Filter(filter)
                .Get(1)
                .ToList();
            var destLocalAgencies =
                destinationUnitOfWork.Repository <AgencyDTO>().Query()
                .Filter(a => a.Id == Singleton.Agency.Id)
                .Get(1)
                .ToList();

            foreach (var source in productActivationDtos)
            {
                _updatesFound = true;


                var adr1        = source;
                var destination =
                    destinationUnitOfWork.Repository <ProductActivationDTO>().Query()
                    .Filter(i => i.RowGuid == adr1.RowGuid)
                    .Get(1)
                    .FirstOrDefault();

                //To Prevent ServerData Overriding
                if (destination != null && (ToServerSyncing && !destination.Synced))
                {
                    continue;
                }

                var clientId = 0;
                if (destination == null)
                {
                    destination = new ProductActivationDTO();
                }
                else
                {
                    clientId = destination.Id;
                }

                try
                {
                    Mapper.Reset();
                    Mapper.CreateMap <ProductActivationDTO, ProductActivationDTO>()
                    .ForMember("Agency", option => option.Ignore())
                    .ForMember("Synced", option => option.Ignore());

                    destination    = Mapper.Map(source, destination);
                    destination.Id = clientId;

                    destination.CreatedByUserId = GetDestCreatedModifiedByUserId(source.CreatedByUserId,
                                                                                 sourceUnitOfWork, destinationUnitOfWork);
                    destination.ModifiedByUserId = GetDestCreatedModifiedByUserId(source.ModifiedByUserId,
                                                                                  sourceUnitOfWork, destinationUnitOfWork);
                }
                catch (Exception ex)
                {
                    LogUtil.LogError(ErrorSeverity.Critical, "SyncProductActivations Mapping",
                                     ex.Message + Environment.NewLine + ex.InnerException, UserName, Agency);
                }

                try
                {
                    #region Foreign Keys

                    var agencyDTO =
                        destLocalAgencies.FirstOrDefault(
                            c => source.Agency != null && c.RowGuid == source.Agency.RowGuid);
                    {
                        destination.Agency   = agencyDTO;
                        destination.AgencyId = agencyDTO != null ? agencyDTO.Id : (int?)null;
                    }

                    #endregion

                    destination.Synced = true;
                    destinationUnitOfWork.Repository <ProductActivationDTO>()
                    .InsertUpdate(destination);
                }
                catch
                {
                    _errorsFound = true;
                    LogUtil.LogError(ErrorSeverity.Critical, "SyncProductActivations Crud",
                                     "Problem On SyncProductActivations Crud Method", UserName, Agency);
                    return(false);
                }
            }
            var changes = destinationUnitOfWork.Commit();
            if (changes < 0)
            {
                _errorsFound = true;
                LogUtil.LogError(ErrorSeverity.Critical, "SyncProductActivations Commit",
                                 "Problem Commiting SyncProductActivations Method", UserName, Agency);
                return(false);
            }

            return(true);
        }
Пример #4
0
        private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (_login)
            {
                DirectLogin();
                //new Login().Show();
            }
            else if (_activations)
            {
                new Activations().Show();
            }
            else if (_suspeciousActivation)
            {
                if (MessageBox.Show(
                        "The Product has already been activated on another computer, Do you want to reset the Key",
                        "Suspicious Activation", MessageBoxButton.YesNo, MessageBoxImage.Error) == MessageBoxResult.Yes)
                {
                    ProductActivationDTO activation =
                        _unitOfWork.Repository <ProductActivationDTO>().Query().Get().FirstOrDefault();
                    _unitOfWork.Repository <ProductActivationDTO>().Delete(activation);
                    _unitOfWork.Commit();

                    new Activations().Show();
                }
            }
            else if (_higherDbVersion)
            {
                MessageBox.Show(
                    "Database version is Newer than the system version, " + Environment.NewLine +
                    "Database Version: " + _activationModel.DatabaseVersionDate + Environment.NewLine +
                    "Installed System Version: " + Singleton.SystemVersionDate + Environment.NewLine +
                    "Please get latest system version",
                    "Old System Version", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else if (_higherSystemVersion)
            {
                MessageBox.Show(
                    "You are not allowed to use this version of the system, " + Environment.NewLine +
                    "Allowed system Version: " + _activationModel.DatabaseVersionDate + Environment.NewLine +
                    "Installed System Version: " + Singleton.SystemVersionDate + Environment.NewLine +
                    "activate your product or contact PINNAFACE OFFICE",
                    "Newer System Version", MessageBoxButton.OK, MessageBoxImage.Error);
                new Activations().Show();
            }
            else if (_blockedKey)
            {
                MessageBox.Show("Your acount is Blocked!",
                                "Blocked Key",
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else if (_exceptions != null)
            {
                MessageBox.Show("Got Exception While Starting The System On Splash Screen", "Got Exception",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                LogUtil.LogError(ErrorSeverity.Critical, "CheckActivation()", _exceptions.Message + Environment.NewLine + _exceptions.InnerException, "", "");
            }
            else
            {
                MessageBox.Show(
                    Singleton.Edition == PinnaFaceEdition.ServerEdition
                        ? "Problem opening oneface, may be the server computer or the network not working properly! try again later.."
                        : "Problem opening oneface! try again later..", "Error Opening",
                    MessageBoxButton.OK, MessageBoxImage.Error);
            }

            CloseWindow(SplashWindow);
        }
Пример #5
0
        private void DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                var instance = Singleton.Instance;
                //Check Database Vs System Version
                _activationModel = ValidateProduct();

                if (_activationModel != null &&
                    _activationModel.DatabaseVersionDate != 0 &&
                    _activationModel.MaximumSystemVersion != 0)
                {
                    if (instance.SystemVersionDate < _activationModel.DatabaseVersionDate)
                    {
                        _higherDbVersion = true;
                    }

                    if (Singleton.SystemVersionDate > _activationModel.MaximumSystemVersion)
                    {
                        _higherSystemVersion = true;
                    }
                }

                if (!_higherDbVersion && !_higherSystemVersion)
                {
                    ProductActivationDTO activation =
                        _unitOfWork.Repository <ProductActivationDTO>().Query().Get().FirstOrDefault();

                    if (activation == null)
                    {
                        _activations = true;
                    }
                    else if (activation.KeyStatus == KeyStatus.Blocked)
                    {
                        _blockedKey = true;
                    }
                    else
                    {
                        LicensedTo = activation.LicensedTo;
                        //Thread.Sleep(1000); //To show to whom the license belongs
                        if (activation.RegisteredBiosSn.Contains(new ProductActivationDTO().BiosSn))
                        {
                            //Check if this product is expired and also check if it is Renewed on the server
                            //Otherwise close the app OR disable features
                            if (activation.KeyStatus == KeyStatus.Expired || DateTime.Now > activation.ExpiryDate)
                            {
                                ActivationKey key = CheckProductRenewalOnActivationServer(activation.ProductKey);
                                if (key != null)
                                {
                                    if (key.ExpiryDate != activation.ExpiryDate)
                                    {
                                        activation.ExpiryDate      = key.ExpiryDate;
                                        activation.LastRenewedDate = key.LastRenewedDate;
                                        activation.KeyStatus       = KeyStatus.Active;
                                    }
                                    else
                                    {
                                        activation.KeyStatus = KeyStatus.Expired;
                                    }
                                }
                                else
                                {
                                    activation.KeyStatus = KeyStatus.Expired;
                                }


                                _unitOfWork.Repository <ProductActivationDTO>().InsertUpdate(activation);
                                _unitOfWork.Commit();
                            }
                            else if (activation.KeyStatus == KeyStatus.Active)
                            {
                                Singleton.ProductActivation = activation;
                                _login = true;
                            }
                        }
                        else
                        {
                            if (Singleton.Edition == PinnaFaceEdition.ServerEdition)
                            {
                                _activations = true;
                            }
                            else
                            {
                                _suspeciousActivation = true;
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                _exceptions = exception;
            }
        }
Пример #6
0
        private void DoWork(object sender, DoWorkEventArgs e)
        {
            #region Update Product Activation
            try
            {
                var unitOfWork = new UnitOfWork(DbContextUtil.GetDbContextInstance());

                ProductActivationDTO productActivation = unitOfWork.Repository <ProductActivationDTO>()
                                                         .Query().Get()
                                                         .FirstOrDefault();

                if (productActivation != null)
                {
                    if (productActivation.DatabaseVersionDate < Singleton.SystemVersionDate)
                    {
                        productActivation.DatabaseVersionDate = Singleton.SystemVersionDate;
                        unitOfWork.Repository <ProductActivationDTO>().Update(productActivation);
                        unitOfWork.Commit();
                    }
                    //DatabaseVersion = productActivation.DatabaseVersionDate.ToString();
                }
                unitOfWork.Dispose();
            }
            catch (Exception exception)
            {
                LogUtil.LogError(ErrorSeverity.Fatal,
                                 "MainViewModel.Set productActivation.DatabaseVersionDate to higher",
                                 exception.Message + Environment.NewLine + exception.InnerException, "", "");
            }
            #endregion

            //#region Update Addresses
            //var localAgency = new LocalAgencyService(true).GetLocalAgency();

            //try
            //{
            //    var unitOfWork = new UnitOfWork(DbContextUtil.GetDbContextInstance());

            //    var addresses = unitOfWork.Repository<AddressDTO>()
            //        .Query().Filter(a => a.AgencyId == null).Get().ToList();
            //    if (addresses.Count > 0)
            //    {
            //        foreach (var addressDTO in addresses)
            //        {
            //            addressDTO.AgencyId = localAgency.Id;
            //            unitOfWork.Repository<AddressDTO>().Update(addressDTO);
            //        }
            //        unitOfWork.Commit();
            //    }


            //    unitOfWork.Dispose();
            //}
            //catch (Exception exception)
            //{
            //    LogUtil.LogError(ErrorSeverity.Fatal,
            //        "MainViewModel.Set productActivation.DatabaseVersionDate to higher",
            //        exception.Message + Environment.NewLine + exception.InnerException, "", "");
            //}
            //#endregion

            //#region Update Attachments
            //try
            //{
            //    var unitOfWork = new UnitOfWork(DbContextUtil.GetDbContextInstance());


            //    var addresses = unitOfWork.Repository<AttachmentDTO>()
            //        .Query().Filter(a => a.AgencyId == null).Get().ToList();

            //    if (addresses.Count > 0)
            //    {
            //        foreach (var addressDTO in addresses)
            //        {
            //            addressDTO.AgencyId = localAgency.Id;
            //            unitOfWork.Repository<AttachmentDTO>().Update(addressDTO);
            //        }
            //        unitOfWork.Commit();
            //    }
            //    unitOfWork.Dispose();
            //}
            //catch (Exception exception)
            //{
            //    LogUtil.LogError(ErrorSeverity.Fatal,
            //        "MainViewModel.Set productActivation.DatabaseVersionDate to higher",
            //        exception.Message + Environment.NewLine + exception.InnerException, "", "");
            //}
            //#endregion

            //try
            //{
            //    LogUtil.LogError(ErrorSeverity.Critical, "FileUploader Started", "", "", "");
            //    var fileUploader = new FileUploader();
            //    fileUploader.UploadFiles();
            //    LogUtil.LogError(ErrorSeverity.Critical, "FileUploader Completed", "", "", "");
            //}
            //catch (Exception ex)
            //{

            //    LogUtil.LogError(ErrorSeverity.Critical, "FileUploader.UploadFiles problem",
            //            ex.Message + Environment.NewLine + ex.InnerException, "", "");
            //}
        }