private static void ReadSettings(XmlDocument d) { #region FolderRootPathName // FolderRootPathName XmlNodeList listFolderRootPathName = d.SelectNodes("//Settings/FolderRootPathNames/FolderRootName"); int k = 0; if (listFolderRootPathName != null) { if (getFolderRootPathName == null) { getFolderRootPathName = new FolderRootPathNames(); getFolderRootPathName.FolderRootName = new List <FolderRootName>(); } foreach (XmlNode node in listFolderRootPathName) { FolderRootName rootName = new FolderRootName(); XmlNode n1 = node.Attributes["Name"]; if (n1 != null) { if (n1 != null) { rootName.Name = n1.Value; } XmlNodeList list2 = node.SelectNodes("PathName"); if (list2 != null) { rootName.PathName = list2[0].InnerXml; } if (getFolderRootPathName.FolderRootName != null && !getFolderRootPathName.FolderRootName.Contains(rootName)) { getFolderRootPathName.FolderRootName.Add(rootName); } } k++; } } #endregion #region Folders // Folders XmlNodeList listFolders = d.SelectNodes("//Settings/Folders/FolderName"); int j = 0; if (listFolders != null) { if (getFolders == null) { getFolders = new Folders(); getFolders.FolderName = new List <FolderName>(); } foreach (XmlNode node in listFolders) { FolderName folderName = new FolderName(); if (folderName.FilesExtension == null) { folderName.FilesExtension = new List <FilesExtension>(); } XmlNode n1 = node.Attributes["Name"]; XmlNode n2 = node.Attributes["RootName"]; if (n1 != null) { folderName.Name = n1.Value; } if (n2 != null) { folderName.RootName = n2.Value; } XmlNodeList listFilesExtension = node.SelectNodes("Extension"); if (listFilesExtension != null) { int ik = 0; foreach (XmlNode nodeExtension in listFilesExtension) { folderName.FilesExtension.Add(new FilesExtension() { Name = nodeExtension.InnerXml }); ik++; } } getFolders.FolderName.Add(folderName); j++; } } #endregion #region Files // Files XmlNodeList listFiles = d.SelectNodes("//Settings/Files/FolderFilesName"); int jk = 0; if (listFolders != null) { if (getFiles == null) { getFiles = new Files(); getFiles.FolderFilesName = new List <FolderFilesName>(); } foreach (XmlNode node in listFiles) { FolderFilesName folderFilesName = new FolderFilesName(); if (folderFilesName.FileName == null) { folderFilesName.FileName = new List <FileName>(); } XmlNode n1 = node.Attributes["Name"]; XmlNode n2 = node.Attributes["RootName"]; if (n1 != null) { folderFilesName.Name = n1.Value; } if (n2 != null) { folderFilesName.RootName = n2.Value; } XmlNodeList listFilesName = node.SelectNodes("FileName"); if (listFilesName != null) { int ik = 0; foreach (XmlNode nodeFileName in listFilesName) { folderFilesName.FileName.Add(new FileName() { Name = nodeFileName.InnerXml }); ik++; } } getFiles.FolderFilesName.Add(folderFilesName); jk++; } } #endregion #region Authentication // Authentication XmlNodeList listServerName = d.SelectNodes("//Settings/Authentication/ServerName"); XmlNodeList listUserName = d.SelectNodes("//Settings/Authentication/UserName"); XmlNodeList listPassword = d.SelectNodes("//Settings/Authentication/Password"); if (getAuthentication == null) { getAuthentication = new Authentication(); } if (listServerName != null) { getAuthentication.ServerName = ((XmlNode)listServerName[0]).InnerXml; } if (listUserName != null) { getAuthentication.UserName = ((XmlNode)listUserName[0]).InnerXml; } if (listPassword != null) { getAuthentication.Password = ((XmlNode)listPassword[0]).InnerXml; } #endregion #region OverDate // OverDate XmlNodeList listOverDate = d.SelectNodes("//Settings/OverDate/Days"); if (getOverDate == null) { getOverDate = new OverDate(); } if (listOverDate != null) { getOverDate.Days = int.Parse(((XmlNode)listOverDate[0]).InnerXml); } #endregion }
public static void Delete() { try { FolderRootPathNames root = Settings.getFolderRootPathName; Folders targetFolder = Settings.getFolders; Files targetFile = Settings.getFiles; Authentication targetAuthentication = Settings.getAuthentication; OverDate targetDays = Settings.getOverDate; IntPtr admin_token; WindowsIdentity wid_admin = null; WindowsImpersonationContext wic = null; LogonUser(targetAuthentication.UserName, targetAuthentication.ServerName, targetAuthentication.Password, 9, 0, out admin_token); wid_admin = new WindowsIdentity(admin_token); wic = wid_admin.Impersonate(); if (root != null && root.FolderRootName != null && root.FolderRootName.Count > 0) { string rootPath = string.Empty; string[] allFiles = default(string[]); foreach (FolderName itemFolder in targetFolder.FolderName) { foreach (FolderRootName itemRoot in root.FolderRootName) { if (itemRoot.Name == itemFolder.RootName) { rootPath = itemRoot.PathName + "\\" + itemFolder.Name; foreach (FilesExtension itemFilesExtension in itemFolder.FilesExtension) { allFiles = Directory.GetFiles(rootPath, string.Concat("*.", itemFilesExtension.Name)); foreach (string itemFiles in allFiles) { doDeleteFile(itemFiles, targetDays.Days); } } } } } foreach (FolderFilesName itemFolderFilesName in targetFile.FolderFilesName) { foreach (FolderRootName itemRoot in root.FolderRootName) { if (itemRoot.Name == itemFolderFilesName.RootName) { rootPath = itemRoot.PathName; int xx = itemFolderFilesName.FileName.Count; foreach (FileName item in itemFolderFilesName.FileName) { doDeleteFile(rootPath + "\\" + item.Name, targetDays.Days); } } } } } } catch (Exception ex) { Log.WriteLogs(ex); } }