Пример #1
0
 /// <summary>
 /// создает новую сессию
 /// </summary>
 public void CreateSession(string planFileName)
 {
     _sessionPath = _startDir + "\\";
     if (!Directory.Exists(_sessionPath))
     {
         Directory.CreateDirectory(_sessionPath);
         _sessionPath += "\\S1";
     }
     else
     {
         var childDirs = new DirectoryInfo(_sessionPath).GetDirectories();
         _sessionPath += "S" + (childDirs.Length + 1).ToString();
     }
     _sessionPath = Helper.CreateDir(_sessionPath);
     _sessionPath += "\\";
     _planPath = _sessionPath + new FileInfo(planFileName).Name;
     File.Copy(planFileName, _planPath);
     _parser = new XParser(_planPath);
     FormDataInitilizer = new Initilizer(_parser);
     _newSession = true;
     #region titlePage
     SessionObjects.TitlePage.University = FormDataInitilizer.GetUniversityName();
     SessionObjects.TitlePage.Qualification = FormDataInitilizer.GetQualification();
     SessionObjects.TitlePage.FormOfTraining = FormDataInitilizer.GetFormOfTraining();
     #endregion
     SearchEngine = new Searcher(_sessionPath);
     ValidatePlan();
     _readyToWork = true;
 }
Пример #2
0
 /// <summary>
 /// загружает сессию
 /// </summary>
 /// <param name="path">путь к папке</param>
 public void LoadSession(string path)
 {
     if (Directory.Exists(path))
     {
         if (path.Contains("\\Resources\\Demo"))
         {
             _demo = true;
         }
         _loading = true;
         _sessionPath = path + "\\";
         var files = new DirectoryInfo(_sessionPath).GetFiles();
         foreach (var file in files)
         {
             var extension = file.FullName.Substring(file.FullName.Length - 7);
             if (extension == "plm.xml" || extension == "pli.xml")
             {
                 _planPath = file.FullName;
                 _parser = new XParser(_planPath);
                 FormDataInitilizer = new Initilizer(_parser);
                 continue;
             }
             var typeName = file.Name.Substring(0, file.Name.Length - 4);
             var type = Type.GetType("DataLibrary." + typeName + ",DataLibrary");
             if (type != null)
             {
                 try
                 {
                     var ob = Activator.CreateInstance(type);
                     ob = SerializeHelper.Deserialize(ob, file.FullName);
                     SessionObjects.SetProperty(type, ob);
                 }
                 catch
                 {
                 }
             }
         }
         _loading = false;
         if (_planPath == String.Empty)
         {
             throw new IOException("В папке с сеансом нет файла с планом. Обновите учебный план." + path);
         }
         UpdateObjects();
         SearchEngine = new Searcher(_sessionPath);
         _readyToWork = true;
         _newSession = false;
     }
     else
     {
         ClearSession();
         throw new IOException("Невозможно найти путь: " + path);
     }
 }
Пример #3
0
        public void ClearSession()
        {
            _readyToWork = false;
            _loading = false;
            _sessionPath = String.Empty;
            _planPath = String.Empty;
            SearchEngine = new Searcher("");
            _newSession = true;
            _newPlan = false;
            _demo = false;

            //вызов метода Clear()
            var sesProperties = SessionObjects.GetType().GetProperties();
            foreach (var p in sesProperties)
            {
                var interfaces = p.PropertyType.GetInterfaces();
                foreach(var i in interfaces)
                {
                    if (i.Name == "IClear")
                    {
                        ((IClear)p.GetValue(SessionObjects, null)).Clear();
                    }
                }
            }
            var addProperties = AdditionalObjects.GetType().GetProperties();
            foreach (var p in addProperties)
            {
                var interfaces = p.PropertyType.GetInterfaces();
                foreach (var i in interfaces)
                {
                    if (i.Name == "IClear")
                    {
                        ((IClear)p.GetValue(AdditionalObjects, null)).Clear();
                    }
                }
            }
        }