Exemple #1
0
        //Create a new file node in the xml document
        private static void CreateFile(XMLWriteFileObject xmlWriteObj)
        {
            XmlDocument xmlDoc = new XmlDocument();
            string xmlFilePath = Path.Combine(xmlWriteObj.Parent, CommonXMLConstants.MetadataPath);
            CommonMethods.CreateFileIfNotExist(xmlWriteObj.Parent);
            CommonMethods.LoadXML(ref xmlDoc, xmlFilePath);

            CommonMethods.DoFileCleanUp(xmlDoc, xmlWriteObj.Name);
            XmlText nameText = xmlDoc.CreateTextNode(xmlWriteObj.Name);
            XmlText hashText = xmlDoc.CreateTextNode(xmlWriteObj.Hash);
            XmlText sizeText = xmlDoc.CreateTextNode(xmlWriteObj.Size.ToString());
            XmlText createdTimeText = xmlDoc.CreateTextNode(xmlWriteObj.CreationTimeUtc.ToString());
            XmlText lastModifiedText = xmlDoc.CreateTextNode(xmlWriteObj.LastModifiedUtc.ToString());
            XmlText lastUpdatedText = xmlDoc.CreateTextNode(xmlWriteObj.MetaUpdatedUtc.ToString());

            XmlElement nameElement = xmlDoc.CreateElement(CommonXMLConstants.NodeName);
            XmlElement hashElement = xmlDoc.CreateElement(CommonXMLConstants.NodeHash);
            XmlElement sizeElement = xmlDoc.CreateElement(CommonXMLConstants.NodeSize);
            XmlElement createdTimeElement = xmlDoc.CreateElement(CommonXMLConstants.NodeLastCreatedUtc);
            XmlElement lastModifiedElement = xmlDoc.CreateElement(CommonXMLConstants.NodeLastModifiedUtc);
            XmlElement lastUpdatedElement = xmlDoc.CreateElement(CommonXMLConstants.NodeLastUpdatedUtc);
            XmlElement fileElement = xmlDoc.CreateElement(CommonXMLConstants.NodeFile);

            nameElement.AppendChild(nameText);
            hashElement.AppendChild(hashText);
            sizeElement.AppendChild(sizeText);
            createdTimeElement.AppendChild(createdTimeText);
            lastModifiedElement.AppendChild(lastModifiedText);
            lastUpdatedElement.AppendChild(lastUpdatedText);

            fileElement.AppendChild(nameElement);
            fileElement.AppendChild(sizeElement);
            fileElement.AppendChild(hashElement);
            fileElement.AppendChild(lastModifiedElement);
            fileElement.AppendChild(createdTimeElement);
            fileElement.AppendChild(lastUpdatedElement);

            XmlNode rootNode = xmlDoc.SelectSingleNode(CommonXMLConstants.XPathExpr);
            if(rootNode == null)
                return;

            rootNode.AppendChild(fileElement);
            CommonMethods.SaveXML(ref xmlDoc, xmlFilePath);
            DeleteFileLastKnownState(xmlWriteObj);
        }
Exemple #2
0
        //Deletes a file node in the last known state file by searching for the name
        private static void DeleteFileLastKnownState(XMLWriteFileObject xmlWriteObj)
        {
            string todoXmlPath = Path.Combine(xmlWriteObj.Parent, CommonXMLConstants.LastKnownStatePath);
            if (!File.Exists(todoXmlPath))
                return;

            XmlDocument todoXmlDoc = new XmlDocument();
            CommonMethods.LoadXML(ref todoXmlDoc, todoXmlPath);
            XmlNode fileNode = todoXmlDoc.SelectSingleNode(CommonXMLConstants.XPathLastKnownState + CommonXMLConstants.XPathFile + "[name=" + CommonMethods.ParseXPathString(xmlWriteObj.Name) + "]");
            if (fileNode != null)
                fileNode.ParentNode.RemoveChild(fileNode);
            CommonMethods.SaveXML(ref todoXmlDoc, todoXmlPath);
        }
Exemple #3
0
        // Called by method GenerateFileLastKnownState to access the xml document and add a new file node in the last
        // known state file
        private static void AppendActionFileLastKnownState(XmlDocument xmlDoc, XMLWriteFileObject xmlWriteObj, string changeType, XmlNode node)
        {
            string hash = string.Empty;
            string lastModified = string.Empty;
            XmlNodeList nodeList = node.ChildNodes;
            for (int i = 0; i < nodeList.Count; i++)
            {
                XmlNode childNode = nodeList[i];
                switch (childNode.Name)
                {
                    case CommonXMLConstants.NodeHash:
                        hash = childNode.InnerText;
                        break;
                    case CommonXMLConstants.NodeLastModifiedUtc:
                        lastModified = childNode.InnerText;
                        break;
                }
            }

            XmlText hashText = xmlDoc.CreateTextNode(hash);
            XmlText actionText = xmlDoc.CreateTextNode(changeType);
            XmlText lastModifiedText = xmlDoc.CreateTextNode(lastModified);
            XmlText nameText = xmlDoc.CreateTextNode(xmlWriteObj.Name);
            XmlText lastUpdatedText = xmlDoc.CreateTextNode(xmlWriteObj.MetaUpdatedUtc.ToString());

            XmlElement fileElement = xmlDoc.CreateElement(CommonXMLConstants.NodeFile);
            XmlElement nameElement = xmlDoc.CreateElement(CommonXMLConstants.NodeName);
            XmlElement hashElement = xmlDoc.CreateElement(CommonXMLConstants.NodeHash);
            XmlElement actionElement = xmlDoc.CreateElement(CommonXMLConstants.NodeAction);
            XmlElement lastModifiedElement = xmlDoc.CreateElement(CommonXMLConstants.NodeLastModifiedUtc);
            XmlElement lastUpdatedElement = xmlDoc.CreateElement(CommonXMLConstants.NodeLastUpdatedUtc);

            hashElement.AppendChild(hashText);
            actionElement.AppendChild(actionText);
            lastModifiedElement.AppendChild(lastModifiedText);
            lastUpdatedElement.AppendChild(lastUpdatedText);
            nameElement.AppendChild(nameText);

            fileElement.AppendChild(nameElement);
            fileElement.AppendChild(actionElement);
            fileElement.AppendChild(hashElement);
            fileElement.AppendChild(lastModifiedElement);
            fileElement.AppendChild(lastUpdatedElement);

            XmlNode rootNode = xmlDoc.SelectSingleNode(CommonXMLConstants.XPathLastKnownState);
            if(rootNode == null)
                return;

            rootNode.AppendChild(fileElement);
        }
Exemple #4
0
        // Generates a new file node in the last known state file based on the XMLWriteFileObject and deleted node
        private static void GenerateFileLastKnownState(XMLWriteFileObject xmlWriteObj, XmlNode deletedNode)
        {
            if (deletedNode == null)
                return;

            string fullPath = xmlWriteObj.Parent;
            XmlDocument xmlTodoDoc = new XmlDocument();
            string todoPath = Path.Combine(fullPath, CommonXMLConstants.LastKnownStatePath);
            CommonMethods.CreateLastKnownStateFile(fullPath);
            CommonMethods.LoadXML(ref xmlTodoDoc, todoPath);
            CommonMethods.DoFileLastKnownCleanUp(xmlTodoDoc, xmlWriteObj.Name);
            AppendActionFileLastKnownState(xmlTodoDoc, xmlWriteObj, CommonXMLConstants.ActionDeleted, deletedNode);
            CommonMethods.SaveXML(ref xmlTodoDoc, todoPath);
        }
Exemple #5
0
        // Delete the file node in the xml document
        private static void DeleteFile(XMLWriteFileObject xmlWriteObj)
        {
            XmlDocument xmlDoc = new XmlDocument();
            XmlNode tempNode = null;
            string xmlFilePath = Path.Combine(xmlWriteObj.Parent, CommonXMLConstants.MetadataPath);
            if (File.Exists(xmlFilePath))
            {
                CommonMethods.LoadXML(ref xmlDoc, xmlFilePath);
                XmlNode node = xmlDoc.SelectSingleNode(CommonXMLConstants.XPathExpr + CommonXMLConstants.XPathFile + "[name=" + CommonMethods.ParseXPathString(xmlWriteObj.Name) + "]");
                if (node == null)
                    return;
                tempNode = node.Clone();
                node.ParentNode.RemoveChild(node);
                CommonMethods.SaveXML(ref xmlDoc, xmlFilePath);
            }

            GenerateFileLastKnownState(xmlWriteObj, tempNode);
        }
Exemple #6
0
        //Rename the existing file node in the xml document
        private static void RenameFile(XMLWriteFileObject xmlWriteObj)
        {
            XmlDocument xmlDoc = new XmlDocument();
            XmlNode tempNode = null;
            string xmlFilePath = Path.Combine(xmlWriteObj.Parent, CommonXMLConstants.MetadataPath);
            CommonMethods.CreateFileIfNotExist(xmlWriteObj.Parent);
            CommonMethods.LoadXML(ref xmlDoc, xmlFilePath);

            XmlNode node = xmlDoc.SelectSingleNode(CommonXMLConstants.XPathExpr + CommonXMLConstants.XPathFile + "[name=" + CommonMethods.ParseXPathString(xmlWriteObj.Name) + "]");
            
            // if the node does not exist, then create the node
            if (node == null)
            {
                CommonMethods.SaveXML(ref xmlDoc, xmlFilePath);
                CreateFile(xmlWriteObj);
                return;
            }

            tempNode = node.Clone();
            node.FirstChild.InnerText = xmlWriteObj.NewName;
            node.LastChild.InnerText = xmlWriteObj.MetaUpdatedUtc.ToString();
            CommonMethods.SaveXML(ref xmlDoc, xmlFilePath);
            GenerateFileLastKnownState(xmlWriteObj, tempNode);
        }
Exemple #7
0
        //Update the existing file node in the xml document 
        private static void UpdateFile(XMLWriteFileObject xmlWriteObj)
        {
            XmlDocument xmlDoc = new XmlDocument();
            string xmlFilePath = Path.Combine(xmlWriteObj.Parent, CommonXMLConstants.MetadataPath);
            CommonMethods.CreateFileIfNotExist(xmlWriteObj.Parent);
            CommonMethods.LoadXML(ref xmlDoc, xmlFilePath);

            XmlNode node = xmlDoc.SelectSingleNode(CommonXMLConstants.XPathExpr + CommonXMLConstants.XPathFile + "[name=" + CommonMethods.ParseXPathString(xmlWriteObj.Name) + "]");
            
            // if the node does not exist , then create the node
            if (node == null)
            {
                CommonMethods.SaveXML(ref xmlDoc, xmlFilePath);
                CreateFile(xmlWriteObj);
                return;
            }

            XmlNodeList childNodeList = node.ChildNodes;
            for (int i = 0; i < childNodeList.Count; i++)
            {
                XmlNode nodes = childNodeList[i];

                switch (nodes.Name)
                {
                    case CommonXMLConstants.NodeSize:
                        nodes.InnerText = xmlWriteObj.Size.ToString();
                        break;
                    case CommonXMLConstants.NodeHash:
                        nodes.InnerText = xmlWriteObj.Hash;
                        break;
                    case CommonXMLConstants.NodeName:
                        nodes.InnerText = xmlWriteObj.Name;
                        break;
                    case CommonXMLConstants.NodeLastModifiedUtc:
                        nodes.InnerText = xmlWriteObj.LastModifiedUtc.ToString();
                        break;
                    case CommonXMLConstants.NodeLastCreatedUtc:
                        nodes.InnerText = xmlWriteObj.CreationTimeUtc.ToString();
                        break;
                    case CommonXMLConstants.NodeLastUpdatedUtc:
                        nodes.InnerText = xmlWriteObj.MetaUpdatedUtc.ToString();
                        break;
                }
            }

            CommonMethods.SaveXML(ref xmlDoc, xmlFilePath);
            DeleteFileLastKnownState(xmlWriteObj);
        }