/// <inheritdoc cref="AbstractCommand.Execute" />
        public override ServerResponse Execute
        (
            ClientQuery query
        )
        {
            Sure.NotNull(query, nameof(query));

            string database = Record.ThrowIfNull("Record").Database
                              ?? Connection.Database;

            ServerResponse result = base.Execute(query);

            MaxMfn = result.GetReturnCode();

            MarcRecord record = Record.ThrowIfNull("Record");

            record.Database = database;
            record.HostName = Connection.Host;

            if (!DontParseResponse)
            {
                ProtocolText.ParseResponseForWriteRecord
                (
                    result,
                    record
                );
            }

            return(result);
        }
Esempio n. 2
0
        private void _ParseRecord <T>
        (
            [NotNull] string line,
            [NotNull] string database,
            [NotNull] Func <MarcRecord, T> func,
            [NotNull] BlockingCollection <T> collection
        )
        {
            if (!string.IsNullOrEmpty(line))
            {
                MarcRecord record = new MarcRecord
                {
                    HostName = Connection.Host,
                    Database = database
                };

                record = ProtocolText.ParseResponseForAllFormat
                         (
                    line,
                    record
                         );

                if (!ReferenceEquals(record, null))
                {
                    if (!record.Deleted)
                    {
                        T result = func(record);

                        collection.Add(result);
                    }
                }
            }
        }
Esempio n. 3
0
 private void ApplyStandartTemplates(
     ProtocolText protocolTemplate,
     Election election,
     Dictionary <PageSection, List <BasePlainElement> > headers)
 {
     foreach (ProtocolTextLine textLine in protocolTemplate.ProtocolLines)
     {
         var text = new StringBuilder(textLine.Text);
         ApplyStandartTemplatesToLine(election, text);
         if (textLine.Text != null && textLine.Text.IndexOf(MACRO_PROTOCOL_NAME) != -1)
         {
             var lines = election.Protocol.Name.Split('\n');
             if (lines.Length > 1)
             {
                 foreach (var line in lines)
                 {
                     AddLineToList(headers[textLine.Section], textLine, line);
                 }
                 continue;
             }
             text.Replace(MACRO_PROTOCOL_NAME, election.Protocol.Name);
         }
         AddLineToList(headers[textLine.Section], textLine, text.ToString());
     }
 }
Esempio n. 4
0
        public static MarcRecord[] ParseAllFormat
        (
            [NotNull] string database,
            [NotNull] IIrbisConnection connection,
            [NotNull] string[] lines
        )
        {
            Sure.NotNullNorEmpty(database, "database");
            Sure.NotNull(connection, "connection");
            Sure.NotNull(lines, "lines");

            List <MarcRecord> result = new List <MarcRecord>();

            foreach (string line in lines)
            {
                MarcRecord record = new MarcRecord
                {
                    HostName = connection.Host,
                    Database = database
                };
                record = ProtocolText.ParseResponseForAllFormat
                         (
                    line,
                    record
                         );

                // coverity[NULL_RETURNS]
                result.Add(record.ThrowIfNull("record"));
            }

            return(result.ToArray());
        }
        /// <inheritdoc cref="AbstractCommand.Execute" />
        public override ServerResponse Execute
        (
            ClientQuery query
        )
        {
            Sure.NotNull(query, nameof(query));

            ServerResponse result = base.Execute(query);

            result.GetReturnCode();

            // ReSharper disable AssignNullToNotNullAttribute
            // ReSharper disable PossibleNullReferenceException
            // ReSharper disable ForCanBeConvertedToForeach
            for (int i = 0; i < References.Count; i++)
            {
                ProtocolText.ParseResponseForWriteRecords
                (
                    result,
                    References[i].Record
                );

                References[i].Mfn = References[i].Record.Mfn;
            }
            // ReSharper restore ForCanBeConvertedToForeach
            // ReSharper restore PossibleNullReferenceException
            // ReSharper restore AssignNullToNotNullAttribute

            return(result);
        }
Esempio n. 6
0
        public static MarcRecord[] ParseAllFormat
        (
            [NotNull] string database,
            [NotNull] ServerResponse response
        )
        {
            Sure.NotNullNorEmpty(database, "database");
            Sure.NotNull(response, "response");

            List <MarcRecord> result = new List <MarcRecord>();

            while (true)
            {
                MarcRecord record = new MarcRecord
                {
                    HostName = response.Connection.Host,
                    Database = database
                };
                record = ProtocolText.ParseResponseForAllFormat
                         (
                    response,
                    record
                         );
                if (ReferenceEquals(record, null))
                {
                    break;
                }
                result.Add(record);
            }

            return(result.ToArray());
        }
Esempio n. 7
0
        private MarcRecord _ParseRecord
        (
            [CanBeNull] string line
        )
        {
            if (string.IsNullOrEmpty(line))
            {
                return(null);
            }

            MarcRecord result = new MarcRecord
            {
                HostName = Connection.Host,
                Database = Database
            };

            result = ProtocolText.ParseResponseForAllFormat
                     (
                line,
                result
                     );

            if (!ReferenceEquals(result, null))
            {
                if (result.Deleted)
                {
                    return(null);
                }
            }

            return(result);
        }
Esempio n. 8
0
        public void WriteRawRecords_Test1()
        {
            IrbisConnection connection = Connection.ThrowIfNull("Connection");

            MarcRecord[] records =
            {
                _GetRecord(1),
                _GetRecord(2),
                _GetRecord(3)
            };

            string[] rawRecords =
            {
                ProtocolText.EncodeRecord(records[0]),
                ProtocolText.EncodeRecord(records[1]),
                ProtocolText.EncodeRecord(records[2])
            };
            string[] result = connection.WriteRawRecords
                              (
                "IBIS",
                rawRecords,
                false,
                true
                              );

            string text = string.Join
                          (
                Environment.NewLine,
                result
                          );

            Write(text);
        }
Esempio n. 9
0
        private void _ParseRecord
        (
            [NotNull] string line,
            [NotNull] string database
        )
        {
            if (!string.IsNullOrEmpty(line))
            {
                MarcRecord result = new MarcRecord
                {
                    HostName = Connection.Host,
                    Database = database
                };

                result = ProtocolText.ParseResponseForAllFormat
                         (
                    line,
                    result
                         );

                if (!ReferenceEquals(result, null))
                {
                    _ThrowIfEmptyRecord(result, line);

                    if (!result.Deleted)
                    {
                        result.Modified = false;
                        _records.Add(result);
                    }
                }
            }
        }
Esempio n. 10
0
        public static Stream EncodeRecord
        (
            [NotNull] this Stream stream,
            [NotNull] MarcRecord record
        )
        {
            Sure.NotNull(stream, nameof(stream));
            Sure.NotNull(record, nameof(record));

            string text = ProtocolText.EncodeRecord(record);

            byte[] bytes = IrbisEncoding.Utf8.GetBytes(text);
            stream.Write(bytes, 0, bytes.Length);

            return(stream);
        }
Esempio n. 11
0
        public void WriteRawRecord_Test1()
        {
            IrbisConnection connection = Connection.ThrowIfNull("Connection");
            MarcRecord      record     = _GetRecord();

            string rawRecord = ProtocolText.EncodeRecord(record);
            string result    = connection.WriteRawRecord
                               (
                "IBIS",
                rawRecord,
                false,
                true
                               );

            Write(result);
        }
Esempio n. 12
0
        private static void EncodeField
        (
            [NotNull] StringBuilder builder,
            [NotNull] RecordField field
        )
        {
            builder.AppendFormat("{0}#", field.Tag);
            builder.Append(field.Value);

            foreach (SubField subField in field.SubFields)
            {
                ProtocolText.EncodeSubField(builder, subField);
            }

            builder.Append('\x001F');
        }
Esempio n. 13
0
        /// <summary>
        /// <see cref="MarcRecord"/> with database prefix.
        /// </summary>
        public static Stream EncodeRecordReference
        (
            [NotNull] this Stream stream,
            [NotNull] RecordReference reference
        )
        {
            Sure.NotNull(stream, nameof(stream));
            Sure.NotNull(reference, nameof(reference));

            if (string.IsNullOrEmpty(reference.Database))
            {
                Log.Error
                (
                    "IrbisNetworkUtility::EncodeRecordReference: "
                    + "database not specified"
                );

                throw new IrbisException("database not specified");
            }

            if (ReferenceEquals(reference.Record, null))
            {
                Log.Error
                (
                    "IrbisNetworkUtility::EncodeRecordReference: "
                    + "record is null"
                );

                throw new IrbisException("record is null");
            }

            string text = reference.Database
                          + IrbisText.IrbisDelimiter
                          + ProtocolText.EncodeRecord(reference.Record);

            byte[] bytes = IrbisEncoding.Utf8.GetBytes(text);
            stream.Write(bytes, 0, bytes.Length);

            return(stream);
        }
Esempio n. 14
0
        /// <inheritdoc cref="AbstractCommand.Execute"/>
        public override ServerResponse Execute
        (
            ClientQuery query
        )
        {
            Sure.NotNull(query, "query");

            ServerResponse response = base.Execute(query);

            CheckResponse(response);

            string line = response.RequireUtfString();

            Result = Record.ThrowIfNull().Clone();
            ProtocolText.ParseResponseForGblFormat
            (
                line,
                Result
            );

            return(response);
        }
Esempio n. 15
0
        public MarcRecord GetRecord
        (
            [NotNull] MarcRecord record
        )
        {
            Sure.NotNull(record, "record");

            string line = GetUtfString();

            if (string.IsNullOrEmpty(line))
            {
                return(null);
            }

            ProtocolText.ParseResponseForReadRecord
            (
                this,
                record
            );

            return(record);
        }
Esempio n. 16
0
        /// <inheritdoc cref="AbstractCommand.Execute" />
        public override ServerResponse Execute
        (
            ClientQuery query
        )
        {
            ServerResponse result = base.Execute(query);

            // Check whether no records read
            if (result.GetReturnCode() != -201)
            {
                MarcRecord record = new MarcRecord
                {
                    HostName = Connection.Host,
                    Database = Database
                };

                record = ProtocolText.ParseResponseForReadRecord
                         (
                    result,
                    record
                         );
                record.Verify(ThrowOnVerify);

                if (ThrowOnEmptyRecord)
                {
                    IrbisNetworkUtility.ThrowIfEmptyRecord
                    (
                        record,
                        result
                    );
                }

                Record = record;
            }

            return(result);
        }
Esempio n. 17
0
        private MarcRecord _ConvertRecord
        (
            FoundItem item
        )
        {
            MarcRecord result = new MarcRecord
            {
                HostName = Connection.Host,
                Database = Database ?? Connection.Database
            };

            ProtocolText.ParseResponseForAllFormat
            (
                item.Text.ThrowIfNull("item.Text"),
                result
            );
            Debug.Assert
            (
                item.Mfn == result.Mfn,
                "item.Mfn == result.Mfn"
            );

            return(result);
        }
Esempio n. 18
0
        private List <BasePlainElement> CreateProtocolBodyTable(
            ProtocolText protocolTemplate,
            Election election,
            bool final,
            bool printResults)
        {
            int    lineNumber   = election.Protocol.GetLatestLineNumber(final);
            string disabled     = election.Protocol.DisabledString;
            bool   showDisabled = !string.IsNullOrEmpty(disabled);
            bool   delimiter    = false;
            var    table        = new List <BasePlainElement>();

            foreach (var voteLine in protocolTemplate.VoteLines)
            {
                var mask = new VoteKey {
                    ElectionNum = election.ElectionId
                };
                switch (voteLine.Type)
                {
                case VoteLineType.Vote:
                    foreach (Candidate currentCand in election.Candidates)
                    {
                        if ((currentCand.Id == voteLine.ID) && (!currentCand.Disabled || showDisabled))
                        {
                            lineNumber++;
                            mask.CandidateId = currentCand.Id;
                            int votesCount = _votingResultManager.VotingResults.VotesCount(mask);
                            table.Add(new LineClause(
                                          new[]
                            {
                                lineNumber.ToString(),
                                currentCand.GetInitials(!currentCand.NoneAbove),
                                currentCand.Disabled ? disabled : (printResults ? votesCount.ToString() : "0"),
                                currentCand.Disabled ? "" : (printResults
                                        ? "(" + CustomRusNumber.Str(votesCount, true).Trim() + ")"
                                        : CustomRusNumber.Str(0, true).Trim())
                            },
                                          voteLine.FontSize, voteLine.Bold, voteLine.Italic, delimiter));
                            delimiter = false;
                            break;
                        }
                    }
                    break;

                case VoteLineType.Line:
                    if (string.CompareOrdinal(voteLine.ID, VoteTextLine.TOTAL_RECEIVED_VOTETEXTLINE_ID) == 0)
                    {
                        var value = _votingResultManager.VotingResults.VotesCount(
                            new VoteKey(
                                BlankType.AllButBad,
                                null, null, null, null,
                                _electionManager.SourceData.GetBlankIdByElectionNumber(election.ElectionId)));
                        var text = string.IsNullOrEmpty(voteLine.Text)
                                           ? VoteTextLine.TOTAL_RECEIVED_VOTETEXTLINE_DEFAULT_TEXT
                                           : voteLine.Text;
                        table.Add(new LineClause(
                                      new[]
                        {
                            "",
                            text,
                            printResults ? value.ToString() : "0",
                            printResults
                                                      ? "(" + CustomRusNumber.Str(value, true).Trim() + ")"
                                                      : CustomRusNumber.Str(0, true).Trim()
                        },
                                      voteLine.FontSize, voteLine.Bold, voteLine.Italic, delimiter));
                    }
                    else
                    {
                        foreach (Line currentLine in election.Protocol.Lines)
                        {
                            if (currentLine.Id == voteLine.ID)
                            {
                                int value = final && currentLine.Value.HasValue ? currentLine.Value.Value : 0;
                                table.Add(new LineClause(
                                              new[]
                                {
                                    currentLine.Num + currentLine.AdditionalNum,
                                    currentLine.Name,
                                    printResults ? value.ToString() : "0",
                                    printResults
                                                              ? "(" + CustomRusNumber.Str(value, true).Trim() + ")"
                                                              : CustomRusNumber.Str(0, true).Trim()
                                },
                                              voteLine.FontSize, voteLine.Bold, voteLine.Italic, delimiter));
                                break;
                            }
                        }
                    }
                    delimiter = false;
                    break;

                case VoteLineType.Delimiter:
                    delimiter = true;
                    break;
                }
            }
            return(table);
        }
Esempio n. 19
0
        private void ApplySourceDataTemplate(ReportType reportType, ListDictionary reportParameters, ReportTemplate template)
        {
            int fromElection = -1;

            if (reportParameters.Contains(PRN_ELECTION))
            {
                fromElection = _electionManager.SourceData.GetElectionIndex(
                    (Election)reportParameters[PRN_ELECTION]);
            }
            var toElection = fromElection != -1 ?
                             fromElection + 1 : _electionManager.SourceData.Elections.Length;

            fromElection = fromElection == -1 ? 0 : fromElection;
            var tables = new List <BaseTableHolder>();

            for (int i = fromElection; i < toElection; i++)
            {
                var   election    = _electionManager.SourceData.Elections[i];
                Table headerTable = null;
                Table footerTable = null;
                Table bodyTable   = null;
                if (election.Protocol.FontType != FontType.Default)
                {
                    template.Font = election.Protocol.FontType;
                }
                if (election.Protocol.FontSize > 0)
                {
                    template.FontSize = election.Protocol.FontSize;
                }
                ProtocolText protocolTemplate = election.Protocol.GetProtocolTemplate(
                    reportType == ReportType.ElectionProtocol);
                if (protocolTemplate == null)
                {
                    return;
                }
                if (protocolTemplate.ProtocolLines.Length > 0)
                {
                    var headers = new Dictionary <PageSection, List <BasePlainElement> >();
                    foreach (PageSection section in Enum.GetValues(typeof(PageSection)))
                    {
                        headers[section] = new List <BasePlainElement>();
                    }
                    try
                    {
                        ApplyStandartTemplates(protocolTemplate, election, headers);
                        template.PageHeader = new BasePlainElement[headers[PageSection.PageHeader].Count];
                        headers[PageSection.PageHeader].CopyTo(template.PageHeader);
                        if (toElection - fromElection > 1)
                        {
                            template.Header = new BasePlainElement[0];
                            headerTable     = new Table
                            {
                                Columns = new[]
                                {
                                    new ColDefinition
                                    {
                                        Width = 100,
                                        Align = null,
                                    },
                                },
                                Body = headers[PageSection.Header].ToArray(),
                            };
                            template.Footer = new BasePlainElement[0];
                            headers[PageSection.Footer].Add(
                                new LineClause
                            {
                                Columns = new[] { new LinePart {
                                                      Text = ""
                                                  } },
                                NewPage         = true,
                                ResetPageNumber = true
                            });
                            footerTable = new Table
                            {
                                Columns = new[]
                                {
                                    new ColDefinition
                                    {
                                        Width = 100,
                                        Align = null,
                                    },
                                },
                                Body = headers[PageSection.Footer].ToArray(),
                            };
                        }
                        else
                        {
                            template.Header = new BasePlainElement[headers[PageSection.Header].Count];
                            headers[PageSection.Header].CopyTo(template.Header);
                            template.Footer = new BasePlainElement[headers[PageSection.Footer].Count];
                            headers[PageSection.Footer].CopyTo(template.Footer);
                        }
                        template.PageFooter = new BasePlainElement[headers[PageSection.PageFooter].Count];
                        headers[PageSection.PageFooter].CopyTo(template.PageFooter);
                    }
                    catch (Exception ex)
                    {
                        _printingManager.Logger.LogError(Message.PrintingReportHeadersBuildFailed, ex);
                    }
                }
                if (protocolTemplate.VoteLines != null && protocolTemplate.VoteLines.Length > 0)
                {
                    try
                    {
                        bodyTable = new Table
                        {
                            Columns = new[]
                            {
                                new ColDefinition {
                                    Width = election.Protocol.NumberWidth
                                },
                                new ColDefinition {
                                    Width = election.Protocol.NameWidth
                                },
                                new ColDefinition {
                                    Width = election.Protocol.ValueWidth
                                },
                                new ColDefinition {
                                    Width = election.Protocol.TextValueWidth
                                },
                            }
                        };
                        var tableEntry = CreateProtocolBodyTable(
                            protocolTemplate,
                            election,
                            reportType == ReportType.ElectionProtocol,
                            (bool)reportParameters[PRN_PRINT_RESULTS]);
                        bodyTable.Body = tableEntry.ToArray();
                    }
                    catch (Exception ex)
                    {
                        _printingManager.Logger.LogError(Message.PrintingReportBodyBuildFailed, ex);
                    }
                }
                if (headerTable != null)
                {
                    tables.Add(headerTable);
                }
                if (bodyTable != null)
                {
                    tables.Add(bodyTable);
                }
                if (footerTable != null)
                {
                    tables.Add(footerTable);
                }
            }
            template.Body = tables.ToArray();
        }