コード例 #1
0
        private void OnAuthenticationCompleted(object sender, CallCompletedEventArgs <AuthenticationResponse> responseArgs)
        {
            if (responseArgs.Response.IsAuthenticated == true)
            {
                CurrentState = AuthenticationState.Upload;

                InfoMessage = m_uploadingMessage;

                var publishingContest = new Callback <T>();
                publishingContest.CallCompleted += PublishCompleted;
                publishingContest.Progress       = m_progressBar;

                //call the upload handler
                try
                {
                    m_uploadHandler(responseArgs.Response.Ticket, Username, publishingContest);
                }
                catch (InvalidOperationException ex)
                {
                    ErrorMessage = ex.Message;
                }
            }
            else
            {
                //show error
                ErrorMessage = responseArgs.Response.ErrorMessage;
            }
        }
コード例 #2
0
        public void OnCallCompleted(object sender, CallCompletedEventArgs args)
        {
            if (!(sender is PhoneStation) || args == null)
            {
                return;
            }

            Logger.Info($"The call is completed. Duration: {args.CallDuration}s.");

            var price = args.Plan.Calculate(args.CallDuration);

            _entries.Add(new BillingSystemEntry(args.SenderNumber, args.ReceiverNumber, args.CallDuration, price));
        }
コード例 #3
0
ファイル: BenchmarkWizard.cs プロジェクト: thbin/TraceLab
        /// <summary>
        /// Called when [retrieve list of benchmarks call has been completed].
        /// It adds online contests to the list of Benchmarks.
        /// The contests that has been already downloaded and thus were loaded from local directery
        /// get their link to website updated and are marked as the online contests (so that user can compete in them)
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="responseArgs">The <see cref="TraceLab.Core.WebserviceAccess.CallCompletedEventArgs&lt;TraceLab.Core.WebserviceAccess.ListOfContestsResponse&gt;"/> instance containing the event data.</param>
        private void OnRetrieveListOfBenchmarksCallCompleted(object sender, CallCompletedEventArgs <ListOfContestsResponse> responseArgs)
        {
            //local Benchmarks has been loaded already
            var localBenchmarks     = BenchmarkLoader.LoadBenchmarksInfo(BenchmarksDirectory);;
            var newOnlineBenchmarks = new List <Benchmark>();

            if (responseArgs.Response.Status == ResponseStatus.STATUS_SUCCESS)
            {
                List <Contest> contests = responseArgs.Response.ListOfContests;

                foreach (Contest contest in contests)
                {
                    //assuming the joomla com_jtracelab components is used, determine the link to contest website
                    string joomlaSiteRootUrl = m_settings.WebserviceAddress.Substring(0, m_settings.WebserviceAddress.IndexOf("administrator"));
                    string linkToContest     = JoomlaLinks.GetContestWebpageLink(joomlaSiteRootUrl, contest.ContestIndex);

                    //check if there is already local benchmark with the same guid
                    var benchmark = localBenchmarks.Find((b) => { return(b.BenchmarkInfo.Id.Equals(contest.ContestGUID)); });
                    if (benchmark == null)
                    {
                        //if benchmark has not been found create new benchmark (note, its template component is empty at this moment)
                        var newOnlineBenchmark = new Benchmark(contest, linkToContest, BenchmarksDirectory);
                        newOnlineBenchmarks.Add(newOnlineBenchmark);
                    }
                    else
                    {
                        //if found, only update the link to website
                        benchmark.BenchmarkInfo.WebPageLink = new Uri(linkToContest);
                        //mark it as online contest so that wizard now if it should give option to user to publish results
                        benchmark.IsOnlineContest = true;
                    }
                }

                //all new benchmarks add to total list of benchmarks
                localBenchmarks.AddRange(newOnlineBenchmarks);
            }
            else
            {
                //log the error, and continue
                string error = String.Format(Messages.RetrievingListOfContestsFailedWarning, responseArgs.Response.ErrorMessage);
                NLog.LogManager.GetCurrentClassLogger().Warn(error);
                ErrorMessage = error;
            }

            Benchmarks = localBenchmarks;
        }
コード例 #4
0
        /// <summary>
        /// Executed when contest publishing has been completed
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void PublishCompleted(object sender, CallCompletedEventArgs <T> responseArgs)
        {
            if (responseArgs.Response.Status.Equals(ResponseStatus.STATUS_SUCCESS))
            {
                //show some message to user
                InfoMessage = m_uploadCompletedMessage;

                IResponseWithContestLink contestPublishedResponse = responseArgs.Response as IResponseWithContestLink;
                if (contestPublishedResponse != null)
                {
                    if (contestPublishedResponse.ContestWebsiteLink != null)
                    {
                        ContestWebsite = new Uri(contestPublishedResponse.ContestWebsiteLink);
                    }
                }
            }
            else
            {
                //show error message
                InfoMessage  = Messages.PublishFailed;
                ErrorMessage = responseArgs.Response.ErrorMessage;
            }
        }
コード例 #5
0
        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;
            }
        }
コード例 #6
0
        /// <summary>
        /// Called when [retrieve list of benchmarks call has been completed].
        /// It adds online contests to the list of Benchmarks.
        /// The contests that has been already downloaded and thus were loaded from local directery
        /// get their link to website updated and are marked as the online contests (so that user can compete in them)
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="responseArgs">The <see cref="TraceLab.Core.WebserviceAccess.CallCompletedEventArgs&lt;TraceLab.Core.WebserviceAccess.ListOfContestsResponse&gt;"/> instance containing the event data.</param>
        private void OnRetrieveListOfBenchmarksCallCompleted(object sender, CallCompletedEventArgs<ListOfContestsResponse> responseArgs)
        {
            //local Benchmarks has been loaded already
            var localBenchmarks = BenchmarkLoader.LoadBenchmarksInfo(BenchmarksDirectory); ;
            var newOnlineBenchmarks = new List<Benchmark>();

            if (responseArgs.Response.Status == ResponseStatus.STATUS_SUCCESS)
            {
                List<Contest> contests = responseArgs.Response.ListOfContests;

                foreach (Contest contest in contests)
                {
                    //assuming the joomla com_jtracelab components is used, determine the link to contest website
                    string joomlaSiteRootUrl = m_settings.WebserviceAddress.Substring(0, m_settings.WebserviceAddress.IndexOf("administrator"));
                    string linkToContest = JoomlaLinks.GetContestWebpageLink(joomlaSiteRootUrl, contest.ContestIndex);
                    
                    //check if there is already local benchmark with the same guid
                    var benchmark = localBenchmarks.Find((b) => { return b.BenchmarkInfo.Id.Equals(contest.ContestGUID); });
                    if (benchmark == null)
                    {
                        //if benchmark has not been found create new benchmark (note, its template component is empty at this moment)
                        var newOnlineBenchmark = new Benchmark(contest, linkToContest, BenchmarksDirectory);
                        newOnlineBenchmarks.Add(newOnlineBenchmark);
                    }
                    else
                    {
                        //if found, only update the link to website
                        benchmark.BenchmarkInfo.WebPageLink = new Uri(linkToContest);
                        //mark it as online contest so that wizard now if it should give option to user to publish results
                        benchmark.IsOnlineContest = true;
                    }
                }

                //all new benchmarks add to total list of benchmarks
                localBenchmarks.AddRange(newOnlineBenchmarks);
            }
            else
            {
                //log the error, and continue
                string error = String.Format(Messages.RetrievingListOfContestsFailedWarning, responseArgs.Response.ErrorMessage);
                NLog.LogManager.GetCurrentClassLogger().Warn(error);
                ErrorMessage = error;
            }

            Benchmarks = localBenchmarks; 
        }
コード例 #7
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;
            }
        }