private void rtvFiles( ) { try { sHost = LoadClient.Properties.Settings.Default.Host; sUser = LoadClient.Properties.Settings.Default.User; sPass = LoadClient.Properties.Settings.Default.Password; ftp = new BasicFTPClient(sUser, sPass, sHost); //Retrieve Folders from Ftp Server Console.WriteLine("Ftp session Begins"); string[] sFolders = ftp.FTPListTree(@"ftp://" + sHost + LoadClient.Properties.Settings.Default.FileStore); Console.WriteLine("Download session Begins"); // 9 August 2011 // do not execute without a proper customer list // this would clean out the xml direcotry. DownloadFiles(sFolders); } catch (Exception ex) { throw ex; } return; }
private void listUnid( ) { try { // Retrieve Unids from Domino Console.WriteLine("Domino Web Service session Begins"); fetchCustomerList(); sHost = Properties.Settings.Default.Host; sUser = Properties.Settings.Default.User; sPass = Properties.Settings.Default.Password; BasicFTPClient ftp = new BasicFTPClient(sUser, sPass, sHost); //Retrieve Folders from Ftp Server Console.WriteLine("Ftp session Begins"); string[] sFolders = ftp.FTPListFolders(@"ftp://" + sHost + @"/XML", false); Console.WriteLine("Compare session Begins"); // 9 August 2011 // do not execute without a proper customer list // this would clean out the xml direcotry. if (slCustomers.Count > 0) { CompareLists(sFolders, bDelFlag); } } catch (Exception ex) { throw ex; } return; }
private void btnUpload_Click(object sender, EventArgs e) { lblUpload.Visible = true; if (this.clBoxCityList.CheckedItems.Count > 0) { var list = generateImages(); BasicFTPClient MyClient = new BasicFTPClient(""); if (list.Count > 0) { try { foreach (string city in this.clBoxCityList.CheckedItems) { XmlNode hostingNode = CommonHelper.randomizeHost(city); foreach (CarStockURL carImage in list) { MyClient.connect(); Stream s = new MemoryStream(carImage.ImageBytes); string imageURL = CommonHelper.generateImageURL(carImage.ImageRow); string imageFileName = CommonHelper.generateImageFileName(carImage.ImageRow); carImage.ImageURL = hostingNode.Attributes["HostName"].Value + imageURL + "/" + imageFileName; MyClient.Upload(hostingNode, s, imageURL, imageFileName); MyClient.closeConnect(); s.Close(); } //CommonHelper.generateXMLFile(list, city); this.listFinishedCities.Items.Add(city); this.Refresh(); System.Threading.Thread.Sleep(1000); } lblUpload.Visible = false; System.Windows.Forms.MessageBox.Show("Uploading images for " + clsVariables.currentDealer.DealershipName + " Is Done", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("Uploading Failed " + ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } else { System.Windows.Forms.MessageBox.Show("Please choose at least one city to upload images", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void CompareLists(string[] sFolders, bool bDeleteFlag) { string sFileName = Properties.Settings.Default.LogFileLoc + @"\" + sHost + @"_Log_" + Convert.ToString(DateTime.Now.DayOfWeek) + ".txt"; StreamWriter sw = new StreamWriter(sFileName, false); sw.WriteLine("Cleanup Begins on {0} at {1}", sHost, DateTime.Now); if (bDeleteFlag) { sw.WriteLine("Delete Flag is active."); } else { sw.WriteLine("Delete Flag is inactive."); } int iHits = 0, iMisses = 0; BasicFTPClient ftp = new BasicFTPClient(sUser, sPass, sHost); // Compare the Folders on FTP Server // Against the Contents of the Domino Server foreach (string fld in sFolders) { string usfld = fld.ToUpper(); string ssTerm = usfld.Replace(@"FTP://" + sHost.ToUpper() + @"/XML/", ""); if (slCustomers.Contains(ssTerm)) { // do nothing Debug.Print("Keep it!{0}", ssTerm); Console.WriteLine("Keeping {0}", ssTerm); iHits += 1; sw.WriteLine("Keeping {0}", ssTerm); } else { Debug.Print("Get Rid of it {0}", ssTerm); Console.WriteLine("Killing {0}", ssTerm); sw.WriteLine("Killing {0}", ssTerm); if (bDeleteFlag) { try { iMisses += 1; // recursive delete on folder - bye bye // 9 August 2011 ftp.DeleteTree(@"ftp://" + sHost + @"/xml/" + ssTerm); // Chg -001 CleanXml(ssTerm); // End change } catch (Exception ex) { throw ex; } } } } // -001 // Compare the xml on file in sql server to Domino List // If missing Delete SqlDataReader dr; using (SqlConnection cn = new SqlConnection(Properties.Settings.Default.SqlConnString)) { cn.Open(); SqlConnection cn2 = new SqlConnection(Properties.Settings.Default.SqlConnString); cn2.Open(); SqlCommand cmd = new SqlCommand("select distinct unid from dbo.XmlParmsDtl order by unid"); cmd.CommandType = CommandType.Text; cmd.Connection = cn; dr = cmd.ExecuteReader(); while (dr.Read()) { string sOnFileUnid = dr["Unid"].ToString(); if (slCustomers.Contains(sOnFileUnid)) { } else // Get rid of it { if (bDeleteFlag) { sw.WriteLine("Killing {0} on SQL Server", sOnFileUnid); using (SqlCommand cmd2 = cn2.CreateCommand()) { cmd2.CommandType = CommandType.StoredProcedure; cmd2.CommandText = "usp_Clean_Xml_Rows"; cmd2.CommandType = CommandType.StoredProcedure; cmd2.Parameters.Add( new SqlParameter("@Unid", sOnFileUnid)); cmd2.ExecuteNonQuery(); } } } } cn.Close(); cn2.Close(); cn2.Dispose(); } // -001 End Debug.Print("Hits = {0}, and Misses = {1}", iHits, iMisses); Console.WriteLine("Hits = {0}, and Misses = {1}", iHits, iMisses); sw.WriteLine("Unids Hits = {0}, and Unids Deleted = {1}", iHits, iMisses); sw.WriteLine("Cleanup Ends on {0} at {1}", sHost, DateTime.Now); sw.Flush(); sw.Close(); sw.Dispose(); }