static void Main(string[] args) { //init datasets for later use previousState = new SofinsDS(); currentState = new SofinsDS(); appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); appDataFolder = Path.Combine(appDataFolder, "Sofins"); Properties.Settings.Default.computerID = Properties.Settings.Default.computerID ; if (currentState.PopulateFromRegistry() == false) MessageBox.Show("Unable to get the list of installed programs from registry!"); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new SoftwareInspectorForm()); }
public static bool PostXMLFileToSite(FileInfo fi) { if (fi == null || !fi.Exists) return false; try { SofinsDS sds = new SofinsDS(); sds.LoadFromAppDataFolder(fi.Directory, fi); string dsAsString = sds.GetXml(); System.Net.WebRequest reqPOST = System.Net.WebRequest.Create(@"http://2.homer.cz8.ru/api/programs"); reqPOST.Method = "POST"; // Устанавливаем метод передачи данных в POST reqPOST.Timeout = 120000; // Устанавливаем таймаут соединения reqPOST.ContentType = "text/xml"; // указываем тип контента // передаем список пар параметров / значений для запрашиваемого скрипта методом POST // здесь используется кодировка cp1251 для кодирования кирилицы и спец. символов в значениях параметров // Если скрипт должен принимать данные в utf-8, то нужно выбрать Encodinf.UTF8 byte[] sentData = Encoding.UTF8.GetBytes(dsAsString); reqPOST.ContentLength = sentData.Length; System.IO.Stream sendStream = reqPOST.GetRequestStream(); sendStream.Write(sentData, 0, sentData.Length); sendStream.Close(); System.Net.WebResponse result = reqPOST.GetResponse(); return true; } catch (Exception ex) { return false; } //System.Net.WebClient wc = new System.Net.WebClient(); //wc.Credentials = new System.Net.NetworkCredential("usr", "mypassword"); //byte[] response = wc.DownloadData("http://localhost/testlogin"); //CookieContainer cookies = new CookieContainer(); //Request.CookieContainer = cookies; //// И после каждого запроса обновляем контейнер: //cookies = Request.CookieContainer; }
static void Main(string[] args) { //init datasets for later use previousState = new SofinsDS(); currentState = new SofinsDS(); appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); appDataFolder = Path.Combine(appDataFolder, "Sofins"); //yes, a magic string here //check if it's time to scan program list DateTime dateOfNextCheck = Properties.Settings.Default.lastLaunchTime.Add(Properties.Settings.Default.reportPeriod); if (DateTime.Now < dateOfNextCheck && System.Environment.MachineName.ToLower() != "homestation") { return; } else { //read the last saved list and compare it to the current list of programs if (previousState.LoadFromAppDataFolder(new DirectoryInfo(Program.appDataFolder), null) == false) { //maybe it's the first run of the program, nothing to load currentState.PopulateFromRegistry(); currentStateSavedTo = currentState.SaveToAppDataFolder(new DirectoryInfo(Program.appDataFolder)); return; } else { //everything's OK currentState.PopulateFromRegistry(); //init software blacklist blacklist = new SofinsDS(); string blacklist_filename = Path.Combine(Directory.GetCurrentDirectory(), "program_blacklist.xml"); blacklist.LoadFromAppDataFolder(null, new FileInfo(blacklist_filename)); //mark programs that shouldn't be processed foreach (SofinsDS.InstalledSoftwareRow inso in currentState.InstalledSoftware ) if (-1 != blacklist.IndexOf(inso.sName )) inso.bHidden = true; currentStateSavedTo = currentState.SaveToAppDataFolder(new DirectoryInfo(Program.appDataFolder)); for (int counter = currentState.InstalledSoftware.Count-1; counter > 0; --counter) if (currentState.InstalledSoftware[counter].bHidden == true) currentState.InstalledSoftware.RemoveInstalledSoftwareRow(currentState.InstalledSoftware[counter]); currentStateSavedTo = currentState.SaveToAppDataFolder(new DirectoryInfo(Program.appDataFolder)); //foreach (SofinsDS.InstalledSoftwareRow isr in currentState.InstalledSoftware) //{ // if (previousState.IndexOf(isr.sName) == -1) // //TODO: a new program found, need to post information about this change to the server // break; //} bool result = SofinsCommon.SofinsCommon.PostXMLFileToSite(new FileInfo(currentStateSavedTo)); } //update lastLaunchTime variable Properties.Settings.Default.lastLaunchTime = DateTime.Now; Properties.Settings.Default.Save(); } }