Exemple #1
0
        public Controller(StagUser stagUser, ScheduleView scheduleView, MainWindow mainWindow)
        {
            Config = new Config();

            this.Client          = new Client(Debug, stagUser);
            this.StudentService  = new StudentService(Debug, Client);
            this.ScheduleService = new ScheduleService(Debug, Client);
            this.TeacherService  = new TeacherService(Debug, Client);

            this.AllServices = new AllServices(StudentService, TeacherService, ScheduleService);

            this.ComonScheduleActionManager  = new ComonScheduleActionManager(Debug, AllServices);
            this.FillerScheduleActionManager = new FillerScheduleActionManager(Debug, AllServices);

            if (Config.LoadedStagUser != null)
            {
                Debug.AddMessage <object>(new Message <object>("Automatically logged in,(using stored user).", MessageTypeEnum.Indifferent));
                Client.StagUser = Config.LoadedStagUser;
            }
            else if (stagUser == null)
            {
                Debug.AddMessage <object>(new Message <object>("Not logged in (yet) => using guest account", MessageTypeEnum.Indifferent));
            }


            this.ScheduleView = scheduleView;
            //InitCustmViews(mainWindow);
            SubscribeEvents();
        }
Exemple #2
0
 public void LoadXmlConfig(out StagUser stagUser)
 {
     if (CheckConfigIntegrity())
     {
         XmlSerializer cvars  = new XmlSerializer(typeof(ConfigVariables));
         XmlReader     reader = XmlReader.Create(ConfigFileName);
         // Just whatever the exception is, the xml file is damaged, user will be asked to remove it.
         try
         {
             ConfigVariables = (ConfigVariables)cvars.Deserialize(reader);
         }
         catch (Exception e)
         {
             MessageBox.Show("Your Config.xml is damaged.\nRemove it.");
             throw;
         }
         stagUser = new StagUser(ConfigVariables.ConfigStagUser.UserName,
                                 ConfigVariables.ConfigStagUser.GetPassword(ConfigVariables.ConfigStagUser.HashedPassword),
                                 ConfigVariables.ConfigStagUser.OsId);
     }
     else
     {
         stagUser = null;
         MessageBox.Show("Your Config.xml is damaged.\nRemove it.");
         App.Current.Dispatcher.Invoke(() =>
         {
             Application.Current.Shutdown();
             Environment.Exit(0);
         });
     }
 }
Exemple #3
0
        public void ReplaceXmlConfig(StagUser stagUser)
        {
            XmlSerializer x      = new XmlSerializer(typeof(ConfigVariables));
            TextWriter    writer = new StreamWriter(ConfigFileName, false);

            x.Serialize(writer, this.ConfigVariables);
            writer.Close();
        }
Exemple #4
0
 /// <summary>
 /// If you create config with existing user, it will automatically load itself.
 /// </summary>
 /// <param name="user"></param>
 public Config()
 {
     if (File.Exists(ConfigFileName) && CheckConfigIntegrity())
     {
         LoadXmlConfig(out StagUser stagUser);
         LoadedStagUser = stagUser;
     }
     ConfigVariables.PropertyChanged += ConfigVariables_PropertyChanged;
 }
Exemple #5
0
        public void CreateAndSaveDefaultXmlConfig(StagUser stagUser, bool append = false)
        {
            XmlSerializer x      = new XmlSerializer(typeof(ConfigVariables));
            TextWriter    writer = new StreamWriter(ConfigFileName, false);

            ConfigVariables = new ConfigVariables();
            ConfigVariables.ConfigStagUser = new ConfigStagUser(stagUser.UserName, stagUser.Password, stagUser.StagOsId);
            x.Serialize(writer, ConfigVariables);
            writer.Close();
        }