public void Add(FictionObject fictionObject)
 {
     if (NotInList(fictionObject))
     {
         ProjectList.Add(fictionObject);
     }
 }
 private bool NotInList(FictionObject o)
 {
     foreach (FictionObject fictionObject in ProjectList)
     {
         if (fictionObject.Equals(o))
         {
             return(false);
         }
     }
     return(true);
 }
 public void Remove(FictionObject fictionObject)
 {
     foreach (FictionObject o in ProjectList)
     {
         if (o.Equals(fictionObject))
         {
             ProjectList.Remove(o);
             return;
         }
     }
 }
 public TranslateExecutor(FictionObject fictionObject, int totalCount, int mergeLimit, WorkingThread reportThread)
 {
     this.fictionObject  = fictionObject;
     this.reportThread   = reportThread;
     this.totalCount     = totalCount;
     this.mergeLimit     = mergeLimit;
     processCount        = 0;
     startPoint          = 0;
     originalStrings     = new List <string>();
     translateMap        = new Dictionary <int, string>();
     chapterTranslateMap = new Dictionary <int, string>();
     workingThreads      = new List <WorkingThread>();
 }
 public List <string> GetLinks(FictionObject fictionObject)
 {
     return(null);
 }
 public void Download(FictionObject fictionObject)
 {
 }
 public void CheckUpdate(FictionObject fictionObject)
 {
 }
        private void LoadProjects(string rootPath)
        {
            string[] file2s = Directory.GetFiles(rootPath, "*.fobj3");
            if (file2s != null && file2s.Length > 0)
            {
                bool loaded = false;

                foreach (string file in file2s)
                {
                    StreamReader writer = null;
                    try
                    {
                        writer = new StreamReader(file,
                                                  Encoding.UTF8, false);
                        var           serializer    = new Newtonsoft.Json.JsonSerializer();
                        FictionObject fictionObject = (FictionObject)serializer.Deserialize(writer, typeof(FictionObject));
                        fictionObject.RecalculatePreviousStepCount();
                        Add(fictionObject);
                        loaded = true;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    finally
                    {
                        if (writer != null)
                        {
                            writer.Close();
                        }
                        writer = null;
                    }
                    if (loaded)
                    {
                        return;
                    }
                }
            }
            string[] files = Directory.GetFiles(rootPath, "*.fobj");
            if (files != null && files.Length > 0)
            {
                Stream stream = null;
                foreach (string file in files)
                {
                    try
                    {
                        stream = File.Open(file, FileMode.Open);
                        BinaryFormatter bf = new BinaryFormatter();

                        FictionObject fictionObject = (FictionObject)bf.Deserialize(stream);
                        String        location      = fictionObject.Location;
                        int           lastIndex     = location.LastIndexOf("\\");
                        if (lastIndex > 0)
                        {
                            fictionObject.Location = location.Substring(lastIndex + 1);
                        }
                        else
                        {
                            fictionObject.Location = location;
                        }
                        fictionObject.RecalculatePreviousStepCount();
                        Add(fictionObject);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    finally
                    {
                        if (stream != null)
                        {
                            stream.Close();
                        }
                        stream = null;
                    }
                }
            }
        }
Exemple #9
0
        internal static string CleanContent(string original, FictionObject fictionObject)
        {
            if (fictionObject.HTMLLink.IndexOf("piaotian") >= 0 ||
                fictionObject.HTMLLink.IndexOf("69shu") >= 0)
            {
                int start = original.IndexOf("&nbsp;&nbsp;&nbsp;&nbsp;");
                // cannot found text, return as normal strip
                if (start == -1)
                {
                    return(StripHTML(original));
                }
                int end = original.IndexOf("</div>", start);
                if (end == -1)
                {
                    end = original.LastIndexOf(@"&nbsp;&nbsp;&nbsp;&nbsp;");
                    end = original.IndexOf("\n", end);
                }
                string subContent = original.Substring(start, end - start);
                return(StripHTML(subContent));
            }
            else if (fictionObject.HTMLLink.IndexOf("quledu") >= 0)
            {
                string startSign = "<div id=\"htmlContent\" class=\"contentbox\"";
                int    start     = original.IndexOf(startSign);
                if (start != -1)
                {
                    int end = original.IndexOf("</div>", start);
                    if (end != -1)
                    {
                        string subContent = original.Substring(start, end - start);
                        return(StripHTML(subContent.Substring(startSign.Length)));
                    }
                    else
                    {
                        return(StripHTML(original));
                    }
                }
                else
                {
                    return(StripHTML(original));
                }
            }
            else if (fictionObject.HTMLLink.IndexOf("uukanshu") > 0)
            {
                HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument();
                htmlDocument.LoadHtml(original);
                var node = htmlDocument.DocumentNode.SelectSingleNode("//div[@id=\"contentbox\"]");
                if (node != null)
                {
                    string text = node.InnerText;
                    text = text.Replace("<br/>", "\r\n");

                    return(StripHTML(text));
                }
                else
                {
                    return(StripHTML(original));
                }
            }
            else if (fictionObject.HTMLLink.IndexOf("17k.com") > 0)
            {
                HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument();
                htmlDocument.LoadHtml(original);
                var node = htmlDocument.DocumentNode.SelectSingleNode("//div[@id=\"chapterContentWapper\"]");
                if (node != null)
                {
                    string text = node.InnerText;
                    text = text.Replace("<br/>", "\r\n");
                    text = text.Replace("< br />", "\r\n");
                    return(StripHTML(text));
                }
                else
                {
                    return(StripHTML(original));
                }
            }
            else
            {
                return(StripHTML(original));
            }
        }
Exemple #10
0
        private void LoadProjects(string rootPath)
        {
            string[] file2s = Directory.GetFiles(rootPath, "*.fobj3");
            if (file2s != null && file2s.Length > 0)
            {
                bool   loaded = false;
                Stream stream = null;
                foreach (string file in file2s)
                {
                    try
                    {
                        StreamReader writer = new StreamReader(file,
                                                               Encoding.UTF8, false);
                        var           serializer    = new Newtonsoft.Json.JsonSerializer();
                        FictionObject fictionObject = (FictionObject)serializer.Deserialize(writer, typeof(FictionObject));

                        //stream = File.Open(file, FileMode.Open);
                        ////BinaryFormatter bf = new BinaryFormatter();

                        ////FictionObject fictionObject = (FictionObject)bf.Deserialize(stream);
                        //var streamReader = new StreamReader(stream);
                        //var reader = new TypeSerializer<FictionObject>();
                        //FictionObject fictionObject = reader.DeserializeFromReader(streamReader);
                        fictionObject.RecalculatePreviousStepCount();
                        Add(fictionObject);
                        writer.Close();
                        loaded = true;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    finally
                    {
                        if (stream != null)
                        {
                            stream.Close();
                        }
                        stream = null;
                    }
                    if (loaded)
                    {
                        return;
                    }
                }
            }
            string[] files = Directory.GetFiles(rootPath, "*.fobj");
            if (files != null && files.Length > 0)
            {
                Stream stream = null;
                foreach (string file in files)
                {
                    try
                    {
                        stream = File.Open(file, FileMode.Open);
                        BinaryFormatter bf = new BinaryFormatter();

                        FictionObject fictionObject = (FictionObject)bf.Deserialize(stream);
                        fictionObject.RecalculatePreviousStepCount();
                        Add(fictionObject);
                    }
                    catch (Exception)
                    {
                    }
                    finally
                    {
                        if (stream != null)
                        {
                            stream.Close();
                        }
                        stream = null;
                    }
                }
            }

            /*string[] paths = Directory.GetDirectories(rootPath);
             * if(paths == null || paths.Length == 0)
             * {
             *  return;
             * }
             * foreach (string path in paths)
             * {
             *  LoadProjects(path);
             * }*/
        }