Beispiel #1
0
        public virtual int AddRow(Array newRow)
        {
            int row = table.AddRow(newRow);

            myHeader.AddValue("NAXIS2", row, null);
            return(row);
        }
        public DocumentationGenerator Download(DocumentType docType,
                                               string fileName,
                                               VideoForUser video)
        {
            DocumentationGenerator documentGenerator = DocumentationGenerator.Create(_domain, _fontPath, docType, fileName);

            var fields = new List <string> {
                "Отрывок текста"
            };

            if (video.HasAnyTranslation)
            {
                fields.Add("Перевод");
            }
            var tableData = new TableData(fields.Count, false);

            tableData.AddHeader(fields);
            foreach (var sentence in video.Sentences)
            {
                fields = new List <string> {
                    sentence.Item1
                };
                if (video.HasTranslation(sentence))
                {
                    fields.Add(sentence.Item2);
                }
                tableData.AddRow(fields);
            }

            documentGenerator.AddHeader(string.Format("Текст из видео «{0}»", video.Title));
            documentGenerator.AddTable(tableData);

            return(documentGenerator);
        }
        public static TableData LoadDataFromfCSV(string fileName, string delimeter = null, bool hasHeaderRecord = true,
                                                 bool ignoreQuotes = true, int[] columnIndexes = null, int classIndex = -1)
        {
            var configuration = new CsvConfiguration();

            configuration.Delimiter         = delimeter ?? "\t";
            configuration.HasExcelSeparator = false;
            configuration.IgnoreQuotes      = ignoreQuotes;
            configuration.HasHeaderRecord   = hasHeaderRecord;
            configuration.QuoteNoFields     = true;
            using (var reader = new CsvReader(new StreamReader(fileName), configuration))
            {
                var data  = new TableData();
                var index = 0;

                while (reader.Read())
                {
                    if (index == 0)
                    {
                        var noOfAttributes = hasHeaderRecord ? reader.FieldHeaders.Length : reader.CurrentRecord.Length;

                        if (columnIndexes == null)
                        {
                            columnIndexes = new int[noOfAttributes];
                            for (var j = 0; j < columnIndexes.Length; j++)
                            {
                                columnIndexes[j] = j;
                            }
                        }


                        for (int column = 0; column < columnIndexes.Length; column++)
                        {
                            var columnName = column == classIndex
                                ? "Class"
                                : hasHeaderRecord
                                    ? reader.FieldHeaders[columnIndexes[column]]
                                    : "Column" + column;
                            data.AddAttribute(columnName);
                        }

                        index++;
                    }


                    var row        = data.NewRow();
                    var attributes = data.Attributes.ToArray();
                    for (var columnIndex = 0; columnIndex < columnIndexes.Length; columnIndex++)
                    {
                        var columnName = attributes[columnIndex];
                        row[columnName] = reader.GetField(columnIndexes[columnIndex]);
                    }
                    data.AddRow(row);
                }
                return(data);
            }
        }
Beispiel #4
0
        public static TableData LoadDataFromfCSV(string fileName, string delimeter = null, bool hasHeaderRecord = true,
         bool ignoreQuotes = true, int[] columnIndexes = null, int classIndex = -1)
        {
            var configuration = new CsvConfiguration();
            configuration.Delimiter = delimeter ?? "\t";
            configuration.HasExcelSeparator = false;
            configuration.IgnoreQuotes = ignoreQuotes;
            configuration.HasHeaderRecord = hasHeaderRecord;
            configuration.QuoteNoFields = true;
            using (var reader = new CsvReader(new StreamReader(fileName), configuration))
            {

                var data = new TableData();
                var index = 0;

                while (reader.Read())
                {

                    if (index == 0)
                    {
                        var noOfAttributes = hasHeaderRecord ? reader.FieldHeaders.Length : reader.CurrentRecord.Length;

                        if (columnIndexes == null)
                        {
                            columnIndexes = new int[noOfAttributes];
                            for (var j = 0; j < columnIndexes.Length; j++)
                            {
                                columnIndexes[j] = j;
                            }
                        }

                        for (int column = 0; column < columnIndexes.Length; column++)
                        {
                            var columnName = column == classIndex
                                ? "Class"
                                : hasHeaderRecord
                                    ? reader.FieldHeaders[columnIndexes[column]]
                                    : "Column" + column;
                            data.AddAttribute(columnName);
                        }

                        index++;
                    }

                    var row = data.NewRow();
                    var attributes = data.Attributes.ToArray();
                    for (var columnIndex = 0; columnIndex < columnIndexes.Length; columnIndex++)
                    {
                        var columnName = attributes[columnIndex];
                        row[columnName] = reader.GetField(columnIndexes[columnIndex]);
                    }
                    data.AddRow(row);

                }
                return data;
            }
        }
Beispiel #5
0
        public TableData CreateTableData()
        {
            TableData td = new TableData(field);

            //int nrow;
            foreach (DataGridViewRow row in grid.Rows)
            {
                if (row.IsNewRow)
                {
                    continue;
                }

                //nrow = row.Index;
                Row trow = td.AddRow();
                foreach (DataGridViewColumn column in grid.Columns)
                {
                    ColumnProperty   cp   = (ColumnProperty)column.Tag;
                    DataGridViewCell cell = row.Cells[column.Name];
                    if (cell.Value != null)
                    {
                        if (cp.Reference != null)
                        {
                            bool find = false;
                            foreach (ObjectData od in this.database.Objects.GetData(cp.Reference))
                            {
                                if (od.ToString() == cell.Value.ToString())
                                {
                                    //td.AddCell(column.Name, nrow, od);
                                    trow.AddCell(cp, od);
                                    find = true;
                                    break;
                                }
                            }

                            if (!find)
                            {
                                //td.AddCell(column.Name, nrow, string.Empty);
                                trow.AddCell(cp, string.Empty);
                            }
                        }
                        else
                        {
                            //td.AddCell(column.Name, nrow, dgvc.Value);
                            trow.AddCell(cp, cell.Value);
                        }
                    }
                    else
                    {
                        //td.AddCell(column.Name, nrow, string.Empty);
                        trow.AddCell(cp, string.Empty);
                    }
                }
            }

            return(td);
        }
Beispiel #6
0
        public DocumentationGenerator Download(DocumentType docType,
                                               string fileName,
                                               Dictionary <KnowledgeDataType, List <GeneratedKnowledgeItem> >
                                               generatedItems)
        {
            DocumentationGenerator documentGenerator = DocumentationGenerator.Create(_domain, _fontPath, docType,
                                                                                     fileName);

            var tables = new Dictionary <string, TableData>();

            foreach (KnowledgeDataType knowledgeDataType in generatedItems.Keys)
            {
                var tableData = new TableData(2, true);

                string tableHeader = GetTableHeader(knowledgeDataType);
                if (!string.IsNullOrEmpty(tableHeader))
                {
                    tableData.AddHeader(tableHeader, "Перевод");

                    string subHeader = GetHeader(knowledgeDataType);
                    tables.Add(subHeader, tableData);
                }

                List <GeneratedKnowledgeItem> items = generatedItems[knowledgeDataType];
                foreach (GeneratedKnowledgeItem item in items)
                {
                    var sourceTranslation = (SourceWithTranslation)item.ParsedData;
                    tableData.AddRow(sourceTranslation.Source.Text, sourceTranslation.Translation.Text);
                }
            }

            if (string.IsNullOrEmpty(Header))
            {
                Header = "Генератор знаний";
            }

            documentGenerator.AddHeader(Header, false);
            foreach (var pair in tables)
            {
                documentGenerator.AddHeader(pair.Key);
                documentGenerator.AddTable(pair.Value);
            }

            return(documentGenerator);
        }
        public DocumentationGenerator Download(DocumentType docType,
                                               string fileName,
                                               RepresentationForUser representationForUser)
        {
            DocumentationGenerator documentGenerator = DocumentationGenerator.Create(_domain, _fontPath, docType, fileName);

            var tableData = new TableData(2, true);

            tableData.AddHeader("Слово", "Перевод");
            foreach (RepresentationAreaForUser area in representationForUser.Areas)
            {
                tableData.AddRow(area.Source.Text, area.Translation.Text);
            }

            documentGenerator.AddHeader(string.Format("Визуальный словарь на тему «{0}»", representationForUser.Title));
            documentGenerator.AddTable(tableData);

            return(documentGenerator);
        }
Beispiel #8
0
        private static void Test()
        {
            var data = new TableData();

            Random    random  = new Random(321);
            const int rows    = 50;
            const int columns = 3;
            var       matrix  = new int[rows, columns];

            for (int currentColumn = 0; currentColumn < columns; currentColumn++)
            {
                data.AddAttribute("attribute" + (currentColumn + 1));
            }

            for (var currentRow = 0; currentRow < rows; currentRow++)
            {
                var row = data.NewRow();
                for (var currentColumn = 0; currentColumn < columns; currentColumn++)
                {
                    var attribute = "attribute" + (currentColumn + 1);
                    matrix[currentRow, currentColumn] = random.Next();
                    row[attribute] = matrix[currentRow, currentColumn];
                }

                data.AddRow(row);
            }

            for (var currentRow = 0; currentRow < rows; currentRow++)
            {
                for (var currentColumn = 0; currentColumn < columns; currentColumn++)
                {
                    var attribute = "attribute" + (currentColumn + 1);
                    //Convert.ChangeType()
                    //var matrix[currentRow, currentColumn]
                    //data[currentRow][attribute]

                    if (matrix[currentRow, currentColumn] != (int)data[currentRow][attribute])
                    {
                        throw new Exception("InvalidData");
                    }
                }
            }
        }
Beispiel #9
0
        public DocumentationGenerator Download(DocumentType docType,
                                               string fileName,
                                               List <SourceWithTranslation> elemsWithTranslations)
        {
            DocumentationGenerator documentGenerator = DocumentationGenerator.Create(_domain, _fontPath, docType,
                                                                                     fileName);

            var tableData = new TableData(2, true);

            tableData.AddHeader(TableHeader, "Перевод");
            foreach (SourceWithTranslation elem in elemsWithTranslations)
            {
                tableData.AddRow(elem.Source.Text, elem.Translation.Text);
            }

            documentGenerator.AddHeader(Header);
            documentGenerator.AddTable(tableData);

            return(documentGenerator);
        }
Beispiel #10
0
        public DocumentationGenerator Download(DocumentType docType,
                                               string fileName,
                                               List <SourceWithTranslation> words)
        {
            DocumentationGenerator documentGenerator = DocumentationGenerator.Create(_domain, _fontPath, docType, fileName);

            var tableData = new TableData(2, true);

            tableData.AddHeader("Слово", "Перевод");
            foreach (SourceWithTranslation word in words)
            {
                tableData.AddRow(word.Source.Text, word.Translation.Text);
            }

            if (string.IsNullOrEmpty(Header))
            {
                Header = "Минилекс Гуннемарка";
            }

            documentGenerator.AddHeader(Header);
            documentGenerator.AddTable(tableData);

            return(documentGenerator);
        }
Beispiel #11
0
        public static TableData LoadDataFromfCSV(string fileName)
        {
            var configuration = new CsvHelper.Configuration.CsvConfiguration();
            configuration.Delimiter = "\t";
            configuration.HasExcelSeparator = false;
            configuration.IgnoreQuotes = true;
            configuration.QuoteNoFields = true;
            using (var reader = new CsvReader(new StreamReader(fileName), configuration))
            {

                var data = new TableData();
                var index = 0;
                string[] headers = null;

                while (reader.Read())
                {

                    if (index == 0)
                    {
                        headers = reader.FieldHeaders;

                        for (var columnIndex = 0; columnIndex < headers.Length; columnIndex++)
                        {
                            var columnName = headers[columnIndex];
                            data.AddAttribute(columnName);
                        }
                        index++;
                        continue;
                    }

                    var row = data.NewRow();
                    for (var columnIndex = 0; columnIndex < headers.Length; columnIndex++)
                    {
                        var columnName = headers[columnIndex];
                        row[columnName] = reader.GetField(columnIndex);
                    }
                    data.AddRow(row);

                }
                return data;
            }
        }
Beispiel #12
0
        private static void Test()
        {
            var data = new TableData();

            Random random = new Random(321);
            const int rows = 50;
            const int columns = 3;
            var matrix = new int[rows, columns];

            for (int currentColumn = 0; currentColumn < columns; currentColumn++)
            {
                data.AddAttribute("attribute" + (currentColumn + 1));
            }

            for (var currentRow = 0; currentRow < rows; currentRow++)
            {
                var row = data.NewRow();
                for (var currentColumn = 0; currentColumn < columns; currentColumn++)
                {
                    var attribute = "attribute" + (currentColumn + 1);
                    matrix[currentRow, currentColumn] = random.Next();
                    row[attribute] = matrix[currentRow, currentColumn];
                }

                data.AddRow(row);
            }

            for (var currentRow = 0; currentRow < rows; currentRow++)
            {
                for (var currentColumn = 0; currentColumn < columns; currentColumn++)
                {
                    var attribute = "attribute" + (currentColumn + 1);
                    //Convert.ChangeType()
                    //var matrix[currentRow, currentColumn]
                    //data[currentRow][attribute]

                    if (matrix[currentRow, currentColumn] != (int)data[currentRow][attribute])
                    {
                        throw new Exception("InvalidData");
                    }
                }
            }
        }
        public byte[] Generate(LanguageShortName from, LanguageShortName to, HashSet <long> visualDictionariesIds)
        {
            var           languagesQuery       = new LanguagesQuery(from, to);
            UserLanguages userLanguages        = languagesQuery.GetLanguagesByShortNames(from, to);
            var           representationsQuery = new RepresentationsQuery(userLanguages.From.Id);

            List <RepresentationForUser> allRepresentations = representationsQuery.GetBought(userLanguages,
                                                                                             visualDictionariesIds);

            PdfGenerator commonPdfGenerator = allRepresentations.Count > 1
                                                  ? new PdfGenerator(_fontPath, _domain, "Все визуальные словари")
                                                  : null;

            var zipKey = GetZipKey(allRepresentations, @from, to);
            var result = _cache.Get(zipKey);

            if (result != null)
            {
                return(result);
            }

            var painter          = new Painter();
            var partImageCreator = new PartImageCreator(painter);

            foreach (RepresentationForUser representation in allRepresentations)
            {
                var tableData = new TableData(3, true);
                tableData.AddHeader(string.Empty, "Слово", "Перевод");

                string title = representation.Title;

                /*if (pictureName != "Лицо" /*&& pictureName != "Человек"#1#) {
                 *  continue;
                 * }*/

                var   byteStream  = new MemoryStream(representation.Image);
                Image image       = Image.FromStream(byteStream);
                var   wordsWriter = new WordsWriter(painter, image.Width, image.Height);

                foreach (RepresentationAreaForUser area in representation.Areas)
                {
                    Point leftCorner  = area.LeftUpperCorner;
                    Point rightCorner = area.RightBottomCorner;

                    string partKey = representation.Id + "_part_" + area.Id + "_"
                                     + representation.SortInfo.LastModified.Ticks + "_" + from + "_" + to + ".jpeg";
                    byte[] partImageBytes = _cache.Get(partKey);
                    if (partImageBytes == null)
                    {
                        PartImageData partImageData = partImageCreator.CutImage(leftCorner, rightCorner, image);

                        partImageBytes = ImageToBytes(partImageData.Bitmap);
                        WriteToCache(partKey, partImageBytes);
                    }
                    tableData.AddRow(new[] {
                        TableDataCell.CreateImage(partImageBytes), TableDataCell.CreateText(area.Source.Text),
                        TableDataCell.CreateText(area.Translation.Text)
                    });

                    wordsWriter.AddRectangle(leftCorner, rightCorner, area);
                }

                string fullKey = representation.Id + "_" + representation.SortInfo.LastModified.Ticks + "_" + from + "_" + to + ".jpeg";

                byte[] imageResult = _cache.Get(fullKey);
                if (imageResult == null)
                {
                    Image imageWithSign = wordsWriter.GetImageWithSigns(image);
                    imageResult = ImageToBytes(imageWithSign);

                    WriteToCache(fullKey, imageResult);
                }

                var    pdfFileName = title + ".pdf";
                string pdfKey      = representation.Id + "_" + representation.SortInfo.LastModified.Ticks + "_" + from + "_" + to + "_" + pdfFileName;
                byte[] pdfContent  = _cache.Get(pdfKey);

                if (pdfContent == null)
                {
                    var pdfGenerator = new PdfGenerator(_fontPath, _domain, string.Format(
                                                            "Визуальный словарь на тему {0}",
                                                            title));
                    WriteDataToPdf(pdfGenerator, title, imageResult, tableData);
                    pdfContent = pdfGenerator.GetAsBytes();
                    WriteToCache(pdfKey, pdfContent);
                }
                _zipCompressor.AddFileToArchive(pdfFileName, pdfContent);

                if (commonPdfGenerator != null)
                {
                    WriteDataToPdf(commonPdfGenerator, title, imageResult, tableData);
                    commonPdfGenerator.NewPage();
                }
            }
            if (commonPdfGenerator != null)
            {
                WritePdfToArchive(commonPdfGenerator, "Всё в одном файле.pdf");
            }

            result = _zipCompressor.GetArchive();
            WriteToCache(zipKey, result);
            return(result);
        }