コード例 #1
0
        public GameViewModel(CardDeck SelectedDeck)
        {
            _selectedDeck = SelectedDeck;

               Quit = new DelegateCommand(() =>
               {
            #if !SILVERLIGHT
               Application.Current.Shutdown();
            #endif
               });

               Cancel = new DelegateCommand(() =>
               {
            #if !WINDOWS_PHONE
               MainViewModel.Instance.CurrentView = MainViewModel.Instance.Decks;
            #else
               Microsoft.Phone.Controls.PhoneApplicationFrame frame = Application.Current.RootVisual as Microsoft.Phone.Controls.PhoneApplicationFrame;
               frame.GoBack();
            #endif

            #if !SILVERLIGHT
               Taskbar.UpdateTaskBarStatus(0, SelectedDeck.Count / 2);
            #endif
               });

               HelpCommand = new DelegateCommand(() =>
               {
            #if !SILVERLIGHT
               MessageBox.Show((string)Application.Current.FindResource("Resource_MessageBox_ShowHelp"));
            #endif
               });
        }
コード例 #2
0
        public DecksCollection()
        {
            _decks = new ObservableCollection<CardDeck>();

            CreateNewDeck = new DelegateCommand(() =>
            {
                SelectedDeck = new CardDeck() { Title = Title };
                SelectedDeck.CreateNewCardPair.Execute(null);
                MainViewModel.Instance.CurrentView = SelectedDeck;
                Title = "";
                IsNew = false;
            },
            () =>
            {
                return !string.IsNullOrEmpty(Title);
            });
        }
コード例 #3
0
        public LearningGameViewModel(CardDeck SelectedDeck)
            : base(SelectedDeck)
        {
            GameName = (string)Application.Current.Resources["Resource_LearningGame"];

            if (SelectedDeck.Collection.Count > 0)
            {
                SelectedCardPair = SelectedDeck.Collection[0];
                Index = 0;
                if(SelectedDeck.Collection.Count == 1)
                    IsNextEnabled = false;
                else
                    IsNextEnabled = true;
                IsPrevEnabled = false;
            }

            PreviousCommand = new DelegateCommand(() =>
            {
                Index--;

                SelectedCardPair = SelectedDeck.Collection[_index];
            });

            NextCommand = new DelegateCommand(() =>
            {
                Index++;

                SelectedCardPair = SelectedDeck.Collection[_index];
            });

            ResetCards = new DelegateCommand(() =>
            {
                Index = 0;
                SelectedCardPair = SelectedDeck.Collection[_index];
            });
        }
コード例 #4
0
        public ShareViewModel(CardDeck cardDeck)
        {
            CardDeck = cardDeck;

            SenderName = Environment.UserName.ToLower();

            ShareDeck = new DelegateCommand(() =>
                {
                    IsBusy = true;
                    WaitIndicatorText = (string)Application.Current.FindResource("Resource_ShareDialog_UploadingDeck");

                    string password = null;

                    BackgroundWorker worker = new BackgroundWorker();
                    worker.DoWork += (s, e) =>
                        {
                            // start upload to azure
                            IFlashCardService prox = null;

                            try
                            {
                                ChannelFactory<IFlashCardService> chf;
                                chf = new ChannelFactory<IFlashCardService>("FlashCardEP");

                                prox = chf.CreateChannel();

                                // increase uploading timeout to 5 minutes
                                (prox as IContextChannel).OperationTimeout = TimeSpan.FromMinutes(5);

                                var message = prox.UploadFile(new UploadFileContentMessage()
                                {
                                    SenderName = SenderName,
                                    FileByteStream = File.OpenRead(CardDeck.ZipPath)
                                });
                                password = message.Password;
                            }
                            catch (Exception ex)
                            {
                                Utils.LogException(MethodBase.GetCurrentMethod(), ex);
                                OnErrorOccured(ex);
                            }
                            finally
                            {
                                (prox as ICommunicationObject).Close();
                            }
                        };

                    worker.RunWorkerCompleted += (s, e) =>
                        {
                            // don't send mail if user clicked cancel
                            if (_isCanceled)
                            {
                                return;
                            }

                            if (string.IsNullOrEmpty(password))
                            {
                                // report error?
                                return;
                            }

                            // open client mail
                            WaitIndicatorText = (string)Application.Current.FindResource("Resource_ShareDialog_PreparingMail");

                            string silverlightBaseUrl = (string)Application.Current.FindResource("Resource_ShareDialog_SilverlightBaseUrl");
                            string flashCardsSiteUrl = (string)Application.Current.FindResource("Resource_ShareDialog_FlashCardsSiteUrl");

                            string mailSubject = (string)Application.Current.FindResource("Resource_ShareDialog_MailSubject");
                            string mailBody = (string)Application.Current.FindResource("Resource_ShareDialog_MailBody");

                            string param = password + SenderName;
                            param = Utils.Encode(param);

                            string silverlightBaseUrlWithParameters = string.Format(silverlightBaseUrl, param);
                            string mailBodyWithParameters = string.Format(mailBody, silverlightBaseUrlWithParameters, flashCardsSiteUrl, SenderName, password);
                            Utils.SendMail(null, null, null, mailSubject, mailBodyWithParameters);

                            IsBusy = false;
                            DialogResult = true;
                        };

                    worker.RunWorkerAsync();
                });

            CancelUpload = new DelegateCommand(() =>
                {
                    _isCanceled = true;
                    IsBusy = false;
                    DialogResult = true;
                });

            CloseForm = new DelegateCommand(() =>
                {
                    DialogResult = true;
                });
        }
コード例 #5
0
        public ShareViewModel(CardDeck cardDeck)
        {
            CardDeck = cardDeck;

            SenderName = Environment.UserName.ToLower();

            ShareDeck = new DelegateCommand(() =>
            {
                IsBusy            = true;
                WaitIndicatorText = (string)Application.Current.FindResource("Resource_ShareDialog_UploadingDeck");

                string password = null;

                BackgroundWorker worker = new BackgroundWorker();
                worker.DoWork          += (s, e) =>
                {
                    // start upload to azure
                    IFlashCardService prox = null;

                    try
                    {
                        ChannelFactory <IFlashCardService> chf;
                        chf = new ChannelFactory <IFlashCardService>("FlashCardEP");

                        prox = chf.CreateChannel();

                        // increase uploading timeout to 5 minutes
                        (prox as IContextChannel).OperationTimeout = TimeSpan.FromMinutes(5);

                        var message = prox.UploadFile(new UploadFileContentMessage()
                        {
                            SenderName     = SenderName,
                            FileByteStream = File.OpenRead(CardDeck.ZipPath)
                        });
                        password = message.Password;
                    }
                    catch (Exception ex)
                    {
                        Utils.LogException(MethodBase.GetCurrentMethod(), ex);
                        OnErrorOccured(ex);
                    }
                    finally
                    {
                        (prox as ICommunicationObject).Close();
                    }
                };

                worker.RunWorkerCompleted += (s, e) =>
                {
                    // don't send mail if user clicked cancel
                    if (_isCanceled)
                    {
                        return;
                    }

                    if (string.IsNullOrEmpty(password))
                    {
                        // report error?
                        return;
                    }

                    // open client mail
                    WaitIndicatorText = (string)Application.Current.FindResource("Resource_ShareDialog_PreparingMail");

                    string silverlightBaseUrl = (string)Application.Current.FindResource("Resource_ShareDialog_SilverlightBaseUrl");
                    string flashCardsSiteUrl  = (string)Application.Current.FindResource("Resource_ShareDialog_FlashCardsSiteUrl");

                    string mailSubject = (string)Application.Current.FindResource("Resource_ShareDialog_MailSubject");
                    string mailBody    = (string)Application.Current.FindResource("Resource_ShareDialog_MailBody");

                    string param = password + SenderName;
                    param        = Utils.Encode(param);

                    string silverlightBaseUrlWithParameters = string.Format(silverlightBaseUrl, param);
                    string mailBodyWithParameters           = string.Format(mailBody, silverlightBaseUrlWithParameters, flashCardsSiteUrl, SenderName, password);
                    Utils.SendMail(null, null, null, mailSubject, mailBodyWithParameters);

                    IsBusy       = false;
                    DialogResult = true;
                };

                worker.RunWorkerAsync();
            });

            CancelUpload = new DelegateCommand(() =>
            {
                _isCanceled  = true;
                IsBusy       = false;
                DialogResult = true;
            });

            CloseForm = new DelegateCommand(() =>
            {
                DialogResult = true;
            });
        }
コード例 #6
0
        /// <summary>
        /// This holds the logic for unpacking the deck from the .deck package and saving it locally
        /// </summary>
        /// <param name="zipFilename">.deck file path</param>
        /// <param name="newDeckGUID">New deck foldername</param>
        public static string ExtractFromZip(string zipFilename)
        {
            try
            {
                string deckGuid  = string.Empty;
                string deckTitle = string.Empty;
                string outputPath;
                using (Package unZip = System.IO.Packaging.Package.Open(zipFilename, FileMode.Open, FileAccess.Read))
                {
                    Uri         uri       = new Uri("/deck.xml", UriKind.RelativeOrAbsolute);
                    PackagePart xmlPart   = unZip.GetPart(uri);
                    Stream      xmlStream = xmlPart.GetStream(FileMode.Open, FileAccess.Read);

                    XmlSerializer SerializerObj = new XmlSerializer(typeof(CardDeck));
                    CardDeck      cDeck         = (CardDeck)SerializerObj.Deserialize(xmlStream);

                    xmlStream.Close();


                    Uri uriFilesXml = new Uri("/files.xml", UriKind.RelativeOrAbsolute);
                    xmlPart   = unZip.GetPart(uriFilesXml);
                    xmlStream = xmlPart.GetStream(FileMode.Open, FileAccess.Read);

                    SerializerObj = new XmlSerializer(typeof(string[]));
                    string[] fileNames = (string[])SerializerObj.Deserialize(xmlStream);


                    xmlStream.Close();

                    // prepare dictionary
                    Dictionary <string, string> dic = new Dictionary <string, string>();
                    for (int i = 0; i < fileNames.Length; i += 2)
                    {
                        dic[fileNames[i]] = fileNames[i + 1];
                    }



                    deckGuid   = cDeck.DeckGUID;
                    deckTitle  = cDeck.Title;
                    outputPath = Path.Combine(DeckFileHelper.ApplicationTempPath, deckGuid);

                    if (!Directory.Exists(outputPath))
                    {
                        Directory.CreateDirectory(outputPath);
                    }
                    foreach (PackagePart part in unZip.GetParts())
                    {
                        string destFilename = Path.Combine(outputPath, Path.GetFileName(part.Uri.OriginalString));
                        if (dic.ContainsKey(Path.GetFileName(part.Uri.OriginalString)))
                        {
                            destFilename = Path.Combine(outputPath, dic[Path.GetFileName(part.Uri.OriginalString)]);
                        }
                        using (Stream source = part.GetStream(FileMode.Open, FileAccess.Read))
                        {
                            using (Stream dest = File.OpenWrite(destFilename))
                            {
                                Utils.CopyStream(source, dest);
                            }
                        }
                    }
                }

                return(outputPath);
            }
            catch (Exception e)
            {
                Utils.LogException(MethodBase.GetCurrentMethod(), e);
                return(string.Empty);
            }
        }