Beispiel #1
0
        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 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);
                    }
                }
            }
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (node == null)
            {
                timer1.Enabled = false;
                this.Close();
                return;
            }

            node.Expand();

            if (node.Checked == false)
            {
                node.Checked = true;
            }

            if (node.Tag != null)
            {
                MtpsNode mtpsNode = node.Tag as MtpsNode;
                TitleLabel.Text = mtpsNode.title;

                DataRow row = contentDataSet.Tables["Item"].Rows.Find(mtpsNode.targetAssetId);

                if (row != null)
                {
                    downloadSize += (ulong)Int32.Parse(row["Size"].ToString());
                }

                filesDownloaded += 1;

                FilesLabel.Text = filesDownloaded.ToString();
                SizeLabel.Text  = convertToBinaryPrefixed(downloadSize);
            }

            if (decendingTree == true && node.FirstNode != null)
            {
                node          = node.FirstNode;
                decendingTree = true;

                return;
            }
            if (node.NextNode != null)
            {
                node          = node.NextNode;
                decendingTree = true;

                return;
            }

            node          = node.Parent;
            decendingTree = false;

            if (node == startingNode && decendingTree == false)
            {
                timer1.Enabled = false;
                this.Close();
            }
        }
Beispiel #4
0
        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;

                    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 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 void ExpandNode(TreeNode node)
        {
            if (node.Nodes[0].Tag == null)
            {
                ContentItem contentItem;
                MtpsNode    mtpsNode = node.Tag as MtpsNode;

                try
                {
                    contentItem = lookupTOCNode(mtpsNode.navAssetId, mtpsNode.navLocale,
                                                mtpsNode.navVersion);
                    processNodeList(contentItem, node.Nodes);
                }
                catch
                {
//                    mtpsNode.external = true;
//                    node.ForeColor = System.Drawing.Color.Red;
                }

                node.Nodes.Remove(node.Nodes[0]); // This removes the node labeled "+"
            }
        }
Beispiel #7
0
        void processNodeList(ContentItem contentItem, TreeNodeCollection tnCollection)
        {
            XmlDocument xmlDocument = new XmlDocument();
            XmlNamespaceManager nsm = new XmlNamespaceManager(xmlDocument.NameTable);
            nsm.AddNamespace("toc", "urn:mtpg-com:mtps/2004/1/toc");
            nsm.AddNamespace("mtps", "http://msdn2.microsoft.com/mtps");
            nsm.AddNamespace("asp", "http://msdn2.microsoft.com/asp");
            nsm.AddNamespace("mshelp", "http:/msdn.microsoft.com/mshelp");

            if(string.IsNullOrEmpty(contentItem.toc) == true)
                return;

            xmlDocument.LoadXml(contentItem.toc);

            XmlNodeList nodes = xmlDocument.SelectNodes("/toc:Node/toc:Node", nsm);


            foreach(XmlNode node in nodes)
            {
                string title = GetAttribute(node.Attributes["toc:Title"]);

                string target = HttpUtility.UrlDecode(GetAttribute(node.Attributes["toc:Target"]));

                string targetLocale = GetAttribute(node.Attributes["toc:TargetLocale"]);
                string targetVersion = GetAttribute(node.Attributes["toc:TargetVersion"]);

                string subTree = HttpUtility.UrlDecode(GetAttribute(node.Attributes["toc:SubTree"]));
                string subTreeVersion = GetAttribute(node.Attributes["toc:SubTreeVersion"]);
                string subTreeLocale = GetAttribute(node.Attributes["toc:SubTreeLocale"]);
                string isPhantom = GetAttribute(node.Attributes["toc:IsPhantom"]);

                if (isPhantom != "true" && 
                    title != "@PhantomNode" &&
                    title != "@NoTitle" &&
                    string.IsNullOrEmpty(title) != true &&
                    string.IsNullOrEmpty(target) != true)
                {
                    TreeNode treeNode = tnCollection.Add(title);

                    MtpsNode mtpsNode = new MtpsNode(subTree, subTreeLocale, subTreeVersion,
                        contentItem.contentId, target, targetLocale, targetVersion, title);

                    treeNode.Tag = mtpsNode;

#if (NODE_DATA_DEBUG)
                    //Is the Asset a GUID?  *-xxxx-xxxx-xxxx-*
                    string[] split = target.Split(new char[] { '-' });
                    if (split.Length == 5 && split[1].Length == 4 && split[2].Length == 4 && split[3].Length == 4)
                    {
                        treeNode.Text = treeNode.Text + "(GUID)";
                        treeNode.ForeColor = System.Drawing.Color.Blue;
                    }

                    treeNode.Text = treeNode.Text + "(" + targetVersion + "/" + targetLocale + ")";
#endif

                    // Mark nodes red that point outside this server
                    if (mtpsNode.external == true)
                    {
                        treeNode.ForeColor = System.Drawing.Color.Red;

                        //treeNode.NodeFont = new System.Drawing.Font(tocControl.Font, System.Drawing.FontStyle.Italic);
                    }


                    if (subTree != null)
                    {
                        // Add a + as the title so any node with subnodes is expandable.
                        // Only load the subnodes when user expands this node.
                        // We rely on Tag == null rather than Text == "+" in case
                        // there really is a node with a title of "+".
                        treeNode.Nodes.Add("+");

                    }
                }
                else
                {
                    if (subTree != null)
                    {
                        // TODO: add a ContentItem constructor that takes a combined 
                        // version string: MSDN.10, Office.12, etc.

                        string[] splitVersion = subTreeVersion.Split(new char[] {'.'});
                        ContentItem childContentItem = new ContentItem(subTree, subTreeLocale, 
                            splitVersion[1], splitVersion[0], application);
                        childContentItem.Load(false);

                        processNodeList(childContentItem, tnCollection);
                    }
                }
            }

        }
        public bool WriteContent(TreeNode node, Content contentDataSet)
        {
            DataRow  row;
            MtpsNode mtpsNode = node.Tag as MtpsNode;

            string[] splitVersion = mtpsNode.targetVersion.Split(new char[] { '.' });

            ContentItem contentItem = new ContentItem("AssetId:" + mtpsNode.targetAssetId, mtpsNode.targetLocale,
                                                      splitVersion[1], splitVersion[0], application);

            try
            {
                contentItem.Load(true);
            }

            catch
            {
                node.ForeColor = System.Drawing.Color.Red;
                return(false); // tell the event handler to reject the click.
            }

            if (contentDataSet.Tables["Item"].Rows.Find(mtpsNode.targetAssetId) == null)
            {
                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["Metadata"]    = contentItem.metadata;
                row["Annotations"] = contentItem.annotations;

                contentDataSet.Tables["Item"].Rows.Add(row);
            }
            if (contentDataSet.Tables["ItemInstance"].Rows.Find(node.FullPath) == null)
            {
                row = contentDataSet.Tables["ItemInstance"].NewRow();
                row["ContentId"] = contentItem.contentId;
                row["FullPath"]  = node.FullPath;
                contentDataSet.Tables["ItemInstance"].Rows.Add(row);
            }
            foreach (string imageFilename in contentItem.ImageFilenames)
            {
                row = contentDataSet.Tables["Picture"].NewRow();
                row["ContentId"] = contentItem.contentId;
                row["Filename"]  = imageFilename;
            }


            if (string.IsNullOrEmpty(contentItem.links) == false)
            {
                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");

                linkDoc.LoadXml(contentItem.links);

                XmlNodeList nodes = linkDoc.SelectNodes("//mtps:link", nsm);

                foreach (XmlNode xmlNode in nodes)
                {
                    XmlNode assetIdNode   = xmlNode.SelectSingleNode("mtps:assetId", nsm);
                    XmlNode contentIdNode = xmlNode.SelectSingleNode("k:contentId", nsm);

                    if (assetIdNode == null || contentIdNode == null)
                    {
                        continue;
                    }

                    string assetId   = assetIdNode.InnerText;
                    string contentId = contentIdNode.InnerText;

                    if (string.IsNullOrEmpty(assetId) == false)
                    {
                        // Remove "assetId:" from front
                        assetId = HttpUtility.UrlDecode(assetIdNode.InnerText.Remove(0, "assetId:".Length));

                        if (links.ContainsKey(assetId) == false)
                        {
                            links.Add(assetId, contentId);
                        }
                    }
                }
            }
            contentItem.Write(rawDir);

            return(true);
        }
        void processNodeList(ContentItem contentItem, TreeNodeCollection tnCollection)
        {
            XmlDocument         xmlDocument = new XmlDocument();
            XmlNamespaceManager nsm         = new XmlNamespaceManager(xmlDocument.NameTable);

            nsm.AddNamespace("toc", "urn:mtpg-com:mtps/2004/1/toc");
            nsm.AddNamespace("mtps", "http://msdn2.microsoft.com/mtps");
            nsm.AddNamespace("asp", "http://msdn2.microsoft.com/asp");
            nsm.AddNamespace("mshelp", "http:/msdn.microsoft.com/mshelp");

            if (string.IsNullOrEmpty(contentItem.toc) == true)
            {
                return;
            }

            xmlDocument.LoadXml(contentItem.toc);

            XmlNodeList nodes = xmlDocument.SelectNodes("/toc:Node/toc:Node", nsm);


            foreach (XmlNode node in nodes)
            {
                string title = GetAttribute(node.Attributes["toc:Title"]);

                string target = HttpUtility.UrlDecode(GetAttribute(node.Attributes["toc:Target"]));


                string targetLocale  = GetAttribute(node.Attributes["toc:TargetLocale"]);
                string targetVersion = GetAttribute(node.Attributes["toc:TargetVersion"]);

                string subTree        = HttpUtility.UrlDecode(GetAttribute(node.Attributes["toc:SubTree"]));
                string subTreeVersion = GetAttribute(node.Attributes["toc:SubTreeVersion"]);
                string subTreeLocale  = GetAttribute(node.Attributes["toc:SubTreeLocale"]);
                string isPhantom      = GetAttribute(node.Attributes["toc:IsPhantom"]);

                if (isPhantom != "true" &&
                    title != "@PhantomNode" &&
                    title != "@NoTitle" &&
                    string.IsNullOrEmpty(title) != true &&
                    string.IsNullOrEmpty(target) != true)
                {
                    TreeNode treeNode = tnCollection.Add(title);

                    MtpsNode mtpsNode = new MtpsNode(subTree, subTreeLocale, subTreeVersion,
                                                     contentItem.contentId, target, targetLocale, targetVersion, title);

                    treeNode.Tag = mtpsNode;

                    // Mark nodes red that point outside this server
                    if (mtpsNode.external == true)
                    {
                        treeNode.ForeColor = System.Drawing.Color.Red;

                        //treeNode.NodeFont = new System.Drawing.Font(tocControl.Font, System.Drawing.FontStyle.Italic);
                    }


                    if (subTree != null)
                    {
                        // Add a + as the title so any node with subnodes is expandable.
                        // Only load the subnodes when user expands this node.
                        // We rely on Tag == null rather than Text == "+" in case
                        // there really is a node with a title of "+".
                        treeNode.Nodes.Add("+");
                    }
                }
                else
                {
                    if (subTree != null)
                    {
                        // TODO: add a ContentItem constructor that takes a combined
                        // version string: MSDN.10, Office.12, etc.

                        string[]    splitVersion     = subTreeVersion.Split(new char[] { '.' });
                        ContentItem childContentItem = new ContentItem(subTree, subTreeLocale,
                                                                       splitVersion[1], splitVersion[0], application);
                        childContentItem.Load(false);

                        processNodeList(childContentItem, tnCollection);
                    }
                }
            }
        }