public Chapter Add(Chapter chapterToAdd) { this.chapterRepository.Add(chapterToAdd); this.chapterRepository.Save(); return chapterToAdd; }
protected void ddlChapters_DataBound(object sender, EventArgs e) { //get right chapter by ID taken from ddlChapters.SelectedValue chap = chap.GetById(new Guid(ddlChapters.SelectedValue)); //call loadChapterContent loadChapterContent(chap.Title, chap.ChapterContent); }
public IEnumerable<IChapter> GetChapters() { List<Chapter> retVal = new List<Chapter>(); string content = Utility.GetContent(url); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(content); doc.DocumentNode.SelectNodes("//table[@id=\"listing\"]//tr") .Skip(1) .ToList() .ForEach(ch => { Chapter chapter = new Chapter { Number = getNumber(ch), Title = getName(ch), Uri = getUrl(ch) }; retVal.Add(chapter); }); return retVal; }
internal Page(Chapter a_chapter, string url, int index, ulong id, string name, byte[] hash, string imageFilePath, PageState pageState) : base(id) { Hash = hash; ImageFilePath = imageFilePath; _pageState = pageState; Chapter = a_chapter; URL = HtmlDecode(url); Index = index; if (State == PageState.Downloading) _pageState = PageState.Initial; if (State == PageState.Waiting) _pageState = PageState.Initial; if (name != "") { name = name.Trim(); name = name.Replace("\t", " "); while (name.IndexOf(" ") != -1) name = name.Replace(" ", " "); name = HtmlDecode(name); Name = FileUtils.RemoveInvalidFileCharacters(name); } else Name = Index.ToString(); }
internal override IEnumerable<Page> DownloadPages(Chapter a_chapter) { HtmlDocument doc = DownloadDocument(a_chapter); var pages = doc.DocumentNode.SelectNodes("//select[@name='pagejump']/option"); var result = new List<Page>(); int index = 0; foreach (var page in pages) { index++; string link = a_chapter.URL; int page_index = link.LastIndexOf("/page"); link = link.Left(page_index + 5); link += page.GetAttributeValue("Value", "") + ".html"; Page pi = new Page(a_chapter, link, index, ""); result.Add(pi); } if (result.Count == 0) throw new Exception("Chapter has no pages"); return result; }
public TrajectorySubParser_(Chapter chapter, Scene scene) : base(chapter) { this.trajectory = new Trajectory(); //scene.setTrajectory(trajectory); this.scene = scene; }
internal override IEnumerable<Page> DownloadPages(Chapter a_chapter) { HtmlDocument doc = DownloadDocument(a_chapter); List<Page> result = new List<Page>(); var top_center_bar = doc.DocumentNode.SelectSingleNode("//div[@id='top_center_bar']"); var pages = top_center_bar.SelectNodes("div[@class='r m']/div[@class='l']/select[@class='m']/option"); int index = 1; foreach (var page in pages) { if (page.NextSibling != null) { if (page.NextSibling.InnerText == "Comments") continue; } Page pi = new Page( a_chapter, a_chapter.URL.Replace("1.html", String.Format("{0}.html", page.GetAttributeValue("value", ""))), index, ""); index++; result.Add(pi); } if (result.Count == 0) throw new Exception("Chapter has no pages"); return result; }
// Use this for initialization public override void Init() { go = GameObject.Find("Pinball(Clone)"); if(go == null) { go = GameObject.Instantiate(Resources.Load("Prefabs/States/Pinball")) as GameObject; thisChapter = StateChapterSelect.Instance.Chapters[ID]; m_PinballMono = go.GetComponent<PinballMono>(); for (int i = 0; i < m_PinballMono.Levels.Length; i++) { m_PinballMono.Levels[i].SetActive(i == StateChapterSelect.Instance.Chapters[ID].LevelNumber); } if(thisChapter.Completed) return; if(ID == 0) { SetBucketPositions(); } else { RandomizeBucketPosition(); } m_PinballMono.SetFrameParent(true); m_PinballMono.SetCannonState(true); } }
internal Page(Chapter a_chapter, string a_url, int a_index, ulong a_id, string a_name, byte[] a_hash, string a_image_file_path, PageState a_state) : base(a_id) { Hash = a_hash; ImageFilePath = a_image_file_path; m_state = a_state; Chapter = a_chapter; URL = HtmlDecode(a_url); Index = a_index; if (State == PageState.Downloading) m_state = PageState.Initial; if (State == PageState.Waiting) m_state = PageState.Initial; if (a_name != "") { a_name = a_name.Trim(); a_name = a_name.Replace("\t", " "); while (a_name.IndexOf(" ") != -1) a_name = a_name.Replace(" ", " "); a_name = HtmlDecode(a_name); Name = FileUtils.RemoveInvalidFileCharacters(a_name); } else Name = Index.ToString(); }
internal override IPage[] GetPages(Chapter chapter, string mangaPageHtml) { var document = Parser.Parse(mangaPageHtml); var listNode = document.QuerySelectorAll("ul.dropdown-menu")[2]; var linksNodes = listNode.QuerySelectorAll("a"); var output = linksNodes.Select((d, e) => new Page(chapter, new Uri(d.Attributes["href"].Value), e + 1)).ToArray(); return output; }
public void AddShouldBeAbleToAddChapter() { Chapter chapter = new Chapter() { Title = "Chapter 1", Duration = TimeSpan.FromSeconds(30) }; this.list.Add(chapter); Assert.AreEqual(1, this.list.Count); Assert.AreEqual("Chapter 1", this.list[0].Title); Assert.AreEqual(TimeSpan.FromSeconds(30), this.list[0].Duration); Assert.AreEqual(chapter, this.list[0]); }
internal void Add(Chapter chapter) { if (_downloading.Contains(chapter)) return; var copy = _downloading.ToList(); copy.Add(chapter); _downloading = copy; }
internal override IPage[] GetPages(Chapter chapter, string mangaPageHtml) { var document = Parser.Parse(mangaPageHtml); var selectNode = document.QuerySelector("select#pageSelect"); var options = selectNode.QuerySelectorAll("option"); var output = options.Select((d, e) => new Page(chapter, new Uri(RootUri, d.Attributes["value"].Value), e + 1)).ToArray(); return output; }
internal void Add(Chapter a_chapter) { if (m_downloading.Contains(a_chapter)) return; var copy = m_downloading.ToList(); copy.Add(a_chapter); m_downloading = copy; }
internal override IPage[] GetPages(Chapter Chapter, string MangaPageHtml) { var Document = Parser.Parse(MangaPageHtml); var Node = Document.QuerySelector("#pages"); var Nodes = Node.QuerySelectorAll("option"); var Output = Nodes.Select((d, e) => new Page(Chapter, new Uri(RootUri, d.Attributes["value"].Value), e + 1)).OrderBy(d => d.PageNo); return Output.ToArray(); }
internal override IPage[] GetPages(Chapter Chapter, string MangaPageHtml) { var Document = Parser.Parse(MangaPageHtml); var Node = Document.QuerySelector("section.readpage_top"); Node = Node.QuerySelector("span.right select"); var Nodes = Node.QuerySelectorAll("option"); var Output = Nodes.Select((d, e) => new Page(Chapter, new Uri(RootUri, d.Attributes["value"].Value), e + 1)); return Output.ToArray(); }
internal override IEnumerable<Page> DownloadPages(Chapter chapter) { //var doc = DownloadDocument(chapter, chapter.URL + "/page/1"); //var doc = DownloadDocument(chapter); var doc = new HtmlDocument(); //var h = new HttpDownloader(chapter.URL, null, null); //doc.OptionReadEncoding = false; var request = (HttpWebRequest)WebRequest.Create(chapter.URL); request.Method = "GET"; //request.TransferEncoding = "utf-8"; using (var response = (HttpWebResponse)request.GetResponse()) { using (var stream = response.GetResponseStream()) { if (stream != null && stream.CanRead) { var stremReader = new StreamReader(stream/*, Encoding.UTF8*/); doc.LoadHtml(stremReader.ReadToEnd()); } } } var result = new List<Page>(); /*var test = document; return result;*/ /*if (!string.IsNullOrEmpty(document)) { var byteArray = Encoding.UTF8.GetBytes(document); var stream = new MemoryStream(byteArray); doc.Load(stream, Encoding.UTF8); }*/ var topbar_right = doc.DocumentNode.SelectSingleNode("//div[@class='topbar_right']"); //var title = (from tag in topbar_right.SelectNodes("./div") where tag.Attributes.Contains("class") && tag.Attributes["class"].Value.Contains("tbtitle") select tag).First(); var title = topbar_right.SelectSingleNode("./div[contains(@class, 'tbtitle dropdown_parent')]"); //return null; var pagesString = title.SelectSingleNode("./div[@class='text']").InnerHtml; var pages = Convert.ToInt32(pagesString.Substring(0, pagesString.IndexOf(' '))); for (var i = 0; i < pages; i++) { result.Add(new Page(chapter, chapter.URL + "/page/" + (i+1), i+1, "")); } if (result.Count == 0) throw new Exception("Chapter has no pages"); return result; }
protected void getReviews(HiddenField hidnValue, HyperLink hlReviews) { Guid storyID = new Guid(); storyID = new Guid(hidnValue.Value); Guid chapID = new Guid(); Chapter chap = new Chapter(); chap = chap.GetFirstByStoryID(storyID); chapID = chap.Id; String navUrl = "~/ReviewsPage.aspx?ChapterID=" + chapID + "&StoryID=" + storyID; hlReviews.NavigateUrl = navUrl; }
protected void ddlChapters_SelectedIndexChanged(object sender, EventArgs e) { //if statement that will run if ddlChapters selected index is greater or equal to zero if (ddlChapters.SelectedIndex >= 0) { //get chapter from Id taken from ddlChapters chap = chap.GetById(new Guid(this.ddlChapters.SelectedValue)); //call loadChapterContent, passing in the chap Title and ChapterContent loadChapterContent(chap.Title, chap.ChapterContent); } }
internal override IPage[] GetPages(Chapter chapter, string mangaPageHtml) { var document = Parser.Parse(mangaPageHtml); var selectorNode = document.QuerySelector("select#page-dropdown"); var optionNodes = selectorNode.QuerySelectorAll("option"); var chaptersRootUri = chapter.FirstPageUri.ToString(); chaptersRootUri = chaptersRootUri.Substring(0, chaptersRootUri.LastIndexOf("/")); var output = optionNodes.Select((d, e) => new Page(chapter, new Uri(string.Format("{0}/{1}", chaptersRootUri, d.TextContent.Trim())), e + 1)).ToArray(); return output; }
public async Task LoadAsync( Chapter C, bool Cache = true ) { if ( Cache && Shared.Storage.FileExists( C.ChapterPath ) ) { OnComplete( C ); } else if ( C is SChapter ) { // if this belongs to the spider SChapter SC = C as SChapter; await SC.SubProcRun( Cache ); if ( SC.TempFile != null ) { await new ContentParser().OrganizeBookContent( await SC.TempFile.ReadString() , SC ); } OnComplete( C ); } else { if ( !ProtoMode ) throw new InvalidOperationException( "ChapterLoader is in Bare mode" ); IRuntimeCache wCache = X.Instance<IRuntimeCache>( XProto.WRuntimeCache ); // Cancel thread if there is same job downloading App.RuntimeTransfer.CancelThread( C.ChapterPath ); // Initiate download, precache should not be done internally. wCache.InitDownload( C.ChapterPath , X.Call<XKey[]>( XProto.WRequest, "GetBookContent", CurrentBook.Id, C.cid ) , async ( DRequestCompletedEventArgs e, string path ) => { await new ContentParser().OrganizeBookContent( e.ResponseString, C ); OnComplete( C ); } , ( string Request, string path, Exception ex ) => { Logger.Log( ID, ex.Message, LogType.ERROR ); System.Utils.ShowError( () => { return new ErrorMessage().DOWNLOAD; } ); // OnComplete( C ); } , false ); } }
protected void btnSaveChanges_Click(object sender, EventArgs e) { //call editExistingChapter() editExistingChapter(); //if statement will run if chapter is savable if (chap.IsSavable() == true) { //save the chap chap = chap.Save(); //call loadChapterContent, passing in Title and ChapterContent properties of chap loadChapterContent(chap.Title, chap.ChapterContent); } }
public void init(object data) { chapter = (Chapter)data; if(chapter.isUnlocked()){ textName.text = Localization.instance.Get("UI_ChapterName_"+chapter.id); textStars.text = string.Format("{0}/{1}",chapter.winStars,chapter.passStars); lockedGroup.SetActive(false); unlockedGroup.SetActive(true); }else{ lockedGroup.SetActive(true); unlockedGroup.SetActive(false); } }
protected void btnAddChapter_Click(object sender, EventArgs e) { //call addNewChapter() addNewChapter(); //check to see if chap is savable if (chap.IsSavable() == true) { //if savable, save it chap = chap.Save(); //refresh page Response.Redirect("AddChapter.aspx"); } }
public void ChaptersWithNullSlidesAreEqual() { Chapter chapter1 = new Chapter("Chapter One") { Slides = null }; Chapter chapter2 = new Chapter(chapter1.Id, "Chapter One") { Slides = null }; Assert.Equal(chapter1, chapter2); }
public void AddChapter(Chapter chapter) { IT.Chapter tmp = new IT.Chapter(chapter.ChapterNumber); tmp.Title = new IT.Paragraph( chapter.Title ); //TODO : Add formatting foreach (var section in chapter.SubElements) { if (section is MultiColumnSection) { }else SectionFormatter.AddFormattedSection( (Section) section, tmp); } document.Add(tmp); }
public ActionResult Chapters_Destroy([DataSourceRequest]DataSourceRequest request, ChapterAdminViewModel chapter) { if (this.ModelState.IsValid) { var entity = new Chapter { Id = chapter.Id, IsDeleted = true }; this.chapterService.Update(entity); } return this.Json(new[] { chapter }.ToDataSourceResult(request, this.ModelState)); }
public void Update(Chapter entity) { var forUpdate = this.chapterRepository.All().FirstOrDefault(x => x.Id == entity.Id); forUpdate.IsDeleted = entity.IsDeleted; forUpdate.AuthorId = entity.AuthorId; forUpdate.Comments = new List<Comment>(entity.Comments); forUpdate.Content = entity.Content; forUpdate.ModifiedOn = entity.ModifiedOn; forUpdate.PreviousChapterId = entity.PreviousChapterId; forUpdate.StoryId = entity.StoryId; forUpdate.Title = entity.Title; this.chapterRepository.Save(); }
public ActionResult Create(Chapter chapter) { if (ModelState.IsValid) { chapter.CreatedDate = DateTime.Now; chapter.LastModifiedDate = DateTime.Now; db.Chapters.Add(chapter); db.SaveChanges(); return RedirectToAction("Chapters", "Dashboard", new { id = chapter.CourseId}); } ViewBag.ParentId = new SelectList(db.Chapters.Where(c=>c.CourseId == chapter.CourseId), "Id", "Title", chapter.ParentId); ViewBag.CourseId = chapter.CourseId; return View(chapter); }
internal override IChapter[] GetChapters(Series series, string seriesPageHtml) { var document = Parser.Parse(seriesPageHtml); var tableNode = document.QuerySelector("table.table-striped") as AngleSharp.Dom.Html.IHtmlTableElement; var rows = tableNode.QuerySelectorAll("tr").Skip(1); var output = rows.Select(d => { var linkNode = d.QuerySelector("a"); var datenode = d.QuerySelectorAll("td").Skip(1); var chapter = new Chapter(series, new Uri(linkNode.Attributes["href"].Value), linkNode.TextContent) { Updated = datenode.First().TextContent.Trim() }; return chapter; }).Reverse().ToArray(); return output; }
static public bool validateChapter(Chapter chapter) { return(chapter != null && chapter.Name != null && chapter.IDCourse != 0 && chapter.ChapterNumber != 0 && chapter.IDChapter != 0); }
public string FormateChapterFolder(Chapter chapter) { return(AppConfig.ChapterPrefix + " " + chapter.Number.ToString(CultureInfo.InvariantCulture).PadLeft(chapter.Number % 1 == 0 ? 4 : 6, '0')); }
public abstract Task <IEnumerable <string> > FindImages(Chapter chapter, IProgress <int> progress, CancellationToken cancellationToken);
/// <summary> /// Performs a JSON-to-Object conversion. /// </summary> /// <param name="reader"> /// A JsonReader object. /// </param> /// <param name="objectType"> /// The type of the object. /// </param> /// <param name="existingValue"> /// The existing value. /// </param> /// <param name="serializer"> /// A JsonSerializer object. /// </param> /// <returns> /// A converted object. /// </returns> public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { const string ITEM_TYPE_KEY = "ItemType"; const string ARGUMENT_EXCEPTON = "Invalid Or Missing ItemType"; ContentItem contentItem = null; ItemType itemType = ItemType.Unknown; JObject jObject = JObject.Load(reader); JToken jToken = null; if (jObject.TryGetValue(ITEM_TYPE_KEY, StringComparison.CurrentCultureIgnoreCase, out jToken) && jToken != null && Enum.TryParse(jToken.Value <string>(), true, out itemType)) { switch (itemType) { case ItemType.Unknown: throw new ArgumentException(ARGUMENT_EXCEPTON); case ItemType.Book: contentItem = new Book(); break; case ItemType.Chapter: contentItem = new Chapter(); break; case ItemType.Journal: contentItem = new Journal(); break; case ItemType.Magazine: contentItem = new Magazine(); break; case ItemType.Newspaper: contentItem = new Newspaper(); break; case ItemType.Webpage: contentItem = new Webpage(); break; case ItemType.Encyclopedia: contentItem = new Encyclopedia(); break; case ItemType.Graphic: contentItem = new Graphic(); break; case ItemType.AudioRecording: contentItem = new AudioRecording(); break; case ItemType.VideoRecording: contentItem = new VideoRecording(); break; case ItemType.Broadcast: contentItem = new Broadcast(); break; case ItemType.PersonalCommunication: contentItem = new PersonalCommunication(); break; case ItemType.Interview: contentItem = new Interview(); break; case ItemType.Presentation: contentItem = new Presentation(); break; case ItemType.Map: contentItem = new Map(); break; case ItemType.Bill: contentItem = new Bill(); break; case ItemType.Legislation: contentItem = new Legislation(); break; case ItemType.LegalCase: contentItem = new LegalCase(); break; case ItemType.Report: contentItem = new Report(); break; case ItemType.ConferencePaper: contentItem = new ConferencePaper(); break; default: throw new NotImplementedException(); } } else { throw new ArgumentException(ARGUMENT_EXCEPTON); } if (serializer != null) { serializer.Populate(jObject.CreateReader(), contentItem); } return(contentItem); }
private List <SOTable> Export(DbSchema schema, SODatabase db, List <SOTable> tableList, ExportTyep exportType) { if (schema == null) { throw new ArgumentException("参数schema不能为空", "schema"); } if (db == null) { throw new ArgumentException("参数dbName不能为空", "dbName"); } Document doc = new Document(PageSize.A4.Rotate(), 20, 20, 20, 20); DocWriter w; switch (exportType) { case ExportTyep.PDF: w = PdfWriter.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write)); break; case ExportTyep.RTF: w = RtfWriter2.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write)); break; //case ExportTyep.HTML: // w = HtmlWriter.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write)); //break; default: break; } doc.Open(); doc.NewPage(); if (tableList == null) { tableList = schema.GetTableList(db); } Chapter cpt = new Chapter(db.Name, 1); Section sec; doc.AddTitle(db.Name); doc.AddAuthor("Kalman"); doc.AddCreationDate(); doc.AddCreator("Kalman"); doc.AddSubject("数据库文档"); foreach (SOTable table in tableList) { sec = cpt.AddSection(new Paragraph(table.Name, font)); if (string.IsNullOrEmpty(table.Comment) == false) { Chunk chunk = new Chunk(table.Comment, font); sec.Add(chunk); } List <SOColumn> columnList = schema.GetTableColumnList(table); t = new Table(7, columnList.Count); t.AutoFillEmptyCells = true; t.CellsFitPage = true; t.TableFitsPage = true; t.Cellpadding = 3; //if (exportType == ExportTyep.PDF) t.Cellspacing = 2; t.DefaultVerticalAlignment = Element.ALIGN_MIDDLE; t.SetWidths(new int[] { 200, 150, 50, 50, 50, 100, 300 }); t.AddCell(BuildHeaderCell("名称")); t.AddCell(BuildHeaderCell("数据类型")); t.AddCell(BuildHeaderCell("主键")); t.AddCell(BuildHeaderCell("标志")); t.AddCell(BuildHeaderCell("可空")); t.AddCell(BuildHeaderCell("默认值")); t.AddCell(BuildHeaderCell("注释")); foreach (SOColumn column in columnList) { t.AddCell(BuildCell(column.Name)); t.AddCell(BuildCell(GetDbColumnType(column))); t.AddCell(BuildCell(column.PrimaryKey ? " √" : "")); t.AddCell(BuildCell(column.Identify ? " √" : "")); t.AddCell(BuildCell(column.Nullable ? " √" : "")); t.AddCell(BuildCell(column.DefaultValue == null ? "" : column.DefaultValue.ToString())); t.AddCell(BuildCell(column.Comment)); } sec.Add(t); } doc.Add(cpt); doc.Close(); return(tableList); }
//public void PDModel2Html(PDModel m) //{ // Export(m, ExportTyep.HTML); //} private void Export(IList <PDTable> tableList, string title, ExportTyep exportType) { Document doc = new Document(PageSize.A4.Rotate(), 20, 20, 20, 20); DocWriter w; switch (exportType) { case ExportTyep.PDF: w = PdfWriter.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write)); break; case ExportTyep.RTF: w = RtfWriter2.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write)); break; //case ExportTyep.HTML: // w = HtmlWriter.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write)); //break; default: break; } doc.Open(); doc.NewPage(); //IList<PDTable> tableList = m.AllTableList; //Chapter cpt = new Chapter(m.Name, 1); Chapter cpt = new Chapter(title, 1); Section sec; //doc.AddTitle(m.Name); doc.AddTitle(title); doc.AddAuthor("Kalman"); doc.AddCreationDate(); doc.AddCreator("Kalman"); doc.AddSubject("PDM数据库文档"); foreach (PDTable table in tableList) { sec = cpt.AddSection(new Paragraph(string.Format("{0}[{1}]", table.Name, table.Code), font)); if (string.IsNullOrEmpty(table.Comment) == false) { Chunk chunk = new Chunk(table.Comment, font); sec.Add(chunk); } t = new Table(9, table.ColumnList.Count); //t.Border = 15; //t.BorderColor = Color.BLACK; //t.BorderWidth = 1.0f; t.AutoFillEmptyCells = true; t.CellsFitPage = true; t.TableFitsPage = true; t.Cellpadding = 3; //if (exportType == ExportTyep.PDF) t.Cellspacing = 2; t.DefaultVerticalAlignment = Element.ALIGN_MIDDLE; t.SetWidths(new int[] { 200, 200, 150, 50, 50, 50, 50, 50, 300 }); t.AddCell(BuildHeaderCell("名称")); t.AddCell(BuildHeaderCell("代码")); t.AddCell(BuildHeaderCell("数据类型")); t.AddCell(BuildHeaderCell("长度")); t.AddCell(BuildHeaderCell("精度")); t.AddCell(BuildHeaderCell("主键")); t.AddCell(BuildHeaderCell("外键")); t.AddCell(BuildHeaderCell("可空")); t.AddCell(BuildHeaderCell("注释")); foreach (PDColumn column in table.ColumnList) { t.AddCell(BuildCell(column.Name)); t.AddCell(BuildCell(column.Code)); t.AddCell(BuildCell(column.DataType)); t.AddCell(BuildCell(column.Length == 0 ? "" : column.Length.ToString())); t.AddCell(BuildCell(column.Precision == 0 ? "" : column.Precision.ToString())); t.AddCell(BuildCell(column.IsPK ? " √" : "")); t.AddCell(BuildCell(column.IsFK ? " √" : "")); t.AddCell(BuildCell(column.Mandatory ? "" : " √")); t.AddCell(BuildCell(column.Comment)); } sec.Add(t); } doc.Add(cpt); doc.Close(); }
public void OnUnZipComplete() { if (processingTask != null) { if (processingTask.type == TaskType.Model) { ModelItem Model = DlcMng.Ins.GetModelMeta(processingTask.index); if (Model != null) { string[] files = System.IO.Directory.GetFiles(Model.LocalPath.Substring(0, Model.LocalPath.Length - 4), "*.*", System.IO.SearchOption.AllDirectories); if (Model.resPath == null) { Model.resPath = new List <string>(); } if (Model.resCrc == null) { Model.resCrc = new List <string>(); } Model.resPath.Clear(); Model.resCrc.Clear(); for (int i = 0; i < files.Length; i++) { Model.resPath.Add(files[i].Replace("\\", "/")); Model.resCrc.Add(Utility.getFileHash(files[i])); } Model.Installed = true; GameStateMgr.Ins.gameStatus.RegisterModel(Model); } } else if (processingTask.type == TaskType.Chapter) { Chapter Chapter = DlcMng.Ins.GetChapterMeta(processingTask.index); if (Chapter != null) { string[] files = System.IO.Directory.GetFiles(Chapter.LocalPath.Substring(0, Chapter.LocalPath.Length - 4), "*.*", System.IO.SearchOption.AllDirectories); if (Chapter.resPath == null) { Chapter.resPath = new List <string>(); } if (Chapter.resCrc == null) { Chapter.resCrc = new List <string>(); } if (Chapter.Res == null) { Chapter.Res = new List <ReferenceItem>(); } Chapter.resPath.Clear(); Chapter.resCrc.Clear(); Chapter.Res.Clear(); for (int i = 0; i < files.Length; i++) { //Debug.Log(files[i]); System.IO.FileInfo fi = new System.IO.FileInfo(files[i]); ReferenceItem template = new ReferenceItem(); template.Name = fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length); template.Path = files[i].Replace("\\", "/"); if (fi.Extension.ToLower() == ".txt") { if (fi.FullName.Contains("npc/") || fi.FullName.Contains("npc\\")) { template.Type = FileExt.Txt; } } else if (fi.Extension.ToLower() == ".pos") //动画分段配置 { template.Type = FileExt.Pos; } else if (fi.Extension.ToLower() == ".des") //关卡配置 { template.Type = FileExt.Des; } else if (fi.Extension.ToLower() == ".skc") //角色皮肤 { template.Type = FileExt.Skc; } else if (fi.Extension.ToLower() == ".bnc") //角色骨架 { template.Type = FileExt.Bnc; } else if (fi.Extension.ToLower() == ".png") //贴图 { template.Type = FileExt.Png; } else if (fi.Extension.ToLower() == ".jpg") //贴图 { template.Type = FileExt.Jpeg; } else if (fi.Extension.ToLower() == ".amb") //动画 { template.Type = FileExt.Amb; } else if (fi.Extension.ToLower() == ".wp") //路点 { template.Type = FileExt.WayPoint; } else if (fi.Extension.ToLower() == ".gmc") //模型 { template.Type = FileExt.Gmc; } else if (fi.Extension.ToLower() == ".fmc") //动画 { template.Type = FileExt.Fmc; } else if (fi.Extension.ToLower() == ".gmb") //模型 { template.Type = FileExt.Gmc; } else if (fi.Extension.ToLower() == ".ef") //特效 { template.Type = FileExt.Sfx; } else if (fi.Extension.ToLower() == ".dll") //特效 { template.Type = FileExt.Dll; } else if (fi.Extension.ToLower() == ".json") //特效 { template.Type = FileExt.Json; } else if (fi.Extension.ToLower() == ".mp3") { template.Type = FileExt.MP3; } Chapter.Res.Add(template); Chapter.resPath.Add(files[i].Replace("\\", "/")); Chapter.resCrc.Add(Utility.getFileHash(files[i])); } Chapter.Installed = true; GameStateMgr.Ins.gameStatus.RegisterDlc(Chapter); } } GameStateMgr.Ins.SaveState(); processingTask.state = TaskStatus.Installed; //刷新一下各个任务的状态. if (DlcManagerDialogState.Exist) { DlcManagerDialogState.Instance.OnRefresh(processingTask.index, processingTask.type); } if (client != null) { client.Dispose(); client = null; } if (processingTask != null) { RemoveTask(processingTask.type, processingTask.index); } processingTask = null; processing = false; } }
public void Update() { if (!processing) { //下载预览图任务 if (Tasks.Count != 0) { processingTask = Tasks[0]; if (processingTask.type == TaskType.ModelPreview) { ModelItem it = DlcMng.Ins.GetModelMeta(processingTask.index); if (it != null) { //如果该封面已经下载过,并且存储到本地了,那么从本地读取 if (File.Exists(it.Preview)) { System.IO.FileStream fs = new System.IO.FileStream(it.Preview, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite, System.IO.FileShare.None); byte[] bitIcon = new byte[fs.Length]; fs.Read(bitIcon, 0, (int)fs.Length); fs.Close(); if (processingTask != null && processingTask.OnComplete != null) { processingTask.OnComplete.Invoke(null, null); } processingTask = null; Tasks.RemoveAt(0); return; } //如果该封面没有下载过.开始下载 processing = true; string urlIconPreview = Main.Ins.baseUrl + it.webPreview; try { if (client == null) { client = new WebClient(); client.DownloadDataCompleted += OnDownloadPreviewComplete; } client.DownloadDataAsync(new Uri(urlIconPreview)); } catch { processing = false; } return; } } else if (processingTask.type == TaskType.ChapterPreview) { //dlc的预览图. Chapter cha = DlcMng.Ins.GetChapterMeta(processingTask.index); //如果该封面已经下载过,并且存储到本地了,那么从本地读取 if (File.Exists(cha.Preview)) { System.IO.FileStream fs = new System.IO.FileStream(cha.Preview, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite, System.IO.FileShare.None); byte[] bitIcon = new byte[fs.Length]; fs.Read(bitIcon, 0, (int)fs.Length); fs.Close(); //Texture2D tex = new Texture2D(200, 150); //tex.LoadImage(bitIcon); //processingTask.Preview.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero); if (processingTask != null && processingTask.OnComplete != null) { processingTask.OnComplete.Invoke(null, null); } processingTask = null; Tasks.RemoveAt(0); return; } processing = true; string urlIconPreview = Main.Ins.baseUrl + cha.webPreview; try { if (client == null) { client = new WebClient(); client.DownloadDataCompleted += OnDownloadPreviewComplete; } client.DownloadDataAsync(new Uri(urlIconPreview)); } catch { processing = false; } } else if (processingTask.type == TaskType.Model) { processing = true; processingTask.state = TaskStatus.Normal; ModelItem it = DlcMng.Ins.GetModelMeta(processingTask.index); if (client == null) { client = new WebClient(); client.DownloadProgressChanged += this.DownLoadProgressChanged; client.DownloadFileCompleted += this.DownLoadFileCompleted; string downloadUrl = Main.Ins.baseUrl + it.Path; client.DownloadFileAsync(new System.Uri(downloadUrl), it.LocalPath); } } else if (processingTask.type == TaskType.Chapter) { processing = true; processingTask.state = TaskStatus.Normal; Chapter cha = DlcMng.Ins.GetChapterMeta(processingTask.index); //dlc的下载. if (client == null) { client = new WebClient(); client.DownloadProgressChanged += this.DownLoadProgressChanged; client.DownloadFileCompleted += this.DownLoadFileCompleted; string downloadUrl = Main.Ins.baseUrl + cha.Path; client.DownloadFileAsync(new System.Uri(downloadUrl), cha.LocalPath); } } } } lock (handler) { for (int i = 0; i < handler.Count; i++) { handler[i].Invoke(); } handler.Clear(); } }
private void OnDownloadPreviewComplete(object sender, DownloadDataCompletedEventArgs e) { lock (handler) { handler.Add(() => { if (e.Error != null) { if (client != null) { client.Dispose(); client = null; } if (processingTask != null) { RemoveTask(processingTask.type, processingTask.index); } processingTask = null; processing = false; } else { if (processingTask == null) { processing = false; return; } byte[] bitIcon = e.Result; if (bitIcon != null && bitIcon.Length != 0) { if (processingTask.type == TaskType.ModelPreview) { ModelItem model = DlcMng.Ins.GetModelMeta(processingTask.index); if (model != null) { try { System.IO.File.WriteAllBytes(model.Preview, bitIcon); } catch (Exception exp) { UnityEngine.Debug.Log(exp.Message); } //刷新UI if (processingTask.OnComplete != null) { processingTask.OnComplete.Invoke(null, null); } client.Dispose(); client = null; if (processingTask != null) { RemoveTask(processingTask.type, processingTask.index); } processingTask = null; processing = false; } } else if (processingTask.type == TaskType.ChapterPreview) { Chapter chapter = DlcMng.Ins.GetChapterMeta(processingTask.index); if (chapter != null) { if (bitIcon != null && bitIcon.Length != 0) { System.IO.File.WriteAllBytes(chapter.Preview, bitIcon); } if (processingTask.OnComplete != null) { processingTask.OnComplete.Invoke(null, null); } client.Dispose(); client = null; if (processingTask != null) { RemoveTask(processingTask.type, processingTask.index); } processingTask = null; processing = false; } } } } }); } }
//取得资料片内所有关卡资料. public List <LevelData> GetDlcLevel(int idx) { Chapter cha = GetPluginChapter(idx); return(cha.LoadAll()); }
public List <EventModel> GetCurrentEvents() { Chapter scene = chapters[iteration]; return(scene.GetChapterEventModels(p, TimeManager)); }
public ClearData(Chapter chapter) : base(chapter) { if (!this.Signature.Equals(ValidSignature, StringComparison.Ordinal)) { throw new InvalidDataException("Signature"); } if (this.Version != ValidVersion) { throw new InvalidDataException("Version"); } if (this.Size != ValidSize) { throw new InvalidDataException("Size"); } var levels = Utils.GetEnumerator <Level>(); var levelsExceptExtra = levels.Where(lv => lv != Level.Extra); var stages = Utils.GetEnumerator <Stage>(); var stagesExceptExtra = stages.Where(st => st != Stage.Extra); var numLevels = levels.Count(); var numPairs = levelsExceptExtra.Count() * stagesExceptExtra.Count(); this.Rankings = new Dictionary <Level, ScoreData[]>(numLevels); this.ClearCounts = new Dictionary <Level, int>(numLevels); this.Practices = new Dictionary <LevelStagePair, Practice>(numPairs); this.Cards = new Dictionary <int, SpellCard>(CardTable.Count); using (var stream = new MemoryStream(this.Data, false)) { var reader = new BinaryReader(stream); this.Chara = (CharaWithTotal)reader.ReadInt32(); foreach (var level in levels) { if (!this.Rankings.ContainsKey(level)) { this.Rankings.Add(level, new ScoreData[10]); } for (var rank = 0; rank < 10; rank++) { var score = new ScoreData(); score.ReadFrom(reader); this.Rankings[level][rank] = score; } } this.TotalPlayCount = reader.ReadInt32(); this.PlayTime = reader.ReadInt32(); foreach (var level in levels) { var clearCount = reader.ReadInt32(); if (!this.ClearCounts.ContainsKey(level)) { this.ClearCounts.Add(level, clearCount); } } foreach (var level in levelsExceptExtra) { foreach (var stage in stagesExceptExtra) { var practice = new Practice(); practice.ReadFrom(reader); var key = new LevelStagePair(level, stage); if (!this.Practices.ContainsKey(key)) { this.Practices.Add(key, practice); } } } for (var number = 0; number < CardTable.Count; number++) { var card = new SpellCard(); card.ReadFrom(reader); if (!this.Cards.ContainsKey(card.Id)) { this.Cards.Add(card.Id, card); } } } }
} // .Length = 18 public static bool CanInitialize(Chapter chapter) { return(chapter.Signature.Equals(ValidSignature, StringComparison.Ordinal) && (chapter.Version == ValidVersion) && (chapter.Size == ValidSize)); }
/** * Constructor. */ public Subparser_(Chapter chapter) { this.chapter = chapter; }