static void test() { try { string ipaddress = "192.168.67.215"; string hostServer = @"\\" + ipaddress + @"\monitor\"; // NetworkShare.ConnectToShare(hostServer, "atladmin", "7mmT@XAy"); //Connect with the new credentials NetworkShare.ConnectToShare(@"\\192.168.67.215\monitor", "atladmin", "7mmT@XAy"); string filepath = ("C:\\webs\\atl_pbx_web\\recordings\\"); DirectoryInfo diSource = new DirectoryInfo(hostServer); DirectoryInfo diTarget = new DirectoryInfo(filepath); foreach (FileInfo wav_file in diSource.GetFiles()) { if (wav_file.CreationTime < DateTime.Now.AddMinutes(-13)) { if (File.Exists(Path.Combine(diTarget.FullName, wav_file.Name))) { File.Delete(Path.Combine(diTarget.FullName, wav_file.Name)); } wav_file.MoveTo(Path.Combine(diTarget.FullName, wav_file.Name)); WriteToFile("Successfully moved file... " + wav_file.Name); } } NetworkShare.DisconnectFromShare(hostServer, false); //Disconnect from the server. } catch (Exception ex) { WriteToFile(ex.Message.ToString()); } }
static void Main(string[] args) { System.Threading.Thread.Sleep(10000); try { // FOR TEST ONLY: if (false) { args = new string[6]; args[0] = "Database=LinkManager"; args[1] = "ClientName=LinkManager"; args[2] = "DatabaseProvider=System.Data.SqlClient"; args[3] = "ConnectionString=Data%20Source%3D.%5CStandard%3BInitial%20Catalog%3DLinkManager%3BIntegrated%20Security%3DTrue"; args[4] = "FileName=C%3A%5CProjects%5CBlueocean%5CLink%5CLinkLibraries%5CLinkManager%5CClients%5CLinkOnline%5CLinkOnline%5CFileadmin%5CClientBackups%5Clinkmanager.xml"; args[5] = "BackupEntryPath=ClientBackups%2FClientBackup%5B%40Id%3D%227c384b95-8d92-4147-bd3c-4949bcceb4c7%22%5D"; } // Run through all command line arguments. foreach (string arg in args) { // Get the name of the argument. string name = arg.Split('=')[0]; // Get the value of the argument. string value = HttpUtility.UrlDecode(arg.Split('=')[1]); switch (name) { case "FileName": fileNameClientBackups = value; break; case "BackupEntryPath": clientBackupEntryPath = value; break; case "Database": databaseName = value; break; case "ClientName": clientName = value; break; case "DatabaseProvider": databaseProvider = HttpUtility.UrlDecode(value); break; case "ConnectionString": connectionString = HttpUtility.UrlDecode(value); break; } } clientUsers = new List <Guid>(); GetClientUsers(); // Build the full path to the backup directory name. string directoryName = Path.Combine( ConfigurationManager.AppSettings["BackupRoot"], DateTime.Now.ToString("yyyy"), DateTime.Now.ToString("MMM"), clientName + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") ); if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["Username"])) { if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } // Backup the client's definition files. BackupFileSystem(directoryName); // Backup the client's database. BackupDatabase(Path.Combine( directoryName, clientName + ".bak" )); } else { string error = NetworkShare.ConnectToShare( ConfigurationManager.AppSettings["BackupRoot"], ConfigurationManager.AppSettings["Username"], ConfigurationManager.AppSettings["Password"] ); /*using (new NetworkConnection(ConfigurationManager.AppSettings["BackupRoot"], new System.Net.NetworkCredential( * ConfigurationManager.AppSettings["Username"], * ConfigurationManager.AppSettings["Password"] * )))*/ { if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } // Backup the client's definition files. BackupFileSystem(directoryName); string tempFile = Path.GetTempFileName() + ".bak"; // Backup the client's database. BackupDatabase(tempFile); File.Move(tempFile, Path.Combine( directoryName, clientName + ".bak" )); } NetworkShare.DisconnectFromShare( ConfigurationManager.AppSettings["BackupRoot"], false ); } XmlDocument document = new XmlDocument(); document.Load(fileNameClientBackups); XmlNode xmlNode = document.SelectSingleNode(clientBackupEntryPath); xmlNode.Attributes["Status"].Value = "Finished"; xmlNode.Attributes["FinishDate"].Value = DateTime.Now.ToString(); xmlNode.Attributes["BackupPath"].Value = directoryName; document.Save(fileNameClientBackups); string zipPath = Path.Combine( ConfigurationManager.AppSettings["BackupRoot"], "Archives", DateTime.Now.ToString("yyyy"), DateTime.Now.ToString("MMM") ); string zipArchiveName = Path.Combine( zipPath, clientName + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".zip" ); if (!Directory.Exists(zipPath)) { Directory.CreateDirectory(zipPath); } StreamWriter writer = new StreamWriter(zipArchiveName); ZipArchive zipArchive = new ZipArchive(writer.BaseStream, ZipArchiveMode.Create); CreateEntryFromDirectory(zipArchive, directoryName, false); zipArchive.Dispose(); } catch (Exception ex) { XmlDocument document = new XmlDocument(); document.Load(fileNameClientBackups); XmlNode xmlNode = document.SelectSingleNode(clientBackupEntryPath); xmlNode.Attributes["Status"].Value = "Failed"; xmlNode.Attributes["FinishDate"].Value = DateTime.Now.ToString(); xmlNode.Attributes["BackupPath"].Value = ""; xmlNode.InnerXml = ex.ToString(); document.Save(fileNameClientBackups); } }