예제 #1
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (inputSourceID.Text.Length == 0)
            {
                MessageBox.Show("Invalid Novel Source ID", "Novel Source ID must not be empty", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!validSource)
            {
                MessageBox.Show("Please validate novel source first", "Invalid Novel Source ID", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (novelTitle != novel.NovelTitle)
            {
                DialogResult forceAddSourceResult = MessageBox.Show("Title for " + novel.NovelTitle + " is different from title found at specified source. Are you sure you want to add this source?", "Mismatch Title", MessageBoxButtons.YesNo);
                if (forceAddSourceResult == DialogResult.No)
                {
                    return;
                }
            }
            string message = "";
            bool   result  = novel.AddSource(source, true, out message);

            if (!result)
            {
                MessageBox.Show(message, "Invalid Source", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            BackgroundService.Instance.novelSourceController.RefreshSourceList();
            BackgroundService.Instance.novelSourceController.CloseAddSourceController();
        }
예제 #2
0
        /*============Public Function=======*/

        public Novel AddNovel(string novelTitle, ISource source, out string message)
        {
            foreach (Novel n in _novelList)
            {
                if (novelTitle.Equals(n.NovelTitle))
                {
                    message = novelTitle + " already exists.";
                    return(null);
                }
            }

            string newNovelLocation = Path.Combine(Configuration.Instance.NovelFolderLocation, novelTitle);

            if (!Directory.Exists(newNovelLocation))
            {
                Directory.CreateDirectory(newNovelLocation);
                Directory.CreateDirectory(Path.Combine(newNovelLocation, "audios"));
                Directory.CreateDirectory(Path.Combine(newNovelLocation, "texts"));
                File.Create(Path.Combine(newNovelLocation, Configuration.Instance.ReplaceSpecification));
                File.Create(Path.Combine(newNovelLocation, Configuration.Instance.DeleteSpecification));
            }
            else
            {
                if (!Directory.Exists(Path.Combine(newNovelLocation, "audios")))
                {
                    Directory.CreateDirectory(Path.Combine(newNovelLocation, "audios"));
                }

                if (!Directory.Exists(Path.Combine(newNovelLocation, "texts")))
                {
                    Directory.CreateDirectory(Path.Combine(newNovelLocation, "texts"));
                }

                if (!File.Exists(Path.Combine(newNovelLocation, Configuration.Instance.ReplaceSpecification)))
                {
                    File.Create(Path.Combine(newNovelLocation, Configuration.Instance.ReplaceSpecification));
                }

                if (!File.Exists(Path.Combine(newNovelLocation, Configuration.Instance.DeleteSpecification)))
                {
                    File.Create(Path.Combine(newNovelLocation, Configuration.Instance.DeleteSpecification));
                }
            }
            Novel newNovel = new Novel();

            using (var transaction = new TransactionScope())
            {
                try
                {
                    newNovel.NovelTitle        = novelTitle;
                    newNovel.LastReadChapterID = -1;
                    newNovel.State             = Novel.NovelState.Active;
                    newNovel.Reading           = false;
                    newNovel.Rank = GetNonDroppedNovelCount();
                    libraryData.Novels.InsertOnSubmit(newNovel);
                    libraryData.SubmitChanges();
                    newNovel.Initiate();
                    _novelList.Insert(GetNonDroppedNovelCount(), newNovel);
                    UpdateNovelRanking();
                    string msg;
                    newNovel.AddSource(source, false, out msg);
                    transaction.Complete();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Unable to add novel");
                    Console.WriteLine(e.ToString());
                    message = "Unable to add novel " + novelTitle;
                    return(null);
                }
            }

            message = novelTitle + " successfully added.";
            return(newNovel);
        }