public ScheduleForm(TreeNode node, Content contentDataSet) { this.startingNode = node; this.contentDataSet = contentDataSet; this.mtpsNode = node.Tag as MtpsNode; InitializeComponent(); DownloadNodeLabel.Text = mtpsNode.title; StartDate.Value = DateTime.Today; StartTime.Value = DateTime.Now; StopDate.Value = DateTime.Today; StopTime.Value = DateTime.Now; StartDate.MinDate = DateTime.Now.Date; StopDate.MinDate = DateTime.Now.Date; //adjust controls for Large Font Display -- Why is this necessary? (Its not on the download dialog) DownloadNodeLabel.Left = Label1.Left + Label1.Width + 5; StopAfterNum.Left = StopAfterCbx.Left + StopAfterCbx.Width + 5; downloadLabel.Left = StopAfterNum.Left + StopAfterNum.Width + 5; sData.Enabled = false; InfoPanel.Visible = false; EnableDisable(); }
public DownloadProgressForm(TreeNode node, Content contentDataSet) { this.startingNode = node; this.node = node; this.contentDataSet = contentDataSet; this.decendingTree = true; dlData.dlgStartTime = DateTime.Now; InitializeComponent(); //Scheduled Dialog used StopDate.Value = DateTime.Today; StopTime.Value = DateTime.Now; StopDate.MinDate = DateTime.Now.Date; if (ScheduleForm.sData.Enabled) { StopCbx.Checked = ScheduleForm.sData.xStop; if (StopCbx.Checked) { StopDate.Value = ScheduleForm.sData.StopDate; StopTime.Value = ScheduleForm.sData.StopTime; } StopAfterCbx.Checked = ScheduleForm.sData.xStopAfter; if (StopAfterCbx.Checked) { StopAfterNum.Value = ScheduleForm.sData.StopAfter; } } //Off we go this.dlgTitle = this.Text; StopCountdownLabel.Text = ""; timer1.Enabled = true; }
public HxS(string workingDir, string hxsFile, string title, string copyright, string locale, TreeNodeCollection nodes, Content contentDataSet, Dictionary<string, string> links) { this.locale = locale; this.title = title; this.copyright = copyright; this.nodes = nodes; this.contentDataSet = contentDataSet; this.links = links; this.outputFile = Path.GetFullPath(hxsFile); this.rawDir = Path.Combine(workingDir, "raw"); // The source shouldn't be hidden away. If an error happens (likely) the user needs to check logs etc. //this.hxsDir = Path.Combine(workingDir, "hxs"); this.hxsDir = GetUniqueDir(hxsFile); this.withinHxsDir = Path.Combine(hxsDir, hxsSubDir); this.baseFilename = Path.GetFileNameWithoutExtension(hxsFile); this.baseFilename = this.baseFilename.Replace(" ", "_"); //replace spaces with _ otherwise we get compile errors this.logFile = Path.Combine(hxsDir, this.baseFilename + ".log"); this.projectFile = Path.Combine(hxsDir, baseFilename + ".hxc"); if (xform == null) { xform = new XslCompiledTransform(true); xform.Load(transformFile); } }
public void UpdateStatusText_ListTab(Content contentDataSet) { if (_tabPage_List != null && contentDataSet != null) { if (listTabText == "") listTabText = _tabPage_List.Text; if (contentDataSet.Item.Count == 0) _tabPage_List.Text = listTabText; else _tabPage_List.Text = listTabText + " (" + contentDataSet.Item.Count.ToString() + ")"; } }
public void CreateHxs(string hxsFile, string title, string copyright, string locale, Content contentDataSet) { HxS hxs = new HxS(workingDir, hxsFile, title, copyright, locale, tocControl.Nodes, contentDataSet, links); hxs.Create(); ExportProgressForm hxsProgressForm = new ExportProgressForm(hxs, hxs.expectedLines); hxsProgressForm.ShowDialog(); }
public void CreateMshc(string MshcFile, string locale, Content contentDataSet, string VendorName, string ProdName, string BookName, string RootTopicSuffix, string RootTopicParent, bool fTopicVersion, string TopicVersion) { Mshc mshc = new Mshc(workingDir, MshcFile, locale, tocControl.Nodes, contentDataSet, links, VendorName, ProdName, BookName, RootTopicSuffix, RootTopicParent, fTopicVersion, TopicVersion); //Mshc.Create(); //progress now calls this.. See Mshc.Compile() ExportProgressForm progressForm = new ExportProgressForm(mshc, mshc.expectedLines); progressForm.ShowDialog(); }
public void CreateChm(string chmFile, string title, string locale, Content contentDataSet) { Chm chm = new Chm(workingDir, title, chmFile, locale, tocControl.Nodes, contentDataSet, links); chm.Create(); ExportProgressForm progressForm = new ExportProgressForm(chm, chm.expectedLines); progressForm.ShowDialog(); }
public void RemoveContent(TreeNode node, Content contentDataSet) { if (node.Tag != null) { MtpsNode mtpsNode = node.Tag as MtpsNode; DataRow row = contentDataSet.Tables["ItemInstance"].Rows.Find(node.FullPath); if (row != null) { DataRow parentRow = row.GetParentRow("FK_Item_ItemInstance"); contentDataSet.Tables["ItemInstance"].Rows.Remove(row); int count = parentRow.GetChildRows("FK_Item_ItemInstance").Length; if (count == 0) // If there are no refs to this item, delete it and its files { foreach (string file in Directory.GetFiles(rawDir, parentRow["ContentId"].ToString() + "*")) { File.Delete(file); } contentDataSet.Tables["Item"].Rows.Remove(parentRow); } UpdateStatusText_ListTab(contentDataSet); } } }
public bool WriteContent(TreeNode node, Content contentDataSet) { DataRow row; MtpsNode mtpsNode = node.Tag as MtpsNode; ContentItem contentItem = null; string[] splitVersion = mtpsNode.targetVersion.Split(new char[] {'.'}); string sdebug = ""; try { sdebug = "z0"; contentItem = new ContentItem("AssetId:" + mtpsNode.targetAssetId, mtpsNode.targetLocale, splitVersion[1], splitVersion[0], application); try { sdebug = "z1"; contentItem.Load(true); sdebug = "z2"; // RWC: This is a HACK -- There are a few pages where the ContentId returns as null even though it's a valid page // if (String.IsNullOrEmpty(contentItem.contentId)) { contentItem.contentId = GetDocShortId(node); } sdebug = "z3"; } catch { node.ForeColor = System.Drawing.Color.Red; return false; // tell the event handler to reject the click. } sdebug = "z4"; if (contentDataSet.Tables["Item"].Rows.Find(mtpsNode.targetAssetId) == null) { sdebug = "z5"; //Issue#14155: Sometimes there can be missing values that cause exceptions. //Lets's try and bluff our way through if (string.IsNullOrEmpty(contentItem.contentId)) { sdebug = "z6"; node.ForeColor = System.Drawing.Color.Red; //Set tree node red to flag problem contentItem.contentId = "PackageThis-" + mtpsNode.targetAssetId; //Create a repeatable ID using the Asset ID } sdebug = "z7"; // If we get no meta/search or wiki data, plug in NOP data so we can limp along (this usually comes with null contentId above) if (string.IsNullOrEmpty(contentItem.metadata)) contentItem.metadata = "<se:search xmlns:se=\"urn:mtpg-com:mtps/2004/1/search\" />"; if (string.IsNullOrEmpty(contentItem.annotations)) contentItem.annotations = "<an:annotations xmlns:an=\"urn:mtpg-com:mtps/2007/1/annotations\" />"; sdebug = "z8"; row = contentDataSet.Tables["Item"].NewRow(); row["ContentId"] = contentItem.contentId; row["Title"] = mtpsNode.title; row["VersionId"] = mtpsNode.targetVersion; row["AssetId"] = mtpsNode.targetAssetId; row["Pictures"] = contentItem.numImages; row["Size"] = contentItem.xml == null ? 0 : contentItem.xml.Length; row["SizePictures"] = contentItem.sizeImages; row["Metadata"] = contentItem.metadata; row["Annotations"] = contentItem.annotations; sdebug = "z9"; contentDataSet.Tables["Item"].Rows.Add(row); } sdebug = "z10"; if (contentDataSet.Tables["ItemInstance"].Rows.Find(node.FullPath) == null) { sdebug = "z11"; row = contentDataSet.Tables["ItemInstance"].NewRow(); row["ContentId"] = contentItem.contentId; row["FullPath"] = node.FullPath; contentDataSet.Tables["ItemInstance"].Rows.Add(row); sdebug = "z12"; } sdebug = "z13"; foreach (string imageFilename in contentItem.ImageFilenames) { sdebug = "z14"; row = contentDataSet.Tables["Picture"].NewRow(); row["ContentId"] = contentItem.contentId; row["Filename"] = imageFilename; sdebug = "z15"; } sdebug = "z16"; if (string.IsNullOrEmpty(contentItem.links) == false) { sdebug = "z17"; XmlDocument linkDoc = new XmlDocument(); XmlNamespaceManager nsm = new XmlNamespaceManager(linkDoc.NameTable); nsm.AddNamespace("k", "urn:mtpg-com:mtps/2004/1/key"); nsm.AddNamespace("mtps", "urn:msdn-com:public-content-syndication"); sdebug = "z18"; linkDoc.LoadXml(contentItem.links); sdebug = "z19"; XmlNodeList nodes = linkDoc.SelectNodes("//mtps:link", nsm); sdebug = "z20"; int z = 0; foreach (XmlNode xmlNode in nodes) { z++; sdebug = "z21_" + z.ToString(); XmlNode assetIdNode = xmlNode.SelectSingleNode("mtps:assetId", nsm); XmlNode contentIdNode = xmlNode.SelectSingleNode("k:contentId", nsm); sdebug = "z22_" + z.ToString(); if (assetIdNode == null || contentIdNode == null) continue; string assetId = assetIdNode.InnerText; string contentId = contentIdNode.InnerText; sdebug = "z23_" + z.ToString(); if (string.IsNullOrEmpty(assetId) == false) { // Remove "assetId:" from front assetId = HttpUtility.UrlDecode(assetIdNode.InnerText.Remove(0, "assetId:".Length)); sdebug = "z24_" + z.ToString(); if (links.ContainsKey(assetId) == false) { links.Add(assetId, contentId); sdebug = "z25_" + z.ToString(); } } } } sdebug = "z26"; contentItem.Write(rawDir); sdebug = "z27"; UpdateStatusText_ListTab(contentDataSet); //throw new Exception("Test Exception"); } // // *** An attempt to catch some of these illusive errors // catch(Exception e) { exceptionCount++; UpdateStatusText_DebugTab(); DebugOut("---------- Critical Exception ---------------- "); DebugOut("Exception time: ", DateTime.Now.ToString()); String docContentId = "0"; try { docContentId = this.GetDocShortId(node); DebugOut("mtpsNode.targetLocale: ", mtpsNode.targetLocale); DebugOut("docContentId: ", docContentId); DebugOut("mtpsNode.targetVersion: ", mtpsNode.targetVersion); } catch { } try { DebugOut("Node.Text: ", node.Text); DebugOut("Debug Point: ", sdebug); DebugOut("e.Message: ", e.Message); DebugOut("e.StackTrace: ", e.StackTrace); DebugOut("e.Source: ", e.Source); DebugOut("e.ToString: ", e.ToString()); String url; if (rootContentItem.msdnSelected) url = String.Format("http://msdn.microsoft.com/{0}/library/{1}({2}).aspx", mtpsNode.targetLocale, docContentId, mtpsNode.targetVersion); else url = String.Format("http://technet.microsoft.com/{0}/library/{1}({2}).aspx", mtpsNode.targetLocale, docContentId, mtpsNode.targetVersion); DebugOut("URL: ", url); } catch { } } return true; }
public void Transform(string contentId, string metadataXml, string annotationsXml, string versionId, string docTitle, Content contentDataSet) { XsltArgumentList arguments = new XsltArgumentList(); Link link = new Link(contentDataSet, links); XmlDocument metadata = new XmlDocument(); XmlDocument annotations = new XmlDocument(); string filename = Path.Combine(withinHxsDir, contentId + ".htm"); string xml; if (File.Exists(filename)) { StreamReader sr = new StreamReader(filename); xml = sr.ReadToEnd(); sr.Close(); } else //Default to Simple headers only { xml = "<div class=\"topic\" xmlns=\"http://www.w3.org/1999/xhtml\">" + Environment.NewLine + " <div class=\"majorTitle\">" + docTitle + "</div>" + Environment.NewLine + " <div class=\"title\">" + docTitle + "</div>" + Environment.NewLine + " <div id=\"mainSection\">" + Environment.NewLine + " <div id=\"mainBody\">" + Environment.NewLine + " <p></p>" + Environment.NewLine + //RWC: Too difficult to add child link list like MSDN Online. Just leave blank. " </div>" + Environment.NewLine + " </div>" + Environment.NewLine + "</div>" + Environment.NewLine; } metadata.LoadXml(metadataXml); annotations.LoadXml(annotationsXml); // Do transform arguments.AddParam("metadata", "", metadata.CreateNavigator()); arguments.AddParam("annotations", "", annotations.CreateNavigator()); arguments.AddParam("version", "", versionId); arguments.AddParam("locale", "", locale); arguments.AddExtensionObject("urn:Link", link); TextReader tr = new StringReader(xml); XmlReader xr = XmlReader.Create(tr); using (StreamWriter sw = new StreamWriter(filename, false, Encoding.UTF8)) { try { xform.Transform(xr, arguments, sw); } catch //(Exception ex) { return; } } }
public void CreateHxt(TreeNodeCollection nodeCollection, Hxt hxt, Content contentDataSet) { bool opened = false; // Keep track of opening or closing of TOC entries in the .hxt foreach (TreeNode node in nodeCollection) { if (node.Checked == true) { MtpsNode mtpsNode = node.Tag as MtpsNode; DataRow row = contentDataSet.Tables["Item"].Rows.Find(mtpsNode.targetAssetId); string Url; //if (Int32.Parse(row["Size"].ToString()) == 0) // Url = null; //else Url = Path.Combine(hxsSubDir, row["ContentId"].ToString() + ".htm"); hxt.WriteStartNode(mtpsNode.title, Url); opened = true; } if (node.Nodes.Count != 0 || node.Tag != null) { CreateHxt(node.Nodes, hxt, contentDataSet); } if (opened) { opened = false; hxt.WriteEndNode(); } } }
public Link(Content contentDataSet, Dictionary<string, string> links) { this.contentDataSet = contentDataSet; this.links = links; }
public Chm(string workingDir, string title, string chmFile, string locale, TreeNodeCollection nodes, Content contentDataSet, Dictionary<string, string> links) { this.workingDir = workingDir; this.title = title; this.chmFile = chmFile; this.locale = locale; this.nodes = nodes; this.contentDataSet = contentDataSet; this.links = links; this.rawDir = Path.Combine(workingDir, "raw"); // The source shouldn't be hidden away. If an error happens (likely) the user needs to check logs etc. //this.chmDir = Path.Combine(workingDir, "chm"); this.chmDir = GetUniqueDir(chmFile); this.withinChmDir = Path.Combine(chmDir, chmSubDir); this.baseName = Path.GetFileNameWithoutExtension(chmFile); if (xform == null) { xform = new XslCompiledTransform(true); xform.Load(transformFile); } }
public void Transform(string contentId, string metadataXml, string annotationsXml, string versionId, string docTitle, Content contentDataSet) { XsltArgumentList arguments = new XsltArgumentList(); Link link = new Link(contentDataSet, links); XmlDocument metadata = new XmlDocument(); XmlDocument annotations = new XmlDocument(); string filename = Path.Combine(withinChmDir, contentId + ".htm"); string xml; if (File.Exists(filename)) { StreamReader sr = new StreamReader(filename); xml = sr.ReadToEnd(); sr.Close(); } else //Probably a node file that simply lists its children -- We will deal with this at a later date { xml = "<div class=\"topic\" xmlns=\"http://www.w3.org/1999/xhtml\">" + Environment.NewLine + " <div class=\"majorTitle\">" + docTitle + "</div>" + Environment.NewLine + " <div class=\"title\">" + docTitle + "</div>" + Environment.NewLine + " <div id=\"mainSection\">" + Environment.NewLine + " <div id=\"mainBody\">" + Environment.NewLine + " <p></p>" + Environment.NewLine + //RWC: Too difficult to add child link list like MSDN Online. Just leave blank. " </div>" + Environment.NewLine + " </div>" + Environment.NewLine + "</div>" + Environment.NewLine; } int codePage = new CultureInfo(locale).TextInfo.ANSICodePage; // We use these fallbacks because is unknown under DBCS like Japanese // and translated to ? by default. Encoding encoding = Encoding.GetEncoding(codePage, new EncoderReplacementFallback(" "), new DecoderReplacementFallback(" ")); metadata.LoadXml(metadataXml); annotations.LoadXml(annotationsXml); arguments.AddParam("metadata", "", metadata.CreateNavigator()); arguments.AddParam("annotations", "", annotations.CreateNavigator()); arguments.AddParam("version", "", versionId); arguments.AddParam("locale", "", locale); arguments.AddParam("charset", "", encoding.WebName); arguments.AddExtensionObject("urn:Link", link); TextReader tr = new StringReader(xml); XmlReader xr = XmlReader.Create(tr); using (StreamWriter sw = new StreamWriter(filename, false, encoding)) { try { xform.Transform(xr, arguments, sw); } catch //(Exception ex) { return; } } }
public void CreateHhc(TreeNodeCollection nodeCollection, Hhc hhc, Content contentDataSet) { bool opened = false; // Keep track of opening or closing of TOC entries foreach (TreeNode node in nodeCollection) { if (node.Checked == true) { MtpsNode mtpsNode = node.Tag as MtpsNode; DataRow row = contentDataSet.Tables["Item"].Rows.Find(mtpsNode.targetAssetId); string Url; //RWC: Now include phantom pages //if (Int32.Parse(row["Size"].ToString()) == 0) // Url = null; //else //{ Url = Path.Combine(chmSubDir, row["ContentId"].ToString() + ".htm"); // Save the first page we see in the TOC as the default page as required // by the chm. if(defaultPage == null) defaultPage = Url; //} hhc.WriteStartNode(mtpsNode.title, Url); opened = true; } if (node.Nodes.Count != 0 || node.Tag != null) { CreateHhc(node.Nodes, hhc, contentDataSet); } if (opened) { opened = false; hhc.WriteEndNode(); } } }
public Mshc(string workingDir, string mshcFile, string locale, TreeNodeCollection nodes, Content contentDataSet, Dictionary<string, string> links, string VendorName, string ProdName, string BookName, string RootTopicSuffix, string RootTopicParent, bool fTopicVersion, string TopicVersion) { this.mshcFile = mshcFile; this.newMshcDir = Path.GetDirectoryName(mshcFile); this.locale = locale; this.nodes = nodes; this.contentDataSet = contentDataSet; this.links = links; this.vendorName = VendorName.Trim(); this.prodName = ProdName.Trim(); this.nookName = BookName.Trim(); this.rootTopicSuffix = RootTopicSuffix; this.rootTopicParent = RootTopicParent.Trim(); this.fTopicVersion = fTopicVersion; this.topicVersion = TopicVersion.Trim(); this.packageName = Path.GetFileNameWithoutExtension(this.mshcFile); this.expectedLines = contentDataSet.Tables["Item"].Rows.Count + 1; this.rawDir = Path.Combine(workingDir, "raw"); if (xform == null) { xform = new XslCompiledTransform(true); xform.Load(transformFile); } }