public void CopyFileFromVPN(string file_type, Double dayAgo, string startTime) { Microsoft.VisualBasic.Devices.Network Network = new Microsoft.VisualBasic.Devices.Network(); string fileName = ""; fileName = startTime.ToString().Replace("/", "-") + "-VPNLOG.txt"; //Filename = startTime.ToString().Replace("/", "-") + "-VPNLOG.txt"; string sourcefile = @"\\172.16.12.138\vpnlog\" + fileName; string destinationfile = Server.MapPath(".") + "\\File\\" + fileName; try { //Response.Write("VPNLOG" + "_" + "innolux"); Network.DownloadFile(sourcefile, destinationfile, "VPNLOG", "VPN@innolux", false, 500, true); } catch (Exception) { throw; } //string drive_id=func.get_netdrive_id(); //func.start_process("net use z: \\172.16.12.138\vpnlog innolux /USER:172.16.12.138\vpnlog "); //// //DirectoryInfo dir = new DirectoryInfo("z:\\"); //// FileInfo[] files = dir.GetFiles("*.xls"); //FileInfo[] files = dir.GetFiles(file_type); //string fileName = ""; //for (int i = 0; i <= files.Length - 1; i++) //{ // if (files[i].CreationTime > DateTime.Now.AddDays(dayAgo)) // { // string sourceFile = System.IO.Path.Combine(@"z:\", files[i].Name); // string destFile = System.IO.Path.Combine(Server.MapPath(".") + "\\File\\", files[i].Name); // //files[i].CopyTo(Server.MapPath(".")+"\\File\\"); // //fileName = files[i].Name; // //File.Copy(files[i].Name, Server.MapPath(".") + "\\File\\" + fileName, true); // System.IO.File.Copy(sourceFile, destFile, true); // } //} // func.start_process("net use use z:/delete "); }
private void btnUpdate_Click(object sender, EventArgs e) { try { checkIfFileExist(Application.StartupPath + "\\UpdateExeFile.zip"); #region download the Update File from server Network network = new Network(); try { network.DownloadFile("http://kayakkitchen.com/privateeye/UpdateExeFile.zip", Application.StartupPath + "\\UpdateExeFile.zip"); } catch (Exception ex) { ErrorDump er = new ErrorDump(); er.WriteToErrorLog(ErrorDump.ErrorDumpErrorLogType.Critical, ex, "Unable to Download the Update File"); } #endregion download the Update File from server #region unzip the file try { ZipFile.ExtractToDirectory(Application.StartupPath + "\\UpdateExeFile.zip", Application.StartupPath); } catch (Exception ex) { ErrorDump er = new ErrorDump(); er.WriteToErrorLog(ErrorDump.ErrorDumpErrorLogType.Critical, ex, "Unable to Extract the Update File"); } #endregion unzip the file #region writeupdated Version No. XmlDocument xml = new XmlDocument(); xml.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath); config.AppSettings.Settings.Remove("Version"); config.AppSettings.Settings.Add("Version", serverVersion); config.Save(ConfigurationSaveMode.Minimal); xml.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); ConfigurationManager.RefreshSection("appSettings"); #endregion writeupdated Version No. File.Delete(Application.StartupPath + "\\updateVersionLog\\updateVersionLog.xml"); File.Delete(Application.StartupPath + "\\UpdateExeFile.zip"); Process.Start(Application.StartupPath + "\\updateHelper.exe"); mailUpdateConfirmation(serverVersion); Application.Exit(); } catch (Exception ex) { ErrorDump ed = new ErrorDump(); ed.WriteToErrorLog(ErrorDump.ErrorDumpErrorLogType.Critical, ex, "Update Failed."); MessageBox.Show("Update Failed. Please try Again.", "Secusys - EID Update", MessageBoxButtons.OK); } }
protected void Page_Load(object sender, EventArgs e) { //func.start_processdelete("net use z: \\192.168.1.22\report 1234 /USER:192.168.1.22\administrator "); //DirectoryInfo dir = new DirectoryInfo( Server.MapPath("..\\mynb")); //DirectoryInfo dir = new DirectoryInfo(@"z:"); Microsoft.VisualBasic.Devices.Network Network = new Microsoft.VisualBasic.Devices.Network(); string fileName = ""; fileName = "A.txt"; string sourcefile = @"\\192.168.1.22\report\" + fileName; string destinationfile = Server.MapPath(".") + "\\RUN_LOG\\" + fileName; try { Network.DownloadFile(sourcefile, destinationfile, "Administrator", "12345678", false, 100, true); } catch (Exception) { throw; } //DirectoryInfo dir = new DirectoryInfo(@"\\192.168.1.22\\report"); //FileInfo[] files = dir.GetFiles("*.xls"); //double dayAgo = -360; //string fileName = ""; //for (int i = 0; i <= files.Length - 1; i++) //{ // if (files[i].CreationTime > DateTime.Now.AddDays(dayAgo)) // { // //string sourceFile = System.IO.Path.Combine(@"z:", files[i].Name); // string sourceFile = System.IO.Path.Combine(@"\\192.168.1.22\\report", files[i].Name); // string destFile = System.IO.Path.Combine(Server.MapPath(".") + "\\RUN_LOG\\", files[i].Name); // //files[i].CopyTo(Server.MapPath(".")+"\\File\\"); // //fileName = files[i].Name; // //File.Copy(files[i].Name, Server.MapPath(".") + "\\File\\" + fileName, true); // System.IO.File.Copy(sourceFile, destFile, true); // } //} }
internal void SetNetworkWatcher() { try { if (networkWatcher == null) { networkWatcher = new Network(); } Logger.Log.InfoFormat("WatchTheNetworkAvailability = " + ApplicationSettingsManager.Settings.WatchTheNetworkAvailability, new object[0]); networkWatcher.NetworkAvailabilityChanged -= Updater_NetworkAvailabilityChanged; if (ApplicationSettingsManager.Settings.WatchTheNetworkAvailability) { networkWatcher.NetworkAvailabilityChanged += Updater_NetworkAvailabilityChanged; } } catch (Exception ex) { Logger.Log.Error("Error trying to watch the network: ", ex); } }
private void winformUpdate_Load(object sender, EventArgs e) { try { checkIfFileExist(Application.StartupPath + "\\UpdateVersionLog.zip"); #region download the File from server Network network = new Network(); try { network.DownloadFile("http://kayakkitchen.com/privateeye/UpdateVersionLog.zip", Application.StartupPath + "\\UpdateVersionLog.zip"); } catch (Exception ex) { ErrorDump er = new ErrorDump(); er.WriteToErrorLog(ErrorDump.ErrorDumpErrorLogType.Critical, ex, "Unable to Download the UpdateVersionLog File"); } #endregion download the File from server string updateVersionLogPath = Application.StartupPath + "\\updateVersionLog"; #region Create_updateVersionLogPath_Directory_ifNotExist if (!Directory.Exists(updateVersionLogPath)) Directory.CreateDirectory(updateVersionLogPath); #endregion Create_updateVersionLogPath_Directory_ifNotExist checkIfFileExist(updateVersionLogPath + "\\updateVersionLog.xml"); #region unzip the file try { ZipFile.ExtractToDirectory(Application.StartupPath + "\\UpdateVersionLog.zip", updateVersionLogPath); } catch (Exception ex) { ErrorDump er = new ErrorDump(); er.WriteToErrorLog(ErrorDump.ErrorDumpErrorLogType.Critical, ex, "Unable to Extract the UpdateVersionLog File"); } File.Delete(Application.StartupPath + "\\UpdateVersionLog.zip"); #endregion unzip the file #region compare current version are equal to server versions string appVersion = ConfigurationManager.AppSettings["Version"]; lblVersion.Text = "Version: " + appVersion; serverVersion = readXmlValue(Application.StartupPath + "\\updateVersionLog\\updateVersionLog.xml"); if (appVersion == serverVersion) { btnUpdate.Enabled = false; btnUpdate.Text = "Secusys-EID is upto date"; } else { btnUpdate.Enabled = true; btnUpdate.Text = "Secusys-EID Update is available"; } #endregion } catch (Exception ex) { ErrorDump ed = new ErrorDump(); ed.WriteToErrorLog(ErrorDump.ErrorDumpErrorLogType.Critical, ex, "Update Failed."); MessageBox.Show("Something Nasty Happened. Please try Again.", "Secusys - EID Update", MessageBoxButtons.OK); } }