コード例 #1
0
        private static ILocation GetLocationInfo(Clipping Clipping, string Line)
        {
            var pageNumber = new PageNumber(Clipping, Line);

            if (pageNumber.IsMatch)
            {
                return(pageNumber);
            }

            var location = new Location(Clipping, Line);

            if (location.IsMatch)
            {
                return(location);
            }

            var locationShort = new LocationShort(Clipping, Line);

            if (locationShort.IsMatch)
            {
                return(locationShort);
            }

            throw new Exception("Location portion of line did not match a known location type.");
        }
コード例 #2
0
        /// <summary>
        /// Adds a clipping to the database and returns a unique identifier for later retrieval
        /// </summary>
        /// <param name="clipping">The clipping to add to the database</param>
        /// <returns>The unique identifier corresponding to this clipping</returns>
        public static int AddClipping(Clipping clipping)
        {
            var id = _clippings.Keys.Count;

            _clippings.Add(id, clipping);

            return id;
        }
コード例 #3
0
        public static IEnumerable <Clipping> Parse(Stream stream)
        {
            var clippings = new Collection <Clipping>();

            using (var sr = new StreamReader(stream))
            {
                int      lineNumber         = 0;
                string   line               = null;
                int      clippingLineNumber = 0;
                Clipping clipping           = new Clipping();

                try
                {
                    while ((line = sr.ReadLine()) != null)
                    {
                        lineNumber++;

                        if (line == ClippingSeparator)
                        {
                            clippings.Add(clipping);
                            clippingLineNumber = 0;
                            clipping           = new Clipping();
                        }
                        else
                        {
                            clippingLineNumber++;
                        }

                        switch (clippingLineNumber)
                        {
                        case 1:
                            ParseLine1(line, clipping);
                            break;

                        case 2:
                            ParseLine2(line, clipping);
                            break;

                        case 4:
                            ParseLine4(line, clipping);
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Error encountered parsing line " + lineNumber + ": " + ex.Message, ex);
                }
            }

            return(clippings);
        }
コード例 #4
0
        public static IEnumerable<Clipping> Parse(Stream stream)
        {
            var clippings = new Collection<Clipping>();

            using (var sr = new StreamReader(stream))
            {
                int lineNumber = 0;
                string line = null;
                int clippingLineNumber = 0;
                Clipping clipping = new Clipping();

                try
                {
                    while ((line = sr.ReadLine()) != null)
                    {
                        lineNumber++;

                        if (line == ClippingSeparator)
                        {
                            clippings.Add(clipping);
                            clippingLineNumber = 0;
                            clipping = new Clipping();
                        }
                        else
                        {
                            clippingLineNumber++;
                        }

                        switch (clippingLineNumber)
                        {
                            case 1:
                                ParseLine1_AuthorTitle(line, clipping);
                                break;
                            case 2:
                                ParseLine2_Location(line, clipping);
                                break;
                            case 4:
                                ParseLine4_ClippingContent(line, clipping);
                                break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Error encountered parsing line " + lineNumber + ": " + ex.Message, ex);
                }
            }

            return clippings;
        }
コード例 #5
0
        private static void ParseLine1(string line, Clipping clipping)
        {
            var match = Regex.Match(line, Line1RegexPattern);
            if (match.Success)
            {
                var bookName = match.Groups[1].Value.Trim();
                var author = match.Groups[2].Value.Trim();

                clipping.BookName = bookName;
                clipping.Author = author;
            }
            else
            {
                throw new Exception("Clipping Line 1 did not match regex pattern.");
            }
        }
コード例 #6
0
        private static void ParseLine2(string line, Clipping clipping)
        {
            var split = line.Split(' ');

            switch (split[2])
            {
            case "Highlight":
                clipping.ClippingType = ClippingTypeEnum.Highlight;
                break;

            case "Note":
                clipping.ClippingType = ClippingTypeEnum.Note;
                break;

            case "Bookmark":
                clipping.ClippingType = ClippingTypeEnum.Bookmark;
                break;
            }

            var hasPageNumber = line.ToLower().Contains(" on page ");
            var hasLocation   = line.Contains(" Location ");

            var dtIdx  = 9;
            var locIdx = 5;

            if (hasPageNumber)
            {
                var pageNumber = split[5];
                clipping.Page = pageNumber;

                locIdx = 8;

                dtIdx = hasLocation ? 12 : 9;
            }

            if (hasLocation)
            {
                var location = split[locIdx];
                clipping.Location = location;
            }

            var dateAddedString = String.Join(" ", split[dtIdx], split[dtIdx + 1], split[dtIdx + 2], split[dtIdx + 3], split[dtIdx + 4], split[dtIdx + 5]);

            var dateAdded = DateTime.Parse(dateAddedString);

            clipping.DateAdded = dateAdded;
        }
コード例 #7
0
        private static void ParseLine1(string line, Clipping clipping)
        {
            var match = Regex.Match(line, Line1RegexPattern);

            if (match.Success)
            {
                var bookName = match.Groups[1].Value.Trim();
                var author   = match.Groups[2].Value.Trim();

                clipping.BookName = bookName;
                clipping.Author   = author;
            }
            else
            {
                throw new Exception("Clipping Line 1 did not match regex pattern.");
            }
        }
コード例 #8
0
        private static void ParseLine2_Location(string line, Clipping clipping)
        {
            var lineSegmentSplitChar = '|';
            var split = line.Split(lineSegmentSplitChar);

            var lineDateInfo = split.Last();
            var lineLocInfo  = String.Join(lineSegmentSplitChar.ToString(), split.Take(split.Length - 1));

            var ParsedClippingType = ParseClippingType(lineLocInfo);

            if (ParsedClippingType.HasValue)
            {
                clipping.ClippingType = ParsedClippingType.Value;
            }

            var location = GetLocationInfo(clipping, line);

            location.SetLocation();

            clipping.DateAdded = ParseDateInfo(lineDateInfo);
        }
コード例 #9
0
        private static ILocation GetLocationInfo(Clipping Clipping, string Line)
        {
            var pageNumber = new PageNumber(Clipping, Line);
            if (pageNumber.IsMatch)
                return pageNumber;

            var location = new Location(Clipping, Line);
            if (location.IsMatch)
                return location;

            var locationShort = new LocationShort(Clipping, Line);
            if (locationShort.IsMatch)
                return locationShort;

            throw new Exception("Location portion of line did not match a known location type.");
        }
コード例 #10
0
 private static void ParseLine4_ClippingContent(string line, Clipping clipping)
 {
     clipping.Text = line.Trim();
 }
コード例 #11
0
        private static void ParseLine2_Location(string line, Clipping clipping)
        {
            var lineSegmentSplitChar = '|';
            var split = line.Split(lineSegmentSplitChar);

            var lineDateInfo = split.Last();
            var lineLocInfo = String.Join(lineSegmentSplitChar.ToString(), split.Take(split.Length - 1));

            var ParsedClippingType = ParseClippingType(lineLocInfo);

            if (ParsedClippingType.HasValue)
                clipping.ClippingType = ParsedClippingType.Value;

            var location = GetLocationInfo(clipping, line);
            location.SetLocation();

            clipping.DateAdded = ParseDateInfo(lineDateInfo);
        }
コード例 #12
0
        private static void ParseLine2(string line, Clipping clipping)
        {
            var split = line.Split(' ');

            switch (split[2])
            {
                case "Highlight":
                    clipping.ClippingType = ClippingTypeEnum.Highlight;
                    break;
                case "Note":
                    clipping.ClippingType = ClippingTypeEnum.Note;
                    break;
                case "Bookmark":
                    clipping.ClippingType = ClippingTypeEnum.Bookmark;
                    break;
            }

            var hasPageNumber = line.Contains(" on Page ");
            var hasLocation = line.Contains(" Location ");

            var dtIdx = 8;
            var locIdx = 4;

            if (hasPageNumber)
            {
                var pageNumber = split[5];
                clipping.Page = pageNumber;

                locIdx = 8;

                dtIdx = hasLocation ? 12 : 9;
            }

            if (hasLocation)
            {
                var location = split[locIdx];
                clipping.Location = location;
            }

            var dateAddedString = String.Join(" ", split[dtIdx], split[dtIdx + 1], split[dtIdx + 2], split[dtIdx + 3], split[dtIdx + 4], split[dtIdx + 5]);

            var dateAdded = DateTime.Parse(dateAddedString);

            clipping.DateAdded = dateAdded;
        }
コード例 #13
0
 private static void ParseLine4(string line, Clipping clipping)
 {
     clipping.Text = line.Trim();
 }
コード例 #14
0
ファイル: MainForm.cs プロジェクト: EdRyan/KindleClippings
 private void OpenClippingWindow(Clipping clipping)
 {
     var form = new ClippingForm(clipping);
     form.Show();
 }
コード例 #15
0
 internal ClippingForm(Clipping clipping)
 {
     _clipping = clipping;
     BuildForm();
 }