protected override void CellAnnotation(AnnotationArgs args, AnnotationResult result)
 {
     if (args.FieldName == nameof(LoginUser.PasswordHash) || args.FieldName == nameof(LoginUser.PasswordSalt))
     {
         result.IsPassword = true;
     }
 }
示例#2
0
 public static void Check(string expression, AnnotationResult result)
 {
     Assert.Equal(0, result.DiagnosticResults.Count);
     Assert.Equal(
         expression,
         string.Join("", result.TextChunks.Select(ch => ch.TextValue)));
 }
示例#3
0
 protected override void CellAnnotation(AnnotationArgs args, AnnotationResult result)
 {
     if (args.FieldName == nameof(Feedback.AttachmentFileName))
     {
         result.IsFileUpload = true;
     }
 }
示例#4
0
 protected override void CellAnnotation(AnnotationArgs args, AnnotationResult result)
 {
     if (args.FieldName == nameof(Feedback.AttachmentFileName) && args.Row.AttachmentData != null)
     {
         result.Html = $"<a href='/feedback/{ args.Row.Name }'>{ args.Row.AttachmentFileName }</a>";
     }
 }
 protected override void CellAnnotation(AnnotationArgs args, AnnotationResult result)
 {
     if (args.FieldName == nameof(StorageFileDisplay.FileName))
     {
         result.IsFileUpload = true;
         if (args.Row.IsData != null)
         {
             result.HtmlRight = $"<a href=\"" + "/assets/" + args.Row.FileName + "\">" + "Open" + "</a>";
         }
     }
 }
        public static AnnotationResultSummary Create(AnnotationResult annotationResult, ErrorCategory?errorCategory, string errorMessage)
        {
            string fileName = Path.GetFileName(annotationResult?.filePath);

            return(new AnnotationResultSummary
            {
                ErrorCategory = errorCategory,
                ErrorMessage = errorMessage,
                FileName = fileName
            });
        }
示例#7
0
        private static AnnotationResult HandleException(StringBuilder runLog, AnnotationResult result, Exception e, string snsTopicArn)
        {
            Logger.Log(e);

            result.status        = e.Message;
            result.errorCategory = ExceptionUtilities.ExceptionToErrorCategory(e);
            Logger.WriteLine($"Error Category: {result.errorCategory}");

            if (result.errorCategory != ErrorCategory.UserError)
            {
                string snsMessage = SNS.CreateMessage(runLog.ToString(), result.status, e.StackTrace);
                SNS.SendMessage(snsTopicArn, snsMessage);
            }

            LogUtilities.LogObject("Result", result);
            return(result);
        }
 protected override void CellAnnotationFilterNew(AnnotationFilterNewArgs args, AnnotationResult result)
 {
     if (args.IsNew && args.FieldName == nameof(StorageFileDisplay.FileName))
     {
         result.IsFileUpload = true;
     }
 }
示例#9
0
        // ReSharper disable once UnusedMember.Global
        public AnnotationResult Run(AnnotationConfig config, ILambdaContext context)
        {
            var result = new AnnotationResult {
                id = config.id
            };
            string snsTopicArn = null;
            var    runLog      = new StringBuilder();

            try
            {
                LogUtilities.UpdateLogger(context.Logger, runLog);
                LogUtilities.LogLambdaInfo(context, CommandLineUtilities.InformationalVersion);
                LogUtilities.LogObject("Config", config);
                LogUtilities.Log(new[] { LambdaUrlHelper.UrlBaseEnvironmentVariableName, LambdaUtilities.SnsTopicKey });

                LambdaUtilities.GarbageCollect();
                LambdaUtilities.DeleteTempOutput();

                snsTopicArn = LambdaUtilities.GetEnvironmentVariable(LambdaUtilities.SnsTopicKey);

                string vcfUrl = config.vcfUrl;

                using (var annotationResources = GetAnnotationResources(config))
                {
                    if (annotationResources.InputStartVirtualPosition == -1)
                    {
                        return(GetSuccessOutput(result));
                    }

                    long fileOffset = VirtualPosition.From(annotationResources.InputStartVirtualPosition).FileOffset;

                    using (var preloadVcfStream = PersistentStreamUtils.GetReadStream(vcfUrl, fileOffset))
                    {
                        annotationResources.GetVariantPositions(new BlockGZipStream(preloadVcfStream, CompressionMode.Decompress), config.annotationRange.ToGenomicRange(annotationResources.SequenceProvider.RefNameToChromosome));
                    }

                    Logger.WriteLine("Scan for positions to preload complete.");

                    using (var aes = new AesCryptoServiceProvider())
                    {
                        FileMetadata jsonMetadata, jasixMetadata;
                        string       jsonPath  = Path.GetTempPath() + LambdaUrlHelper.JsonSuffix;
                        string       jasixPath = jsonPath + LambdaUrlHelper.JsonIndexSuffix;

                        using (var inputVcfStream = new BlockGZipStream(PersistentStreamUtils.GetReadStream(vcfUrl, fileOffset), CompressionMode.Decompress))
                            using (var headerStream = config.annotationRange == null ? null : new BlockGZipStream(PersistentStreamUtils.GetReadStream(vcfUrl), CompressionMode.Decompress))
                                //
                                using (var jsonFileStream = FileUtilities.GetCreateStream(jsonPath))
                                    using (var jsonCryptoStream = new CryptoStream(jsonFileStream, aes.CreateEncryptor(), CryptoStreamMode.Write))
                                        using (var jsonMd5Stream = new MD5Stream(jsonCryptoStream))
                                            //
                                            using (var jasixFileStream = FileUtilities.GetCreateStream(jasixPath))
                                                using (var jasixCryptoStream = new CryptoStream(jasixFileStream, aes.CreateEncryptor(), CryptoStreamMode.Write))
                                                    using (var jasixMd5Stream = new MD5Stream(jasixCryptoStream))
                                                    {
                                                        IVcfFilter vcfFilter = config.annotationRange == null
                                ? new NullVcfFilter() as IVcfFilter
                                : new VcfFilter(config.annotationRange.ToGenomicRange(annotationResources.SequenceProvider.RefNameToChromosome));

                                                        using (var jsonCompressStream = new BlockGZipStream(jsonMd5Stream, CompressionMode.Compress))
                                                        {
                                                            StreamAnnotation.Annotate(headerStream, inputVcfStream, jsonCompressStream, jasixMd5Stream, annotationResources, vcfFilter, true);
                                                        }

                                                        Logger.WriteLine("Annotation done.");

                                                        jsonMetadata  = jsonMd5Stream.GetFileMetadata();
                                                        jasixMetadata = jasixMd5Stream.GetFileMetadata();
                                                    }

                        result.filePath = S3Utilities.GetKey(config.outputDir.path, config.outputPrefix + LambdaUrlHelper.JsonSuffix);
                        string jasixKey = result.filePath + LambdaUrlHelper.JsonIndexSuffix;

                        var s3Client = config.outputDir.GetS3Client(context.RemainingTime);
                        s3Client.DecryptUpload(config.outputDir.bucketName, jasixKey, jasixPath, aes, jasixMetadata);
                        s3Client.DecryptUpload(config.outputDir.bucketName, result.filePath, jsonPath, aes, jsonMetadata);

                        Logger.WriteLine("Nirvana result files uploaded.");
                    }
                }

                LambdaUtilities.DeleteTempOutput();
                if (string.IsNullOrEmpty(result.filePath))
                {
                    throw new FileNotFoundException();
                }

                return(GetSuccessOutput(result));
            }
            catch (Exception exception)
            {
                LambdaUtilities.DeleteTempOutput();
                return(HandleException(runLog, result, exception, snsTopicArn));
            }
        }
示例#10
0
 private static AnnotationResult GetSuccessOutput(AnnotationResult result)
 {
     result.status = LambdaUtilities.SuccessMessage;
     LogUtilities.LogObject("Result", result);
     return(result);
 }