Ejemplo n.º 1
0
 // Invoke the ConnectionError event;
 protected virtual void OnConnectionError(ExtendedEventArgs e)
 {
     if (ConnectionError != null)
     {
         ConnectionError(this, e);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Load the requested file/match
        /// </summary>
        /// <returns></returns>
        public async Task Load(String Filename)
        {
            try
            {
                //Load the data
                String XML = await Helpers.LocalStorage.Load(Filename);

                //CompressedXML = "";
                //Deserialize
                TennisMatch StoredMatch = (TennisMatch)Helpers.Serializer.XMLDeserialize(XML, typeof(TennisMatch));

                //Restore references

                //Set it as the current match
                Match = StoredMatch;
                StatisticsCollection.SetSource(_Match);
            }
            catch (Exception)
            {
                ExtendedEventArgs eea = new ExtendedEventArgs();
                eea.Error = "An error occured while loading the stored match";
                OnFatalError(eea);
                //throw new Exception();
            }
        }
Ejemplo n.º 3
0
 // Invoke the ConnectionError event;
 protected virtual void OnFatalError(ExtendedEventArgs e)
 {
     if (FatalError != null)
     {
         FatalError(this, e);
     }
 }
Ejemplo n.º 4
0
 // Invoke the ConnectionError event;
 protected virtual void OnException(ExtendedEventArgs e)
 {
     if (Exception != null)
     {
         Exception(this, e);
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Perform the download of the user its profile picture asynchronously
 /// </summary>
 /// <param name="operation"></param>
 /// <param name="File"></param>
 ///
 private async Task ProcessDownloadProfilePicture(Windows.Networking.BackgroundTransfer.DownloadOperation operation, StorageFile File)
 {
     try
     {
         var   asyncOperation = operation.StartAsync();
         await asyncOperation;
     }
     catch (Exception e)
     {
         ExtendedEventArgs eea = new ExtendedEventArgs();
         eea.Error = String.Format("An error occurred while accessing the profile picture of your Microsoft account: {0}", e.Message);
         OnConnectionError(eea);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Initiate the download of the user its profile picture
        /// </summary>
        public async Task LoadProfilePicture()
        {
            try
            {
                StorageFolder LocalFolder = ApplicationData.Current.LocalFolder;
                StorageFile   File        = await LocalFolder.CreateFileAsync(ID + ".png", CreationCollisionOption.ReplaceExisting);

                var Downloader        = new Windows.Networking.BackgroundTransfer.BackgroundDownloader();
                var DownloadOperation = Downloader.CreateDownload(new Uri(String.Format("https://apis.live.net/v5.0/{0}/picture", ID)), File);
                await ProcessDownloadProfilePicture(DownloadOperation, File);

                NotifyPropertyChanged("ProfilePicture");
            }
            catch (Exception e)
            {
                ExtendedEventArgs eea = new ExtendedEventArgs();
                eea.Error = String.Format("An error occurred while accessing the profile picture of your Microsoft account: {0}", e.Message);
                OnConnectionError(eea);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Process the action/choice of the user
        /// </summary>
        /// <param name="Method"></param>
        public void ProcessAction(string CommandMethod)
        {
            try
            {
                switch (CommandMethod)
                {
                case "CommandTerminate":

                    Match.Terminate();

                    break;

                case "CommandEnd":

                    Match.End(TennisMatch.MatchStatus.Terminated);

                    break;

                case "CommandResign":

                    Match.End(TennisMatch.MatchStatus.Resigned);

                    break;

                case "CommandUndo":

                    if (CurrentPoint == null || CurrentPoint.Point.Winner == 0 && CurrentPoint.Point.Serve != TennisPoint.PointServe.SecondServe)
                    {
                        //Undo the last played point if the current point is not present, or if it has not been played yet.
                        Match.Undo();
                    }

                    NewPoint();

                    break;

                case "CommandSwitchServer":

                    Match.SwitchServer();

                    NewPoint();

                    break;

                case "CommandExtend":

                    Match.Extend();

                    NewPoint();

                    break;

                default:

                    CurrentPoint.ProcessAction(CommandMethod);

                    if (CurrentPoint.PossibleActions.Count <= 1)
                    {
                        //no choices to make; start a new point
                        Match.Add(CurrentPoint.Point);

                        NewPoint();
                    }
                    break;
                }

                NotifyPropertyChanged("CurrentPoint");
                NotifyPropertyChanged("Duration");
                NotifyPropertyChanged("IsExtendPossible");
                NotifyPropertyChanged("SetScores");
                NotifyPropertyChanged("ScorePlayer1");
                NotifyPropertyChanged("ScorePlayer2");
                NotifyPropertyChanged("Server");
                NotifyPropertyChanged("InProgress");
                NotifyPropertyChanged("Winner");
                NotifyPropertyChanged("Completed");
                NotifyPropertyChanged("Undo");
                NotifyPropertyChanged("Sets");
                NotifyPropertyChanged("Switch");
                NotifyPropertyChanged("MatchType");
                NotifyPropertyChanged("Status");

                CurrentSetScore.Notify();
                TotalSets.Notify();
                StatisticsCollection.Notify();
            }
            catch (Exception e)
            {
                ExtendedEventArgs eaa = new ExtendedEventArgs();
                eaa.Error = "A fatal error occurred. Please try again or stop this match to preserve the statistics.";
                #if DEBUG
                eaa.Error = String.Format("A fatal error occurred. {1}:{0}", e.Message, e.Source);
                #endif
                OnFatalError(eaa);
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Propagate the error in the MicrosoftAccount instance
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void _MicrosoftAccount_ConnectionError(object sender, ExtendedEventArgs e)
 {
     Error = e.Error;
     OnException(e);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Propagate the error in the LocalPlayer instance
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void m_Player_ConnectionError(object sender, ExtendedEventArgs e)
 {
     Error = e.Error;
     OnException(e);
 }