コード例 #1
0
 /// <summary>
 /// Create a new session
 /// </summary>
 public MeetingCentreService()
 {
     this.MeetingCentres = new ObservableCollection <MeetingCentre>();
     this.MeetingCentres.CollectionChanged += CentresCollectionChanged;
     this.ServiceChanged          = false;
     MeetingCentreService.Current = this;
     this.LoadFromContext();
 }
コード例 #2
0
 /// <summary>
 /// Create a session from an imported MeetingCentre collection
 /// </summary>
 /// <param name="import"></param>
 public MeetingCentreService(IList <MeetingCentre> import)
 {
     foreach (MeetingCentre centre in import)
     {
         centre.PropertyChanged += CentreChanged;
     }
     this.MeetingCentres = new ObservableCollection <MeetingCentre>(import);
     this.MeetingCentres.CollectionChanged += CentresCollectionChanged;
     this.CentresCollectionChanged(this, new System.Collections.Specialized.NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction.Add, this.MeetingCentres));
     this.ServiceChanged          = false;
     MeetingCentreService.Current = this;
     this.LoadFromContext();
 }
コード例 #3
0
        private async Task _import(string fileName, Models.Data.DocumentFormat format)
        {
            Views.Popups.FileProcessingPopup popup = new Views.Popups.FileProcessingPopup(fileName);
            popup.Show();
            Models.Entities.MeetingCentreService service = await Models.Entities.MeetingCentreService.LoadServiceAsync(fileName, format);

            popup.Close();
            if (service != null)
            {
                ViewModels.CentresViewModel.Context.RefreshService();
                ViewModels.MeetingsViewModel.Context.ResetService();
            }
            else
            {
                MessageBox.Show("The selected file doesn't exist anymore or is not in the correct format.", "Importing file", MessageBoxButton.OK);
            }
        }
コード例 #4
0
        /// <summary cref="MeetingCentreService">
        /// Asynchronously loads a MeetingCentreService
        /// </summary>
        public static async Task <MeetingCentreService> LoadServiceAsync(string loadFrom, Data.DocumentFormat format)
        {
            MeetingCentreService service = null;

            try
            {
                switch (format)
                {
                case Data.DocumentFormat.XML:
                    service = await Data.XmlIO.ParseXmlAsync(loadFrom);

                    service.FilePath = loadFrom;
                    break;

                case Data.DocumentFormat.JSON:
                    service = await Data.JsonIO.ParseJsonAsync(loadFrom);

                    service.FilePath = loadFrom;
                    break;

                case Data.DocumentFormat.CSVStyle:
                    service = new MeetingCentreService(await Data.CsvImporter.ReadFromFileAsync(loadFrom));
                    break;

                default:
                    throw new InvalidEnumArgumentException();
                }
            }
            catch (System.IO.IOException e)
            {
                MessageBox.Show(e.Message, "Failed opening file", MessageBoxButton.OK);
            }
            catch (JsonException e)
            {
                MessageBox.Show(e.Message, "Failed importing JSON file", MessageBoxButton.OK);
            }
            return(service);
        }