예제 #1
0
        public async Task <IEnumerable <ProgramSummary> > GetProgramSummary(List <Program> programs)
        {
            List <ProgramSummary> returnData = new List <ProgramSummary>();

            foreach (Program program in programs)
            {
                ProgramSummary summary;
                try
                {
                    List <Event> events = await this.Events.FindAsync(x => x.ProgramId == program.Id).ConfigureAwait(false);

                    List <EventTelemetrySummary> eventSummaries = events.SelectMany(x => x.TelemetrySummaries).ToList();

                    summary = new ProgramSummary
                    {
                        ProgramName      = program.Name
                        , DeveloperName  = program.DeveloperTeam?.Name ?? "N/A"
                        , TelemetryKey   = program.TelemetryKey
                        , RegisteredDate = program.RegisteredDate
                        , UsersCount     = eventSummaries.DistinctBy(x => x.ClientAppUserId).Count()
                    };
                    ProgramUpdatePackageInfo latestPkg = await this.UpdatePackages.GetLatestPackage(program.Id).ConfigureAwait(false);

                    if (latestPkg != null)
                    {
                        summary.LastUpdateDate = latestPkg.UploadedDate;
                        summary.LatestVersion  = latestPkg.SupportedToolkitVersion ?? "?";
                        summary.ToolkitVersion = latestPkg.SupportedToolkitVersion ?? "?";
                    }
                    else
                    {
                        ProgramPackageInfo programPkg = await this.ProgramPackages.GetLatestProgramPackageInfo(program.Id).ConfigureAwait(false);

                        if (programPkg != null)
                        {
                            summary.LastUpdateDate = programPkg.UploadedDate;
                            summary.LatestVersion  = programPkg.Version;
                            summary.ToolkitVersion = programPkg.SupportedToolkitVersion;
                        }
                        else
                        {
                            summary.LatestVersion  = "N/A";
                            summary.ToolkitVersion = "N/A";
                        }
                    }

                    summary.NumberOfUpdatePackages = await this.UpdatePackages.CountPackages(program.Id).ConfigureAwait(false);
                }
                catch (Exception)
                {
                    summary               = new ProgramSummary();
                    summary.ProgramName   = program?.Name ?? "Error while loading summary";
                    summary.DeveloperName = "Error while loading summary";
                }

                returnData.Add(summary);
            }

            return(returnData);
        }
예제 #2
0
        public async Task <IHttpActionResult> Upload(Guid telemetryKey)
        {
            try
            {
                HttpPostedFile uploadedFile = HttpContext.Current.Request.Files.Count > 0 ? HttpContext.Current.Request.Files[0] : null;
                if (uploadedFile != null && uploadedFile.ContentLength > 0)
                {
                    var program = await this.Work.Programs.FirstOrDefaultAsync(x => x.TelemetryKey == telemetryKey).ConfigureAwait(false);

                    if (program == null)
                    {
                        return(this.BadRequest("Failed to find corresponding program"));
                    }

                    ProgramPackageInfo pkg = await this.Work.ProgramPackages.StorePackageAsync(program, uploadedFile.InputStream, uploadedFile.FileName, this.fileSaver).ConfigureAwait(false);

                    await this.Work.CompleteAsync().ConfigureAwait(false);

                    return(this.Ok(pkg.PublicId));
                }

                return(this.BadRequest("Empty attachment"));
            }
            catch (Exception ex)
            {
                return(this.BadRequest(ex.Message));
            }
        }
예제 #3
0
        public static async Task <IHttpActionResult> GetDownloadLatestProgramPackageResponse(IProgramsUnitOfWork unitOfWork, int programId, IFileRetriever fileRetriever)
        {
            ProgramPackageInfo packageInfo = await unitOfWork.ProgramPackages.GetLatestProgramPackageInfo(programId).ConfigureAwait(false);

            byte[] bytes = await unitOfWork.ProgramPackages.GetPackage(packageInfo.Id, fileRetriever).ConfigureAwait(false);

            HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new ByteArrayContent(bytes)
            };

            result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
            {
                FileName = packageInfo.FileName
            };
            result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");

            return(new ResponseMessageResult(result));
        }
예제 #4
0
        public async Task <IHttpActionResult> Upload(Guid telemetryKey)
        {
            try
            {
                HttpPostedFile uploadedFile = HttpContext.Current.Request.Files.Count > 0 ? HttpContext.Current.Request.Files[0] : null;
                if (uploadedFile != null && uploadedFile.ContentLength > 0)
                {
                    var program = await this.Work.Programs.GetByTelemetryKey(telemetryKey).ConfigureAwait(false);

                    if (program == null)
                    {
                        return(this.BadRequest("Failed to find corresponding program"));
                    }
                    this.telemetryClient.TrackEvent("UploadedPackage", new Dictionary <string, string>()
                    {
                        { $"ProgramName", program.Name },
                        { $"UploadedFileName", uploadedFile?.FileName },
                    });
                    ProgramPackageInfo pkg = await this.Work.ProgramPackages.StorePackageAsync(program, uploadedFile.InputStream, uploadedFile.FileName, this.fileSaver).ConfigureAwait(false);

                    await this.Work.CompleteAsync().ConfigureAwait(false);

                    return(this.Ok(pkg.PublicId));
                }

                return(this.BadRequest("Empty attachment"));
            }
            catch (Exception ex)
            {
                this.telemetryClient.TrackException(ex, new Dictionary <string, string>()
                {
                    { $"Method", Routes.Upload },
                    { $"{nameof(Program.TelemetryKey)}", telemetryKey.ToString() }
                });
                return(this.BadRequest(ex.Message));
            }
        }