Ejemplo n.º 1
0
        public static Collection <ExerciseSerie> CreateSeriesForDate(DateTime date)
        {
            if (date.TimeOfDay < new TimeSpan(5, 0, 0))
            {
                date = date.AddDays(-1);
            }

            Collection <ExerciseSerie> result = new Collection <ExerciseSerie>();

            DirectoryInfo mainTempDir = new DirectoryInfo(Config.LogFolder);

            if (mainTempDir.Exists)
            {
                FileInfo[] xmlFiles;

                // Получение файлов для Меркурия.
                xmlFiles = mainTempDir.GetFiles(string.Format("Тренировки за {0}.xml", date.ToString("yyyy-MM-dd") + "*"), SearchOption.TopDirectoryOnly);
                foreach (FileInfo file in xmlFiles)
                {
                    Collection <ExerciseSerie> col = LogExercise.CreateSeriesFromFile(file.FullName);

                    foreach (ExerciseSerie item in col)
                    {
                        result.Add(item);
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        public static Hashtable GetOldTestWords(int wordCount)
        {
            Hashtable result = new Hashtable();

            if (wordCount <= 0)
            {
                return(result);
            }

            DirectoryInfo mainTempDir = new DirectoryInfo(Config.LogFolder);

            if (mainTempDir.Exists)
            {
                FileInfo[] xmlFiles;

                // Получение файлов для Меркурия.
                xmlFiles = mainTempDir.GetFiles(string.Format(LogExercise.searchPattern, "*"), SearchOption.TopDirectoryOnly);

                Collection <KeyValuePair <DateTime, FileInfo> > filesList = new Collection <KeyValuePair <DateTime, FileInfo> >();
                foreach (FileInfo item in xmlFiles)
                {
                    string fileName = Path.GetFileNameWithoutExtension(item.FullName);

                    Regex regex = new Regex(LogExercise.regexLogFileName, RegexOptions.ExplicitCapture);
                    if (regex.IsMatch(fileName))
                    {
                        Match    match = regex.Match(fileName);
                        DateTime date  = new DateTime(Convert.ToInt32(match.Groups["Year"].Value), Convert.ToInt32(match.Groups["Month"].Value), Convert.ToInt32(match.Groups["Day"].Value));

                        filesList.Add(new KeyValuePair <DateTime, FileInfo>(date, item));
                    }
                }

                DateTime[] dates = new DateTime[filesList.Count];
                FileInfo[] files = new FileInfo[filesList.Count];

                for (int i = 0; i < filesList.Count; i++)
                {
                    dates[i] = filesList[i].Key;
                    files[i] = filesList[i].Value;
                }

                Array.Sort(dates, files);

                int fileIndex = files.Length - 1;
                while (fileIndex >= 0)
                {
                    FileInfo file = files[fileIndex];

                    Collection <ExerciseSerie> series = LogExercise.CreateSeriesFromFile(file.FullName);

                    foreach (ExerciseSerie itemSerie in series)
                    {
                        if (itemSerie.Type.Type == TrainType.ConsecutiveAssociations)
                        {
                            foreach (ExerciseAttemptAssociationsСonsecutive item in itemSerie.Attempts)
                            {
                                foreach (AssociationQuestion question in item.Questions)
                                {
                                    if (!result.ContainsKey(question.Question))
                                    {
                                        result.Add(question.Question, null);

                                        if (result.Count == wordCount)
                                        {
                                            return(result);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    fileIndex--;
                }
            }

            return(result);
        }