Пример #1
0
        public void CreateXml(ListItemCollection InputList, DateTime date, string docType, List <ModXXFamXX> ModXXs, ClientContext clientContext)
        {
            try
            {
                DateTime    inputDate       = date;
                XmlDocument xmlDoc          = new XmlDocument();
                string      itemType        = string.Empty; // to check item is document set(folder) or document(file)
                string      contentType     = string.Empty; //to get content type
                string      confidentiality = string.Empty;

                XmlNode nodeLevel4        = StaticNodes(xmlDoc, docType);
                XmlNode nodeLevel5Dynamic = null;
                XmlNode nodeLevel6Dynamic = null;

                //Families for selected ModXXs
                var selectedFamXX = (from A in ModXXs
                                     select A.FamilAlias).ToList().Distinct().ToList();
                //Selected ModXXs
                var selectedModXX = (from A in ModXXs
                                     select A.ModXXName).ToList();

                var listItems = InputList.ToList();
                if (docType == "WAR")
                {
                    listItems = InputList.OrderBy(c => c["TATNS"]).ThenByDescending(n => n.FileSystemObjectType).ThenBy(n => n["FileLeafRef"]).ToList();
                }
                else
                {
                    listItems = InputList.OrderBy(c => c["TATNS"]).ThenByDescending(n => n.FileSystemObjectType).ThenBy(n => n["FileLeafRef"]).ToList();
                }

                for (int i = 0; i < listItems.Count; i++)
                {
                    itemType        = listItems[i].FileSystemObjectType.ToString();
                    contentType     = listItems[i].ContentType.Name;
                    confidentiality = Convert.ToString(listItems[i]["Confidentiality"]);
                    if (confidentiality == "Public" || String.IsNullOrEmpty(confidentiality))
                    {
                        if (docType == "WAR")
                        {
                            if (contentType.Contains("My ContentType"))
                            {
                                if (itemType == "Folder")
                                {
                                    string strTATNS = string.Empty;
                                    strTATNS = Convert.ToString(listItems[i]["TATNS"]);
                                    string tatNumber = strTATNS.Split(new char[0])[0];
                                    // Get list of existing LEVEL5 nodes.
                                    string      level5    = String.Format("/LEVEL3/LEVEL4/LEVEL5[@KEY='{0}']", tatNumber);
                                    XmlNodeList node5List = xmlDoc.SelectNodes(level5);
                                    if (node5List.Count > 0)
                                    {
                                        nodeLevel5Dynamic = node5List[0];
                                    }
                                    else
                                    {
                                        nodeLevel5Dynamic = DocumentSetNode(listItems[i], xmlDoc, tatNumber, strTATNS);
                                    }
                                    nodeLevel4.AppendChild(nodeLevel5Dynamic);
                                }
                                else
                                {
                                    // check needs to be added for files with name starting with WAR
                                    if (listItems[i]["FileLeafRef"].ToString().StartsWith("WAR"))
                                    {
                                        XmlNode nodeLevel6DynamicAw = DocumentNode(listItems[i], xmlDoc, inputDate);
                                        nodeLevel5Dynamic.AppendChild(nodeLevel6DynamicAw);
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (contentType.Contains("MyBulletin"))
                            {
                                string strTATNS       = string.Empty;
                                string strDescription = string.Empty;
                                string name           = string.Empty;
                                strTATNS = Convert.ToString(listItems[i]["TATNS"]);
                                string tatNumber = strTATNS.Split(new char[0])[0];
                                name           = Convert.ToString(listItems[i]["FileLeafRef"]);
                                strDescription = Convert.ToString(listItems[i]["ProductDescription"]);

                                if (itemType == "Folder")
                                {
                                    // Get list of existing LEVEL5 nodes.
                                    string      level5    = String.Format("/LEVEL3/LEVEL4/LEVEL5[@KEY='{0}']", tatNumber);
                                    XmlNodeList node5List = xmlDoc.SelectNodes(level5);

                                    if (node5List.Count > 0)
                                    {
                                        nodeLevel5Dynamic = node5List[0];
                                    }
                                    else
                                    {
                                        nodeLevel5Dynamic = DocumentSetNode(listItems[i], xmlDoc, tatNumber, strTATNS);
                                    }
                                    nodeLevel4.AppendChild(nodeLevel5Dynamic);
                                    // Get list of existing LEVEL6 nodes.
                                    string      level6    = String.Format("/LEVEL3/LEVEL4/LEVEL5/LEVEL6[@KEY='{0}']", name);
                                    XmlNodeList node6List = xmlDoc.SelectNodes(level6);
                                    if (node6List.Count > 0)
                                    {
                                        nodeLevel6Dynamic = node6List[0];
                                    }
                                    else
                                    {
                                        nodeLevel6Dynamic = WriteSB.DocumentSetNodeSBLevel6(listItems[i], xmlDoc, name, strDescription);
                                    }
                                    nodeLevel5Dynamic.AppendChild(nodeLevel6Dynamic);
                                }
                                else
                                {
                                    // Find level6 node with same title as level 7 then add. Find level6 in all items with same title as listItems[i]
                                    string title = Convert.ToString(listItems[i]["Title"]);
                                    var    docSetWithSameTitle = listItems.Where(s => Convert.ToString(s["Title"]) == title).Where(s => s.FileSystemObjectType == FileSystemObjectType.Folder).ToList();
                                    //Check if node 6 has same name as docset above.
                                    if (docSetWithSameTitle.Count > 0)
                                    {
                                        string      nameofDocSet = Convert.ToString(docSetWithSameTitle[0]["FileLeafRef"]);
                                        string      level6       = String.Format("/LEVEL3/LEVEL4/LEVEL5/LEVEL6[@KEY='{0}']", nameofDocSet);
                                        XmlNodeList node6List    = xmlDoc.SelectNodes(level6);
                                        if (node6List.Count > 0)
                                        {
                                            nodeLevel6Dynamic = node6List[0];
                                        }

                                        XmlNode nodeLevel7Dynamic = WriteSB.DocumentNodeSB(listItems[i], xmlDoc, inputDate);
                                        nodeLevel6Dynamic.AppendChild(nodeLevel7Dynamic);
                                    }
                                    else
                                    {
                                        logger.LogMissingTitles("Following file is missing Title. Downloaded but not included in XML: " + listItems[i].DisplayName, selectedFamXX, selectedModXX);
                                        //logger.WriteEventLog("Following file is missing Title. Downloaded but not included in XML: " + listItems[i].DisplayName);
                                    }
                                    // Download file
                                    download.FileRef(listItems[i], clientContext, selectedFamXX, selectedModXX);
                                }
                            }
                        }
                    }
                }

                string fileDirectory = ConfigurationManager.AppSettings["XmlFileLocation"];
                if (!Directory.Exists(fileDirectory))
                {
                    Directory.CreateDirectory(fileDirectory);
                }

                if (docType == "WAR")
                {
                    string strAbbreviation = string.Join("", selectedFamXX.ToArray());
                    string strModXX        = string.Join("", selectedModXX.ToArray()) + "_AW_INDEX";
                    string xmlFileLocation = fileDirectory + strAbbreviation + strModXX + ".xml";
                    xmlDoc.Save(xmlFileLocation);
                    string      formattedString = formatXml.ReplaceSpecialChar(xmlFileLocation);
                    XmlDocument formattedXml    = new XmlDocument();
                    formattedXml.LoadXml(formattedString);
                    formattedXml.Save(xmlFileLocation);
                }
                else
                {
                    string strSBAbbreviation = string.Join("", selectedFamXX.ToArray());
                    string strModXX          = string.Join("", selectedModXX.ToArray()) + "_SB_INDEX";
                    string xmlFileLocation   = fileDirectory + strSBAbbreviation + strModXX + ".xml";
                    xmlDoc.Save(xmlFileLocation);
                    string      formattedString = formatXml.ReplaceSpecialChar(xmlFileLocation);
                    XmlDocument formattedXml    = new XmlDocument();
                    formattedXml.LoadXml(formattedString);
                    formattedXml.Save(xmlFileLocation);
                }
            }
            catch (Exception exec)
            {
                logger.WriteEventLog("Please contact admin : " + exec.Message);
                throw exec;
            }
        }