Пример #1
0
        StringArrayList GetAuthors()
        {
            WriteLine(10, "SidePaneTreeStore.GetAuthors()");
            var authors = new StringArrayList();

            if (IterHasChild(iterAuth))
            {
                Gtk.TreeIter iter;

                IterChildren(out iter, iterAuth);

                while (IterIsValid(iter))
                {
                    string author = (string)GetValue(iter, 0);
                    WriteLine(10, "Add the Author {0} to an output list", author);
                    authors.Add(author);
                    if (!IterNext(ref iter))
                    {
                        break;
                    }
                }
            }
            authors.Sort();
            return(authors);
        }
Пример #2
0
        public static Tri Index(StringArrayList textualDataArray)
        {
            Tri index = new Tri();

            if (textualDataArray != null)
            {
                for (int line = 0; line < textualDataArray.Count; line++)
                {
                    string data = textualDataArray [line].ToLower();
                    data = Regex.Replace(data, @"</?\w+((\s+\w+(\s*=\s*(?:"".*?""|'.*?'|[^'"">\s]+))?)+\s*|\s*)/?>", string.Empty);
                    //data = Regex.Replace(data, "[^\\w\\.@-]", String.Empty);
                    data = Regex.Replace(data, "[\\d]", string.Empty);
                    string [] tokens = data.Split(' ');
                    foreach (string token in tokens)
                    {
                        index.AddString(token);
                    }
                }
            }
            else
            {
                WriteLine(5, "Got null back for index data :-(");
            }

            return(index);
        }
Пример #3
0
        public static StringArrayList GetTextualData(string uriString)
        {
            // TODO: Cache result, and load cache if cache exists!!
            StringArrayList textualData = null;
            StringArrayList extractor;
            Uri             uri;
            string          mimeType;
            ulong           data_size;

            data_size = 0;

            uri      = new Uri(uriString);
            mimeType = GLib.ContentType.Guess(uri.ToString(), out byte data, data_size, out bool uncertain);
            WriteLine(5, "Indexing a file of MimeType: " + mimeType);

            extractor = GetTextualExtractor(mimeType);

            if (extractor.Count == 2)
            {
                WriteLine(10, "Textual extractor is {0}", extractor [0]);
                string extractor_options;
                extractor_options = string.Format(extractor [1], '"' + uri.LocalPath + '"');
                WriteLine(10, "extractor options are {0}", extractor_options);
                if (Environment.OSVersion.Platform == PlatformID.Win32NT)
                {
                    Environment.SetEnvironmentVariable("HOME", AppDomain.CurrentDomain.BaseDirectory);
                }
                WriteLine(10, "Extracting text using: " + extractor [0]);
                textualData = GetProcessOutput(extractor [0], extractor_options);
                WriteLine(5, "Finished extracting text using: " + extractor [0]);
            }

            return(textualData);
        }
Пример #4
0
        private static StringArrayList GetProcessOutput(string command, string args)
        {
            StringArrayList result = new StringArrayList();

            proc.StartInfo.FileName  = command;
            proc.StartInfo.Arguments = args;
            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.UseShellExecute        = false;
            try {
                proc.Start();

                while (true)
                {
                    string line = proc.StandardOutput.ReadLine();
                    if (line != null)
                    {
                        result.Add(line);
                    }
                    else
                    {
                        break;
                    }
                }

                if (proc.HasExited)
                {
                    if (proc.ExitCode == 0)
                    {
                        return(result);
                    }
                    WriteLine(5, "Running of program '{0}' with args '{1}' failed with exit code {2}", command, args, proc.ExitCode);
                    return(null);
                }
                WriteLine(5, "Read From File process, '{0}' did not exit, so it was killed", command);
                return(result);
            } catch (InvalidOperationException e) {
                WriteLine(1, "Caught InvalidOperationException");
                WriteLine(1, e.Message);
                WriteLine(1, e.StackTrace);
                return(null);
            } catch (FileNotFoundException e) {
                WriteLine(1, "Cannot Index file. Application '{0}' not found.", command);
                WriteLine(1, e.Message);
                WriteLine(1, e.StackTrace);
                return(null);
                // Why is this exception being thrown under linux???
            } catch (System.ComponentModel.Win32Exception e) {
                WriteLine(1, "Cannot Index file. Application '{0}' not found.", command);
                WriteLine(1, e.Message);
                WriteLine(1, e.StackTrace);
                return(null);
            } catch (Exception e) {
                WriteLine(1, "Caught Unhandled Exception");
                WriteLine(1, e.Message);
                WriteLine(1, e.StackTrace);
                return(null);
            }
        }
    public static void Main(string[] args)
    {
        StringArrayList array = GetStrings( );

        for (int i = 0; i < array.Count; i++)
        {
            Console.WriteLine(array[i]);
        }
    }
Пример #6
0
        private static StringArrayList GetTextualExtractor(object mimeType)
        {
            BibliographerSettings settings;

            string []       extractors;
            StringArrayList extractor;

            extractor  = new StringArrayList();
            settings   = new BibliographerSettings("apps.bibliographer.index");
            extractors = settings.GetStrv("textual-extractor");

            if (extractors.Length == 0)
            {
                ArrayList newExtractors;
                newExtractors = new ArrayList();

                if (Environment.OSVersion.Platform == PlatformID.Win32NT)
                {
                    // Default extractors for Windows systems
                    newExtractors.Add(".pdf:pdftotext:{0} -");
                    newExtractors.Add(".doc:antiword:{0}");
                    newExtractors.Add(".docx:opc_text:{0}");
                }
                else
                {
                    // Default extractors for Gnu/Linux systems
                    newExtractors.Add("application/pdf:pdftotext:{0} -");
                    newExtractors.Add("application/msword:antiword:{0}");
                    newExtractors.Add("application/postscript:pstotext:{0}");
                    newExtractors.Add("text/plain:cat:{0}");
                }

                //TODO: Add default extractors for other systems

                extractors = (string [])newExtractors.ToArray(typeof(string));
                settings.SetStrv("textual-extractor", extractors);
            }
            string [] output;

            foreach (string entry in extractors)
            {
                output = entry.Split(':');
                if (output [0] == mimeType.ToString())
                {
                    extractor.Add(output [1]);
                    extractor.Add(output [2]);
                }
            }

            if (extractor.Count > 0)
            {
                WriteLine(5, "textual extractor determined: " + extractor [0]);
            }

            return(extractor);
        }
Пример #7
0
        static void RenderColumnTextFromBibtexRecord(Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.ITreeModel model, Gtk.TreeIter iter)
        {
            // See here for an example of how you can highlight cells
            // based on something todo with the entry
            //
            // TODO: extend this feature to highlight entries that
            // are missing required fields

            if ((model != null) && (column != null) && (column.Title != null))
            {
                var record = (BibtexRecord)model.GetValue(iter, 0);
                if (record != null)
                {
                    if (record.HasField(column.Title) && column.Title != "Author")
                    {
                        (cell as Gtk.CellRendererText).Text       = StringOps.TeXToUnicode(record.GetField(column.Title));
                        (cell as Gtk.CellRendererText).Background = "white";
                        (cell as Gtk.CellRendererText).Ellipsize  = Pango.EllipsizeMode.End;
                    }
                    else if (record.HasField(column.Title) && column.Title == "Author")
                    {
                        StringArrayList authors       = record.GetAuthors();
                        string          author_string = "";
                        foreach (string author in authors)
                        {
                            if (author_string == "")
                            {
                                author_string = author;
                            }
                            else
                            {
                                author_string = String.Concat(author_string, "; ", author);
                            }
                        }
                        (cell as Gtk.CellRendererText).Text       = StringOps.TeXToUnicode(author_string);
                        (cell as Gtk.CellRendererText).Background = "white";
                        (cell as Gtk.CellRendererText).Ellipsize  = Pango.EllipsizeMode.End;
                    }
                    else
                    {
                        (cell as Gtk.CellRendererText).Text = "";
                        // could highlight important fields that are missing data too,
                        // for e.g. the line below:
                        //(cell as Gtk.CellRendererText).Background = "green";
                    }
                    if (!BibtexRecordTypeLibrary.Contains(record.RecordType))
                    {
                        (cell as Gtk.CellRendererText).Foreground = "red";
                    }
                    else
                    {
                        (cell as Gtk.CellRendererText).Foreground = "black";
                    }
                }
            }
        }
Пример #8
0
        private static string ExtractDOI(StringArrayList stringDataArray)
        {
            WriteLine(5, "Attempting to extract DOI");
            if (stringDataArray != null)
            {
                for (int line = 0; line < stringDataArray.Count; line++)
                {
                    string lineData = stringDataArray [line].ToLower();
                    if (lineData.IndexOf("doi", StringComparison.CurrentCultureIgnoreCase) >= 0)
                    {
                        int idx1;
                        idx1 = 0;
                        if (lineData.IndexOf("doi:", StringComparison.CurrentCultureIgnoreCase) >= 0)
                        {
                            idx1 = lineData.IndexOf("doi:", StringComparison.CurrentCultureIgnoreCase) + 4;
                            if (lineData.IndexOf("doi:", idx1, StringComparison.CurrentCultureIgnoreCase) >= 0)
                            {
                                idx1 = lineData.IndexOf("doi:", idx1, StringComparison.CurrentCultureIgnoreCase) + 4;
                            }
                        }
                        else if (lineData.IndexOf("doi.org/", StringComparison.CurrentCultureIgnoreCase) >= 0)
                        {
                            idx1 = lineData.IndexOf("doi.org/", StringComparison.CurrentCultureIgnoreCase) + 8;
                        }

                        lineData = lineData.Substring(idx1);
                        lineData = lineData.Trim();
                        // If there are additional characters on this line, find a space character and chop them off
                        if (lineData.IndexOf(' ') > 0)
                        {
                            int idx2 = lineData.IndexOf(' ');
                            lineData = lineData.Substring(0, lineData.Length - idx2);
                        }
                        if (lineData.IndexOf(',') > 0)
                        {
                            int idx3 = lineData.IndexOf(',');
                            lineData = lineData.Substring(0, lineData.Length - idx3);
                        }
                        if ((lineData.Length > 3) && lineData.Contains("/"))
                        {
                            WriteLine(10, "Found doi:{0}", lineData);
                            return(lineData);
                        }
                    }
                }
            }
            return(null);
        }
Пример #9
0
        void UpdateAuthors(BibtexRecord btRecord)
        {
            string          author;
            StringArrayList bibrecAuthors;

            bibrecAuthors = btRecord.GetAuthors();
            StringArrayList bibrecsAuthors;

            bibrecsAuthors = bibtexRecords.GetAuthors();

            // Interate through updated record's authors
            for (int ii = 0; ii < bibrecAuthors.Count; ii++)
            {
                author = bibrecAuthors[ii];
                // Insert Author
                StringArrayList treeAuthors = GetAuthors();
                if ((!treeAuthors.Contains(author)) && (author != null) && (author != ""))
                {
                    WriteLine(10, "Inserting Author {0} into Filter List", author);
                    AppendValues(iterAuth, author);
                }
            }

            // Iterate through tree and remove authors that are not in the bibtexRecords
            Gtk.TreeIter iter;
            var          treeAuth = new StringArrayList();

            IterChildren(out iter, iterAuth);
            int n = IterNChildren(iterAuth);

            for (int i = 0; i < n; i++)
            {
                string author1 = (string)GetValue(iter, 0);
                if (bibrecsAuthors.Contains(author1) && !treeAuth.Contains(author1))
                {
                    IterNext(ref iter);
                    treeAuth.Add(author1);
                }
                else
                {
                    WriteLine(10, "Removing Author {0} from Side Pane", author1);
                    Remove(ref iter);
                }
            }
        }
Пример #10
0
        protected override StringArrayList ExtractArchive()
        {
            StringArrayList ret = new StringArrayList();

            Ambertation.SevenZip.IO.CommandlineArchive a       = new Ambertation.SevenZip.IO.CommandlineArchive(this.ArchiveName);
            Ambertation.SevenZip.IO.ArchiveFile[]      content = a.ListContent();
            a.Extract(SimPe.Helper.SimPeTeleportPath, false);

            foreach (Ambertation.SevenZip.IO.ArchiveFile desc in content)
            {
                string rname = System.IO.Path.Combine(Helper.SimPeTeleportPath, desc.Name);
                if (System.IO.File.Exists(rname))
                {
                    ret.Add(rname);
                }
            }
            return(ret);
        }
Пример #11
0
        void InitialiseJournals()
        {
            string          journal;
            StringArrayList bibrecsJournals;

            bibrecsJournals = bibtexRecords.GetJournals();
            for (int ii = 0; ii < bibrecsJournals.Count; ii++)
            {
                journal = bibrecsJournals[ii];

                // Insert Journal
                StringArrayList treeJournals = GetJournals();
                if ((!treeJournals.Contains(journal)) && (journal != null) && (journal != ""))
                {
                    WriteLine(10, "Inserting Journal into Filter List");
                    AppendValues(iterJourn, journal);
                }
            }

            // Iterate through tree and remove journals that are not in the bibtexRecords
            var treeJourn = new StringArrayList();

            Gtk.TreeIter iter;
            IterChildren(out iter, iterJourn);
            int n = IterNChildren(iterJourn);

            for (int i = 0; i < n; i++)
            {
                string journal1 = (string)GetValue(iter, 0);
                if (bibrecsJournals.Contains(journal1) && !treeJourn.Contains(journal1))
                {
                    IterNext(ref iter);
                    treeJourn.Add(journal1);
                }
                else
                {
                    WriteLine(10, "Removing Journal {0} from Side Pane", journal1);
                    Remove(ref iter);
                }
            }
        }
Пример #12
0
        void InitialiseYears()
        {
            string          year;
            StringArrayList bibrecsYear;

            bibrecsYear = bibtexRecords.GetYears();
            for (int ii = 0; ii < bibrecsYear.Count; ii++)
            {
                year = bibrecsYear[ii];

                // Insert Year
                StringArrayList treeYear = GetYears();
                if ((!treeYear.Contains(year)) && (year != null) && (year != ""))
                {
                    WriteLine(10, "Inserting Year into Filter List");
                    AppendValues(iterYear, year);
                }
            }

            // Iterate through tree and remove years that are not in the bibtexRecords
            Gtk.TreeIter iter;
            var          treeYr = new StringArrayList();

            IterChildren(out iter, iterYear);
            int n = IterNChildren(iterYear);

            for (int i = 0; i < n; i++)
            {
                string year1 = (string)GetValue(iter, 0);
                if (bibrecsYear.Contains(year1) && !treeYr.Contains(year1))
                {
                    IterNext(ref iter);
                    treeYr.Add(year1);
                }
                else
                {
                    WriteLine(10, "Removing Year {0} from Side Pane", year1);
                    Remove(ref iter);
                }
            }
        }
    // Read an unlimited number of String; return an ArrayList
    public static StringArrayList GetStrings( )
    {
        StringArrayList array = new StringArrayList( );
        string          oneLine;

        Console.WriteLine("Enter any number of strings, one per line; ");
        Console.WriteLine("Terminate with empty line: ");
        try
        {
            while ((oneLine = Console.ReadLine( )) != null && oneLine != "")
            {
                array.Add(oneLine);
            }
        }
        catch (IOException)
        {
            Console.WriteLine("Unexpected IO Exception has shortened amount read");
        }
        Console.WriteLine("Done reading");
        return(array);
    }
Пример #14
0
        StringArrayList GetJournals()
        {
            var journals = new StringArrayList();

            if (IterHasChild(iterJourn))
            {
                Gtk.TreeIter iter;
                IterChildren(out iter, iterJourn);
                while (IterIsValid(iter))
                {
                    string journal = (string)GetValue(iter, 0);
                    journals.Add(journal);
                    if (!IterNext(ref iter))
                    {
                        break;
                    }
                }
            }
            journals.Sort();
            return(journals);
        }
Пример #15
0
        StringArrayList GetYears()
        {
            var years = new StringArrayList();

            if (IterHasChild(iterYear))
            {
                Gtk.TreeIter iter;
                IterChildren(out iter, iterYear);
                while (IterIsValid(iter))
                {
                    string year = (string)GetValue(iter, 0);
                    years.Add(year);
                    if (!IterNext(ref iter))
                    {
                        break;
                    }
                }
            }
            years.Sort();
            return(years);
        }
Пример #16
0
        protected override StringArrayList ExtractArchive()
        {
            StringArrayList ret = new StringArrayList();

            SimPe.Packages.S2CPDescriptor[] content = SimPe.Packages.Sims2CommunityPack.Open(this.ArchiveName);

            foreach (SimPe.Packages.S2CPDescriptor desc in content)
            {
                string name = System.IO.Path.Combine(Helper.SimPeTeleportPath, desc.Name);
                string rname = name; int ct = 0;
                while (System.IO.File.Exists(rname))
                {
                    rname = System.IO.Path.Combine(Helper.SimPeTeleportPath, ct.ToString() + "_" + desc.Name);
                    ct++;
                }
                desc.Package.Save(rname);
                if (System.IO.File.Exists(rname))
                {
                    ret.Add(rname);
                }
            }
            return(ret);
        }
Пример #17
0
        private SimPe.StringArrayList SortFilesByType(SimPe.StringArrayList files)
        {
            SimPe.StringArrayList objects = new StringArrayList();
            SimPe.StringArrayList other   = new StringArrayList();
            foreach (string file in files)
            {
                SimPe.Cache.PackageType type = PackageInfo.ClassifyPackage(file);
                SimPe.Plugin.DownloadsToolFactory.TeleportFileIndex.AddIndexFromPackage(file);

                if (type == SimPe.Cache.PackageType.Object || type == SimPe.Cache.PackageType.MaxisObject || type == SimPe.Cache.PackageType.Sim)
                {
                    objects.Add(file);
                }
                else
                {
                    other.Add(file);
                }
            }
            objects.AddRange(other);
            other.Clear(); other = null;
            files.Clear(); files = null;

            return(objects);
        }
Пример #18
0
        public void UpdateTreeStore()
        {
            if (!threadLock)
            {
                threadLock = true;

                if (bibtexRecords != null)
                {
                    // Deal with authors
                    StringArrayList bibAuthors;
                    if (bibtexRecords.GetAuthors() == null)
                    {
                        bibAuthors = new StringArrayList();
                    }
                    else
                    {
                        bibAuthors = bibtexRecords.GetAuthors();
                    }
                    if (IterHasChild(iterAuth))
                    {
                        Gtk.TreeIter iter;
                        IterChildren(out iter, iterAuth);
                        int n = IterNChildren(iterAuth);
                        for (int i = 0; i < n; i++)
                        {
                            string author = (string)GetValue(iter, 0);
                            if (bibAuthors.Contains(author))
                            {
                                IterNext(ref iter);
                            }
                            else
                            {
                                WriteLine(10, "Removing Author {0} from Side Pane", author);
                                Remove(ref iter);
                            }
                        }
                        StringArrayList treeAuthors = GetAuthors();
                        for (int i = 0; i < bibAuthors.Count; i++)
                        {
                            if (!(treeAuthors.Contains(bibAuthors [i])))
                            {
                                // Add bibAuthor to the TreeStore
                                if (bibAuthors [i] != "")
                                {
                                    WriteLine(10, "Inserting Author {0} to Side Pane", bibAuthors [i]);
                                    Gtk.TreeIter insert = InsertNode(iterAuth, i);
                                    SetValue(insert, 0, bibAuthors [i]);
                                }
                            }
                        }
                    }
                    else
                    {
                        WriteLine(10, "Generating Author Filter List");
                        for (int i = 0; i < bibAuthors.Count; i++)
                        {
                            if (bibAuthors [i] != "")
                            {
                                AppendValues(iterAuth, bibAuthors [i]);
                            }
                        }
                    }

                    // Deal with years
                    StringArrayList bibYears;
                    if (bibtexRecords.GetYears() == null)
                    {
                        bibYears = new StringArrayList();
                    }
                    else
                    {
                        bibYears = bibtexRecords.GetYears();
                    }

                    if (IterHasChild(iterYear))
                    {
                        Gtk.TreeIter iter;
                        IterChildren(out iter, iterYear);
                        for (int i = 0; i < IterNChildren(iterYear); i++)
                        {
                            string year = (string)GetValue(iter, 0);

                            if (bibYears.Contains(year))
                            {
                                IterNext(ref iter);
                            }
                            else
                            {
                                WriteLine(10, "Removing Year {0} from Side Pane", year);
                                Remove(ref iter);
                            }
                        }
                        StringArrayList treeYears = GetYears();
                        for (int i = 0; i < bibYears.Count; i++)
                        {
                            if (!(treeYears.Contains(bibYears [i])))
                            {
                                // Add bibYear to the TreeStore
                                if (bibYears [i] != "")
                                {
                                    WriteLine(10, "Inserting Year {0} to Side Pane", bibYears [i]);
                                    Gtk.TreeIter insert = InsertNode(iterYear, i);
                                    SetValue(insert, 0, bibYears [i]);
                                }
                            }
                        }
                    }
                    else
                    {
                        WriteLine(10, "Generating Year Filter List");
                        for (int i = 0; i < bibYears.Count; i++)
                        {
                            if (bibYears [i] != "")
                            {
                                AppendValues(iterYear, bibYears [i]);
                            }
                        }
                    }

                    // Deal with journals
                    StringArrayList bibJournals;
                    if (bibtexRecords.GetJournals() == null)
                    {
                        bibJournals = new StringArrayList();
                    }
                    else
                    {
                        bibJournals = bibtexRecords.GetJournals();
                    }

                    if (IterHasChild(iterJourn))
                    {
                        Gtk.TreeIter iter;
                        IterChildren(out iter, iterJourn);
                        for (int i = 0; i < IterNChildren(iterJourn); i++)
                        {
                            string journal = (string)GetValue(iter, 0);

                            if (bibYears.Contains(journal))
                            {
                                IterNext(ref iter);
                            }
                            else
                            {
                                WriteLine(10, "Removing Journal {0} from Side Pane", journal);
                                Remove(ref iter);
                            }
                        }
                        StringArrayList treeJournals = GetJournals();
                        for (int i = 0; i < bibJournals.Count; i++)
                        {
                            if (!(treeJournals.Contains(bibJournals [i])))
                            {
                                // Add bibYear to the TreeStore
                                if (bibJournals [i] != "")
                                {
                                    WriteLine(10, "Inserting Journal {0} to Side Pane", bibJournals [i]);
                                    Gtk.TreeIter insert = InsertNode(iterJourn, i);
                                    SetValue(insert, 0, bibJournals [i]);
                                }
                            }
                        }
                    }
                    else
                    {
                        WriteLine(10, "Generating Journal Filter List");
                        for (int i = 0; i < bibJournals.Count; i++)
                        {
                            if (bibJournals [i] != "")
                            {
                                AppendValues(iterJourn, bibJournals [i]);
                            }
                        }
                    }
                }
                threadLock = false;
            }
            else
            {
                WriteLine(2, "Thread is locked");
            }
        }