Esempio n. 1
0
 void NotifyMessage(WikiMedia.ExportNotify notify, string msg)
 {
     if (notify != null)
     {
         notify(msg);
     }
 }
Esempio n. 2
0
        public void Export(WikiMedia.ExportNotify notify)
        {
            string expCategory = "Category:" + iCategory.Text.Trim();

            if (cbIndex.Checked)
            {
                NotifyMessage(notify, "Index of " + expCategory + "\n");
                int size   = 350;
                int paging = 5;
                Int32.TryParse(iIndexSize.Text, out size);
                Int32.TryParse(iIndexPaging.Text, out paging);
                converter.ExportIndex(expCategory, iIndexName.Text, paging, size, notify);
            }
            if (cbSummary.Checked)
            {
                NotifyMessage(notify, "Summary of " + expCategory + "\n");
                int paging = 24;
                Int32.TryParse(iSummaryPaging.Text, out paging);
                converter.ExportSummary(expCategory, iSummaryName.Text, iSummaryIndex.Text, paging, extractors[iExtractor.SelectedIndex].Export, notify);
            }
            if (cbPages.Checked)
            {
                NotifyMessage(notify, "Pages of " + expCategory + "\n");
                converter.ExportPages(expCategory, iPagesDir.Text, notify);
            }
        }
        public void Export(WikiMedia.ExportNotify notify)
        {
            string expCategory = "Category:" + iCategory.Text.Trim();

            if (cbContacts.Checked)
            {
                NotifyMessage(notify, "Contacts of " + expCategory + "\n");
                contacts.Export(notify, expCategory, iContactsName.Text);
            }
        }
 public void Process(WikiDocument doc, WikiMedia.ExportNotify notify)
 {
     foreach (string name in blacklist)
     {
         WikiHeader header = doc.FindHeader(name);
         if (header != null)
         {
             notify("E\t" + doc.title + "\tInvalid header: " + name + "\n");
         }
     }
 }
 public void Process(WikiDocument doc, WikiMedia.ExportNotify notify)
 {
     foreach (string name in requiredNames)
     {
         WikiHeader header = doc.FindHeader(name);
         if (header == null)
         {
             notify("E\t" + doc.title + "\tMissing header: " + name + "\n");
         }
     }
 }
Esempio n. 6
0
        //Export pages present in a Wiki Category
        public void ExportPages(string expCat, string expDir, WikiMedia.ExportNotify expNotify)
        {
            PageList pl = wiki.GetPages(expCat);

            string[] pages = new string[pl.Count()];
            for (int i = 0; i < pl.Count(); i++)
            {
                Page page = pl[i];
                pages[i] = GetTitle(page);
            }
            ExportPages(pages, expDir, expNotify);
        }
        public void Process(WikiDocument doc, WikiMedia.ExportNotify notify)
        {
            WikiHeader header;

            header = doc.FindHeader("Contact Information");
            if (header != null)
            {
                foreach (string line in header.text)
                {
                    if (line.EndsWith("http://"))
                    {
                        notify("E\t" + doc.title + "\tInvalid header: Contact Information\n");
                    }
                }
            }
        }
Esempio n. 8
0
        public void Replace(string category, string[,] replaces, WikiMedia.ExportNotify notify)
        {
            Regex[]  re = CalcRegex(replaces);
            PageList pl = GetPages(category);

            foreach (Page page in pl)
            {
                page.Load();
                string text = DoRegex(page.text, re, replaces);
                if (!text.Equals(page.text))
                {
                    notify(page.title);
                    page.text = text;
                    page.Save();
                }
            }
        }
Esempio n. 9
0
 public void CreatePages(string template, string[] lines, WikiMedia.ExportNotify notify)
 {
     char[]   sep = { '\t' };
     string[] val = null;
     for (int i = 0; i < lines.Length; i++)
     {
         string[] fld = lines[i].Split(sep);
         val = new string[fld.Length];
         string pageName = GetPageName(fld[0].Trim());
         string msg      = pageName;
         if (!string.IsNullOrEmpty(pageName))
         {
             int cnt = fld.Length;
             for (int j = 0; j < val.Length; j++)
             {
                 string vl = null;
                 if (j < fld.Length)
                 {
                     vl = fld[j];
                 }
                 if (vl == null)
                 {
                     vl = "";
                 }
                 val[j] = vl;
             }
             Page p = new Page(site, pageName);
             p.Load();
             if (!p.Exists())
             {
                 msg   += " created";
                 p.text = string.Format(template, val);
                 p.Save();
             }
             else
             {
                 msg += " skipped";
             }
             notify(msg);
         }
     }
 }
Esempio n. 10
0
        //Export a set of Wiki pages into several Power Point slides (saved into export directory)
        public void ExportPages(string[] pages, string expDir, WikiMedia.ExportNotify expNotify)
        {
            Page         page;
            Document     doc;
            Presentation pres;
            string       outPath = BuildPath(expDir);

            foreach (string title in pages)
            {
                if (String.IsNullOrEmpty(title))
                {
                    continue;
                }
                if (expNotify != null)
                {
                    expNotify(title);
                }
                page = wiki.GetPage(title);
                page.LoadHTML();
                if (!String.IsNullOrEmpty(page.text))
                {
                    doc  = HTML2Model.Convert(page.text);
                    pres = new Presentation(fTemplatePath);
                    Page2Slide(pres, doc, title, true);
                    StringBuilder fileName = new StringBuilder(title.Length);
                    for (int i = 0; i < title.Length; i++)
                    {
                        char c = title[i];
                        if ("\\:/".IndexOf(c) == -1)
                        {
                            fileName.Append(c);
                        }
                    }
                    pres.Save(outPath + fileName.ToString() + ".ppt");
                    pres.Close();
                }
            }
        }
Esempio n. 11
0
 public void Process(string[] pages, string[,] replaces, WikiProcessor[] procs, WikiErrorCheck[] checks, bool preview, bool save, WikiMedia.ExportNotify notify)
 {
     Regex[] re = CalcRegex(replaces);
     foreach (string pageName in pages)
     {
         if (!String.IsNullOrEmpty(pageName))
         {
             Page page = new Page(site, pageName);
             page.Load();
             if (!String.IsNullOrEmpty(page.text))
             {
                 string text = page.text.Trim();
                 page.text = text;
                 text      = DoRegex(page.text, re, replaces);
                 WikiDocument doc = new WikiDocument(pageName, text);
                 foreach (WikiProcessor p in procs)
                 {
                     p.Process(doc);
                 }
                 foreach (WikiErrorCheck check in checks)
                 {
                     check.Process(doc, notify);
                 }
                 text = doc.ToString().Trim();
                 if (!text.Equals(page.text))
                 {
                     notify("W\t" + pageName + "\tchanged \n");
                     if (preview)
                     {
                         char[]     sep     = { '\n' };
                         IDiffList  oldText = new DiffList_String(page.text, sep);
                         IDiffList  newText = new DiffList_String(text, sep);
                         double     time    = 0;
                         DiffEngine de      = new DiffEngine();
                         time = de.ProcessDiff(oldText, newText);
                         ArrayList rep = de.DiffReport();
                         Results   dlg = new Results(oldText, newText, rep, time);
                         dlg.Size          = new Size(1000, 700);
                         dlg.ShowInTaskbar = false;
                         dlg.StartPosition = FormStartPosition.Manual;
                         dlg.ShowDialog();
                         dlg.Dispose();
                     }
                     if (save)
                     {
                         try {
                             page.text = text;
                             page.Save();
                         }
                         catch (Exception e) {
                             notify("E\t" + pageName + "\t" + e.Message + "\n");
                         }
                     }
                 }
                 else
                 {
                     notify("N\t" + pageName + "\t\n");
                 }
             }
             else
             {
                 notify("I\t" + pageName + "\t\n");
             }
         }
     }
 }
Esempio n. 12
0
        public void Export(WikiMedia.ExportNotify notify, string category, string outPath)
        {
            FileStream   outFile = new FileStream(outPath, FileMode.Create);
            StreamWriter writer  = new StreamWriter(outFile);

            writer.WriteLine(outlookHeader);
            PageList pl = wiki.GetPages(category);

            foreach (Page page in pl)
            {
                page.Load();
                string text = page.text;
                // Decodifica Company
                int       compBase = defContatto.Length;
                string[]  cats     = page.GetAllCategories(false);
                ArrayList comp     = new ArrayList();
                for (int i = 0; i < cats.Length; i++)
                {
                    if (!cats[i].Equals("Rubrica"))
                    {
                        comp.Add(cats[i]);
                    }
                }
                if (comp.Count == 0)
                {
                    comp.Add("");
                }
                string[] vals = new string[defContatto.Length + comp.Count];
                // Copia company
                for (int i = 0; i < comp.Count; i++)
                {
                    vals[compBase + i] = comp[i].ToString();
                }
                // Estrai campi
                for (int i = 0; i < defContatto.Length; i++)
                {
                    Match m = rRules[i].Match(text);
                    if (m.Success)
                    {
                        vals[i] = m.Groups[1].Captures[0].ToString().Trim();
                    }
                    else
                    {
                        vals[i] = "";
                    }
                }
                // FixUp
                if (String.IsNullOrEmpty(vals[7]) && !String.IsNullOrEmpty(vals[8]))
                {
                    vals[7] = vals[8];
                    vals[8] = "";
                }
                string[] tels   = { "", "", "" };
                int      telCnt = 0;
                if (!String.IsNullOrEmpty(vals[9]))
                {
                    tels[telCnt] = vals[9];
                    telCnt++;
                }
                if (!String.IsNullOrEmpty(vals[10]))
                {
                    tels[telCnt] = vals[10];
                    telCnt++;
                }
                if (!String.IsNullOrEmpty(vals[11]))
                {
                    tels[telCnt] = vals[11];
                    telCnt++;
                }
                if (telCnt == 1)
                {
                    vals[9]  = "";
                    vals[10] = tels[0];
                    vals[11] = "";
                }
                else if (telCnt == 2)
                {
                    vals[9]  = "";
                    vals[10] = tels[0];
                    vals[11] = tels[1];
                }
                // Export
                if (!String.IsNullOrEmpty(vals[1]))
                {
                    notify(vals[1]);
                    string row = String.Format(outlookFormat, vals);
                    writer.WriteLine(row);
                }
            }
            writer.Close();
        }
Esempio n. 13
0
        public void Export(WikiMedia.ExportNotify notify)
        {
            string outDir = iOutDir.Text;

            converter.ExportPages(iPages.Lines, outDir, notify);
        }
Esempio n. 14
0
        //Export a summary Presentation with all the pages present in a category
        //The summar is composed by an index (optional) and a slide for each page
        //the slide content will be detemined by the expDetail delegate
        public void ExportSummary(string expCat, string outFileName, string expIdxName, int expPaging, ExportProc expDetail, WikiMedia.ExportNotify expNotify)
        {
            Presentation pres = new Presentation(fTemplatePath);
            PageList     pl   = wiki.GetPages(expCat);

            if (expIdxName != null)
            {
                Index2Slide(pres, pl, expIdxName, expPaging);
            }
            foreach (Page page in pl)
            {
                string title = GetTitle(page);
                if (title == null)
                {
                    continue;
                }
                if (expNotify != null)
                {
                    expNotify(page.title);
                }
                page.LoadHTML();
                Document doc = HTML2Model.Convert(page.text);
                expDetail(pres, doc, title);
            }
            pres.Save(fBasePath + outFileName);
            pres.Close();
        }
Esempio n. 15
0
        //Export all the pages in a Wiki category into a index presentation, each page
        //will contain up to expPagining summaries. A summary will be composed up to
        //descSize characters taken from the first Header of the Page
        public void ExportIndex(string expCat, string outFileName, int expPaging, int descSize, WikiMedia.ExportNotify expNotify)
        {
            Microsoft.Office.Interop.PowerPoint.Slide     slide     = null;
            Microsoft.Office.Interop.PowerPoint.TextRange textRange = null;
            Presentation pres = new Presentation(fTemplatePath);
            PageList     pl   = wiki.GetPages(expCat);
            int          cnt  = 0;

            foreach (Page page in pl)
            {
                string title = GetTitle(page);
                if (title == null)
                {
                    continue;
                }
                cnt++;
                if ((cnt % expPaging) == 1)
                {
                    slide     = pres.Add(Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText, GetTitleName(expCat));
                    textRange = slide.Shapes[2].TextFrame.TextRange;
                }
                if (expNotify != null)
                {
                    expNotify(page.title);
                }
                page.LoadHTML();
                Document doc = HTML2Model.Convert(page.text);
                AddFirstHeader(textRange, doc, page, title, descSize);
            }
            pres.Save(fBasePath + outFileName);
            pres.Close();
        }