Esempio n. 1
0
        private async Task <bool> Import(QuestionType questionType)
        {
            if (string.IsNullOrEmpty(questionType.Source))
            {
                return(true);
            }

            try
            {
                ImportDto <List <ImportChapterDto> > importDto = HttpHelper.Get <ImportDto <List <ImportChapterDto> > >(questionType.Source);

                if (!importDto.Success)
                {
                    return(false);
                }

                foreach (ImportChapterDto importChapterDto in importDto.Data)
                {
                    if (!(await Import(questionType, importChapterDto)))
                    {
                        return(false);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                return(false);
            }
        }
Esempio n. 2
0
        private void ProcessRoleSettings(ExportImportJob importJob, ImportDto importDto,
                                         IList <ExportRole> otherRoles, IEnumerable <ExportRoleSetting> otherRoleSettings)
        {
            var changedSettings = new List <SettingItem>();
            var portalId        = importJob.PortalId;

            foreach (var other in otherRoleSettings)
            {
                if (CheckCancelled(importJob))
                {
                    return;
                }
                var createdBy  = Util.GetUserIdByName(importJob, other.CreatedByUserID, other.CreatedByUserName);
                var modifiedBy = Util.GetUserIdByName(importJob, other.LastModifiedByUserID, other.LastModifiedByUserName);
                var otherRole  = otherRoles.FirstOrDefault(r => r.RoleID == other.RoleID);
                if (otherRole == null || !otherRole.LocalId.HasValue)
                {
                    continue;
                }
                var localRoleInfo = RoleController.Instance.GetRoleById(portalId, otherRole.LocalId.Value);
                if (localRoleInfo == null)
                {
                    continue;
                }

                switch (importDto.CollisionResolution)
                {
                case CollisionResolution.Ignore:
                    Result.AddLogEntry("Ignored role setting", other.SettingName);
                    break;

                case CollisionResolution.Overwrite:
                    string settingValue;
                    if (!localRoleInfo.Settings.TryGetValue(other.SettingName, out settingValue) ||
                        settingValue != other.SettingValue)
                    {
                        changedSettings.Add(new SettingItem(localRoleInfo.RoleID, other.SettingName, createdBy, modifiedBy));
                        localRoleInfo.Settings[other.SettingName] = other.SettingValue;
                        RoleController.Instance.UpdateRoleSettings(localRoleInfo, false);
                        Result.AddLogEntry("Updated role setting", other.SettingName);
                        //No need to clear cache as the caller will do it one time at end
                    }
                    else
                    {
                        Result.AddLogEntry("Ignored role setting", other.SettingName);
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException(importDto.CollisionResolution.ToString());
                }
            }

            if (changedSettings.Count > 0)
            {
                RefreshRecordsUserIds(changedSettings);
            }

            RoleController.Instance.ClearRoleCache(importJob.PortalId);
        }
Esempio n. 3
0
        private async Task <bool> Import(QuestionType questionType, QuestionChapter questionChapter, List <int> questionList, int intOrderIndex)
        {
            if (!questionList.Any())
            {
                return(true);
            }

            try
            {
                ImportDto <List <ImportQuestionDto> > importDto = HttpHelper.Get <ImportDto <List <ImportQuestionDto> > >("http://api2.jiakaobaodian.com/api/open/question/question-list.htm?_r=114972216825686778106&questionIds=" + string.Join("%2C", questionList) + "&_=0.8455804460813621");
                if (!importDto.Success)
                {
                    return(false);
                }

                foreach (ImportQuestionDto importQuestionDto in importDto.Data)
                {
                    if (!(await Import(questionType, questionChapter, importQuestionDto, intOrderIndex++)))
                    {
                        return(false);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                return(false);
            }
        }
Esempio n. 4
0
        private void ProcessRoleGroups(ExportImportJob importJob, ImportDto importDto,
                                       IEnumerable <ExportRoleGroup> otherRoleGroups)
        {
            var changedGroups   = new List <RoleGroupItem>();
            var portalId        = importJob.PortalId;
            var localRoleGroups = CBO.FillCollection <ExportRoleGroup>(DataProvider.Instance().GetAllRoleGroups(portalId, DateUtils.GetDatabaseUtcTime().AddYears(1), null));

            foreach (var other in otherRoleGroups)
            {
                if (CheckCancelled(importJob))
                {
                    return;
                }
                var createdBy  = Util.GetUserIdByName(importJob, other.CreatedByUserID, other.CreatedByUserName);
                var modifiedBy = Util.GetUserIdByName(importJob, other.LastModifiedByUserID, other.LastModifiedByUserName);
                var local      = localRoleGroups.FirstOrDefault(t => t.RoleGroupName == other.RoleGroupName);

                if (local != null)
                {
                    other.LocalId = local.RoleGroupID;
                    switch (importDto.CollisionResolution)
                    {
                    case CollisionResolution.Ignore:
                        Result.AddLogEntry("Ignored role group", other.RoleGroupName);
                        break;

                    case CollisionResolution.Overwrite:
                        var roleGroup = new RoleGroupInfo(local.RoleGroupID, portalId, false)
                        {
                            RoleGroupName = other.RoleGroupName,
                            Description   = other.Description,
                        };
                        RoleController.UpdateRoleGroup(roleGroup, false);
                        changedGroups.Add(new RoleGroupItem(roleGroup.RoleGroupID, createdBy, modifiedBy));
                        DataCache.ClearCache(string.Format(DataCache.RoleGroupsCacheKey, local.RoleGroupID));
                        Result.AddLogEntry("Updated role group", other.RoleGroupName);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(importDto.CollisionResolution.ToString());
                    }
                }
                else
                {
                    var roleGroup = new RoleGroupInfo()
                    {
                        PortalID      = portalId,
                        RoleGroupName = other.RoleGroupName,
                        Description   = other.Description,
                    };
                    other.LocalId = RoleController.AddRoleGroup(roleGroup);
                    changedGroups.Add(new RoleGroupItem(roleGroup.RoleGroupID, createdBy, modifiedBy));
                    Result.AddLogEntry("Added role group", other.RoleGroupName);
                }
            }
            if (changedGroups.Count > 0)
            {
                RefreshRecordsUserIds(changedGroups);
            }
        }
Esempio n. 5
0
        private void ProcessPortalLanguages(ExportImportJob importJob, ImportDto importDto,
                                            IEnumerable <ExportPortalLanguage> portalLanguages)
        {
            var portalId             = importJob.PortalId;
            var localPortalLanguages =
                CBO.FillCollection <ExportPortalLanguage>(DataProvider.Instance().GetPortalLanguages(portalId, DateUtils.GetDatabaseUtcTime().AddYears(1), null));
            var localLanguages = CBO.FillCollection <Locale>(DotNetNuke.Data.DataProvider.Instance().GetLanguages());

            foreach (var exportPortalLanguage in portalLanguages)
            {
                if (CheckCancelled(importJob))
                {
                    return;
                }
                var localLanguageId =
                    localLanguages.FirstOrDefault(x => x.Code == exportPortalLanguage.CultureCode)?.LanguageId;
                var existingPortalLanguage =
                    localPortalLanguages.FirstOrDefault(
                        t =>
                        t.LanguageId == localLanguageId);
                var isUpdate = false;
                if (existingPortalLanguage != null)
                {
                    switch (importDto.CollisionResolution)
                    {
                    case CollisionResolution.Overwrite:
                        isUpdate = true;
                        break;

                    case CollisionResolution.Ignore:
                        Result.AddLogEntry("Ignored portal language", exportPortalLanguage.CultureCode);
                        continue;

                    default:
                        throw new ArgumentOutOfRangeException(importDto.CollisionResolution.ToString());
                    }
                }
                if (isUpdate)
                {
                    var modifiedBy = Util.GetUserIdByName(importJob, exportPortalLanguage.LastModifiedByUserId, exportPortalLanguage.LastModifiedByUserName);

                    DotNetNuke.Data.DataProvider.Instance()
                    .UpdatePortalLanguage(importJob.PortalId, exportPortalLanguage.LanguageId,
                                          exportPortalLanguage.IsPublished, modifiedBy);

                    Result.AddLogEntry("Updated portal language", exportPortalLanguage.CultureCode);
                }
                else
                {
                    var createdBy = Util.GetUserIdByName(importJob, exportPortalLanguage.CreatedByUserId, exportPortalLanguage.CreatedByUserName);

                    exportPortalLanguage.PortalLanguageId = DotNetNuke.Data.DataProvider.Instance()
                                                            .AddPortalLanguage(importJob.PortalId, exportPortalLanguage.LanguageId,
                                                                               exportPortalLanguage.IsPublished, createdBy);
                    Result.AddLogEntry("Added portal language", exportPortalLanguage.CultureCode);
                }
            }
        }
Esempio n. 6
0
        public override void ImportData(ExportImportJob importJob, ImportDto importDto)
        {
            if (this.CheckPoint.Stage > 0)
            {
                return;
            }

            var profileProperties = this.Repository.GetAllItems <ExportProfileProperty>().ToList();

            // Update the total items count in the check points. This should be updated only once.
            this.CheckPoint.TotalItems = this.CheckPoint.TotalItems <= 0 ? profileProperties.Count : this.CheckPoint.TotalItems;
            this.CheckPointStageCallback(this);

            foreach (var profileProperty in profileProperties)
            {
                if (this.CheckCancelled(importJob))
                {
                    return;
                }

                var existingProfileProperty = CBO.FillObject <ExportProfileProperty>(DotNetNuke.Data.DataProvider.Instance()
                                                                                     .GetPropertyDefinitionByName(importJob.PortalId, profileProperty.PropertyName));

                if (existingProfileProperty != null)
                {
                    switch (importDto.CollisionResolution)
                    {
                    case CollisionResolution.Overwrite:
                        var modifiedById = Util.GetUserIdByName(importJob, profileProperty.LastModifiedByUserId, profileProperty.LastModifiedByUserName);
                        ProcessUpdateProfileProperty(profileProperty, existingProfileProperty, modifiedById);
                        break;

                    case CollisionResolution.Ignore:
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(importDto.CollisionResolution.ToString());
                    }
                }
                else
                {
                    var createdById = Util.GetUserIdByName(
                        importJob,
                        profileProperty.CreatedByUserId,
                        profileProperty.CreatedByUserName);

                    ProcessCreateProfileProperty(importJob, profileProperty, createdById);
                }
            }

            this.Result.AddSummary("Imported Profile Properties", profileProperties.Count.ToString());
            this.CheckPoint.ProcessedItems = profileProperties.Count;
            this.CheckPoint.Completed      = true;
            this.CheckPoint.Progress       = 100;
            this.CheckPoint.Stage++;
            this.CheckPointStageCallback(this);
        }
        private void ProcessImportModulePackages(ImportDto importDto)
        {
            var packageZipFile = $"{Globals.ApplicationMapPath}{Constants.ExportFolder}{this.exportImportJob.Directory.TrimEnd('\\', '/')}\\{Constants.ExportZipPackages}";
            var tempFolder     = $"{Path.GetDirectoryName(packageZipFile)}\\{DateTime.Now.Ticks}";

            if (File.Exists(packageZipFile))
            {
                CompressionUtil.UnZipArchive(packageZipFile, tempFolder);
                var exportPackages = this.Repository.GetAllItems <ExportPackage>().ToList();

                this.CheckPoint.TotalItems = this.CheckPoint.TotalItems <= 0 ? exportPackages.Count : this.CheckPoint.TotalItems;
                if (this.CheckPointStageCallback(this))
                {
                    return;
                }

                if (this.CheckPoint.Stage == 0)
                {
                    try
                    {
                        foreach (var exportPackage in exportPackages)
                        {
                            this.ProcessImportModulePackage(exportPackage, tempFolder, importDto.CollisionResolution);

                            this.CheckPoint.ProcessedItems++;
                            this.CheckPoint.Progress = this.CheckPoint.ProcessedItems * 100.0 / exportPackages.Count;
                            if (this.CheckPointStageCallback(this))
                            {
                                break;
                            }
                        }

                        this.CheckPoint.Stage++;
                        this.CheckPoint.Completed = true;
                    }
                    finally
                    {
                        this.CheckPointStageCallback(this);
                        try
                        {
                            FileSystemUtils.DeleteFolderRecursive(tempFolder);
                        }
                        catch (Exception)
                        {
                            // ignore
                        }
                    }
                }
            }
            else
            {
                this.CheckPoint.Completed = true;
                this.CheckPointStageCallback(this);
                this.Result.AddLogEntry("PackagesFileNotFound", "Packages file not found. Skipping packages import", ReportLevel.Warn);
            }
        }
Esempio n. 8
0
        private void ProcessPortalSettings(ExportImportJob importJob, ImportDto importDto,
            IEnumerable<ExportPortalSetting> portalSettings)
        {
            var portalId = importJob.PortalId;
            var localPortalSettings =
                CBO.FillCollection<ExportPortalSetting>(DataProvider.Instance().GetPortalSettings(portalId, DateUtils.GetDatabaseUtcTime().AddYears(1), null));
            foreach (var exportPortalSetting in portalSettings)
            {
                if (CheckCancelled(importJob)) return;

                var existingPortalSetting =
                    localPortalSettings.FirstOrDefault(
                        t =>
                            t.SettingName == exportPortalSetting.SettingName &&
                            (t.CultureCode == exportPortalSetting.CultureCode ||
                             (string.IsNullOrEmpty(t.CultureCode) &&
                              string.IsNullOrEmpty(exportPortalSetting.CultureCode))));
                var isUpdate = false;
                if (existingPortalSetting != null)
                {
                    switch (importDto.CollisionResolution)
                    {
                        case CollisionResolution.Overwrite:
                            isUpdate = true;
                            break;
                        case CollisionResolution.Ignore:
                            Result.AddLogEntry("Ignored portal settings", exportPortalSetting.SettingName);
                            continue;
                        default:
                            throw new ArgumentOutOfRangeException(importDto.CollisionResolution.ToString());
                    }
                }
                if (isUpdate)
                {
                    var modifiedBy = Util.GetUserIdByName(importJob, exportPortalSetting.LastModifiedByUserId,
                     exportPortalSetting.LastModifiedByUserName);

                    exportPortalSetting.PortalSettingId = existingPortalSetting.PortalSettingId;
                    DotNetNuke.Data.DataProvider.Instance()
                        .UpdatePortalSetting(importJob.PortalId, exportPortalSetting.SettingName,
                            exportPortalSetting.SettingValue, modifiedBy, exportPortalSetting.CultureCode);
                    Result.AddLogEntry("Updated portal settings", exportPortalSetting.SettingName);
                }
                else
                {
                    var createdBy = Util.GetUserIdByName(importJob, exportPortalSetting.CreatedByUserId, exportPortalSetting.CreatedByUserName);

                    DotNetNuke.Data.DataProvider.Instance()
                        .UpdatePortalSetting(importJob.PortalId, exportPortalSetting.SettingName,
                            exportPortalSetting.SettingValue, createdBy, exportPortalSetting.CultureCode);

                    Result.AddLogEntry("Added portal settings", exportPortalSetting.SettingName);
                }
            }
        }
Esempio n. 9
0
        public HttpResponseMessage Import(ImportDto importDto)
        {
            var    controller = new ImportController();
            string message;

            if (controller.VerifyImportPackage(importDto.PackageId, null, out message))
            {
                var jobId = controller.QueueOperation(PortalSettings.UserId, importDto);
                return(Request.CreateResponse(HttpStatusCode.OK, new { jobId }));
            }
            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, message));
        }
        /// <summary>
        /// 导入需求预测数据
        /// </summary>
        /// <returns></returns>
        public async Task <APIResultDto> ImportDemandDetailExcelAsync(ImportDto input)
        {
            //获取Excel数据
            var excelList = await GetDemandDetailDataAsync();

            //循环批量更新
            await UpdateDemandDetailDataAsync(excelList, input.DemandForecastId);

            return(new APIResultDto()
            {
                Code = 0, Msg = "导入数据成功"
            });
        }
Esempio n. 11
0
        public override void ImportData(ExportImportJob importJob, ImportDto importDto)
        {
            // Update the total items count in the check points. This should be updated only once.
            this.CheckPoint.TotalItems = this.CheckPoint.TotalItems = this.CheckPoint.TotalItems <= 0 ? this.GetImportTotal() : this.CheckPoint.TotalItems;
            if (this.CheckPointStageCallback(this))
            {
                return;
            }

            if (this.CheckPoint.Stage > 1)
            {
                return;
            }

            if (this.CheckPoint.Stage == 0)
            {
                var portalSettings = this.Repository.GetAllItems <ExportPortalSetting>().ToList();
                this.ProcessPortalSettings(importJob, importDto, portalSettings);
                this.CheckPoint.TotalItems = this.GetImportTotal();
                this.Result.AddSummary("Imported Portal Settings", portalSettings.Count.ToString());
                this.CheckPoint.Progress += 50;
                this.CheckPoint.Stage++;
                this.CheckPoint.ProcessedItems = portalSettings.Count;
                if (this.CheckPointStageCallback(this))
                {
                    return;
                }
            }

            if (this.CheckPoint.Stage == 1)
            {
                var portalLanguages = this.Repository.GetAllItems <ExportPortalLanguage>().ToList();
                this.ProcessPortalLanguages(importJob, importDto, portalLanguages);
                this.Result.AddSummary("Imported Portal Languages", portalLanguages.Count.ToString());
                this.CheckPoint.Progress += 50;
                this.CheckPoint.Completed = true;
                this.CheckPoint.Stage++;
                this.CheckPoint.ProcessedItems += portalLanguages.Count;
                this.CheckPointStageCallback(this);
            }

            /*
             * ProgressPercentage = 0;
             * var portalLocalizations = Repository.GetAllItems<ExportPortalLocalization>().ToList();
             * ProcessPortalLocalizations(importJob, importDto, portalLocalizations);
             * Result.AddSummary("Imported Portal Localizations", portalLocalizations.Count.ToString());
             * ProgressPercentage += 40;
             */
        }
Esempio n. 12
0
        public override void ImportData(ExportImportJob importJob, ImportDto importDto)
        {
            if (CheckCancelled(importJob))
            {
                return;
            }
            //Skip the export if all the templates have been processed already.
            if (CheckPoint.Stage >= 1 || CheckPoint.Completed)
            {
                return;
            }

            _exportImportJob = importJob;

            ProcessImportModulePackages(importDto);
        }
Esempio n. 13
0
        private async Task <bool> Import(QuestionType questionType, ImportChapterDto importChapterDto)
        {
            try
            {
                QuestionChapter questionChapter = new QuestionChapter
                {
                    QuestionTypeId = questionType.Id,
                    Name           = importChapterDto.Title,
                    OrderIndex     = importChapterDto.Chapter
                };

                _Db.QuestionChapters.Add(questionChapter);
                await _Db.SaveChangesAsync();

                ImportDto <ImportChapterQuestionDto> importDto = HttpHelper.Get <ImportDto <ImportChapterQuestionDto> >("https://api2.jiakaobaodian.com/api/open/exercise/chapter.htm?_appName=jiakaobaodian&_platform=wap&_r=110028075929574772092&carType=car&chapterId=" + importChapterDto.Id + "&cityCode=430100&course=kemu1");
                if (!importDto.Success)
                {
                    return(false);
                }

                int intOrderIndex = 0;

                List <int> questionList = new List <int>();

                foreach (int question in importDto.Data.questionList)
                {
                    if (questionList.Count >= 50)
                    {
                        await Import(questionType, questionChapter, questionList, intOrderIndex);

                        intOrderIndex += questionList.Count;
                        questionList.Clear();
                    }
                    questionList.Add(question);
                }

                await Import(questionType, questionChapter, questionList, intOrderIndex);

                return(true);
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                return(false);
            }
        }
Esempio n. 14
0
        public ImportDto ImportExistingData(GetClaimsInput input)
        {
            ImportDto importDto = new ImportDto();
            var       query     = _clientRepository.GetAll()
                                  .Where(p =>
                                         p.IdNumber.Equals(input.FilterText) ||
                                         p.Tel.Equals(input.FilterText) ||
                                         p.Email.Equals(input.FilterText))
                                  .FirstOrDefault();

            if (query != null)
            {
                importDto.Id                     = query.Id;
                importDto.Name                   = query.Name;
                importDto.Surname                = query.Surname;
                importDto.Title                  = query.Title;
                importDto.Email                  = query.Email;
                importDto.Tel                    = query.Tel;
                importDto.IdNumber               = query.IdNumber;
                importDto.CommunicationType      = query.CommunicationType;
                importDto.ContactAfterService    = query.ContactAfterService;
                importDto.ClientOtherInformation = query.OtherInformation;
            }
            var query1 = _brvehiclerepository.GetAll()
                         .Where(p => p.RegistrationNumber.Equals(input.FilterText1) || p.VinNumber.Equals(input.FilterText1))
                         .FirstOrDefault();

            if (query1 != null)
            {
                importDto.MakeId             = query1.MakeId;
                importDto.ModelId            = query1.ModelId;
                importDto.Colour             = query1.Color;
                importDto.PaintTypeId        = query1.PaintTypeId;
                importDto.Year               = query1.Year;
                importDto.RegistrationNumber = query1.RegistrationNumber;
                importDto.VinNumber          = query1.VinNumber;
                //importDto.UnderWaranty = query1.UnderWaranty;
                importDto.IsSpecialisedType       = query1.IsSpecialisedType;
                importDto.IsLuxury                = query1.IsLuxury;
                importDto.VehicleOtherInformation = query1.OtherInformation;
                importDto.VId = query1.Id;
            }
            return(importDto);
        }
Esempio n. 15
0
        public override void ImportData(ExportImportJob importJob, ImportDto importDto)
        {
            if (this.CheckPoint.Stage > 0)
            {
                return;
            }

            if (this.CheckCancelled(importJob))
            {
                return;
            }

            // Update the total items count in the check points. This should be updated only once.
            this.CheckPoint.TotalItems = this.CheckPoint.TotalItems = this.CheckPoint.TotalItems <= 0 ? this.GetImportTotal() : this.CheckPoint.TotalItems;
            if (this.CheckPoint.Stage == 0)
            {
                var otherScopeTypes = this.Repository.GetAllItems <TaxonomyScopeType>().ToList();

                // the table Taxonomy_ScopeTypes is used for lookup only and never changed/updated in the database
                // CheckPoint.Progress = 10;

                // var otherVocabularyTypes = Repository.GetAllItems<TaxonomyVocabularyType>().ToList();
                // the table Taxonomy_VocabularyTypes is used for lookup only and never changed/updated in the database
                this.CheckPoint.Progress = 20;

                var otherVocabularies = this.Repository.GetAllItems <TaxonomyVocabulary>().ToList();
                this.ProcessVocabularies(importJob, importDto, otherScopeTypes, otherVocabularies);
                this.Repository.UpdateItems(otherVocabularies);
                this.Result.AddSummary("Imported Vocabularies", otherVocabularies.Count.ToString());
                this.CheckPoint.Progress        = 60;
                this.CheckPoint.ProcessedItems += otherVocabularies.Count;

                var otherTaxonomyTerms = this.Repository.GetAllItems <TaxonomyTerm>().ToList();
                this.ProcessTaxonomyTerms(importJob, importDto, otherVocabularies, otherTaxonomyTerms);
                this.Repository.UpdateItems(otherTaxonomyTerms);
                this.Result.AddSummary("Imported Terms", otherTaxonomyTerms.Count.ToString());
                this.CheckPoint.Progress        = 100;
                this.CheckPoint.ProcessedItems += otherTaxonomyTerms.Count;
                this.CheckPoint.Stage++;
                this.CheckPoint.Completed = true;
                this.CheckPointStageCallback(this);
            }
        }
Esempio n. 16
0
        public int QueueOperation(int userId, ImportDto importDto)
        {
            using (var repository = new ExportImportRepository(GetPackageDbPath(importDto.PackageId)))
            {
                var exportDto = repository.GetSingleItem <ExportDto>();
                importDto.ExportDto = exportDto;
            }

            importDto.ExportFileInfo =
                GetExportFileInfo(Path.Combine(ExportFolder, importDto.PackageId, Constants.ExportManifestName));
            var dataObject = JsonConvert.SerializeObject(importDto);
            var jobId      = DataProvider.Instance().AddNewJob(
                importDto.PortalId, userId, JobType.Import, null, null, importDto.PackageId, dataObject);

            //Run the scheduler if required.
            if (importDto.RunNow)
            {
                EntitiesController.Instance.RunSchedule();
            }
            AddEventLog(importDto.PortalId, userId, jobId, Constants.LogTypeSiteImport);
            return(jobId);
        }
Esempio n. 17
0
        private BeatCharacterLocalDto ProcessModelCharacter(ImportDto character, decimal K, JobLifeStyleDto lastdto)
        {
            var billing   = IocContainer.Get <IBillingManager>();
            var workModel = new WorkModelDto
            {
                Dividends1          = character?.EreminModel?.workModel?.passiveAbilities?.Any(p => p.id == "dividends-1") ?? false,
                Dividends2          = character?.EreminModel?.workModel?.passiveAbilities?.Any(p => p.id == "dividends-2") ?? false,
                Dividends3          = character?.EreminModel?.workModel?.passiveAbilities?.Any(p => p.id == "dividends-3") ?? false,
                StockGainPercentage = character?.EreminModel?.workModel?.billing?.stockGainPercentage ?? 0,
                KarmaCount          = character?.EreminModel?.workModel?.karma?.spent ?? 0
            };
            var dto = billing.ProcessCharacterBeat(character.Sin.Id, workModel, K, lastdto);

            try
            {
                EreminPushAdapter.SendNotification(character.Sin.Character.Model, "Кошелек", "Экономический пересчет завершен");
            }
            catch (Exception e)
            {
                LogException(e);
            }
            return(dto);
        }
Esempio n. 18
0
        private void LoadCharacters(List <SIN> sins, ConcurrentQueue <ImportDto> concurrent)
        {
            var erService = new EreminService();

            Parallel.ForEach(sins, new ParallelOptions {
                MaxDegreeOfParallelism = 5
            }, sin =>
            {
                var dto = new ImportDto {
                    Sin = sin
                };
                try
                {
                    dto.EreminModel = erService.GetCharacter(sin.Character.Model);
                }
                catch (Exception e)
                {
                    LogException(e);
                    dto.ErrorText = e.Message;
                }
                concurrent.Enqueue(dto);
            });
        }
Esempio n. 19
0
        public override void ImportData(ExportImportJob importJob, ImportDto importDto)
        {
            if (this.CheckCancelled(importJob))
            {
                return;
            }

            const int pageSize                      = Constants.DefaultPageSize;
            var       totalUsersImported            = 0;
            var       totalPortalsImported          = 0;
            var       totalAspnetUserImported       = 0;
            var       totalAspnetMembershipImported = 0;
            var       totalUserAuthenticationCount  = 0;
            var       totalUsers                    = this.Repository.GetCount <ExportUser>();

            if (totalUsers == 0)
            {
                this.CheckPoint.Completed = true;
                this.CheckPointStageCallback(this);
                return;
            }

            var totalPages = Util.CalculateTotalPages(totalUsers, pageSize);

            // Skip the import if all the users has been processed already.
            if (this.CheckPoint.Stage >= totalPages)
            {
                return;
            }

            var pageIndex = this.CheckPoint.Stage;

            var totalUsersToBeProcessed = totalUsers - (pageIndex * pageSize);

            // Update the total items count in the check points. This should be updated only once.
            this.CheckPoint.TotalItems = this.CheckPoint.TotalItems <= 0 ? totalUsers : this.CheckPoint.TotalItems;
            if (this.CheckPointStageCallback(this))
            {
                return;
            }

            try
            {
                this.Repository.RebuildIndex <ExportUser>(x => x.Id, true);
                this.Repository.RebuildIndex <ExportUserPortal>(x => x.ReferenceId);
                this.Repository.RebuildIndex <ExportAspnetUser>(x => x.ReferenceId);
                this.Repository.RebuildIndex <ExportAspnetMembership>(x => x.ReferenceId);
                this.Repository.RebuildIndex <ExportUserAuthentication>(x => x.ReferenceId);
                var portalId     = importJob.PortalId;
                var dataProvider = DotNetNuke.Data.DataProvider.Instance();
                using (var table = new DataTable("Users"))
                {
                    // must create the columns from scratch with each iteration
                    table.Columns.AddRange(
                        UsersDatasetColumns.Select(column => new DataColumn(column.Item1, column.Item2)).ToArray());
                    while (totalUsersImported < totalUsersToBeProcessed)
                    {
                        if (this.CheckCancelled(importJob))
                        {
                            return;
                        }

                        var users =
                            this.Repository.GetAllItems <ExportUser>(null, true, pageIndex * pageSize, pageSize).ToList();
                        var tempAspUserCount            = 0;
                        var tempAspMembershipCount      = 0;
                        var tempUserPortalCount         = 0;
                        var tempUserAuthenticationCount = 0;
                        try
                        {
                            foreach (var user in users)
                            {
                                if (this.CheckCancelled(importJob))
                                {
                                    return;
                                }

                                var row = table.NewRow();

                                var userPortal         = this.Repository.GetRelatedItems <ExportUserPortal>(user.Id).FirstOrDefault();
                                var userAuthentication = this.Repository.GetRelatedItems <ExportUserAuthentication>(user.Id).FirstOrDefault();

                                // Aspnet Users and Membership
                                var aspNetUser       = this.Repository.GetRelatedItems <ExportAspnetUser>(user.Id).FirstOrDefault();
                                var aspnetMembership = aspNetUser != null
                                    ? this.Repository.GetRelatedItems <ExportAspnetMembership>(aspNetUser.Id).FirstOrDefault()
                                    : null;

                                row["PortalId"]                = portalId;
                                row["Username"]                = user.Username;
                                row["FirstName"]               = string.IsNullOrEmpty(user.FirstName) ? string.Empty : user.FirstName;
                                row["LastName"]                = string.IsNullOrEmpty(user.LastName) ? string.Empty : user.LastName;
                                row["AffiliateId"]             = dataProvider.GetNull(user.AffiliateId);
                                row["IsSuperUser"]             = user.IsSuperUser;
                                row["Email"]                   = user.Email;
                                row["DisplayName"]             = string.IsNullOrEmpty(user.DisplayName) ? string.Empty : user.DisplayName;
                                row["UpdatePassword"]          = user.UpdatePassword;
                                row["CreatedByUserID"]         = Util.GetUserIdByName(importJob, user.CreatedByUserId, user.CreatedByUserName);
                                row["LastIPAddress"]           = dataProvider.GetNull(user.LastIpAddress);
                                row["PasswordResetToken"]      = dataProvider.GetNull(user.PasswordResetToken);
                                row["PasswordResetExpiration"] = dataProvider.GetNull(user.PasswordResetExpiration);
                                row["LastModifiedByUserID"]    = Util.GetUserIdByName(importJob, user.LastModifiedByUserId, user.LastModifiedByUserName);

                                if (userPortal != null)
                                {
                                    tempUserPortalCount += 1;
                                    row["Authorised"]    = userPortal.Authorised;
                                    row["VanityUrl"]     = userPortal.VanityUrl;
                                    row["RefreshRoles"]  = userPortal.RefreshRoles;
                                    row["IsDeleted"]     = userPortal.IsDeleted;
                                }
                                else
                                {
                                    row["Authorised"]   = DBNull.Value;
                                    row["VanityUrl"]    = DBNull.Value;
                                    row["RefreshRoles"] = DBNull.Value;
                                    row["IsDeleted"]    = DBNull.Value;
                                }

                                if (userAuthentication != null)
                                {
                                    tempUserAuthenticationCount += 1;
                                    row["AuthenticationType"]    = userAuthentication?.AuthenticationType;
                                    row["AuthenticationToken"]   = userAuthentication?.AuthenticationToken;
                                }
                                else
                                {
                                    row["AuthenticationType"]  = DBNull.Value;
                                    row["AuthenticationToken"] = DBNull.Value;
                                }

                                if (aspNetUser != null)
                                {
                                    tempAspUserCount    += 1;
                                    row["ApplicationId"] = this.GetApplicationId();
                                    row["AspUserId"]     = aspNetUser.UserId;
                                    row["MobileAlias"]   = aspNetUser.MobileAlias;
                                    row["IsAnonymous"]   = aspNetUser.IsAnonymous;
                                    if (aspnetMembership != null)
                                    {
                                        tempAspMembershipCount                 += 1;
                                        row["Password"]                         = string.IsNullOrEmpty(aspnetMembership.Password) ? string.Empty : aspnetMembership.Password;
                                        row["PasswordFormat"]                   = aspnetMembership.PasswordFormat;
                                        row["PasswordSalt"]                     = aspnetMembership.PasswordSalt;
                                        row["MobilePIN"]                        = aspnetMembership.MobilePin;
                                        row["PasswordQuestion"]                 = aspnetMembership.PasswordQuestion;
                                        row["PasswordAnswer"]                   = aspnetMembership.PasswordAnswer;
                                        row["IsApproved"]                       = aspnetMembership.IsApproved;
                                        row["IsLockedOut"]                      = aspnetMembership.IsLockedOut;
                                        row["FailedPasswordAttemptCount"]       = aspnetMembership.FailedPasswordAttemptCount;
                                        row["FailedPasswordAnswerAttemptCount"] = aspnetMembership.FailedPasswordAnswerAttemptCount;
                                        row["Comment"] = aspnetMembership.Comment;
                                    }
                                }
                                else
                                {
                                    row["ApplicationId"]                    = DBNull.Value;
                                    row["AspUserId"]                        = DBNull.Value;
                                    row["MobileAlias"]                      = DBNull.Value;
                                    row["IsAnonymous"]                      = DBNull.Value;
                                    row["Password"]                         = DBNull.Value;
                                    row["PasswordFormat"]                   = DBNull.Value;
                                    row["PasswordSalt"]                     = DBNull.Value;
                                    row["MobilePIN"]                        = DBNull.Value;
                                    row["PasswordQuestion"]                 = DBNull.Value;
                                    row["PasswordAnswer"]                   = DBNull.Value;
                                    row["IsApproved"]                       = DBNull.Value;
                                    row["IsLockedOut"]                      = DBNull.Value;
                                    row["FailedPasswordAttemptCount"]       = DBNull.Value;
                                    row["FailedPasswordAnswerAttemptCount"] = DBNull.Value;
                                    row["Comment"] = DBNull.Value;
                                }

                                table.Rows.Add(row);
                            }

                            var overwrite = importDto.CollisionResolution == CollisionResolution.Overwrite;

                            // Bulk insert the data in DB
                            DotNetNuke.Data.DataProvider.Instance()
                            .BulkInsert("ExportImport_AddUpdateUsersBulk", "@DataTable", table, new Dictionary <string, object> {
                                { "Overwrite", overwrite }
                            });
                            totalUsersImported             += users.Count;
                            totalAspnetUserImported        += tempAspUserCount;
                            totalAspnetMembershipImported  += tempAspMembershipCount;
                            totalPortalsImported           += tempUserPortalCount;
                            totalUserAuthenticationCount   += tempUserAuthenticationCount;
                            this.CheckPoint.ProcessedItems += users.Count;
                        }
                        catch (Exception ex)
                        {
                            this.Result.AddLogEntry($"Importing Users from {pageIndex * pageSize} to {(pageIndex * pageSize) + pageSize} exception", ex.Message, ReportLevel.Error);
                        }

                        table.Rows.Clear();
                        pageIndex++;
                        this.CheckPoint.Progress = this.CheckPoint.ProcessedItems * 100.0 / totalUsers;
                        this.CheckPoint.Stage++;
                        this.CheckPoint.StageData = null;
                        if (this.CheckPointStageCallback(this))
                        {
                            return;
                        }
                    }
                }

                this.CheckPoint.Completed = true;
                this.CheckPoint.Progress  = 100;
            }
            finally
            {
                this.CheckPointStageCallback(this);
                this.Result.AddSummary("Imported Users", totalUsersImported.ToString());
                this.Result.AddSummary("Imported User Portals", totalPortalsImported.ToString());
                this.Result.AddSummary("Import User Authentications", totalUserAuthenticationCount.ToString());
                this.Result.AddSummary("Imported Aspnet Users", totalAspnetUserImported.ToString());
                this.Result.AddSummary("Imported Aspnet Memberships", totalAspnetMembershipImported.ToString());
            }
        }
Esempio n. 20
0
        public override void ImportData(ExportImportJob importJob, ImportDto importDto)
        {
            if (CheckCancelled(importJob) || CheckPoint.Stage >= 1 || CheckPoint.Completed || CheckPointStageCallback(this))
            {
                return;
            }

            var workflowManager      = WorkflowManager.Instance;
            var workflowStateManager = WorkflowStateManager.Instance;
            var portalId             = importJob.PortalId;
            var importWorkflows      = Repository.GetAllItems <ExportWorkflow>().ToList();
            var existWorkflows       = workflowManager.GetWorkflows(portalId).ToList();
            var defaultTabWorkflowId = importWorkflows.FirstOrDefault(w => w.IsDefault)?.WorkflowID ?? 1;

            CheckPoint.TotalItems = CheckPoint.TotalItems <= 0 ? importWorkflows.Count : CheckPoint.TotalItems;

            #region importing workflows

            foreach (var importWorkflow in importWorkflows)
            {
                var workflow = existWorkflows.FirstOrDefault(w => w.WorkflowName == importWorkflow.WorkflowName);
                if (workflow != null)
                {
                    if (!importWorkflow.IsSystem && importDto.CollisionResolution == CollisionResolution.Overwrite)
                    {
                        if (workflow.Description != importWorkflow.Description ||
                            workflow.WorkflowKey != importWorkflow.WorkflowKey)
                        {
                            workflow.Description = importWorkflow.Description;
                            workflow.WorkflowKey = importWorkflow.WorkflowKey;
                            workflowManager.UpdateWorkflow(workflow);
                            Result.AddLogEntry("Updated workflow", workflow.WorkflowName);
                        }
                    }
                }
                else
                {
                    workflow = new Workflow
                    {
                        PortalID     = portalId,
                        WorkflowName = importWorkflow.WorkflowName,
                        Description  = importWorkflow.Description,
                        WorkflowKey  = importWorkflow.WorkflowKey,
                    };

                    workflowManager.AddWorkflow(workflow);
                    Result.AddLogEntry("Added workflow", workflow.WorkflowName);

                    if (importWorkflow.WorkflowID == defaultTabWorkflowId)
                    {
                        TabWorkflowSettings.Instance.SetDefaultTabWorkflowId(portalId, workflow.WorkflowID);
                    }
                }

                importWorkflow.LocalId = workflow.WorkflowID;

                #region importing workflow states

                var importStates = Repository.GetRelatedItems <ExportWorkflowState>(importWorkflow.Id).ToList();
                foreach (var importState in importStates)
                {
                    var workflowState = workflow.States.FirstOrDefault(s => s.StateName == importState.StateName);
                    if (workflowState != null)
                    {
                        if (!workflowState.IsSystem)
                        {
                            workflowState.Order            = importState.Order;
                            workflowState.IsSystem         = false;
                            workflowState.SendNotification = importState.SendNotification;
                            workflowState.SendNotificationToAdministrators = importState.SendNotificationToAdministrators;
                            workflowStateManager.UpdateWorkflowState(workflowState);
                            Result.AddLogEntry("Updated workflow state", workflowState.StateID.ToString());
                        }
                    }
                    else
                    {
                        workflowState = new WorkflowState
                        {
                            StateName        = importState.StateName,
                            WorkflowID       = workflow.WorkflowID,
                            Order            = importState.Order,
                            IsSystem         = importState.IsSystem,
                            SendNotification = importState.SendNotification,
                            SendNotificationToAdministrators = importState.SendNotificationToAdministrators
                        };
                        WorkflowStateManager.Instance.AddWorkflowState(workflowState);
                        Result.AddLogEntry("Added workflow state", workflowState.StateID.ToString());
                    }
                    importState.LocalId = workflowState.StateID;

                    #region importin permissions

                    if (!workflowState.IsSystem)
                    {
                        var importPermissions = Repository.GetRelatedItems <ExportWorkflowStatePermission>(importState.Id).ToList();
                        foreach (var importPermission in importPermissions)
                        {
                            var permissionId = DataProvider.Instance().GetPermissionId(
                                importPermission.PermissionCode, importPermission.PermissionKey, importPermission.PermissionName);

                            if (permissionId != null)
                            {
                                var noRole = Convert.ToInt32(Globals.glbRoleNothing);
                                var userId = UserController.GetUserByName(importDto.PortalId, importPermission.Username)?.UserID;
                                var roleId = Util.GetRoleIdByName(importDto.PortalId, importPermission.RoleID ?? noRole, importPermission.RoleName);

                                var permission = new WorkflowStatePermission
                                {
                                    PermissionID = permissionId ?? -1,
                                    StateID      = workflowState.StateID,
                                    RoleID       = noRole,
                                    UserID       = -1,
                                    AllowAccess  = importPermission.AllowAccess,
                                    //TODO: ModuleDefID = ??? what value to set here ?
                                };

                                if (importPermission.UserID != null && importPermission.UserID > 0 && !string.IsNullOrEmpty(importPermission.Username))
                                {
                                    if (userId == null)
                                    {
                                        Result.AddLogEntry("Couldn't add tab permission; User is undefined!",
                                                           $"{importPermission.PermissionKey} - {importPermission.PermissionID}", ReportLevel.Warn);
                                        continue;
                                    }
                                    permission.UserID = userId.Value;
                                }

                                if (importPermission.RoleID != null && importPermission.RoleID > noRole && !string.IsNullOrEmpty(importPermission.RoleName))
                                {
                                    if (roleId == null)
                                    {
                                        Result.AddLogEntry("Couldn't add tab permission; Role is undefined!",
                                                           $"{importPermission.PermissionKey} - {importPermission.PermissionID}", ReportLevel.Warn);
                                        continue;
                                    }
                                    permission.RoleID = roleId.Value;
                                }

                                try
                                {
                                    var existingPermissions = workflowStateManager.GetWorkflowStatePermissionByState(workflowState.StateID);
                                    var local = existingPermissions.FirstOrDefault(
                                        x => x.PermissionCode == importPermission.PermissionCode && x.PermissionKey == importPermission.PermissionKey &&
                                        x.PermissionName.Equals(importPermission.PermissionName, StringComparison.InvariantCultureIgnoreCase) &&
                                        x.RoleID == roleId && x.UserID == userId);


                                    if (local == null)
                                    {
                                        workflowStateManager.AddWorkflowStatePermission(permission, -1);
                                        importPermission.LocalId = permission.WorkflowStatePermissionID;
                                        Result.AddLogEntry("Added workflow state permission",
                                                           permission.WorkflowStatePermissionID.ToString());
                                    }
                                    else
                                    {
                                        importPermission.LocalId = local.WorkflowStatePermissionID;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Result.AddLogEntry("Exception adding workflow state permission", ex.Message, ReportLevel.Error);
                                }
                            }
                        }
                    }

                    #endregion
                }

                #endregion

                Repository.UpdateItems(importStates);
                Result.AddSummary("Imported Workflow", importWorkflows.Count.ToString());
                CheckPoint.ProcessedItems++;
                CheckPointStageCallback(this); // no need to return; very small amount of data processed
            }

            #endregion

            Repository.UpdateItems(importWorkflows);

            CheckPoint.Stage++;
            CheckPoint.StageData      = null;
            CheckPoint.Progress       = 100;
            CheckPoint.TotalItems     = importWorkflows.Count;
            CheckPoint.ProcessedItems = importWorkflows.Count;
            CheckPointStageCallback(this);
        }
Esempio n. 21
0
        private void ProcessFiles(ExportImportJob importJob, ImportDto importDto, ExportFile file, IEnumerable <ExportFile> localFiles)
        {
            if (file == null)
            {
                return;
            }
            var existingFile = localFiles.FirstOrDefault(x => x.FileName == file.FileName);
            var isUpdate     = false;

            if (existingFile != null)
            {
                switch (importDto.CollisionResolution)
                {
                case CollisionResolution.Overwrite:
                    isUpdate = true;
                    break;

                case CollisionResolution.Ignore:
                    return;

                default:
                    throw new ArgumentOutOfRangeException(importDto.CollisionResolution.ToString());
                }
            }
            if (isUpdate)
            {
                var modifiedBy = Util.GetUserIdByName(importJob, file.LastModifiedByUserId, file.LastModifiedByUserName);
                file.FileId = existingFile.FileId;
                DotNetNuke.Data.DataProvider.Instance()
                .UpdateFile(existingFile.FileId, file.VersionGuid, file.FileName, file.Extension, file.Size,
                            file.Width ?? Null.NullInteger, file.Height ?? Null.NullInteger, file.ContentType, file.FolderId,
                            modifiedBy, file.Sha1Hash, DateUtils.GetDatabaseLocalTime(), file.Title, file.Description,
                            file.StartDate, file.EndDate ?? Null.NullDate, file.EnablePublishPeriod,
                            existingFile.ContentItemId ?? Null.NullInteger);

                if ((file.Content != null && existingFile.Content == null) ||
                    (existingFile.Content != null && file.Content == null) ||
                    (file.Content != null && existingFile.Content != null &&
                     file.Content.SequenceEqual(existingFile.Content)))
                {
                    DotNetNuke.Data.DataProvider.Instance().UpdateFileContent(file.FileId, file.Content);
                }
            }
            else
            {
                var createdBy = Util.GetUserIdByName(importJob, file.CreatedByUserId, file.CreatedByUserName);
                file.FileId = DotNetNuke.Data.DataProvider.Instance()
                              .AddFile(importJob.PortalId, Guid.NewGuid(), file.VersionGuid, file.FileName, file.Extension,
                                       file.Size,
                                       file.Width ?? Null.NullInteger, file.Height ?? Null.NullInteger, file.ContentType, file.Folder,
                                       file.FolderId,
                                       createdBy, file.Sha1Hash, DateUtils.GetDatabaseLocalTime(), file.Title, file.Description,
                                       file.StartDate, file.EndDate ?? Null.NullDate, file.EnablePublishPeriod,
                                       //file.ContentItemId ?? Null.NullInteger);--If we keep it we will see FK_PK relationship errors.
                                       Null.NullInteger);


                if (file.Content != null)
                {
                    DotNetNuke.Data.DataProvider.Instance().UpdateFileContent(file.FileId, file.Content);
                }
            }
        }
Esempio n. 22
0
        private void ProcessFolderPermission(ExportImportJob importJob, ImportDto importDto,
                                             ExportFolderPermission folderPermission, IEnumerable <ExportFolderPermission> localPermissions)
        {
            var portalId = importJob.PortalId;
            var noRole   = Convert.ToInt32(Globals.glbRoleNothing);

            if (folderPermission == null)
            {
                return;
            }
            var roleId = Util.GetRoleIdByName(portalId, folderPermission.RoleId ?? noRole, folderPermission.RoleName);
            var userId = UserController.GetUserByName(portalId, folderPermission.Username)?.UserID;

            var existingFolderPermission = localPermissions.FirstOrDefault(
                x =>
                (x.FolderPath == folderPermission.FolderPath ||
                 (string.IsNullOrEmpty(x.FolderPath) && string.IsNullOrEmpty(folderPermission.FolderPath))) &&
                x.PermissionCode == folderPermission.PermissionCode && x.PermissionKey == folderPermission.PermissionKey &&
                x.PermissionName.Equals(folderPermission.PermissionName, StringComparison.InvariantCultureIgnoreCase) &&
                x.RoleId == roleId && x.UserId == userId);

            var isUpdate = false;

            if (existingFolderPermission != null)
            {
                switch (importDto.CollisionResolution)
                {
                case CollisionResolution.Overwrite:
                    isUpdate = true;
                    break;

                case CollisionResolution.Ignore:
                    return;

                default:
                    throw new ArgumentOutOfRangeException(importDto.CollisionResolution.ToString());
                }
            }
            if (isUpdate)
            {
                var modifiedBy = Util.GetUserIdByName(importJob, folderPermission.LastModifiedByUserId,
                                                      folderPermission.LastModifiedByUserName);

                DotNetNuke.Data.DataProvider.Instance()
                .UpdateFolderPermission(existingFolderPermission.FolderPermissionId, folderPermission.FolderId,
                                        existingFolderPermission.PermissionId, existingFolderPermission.RoleId ?? Convert.ToInt32(Globals.glbRoleNothing),
                                        folderPermission.AllowAccess, existingFolderPermission.UserId ?? Null.NullInteger, modifiedBy);

                folderPermission.FolderPermissionId = existingFolderPermission.FolderPermissionId;
            }
            else
            {
                var permissionId = DataProvider.Instance()
                                   .GetPermissionId(folderPermission.PermissionCode, folderPermission.PermissionKey,
                                                    folderPermission.PermissionName);

                if (permissionId != null)
                {
                    folderPermission.PermissionId = Convert.ToInt32(permissionId);
                    if (folderPermission.UserId != null && folderPermission.UserId > 0 && !string.IsNullOrEmpty(folderPermission.Username))
                    {
                        folderPermission.UserId = userId;
                        if (folderPermission.UserId == null)
                        {
                            return;
                        }
                    }
                    if (folderPermission.RoleId != null && folderPermission.RoleId > noRole && !string.IsNullOrEmpty(folderPermission.RoleName))
                    {
                        folderPermission.RoleId = roleId;
                        if (folderPermission.RoleId == null)
                        {
                            return;
                        }
                    }
                    var createdBy = Util.GetUserIdByName(importJob, folderPermission.CreatedByUserId,
                                                         folderPermission.CreatedByUserName);

                    folderPermission.FolderPermissionId = DotNetNuke.Data.DataProvider.Instance()
                                                          .AddFolderPermission(folderPermission.FolderId, folderPermission.PermissionId,
                                                                               folderPermission.RoleId ?? noRole, folderPermission.AllowAccess,
                                                                               folderPermission.UserId ?? Null.NullInteger, createdBy);
                }
            }
            folderPermission.LocalId = folderPermission.FolderPermissionId;
        }
Esempio n. 23
0
        public override void ImportData(ExportImportJob importJob, ImportDto importDto)
        {
            if (CheckPoint.Stage > 2)
            {
                return;
            }

            if (CheckCancelled(importJob))
            {
                return;
            }
            //Update the total items count in the check points. This should be updated only once.
            CheckPoint.TotalItems = CheckPoint.TotalItems <= 0 ? GetImportTotal() : CheckPoint.TotalItems;
            CheckPointStageCallback(this);

            var otherRoleGroups = Repository.GetAllItems <ExportRoleGroup>().ToList();

            if (CheckPoint.Stage == 0)
            {
                ProcessRoleGroups(importJob, importDto, otherRoleGroups);
                Repository.UpdateItems(otherRoleGroups);
                Result.AddSummary("Imported Role Groups", otherRoleGroups.Count.ToString());
                CheckPoint.Progress       = 40;
                CheckPoint.ProcessedItems = otherRoleGroups.Count;
                CheckPoint.Stage++;
                if (CheckPointStageCallback(this))
                {
                    return;
                }
            }

            if (CheckCancelled(importJob))
            {
                return;
            }
            var otherRoles = Repository.GetAllItems <ExportRole>().ToList();

            if (CheckPoint.Stage == 1)
            {
                Result.AddSummary("Imported Roles", otherRoles.Count.ToString());
                ProcessRoles(importJob, importDto, otherRoleGroups, otherRoles);
                Repository.UpdateItems(otherRoles);
                CheckPoint.Progress        = 50;
                CheckPoint.ProcessedItems += otherRoles.Count;
                CheckPoint.Stage++;
                if (CheckPointStageCallback(this))
                {
                    return;
                }
            }

            if (CheckPoint.Stage == 2)
            {
                if (CheckCancelled(importJob))
                {
                    return;
                }
                var otherRoleSettings = Repository.GetAllItems <ExportRoleSetting>().ToList();
                ProcessRoleSettings(importJob, importDto, otherRoles, otherRoleSettings);
                Repository.UpdateItems(otherRoleSettings);
                Result.AddSummary("Imported Role Settings", otherRoleSettings.Count.ToString());
                CheckPoint.Progress        = 100;
                CheckPoint.ProcessedItems += otherRoleSettings.Count;
                CheckPoint.Completed       = true;
                CheckPoint.Stage++;
                CheckPointStageCallback(this);
            }
        }
Esempio n. 24
0
        private void ProcessTaxonomyTerms(ExportImportJob importJob, ImportDto importDto,
                                          IList <TaxonomyVocabulary> otherVocabularies, IList <TaxonomyTerm> otherTaxonomyTerms)
        {
            var dataService = Util.GetDataService();
            //var vocabularyController = new VocabularyController();
            var localTaxonomyTerms = GetTaxonomyTerms(importDto.PortalId, DateUtils.GetDatabaseUtcTime().AddYears(1), null);

            foreach (var other in otherTaxonomyTerms)
            {
                var createdBy  = Common.Util.GetUserIdByName(importJob, other.CreatedByUserID, other.CreatedByUserName);
                var modifiedBy = Common.Util.GetUserIdByName(importJob, other.LastModifiedByUserID, other.LastModifiedByUserName);

                var vocabulary   = otherVocabularies.FirstOrDefault(v => v.VocabularyID == other.VocabularyID);
                var vocabularyId = vocabulary?.LocalId ?? 0;
                var local        = localTaxonomyTerms.FirstOrDefault(t => t.Name == other.Name && t.VocabularyID == vocabularyId);

                if (local != null)
                {
                    other.LocalId = local.TermID;
                    switch (importDto.CollisionResolution)
                    {
                    case CollisionResolution.Ignore:
                        Result.AddLogEntry("Ignored taxonomy", other.Name);
                        break;

                    case CollisionResolution.Overwrite:
                        var parent = other.ParentTermID.HasValue
                                ? otherTaxonomyTerms.FirstOrDefault(v => v.TermID == other.ParentTermID.Value)
                                : null;
                        var term = new Term(other.Name, other.Description, vocabularyId)
                        {
                            TermId       = local.TermID,
                            ParentTermId = parent?.LocalId,
                            Weight       = other.Weight,
                        };

                        if (term.ParentTermId.HasValue)
                        {
                            dataService.UpdateHeirarchicalTerm(term, modifiedBy);
                        }
                        else
                        {
                            dataService.UpdateSimpleTerm(term, modifiedBy);
                        }
                        DataCache.ClearCache(string.Format(DataCache.TermCacheKey, term.TermId));
                        Result.AddLogEntry("Updated taxonomy", other.Name);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(importDto.CollisionResolution.ToString());
                    }
                }
                else
                {
                    var parent = other.ParentTermID.HasValue
                        ? otherTaxonomyTerms.FirstOrDefault(v => v.TermID == other.ParentTermID.Value)
                        : null;
                    var term = new Term(other.Name, other.Description, vocabularyId)
                    {
                        ParentTermId = parent?.LocalId,
                        Weight       = other.Weight,
                    };


                    other.LocalId = term.ParentTermId.HasValue
                        ? dataService.AddHeirarchicalTerm(term, createdBy)
                        : dataService.AddSimpleTerm(term, createdBy);
                    Result.AddLogEntry("Added taxonomy", other.Name);
                }
            }
        }
Esempio n. 25
0
        private void ProcessRoles(ExportImportJob importJob, ImportDto importDto,
                                  List <ExportRoleGroup> otherRoleGroups, IEnumerable <ExportRole> otherRoles)
        {
            var roleItems = new List <RoleItem>();
            var portalId  = importJob.PortalId;

            foreach (var other in otherRoles)
            {
                if (CheckCancelled(importJob))
                {
                    return;
                }
                var createdBy     = Util.GetUserIdByName(importJob, other.CreatedByUserID, other.CreatedByUserName);
                var modifiedBy    = Util.GetUserIdByName(importJob, other.LastModifiedByUserID, other.LastModifiedByUserName);
                var localRoleInfo = RoleController.Instance.GetRoleByName(portalId, other.RoleName);
                if (localRoleInfo != null)
                {
                    other.LocalId = localRoleInfo.RoleID;
                    switch (importDto.CollisionResolution)
                    {
                    case CollisionResolution.Ignore:
                        Result.AddLogEntry("Ignored role", other.RoleName);
                        break;

                    case CollisionResolution.Overwrite:
                        var group = other.RoleGroupID.HasValue
                                ? otherRoleGroups.FirstOrDefault(g => g.RoleGroupID == other.RoleGroupID.Value)
                                : null;

                        localRoleInfo.RoleName         = other.RoleName;
                        localRoleInfo.AutoAssignment   = false;   //other.AutoAssignment; CP: said do not do this
                        localRoleInfo.BillingFrequency = other.BillingFrequency;
                        localRoleInfo.BillingPeriod    = other.BillingPeriod ?? 0;
                        localRoleInfo.Description      = other.Description;
                        localRoleInfo.IconFile         = other.IconFile;  //TODO: map to local file
                        localRoleInfo.IsPublic         = other.IsPublic;
                        localRoleInfo.IsSystemRole     = other.IsSystemRole;
                        localRoleInfo.RoleGroupID      = group?.LocalId ?? Null.NullInteger;
                        localRoleInfo.RSVPCode         = other.RSVPCode;
                        localRoleInfo.SecurityMode     = (SecurityMode)other.SecurityMode;
                        localRoleInfo.ServiceFee       = Convert.ToSingle(other.ServiceFee ?? 0m);
                        localRoleInfo.Status           = (RoleStatus)other.Status;
                        localRoleInfo.TrialFee         = Convert.ToSingle(other.TrialFee ?? 0m);
                        localRoleInfo.TrialFrequency   = other.TrialFrequency;
                        localRoleInfo.TrialPeriod      = other.TrialPeriod ?? 0;

                        RoleController.Instance.UpdateRole(localRoleInfo, false);
                        roleItems.Add(new RoleItem(localRoleInfo.RoleID, createdBy, modifiedBy));

                        // do not assign existing users to the roles automatically
                        if (other.AutoAssignment)
                        {
                            DataProvider.Instance().SetRoleAutoAssign(localRoleInfo.RoleID);
                        }

                        RoleController.Instance.ClearRoleCache(localRoleInfo.RoleID);
                        Result.AddLogEntry("Updated role", other.RoleName);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(importDto.CollisionResolution.ToString());
                    }
                }

                if (localRoleInfo == null)
                {
                    var group = other.RoleGroupID.HasValue
                        ? otherRoleGroups.FirstOrDefault(g => g.RoleGroupID == other.RoleGroupID.Value)
                        : null;

                    var roleInfo = new RoleInfo
                    {
                        PortalID         = portalId,
                        RoleName         = other.RoleName,
                        AutoAssignment   = other.AutoAssignment,
                        BillingFrequency = other.BillingFrequency,
                        BillingPeriod    = other.BillingPeriod ?? 0,
                        Description      = other.Description,
                        IconFile         = other.IconFile, //TODO: map to local file
                        IsPublic         = other.IsPublic,
                        IsSystemRole     = other.IsSystemRole,
                        RoleGroupID      = group?.LocalId ?? Null.NullInteger,
                        RSVPCode         = other.RSVPCode,
                        SecurityMode     = (SecurityMode)other.SecurityMode,
                        ServiceFee       = Convert.ToSingle(other.ServiceFee ?? 0m),
                        Status           = (RoleStatus)other.Status,
                        TrialFee         = Convert.ToSingle(other.TrialFee ?? 0m),
                        TrialFrequency   = other.TrialFrequency,
                        TrialPeriod      = other.TrialPeriod ?? 0,
                    };

                    other.LocalId = RoleController.Instance.AddRole(roleInfo, false);
                    roleItems.Add(new RoleItem(roleInfo.RoleID, createdBy, modifiedBy));
                    RoleController.Instance.ClearRoleCache(roleInfo.RoleID);
                    Result.AddLogEntry("Added role", other.RoleName);
                }
            }

            //set created/updated for any added/modified item
            if (roleItems.Count > 0)
            {
                RefreshRecordsUserIds(roleItems);
            }
        }
        public override void ImportData(ExportImportJob importJob, ImportDto importDto)
        {
            if (CheckCancelled(importJob))
            {
                return;
            }

            var       pageIndex = 0;
            const int pageSize  = Constants.DefaultPageSize;
            var       totalUserRolesImported = 0;
            var       totalProfilesImported  = 0;
            var       totalProcessed         = 0;
            var       totalUsers             = Repository.GetCount <ExportUser>();

            if (totalUsers == 0)
            {
                CheckPoint.Completed = true;
                CheckPointStageCallback(this);
                return;
            }
            var totalPages = Util.CalculateTotalPages(totalUsers, pageSize);

            //Skip the import if all the users has been processed already.
            if (CheckPoint.Stage >= totalPages)
            {
                return;
            }

            pageIndex = CheckPoint.Stage;

            var totalUsersToBeProcessed = totalUsers - pageIndex * pageSize;

            //Update the total items count in the check points. This should be updated only once.
            CheckPoint.TotalItems = CheckPoint.TotalItems <= 0 ? totalUsers : CheckPoint.TotalItems;
            if (CheckPointStageCallback(this))
            {
                return;
            }
            var includeProfile = importDto.ExportDto.IncludeProperfileProperties;

            try
            {
                Repository.RebuildIndex <ExportUserRole>(x => x.ReferenceId);
                if (includeProfile)
                {
                    Repository.RebuildIndex <ExportUserProfile>(x => x.ReferenceId);
                }
                var portalId = importJob.PortalId;
                using (var tableUserProfile = new DataTable("UserProfile"))
                    using (var tableUserRoles = new DataTable("UserRoles"))
                    {
                        // must create the columns from scratch with each iteration
                        tableUserProfile.Columns.AddRange(UserProfileDatasetColumns.Select(column => new DataColumn(column.Item1, column.Item2)).ToArray());
                        tableUserRoles.Columns.AddRange(UserRolesDatasetColumns.Select(column => new DataColumn(column.Item1, column.Item2)).ToArray());
                        var dataProvider = DotNetNuke.Data.DataProvider.Instance();
                        while (totalProcessed < totalUsersToBeProcessed)
                        {
                            if (CheckCancelled(importJob))
                            {
                                return;
                            }
                            var users = Repository.GetAllItems <ExportUser>(null, true, pageIndex * pageSize, pageSize).ToList();
                            var tempUserRolesCount   = 0;
                            var tempUserProfileCount = 0;
                            try
                            {
                                foreach (var user in users)
                                {
                                    if (CheckCancelled(importJob))
                                    {
                                        return;
                                    }
                                    //Find the correct userId from the system which was added/updated by UserExportService.
                                    var userId = UserController.GetUserByName(user.Username)?.UserID;
                                    if (userId != null)
                                    {
                                        var userRoles = Repository.GetRelatedItems <ExportUserRole>(user.Id).ToList();
                                        foreach (var userRole in userRoles)
                                        {
                                            var roleId = Util.GetRoleIdByName(importJob.PortalId, userRole.RoleId, userRole.RoleName);
                                            if (roleId == null)
                                            {
                                                continue;
                                            }
                                            if (!(roleId > Convert.ToInt32(Globals.glbRoleNothing)))
                                            {
                                                continue;
                                            }
                                            var userRoleRow = tableUserRoles.NewRow();
                                            userRoleRow["PortalId"]             = portalId;
                                            userRoleRow["UserId"]               = userId;
                                            userRoleRow["RoleId"]               = roleId;
                                            userRoleRow["ExpiryDate"]           = dataProvider.GetNull(userRole.ExpiryDate);
                                            userRoleRow["IsTrialUsed"]          = userRole.IsTrialUsed;
                                            userRoleRow["EffectiveDate"]        = dataProvider.GetNull(userRole.EffectiveDate);
                                            userRoleRow["CreatedByUserId"]      = Util.GetUserIdByName(importJob, user.CreatedByUserId, user.CreatedByUserName);
                                            userRoleRow["LastModifiedByUserId"] = Util.GetUserIdByName(importJob, user.LastModifiedByUserId, user.LastModifiedByUserName);
                                            userRoleRow["Status"]               = userRole.Status;
                                            userRoleRow["IsOwner"]              = userRole.IsOwner;
                                            userRoleRow["IsSuperUser"]          = user.IsSuperUser;
                                            tableUserRoles.Rows.Add(userRoleRow);
                                            tempUserRolesCount++;
                                        }
                                        if (includeProfile)
                                        {
                                            var userProfiles =
                                                Repository.GetRelatedItems <ExportUserProfile>(user.Id).ToList();
                                            foreach (var userProfile in userProfiles)
                                            {
                                                var profileDefinitionId = Util.GetProfilePropertyId(importJob.PortalId,
                                                                                                    userProfile.PropertyDefinitionId, userProfile.PropertyName);
                                                if (profileDefinitionId == null || profileDefinitionId == -1)
                                                {
                                                    continue;
                                                }
                                                var value = userProfile.PropertyValue;
                                                if (userProfile.PropertyName.Equals("photo", StringComparison.InvariantCultureIgnoreCase) && (value = GetUserPhotoId(portalId, value, user)) == null)
                                                {
                                                    continue;
                                                }

                                                var userProfileRow = tableUserProfile.NewRow();
                                                userProfileRow["PortalId"]             = importJob.PortalId;
                                                userProfileRow["UserId"]               = userId;
                                                userProfileRow["PropertyDefinitionId"] = profileDefinitionId.Value;
                                                userProfileRow["PropertyValue"]        = value;
                                                userProfileRow["PropertyText"]         = userProfile.PropertyText;
                                                userProfileRow["Visibility"]           = userProfile.Visibility;
                                                userProfileRow["ExtendedVisibility"]   = userProfile.ExtendedVisibility;
                                                userProfileRow["IsSuperUser"]          = user.IsSuperUser;
                                                tableUserProfile.Rows.Add(userProfileRow);
                                                tempUserProfileCount++;
                                            }
                                        }
                                    }
                                }
                                var overwrite = importDto.CollisionResolution == CollisionResolution.Overwrite;
                                //Bulk insert the data in DB
                                DotNetNuke.Data.DataProvider.Instance()
                                .BulkInsert("ExportImport_AddUpdateUserRolesBulk", "@DataTable", tableUserRoles, new Dictionary <string, object> {
                                    { "Overwrite", overwrite }
                                });
                                totalUserRolesImported += tempUserRolesCount;

                                if (includeProfile)
                                {
                                    DotNetNuke.Data.DataProvider.Instance()
                                    .BulkInsert("ExportImport_AddUpdateUsersProfilesBulk", "@DataTable",
                                                tableUserProfile, new Dictionary <string, object> {
                                        { "Overwrite", overwrite }
                                    });
                                    totalProfilesImported += tempUserProfileCount;
                                }

                                CheckPoint.ProcessedItems += users.Count;
                                totalProcessed            += users.Count;
                                CheckPoint.Progress        = CheckPoint.ProcessedItems * 100.0 / totalUsers;
                                CheckPoint.StageData       = null;
                            }
                            catch (Exception ex)
                            {
                                Result.AddLogEntry($"Importing Users Data from {pageIndex * pageSize} to {pageIndex * pageSize + pageSize} exception", ex.Message, ReportLevel.Error);
                            }
                            tableUserRoles.Rows.Clear();
                            tableUserProfile.Rows.Clear();
                            pageIndex++;
                            CheckPoint.Progress = CheckPoint.ProcessedItems * 100.0 / totalUsers;
                            CheckPoint.Stage++;
                            CheckPoint.StageData = null;
                            if (CheckPointStageCallback(this))
                            {
                                return;
                            }
                        }
                    }
                CheckPoint.Completed = true;
                CheckPoint.Progress  = 100;
            }
            finally
            {
                CheckPointStageCallback(this);
                Result.AddSummary("Imported User Roles", totalUserRolesImported.ToString());
                if (includeProfile)
                {
                    Result.AddSummary("Imported User Profiles", totalProfilesImported.ToString());
                }
            }
        }
Esempio n. 27
0
        public override void ImportData(ExportImportJob importJob, ImportDto importDto)
        {
            if (CheckCancelled(importJob))
            {
                return;
            }
            //Stage 1: Portals files unzipped.
            //Stage 2: All folders and files imported.
            //Stage 3: Synchronization completed.
            //Skip the export if all the folders have been processed already.
            if (CheckPoint.Stage >= 2 || CheckPoint.Completed)
            {
                return;
            }

            var totalFolderImported            = 0;
            var totalFolderPermissionsImported = 0;
            var totalFilesImported             = 0;
            var skip           = GetCurrentSkip();
            var currentIndex   = skip;
            var portalId       = importJob.PortalId;
            var portal         = PortalController.Instance.GetPortal(portalId);
            var assetsFile     = string.Format(_assetsFolder, importJob.Directory.TrimEnd('\\').TrimEnd('/'));
            var userFolderPath = string.Format(UsersAssetsTempFolder, portal.HomeDirectoryMapPath.TrimEnd('\\'));

            if (CheckPoint.Stage == 0)
            {
                if (!File.Exists(assetsFile))
                {
                    Result.AddLogEntry("AssetsFileNotFound", "Assets file not found. Skipping assets import",
                                       ReportLevel.Warn);
                    CheckPoint.Completed = true;
                    CheckPointStageCallback(this);
                }
                else
                {
                    CompressionUtil.UnZipArchive(assetsFile, portal.HomeDirectoryMapPath,
                                                 importDto.CollisionResolution == CollisionResolution.Overwrite);
                    //Stage 1: Once unzipping of portal files is completed.
                    CheckPoint.Stage++;
                    CheckPoint.StageData = null;
                    CheckPoint.Progress  = 10;
                    if (CheckPointStageCallback(this))
                    {
                        return;
                    }
                }
            }

            if (CheckPoint.Stage == 1)
            {
                try
                {
                    //Stage 2 starts
                    var sourceFolders = Repository.GetAllItems <ExportFolder>(x => x.CreatedOnDate, true, skip).ToList();

                    var totalFolders = sourceFolders.Any() ? sourceFolders.Count : 0;
                    //Update the total items count in the check points. This should be updated only once.
                    CheckPoint.TotalItems = CheckPoint.TotalItems <= 0 ? totalFolders : CheckPoint.TotalItems;
                    if (CheckPointStageCallback(this))
                    {
                        return;
                    }

                    foreach (var sourceFolder in sourceFolders)
                    {
                        if (CheckCancelled(importJob))
                        {
                            break;
                        }
                        // PROCESS FOLDERS
                        //Create new or update existing folder
                        if (ProcessFolder(importJob, importDto, sourceFolder))
                        {
                            totalFolderImported++;

                            //Include permissions only if permissions were exported in package.
                            if (importDto.ExportDto.IncludePermissions)
                            {
                                // PROCESS FOLDER PERMISSIONS
                                var sourceFolderPermissions =
                                    Repository.GetRelatedItems <ExportFolderPermission>(sourceFolder.Id).ToList();
                                //Replace folderId for each permission with new one.
                                sourceFolderPermissions.ForEach(x =>
                                {
                                    x.FolderId   = Convert.ToInt32(sourceFolder.FolderId);
                                    x.FolderPath = sourceFolder.FolderPath;
                                });

                                // PROCESS FOLDER PERMISSIONS
                                //File local files in the system related to the folder path.
                                var localPermissions =
                                    CBO.FillCollection <ExportFolderPermission>(DataProvider.Instance()
                                                                                .GetFolderPermissionsByPath(portalId, sourceFolder.FolderPath,
                                                                                                            DateUtils.GetDatabaseUtcTime().AddYears(1), null));

                                foreach (var folderPermission in sourceFolderPermissions)
                                {
                                    ProcessFolderPermission(importJob, importDto, folderPermission,
                                                            localPermissions);
                                }
                                totalFolderPermissionsImported += sourceFolderPermissions.Count;
                            }

                            // PROCESS FILES
                            var sourceFiles =
                                Repository.GetRelatedItems <ExportFile>(sourceFolder.Id).ToList();
                            //Replace folderId for each file with new one.
                            sourceFiles.ForEach(x =>
                            {
                                x.FolderId = Convert.ToInt32(sourceFolder.FolderId);
                                x.Folder   = sourceFolder.FolderPath;
                            });

                            //File local files in the system related to the folder
                            var localFiles =
                                CBO.FillCollection <ExportFile>(DataProvider.Instance()
                                                                .GetFiles(portalId, sourceFolder.FolderId,
                                                                          DateUtils.GetDatabaseUtcTime().AddYears(1), null));

                            foreach (var file in sourceFiles)
                            {
                                ProcessFiles(importJob, importDto, file, localFiles);
                            }
                            totalFilesImported += sourceFiles.Count;
                        }

                        currentIndex++;
                        CheckPoint.ProcessedItems++;
                        CheckPoint.Progress = 10 + CheckPoint.ProcessedItems * 90.0 / totalFolders;
                        //After every 10 items, call the checkpoint stage. This is to avoid too many frequent updates to DB.
                        if (currentIndex % 10 == 0 && CheckPointStageCallback(this))
                        {
                            return;
                        }
                    }
                    currentIndex         = 0;
                    CheckPoint.Completed = true;
                    CheckPoint.Stage++;
                    CheckPoint.Progress = 100;
                }
                finally
                {
                    CheckPoint.StageData = currentIndex > 0
                        ? JsonConvert.SerializeObject(new { skip = currentIndex })
                        : null;
                    CheckPointStageCallback(this);

                    Result.AddSummary("Imported Folders", totalFolderImported.ToString());
                    Result.AddSummary("Imported Folder Permissions", totalFolderPermissionsImported.ToString());
                    Result.AddSummary("Imported Files", totalFilesImported.ToString());

                    if (Directory.Exists(userFolderPath) && currentIndex == 0)
                    {
                        Directory.Delete(userFolderPath, true);
                    }
                }
            }
        }
Esempio n. 28
0
        private bool ProcessFolder(ExportImportJob importJob, ImportDto importDto, ExportFolder folder)
        {
            var portalId = importJob.PortalId;

            if (folder == null)
            {
                return(false);
            }

            var existingFolder = CBO.FillObject <ExportFolder>(DotNetNuke.Data.DataProvider.Instance().GetFolder(portalId, folder.FolderPath ?? ""));
            var isUpdate       = false;
            var modifiedBy     = Util.GetUserIdByName(importJob, folder.LastModifiedByUserId, folder.LastModifiedByUserName);

            if (existingFolder != null)
            {
                switch (importDto.CollisionResolution)
                {
                case CollisionResolution.Overwrite:
                    isUpdate = true;
                    break;

                case CollisionResolution.Ignore:
                    return(false);

                default:
                    throw new ArgumentOutOfRangeException(importDto.CollisionResolution.ToString());
                }
            }
            folder.FolderPath = string.IsNullOrEmpty(folder.FolderPath) ? "" : folder.FolderPath;
            var folderMapping = FolderMappingController.Instance.GetFolderMapping(portalId, folder.FolderMappingName);

            if (folderMapping == null)
            {
                return(false);
            }
            var workFlowId = GetLocalWorkFlowId(folder.WorkflowId);

            if (isUpdate)
            {
                Util.FixDateTime(existingFolder);
                DotNetNuke.Data.DataProvider.Instance()
                .UpdateFolder(importJob.PortalId, folder.VersionGuid, existingFolder.FolderId, folder.FolderPath,
                              folder.StorageLocation, folder.MappedPath, folder.IsProtected, folder.IsCached,
                              DateUtils.GetDatabaseLocalTime(), modifiedBy, folderMapping.FolderMappingID, folder.IsVersioned,
                              workFlowId, existingFolder.ParentId ?? Null.NullInteger);

                folder.FolderId = existingFolder.FolderId;

                if (folder.UserId != null && folder.UserId > 0 && !string.IsNullOrEmpty(folder.Username))
                {
                    SyncUserFolder(importJob.PortalId, folder);
                }
            }
            else
            {
                folder.FolderMappingId = folderMapping.FolderMappingID;
                var createdBy = Util.GetUserIdByName(importJob, folder.CreatedByUserId, folder.CreatedByUserName);
                if (folder.ParentId != null && folder.ParentId > 0)
                {
                    //Find the previously created parent folder id.
                    folder.ParentId = CBO.FillObject <ExportFolder>(DotNetNuke.Data.DataProvider.Instance().GetFolder(portalId, folder.ParentFolderPath ?? ""))?.FolderId;
                }
                //ignore folders which start with Users but are not user folders.
                if (!folder.FolderPath.StartsWith(DefaultUsersFoldersPath))
                {
                    folder.FolderId = DotNetNuke.Data.DataProvider.Instance()
                                      .AddFolder(importJob.PortalId, Guid.NewGuid(), folder.VersionGuid, folder.FolderPath,
                                                 folder.MappedPath, folder.StorageLocation, folder.IsProtected, folder.IsCached,
                                                 DateUtils.GetDatabaseLocalTime(),
                                                 createdBy, folderMapping.FolderMappingID, folder.IsVersioned, workFlowId,
                                                 folder.ParentId ?? Null.NullInteger);
                }
                //Case when the folder is a user folder.
                else if (folder.UserId != null && folder.UserId > 0 && !string.IsNullOrEmpty(folder.Username))
                {
                    var userInfo = UserController.GetUserByName(portalId, folder.Username);
                    if (userInfo == null)
                    {
                        folder.FolderId = 0;
                        return(false);
                    }
                    userInfo.IsSuperUser = false;
                    var newFolder = FolderManager.Instance.GetUserFolder(userInfo);
                    folder.FolderId   = newFolder.FolderID;
                    folder.FolderPath = newFolder.FolderPath;
                    SyncUserFolder(importJob.PortalId, folder);
                    return(true);
                }
                else
                {
                    folder.FolderId = 0;
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 29
0
        private void ProcessVocabularies(ExportImportJob importJob, ImportDto importDto,
                                         IList <TaxonomyScopeType> otherScopeTypes, IEnumerable <TaxonomyVocabulary> otherVocabularies)
        {
            var changed           = false;
            var dataService       = Util.GetDataService();
            var localVocabularies = GetTaxonomyVocabularies(importDto.PortalId, DateUtils.GetDatabaseUtcTime().AddYears(1), null);

            foreach (var other in otherVocabularies)
            {
                var createdBy  = Common.Util.GetUserIdByName(importJob, other.CreatedByUserID, other.CreatedByUserName);
                var modifiedBy = Common.Util.GetUserIdByName(importJob, other.LastModifiedByUserID, other.LastModifiedByUserName);
                var local      = localVocabularies.FirstOrDefault(t => t.Name == other.Name);
                var scope      = otherScopeTypes.FirstOrDefault(s => s.ScopeTypeID == other.ScopeTypeID);

                var scopeId = other.ScopeID ?? Null.NullInteger;
                if (scope != null && scope.ScopeType.Equals("Application", StringComparison.InvariantCultureIgnoreCase))
                {
                    scopeId = Null.NullInteger;
                }
                else if (scope != null && scope.ScopeType.Equals("Portal", StringComparison.InvariantCultureIgnoreCase))
                {
                    scopeId = importDto.PortalId;
                }

                if (local != null)
                {
                    other.LocalId = local.VocabularyID;
                    switch (importDto.CollisionResolution)
                    {
                    case CollisionResolution.Ignore:
                        Result.AddLogEntry("Ignored vocabulary", other.Name);
                        break;

                    case CollisionResolution.Overwrite:
                        var vocabulary = new Vocabulary(other.Name, other.Description)
                        {
                            IsSystem    = other.IsSystem,
                            Weight      = other.Weight,
                            ScopeId     = scopeId,
                            ScopeTypeId = scope?.LocalId ?? other.ScopeTypeID,
                        };
                        dataService.UpdateVocabulary(vocabulary, modifiedBy);
                        Result.AddLogEntry("Updated vocabulary", other.Name);
                        changed = true;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(importDto.CollisionResolution.ToString());
                    }
                }
                else
                {
                    var vocabulary = new Vocabulary(other.Name, other.Description, (VocabularyType)other.VocabularyTypeID)
                    {
                        IsSystem    = other.IsSystem,
                        Weight      = other.Weight,
                        ScopeId     = scopeId,
                        ScopeTypeId = scope?.LocalId ?? other.ScopeTypeID,
                    };
                    other.LocalId = dataService.AddVocabulary(vocabulary, createdBy);
                    Result.AddLogEntry("Added vocabulary", other.Name);
                    changed = true;
                }
            }
            if (changed)
            {
                DataCache.ClearCache(DataCache.VocabularyCacheKey);
            }
        }
Esempio n. 30
0
 public abstract void ImportData(ExportImportJob importJob, ImportDto importDto);