コード例 #1
0
ファイル: BenchmarkWizard.cs プロジェクト: thbin/TraceLab
        public void DownloadContestPackage(IProgress progress, Benchmark benchmark)
        {
            var contestPackageResponseCallback = new BenchmarkDownloadCallback(benchmark);

            contestPackageResponseCallback.CallCompleted += OnContestPackageDownloadCompleted;
            contestPackageResponseCallback.Progress       = progress;
            WebService.DownloadContestPackage(benchmark.BenchmarkInfo.Id, contestPackageResponseCallback);
        }
コード例 #2
0
ファイル: BenchmarkWizard.cs プロジェクト: thbin/TraceLab
        internal void OnContestPackageDownloadCompleted(object sender, CallCompletedEventArgs <ContestPackageResponse> responseArgs)
        {
            BenchmarkDownloadCallback callback = sender as BenchmarkDownloadCallback;
            var benchmark = callback.Benchmark;

            if (responseArgs.Response.Status == ResponseStatus.STATUS_SUCCESS)
            {
                //do error handling of file writing and deserialization
                try
                {
                    //save the file to benchmark directory into its filepath
                    File.WriteAllBytes(benchmark.BenchmarkInfo.FilePath, Convert.FromBase64String(responseArgs.Response.ContestPackage));

                    //load benchmark info to update its experiment results unitname
                    string resultsUnitname = BenchmarkLoader.ReadExperimentResultsUnitname(benchmark.BenchmarkInfo.FilePath);
                    if (resultsUnitname != null)
                    {
                        benchmark.BenchmarkInfo.ExperimentResultsUnitname = resultsUnitname;

                        //read the file to determine ComponentTemplate
                        ComponentTemplateMetadata template = BenchmarkLoader.FindTemplateComponentMetadata(benchmark.BenchmarkInfo.FilePath);

                        //set the benchmark
                        if (template != null)
                        {
                            benchmark.ComponentTemplate = template;
                        }
                        else
                        {
                            callback.Progress.Reset();
                            callback.Progress.SetError(true);
                            callback.Progress.CurrentStatus = "Error!";
                            benchmark.ErrorMessage          = Messages.ComponentTemplateNotFoundInContestError;
                        }
                    }
                    else
                    {
                        callback.Progress.Reset();
                        callback.Progress.SetError(true);
                        callback.Progress.CurrentStatus = "Error!";
                        benchmark.ErrorMessage          = Messages.ExperimentResultsUnitnameNotDefined;
                    }
                }
                catch (System.Xml.XmlException)
                {
                    callback.Progress.Reset();
                    callback.Progress.SetError(true);
                    callback.Progress.CurrentStatus = "Error!";
                    benchmark.ErrorMessage          = Messages.ContestFileDeserializationError;
                }
                catch (UnauthorizedAccessException ex)
                {
                    callback.Progress.Reset();
                    callback.Progress.SetError(true);
                    callback.Progress.CurrentStatus = "Error!";
                    benchmark.ErrorMessage          = String.Format(Messages.ContestFileSaveError, ex.Message);
                }
                catch (IOException ex)
                {
                    callback.Progress.Reset();
                    callback.Progress.SetError(true);
                    callback.Progress.CurrentStatus = "Error!";
                    benchmark.ErrorMessage          = String.Format(Messages.ContestFileSaveError, ex.Message);
                }
                catch (System.Security.SecurityException ex)
                {
                    callback.Progress.Reset();
                    callback.Progress.SetError(true);
                    callback.Progress.CurrentStatus = "Error!";
                    benchmark.ErrorMessage          = String.Format(Messages.ContestFileSaveError, ex.Message);
                }
                catch (System.Exception ex)
                {
                    callback.Progress.Reset();
                    callback.Progress.SetError(true);
                    callback.Progress.CurrentStatus = "Error!";
                    benchmark.ErrorMessage          = String.Format(Messages.ContestDownloadError, ex.Message);
                }
            }
            else //response status different than SUCCESS
            {
                //propagate error from the response args
                callback.Progress.Reset();
                callback.Progress.SetError(true);
                callback.Progress.CurrentStatus = "Error!";
                benchmark.ErrorMessage          = responseArgs.Response.ErrorMessage;
            }
        }