private void PopulateCommentTypes() { CommentTypes.Add("General Comment (no reply required)"); CommentTypes.Add("General Comment (reply required)"); CommentTypes.Add("Data Request"); CommentTypes.Add("Data Error"); }
internal CodeProcessingConfiguration(Regex parser, Regex commentExtractor, string compatibleFileExtensions, CommentTypes commentType) { Parser = parser; CommentExtractor = commentExtractor; CompatibleFileExtensions = compatibleFileExtensions; CommentTypes = commentType; }
private void PopulateCommentTypes() { CommentTypes.Add(CommentInfoResource.CommentInfo.GeneralCommentNoReplyRequired); CommentTypes.Add(CommentInfoResource.CommentInfo.GeneralCommentReplyRequired); CommentTypes.Add(CommentInfoResource.CommentInfo.DataRequest); CommentTypes.Add(CommentInfoResource.CommentInfo.DataError); }
private static string CommentTypeToString(CommentTypes argument) { if (argument == CommentTypes.BugReport) { return("bug report"); } return(argument == CommentTypes.Feature ? "feature suggestion" : argument.ToString()); }
private static void ProcessFiles(string[] filePaths) { CommentTypes commentTypes = Settings.GetCommenTypes(); List <string> validatedFilePaths = filePaths.AsEnumerable(). Where(s => String.IsNullOrEmpty(s) == false).ToList(); LogToFile(batchStartedLogMessage); if (validatedFilePaths.Count == 0) { DisplayDialogBoxMessage(noFilesFoundDialogMessage, true); } else if (commentTypes == CommentTypes.None) { DisplayDialogBoxMessage(String.Format(CultureInfo.InvariantCulture, noCommentTypesSelectedDialogMessage, settingsMenuItem), true); } else { //start batch batchFilesCount = validatedFilePaths.Count; batchProcessedFilesCount = 0; List <KeyValuePair <string, string> > filesToWrite = new List <KeyValuePair <string, string> >(); try { filesToWrite = GetModifiedFiles(validatedFilePaths, commentTypes); } catch (Exception) { filesToWrite.Clear(); DisplayDialogBoxMessage(processingEncountredCriticalErrorDialogMessage, true); throw; } finally { WriteFilesToDisk(filesToWrite); LogModifiedFilesList(filesToWrite); EditorUtility.ClearProgressBar(); //end batch batchFilesCount = 0; batchProcessedFilesCount = 0; } } }
public CommentTypes GetCommenTypes() { CommentTypes result = CommentTypes.None; if (ParseSingleLineDocumentationComments) { result = result | CommentTypes.SingleLineDocumentation; } if (ParseDelimitedDocumentationComments) { result = result | CommentTypes.DelimitedDocumentation; } if (ParseSingleLineComments) { result = result | CommentTypes.SingleLine; } return(result); }
/// <summary> /// Returns the files that were modified to add/update tooltips. /// This method doesn't write on disk the modified files /// </summary> /// <param name="filePaths"></param> /// <param name="commentTypes"></param> /// <returns>A list of pairs. The pair's key is the file's path, and the pair's value is the modified file's content</returns> private static List <KeyValuePair <string, string> > GetModifiedFiles(List <string> filePaths, CommentTypes commentTypes) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); List <KeyValuePair <string, string> > modifiedFiles = new List <KeyValuePair <string, string> >(batchFilesCount); bool operationWasCanceled = false; bool exceptionCatched = false; foreach (string filePath in filePaths) { //canceling handling if (DisplayCancelableProgressBar(filePath)) { operationWasCanceled = true; break; } try { String readFileContent = File.ReadAllText(filePath, Encoding.Default); string modifiedFileContent; if (tooltipGenerator.TryProcessText(readFileContent, out modifiedFileContent, commentTypes)) { modifiedFiles.Add(new KeyValuePair <string, string>(filePath, modifiedFileContent)); } } catch (Exception exception) { DisplayConsoleMessage(String.Format(recoverableErrorEncoutredConsoleMessage, filePath), true); DisplayConsoleException(exception); exceptionCatched = true; } finally { batchProcessedFilesCount++; } } if (operationWasCanceled) { modifiedFiles.Clear(); DisplayDialogBoxMessage(processingInteruptedDialogMessage, true); } else { DisplayOperationCompletedMessage(modifiedFiles.Count, stopWatch.Elapsed.TotalSeconds, exceptionCatched); } stopWatch.Stop(); return(modifiedFiles); }
private static string CommentTypeToString(CommentTypes argument) { if (argument == CommentTypes.BugReport) return "bug report"; return argument == CommentTypes.Feature ? "feature suggestion" : argument.ToString(); }
public CommentListViewModel(IODataClient oDataClient, ICommentValidator commentValidator, ISanaapAppTranslateService translateService, IUserDialogs userDialogs, IEventAggregator eventAggregator, ICommentService commentService, IPageDialogService pageDialogService) { _oDataClient = oDataClient; _userDialogs = userDialogs; _commentService = commentService; CommentTypes = EnumHelper <CommentType> .GetDisplayValues(CommentType.Complaint); SelectedCommentType = CommentTypes[1]; CreateComment = new BitDelegateCommand(async() => { submitCancellationTokenSource?.Cancel(); submitCancellationTokenSource = new CancellationTokenSource(); using (userDialogs.Loading(ConstantStrings.Loading, cancelText: ConstantStrings.Loading_Cancel, onCancel: submitCancellationTokenSource.Cancel)) { Comment.CommentType = (CommentType)CommentTypes.IndexOf(SelectedCommentType); if (!commentValidator.IsValid(Comment, out string errorMessage)) { await pageDialogService.DisplayAlertAsync(string.Empty, translateService.Translate(errorMessage), ConstantStrings.Ok); return; } Comment = await commentService.AddAsync(Comment); await pageDialogService.DisplayAlertAsync(string.Empty, ConstantStrings.SuccessfulProcess, ConstantStrings.Ok); Comment = new CommentDto(); eventAggregator.GetEvent <OpenCreateCommentPopupEvent>().Publish(new OpenCreateCommentPopupEvent()); await loadComments(); } }); ShowComment = new BitDelegateCommand <CommentItemSource>(async(comment) => { if (string.IsNullOrEmpty(comment.Answer)) { comment.Answer = ConstantStrings.ResponseNotFoundFromSupport; } await NavigationService.NavigateAsync(nameof(CommentAnswerPopupView), new NavigationParameters { { nameof(Comment), comment } }); }); OpenCreatePopup = new BitDelegateCommand(async() => { eventAggregator.GetEvent <OpenCreateCommentPopupEvent>().Publish(new OpenCreateCommentPopupEvent()); }); }
/// <summary> /// Processes the file's content, and if any tooltip was generated, updates the file. /// </summary> /// <param name="filePath"> The path of the file to update. </param> /// <param name="commentTypes"> The <see cref="CommentTypes"/> to be considered while generating the tooltips. </param> /// <returns> True if the file was updated. </returns> public bool TryProcessFile(string filePath, CommentTypes commentTypes) { return(TryProcessFile(filePath, filePath, Encoding.Default, commentTypes)); }
/// <summary> /// Processes the given text by updating it with tooltips generated from valid comments. /// </summary> /// <param name="textToProcess"> The input text. </param> /// <param name="processedText"> The output text. If method returns false, this text will be equal to <paramref name="textToProcess"/>. </param> /// <param name="commentTypes"> The <see cref="CommentTypes"/> to be considered while generating the tooltips. </param> /// <returns> True if the text was updated.</returns> public Boolean TryProcessText(string textToProcess, out string processedText, CommentTypes commentTypes) { processedText = textToProcess; bool fileWasModified = false; foreach (CodeProcessingConfiguration codeProcessor in codeProcessors) { if ((codeProcessor.CommentTypes & commentTypes) == CommentTypes.None) { continue; } int insertedTextLength = 0; MatchCollection matches = codeProcessor.Parser.Matches(processedText); int matchesCount = matches.Count; for (int matchIndex = 0; matchIndex < matchesCount; matchIndex++) { Match match = matches[matchIndex]; GroupCollection groups = match.Groups; string tooltipContent = BuildTooltipContent(groups["documentation"].Captures, codeProcessor.CommentExtractor); //if existing tooltip is different than the generated one if (tooltipContent != groups["tooltipContent"].ToString()) { tooltipTagBuilder.Append(groups["beginning"]); //tooltip attribute beginning tooltipTagBuilder.Append("[UnityEngine.Tooltip(\""); tooltipTagBuilder.Append(tooltipContent); //tooltip attribute end tooltipTagBuilder.Append("\")]"); tooltipTagBuilder.Append(newLineInGeneratedCode); string tooltip = tooltipTagBuilder.ToString(); tooltipTagBuilder.Length = 0; tooltipTagBuilder.Capacity = 0; //remove possible old tooltip Group oldTooltipGroup = groups["tooltip"]; int oldTolltipLength = oldTooltipGroup.Length; if (oldTolltipLength > 0) { processedText = processedText.Remove(insertedTextLength + oldTooltipGroup.Index, oldTolltipLength); insertedTextLength -= oldTolltipLength; } //insert tooltip in text processedText = processedText.Insert(insertedTextLength + groups["field"].Index, tooltip); insertedTextLength += tooltip.Length; fileWasModified = true; } } } return(fileWasModified); }
/// <summary> /// Processes the input file's content, and if any tooltip was generated, an output file will be created containing the updated content. /// </summary> /// <param name="inputFilePath"> The path of the input file. </param> /// <param name="outputFilePath"> The path of the output file. </param> /// <param name="fileEncoding"> The <see cref="Encoding"/> of the input file and output file. </param> /// <param name="commentTypes"> The <see cref="CommentTypes"/> to be considered while generating the tooltips. </param> /// <returns> True if an output file with updated content was created. </returns> public bool TryProcessFile(string inputFilePath, string outputFilePath, Encoding fileEncoding, CommentTypes commentTypes) { String inputFileContent; using (StreamReader streamReader = new StreamReader(inputFilePath, fileEncoding)) { inputFileContent = streamReader.ReadToEnd(); } string outputFileContent; bool fileWasModified = TryProcessText(inputFileContent, out outputFileContent, commentTypes); if (fileWasModified) { using (StreamWriter writer = new StreamWriter(outputFilePath, false, fileEncoding)) { writer.Write(outputFileContent); } } return(fileWasModified); }
/// <summary> /// Processes the input file's content, and if any tooltip was generated, an output file will be created containing the updated content. /// </summary> /// <param name="inputFilePath"> The path of the input file. </param> /// <param name="outputFilePath"> The path of the output file. </param> /// <param name="commentTypes"> The <see cref="CommentTypes"/> to be considered while generating the tooltips. </param> /// <returns> True if an output file with updated content was created. </returns> public bool TryProcessFile(string inputFilePath, string outputFilePath, CommentTypes commentTypes) { return(TryProcessFile(inputFilePath, outputFilePath, Encoding.Default, commentTypes)); }