コード例 #1
0
        /// <summary>
        /// Break down scriptContent into a combination of StringToken, CommentToken, UnprocessedContentToken and EndOfStatementNewLine instances (the
        /// end of statement tokens will not have been comprehensively handled).  This will never return null nor a set containing any null references.
        /// </summary>
        public static IEnumerable <IToken> SegmentString(string scriptContent)
        {
            if (scriptContent == null)
            {
                throw new ArgumentNullException("scriptContent");
            }

            // Normalise line returns
            scriptContent = scriptContent.Replace("\r\n", "\n").Replace('\r', '\n');

            var index        = 0;
            var tokenContent = "";
            var tokens       = new List <IToken>();
            var lineIndex    = 0;
            var lineIndexForStartOfContent = 0;

            while (index < scriptContent.Length)
            {
                var chr = scriptContent.Substring(index, 1);

                // Check for comment
                bool isComment;
                if (chr == "'")
                {
                    isComment = true;
                }
                else if (index <= (scriptContent.Length - 3))
                {
                    var threeChars = scriptContent.Substring(index, 3);
                    var fourthChar = (index == scriptContent.Length - 3) ? (char?)null : scriptContent[index + 3];
                    if (threeChars.Equals("REM", StringComparison.InvariantCultureIgnoreCase) &&
                        ((fourthChar == null) || _whiteSpaceCharsExceptLineReturn.Contains(fourthChar.Value)))
                    {
                        isComment = true;
                        index    += 2;
                    }
                    else
                    {
                        isComment = false;
                    }
                }
                else
                {
                    isComment = false;
                }
                if (isComment)
                {
                    // Store any previous token content
                    bool isInlineComment;
                    if (tokenContent != "")
                    {
                        // If there has been any one the same line as this comment, then this is an inline comment
                        var contentAfterLastLineReturn = tokenContent.Split('\n').Last();
                        isInlineComment = (contentAfterLastLineReturn.Trim() != "");
                        tokens.Add(new UnprocessedContentToken(tokenContent, lineIndexForStartOfContent));
                        tokenContent = "";
                    }
                    else
                    {
                        isInlineComment = false;
                    }

                    // Move past comment marker and look for end of comment (end of the line) then store in a CommentToken instance
                    // - Note: Always want an EndOfStatementNewLineToken to appear before comments, so ensure this is the case (if the previous token was
                    //   a Comment it doesn't matter, if the previous statement was a String we'll definitely need an end-of-statement, if the previous
                    //   was Unprocessed, we only need end-of-statement if the content didn't end with a line-return)
                    lineIndexForStartOfContent = lineIndex;
                    index++;
                    int breakPoint = scriptContent.IndexOf("\n", index);
                    if (breakPoint == -1)
                    {
                        breakPoint = scriptContent.Length;
                    }
                    if (tokens.Count > 0)
                    {
                        var prevToken = tokens[tokens.Count - 1];
                        if (prevToken is UnprocessedContentToken)
                        {
                            // UnprocessedContentToken MAY conclude with end-of-statement content, we'll need to check
                            if (!prevToken.Content.TrimEnd(_whiteSpaceCharsExceptLineReturn).EndsWith("\n"))
                            {
                                tokens.RemoveAt(tokens.Count - 1);
                                var unprocessedContentToRecord = prevToken.Content.TrimEnd('\t', ' ');
                                if (unprocessedContentToRecord != "")
                                {
                                    tokens.Add(new UnprocessedContentToken(unprocessedContentToRecord, prevToken.LineIndex));
                                    tokens.Add(new EndOfStatementSameLineToken(prevToken.LineIndex));
                                }
                            }
                        }
                    }
                    if (tokens.Any() && ((tokens.Last() is DateLiteralToken) || (tokens.Last() is StringToken)))
                    {
                        // Quoted literals (ie. string or date) CAN'T contain end-of-statement content so we'll definitely need an EndOfStatementNewLineToken
                        // Note: This has to be done after the above work in case there was a literal token then some whitespace (which is removed above)
                        // then a Comment. If the work above wasn't done before this check then "prevToken" would not be a StringToken, it would be the
                        // whitespace - but that would be removed and then the literal would be arranged right next to the Comment, without an end-
                        // of-statement token between them!
                        tokens.Add(new EndOfStatementSameLineToken(lineIndexForStartOfContent));
                    }
                    var commentContent = scriptContent.Substring(index, breakPoint - index);
                    if (isInlineComment)
                    {
                        tokens.Add(new InlineCommentToken(commentContent, lineIndexForStartOfContent));
                    }
                    else
                    {
                        tokens.Add(new CommentToken(commentContent, lineIndexForStartOfContent));
                    }
                    index = breakPoint;
                    lineIndex++;
                    lineIndexForStartOfContent = lineIndex;
                }

                // Check for string content
                else if (chr == "\"")
                {
                    // Store any previous token content
                    if (tokenContent != "")
                    {
                        tokens.Add(new UnprocessedContentToken(tokenContent, lineIndexForStartOfContent));
                        tokenContent = "";
                    }

                    // Try to grab string content
                    lineIndexForStartOfContent = lineIndex;
                    var indexString = index + 1;
                    while (true)
                    {
                        chr = scriptContent.Substring(indexString, 1);
                        if (chr == "\n")
                        {
                            throw new Exception("Encountered line return in string content around line " + (lineIndexForStartOfContent + 1));
                        }
                        if (chr != "\"")
                        {
                            tokenContent += chr;
                        }
                        else
                        {
                            // Quote character - is it doubled (ie. escaped quote)?
                            string chrNext;
                            if (indexString < (scriptContent.Length - 1))
                            {
                                chrNext = scriptContent.Substring(indexString + 1, 1);
                            }
                            else
                            {
                                chrNext = null;
                            }
                            if (chrNext == "\"")
                            {
                                // Escaped quote: push past and add singe chr to content
                                indexString++;
                                tokenContent += "\"";
                            }
                            else
                            {
                                // Non-escaped quote: string end
                                tokens.Add(new StringToken(tokenContent, lineIndexForStartOfContent));
                                tokenContent = "";
                                lineIndexForStartOfContent = lineIndex;
                                index = indexString;
                                break;
                            }
                        }
                        indexString++;
                    }
                }

                // Check for crazy VBScript escaped-name variable content
                // - It's acceptable to name a variable pretty much anything if it's wrapped in square brackets; seems to be any character other than
                //   line returns and a closing square bracket (since there is no support for escaping the closing bracket). This includes single and
                //   double quotes, whitespace, colons, numbers, underscores, anything - in fact a valid variable name is [ ], meaning a single space
                //   wrapped in square brackets! This is a little-known feature but it shouldn't be too hard to parse out at this point.
                else if (chr == "[")
                {
                    // Store any previous token content
                    if (tokenContent != "")
                    {
                        tokens.Add(new UnprocessedContentToken(tokenContent, lineIndexForStartOfContent));
                    }

                    lineIndexForStartOfContent = lineIndex;
                    tokenContent = "[";
                    var indexString = index + 1;
                    while (true)
                    {
                        chr = scriptContent.Substring(indexString, 1);
                        if (chr == "\n")
                        {
                            throw new Exception("Encountered line return in escaped-content variable name");
                        }
                        tokenContent += chr;
                        if (chr == "]")
                        {
                            tokens.Add(AtomToken.GetNewToken(tokenContent, lineIndexForStartOfContent));
                            tokenContent = "";
                            lineIndexForStartOfContent = lineIndex;
                            index = indexString;
                            break;
                        }
                        indexString++;
                    }
                }

                // VBScript supports date literals, wrapped in hashes. These introduce a range of complications - such as literal comparisons requiring
                // special logic, as string and number literals do - eg. ("a" = #2015-5-27#) will fail at runtime as "a" must be parse-able as a date,
                // and it isn't. It also has complications around culture - so the value #1 5 2015# must be parsed as 2015-5-1 in the UK when the
                // translated output is executed but as 2015-1-5 in the US. On top of that, VBScript is very flexible in its acceptance of date formats -
                // amongst these problems is that the year is optional and so #1 5# means 1st of May or 5th of January (depending upon culture) in the
                // current year - however, once a date literal has had a default year set for a given request it must stick to that year; so if the request
                // is unfortunate enough to be slow and cross years, a given date literal must consistently stick to using the year from when the request
                // started. When a new request starts, however, if the year has changed then that new request must default to that new year, it would be no
                // good if the year was determined once (at translation time) and then never changed, since this would be inconsistent with VBScript's behaviour
                // of treating each request as a whole new start-up / serve / tear-down process. This means that the value #29 2# will change by year, being
                // the 29th of February if the current year is a leap year and the 1st of February 2029 if not (since #29 2# will be interpreted as year 29
                // and month 2 since 29 could not be a valid month - and then 29 will be treated as a two-digit year which must be bumped up to 2029). Also
                // note that even in the US #29 2# will be interpreted as the 29th of February (or 1st of February 2029) since there is no way to parse that
                // as a month-then-day format).
                // - Note: This gets the lowest priority in terms of wrapping characters, so [#1 1#] is a variable name and not something containing a
                //   date, likewise "#1 1#" is a string and nothing to do with a date. There are no escape characters. If the wrapped value can not
                //   possibly be valid then an exception will be raised at this point.
                else if (chr == "#")
                {
                    // Store any previous token content
                    if (tokenContent != "")
                    {
                        tokens.Add(new UnprocessedContentToken(tokenContent, lineIndexForStartOfContent));
                    }

                    lineIndexForStartOfContent = lineIndex;
                    tokenContent = "";
                    var indexString = index + 1;
                    while (true)
                    {
                        chr = scriptContent.Substring(indexString, 1);
                        if (chr == "\n")
                        {
                            throw new Exception("Encountered line return in date literal content");
                        }
                        if (chr == "#")
                        {
                            // We can only catch certain kinds of invalid date literal format here since some formats are culture-dependent (eg. "1 May 2010" is
                            // valid in English but not in French) and I don't want to assume that translated programs are running with the same culture as the
                            // translation process. The "limitedDateParser" can catch some invalid formats, which is better than nothing, but others will have
                            // to checked at runtime (see the notes around the instantiation of the limitedDateParser).
                            try
                            {
                                _limitedDateParser.Parse(tokenContent);
                            }
                            catch (Exception e)
                            {
                                throw new ArgumentException("Invalid date literal content encountered on line " + lineIndex + ": #" + tokenContent + "#", e);
                            }
                            tokens.Add(new DateLiteralToken(tokenContent, lineIndexForStartOfContent));
                            tokenContent = "";
                            lineIndexForStartOfContent = lineIndex;
                            index = indexString;
                            break;
                        }
                        else
                        {
                            tokenContent += chr;
                        }
                        indexString++;
                    }
                }

                // Mustn't be neither comment, string, date nor VBScript-escaped-variable-name..
                else
                {
                    tokenContent += chr;
                }

                // Move to next character (if any)..
                index++;
                if (chr == "\n")
                {
                    lineIndex++;
                }
            }

            // Don't let any unhandled content get away!
            if (tokenContent != "")
            {
                tokens.Add(new UnprocessedContentToken(tokenContent, lineIndexForStartOfContent));
            }

            return(tokens);
        }
コード例 #2
0
        public CliParser()
        {
            _product = new Product();
            _license = new License();

            _parser = new FluentCommandLineParser
            {
                IsCaseSensitive = false
            };

            _parser.SetupHelp("?", "help")
            .Callback(text => Console.WriteLine(text));

            _parser.Setup <string>('k', "key")
            .Callback(privatKey =>
            {
                _product.PrivateKey = privatKey;
                _keySet             = true;
            });

            _parser.Setup <string>('p', "key-path")
            .Callback(path => _keyPath = path);

            _parser.Setup <string>('n', "name")
            .Callback(name => _license.OwnerName = name)
            .Required();

            _parser.Setup <string>('i', "id")
            .Callback(s =>
            {
                if (!Guid.TryParse(s, out var guid))
                {
                    Console.WriteLine($"\"{s}\" is not a valid Id!\n" +
                                      "Please use either of these formats for Ids:\n" +
                                      $"\t{Guid.Empty:N}\n" +
                                      $"\t{Guid.Empty:B}\n" +
                                      $"\t{Guid.Empty:D}\n" +
                                      $"\t{Guid.Empty:P}\n" +
                                      $"\t{Guid.Empty:X}\n");

                    throw new Exception();
                }

                _license.ID = guid;
            });

            _parser.Setup <string>('e', "exp")
            .Callback(exp =>
            {
                var dateParser = new DateParser();
                if (!dateParser.Parse(exp, out var date))
                {
                    Console.WriteLine($"\"{exp}\" is not a valid Date!\n" +
                                      "Please use either of these formats for Dates:\n" +
                                      $"{dateParser.Examples}\n");

                    throw new Exception();
                }

                _license.ExpirationDate = date;
            });

            _parser.Setup <LicenseType>('l', "lic")
            .Callback(lic => _license.LicenseType = lic)
            .Required();
        }
コード例 #3
0
        public void Dates_with_years_in_the_middle_cannot_be_parsed(string dateText, DateQualityStatus expectedQuality)
        {
            var dateRange = dateParser.Parse(dateText);

            Assert.Equal(expectedQuality, dateRange.Status);
        }
コード例 #4
0
 public void DateParser_Parse_DateContainsAlphaCharacters_ShouldThrowFormatException()
 {
     DateParser.Parse("18ab02");
 }
コード例 #5
0
        public void DateParser_Parse_DateIs791231_ShouldParseAs2079()
        {
            var result = DateParser.Parse("791231");

            Assert.AreEqual(new DateTime(2079, 12, 31), result);
        }
コード例 #6
0
        private void UpdateFields()
        {
            if (Study == null)
            {
                return;
            }

            var patientName   = new PersonName(Study.PatientsName);
            var physicianName = new PersonName(Study.ReferringPhysiciansName);

            PatientNamePanel.PersonName            = patientName;
            ReferringPhysicianNamePanel.PersonName = physicianName;

            // Patient Information
            if (!string.IsNullOrEmpty(Study.PatientsSex))
            {
                switch (Study.PatientsSex)
                {
                case "M":
                    PatientGender.SelectedIndex = 1;
                    break;

                case "F":
                    PatientGender.SelectedIndex = 2;
                    break;

                case "O":
                    PatientGender.SelectedIndex = 3;
                    break;

                default:
                    PatientGender.SelectedIndex = 0;
                    break;
                }
            }
            else
            {
                PatientGender.SelectedIndex = 0;
            }

            PatientID.Text = Study.PatientId;
            DateTime?birthDate = String.IsNullOrEmpty(Study.PatientsBirthDate)? null:DateParser.Parse(Study.PatientsBirthDate);

            if (birthDate == null)
            {
                PatientBirthDate.Text = String.Empty; // calendar fills in the default date if it's null, we don't want that to happen.
            }
            if (!String.IsNullOrEmpty(Study.PatientsAge))
            {
                PatientAge.Text = Study.PatientsAge.Substring(0, 3).TrimStart('0');
                switch (Study.PatientsAge.Substring(3))
                {
                case "Y":
                    PatientAgePeriod.SelectedIndex = 0;
                    break;

                case "M":
                    PatientAgePeriod.SelectedIndex = 1;
                    break;

                case "W":
                    PatientAgePeriod.SelectedIndex = 2;
                    break;

                default:
                    PatientAgePeriod.SelectedIndex = 3;
                    break;
                }
            }
            else
            {
                PatientAge.Text = string.Empty;
                PatientAgePeriod.SelectedIndex = 0;
            }

            // Study Information
            StudyDescription.Text = Study.StudyDescription;
            StudyID.Text          = Study.StudyId;
            AccessionNumber.Text  = Study.AccessionNumber;

            if (!string.IsNullOrEmpty(Study.StudyDate))
            {
                DateTime?studyDate = DateParser.Parse(Study.StudyDate);
                StudyDateCalendarExtender.SelectedDate = studyDate;
            }
            else
            {
                StudyDateCalendarExtender.SelectedDate = null;
            }


            if (!string.IsNullOrEmpty(Study.StudyTime))
            {
                DateTime?studyTime = TimeParser.Parse(Study.StudyTime);
                if (studyTime != null)
                {
                    StudyTimeHours.Text = String.Format("{0:00}", studyTime.Value.Hour);

                    StudyTimeMinutes.Text = String.Format("{0:00}", studyTime.Value.Minute);
                    StudyTimeSeconds.Text = String.Format("{0:00}", studyTime.Value.Second);
                }
                else
                {
                    // The time is invalid, display it in the boxes
                    StudyTimeHours.Text   = "";
                    StudyTimeMinutes.Text = "";
                    StudyTimeSeconds.Text = "";
                }
            }
            else
            {
                StudyTimeHours.Text   = "00";
                StudyTimeMinutes.Text = "00";
                StudyTimeSeconds.Text = "00";
            }

            ReasonListBox.SelectedIndex = 0;
            if (string.IsNullOrEmpty(ReasonListBox.SelectedValue))
            {
                Comment.Text = string.Empty;
            }
            else
            {
                Comment.Text = SR.CustomReasonComment;
            }
            SaveReasonAsName.Text = string.Empty;

            AttachmentExistWarning.Visible = this.Study.HasAttachment;

            DataBind();
        }
コード例 #7
0
 public void DateParser_Parse_DateIsTooShort_ShouldThrowFormatException()
 {
     DateParser.Parse("1805");
 }
コード例 #8
0
ファイル: SendSeriesTool.cs プロジェクト: bangush/server-1
        private void SendSeriesInternal()
        {
            if (!Enabled || this.Context.SelectedSeries == null)
            {
                return;
            }

            if (SelectedSeries.Any(series => series.ScheduledDeleteTime.HasValue))
            {
                Context.DesktopWindow.ShowMessageBox(SR.MessageCannotSendSeriesScheduledForDeletion, MessageBoxActions.Ok);
                return;
            }

            var serverTreeComponent = new ServerTreeComponent
            {
                IsReadOnly          = true,
                ShowCheckBoxes      = false,
                ShowLocalServerNode = false,
                ShowTitlebar        = false,
                ShowTools           = false
            };

            var dialogContainer = new SimpleComponentContainer(serverTreeComponent);

            ApplicationComponentExitCode code =
                ApplicationComponent.LaunchAsDialog(
                    Context.DesktopWindow,
                    dialogContainer,
                    SR.TitleSendSeries);

            if (code != ApplicationComponentExitCode.Accepted)
            {
                return;
            }

            if (serverTreeComponent.SelectedServers.Count == 0)
            {
                Context.DesktopWindow.ShowMessageBox(SR.MessageSelectDestination, MessageBoxActions.Ok);
                return;
            }

            if (serverTreeComponent.SelectedServers.Count > 1)
            {
                if (Context.DesktopWindow.ShowMessageBox(SR.MessageConfirmSendToMultipleServers, MessageBoxActions.YesNo) == DialogBoxAction.No)
                {
                    return;
                }
            }

            var client     = new DicomSendBridge();
            var seriesUids = Context.SelectedSeries.Select(item => item.SeriesInstanceUid).ToList();

            foreach (var destination in serverTreeComponent.SelectedServers)
            {
                try
                {
                    client.SendSeries(destination, Context.Study, seriesUids.ToArray(), WorkItemPriorityEnum.High);
                    DateTime?studyDate = DateParser.Parse(Context.Study.StudyDate);
                    Context.DesktopWindow.ShowAlert(AlertLevel.Info,
                                                    string.Format(SR.MessageFormatSendSeriesScheduled, seriesUids.Count,
                                                                  destination.Name, Context.Study.PatientsName.FormattedName, studyDate.HasValue ? Format.Date(studyDate.Value) : string.Empty,
                                                                  Context.Study.AccessionNumber),
                                                    SR.LinkOpenActivityMonitor, ActivityMonitorManager.Show, true);
                }
                catch (EndpointNotFoundException)
                {
                    Context.DesktopWindow.ShowMessageBox(SR.MessageSendDicomServerServiceNotRunning,
                                                         MessageBoxActions.Ok);
                }
                catch (Exception e)
                {
                    ExceptionHandler.Report(e, SR.MessageFailedToSendSeries, Context.DesktopWindow);
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// Read data from the specified reader.
        /// </summary>
        /// <param name="reader">CSV reader.</param>
        /// <param name="date">Date.</param>
        /// <returns>Data.</returns>
        protected override Level1ChangeMessage Read(FastCsvReader reader, DateTime date)
        {
            var level1 = new Level1ChangeMessage
            {
                SecurityId = SecurityId,
                ServerTime = ReadTime(reader, date),
            };

            foreach (var field in _level1Fields)
            {
                switch (field)
                {
                case Level1Fields.BestAskTime:
                case Level1Fields.BestBidTime:
                case Level1Fields.LastTradeTime:
                    var dtStr = reader.ReadString();

                    if (dtStr != null)
                    {
                        level1.Changes.Add(field, (DateParser.Parse(dtStr) + TimeParser.Parse(reader.ReadString())).ToDateTimeOffset(TimeSpan.Parse(reader.ReadString().Remove("+"))));
                    }
                    else
                    {
                        reader.Skip(2);
                    }

                    break;

                case Level1Fields.LastTradeId:
                    var id = reader.ReadNullableLong();

                    if (id != null)
                    {
                        level1.Changes.Add(field, id);
                    }

                    break;

                case Level1Fields.AsksCount:
                case Level1Fields.BidsCount:
                case Level1Fields.TradesCount:
                    var count = reader.ReadNullableLong();

                    if (count != null)
                    {
                        level1.Changes.Add(field, count);
                    }

                    break;

                case Level1Fields.LastTradeUpDown:
                case Level1Fields.IsSystem:
                    var flag = reader.ReadNullableBool();

                    if (flag != null)
                    {
                        level1.Changes.Add(field, flag);
                    }

                    break;

                default:
                    var value = reader.ReadNullableDecimal();

                    if (value != null)
                    {
                        level1.Changes.Add(field, value);
                    }

                    break;
                }
            }

            return(level1);
        }
コード例 #10
0
 public void DateParser_Parse_DateIsImpossible_eg189901_ShouldThrowArgumentOutOfRangeException()
 {
     DateParser.Parse("189901");
 }
コード例 #11
0
        public void Dates_can_be_parsed_and_expanded_into_date_ranges(string dateText, DateRangeScope expectedScope)
        {
            var dateRange = dateParser.Parse(dateText);

            Assert.Equal(expectedScope, dateRange.Scope);
        }
コード例 #12
0
 public void DateParser_Parse_DateIsNull_ShouldThrowArgumentNullException()
 {
     DateParser.Parse(null);
 }
コード例 #13
0
ファイル: ZDateTime.cs プロジェクト: jar1karp/.Net-Bridge
        private static ZDateTime Parse(string date, ZTimeZone zone)
        {
            DateParser parser = DateParser.DefaultParser;

            return(parser.Parse(date, zone));
        }
コード例 #14
0
        /// <summary>
        /// Load data from the specified reader.
        /// </summary>
        /// <param name="reader">CSV reader.</param>
        /// <param name="date">Date.</param>
        /// <returns>Data.</returns>
        protected override ExecutionMessage Read(FastCsvReader reader, DateTime date)
        {
            var msg = new ExecutionMessage
            {
                SecurityId            = SecurityId,
                ExecutionType         = ExecutionTypes.Transaction,
                ServerTime            = ReadTime(reader, date),
                TransactionId         = reader.ReadLong(),
                OriginalTransactionId = reader.ReadLong(),
                OrderId              = reader.ReadNullableLong(),
                OrderStringId        = reader.ReadString(),
                OrderBoardId         = reader.ReadString(),
                UserOrderId          = reader.ReadString(),
                OrderPrice           = reader.ReadDecimal(),
                OrderVolume          = reader.ReadNullableDecimal(),
                Balance              = reader.ReadNullableDecimal(),
                VisibleVolume        = reader.ReadNullableDecimal(),
                Side                 = reader.ReadEnum <Sides>(),
                OriginSide           = reader.ReadNullableEnum <Sides>(),
                OrderState           = reader.ReadNullableEnum <OrderStates>(),
                OrderType            = reader.ReadNullableEnum <OrderTypes>(),
                TimeInForce          = reader.ReadNullableEnum <TimeInForce>(),
                TradeId              = reader.ReadNullableLong(),
                TradeStringId        = reader.ReadString(),
                TradePrice           = reader.ReadNullableDecimal(),
                TradeVolume          = reader.ReadNullableDecimal(),
                PortfolioName        = reader.ReadString(),
                ClientCode           = reader.ReadString(),
                BrokerCode           = reader.ReadString(),
                DepoName             = reader.ReadString(),
                IsSystem             = reader.ReadNullableBool(),
                HasOrderInfo         = reader.ReadBool(),
                HasTradeInfo         = reader.ReadBool(),
                Commission           = reader.ReadNullableDecimal(),
                Currency             = reader.ReadNullableEnum <CurrencyTypes>(),
                Comment              = reader.ReadString(),
                SystemComment        = reader.ReadString(),
                DerivedOrderId       = reader.ReadNullableLong(),
                DerivedOrderStringId = reader.ReadString(),
                IsUpTick             = reader.ReadNullableBool(),
                IsCancelled          = reader.ReadBool(),
                OpenInterest         = reader.ReadNullableDecimal(),
                PnL         = reader.ReadNullableDecimal(),
                Position    = reader.ReadNullableDecimal(),
                Slippage    = reader.ReadNullableDecimal(),
                TradeStatus = reader.ReadNullableInt(),
                OrderStatus = reader.ReadNullableLong(),
                Latency     = reader.ReadNullableLong().To <TimeSpan?>(),
            };

            var error = reader.ReadString();

            if (!error.IsEmpty())
            {
                msg.Error = new InvalidOperationException(error);
            }

            var dtStr = reader.ReadString();

            if (dtStr != null)
            {
                msg.ExpiryDate = (DateParser.Parse(dtStr) + TimeParser.Parse(reader.ReadString())).ToDateTimeOffset(TimeSpan.Parse(reader.ReadString().Replace("+", string.Empty)));
            }
            else
            {
                reader.Skip(2);
            }

            return(msg);
        }
コード例 #15
0
        public void Empty_does_not_throw_exception_when_parsing_date()
        {
            var dateRange = dateParser.Parse(string.Empty);

            Assert.NotNull(dateRange);
        }
コード例 #16
0
        public ChattyThread ParseThreadTree(Parser p, bool stopAtFullPost = true)
        {
            if (p.Peek(1, "<div class=\"postbody\">") == -1)
            {
                throw new MissingThreadException($"Thread does not exist.");
            }

            var list = new List <ChattyPost>();

            var authorSection   = p.Clip(_threadTreeAuthorSectionStart, "\"");
            var rootAuthorId    = int.Parse(authorSection.Replace("fpfrozen", ""));
            var rootIsFrozen    = authorSection.Contains("fpfrozen", StringComparison.Ordinal);
            var rootAuthorFlair = ParseUserFlair(p.Clip(_threadTreeAuthorFlairStart, "</span>"));
            var rootBody        = MakeSpoilersClickable(HtmlDecodeExceptLtGt(RemoveNewlines(p.Clip(
                                                                                                _threadTreeRootBodyStart,
                                                                                                "</div>"))));
            var rootDate = DateParser.Parse(StripTags(p.Clip(
                                                          _threadTreeRootDateStart,
                                                          "T</div")).Replace("Flag", "") + "T");

            var depth      = 0;
            var nextThread = p.Peek(1, "<div class=\"fullpost op");

            if (nextThread == -1)
            {
                nextThread = p.Length;
            }

            while (true)
            {
                var nextReply = p.Peek(1, "<div class=\"oneline");
                if (nextReply == -1 || (stopAtFullPost && nextReply > nextThread))
                {
                    break;
                }

                var reply = new ChattyPost {
                    Depth = depth
                };

                if (list.Count == 0)
                {
                    reply.Body        = rootBody;
                    reply.Date        = rootDate;
                    reply.AuthorId    = rootAuthorId;
                    reply.AuthorFlair = rootAuthorFlair;
                    reply.IsFrozen    = rootIsFrozen;
                }

                reply.Category = V2ModerationFlagConverter.Parse(p.Clip(
                                                                     _threadTreeReplyCategoryStart,
                                                                     " "));
                reply.Id = int.Parse(p.Clip(
                                         _threadTreeReplyIdStart,
                                         "\""));
                reply.Author = HtmlDecodeExceptLtGt(p.Clip(
                                                        _threadTreeReplyAuthorStart,
                                                        "</span>"));

                // Determine the next level of depth.
                while (true)
                {
                    var nextLi    = p.Peek(1, "<li ");
                    var nextUl    = p.Peek(1, "<ul>");
                    var nextEndUl = p.Peek(1, "</ul>");

                    if (nextLi == -1)
                    {
                        nextLi = nextThread;
                    }
                    if (nextUl == -1)
                    {
                        nextUl = nextThread;
                    }
                    if (nextEndUl == -1)
                    {
                        nextEndUl = nextThread;
                    }

                    var next = Math.Min(Math.Min(nextLi, nextUl), nextEndUl);

                    if (next == nextThread)
                    {
                        // This thread has no more replies.
                        break;
                    }
                    else if (next == nextLi)
                    {
                        // Next reply is on the same depth level.
                        break;
                    }
                    else if (next == nextUl)
                    {
                        // Next reply is underneath this one.
                        depth++;
                    }
                    else if (next == nextEndUl)
                    {
                        // Next reply is above this one.
                        depth--;
                    }

                    p.Cursors[1] = next + 1;
                }

                list.Add(reply);
            }

            return(new ChattyThread {
                Posts = list
            });
        }
コード例 #17
0
        public void OnStudyQuery(DicomMessage message, SelectCallback <IStudyData> callback)
        {
            // Supported Query Condition includes:
            // PatientsName, PatientsId, PatientsSex, PatientsBirthDate, PatientsBirthTime
            // StudyInstanceUid, StudyId, StudyDescription, AccessionNumber, ModalitiesInStudy
            // ReferringPhysiciansName, StudyDate, StudyTime

            var data = message.DataSet;

            using (var ctx = new PacsContext())
            {
                #region Build Query

                //Linq query is lazy query mechanism
                var results = from study in ctx.Studies select study;
                foreach (var attrib in message.DataSet)
                {
                    if (!attrib.IsNull)
                    {
                        switch (attrib.Tag.TagValue)
                        {
                        case DicomTags.PatientsName:
                        {
                            var patientName = data[DicomTags.PatientsName].GetString(0,
                                                                                     string.Empty);
                            if (patientName.Length == 0)
                            {
                                break;
                            }

                            var replaced = QueryHelper.ReplacsWildcard(patientName);
                            if (replaced == null)
                            {
                                results = from study in results
                                          where study.PatientName.Equals(patientName)
                                          select study;
                            }
                            else
                            {
                                results = from study in results
                                          where study.PatientName.Contains(replaced)
                                          select study;
                            }

                            break;
                        }

                        case DicomTags.PatientId:
                        {
                            var patientId = data[DicomTags.PatientId].GetString(0, string.Empty);
                            if (patientId.Length == 0)
                            {
                                break;
                            }

                            var replaced = QueryHelper.ReplacsWildcard(patientId);
                            if (replaced == null)
                            {
                                results = from row in results
                                          where row.PatientId.Equals(patientId)
                                          select row;
                            }
                            else
                            {
                                results = from row in results
                                          where row.PatientId.Contains(replaced)
                                          select row;
                            }

                            break;
                        }

                        case DicomTags.PatientsSex:
                        {
                            var values = (string[])data[DicomTags.PatientsSex].Values;
                            if (values == null || values.Length == 0)
                            {
                                break;
                            }

                            results = from study in results
                                      where values.Length == 1
                                        ? study.PatientSex.Equals(values[0])
                                        : values.Contains(study.PatientSex)
                                      select study;
                            break;
                        }

                        case DicomTags.PatientsBirthDate:
                        {
                            var values = (string[])data[DicomTags.PatientsBirthDate].Values;
                            if (values == null || values.Length == 0)
                            {
                                break;
                            }

                            var dt = DateParser.Parse(values[0]);
                            if (dt == null)
                            {
                                break;
                            }

                            results = from study in results
                                      where values.Length == 1
                                        ? study.PatientBirthday.Equals(dt.Value)
                                        : values.Contains(DateParser.ToDicomString(study.PatientBirthday))
                                      select study;
                            break;
                        }

                        case DicomTags.StudyDate:
                        {
                            var v = data[DicomTags.StudyDate].GetString(0, string.Empty);
                            if (string.IsNullOrEmpty(v))
                            {
                                break;
                            }

                            DateTime?startDate;
                            DateTime?toDate;
                            bool     isRange;
                            DateRangeHelper.Parse(v, out startDate, out toDate, out isRange);

                            if (isRange)
                            {
                                results = from study in results
                                          where study.StudyDate >= startDate.Value &&
                                          study.StudyDate <= toDate.Value
                                          select study;
                            }
                            else
                            {
                                if (startDate != null)
                                {
                                    results = from study in results
                                              where study.StudyDate >= startDate.Value
                                              select study;
                                }
                                else
                                {
                                    results = from study in results
                                              where study.StudyDate <= toDate.Value
                                              select study;
                                }
                            }

                            break;
                        }
                        }
                    }
                }

                #endregion

                Logger.Warn(results.ToString());

                foreach (var source in results.ToList())
                {
                    callback(source);
                }
            }
        }
コード例 #18
0
        public static ImageProperty Create(DicomAttribute attribute, string category, string name, string description, string separator)
        {
            // always use the hex value as the identifier, so that private and unknown tags aren't all mapped to the same identifier
            string identifier = attribute.Tag.HexString;

            if (category == null)
            {
                category = string.Empty;
            }

            if (string.IsNullOrEmpty(name))
            {
                name = GetTagName(attribute.Tag);
            }

            if (string.IsNullOrEmpty(description))
            {
                description = GetTagDescription(attribute.Tag);
            }

            if (attribute.IsNull || attribute.IsEmpty)
            {
                return(new ImageProperty(identifier, category, name, description, string.Empty));
            }

            if (String.IsNullOrEmpty(separator))
            {
                separator = ", ";
            }

            object value;

            if (attribute.Tag.VR.Name == DicomVr.DAvr.Name)
            {
                value = StringUtilities.Combine(attribute.Values as string[], separator,
                                                delegate(string dateString)
                {
                    DateTime?date = DateParser.Parse(dateString);
                    if (!date.HasValue)
                    {
                        return(null);
                    }
                    else
                    {
                        return(Format.Date(date.Value));
                    }
                }, true);
            }
            else if (attribute.Tag.VR.Name == DicomVr.TMvr.Name)
            {
                value = StringUtilities.Combine(attribute.Values as string[], separator,
                                                delegate(string timeString)
                {
                    DateTime?time = TimeParser.Parse(timeString);
                    if (!time.HasValue)
                    {
                        return(null);
                    }
                    else
                    {
                        return(Format.Time(time.Value));
                    }
                }, true);
            }
            else if (attribute.Tag.VR.Name == DicomVr.DTvr.Name)
            {
                value = StringUtilities.Combine(attribute.Values as string[], separator,
                                                delegate(string dateTimeString)
                {
                    DateTime?dateTime = DateTimeParser.Parse(dateTimeString);
                    if (!dateTime.HasValue)
                    {
                        return(null);
                    }
                    else
                    {
                        return(Format.Time(dateTime.Value));
                    }
                }, true);
            }
            else if (attribute.Tag.VR.Name == DicomVr.PNvr.Name)
            {
                value = StringUtilities.Combine(attribute.Values as string[], separator,
                                                delegate(string nameString)
                {
                    PersonName personName = new PersonName(nameString ?? "");
                    return(personName.FormattedName);
                }, true);
            }
            else if (attribute.Tag.VR == DicomVr.SQvr)
            {
                value = string.Empty;

                var values = attribute.Values as DicomSequenceItem[];
                if (values != null && values.Length > 0)
                {
                    // handle simple use case by listing only the attributes of the first sequence item
                    // since user can always use DICOM editor for more complex use cases
                    var subproperties = new List <IImageProperty>();
                    foreach (var subattribute in values[0])
                    {
                        subproperties.Add(Create(subattribute, string.Empty, null, null, null));
                    }
                    subproperties.Sort((x, y) => string.Compare(x.Name, y.Name, StringComparison.CurrentCultureIgnoreCase));
                    value = subproperties.ToArray();
                }
            }
            else if (attribute.Tag.VR.IsTextVR && attribute.GetValueType() == typeof(string[]))
            {
                value = StringUtilities.Combine(attribute.Values as string[], separator, true);
            }
            else
            {
                value = attribute.ToString();
            }

            return(new ImageProperty(identifier, category, name, description, value));
        }
コード例 #19
0
 public void DateParser_Parse_DateIsEmpty_ShouldThrowFormatException()
 {
     DateParser.Parse("");
 }
コード例 #20
0
 private static DateTime GetDateFrom(string[] arguments) => DateParser.Parse(arguments[1]);
コード例 #21
0
 public void DateParser_Parse_DateIsTooLong_ShouldThrowFormatException()
 {
     DateParser.Parse("18050317");
 }
コード例 #22
0
        public async Task <MessagePage> GetMessagePage(Mailbox folder, string username, string password, int page)
        {
            if (page < 1)
            {
                throw new Api400Exception("Invalid page.");
            }

            var folderName = folder == Mailbox.Inbox ? "inbox" : "sent";

            var messagesPerPage = 50;
            var html            = await _downloadService.DownloadWithUserLogin(
                $"https://www.shacknews.com/messages/{folderName}?page={page}",
                username, password);

            var p = new Parser(html);

            var messagePage =
                new MessagePage
            {
                Messages = new List <MessageModel>()
            };

            p.Seek(1, "class=\"tools\"");
            messagePage.UnreadCount = int.Parse(p.Clip(new string[] { "<span class=\"flag\"", ">" }, "</span>"));

            p.Seek(1, "<h2>Message Center</h2>");

            if (p.Peek(1, "<div class=\"showing-column\">") == -1)
            {
                messagePage.TotalCount = 0;
                messagePage.LastPage   = 1;
            }
            else
            {
                messagePage.TotalCount = int.Parse(p.Clip(
                                                       new[] { "<div class=\"showing-column\">", ">", "of", " " },
                                                       "</div>"));
                messagePage.LastPage = (int)Math.Ceiling((double)messagePage.TotalCount / messagesPerPage);
                p.Seek(1, "<ul id=\"messages\">");
            }

            while (p.Peek(1, "<li class=\"message") != -1)
            {
                var message   = new MessageModel();
                var liClasses = p.Clip(
                    new[] { "<li class=\"message", "\"" },
                    "\"");
                if (!liClasses.Contains("read"))
                {
                    message.Unread = true;
                }

                message.Id = int.Parse(p.Clip(
                                           new[] { "<input type=\"checkbox\" class=\"mid\" name=\"messages[]\"", "value=", "\"" },
                                           "\">"));

                var otherUser = WebUtility.HtmlDecode(p.Clip(
                                                          new[] { "<span class=\"message-username\"", ">" },
                                                          "</span>"));
                if (folder == Mailbox.Inbox)
                {
                    message.From = otherUser;
                    message.To   = username;
                }
                else
                {
                    message.From = username;
                    message.To   = otherUser;
                }

                message.Subject = WebUtility.HtmlDecode(p.Clip(
                                                            new[] { "<span class=\"message-subject\"", ">" },
                                                            "</span>"));
                message.Date = DateParser.Parse(p.Clip(
                                                    new[] { "<span class=\"message-date\"", ">" },
                                                    "</span>"));
                message.Body = p.Clip(
                    new[] { "<div class=\"message-body\"", ">" },
                    "</div>");

                messagePage.Messages.Add(message);
            }

            return(messagePage);
        }
コード例 #23
0
        public void DateParser_Parse_DateIs180220_ShouldParseCorrectly()
        {
            var result = DateParser.Parse("180220");

            Assert.AreEqual(new DateTime(2018, 02, 20), result);
        }
コード例 #24
0
        public void Update(StudyXml studyXml)
        {
            Platform.CheckForNullReference(studyXml, "studyXml");

            var dataSet = studyXml.First().First().Collection;

            DicomAttribute attribute       = dataSet[DicomTags.StudyInstanceUid];
            string         datasetStudyUid = attribute.ToString();

            if (!String.IsNullOrEmpty(StudyInstanceUid) && StudyInstanceUid != datasetStudyUid)
            {
                string message = String.Format("The study uid in the data set does not match this study's uid ({0} != {1}).",
                                               datasetStudyUid, StudyInstanceUid);

                throw new InvalidOperationException(message);
            }

            StudyInstanceUid = attribute.ToString();

            Platform.CheckForEmptyString(StudyInstanceUid, "StudyInstanceUid");

            _studyXml = studyXml;

            attribute = dataSet[DicomTags.PatientId];
            PatientId = attribute.ToString();

            attribute    = dataSet[DicomTags.PatientsName];
            PatientsName = new PersonName(attribute.ToString());

            attribute = dataSet[DicomTags.ReferringPhysiciansName];
            ReferringPhysiciansName = new PersonName(attribute.ToString());

            attribute   = dataSet[DicomTags.PatientsSex];
            PatientsSex = attribute.ToString();

            attribute            = dataSet[DicomTags.PatientsBirthDate];
            PatientsBirthDateRaw = attribute.ToString();
            PatientsBirthDate    = DateParser.Parse(PatientsBirthDateRaw);

            attribute            = dataSet[DicomTags.PatientsBirthTime];
            PatientsBirthTimeRaw = attribute.ToString();
            var time = TimeParser.Parse(PatientsBirthTimeRaw);

            if (time.HasValue)
            {
                PatientsBirthTimeTicks = time.Value.TimeOfDay.Ticks;
            }
            else
            {
                PatientsBirthTimeTicks = null;
            }

            attribute = dataSet[DicomTags.StudyId];
            StudyId   = attribute.ToString();

            attribute       = dataSet[DicomTags.AccessionNumber];
            AccessionNumber = attribute.ToString();

            attribute        = dataSet[DicomTags.StudyDescription];
            StudyDescription = attribute.ToString();

            attribute    = dataSet[DicomTags.StudyDate];
            StudyDateRaw = attribute.ToString();
            StudyDate    = DateParser.Parse(StudyDateRaw);

            attribute    = dataSet[DicomTags.StudyTime];
            StudyTimeRaw = attribute.ToString();
            time         = TimeParser.Parse(StudyTimeRaw);
            if (time.HasValue)
            {
                StudyTimeTicks = time.Value.TimeOfDay.Ticks;
            }
            else
            {
                StudyTimeTicks = null;
            }

            if (dataSet.Contains(DicomTags.ProcedureCodeSequence))
            {
                attribute = dataSet[DicomTags.ProcedureCodeSequence];
                if (!attribute.IsEmpty && !attribute.IsNull)
                {
                    DicomSequenceItem sequence = ((DicomSequenceItem[])attribute.Values)[0];
                    ProcedureCodeSequenceCodeValue = sequence[DicomTags.CodeValue].ToString();
                    ProcedureCodeSequenceCodingSchemeDesignator = sequence[DicomTags.CodingSchemeDesignator].ToString();
                }
            }

            attribute = dataSet[DicomTags.PatientSpeciesDescription];
            PatientSpeciesDescription = attribute.ToString();

            if (dataSet.Contains(DicomTags.PatientSpeciesCodeSequence))
            {
                attribute = dataSet[DicomTags.PatientSpeciesCodeSequence];
                if (!attribute.IsEmpty && !attribute.IsNull)
                {
                    DicomSequenceItem sequence = ((DicomSequenceItem[])attribute.Values)[0];
                    PatientSpeciesCodeSequenceCodingSchemeDesignator = sequence[DicomTags.CodingSchemeDesignator].ToString();
                    PatientSpeciesCodeSequenceCodeValue   = sequence[DicomTags.CodeValue].ToString();
                    PatientSpeciesCodeSequenceCodeMeaning = sequence[DicomTags.CodeMeaning].ToString();
                }
            }

            attribute = dataSet[DicomTags.PatientBreedDescription];
            PatientBreedDescription = attribute.ToString();

            if (dataSet.Contains(DicomTags.PatientBreedCodeSequence))
            {
                attribute = dataSet[DicomTags.PatientBreedCodeSequence];
                if (!attribute.IsEmpty && !attribute.IsNull)
                {
                    DicomSequenceItem sequence = ((DicomSequenceItem[])attribute.Values)[0];
                    PatientBreedCodeSequenceCodingSchemeDesignator = sequence[DicomTags.CodingSchemeDesignator].ToString();
                    PatientBreedCodeSequenceCodeValue   = sequence[DicomTags.CodeValue].ToString();
                    PatientBreedCodeSequenceCodeMeaning = sequence[DicomTags.CodeMeaning].ToString();
                }
            }

            attribute         = dataSet[DicomTags.ResponsiblePerson];
            ResponsiblePerson = new PersonName(attribute.ToString());

            attribute             = dataSet[DicomTags.ResponsiblePersonRole];
            ResponsiblePersonRole = attribute.ToString();

            attribute = dataSet[DicomTags.ResponsibleOrganization];
            ResponsibleOrganization = attribute.ToString();

            attribute            = dataSet[DicomTags.SpecificCharacterSet];
            SpecificCharacterSet = attribute.ToString();

            var modalities = _studyXml
                             .Select(s => s.First()[DicomTags.Modality].GetString(0, null))
                             .Where(value => !String.IsNullOrEmpty(value)).Distinct();

            ModalitiesInStudy = DicomStringHelper.GetDicomStringArray(modalities);

            var stationNames = _studyXml
                               .Select(s => s.First()[DicomTags.StationName].GetString(0, null))
                               .Where(value => !String.IsNullOrEmpty(value)).Distinct();

            StationNamesInStudy = DicomStringHelper.GetDicomStringArray(stationNames);

            var institutionNames = _studyXml
                                   .Select(s => s.First()[DicomTags.InstitutionName].GetString(0, null))
                                   .Where(value => !String.IsNullOrEmpty(value)).Distinct();

            InstitutionNamesInStudy = DicomStringHelper.GetDicomStringArray(institutionNames);

            var sopClasses = (from series in _studyXml
                              from instance in series
                              where instance.SopClass != null
                              select instance.SopClass.Uid).Distinct();

            SopClassesInStudy = DicomStringHelper.GetDicomStringArray(sopClasses);

            #region Meta Info

            var sourceAEs = (from series in _studyXml
                             from instance in series
                             where !String.IsNullOrEmpty(instance.SourceAETitle)
                             select instance.SourceAETitle).Distinct();
            SourceAETitlesInStudy = DicomStringHelper.GetDicomStringArray(sourceAEs);

            #endregion

            //these have to be here, rather than in Initialize b/c they are
            // computed from the series, which are parsed from the xml.
            NumberOfStudyRelatedSeries    = _studyXml.NumberOfStudyRelatedSeries;
            NumberOfStudyRelatedInstances = _studyXml.NumberOfStudyRelatedInstances;
        }
コード例 #25
0
        public void DateParser_Parse_DateIs800101_ShouldParseAs1980()
        {
            var result = DateParser.Parse("800101");

            Assert.AreEqual(new DateTime(1980, 01, 01), result);
        }
コード例 #26
0
        internal void Initialize(DicomFile file)
        {
            DicomAttributeCollection sopInstanceDataset = file.DataSet;

            DicomAttribute attribute       = sopInstanceDataset[DicomTags.StudyInstanceUid];
            string         datasetStudyUid = attribute.ToString();

            if (!String.IsNullOrEmpty(StudyInstanceUid) && StudyInstanceUid != datasetStudyUid)
            {
                string message = String.Format("The study uid in the data set does not match this study's uid ({0} != {1}).",
                                               datasetStudyUid, StudyInstanceUid);

                throw new InvalidOperationException(message);
            }
            else
            {
                StudyInstanceUid = attribute.ToString();
            }

            Platform.CheckForEmptyString(StudyInstanceUid, "StudyInstanceUid");

            attribute = sopInstanceDataset[DicomTags.PatientId];
            PatientId = attribute.ToString();

            attribute       = sopInstanceDataset[DicomTags.PatientsName];
            PatientsName    = new PersonName(attribute.ToString());
            PatientsNameRaw = DicomImplementation.CharacterParser.EncodeAsIsomorphicString(PatientsName, sopInstanceDataset.SpecificCharacterSet);

            attribute = sopInstanceDataset[DicomTags.ReferringPhysiciansName];
            ReferringPhysiciansName    = new PersonName(attribute.ToString());
            ReferringPhysiciansNameRaw = DicomImplementation.CharacterParser.EncodeAsIsomorphicString(ReferringPhysiciansName, sopInstanceDataset.SpecificCharacterSet);

            attribute   = sopInstanceDataset[DicomTags.PatientsSex];
            PatientsSex = attribute.ToString();

            attribute            = sopInstanceDataset[DicomTags.PatientsBirthDate];
            PatientsBirthDateRaw = attribute.ToString();

            attribute = sopInstanceDataset[DicomTags.StudyId];
            StudyId   = attribute.ToString();

            attribute       = sopInstanceDataset[DicomTags.AccessionNumber];
            AccessionNumber = attribute.ToString();

            attribute        = sopInstanceDataset[DicomTags.StudyDescription];
            StudyDescription = attribute.ToString();

            attribute    = sopInstanceDataset[DicomTags.StudyDate];
            StudyDateRaw = attribute.ToString();
            StudyDate    = DateParser.Parse(StudyDateRaw);

            attribute    = sopInstanceDataset[DicomTags.StudyTime];
            StudyTimeRaw = attribute.ToString();

            if (sopInstanceDataset.Contains(DicomTags.ProcedureCodeSequence))
            {
                attribute = sopInstanceDataset[DicomTags.ProcedureCodeSequence];
                if (!attribute.IsEmpty && !attribute.IsNull)
                {
                    DicomSequenceItem sequence = ((DicomSequenceItem[])attribute.Values)[0];
                    ProcedureCodeSequenceCodeValue = sequence[DicomTags.CodeValue].ToString();
                    ProcedureCodeSequenceCodingSchemeDesignator = sequence[DicomTags.CodingSchemeDesignator].ToString();
                }
            }

            attribute            = sopInstanceDataset[DicomTags.SpecificCharacterSet];
            SpecificCharacterSet = attribute.ToString();

            string[] modalitiesInStudy = DicomStringHelper.GetStringArray(ModalitiesInStudy ?? "");
            ModalitiesInStudy = DicomStringHelper.GetDicomStringArray(
                ComputeModalitiesInStudy(modalitiesInStudy, sopInstanceDataset[DicomTags.Modality].GetString(0, "")));
        }