Пример #1
0
        public static RecordField ParseLine
        (
            [NotNull] string line
        )
        {
            Sure.NotNullNorEmpty(line, "line");

            StringReader reader = new StringReader(line);

            RecordField result = new RecordField
            {
                Tag   = NumericUtility.ParseInt32(_ReadTo(reader, '#')),
                Value = _ReadTo(reader, '^')
            };

            while (true)
            {
                int next = reader.Read();
                if (next < 0)
                {
                    break;
                }
                char     code     = char.ToLower((char)next);
                string   text     = _ReadTo(reader, '^');
                SubField subField = new SubField
                {
                    Code  = code,
                    Value = text
                };
                result.SubFields.Add(subField);
            }

            return(result);
        }
Пример #2
0
        /// <summary>
        /// Parse server answer.
        /// </summary>
        public static RecordState ParseServerAnswer
        (
            [NotNull] string line
        )
        {
            Sure.NotNullNorEmpty(line, "line");

            //
            // &uf('G0$',&uf('+0'))
            //
            // 0 MFN#STATUS 0#VERSION OTHER
            // 0 161608#0 0#1 101#
            //

            RecordState result = new RecordState();

            string[] parts;

#if WINMOBILE
            parts = line.Split(_delimiters);
#else
            parts = line.Split
                    (
                _delimiters,
                StringSplitOptions.RemoveEmptyEntries
                    );
#endif

            if (parts.Length < 5)
            {
                Log.Error
                (
                    "RecordState::ParseServerAnswer: "
                    + "bad line format: "
                    + line
                );

                throw new IrbisException("bad line format");
            }

            result.Mfn = NumericUtility.ParseInt32(parts[1]);
            result.Status
                           = (RecordStatus)NumericUtility.ParseInt32(parts[2]);
            result.Version = NumericUtility.ParseInt32(parts[4]);

            return(result);
        }
Пример #3
0
        public static MagazineInfo FromRecord
        (
            MarcRecord record
        )
        {
            int marsCode = NumericUtility.ParseInt32(CM.AppSettings["mars-code"]);
            int marsFlag = NumericUtility.ParseInt32(CM.AppSettings["mars-flag"]);

            MagazineInfo result = new MagazineInfo
            {
                Title    = record.FM(200, 'a'),
                Index    = record.FM(903),
                MarsCode = record.FM(marsCode),
                Flag     = record.FM(marsFlag),
                Mfn      = record.Mfn
            };

            return(result);
        }
Пример #4
0
        /// <summary>
        /// Convert string to time.
        /// </summary>
        public static TimeSpan ConvertStringToTime
        (
            [CanBeNull] string time
        )
        {
            if (string.IsNullOrEmpty(time) ||
                time.Length < 4)
            {
                return(new TimeSpan());
            }

            int hours   = NumericUtility.ParseInt32(time.Substring(0, 2));
            int minutes = NumericUtility.ParseInt32(time.Substring(2, 2));
            int seconds = time.Length < 6
                ? 0
                : NumericUtility.ParseInt32(time.Substring(4, 2));
            TimeSpan result = new TimeSpan(hours, minutes, seconds);

            return(result);
        }
Пример #5
0
        public static FileSpecification Parse
        (
            [NotNull] string text
        )
        {
            Sure.NotNullNorEmpty(text, "text");

            TextNavigator navigator  = new TextNavigator(text);
            int           path       = NumericUtility.ParseInt32(navigator.ReadTo("."));
            string        database   = navigator.ReadTo(".").EmptyToNull();
            string        fileName   = navigator.GetRemainingText();
            bool          binaryFile = fileName.StartsWith("@");

            if (binaryFile)
            {
                fileName = fileName.Substring(1);
            }

            string content  = null;
            int    position = fileName.IndexOf("&");

            if (position >= 0)
            {
                content  = fileName.Substring(position + 1);
                fileName = fileName.Substring(0, position);
            }
            FileSpecification result = new FileSpecification
            {
                BinaryFile = binaryFile,
                Path       = (IrbisPath)path,
                Database   = database,
                FileName   = fileName,
                Content    = content
            };


            return(result);
        }
Пример #6
0
        static Form _CreateForm
        (
            string[] commandArgs
        )
        {
            if (commandArgs.Length != 0)
            {
                string   encodingName = commandArgs[0];
                Encoding encoding;

                switch (encodingName)
                {
                case "default":
                case "ansi":
                case "ANSI":
                    encoding = Encoding.Default;
                    break;

                default:
                    if (encodingName.IsPositiveInteger())
                    {
                        int codePage
                                 = NumericUtility.ParseInt32(encodingName);
                        encoding = Encoding.GetEncoding(codePage);
                    }
                    else
                    {
                        encoding = Encoding.GetEncoding(encodingName);
                    }
                    break;
                }

                Console.InputEncoding = encoding;
            }

            string        text   = Console.In.ReadToEnd();
            PlainTextForm result = new PlainTextForm(text)
            {
                Icon = Properties.Resources.Pipe
            };
            ToolStripButton button = new ToolStripButton
                                     (
                "Send to console and close (F2)",
                Properties.Resources.PipeEnd.ToBitmap()
                                     );
            EventHandler handler1 = (sender, args) =>
            {
                string modifiedText = result.Text;
                Console.Out.Write(modifiedText);
                result.Close();
            };

            button.Click += handler1;
            result.Editor.TextBox.KeyDown += (sender, args) =>
            {
                if (args.KeyCode == Keys.F2)
                {
                    handler1(sender, args);
                }
            };
            result.AddButton(button);

            return(result);
        }
Пример #7
0
        static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine
                (
                    "RecordDumper <connection-string> "
                    + "<search-expression> <output-file>"
                );

                return;
            }

            string connectionString = args[0];
            string searchExpression = args[1];
            string outputFileName   = args[2];

            try
            {
                JObject config
                    = JsonUtility.ReadObjectFromFile("dumperConfig.json");
                int   etalonTag   = config["etalonTag"].Value <int>();
                int[] excludeTags = config["excludeTags"]
                                    .Values <int>().ToArray();
                string[] excludePages = config["excludePages"]
                                        .Values <string>().ToArray();

                using (IrbisProvider provider = ProviderManager
                                                .GetAndConfigureProvider(connectionString))
                    using (StreamWriter writer = TextWriterUtility.Create
                                                 (
                               outputFileName,
                               IrbisEncoding.Utf8
                                                 ))
                    {
                        FileSpecification specification = new FileSpecification
                                                          (
                            IrbisPath.MasterFile,
                            provider.Database,
                            "WS31.OPT"
                                                          );
                        IrbisOpt opt = IrbisOpt.LoadFromServer
                                       (
                            provider,
                            specification
                                       );
                        if (ReferenceEquals(opt, null))
                        {
                            throw new IrbisException("Can't load OPT file!");
                        }

                        int[] found = provider.Search(searchExpression);
                        Console.WriteLine("Found: {0}", found.Length);

                        foreach (int mfn in found)
                        {
                            MarcRecord record = provider.ReadRecord(mfn);
                            if (ReferenceEquals(record, null))
                            {
                                continue;
                            }
                            string title = record.FM(etalonTag);
                            if (string.IsNullOrEmpty(title))
                            {
                                continue;
                            }

                            string wsName = opt.SelectWorksheet(opt.GetWorksheet(record));
                            if (string.IsNullOrEmpty(wsName))
                            {
                                continue;
                            }
                            specification = new FileSpecification
                                            (
                                IrbisPath.MasterFile,
                                provider.Database,
                                wsName + ".ws"
                                            );
                            WsFile worksheet = WsFile.ReadFromServer
                                               (
                                provider,
                                specification
                                               );
                            if (ReferenceEquals(worksheet, null))
                            {
                                continue;
                            }

                            Console.WriteLine("MFN={0}: {1}", mfn, title);
                            writer.WriteLine("<h3>{0}</h3>", title);

                            string description = provider.FormatRecord(record, "@");
                            writer.WriteLine(description);

                            RecordField[] fields = record.Fields
                                                   .Where(field => !field.Tag.OneOf(excludeTags))
                                                   .ToArray();

                            writer.WriteLine
                            (
                                "<table border=\"1\" "
                                + "cellpadding=\"3\" "
                                + "cellspacing=\"0\" "
                                + ">"
                            );
                            writer.WriteLine
                            (
                                "<tr bgcolor=\"black\">"
                                + "<th style=\"color:white;text-align:left;\">Поле</th>"
                                + "<th style=\"color:white;text-align:left;\">Подполе</th>"
                                + "<th style=\"color:white;text-align:left;\">Значение</th>"
                                + "</tr>"
                            );
                            foreach (WorksheetPage page in worksheet.Pages)
                            {
                                if (page.Name.OneOf(excludePages))
                                {
                                    continue;
                                }

                                int[] tags = page.Items
                                             .Select(item => item.Tag)
                                             .Select(NumericUtility.ParseInt32)
                                             .ToArray();
                                if (!fields.Any(field => field.Tag.OneOf(tags)))
                                {
                                    continue;
                                }
                                writer.WriteLine
                                (
                                    "<tr><td colspan=\"3\"><b>Вкладка «{0}»</b></td></tr>",
                                    page.Name
                                );

                                foreach (WorksheetItem item in page.Items)
                                {
                                    if (string.IsNullOrEmpty(item.Tag))
                                    {
                                        continue;
                                    }

                                    int tag = NumericUtility.ParseInt32(item.Tag);
                                    if (tag <= 0)
                                    {
                                        continue;
                                    }

                                    RecordField[] itemFields = fields.GetField(tag);
                                    for (int i = 0; i < itemFields.Length; i++)
                                    {
                                        RecordField field = itemFields[i];
                                        title = item.Title;
                                        title = StringUtility.Sparse(title);
                                        if (i != 0)
                                        {
                                            title = string.Format
                                                    (
                                                "(повторение {0})",
                                                i + 1
                                                    );
                                        }
                                        int rowspan = 1;
                                        if (string.IsNullOrEmpty(field.Value))
                                        {
                                            rowspan = 1 + field.SubFields.Count;
                                        }
                                        writer.WriteLine
                                        (
                                            "<tr><td rowspan=\"{0}\" \"width=\"{1}\"><b>{2}</b></td><td colspan=\"2\"><b>{3}</b></td></tr>",
                                            rowspan,
                                            FirstWidth,
                                            field.Tag,
                                            HtmlText.Encode(title)
                                        );

                                        if (!string.IsNullOrEmpty(field.Value))
                                        {
                                            writer.WriteLine
                                            (
                                                "<tr><td colspan=\"2\">&nbsp;</td><td>{0}</td></tr>",
                                                HtmlText.Encode(field.Value)
                                            );
                                        }

                                        if (item.EditMode == "5")
                                        {
                                            string inputInfo = item.InputInfo
                                                               .ThrowIfNull("item.InputInfo");

                                            // Поле с подполями
                                            specification = new FileSpecification
                                                            (
                                                IrbisPath.MasterFile,
                                                provider.Database,
                                                inputInfo
                                                            );
                                            WssFile wss = WssFile.ReadFromServer
                                                          (
                                                provider,
                                                specification
                                                          );
                                            if (ReferenceEquals(wss, null))
                                            {
                                                Console.WriteLine
                                                (
                                                    "Can't load: " + inputInfo
                                                );
                                            }
                                            else
                                            {
                                                foreach (WorksheetItem line in wss.Items)
                                                {
                                                    char     code     = line.Tag.FirstChar();
                                                    SubField subField = field.GetFirstSubField(code);
                                                    if (!ReferenceEquals(subField, null))
                                                    {
                                                        writer.WriteLine
                                                        (
                                                            "<tr>"
                                                            + "<td width=\"{0}\"><b>{1}</b>: {2}</td>"
                                                            + "<td width=\"{3}\">{4}</td></tr>",
                                                            SecondWidth,
                                                            CharUtility.ToUpperInvariant(code),
                                                            HtmlText.Encode(line.Title),
                                                            ThirdWidth,
                                                            HtmlText.Encode(subField.Value)
                                                        );
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            writer.WriteLine("</table>");
                        }
                    }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Пример #8
0
 public void NumericUtility_ParseInt32_1()
 {
     Assert.AreEqual(123, NumericUtility.ParseInt32("123"));
     Assert.AreEqual(123, NumericUtility.ParseInt32("12,3"));
     Assert.AreEqual(123, NumericUtility.ParseInt32("123,"));
 }