Example #1
0
 public void Reset()
 {
     manager.Refresh();
     sectionParser = new SectionParser(manager);
     sections      = sectionParser.Sections;
     groups        = sectionParser.GroupSections;
 }
Example #2
0
 private void LoadSection(String sectionFile)
 {
     vfl.ClearSections();
     SectionParser.ParseSections(sectionFile, vfl);
     this.Text = String.Format("Section Editor - {0}", sectionFile);
     RefreshSectionList();
 }
Example #3
0
        public static Section[] Parse(TextReader reader, TextWriter messageWriter)
        {
            SectionParser parser = new SectionParser(reader);

            parser.MessageWriter = messageWriter;
            return(parser.Parse());
        }
        private void WriteTables(SectionParser parser)
        {
            bool tablesWritten             = false;
            IEnumerable <DataTable> tables = parser.GenerateDataTables();

            foreach (DataTable table in tables)
            {
                if (table.Rows.Count > 0)
                {
                    DataAccess.CreateDatabase(DefaultDirectory, table, table.TableName, CaseNumber);
                    tablesWritten = true;
                }
            }

            if (!tablesWritten)
            {
                throw new SectionEmptyException(parser.DisplaySectionName);
            }

            if (parser.ContainsLocationData)
            {
                LocationData = parser.GenerateLocationInformation();
            }

            if (parser.ContainsPreservationQueries)
            {
                PreservationQueries = parser.PreservationQueries;
            }
        }
Example #5
0
 private void btnSaveToFile_Click(object sender, EventArgs e)
 {
     try
     {
         if (vfl.CountSections > 0)
         {
             String filename = ShowSaveFileDialog("Select a section filename to save...", "", "(*.txt) Text files|*.txt|(*.*) All files|*.*");
             if (filename != null)
             {
                 if (filename.Length > 0)
                 {
                     SectionParser.WriteSections(vfl, filename);
                     this.Text = String.Format("Section Editor - {0}", filename);
                     ShowSuccessMessage("Successfully written section file!");
                 }
             }
         }
         else
         {
             throw new Exception("No sections to write!");
         }
     }
     catch (Exception ex)
     {
         ShowExceptionMessage(ex);
     }
 }
Example #6
0
        public void Keys_should_be_able_to_contain_empty_values()
        {
            var reader = new FileReader(GetPath("key-with-empty-value.txt"));
            var parser = new SectionParser(reader);

            Assert.AreEqual(string.Empty, parser.Sections["header"]["project"]);
            Assert.AreEqual("4.5", parser.Sections["header"]["budget"]);
        }
Example #7
0
        public void The_same_key_should_be_usable_in_different_sections()
        {
            var reader = new FileReader(GetPath("sections-with-same-keys.txt"));
            var parser = new SectionParser(reader);

            Assert.AreEqual("value", parser.Sections["section-one"]["key"]);
            Assert.AreEqual("value", parser.Sections["section-two"]["key"]);
        }
Example #8
0
        public List <string> Resolve(List <string> content)
        {
            ContentReader contentReader = new ContentReader();

            var variableSection = SectionParser.GetSection(content, "[Variables]");
            var eventSection    = SectionParser.GetSection(content, "[Events]");

            variableSection.ForEach(line => AddToDictionary(line));

            return(ReplaceWithValues(eventSection));
        }
Example #9
0
        ///	<summary>
        /// Obtain a handle to a parsed set of configuration values.
        /// </summary>
        ///	<param name="parser">
        /// Parser which can create the model if it is not already
        /// available in this configuration file. The parser is also used
        /// as the key into a cache and must obey the hashCode and equals
        /// contract in order to reuse a parsed model.
        /// </param>
        ///	<returns>
        /// The parsed object instance, which is cached inside this config.
        /// </returns>
        /// <typeparam name="T">Type of configuration model to return.</typeparam>
        public T get <T>(SectionParser <T> parser)
        {
            State myState = getState();
            T     obj     = (T)myState.Cache.get <object, object>(parser);

            if (Equals(obj, default(T)))
            {
                obj = (T)parser.parse(this);
                myState.Cache.put <object, object>(parser, obj);
            }
            return(obj);
        }
Example #10
0
        public Config Parse(string path)
        {
            var configBuilder = new Config.Builder();

            using (var fs = File.OpenRead(path))
                using (var sr = new StreamReader(fs, Encoding.UTF8))
                {
                    var validSection = false;
                    BaseSection.Builder currentSectionBuilder = null;
                    while (!sr.EndOfStream)
                    {
                        var line = sr.ReadLine();
                        if (line.Length == 0)
                        {
                            continue;
                        }

                        var lineType = CheckLineType(line);
                        if (lineType == LineType.COMMENT)
                        {
                            continue;
                        }

                        if (lineType == LineType.SECTION)
                        {
                            var sectionParser = new SectionParser();
                            validSection = sectionParser.TryParse(line, out var sectionBuilder);
                            if (validSection)
                            {
                                sectionBuilder.AddToConfigBuilder(configBuilder);
                                currentSectionBuilder = sectionBuilder;
                            }
                        }
                        else if (lineType == LineType.PARAMETER)
                        {
                            if (validSection)
                            {
                                var kvParser = new KeyValueParser();
                                if (kvParser.TryParse(line, out var kv))
                                {
                                    currentSectionBuilder.SetValue(kv);
                                }
                            }
                        }
                    }
                }

            return(configBuilder.Build());
        }
        public void ShallReturnSectionComponent()
        {
            var xml     = XDocument.Load("C-CDA_R2-1_CCD.xml");
            var element = xml.Root.CdaElement("component").CdaElement("structuredBody").CdaElement("component").CdaElement("section");

            var result = new SectionParser().FromXml(element);

            result.Should().NotBeNull();
            // US-Core Shall have title
            result.Title.Should().NotBeNullOrEmpty();
            // US-Core Shall have code
            result.Code?.Coding.Any().Should().BeTrue();
            // Us-Core Shall have text
            result.Text?.Div.Should().NotBeNullOrEmpty();
        }
Example #12
0
        public void ParseTest()
        {
            string text = @"# HEAD1
DOCUMENT CREATE.
DOCUMENT CREATE.
DOCUMENT CREATE.

* ITEM1
    * ITEM1-1
* ITEM2
        + ITEM2-1-1
    - ITEM2-2
    + ITEM2-3
* ITEM3
    + ITEM3-1
        - ITEM3-1-1

1. ITEM1
    * ITEM1-1
    1. ITEM1-2
2. ITEM2
    1. ITEM2-1
    2. ITEM2-2
3. ITEM3
    * ITEM3-1
    * ITEM3-2
    * ITEM3-3

    CODE1
    CODE2
    CODE3

> 1DATA1
> 1DATA2
> 1DATA3

> > 2DATA1
> > 2DATA2
> > 2DATA3
";

            using (StringReader reader = new StringReader(text))
            {
                SectionParser parser = new SectionParser(reader);

                Section[] sections = parser.Parse();
            }
        }
Example #13
0
        ///	<summary>
        /// Obtain a handle to a parsed set of configuration values.
        /// </summary>
        ///	<param name="parser">
        /// Parser which can create the model if it is not already
        /// available in this configuration file. The parser is also used
        /// as the key into a cache and must obey the hashCode and equals
        /// contract in order to reuse a parsed model.
        /// </param>
        ///	<returns>
        /// The parsed object instance, which is cached inside this config.
        /// </returns>
        /// <typeparam name="T">Type of configuration model to return.</typeparam>
        public T get <T>(SectionParser <T> parser)
        {
            State myState = getState();
            T     obj;

            if (!myState.Cache.ContainsKey(parser))
            {
                obj = parser.parse(this);
                myState.Cache.Add(parser, obj);
            }
            else
            {
                obj = (T)myState.Cache[parser];
            }
            return(obj);
        }
  /// <summary>
  /// This is the main method where the pbxproj file will be modified. In the body of the method there will be calls to other methods which will perform their logic for inserting the respective configurations into the pbxproj file.
  /// This finishes by writing out the entire new pbxproj file
  /// </summary>
  /// <param name="pbxProjectFilePath">This is the path to the pbxproj file being modified</param>
  /// <param name="thirdPartyFrameworkDirectoryPath">This is the path to the third-party frameworks directory being added into the XCode project's root directory.</param>
  /// <param name="frameworksToAdd">This is an array of frameworks that will be added to the pbxproj file.</param>
  public static void updateXcodeProject(string pbxProjectFilePath, string thirdPartyFrameworkDirectoryPath, Framework[] frameworksToAdd)
  {
    // STEP 1: Open the pbx project file and read in the lines to a list so it can have new lines injected
    string[] lines = System.IO.File.ReadAllLines(pbxProjectFilePath);
    List<string> linesList = new List<string>();
    foreach(string line in lines) {
      linesList.Add(line);
    }
    sectionParser = new SectionParser(linesList, '{', '}');

    // STEP 2: Next check which frameworks have already been added. If they have been added don't bother adding them
    //         This is probably redundant, but it felt like it was something worthwhile to do
    MarkFrameworksAlreadyAdded(lines, frameworksToAdd);
    // Debug.Log("Frameworks being added to the XCode Project:");
    foreach(Framework framework in frameworksToAdd) {
      if(!framework.hasBeenAdded) {
        // Debug.Log(framework.name + " will be added to the XCode project.");
      }
    }

    // STEP 3: Next each section in the pbxproj file will be modified to include the passed in list of
    Debug.Log("AdColony is adding frameworks to the PBXBuildFile section.");
    AddFrameworksToPBXBuildFileSection(linesList, frameworksToAdd);
    // Debug.Log("-------------------------------------------------");
    Debug.Log("AdColony is adding frameworks to the PBXBuildFileReference section.");
    AddFrameworksToPBXFileReferenceSection(linesList, frameworksToAdd);
    // Debug.Log("-------------------------------------------------");
    Debug.Log("AdColony is adding frameworks to the PBXFrameworksBuildPhase section.");
    AddFrameworksToPBXFrameworksBuildPhaseSection(linesList, frameworksToAdd);
    // Debug.Log("-------------------------------------------------");
    Debug.Log("AdColony is adding frameworks to the PBXGroup section.");
    AddFrameworksToPBXGroupSection(linesList, frameworksToAdd);
    // Debug.Log("-------------------------------------------------");
    // Debug.Log("AdColony is adding build settings to targets.");
    AddConfigurationsToXCBuildConfiguration(linesList, thirdPartyFrameworkDirectoryPath, frameworksToAdd);

    // STEP 4: Output the finally configured pbxproj file lines to the new file
    FileStream filestr = new FileStream(pbxProjectFilePath, FileMode.Create); //Create new file and open it for read and write, if the file exists overwrite it.
    filestr.Close() ;
    StreamWriter fCurrentXcodeProjFile = new StreamWriter(pbxProjectFilePath) ; // will be used for writing
    foreach(string line in linesList) {
      fCurrentXcodeProjFile.WriteLine(line);
    }
    fCurrentXcodeProjFile.Close();
  }
Example #15
0
 public void No_valid_keys_in_section_should_throw_ArgumentException()
 {
     //header section has no keys starting in column 0
     var reader = new FileReader(GetPath("section-no-keys.txt"));
     var parser = new SectionParser(reader);
 }
Example #16
0
 public void Constructor_should_throw_ArgumentException_if_file_has_non_unique_section_headers()
 {
     var parser = new SectionParser(new FileReader(GetPath("duplicate-headings.txt")));
 }
Example #17
0
 public void Constructor_should_throw_ArgumentException_if_first_non_blank_line_is_not_a_section_heading()
 {
     var parser = new SectionParser(new FileReader(GetPath("invalid-firstline.txt")));
 }
Example #18
0
 public virtual void SetUp()
 {
     Parser = new SectionParser(new FileReader(GetPath("valid-config.txt")));
 }
        public void NullElementShallReturnNull()
        {
            var result = new SectionParser().FromXml(null);

            result.Should().BeNull();
        }
Example #20
0
 public override void SetUp()
 {
     Parser = new SectionParser(new FileReader(GetPath("valid-leading-whitespace.txt")));
 }
 public SectionParserTest()
 {
     _sectionParser = new SectionParser(new ParserFactory());
 }
Example #22
0
        private void btnSplit_Click(object sender, EventArgs e)
        {
            try
            {
                AssParser assP = new AssParser();
                assP.ParseASS(txtAssFile.Text);
                VideoFrameList vfl = new VideoFrameList();
                SectionParser.ParseSections(txtSectionsFile.Text, vfl);
                Decimal framerate = AcHelper.DecimalParse(txtFramerate.Text);
                foreach (AssDialogue assD in assP.AssContents)
                {
                    Decimal timeToDelete = 0;
                    for (Int32 currentSection = 0; currentSection < vfl.FrameSections.Count; currentSection++)
                    {
                        VideoFrameSection vfs          = vfl.FrameSections[currentSection];
                        Decimal           startSection = VideoFrame.GetStartTimeFromFrameNumber(vfs.FrameStart, framerate);
                        Decimal           endSection   = VideoFrame.GetStartTimeFromFrameNumber(vfs.FrameEnd, framerate);
                        //Check if the sub ends before the section
                        if (assD.time_end_double <= startSection)
                        {
                            assD.deleted = true;
                            break;
                        }
                        //Check if the sub starts after the section
                        if (assD.time_start_double >= endSection)
                        {
                            //If its the last sections, then delete the sub
                            if (currentSection == vfl.FrameSections.Count - 1)
                            {
                                assD.deleted = true;
                                break;
                            }
                            else
                            {
                                continue;
                            }
                        }
                        //Time to resync the sub
                        if (currentSection == 0)
                        {
                            TimeSpan ts;
                            timeToDelete           = startSection;
                            assD.time_start_double = assD.time_start_double - timeToDelete;
                            ts = TimeSpan.FromMilliseconds(Convert.ToDouble(assD.time_start_double));
                            assD.time_start = ts.Hours.ToString("0") + ":" + ts.Minutes.ToString("00")
                                              + ":" + ts.Seconds.ToString("00") + "." + ts.Milliseconds.ToString("00");

                            assD.time_end_double = assD.time_end_double - timeToDelete;
                            ts            = TimeSpan.FromMilliseconds(Convert.ToDouble(assD.time_end_double));
                            assD.time_end = ts.Hours.ToString("0") + ":" + ts.Minutes.ToString("00")
                                            + ":" + ts.Seconds.ToString("00") + "." + ts.Milliseconds.ToString("00");
                            break;
                        }
                        else
                        {
                            TimeSpan ts;
                            Decimal  start   = startSection;
                            Decimal  end     = endSection;
                            Decimal  prevEnd = VideoFrame.GetStartTimeFromFrameNumber(vfl.FrameSections[currentSection - 1].FrameEnd, framerate);
                            timeToDelete          += start - prevEnd - VideoFrame.GetDurationFromFrameRate(framerate);
                            assD.time_start_double = assD.time_start_double - timeToDelete;
                            ts = TimeSpan.FromMilliseconds(Convert.ToDouble(assD.time_start_double));
                            assD.time_start = ts.Hours.ToString("0") + ":" + ts.Minutes.ToString("00")
                                              + ":" + ts.Seconds.ToString("00") + "." + ts.Milliseconds.ToString("00");

                            assD.time_end_double = assD.time_end_double - timeToDelete;
                            ts            = TimeSpan.FromMilliseconds(Convert.ToDouble(assD.time_end_double));
                            assD.time_end = ts.Hours.ToString("0") + ":" + ts.Minutes.ToString("00")
                                            + ":" + ts.Seconds.ToString("00") + "." + ts.Milliseconds.ToString("00");
                            break;
                        }
                    }
                }
                assP.WriteFinalAss(txtAssFile.Text.Substring(0, txtAssFile.Text.LastIndexOf(".") - 1) + ".resync.ass");
                MessageBox.Show("Resync complete!", "Success!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error!");
            }
        }
Example #23
0
 public void Section_should_not_contain_duplicate_keys()
 {
     var reader = new FileReader(GetPath("duplicate-section-keys.txt"));
     var parser = new SectionParser(reader);
 }
Example #24
0
 /// <summary>
 /// Remove a cached configuration object.
 ///	<para />
 /// If the associated configuration object has not yet been cached, this
 /// method has no effect.
 /// </summary>
 ///	<param name="parser">Parser used to obtain the configuration object.</param>
 ///	<seealso cref="get{T}"/>
 public void uncache <T>(SectionParser <T> parser)
 {
     _state.Cache.Remove(parser);
 }
 public void Setup()
 {
     SUT = new SectionParser();
 }
Example #26
0
 /// <summary>
 /// Load sections from a sections/trims file
 /// </summary>
 /// <param name="sectionsFile"></param>
 public void LoadSections(String sectionsFile)
 {
     SectionParser.ParseSections(sectionsFile, this);
 }
 public void Teardown()
 {
     SUT = null;
 }
Example #28
0
        public void CreateFromSections(String sectionsFile, String chaptersFile, Decimal frameRate, Boolean useChapters, Boolean isTrimFile)
        {
            //clear chapters
            chapterList.Clear();

            //If use chapters, load chapter file
            if (useChapters)
            {
                if (AcHelper.GetFilename(chaptersFile, GetFileNameMode.ExtensionOnly, GetDirectoryNameMode.NoPath).ToLowerInvariant() == "xml")
                {
                    Load(ChapterType.XML, chaptersFile);
                }
                else if (AcHelper.GetFilename(chaptersFile, GetFileNameMode.ExtensionOnly, GetDirectoryNameMode.NoPath).ToLowerInvariant() == "txt")
                {
                    Load(ChapterType.OGM, chaptersFile);
                }
            }

            //Create a Videoframelist
            vfl = new VideoFrameList();

            //Load the sections file
            SectionParser.ParseSections(sectionsFile, vfl);

            //Sanity check
            if (useChapters && vfl.CountSections != chapterList.Count)
            {
                throw new AcException("Error creating chapters! Sections count is different from the chapters count!");
            }

            if (isTrimFile)
            {
                Int32 framesToDelete = 0;
                for (Int32 i = 0; i < vfl.CountSections; i++)
                {
                    //If no chapters are loaded
                    if (!useChapters)
                    {
                        //Create new empty chapter
                        VideoChapter chap = new VideoChapter();
                        chapterList.Add(chap);
                    }

                    if (i == 0)
                    {
                        Int32 start = 0;
                        Int32 end   = vfl.FrameSections[i].FrameEnd;
                        framesToDelete           = vfl.FrameSections[0].FrameStart;
                        end                     -= framesToDelete;
                        chapterList[i].StartTime = VideoFrame.FrameTimeFromFrameNumber(start, frameRate, FrameFromType.FromFrameRate);
                        chapterList[i].EndTime   = VideoFrame.FrameTimeFromFrameNumber(Convert.ToDecimal(end) + 0.5m,
                                                                                       frameRate, FrameFromType.FromFrameRate);
                    }
                    else
                    {
                        Int32 start   = vfl.FrameSections[i].FrameStart;
                        Int32 end     = vfl.FrameSections[i].FrameEnd;
                        Int32 prevEnd = vfl.FrameSections[i - 1].FrameEnd;
                        framesToDelete          += start - prevEnd - 1;
                        start                   -= framesToDelete;
                        end                     -= framesToDelete;
                        chapterList[i].StartTime = VideoFrame.FrameTimeFromFrameNumber(Convert.ToDecimal(start) + 0.5m,
                                                                                       frameRate, FrameFromType.FromFrameRate);
                        chapterList[i].EndTime = VideoFrame.FrameTimeFromFrameNumber(Convert.ToDecimal(end) + 0.5m,
                                                                                     frameRate, FrameFromType.FromFrameRate);
                    }
                }
            }
            else
            {
                for (Int32 i = 0; i < vfl.CountSections; i++)
                {
                    //If no chapters are loaded
                    if (!useChapters)
                    {
                        //Create new empty chapter
                        VideoChapter chap = new VideoChapter();
                        chapterList.Add(chap);
                    }

                    Int32 start = vfl.FrameSections[i].FrameStart;
                    Int32 end   = vfl.FrameSections[i].FrameEnd;
                    chapterList[i].StartTime = VideoFrame.FrameTimeFromFrameNumber(Convert.ToDecimal(start) + 0.5m,
                                                                                   frameRate, FrameFromType.FromFrameRate);
                    chapterList[i].EndTime = VideoFrame.FrameTimeFromFrameNumber(Convert.ToDecimal(end) + 0.5m,
                                                                                 frameRate, FrameFromType.FromFrameRate);
                }
            }
        }
Example #29
0
        public void EncodeTest()
        {
            string text = @"# HEAD1
DOCUMENT CREATE.
DOCUMENT CREATE.
DOCUMENT CREATE.

## HEAD2
### HEAD3
* ITEM1
    * ITEM1-1
* ITEM2
        + ITEM2-1-1
    - ITEM2-2
    + ITEM2-3
* ITEM3
    + ITEM3-1
        - ITEM3-1-1
XXXXXXXXXXXXXXXXX
1. ITEM1
    * ITEM1-1
    1. ITEM1-2
2. ITEM2
    1. ITEM2-1
    2. ITEM2-2
3. ITEM3
    * ITEM3-1
    * ITEM3-2
    * ITEM3-3

    CODE1
    CODE2
    CODE3

> 1DATA1
> 1DATA2
> 1DATA3

> > 2DATA1
> > 2DATA2
> > 2DATA3

:CAPTION1
CONTEXT CONTEXT CONTEXT
:CAPTION2
CONTEXT1 CONTEXT1 CONTEXT1
";

            Section[] sections;
            using (StringReader reader = new StringReader(text))
            {
                SectionParser parser = new SectionParser(reader);

                sections = parser.Parse();
            }

            HtmlEncoder encoder = new HtmlEncoder();

            StringWriter writer = new StringWriter();

            encoder.Encode(writer, sections);

            string ccc = writer.ToString();
        }