Пример #1
0
        public async Task <IActionResult> Page(string id)
        {
            KirjaPage page = null;

            if (!string.IsNullOrEmpty(id))
            {
                page = await _pageDbAccess.GetPageById(id);
            }
            else
            {
                GoNorthProject project = await _projectDbAccess.GetDefaultProject();

                page = await _pageDbAccess.GetDefaultPageForProject(project.Id);

                if (page == null)
                {
                    page           = new KirjaPage();
                    page.IsDefault = true;
                    page.ProjectId = project.Id;
                    page.Name      = _localizer["DefaultPageName"];
                    page.Content   = _localizer["DefaultPageContent"];

                    _pageParserService.ParsePage(page);

                    page = await _pageDbAccess.CreatePage(page);
                }
            }
            return(Ok(page));
        }
Пример #2
0
        public async Task <IActionResult> Maps()
        {
            GoNorthProject project = await _projectDbAccess.GetDefaultProject();

            List <KartaMap> maps = await _mapDbAccess.GetAllProjectMaps(project.Id);

            return(Ok(maps));
        }
Пример #3
0
        public async Task <IActionResult> GetChapterOverview()
        {
            GoNorthProject defaultProject = await _projectDbAccess.GetDefaultProject();

            AikaChapterOverview chapterOverview = await _chapterOverviewDbAccess.GetChapterOverviewByProjectId(defaultProject.Id);

            return(Ok(chapterOverview));
        }
Пример #4
0
        public async Task <IActionResult> Folders(string parentId, int start, int pageSize)
        {
            string folderName     = string.Empty;
            string parentFolderId = string.Empty;
            Task <List <FlexFieldFolder> > queryTask;
            Task <int> countTask;

            if (string.IsNullOrEmpty(parentId))
            {
                GoNorthProject project = await _projectDbAccess.GetDefaultProject();

                queryTask = _folderDbAccess.GetRootFoldersForProject(project.Id, start, pageSize);
                countTask = _folderDbAccess.GetRootFolderCount(project.Id);
            }
            else
            {
                FlexFieldFolder folder = await _folderDbAccess.GetFolderById(parentId);

                parentFolderId = folder.ParentFolderId;
                folderName     = folder.Name;
                queryTask      = _folderDbAccess.GetChildFolders(parentId, start, pageSize);
                countTask      = _folderDbAccess.GetChildFolderCount(parentId);
            }

            Task.WaitAll(queryTask, countTask);

            FolderQueryResult queryResult = new FolderQueryResult();

            queryResult.FolderName = folderName;
            queryResult.ParentId   = parentFolderId;
            queryResult.Folders    = queryTask.Result;
            queryResult.HasMore    = start + queryResult.Folders.Count < countTask.Result;
            return(Ok(queryResult));
        }
Пример #5
0
        /// <summary>
        /// Manage function generation conditions
        /// </summary>
        /// <returns>View</returns>
        public async Task <IActionResult> FunctionGenerationCondition()
        {
            GoNorthProject project = await _projectDbAccess.GetDefaultProject();

            FunctionGenerationConditionViewModel viewModel = new FunctionGenerationConditionViewModel();

            viewModel.DialogFunctionGenerationActionTypes = Enum.GetValues(typeof(ActionType)).Cast <ActionType>().Select(s => new MappedDialogFunctionGenerationActionType {
                Value = (int)s,
                Name  = s.ToString()
            }).ToList();
            viewModel.NodeTypes = ExportDialogData.GetAllNodeTypes();
            viewModel.LockId    = project.Id;

            return(View(viewModel));
        }
Пример #6
0
        public async Task <IActionResult> GetJsonConfigByKey(string configKey)
        {
            GoNorthProject project = await _projectDbAccess.GetDefaultProject();

            JsonConfigEntry configEntry = await _projectConfigDbAccess.GetJsonConfigByKey(project.Id, configKey);

            if (configEntry != null)
            {
                return(Ok(configEntry.ConfigData));
            }
            else
            {
                return(Ok(string.Empty));
            }
        }
Пример #7
0
 /// <summary>
 /// Ensures that the project is loaded
 /// </summary>
 /// <returns>Task</returns>
 private async Task EnsureProject()
 {
     if (_project == null)
     {
         _project = await _projectDbAccess.GetDefaultProject();
     }
 }
Пример #8
0
        /// <summary>
        /// Configures the project
        /// </summary>
        /// <returns>Task</returns>
        private static async Task ConfigureProject()
        {
            ServiceProvider serviceProvider = ServiceProviderBuilder.BuildServiceProvider();

            IProjectDbAccess projectDbAccess = serviceProvider.GetService <IProjectDbAccess>();
            GoNorthProject   defaultProject  = await projectDbAccess.GetDefaultProject();

            if (defaultProject != null)
            {
                MessageService.PrintDefaultProjectExistMessage();
                return;
            }

            try
            {
                string         displayName     = MessageService.GetDefaultProjectName();
                GoNorthProject projectToCreate = new GoNorthProject
                {
                    Name      = displayName,
                    IsDefault = true
                };
                await projectDbAccess.CreateProject(projectToCreate);

                MessageService.PrintSuccessCreatingDefaultProject();
            }
            catch (Exception ex)
            {
                MessageService.PrintErrorCreatingDefaultProject(ex);
            }
        }
Пример #9
0
        public async Task <IActionResult> GetOpenTaskBoards(int start, int pageSize)
        {
            GoNorthProject project = await _projectDbAccess.GetDefaultProject();

            Task <List <TaskBoard> > queryTask;
            Task <int> countTask;

            queryTask = _taskBoardDbAccess.GetOpenTaskBoards(project.Id, start, pageSize);
            countTask = _taskBoardDbAccess.GetOpenTaskBoardCount(project.Id);
            Task.WaitAll(queryTask, countTask);

            TaskBoardQueryResult queryResult = new TaskBoardQueryResult();

            queryResult.Boards  = queryTask.Result;
            queryResult.HasMore = start + queryResult.Boards.Count < countTask.Result;
            return(Ok(queryResult));
        }
Пример #10
0
        /// <summary>
        /// Index view
        /// </summary>
        /// <returns>View</returns>
        public async Task <IActionResult> Index()
        {
            GoNorthProject defaultProject = await _projectDbAccess.GetDefaultProject();

            IndexViewModel viewModel = new IndexViewModel();

            viewModel.ProjectName = defaultProject != null ? defaultProject.Name : "";

            return(View(viewModel));
        }
Пример #11
0
        /// <summary>
        /// Returns the project
        /// </summary>
        /// <returns>Project</returns>
        public async Task <GoNorthProject> GetDefaultProject()
        {
            if (_project != null)
            {
                return(_project);
            }

            _project = await _projectDbAccess.GetDefaultProject();

            return(_project);
        }
Пример #12
0
        /// <summary>
        /// Adds a timeline event
        /// </summary>
        /// <param name="timelineEvent">Timeline Event</param>
        /// <param name="additionalValues">Additional Values</param>
        /// <returns>Task</returns>
        public async Task AddTimelineEntry(TimelineEvent timelineEvent, params string[] additionalValues)
        {
            Task <GoNorthUser>    currentUserTask = _userManager.GetUserAsync(_httpContext.HttpContext.User);
            Task <GoNorthProject> projectTask     = _projectDbAccess.GetDefaultProject();

            Task.WaitAll(currentUserTask, projectTask);
            GoNorthUser    currentUser = currentUserTask.Result;
            GoNorthProject project     = projectTask.Result;

            TimelineEntry entry = new TimelineEntry();

            entry.ProjectId        = project != null ? project.Id : string.Empty;
            entry.Event            = timelineEvent;
            entry.Timestamp        = DateTimeOffset.UtcNow;
            entry.AdditionalValues = additionalValues;
            entry.Username         = currentUser.UserName;
            entry.UserDisplayName  = currentUser.DisplayName;

            await _timelineDbAccess.CreateTimelineEntry(entry);
        }
Пример #13
0
        /// <summary>
        /// Sets the project ids for tags
        /// </summary>
        /// <returns>Task</returns>
        private async Task SetTagProjectIds()
        {
            GoNorthProject project = await _projectDbAccess.GetDefaultProject();

            if (project == null)
            {
                return;
            }

            await _npcTagDbAccess.SetProjectIdForLegacyTags(project.Id);

            await _itemTagDbAccess.SetProjectIdForLegacyTags(project.Id);

            await _skillTagDbAccess.SetProjectIdForLegacyTags(project.Id);
        }
        public async Task <IActionResult> GetCodeEditorPreferences()
        {
            GoNorthUser currentUser = await _userManager.GetUserAsync(this.User);

            UserPreferences userPreferences = await _userPreferencesDbAccess.GetUserPreferences(currentUser.Id);

            GoNorthProject defaultProject = await _projectDbAccess.GetDefaultProject();

            ExportSettings settings = await _exportSettingsDbAccess.GetExportSettings(defaultProject.Id);

            UserCodeEditorPreferences codeEditorPreferences = new UserCodeEditorPreferences();

            codeEditorPreferences.CodeEditorTheme = userPreferences.CodeEditorTheme;
            codeEditorPreferences.ScriptLanguage  = settings.ScriptLanguage;

            return(Ok(codeEditorPreferences));
        }
Пример #15
0
        /// <summary>
        /// Exports an object
        /// </summary>
        /// <param name="template">Template to use</param>
        /// <param name="objectData">Object data</param>
        /// <returns>Export Result</returns>
        public async Task <ExportObjectResult> ExportObject(ExportTemplate template, ExportObjectData objectData)
        {
            GoNorthProject project = await _projectDbAccess.GetDefaultProject();

            ExportSettings exportSettings = await _exportSettingsDbAccess.GetExportSettings(project.Id);

            ExportObjectResult result = new ExportObjectResult();

            result.FileExtension = exportSettings.ScriptExtension;

            ExportPlaceholderFillResult filledResult = await _placeholderResolver.FillPlaceholders(template.TemplateType, template.Code, objectData);

            result.Code   = filledResult.Code;
            result.Errors = filledResult.Errors.ToErrorList();

            return(result);
        }
Пример #16
0
        /// <summary>
        /// Returns the current user project
        /// </summary>
        /// <returns>Current user project</returns>
        public async Task <GoNorthProject> GetUserProject()
        {
            string userId = _userManager.GetUserId(_httpContext.HttpContext.User);
            UserSelectedProject selectedProject = await _projectDbAccess.GetUserSelectedProject(userId);

            GoNorthProject project = null;

            if (selectedProject != null)
            {
                project = await _projectDbAccess.GetProjectById(selectedProject.ProjectId);
            }

            if (project == null)
            {
                project = await _projectDbAccess.GetDefaultProject();
            }

            return(project);
        }
Пример #17
0
        /// <summary>
        /// Exports an object
        /// </summary>
        /// <param name="template">Template to use</param>
        /// <param name="objectData">Object data</param>
        /// <returns>Export Result</returns>
        public async Task <ExportObjectResult> ExportObject(ExportTemplate template, ExportObjectData objectData)
        {
            // Run script export to refresh language keys
            IFlexFieldExportable flexFieldObject = null;

            if (objectData.ExportData.ContainsKey(ExportConstants.ExportDataObject))
            {
                flexFieldObject = objectData.ExportData[ExportConstants.ExportDataObject] as IFlexFieldExportable;
            }

            if (flexFieldObject != null)
            {
                _languageKeyReferenceCollector.PrepareCollectionForGroup(flexFieldObject.Id);
            }
            else
            {
                _languageKeyReferenceCollector.PrepareCollectionForGroup(null);
            }

            await _scriptExporter.ExportObject(template, objectData);

            objectData.ExportData[ExportConstants.ExportDataReferencedLanguageIds] = _languageKeyReferenceCollector.GetReferencedLanguageKeys();

            // Export language keys
            GoNorthProject project = await _projectDbAccess.GetDefaultProject();

            ExportSettings exportSettings = await _exportSettingsDbAccess.GetExportSettings(project.Id);

            ExportTemplate exportTemplate = await _defaultTemplateProvider.GetDefaultTemplateByType(project.Id, TemplateType.LanguageFile);

            ExportObjectResult result = new ExportObjectResult();

            result.FileExtension = exportSettings.LanguageFileExtension;

            ExportPlaceholderFillResult filledResult = await _placeholderResolver.FillPlaceholders(TemplateType.LanguageFile, exportTemplate.Code, objectData);

            result.Code   = filledResult.Code;
            result.Errors = filledResult.Errors.ToErrorList();

            return(result);
        }
Пример #18
0
        /// <summary>
        /// Exports an object
        /// </summary>
        /// <param name="template">Template to use</param>
        /// <param name="objectData">Object data</param>
        /// <returns>Export Result</returns>
        public async Task <ExportObjectResult> ExportObject(ExportTemplate template, ExportObjectData objectData)
        {
            // Run script export to refresh language keys
            await _scriptExporter.ExportObject(template, objectData);

            // Export language keys
            GoNorthProject project = await _projectDbAccess.GetDefaultProject();

            ExportSettings exportSettings = await _exportSettingsDbAccess.GetExportSettings(project.Id);

            ExportTemplate exportTemplate = await _defaultTemplateProvider.GetDefaultTemplateByType(project.Id, TemplateType.LanguageFile);

            ExportObjectResult result = new ExportObjectResult();

            result.FileExtension = exportSettings.LanguageFileExtension;

            ExportPlaceholderFillResult filledResult = await _placeholderResolver.FillPlaceholders(TemplateType.LanguageFile, exportTemplate.Code, objectData);

            result.Code   = filledResult.Code;
            result.Errors = filledResult.Errors.ToErrorList();

            return(result);
        }
Пример #19
0
        public async Task <IActionResult> GetDefaultTemplatesByCategory(TemplateCategory category)
        {
            GoNorthProject project = await _projectDbAccess.GetDefaultProject();

            List <ExportTemplate> templates = await _defaultTemplateProvider.GetDefaultTemplatesByCategory(project.Id, category);

            return(Ok(templates.Select(t => TranslateTemplateLabel(t)).ToList()));
        }
Пример #20
0
        public async Task <IActionResult> SaveDialog(string relatedObjectId, [FromBody] TaleDialog dialog)
        {
            // Validate data
            if (string.IsNullOrEmpty(relatedObjectId))
            {
                return(StatusCode((int)HttpStatusCode.BadRequest));
            }

            List <KortistoNpc> npcNames = await _npcDbAccess.ResolveFlexFieldObjectNames(new List <string> {
                relatedObjectId
            });

            if (npcNames.Count == 0)
            {
                return(StatusCode((int)HttpStatusCode.BadRequest));
            }
            string npcName = npcNames[0].Name;

            GoNorthProject project = await _projectDbAccess.GetDefaultProject();

            // Update or create dialog
            TaleDialog existingDialog = await _taleDbAccess.GetDialogByRelatedObjectId(relatedObjectId);

            bool isCreate = false;

            if (existingDialog == null)
            {
                existingDialog = new TaleDialog();
                existingDialog.RelatedObjectId = relatedObjectId;
                isCreate = true;
            }

            existingDialog.ProjectId  = project.Id;
            existingDialog.Link       = dialog.Link != null ? dialog.Link : new List <NodeLink>();
            existingDialog.PlayerText = dialog.PlayerText != null ? dialog.PlayerText : new List <TextNode>();
            existingDialog.NpcText    = dialog.NpcText != null ? dialog.NpcText : new List <TextNode>();
            existingDialog.Choice     = dialog.Choice != null ? dialog.Choice : new List <TaleChoiceNode>();
            existingDialog.Action     = dialog.Action != null ? dialog.Action : new List <ActionNode>();
            existingDialog.Condition  = dialog.Condition != null ? dialog.Condition : new List <ConditionNode>();

            await this.SetModifiedData(_userManager, existingDialog);

            // Save Data
            if (isCreate)
            {
                existingDialog = await _taleDbAccess.CreateDialog(existingDialog);

                await _timelineService.AddTimelineEntry(TimelineEvent.TaleDialogCreated, relatedObjectId, npcName);
            }
            else
            {
                // Check implementation state
                if (existingDialog.IsImplemented)
                {
                    CompareResult result = await _implementationStatusComparer.CompareDialog(existingDialog.Id, existingDialog);

                    if (result.CompareDifference != null && result.CompareDifference.Count > 0)
                    {
                        existingDialog.IsImplemented = false;
                    }
                }

                await _taleDbAccess.UpdateDialog(existingDialog);

                await _timelineService.AddTimelineEntry(TimelineEvent.TaleDialogUpdated, relatedObjectId, npcName);
            }

            return(Ok(existingDialog));
        }
Пример #21
0
        /// <summary>
        /// Adds a timeline event
        /// </summary>
        /// <param name="timelineEvent">Timeline Event</param>
        /// <param name="additionalValues">Additional Values</param>
        /// <returns>Task</returns>
        public async Task AddTimelineEntry(TimelineEvent timelineEvent, params string[] additionalValues)
        {
            Task <GoNorthUser>    currentUserTask = _userManager.GetUserAsync(_httpContext.HttpContext.User);
            Task <GoNorthProject> projectTask     = _projectDbAccess.GetDefaultProject();

            Task.WaitAll(currentUserTask, projectTask);
            GoNorthUser    currentUser = currentUserTask.Result;
            GoNorthProject project     = projectTask.Result;

            string updateId = null;

            if (_eventMergeTimeSpan > 0)
            {
                DateTimeOffset       dateLimit       = DateTimeOffset.UtcNow.AddMinutes(-_eventMergeTimeSpan);
                List <TimelineEntry> timelineEntries = await _timelineDbAccess.GetTimelineEntriesByUserInTimeSpan(project.Id, currentUser.UserName, timelineEvent, dateLimit);

                foreach (TimelineEntry curEntry in timelineEntries)
                {
                    if (curEntry.AdditionalValues == null && additionalValues == null)
                    {
                        updateId = curEntry.Id;
                        break;
                    }
                    else if (curEntry.AdditionalValues == null || additionalValues == null)
                    {
                        continue;
                    }

                    if (curEntry.AdditionalValues.Length != additionalValues.Length)
                    {
                        continue;
                    }

                    bool isNotValid = false;
                    for (int curAdditionalValue = 0; curAdditionalValue < additionalValues.Length; ++curAdditionalValue)
                    {
                        if (curEntry.AdditionalValues[curAdditionalValue] != additionalValues[curAdditionalValue])
                        {
                            isNotValid = true;
                            break;
                        }
                    }

                    if (isNotValid)
                    {
                        continue;
                    }

                    updateId = curEntry.Id;
                    break;
                }
            }

            TimelineEntry entry = new TimelineEntry();

            entry.ProjectId        = project != null ? project.Id : string.Empty;
            entry.Event            = timelineEvent;
            entry.Timestamp        = DateTimeOffset.UtcNow;
            entry.AdditionalValues = additionalValues;
            entry.Username         = currentUser.UserName;
            entry.UserDisplayName  = currentUser.DisplayName;

            if (string.IsNullOrEmpty(updateId))
            {
                await _timelineDbAccess.CreateTimelineEntry(entry);
            }
            else
            {
                entry.Id = updateId;
                await _timelineDbAccess.UpdateTimelineEntry(entry);
            }
        }