Exemplo n.º 1
0
        public byte[] Generate(long languageId, UserLanguages userLanguages)
        {
            var allMaterialsQuery = new AllMaterialsQuery(languageId, userLanguages, _forbiddenSectionsChecker);
            Dictionary <SectionId, List <Tuple <long, string, DateTime> > > tupleBySections =
                allMaterialsQuery.GetDataBySections();

            string keyFromContent = GetKeyFromContent(tupleBySections);
            string zipKey         = "AllMaterials" + "_" + keyFromContent + "_" + userLanguages.From.ShortName + "_"
                                    + userLanguages.To.ShortName + ".zip";

            byte[] result = _cache.Get(zipKey);
            if (result != null)
            {
                return(result);
            }

            foreach (var pairBySection in tupleBySections)
            {
                SectionId sectionId  = pairBySection.Key;
                string    folderName = allMaterialsQuery.GetHeader(sectionId);

                foreach (var tuple in pairBySection.Value)
                {
                    DocumentationGenerator generator = GetGenerator(allMaterialsQuery, sectionId, tuple.Item1,
                                                                    tuple.Item2);
                    if (generator == null)
                    {
                        //TODO: логировать и отсылать мне на почту
                        continue;
                    }

                    Stream fileContent = generator.Generate();
                    if (fileContent == null)
                    {
                        //TODO: логировать и отсылать мне на почту
                        continue;
                    }

                    string entryName = folderName + "/" + generator.FileName;
                    _zipCompressor.AddFileToArchive(entryName, fileContent);
                }
            }

            result = _zipCompressor.GetArchive();
            WriteToCache(zipKey, result);
            return(result);
        }
Exemplo n.º 2
0
        private DocumentationGenerator GetGenerator(AllMaterialsQuery allMaterialsQuery,
                                                    SectionId sectionId,
                                                    long id,
                                                    string title)
        {
            DocumentationGenerator result;

            switch (sectionId)
            {
            case SectionId.GroupByWords:
                var groupWordsDownloader = new GroupDataDownloader(_domain, _fontPath)
                {
                    Header      = string.Format("Слова на тему «{0}»", title),
                    TableHeader = "Слово"
                };

                List <SourceWithTranslation> words = allMaterialsQuery.GetWordsByGroup(id);
                result = groupWordsDownloader.Download(DOCUMENT_TYPE, title, words);
                break;

            case SectionId.GroupByPhrases:
                var groupDataDownloader = new GroupDataDownloader(_domain, _fontPath)
                {
                    Header      = string.Format("Фразы на тему «{0}»", title),
                    TableHeader = "Фраза"
                };

                List <SourceWithTranslation> sentences = allMaterialsQuery.GetSentencesByGroup(id);
                result = groupDataDownloader.Download(DOCUMENT_TYPE, title, sentences);
                break;

            case SectionId.VisualDictionary:
                var visualDictionaryDownloader = new VisualDictionaryDownloader(_domain, _fontPath);

                RepresentationForUser representationForUser = allMaterialsQuery.GetVisualDictionary(title);
                result = visualDictionaryDownloader.Download(DOCUMENT_TYPE, title, representationForUser);
                break;

            case SectionId.FillDifference:
                var comparisonDownloader = new ComparisonDownloader(_domain, _fontPath);

                ComparisonForUser comparisonForUser = allMaterialsQuery.GetComparison(title);
                result = comparisonDownloader.Download(DOCUMENT_TYPE, title, comparisonForUser);
                break;

            case SectionId.Video:
                var videoTextDownloader = new VideoTextDownloader(_domain, _fontPath);

                VideoForUser videoForUser = allMaterialsQuery.GetVideo(title);
                result = videoTextDownloader.Download(DOCUMENT_TYPE, title, videoForUser);
                break;

            case SectionId.PopularWord:
                var popularWordsDownloader = new PopularWordsDownloader(_domain, _fontPath)
                {
                    Header = "Минилекс слов Гуннемарка"
                };

                List <SourceWithTranslation> popularWords = allMaterialsQuery.GetPopularWords();
                result = popularWordsDownloader.Download(DOCUMENT_TYPE, title, popularWords);
                break;

            default:
                result = null;
                break;
            }
            return(result);
        }