public void CloseSession(string url) { try { if (url.Contains(CatalogApi.UrlConstants.CitroenRoot) == true) { RequestProcessor.CitroenPortal.CloseSession(url); } else if (url.Contains(CatalogApi.UrlConstants.PeugeotRoot) == true) { RequestProcessor.PeugeotPortal.CloseSession(url); } else if (url.Contains(CatalogApi.UrlConstants.Partslink24Root)) { RequestProcessor.PartslinkPortal.CloseSession(url); } else if (url.Contains(CatalogApi.UrlConstants.ChevroletOpelGroupRoot)) { RequestProcessor.ChevroletPortal.CloseSession(url); } else { throw new System.Exception("Close session error"); } } catch (System.Exception ex) { ErrorLogHelper.AddErrorInLog("CloseSession()", ex.Message + "|" + ex.StackTrace); ConsoleHelper.Error(string.Format("{0} || {1} || {2}", ex.Message, ex.StackTrace, ex.Data)); } }
public MainWindow() { try { _dictBrandLauncherView = new Dictionary <int, BrandLauncherView>(); _dictBrowserLauncherView = new Dictionary <KeyBrowserLauncherView, BrowserLauncherView>(); EventNewBrandLauncherView += new Action <SystemTime, CatalogApi.Settings.Brand>(newBrandLauncherView); this.InitializeComponent(); base.DataContext = this.News; this.NewsBox.ItemsSource = this.News; this.InitializeSettings(); this.StartNewEventSession(); this.CheckForUpdateAndStartProcess(); } catch (Exception exception) { ErrorLogHelper.AddErrorInLog("Запуск приложения - MainWindow()", exception.Message + " | " + exception.StackTrace); MessageBox.Show(exception.Message + " | " + exception.StackTrace); if (!(Application.Current == null)) { Application.Current.Shutdown(0); } else { ; } } }
public System.IO.Stream DownloadUpdate() { System.IO.Stream result; try { lock (RequestProcessor.SyncLoadNewUpdate) { string fileName = System.IO.Path.Combine("Temp", "Temp.zip"); if (!System.IO.Directory.Exists("Temp")) { System.IO.Directory.CreateDirectory("Temp"); } if (!System.IO.File.Exists(fileName)) { ZipFile.CreateFromDirectory("Temp", fileName); } result = System.IO.File.OpenRead(fileName); } } catch (System.Exception ex) { ErrorLogHelper.AddErrorInLog("DownloadUpdate()", ex.Message + "|" + ex.StackTrace); ConsoleHelper.Error(string.Format("{0} || {1} || {2}", ex.Message, ex.StackTrace, ex.Data)); result = null; } return(result); }
public void OpenSession(string url, long providerId, bool forceSession) { try { if (url.Contains(CatalogApi.UrlConstants.CitroenRoot) == true) { RequestProcessor.CitroenPortal.OpenSession(url, providerId, forceSession); } else if (url.Contains(CatalogApi.UrlConstants.PeugeotRoot) == true) { RequestProcessor.PeugeotPortal.OpenSession(url, providerId, forceSession); } else if (url.Contains(CatalogApi.UrlConstants.Partslink24Root)) { RequestProcessor.PartslinkPortal.OpenSession(url, providerId, forceSession); } else if (url.Contains(CatalogApi.UrlConstants.ChevroletOpelGroupRoot)) { RequestProcessor.ChevroletPortal.OpenSession(url, providerId, forceSession); // RequestProcessor.OpelPortal.OpenSession(url, forceSession); } else { throw new System.Exception(string.Format("RequestProccessor::OpenSession(Url={0}) Error..." , url)); } } catch (System.Exception ex) { ErrorLogHelper.AddErrorInLog(string.Format("OpenSession(url={0}, force={1})", url, forceSession), ex.Message + "|" + ex.StackTrace); ConsoleHelper.Error(string.Format("{0} || {1} || {2}", ex.Message, ex.StackTrace, ex.Data)); } }
private void ExtractResourcesToFolder(LauncherSettings settings) { try { string root = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), ResourceManager.Root); try { ClearRootDirectory(root); } catch (Exception e) { ErrorLogHelper.AddErrorInLog(string.Format("::ExtractResourcesToFolder (step=clearRootDirectory) - root={0}..." , root) , string.Format("{0} | {1}", e.Message, e.StackTrace)); } try { this.CreateRootDirectory(root, settings); } catch (Exception e) { ErrorLogHelper.AddErrorInLog(string.Format("::ExtractResourcesToFolder (step=createRootDirectory) - root={0}..." , root) , string.Format("{0} | {1}", e.Message, e.StackTrace)); } } catch { } }
private static void Main() { try { using (ServiceHost proxyHost = new ServiceHost(typeof(RequestProcessor), new Uri[] { new Uri(ConfigurationManager.AppSettings["ProxyAddress"]) })) { using (ServiceHost storageHost = new ServiceHost(typeof(RequestProcessor), new Uri[] { new Uri(ConfigurationManager.AppSettings["StorageAddress"]) })) { ServiceMetadataBehavior metadataBehavior = new ServiceMetadataBehavior { HttpGetEnabled = true, MetadataExporter = { PolicyVersion = PolicyVersion.Policy15 } }; Program.SetupHost(proxyHost, metadataBehavior); Program.SetupHost(storageHost, metadataBehavior); ConsoleHelper.Info(string.Format("Proxy Address: {0}", new Uri(ConfigurationManager.AppSettings["ProxyAddress"]).Authority)); while (true) { ConsoleKey pressedKey = Console.ReadKey(true).Key; ConsoleKey consoleKey = pressedKey; if (consoleKey != ConsoleKey.Escape) { ConsoleHelper.Warning("Press 'ESCAPE' to stop proxy server.."); } else { Program.RpClient.CloseSession("https://www.partslink24.com/partslink24/user/logout.do"); Program.StopHost(proxyHost); Program.StopHost(storageHost); ConsoleHelper.Warning("Proxy session was stopped. Now can close console window"); } } } } } catch (Exception ex) { ErrorLogHelper.AddErrorInLog("Main()", ex.Message + "|" + ex.StackTrace); using (FileStream fileStream = new FileStream("ServerHost_Exception.txt", FileMode.OpenOrCreate, FileAccess.Write)) { using (StreamWriter streamWriter = new StreamWriter(fileStream)) { streamWriter.Write("{0} / {1}", ex.Message, ex.StackTrace); } } Environment.Exit(0); } }
private void CreateRootDirectory(string root, LauncherSettings settings) { string path = string.Empty; foreach (GroupSet set in settings.Groups) { foreach (CatalogApi.Settings.GroupBox box in set.GroupBoxs) { foreach (CatalogApi.Settings.Brand brand in box.Brands) { try { path = Path.Combine(root, brand.NameAndFolder); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (brand.IconPathImg != null) { File.WriteAllBytes(string.Join(@"\", new string[] { path, brand.IconPath }), brand.IconPathImg); } if (brand.IconPath2Img != null) { File.WriteAllBytes(string.Join(@"\", new string[] { path, brand.IconPath2 }), brand.IconPath2Img); } foreach (BrandProvider provider in brand.Providers) { foreach (CatalogApi.Settings.CommandFile file in provider.CommandFiles) { using (StreamWriter writer = new StreamWriter(string.Join(@"\", new string[] { path, file.FileName }))) { writer.Write(file.FileContent); } } foreach (CatalogApi.Settings.ProviderFile file2 in provider.ProviderFiles) { File.WriteAllBytes(string.Join(@"\", new string[] { path, file2.FileName }), file2.FileContent); } } } catch (Exception e) { ErrorLogHelper.AddErrorInLog(string.Format("::CreateRootDirectory (root={0}, brand.Id={1}, brand.NameAndFolder={2}, path={3}) - ..." , root , brand.BrandId, brand.NameAndFolder , path) , string.Format("{0} | {1}", e.Message, e.StackTrace)); } } } } }
private void OnDeactivated(object sender, EventArgs eventArgs) { try { base.Icon = new BitmapImage(new Uri("pack://application:,,,/Resources/FavInactive.ico")); } catch (Exception exception) { ErrorLogHelper.AddErrorInLog("OnDeactivated", exception.Message + " | " + exception.StackTrace); new ReportWindow().ShowReportWindow(exception); } }
private void OnDeactivated(object sender, EventArgs eventArgs) { try { base.Icon = new BitmapImage(new Uri("pack://application:,,,/Resources/FavInactive.ico")); } catch (Exception exception) { ErrorLogHelper.AddErrorInLog("OnDeactivated", exception.Message + " | " + exception.StackTrace); MessageBox.Show(string.Format("::OnDeactivated () - ...{0}Message={1}{0}StackTrace={2}", Environment.NewLine, exception.Message, exception.StackTrace)); //new ReportWindow().ShowReportWindow(exception); } }
public string DownloadGuiSettigs() { string result; try { lock (RequestProcessor.SyncLoadGuiSettings) { using (AvtoritetEntities ae = new AvtoritetEntities()) { SettingUpdate updateFlag = ae.SettingUpdate.FirstOrDefault <SettingUpdate>(); string settings = string.Empty; string baseDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); string root = System.IO.Path.Combine(baseDir, ResourceManager.Root); string path = string.Join("\\", new string[] { root, "settingui.zip" }); if (updateFlag != null && (!updateFlag.Update || !System.IO.File.Exists(path))) { settings = RequestProcessor.ReadConfigToString(); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } System.IO.File.WriteAllText(path, settings, System.Text.Encoding.Unicode); updateFlag.Update = true; ae.SaveChanges(); } else if (System.IO.File.Exists(path)) { settings = System.IO.File.ReadAllText(path, System.Text.Encoding.Unicode); } else { settings = null; } result = settings; } } } catch (System.Exception ex) { ErrorLogHelper.AddErrorInLog("DownloadGuiSettigs()", ex.Message + "|" + ex.StackTrace); result = string.Format("[{0}] {1} / {2}", System.DateTime.Now, ex.Message, ex.StackTrace); } return(result); }
private static void LoadUpdates() { Exception exception; try { using (AvtoritetEntities entities = new AvtoritetEntities()) { //if (!(entities.Database.Connection.State == ConnectionState.Closed)) //{ int? settingVersion = entities.SettingUpdate.FirstOrDefault().SettingVersion; Version version = new Version(entities.VersionLog.FirstOrDefault().Value) , version2 = new Version(JsonConvert.DeserializeObject <VersionEntity>(FileHelper.OpenFile("Version.json")).Version); if (version > version2) { try { } catch (Exception exception1) { exception = exception1; ErrorLogHelper.AddErrorInLog("LoadUpdates()", exception.Message + " | " + exception.StackTrace); } } if (!System.IO.File.Exists("settingver.txt")) { System.IO.File.WriteAllText("settingver.txt", "1"); } int num = int.Parse(System.IO.File.ReadAllText("settingver.txt")); int?nullable2 = settingVersion; int num2 = num; if ((nullable2.GetValueOrDefault() > num2) && (nullable2.HasValue == true)) { launcherSettings = new SettingsFactory(categoryEventHandler).DownloadSettings(true, true); System.IO.File.WriteAllText("settingver.txt", settingVersion.ToString()); HaveNewUpdate = true; } //} //else //ErrorLogHelper.AddErrorInLog("Обновление приложения - LoadUpdates() - ...", string.Format("Состояние БД={0}", entities.Database.Connection.State.ToString())); } } catch (Exception exception2) { exception = exception2; ErrorLogHelper.AddErrorInLog("Обновление приложения - LoadUpdates()", exception.Message + " | " + exception.StackTrace); MessageBox.Show(exception.Message + " | " + exception.StackTrace); } }
private static void FreeOccupiedAccount() { try { if (!((AccountManager.Account == null) || (string.IsNullOrEmpty(AccountManager.Account.Name) == true))) { RequestHelper.Client.FreeOccupiedAccount(AccountManager.Account.Name); } else { ; } } catch (Exception e) { ErrorLogHelper.AddErrorInLog(string.Format(@"MainWindow::FreeOccupiedAccount () - ...") , string.Format("{0} | {1}", e.Message, e.StackTrace)); } }
public string GetCookies(string url) { string result; Uri uri = new Uri(url); ConsoleHelper.Debug(string.Format("GetCookies() - url={0} || �ץולא={1} || �מסע={2} || אבס.={3} || כמך.={4} || פאיכ?={5}" , url , uri.Scheme , uri.Host , uri.AbsolutePath , uri.LocalPath , uri.IsFile)); try { if (url.Contains(CatalogApi.UrlConstants.CitroenRoot) == true) { result = RequestProcessor.CitroenPortal.GetCookies(url); } else if (url.Contains(CatalogApi.UrlConstants.PeugeotRoot) == true) { result = RequestProcessor.PeugeotPortal.GetCookies(url); } else if (url.Contains(CatalogApi.UrlConstants.Partslink24Root)) { result = RequestProcessor.PartslinkPortal.GetCookies(url); } else if (url.Contains(CatalogApi.UrlConstants.ChevroletOpelGroupRoot)) { result = RequestProcessor.ChevroletPortal.GetCookies(url); } else { throw new System.Exception(string.Format("Getting cookies error (url={0}) - ..", url)); } } catch (System.Exception ex) { ErrorLogHelper.AddErrorInLog("GetCookies()", ex.Message + "|" + ex.StackTrace); ConsoleHelper.Error(string.Format("{0} || {1} || {2}", ex.Message, ex.StackTrace, ex.Data)); result = string.Empty; } return(result); }
public string GetCookies(string url) { string result; try { if (url.Contains("citroen")) { result = RequestProcessor.CitroenPortal.GetCookies(url); } else if (url.Contains("peugeot")) { result = RequestProcessor.PeugeotPortal.GetCookies(url); } else { if (!url.Contains("partslink24")) { if (url.Contains("imtportal.gm")) { if (url.Contains("opel")) { result = RequestProcessor.OpelPortal.GetCookies(url.Replace("opel", string.Empty)); return(result); } if (url.Contains("chevrolet")) { result = RequestProcessor.ChevroletPortal.GetCookies(url.Replace("opel", string.Empty)); return(result); } } throw new System.Exception("Getting cookies error"); } result = RequestProcessor.PartslinkPortal.GetCookies(url); } } catch (System.Exception ex) { ErrorLogHelper.AddErrorInLog("GetCookies()", ex.Message + "|" + ex.StackTrace); ConsoleHelper.Error(string.Format("{0} || {1} || {2}", ex.Message, ex.StackTrace, ex.Data)); result = string.Empty; } return(result); }
private void CheckForUpdateAndStartProcess() { string nameUpdateDirectory = string.Empty , nameAppVersionFile = string.Empty; bool fileExists = false; try { CatalogApi.Logging.Info(string.Format("::CheckForUpdateAndStartProcess() - вход...")); nameUpdateDirectory = ResourceManager.UpdateDirectory; nameAppVersionFile = new CatalogApi.Settings.File(ConfigurationManager.AppSettings["FileAppVersion"]).Name; if (Directory.Exists(nameUpdateDirectory)) { IoHelper.DirectoryClear(nameUpdateDirectory); } AccountManager.Account = RequestHelper.Client.GetUnoccupiedAccount(); launcherSettings = new SettingsFactory(categoryEventHandler).DownloadSettings(false, true); this.BuildWindow(); if (System.IO.File.Exists(nameAppVersionFile)) { this.RefreshTitle(new Version(JsonConvert.DeserializeObject <VersionEntity>(IoHelper.OpenFile(nameAppVersionFile, out fileExists)).Version).ToString()); } else { ; } this.SetWindowVisibility(Visibility.Visible); CatalogApi.Logging.Info(string.Format("::CheckForUpdateAndStartProcess() - успех...")); } catch (Exception exception) { ErrorLogHelper.AddErrorInLog("CheckForUpdateAndStartProcess()", exception.Message + " | " + exception.StackTrace); MessageBox.Show(exception.Message + " | " + exception.StackTrace); Application.Current.Shutdown(-1); } }
public MainWindow() { try { this.InitializeComponent(); base.DataContext = this.News; this.NewsBox.ItemsSource = this.News; this.InitializeSettings(); this.StartNewEventSession(); this.CheckForUpdateAndStartProcess(); } catch (Exception exception) { ErrorLogHelper.AddErrorInLog("Запуск приложения - MainWindow()", exception.Message + " | " + exception.StackTrace); MessageBox.Show(exception.Message + " | " + exception.StackTrace); Application.Current.Shutdown(0); } }
public System.IO.Stream DownloadSettings() { System.IO.Stream result; try { lock (RequestProcessor.SyncLoadSettings) { string settings = this.settingsZipper.CreateZipFromSettings(RequestProcessor.ReadConfigToString()); result = System.IO.File.OpenRead(settings); } } catch (System.Exception ex) { ErrorLogHelper.AddErrorInLog("DownloadSettings()", ex.Message + "|" + ex.StackTrace); ConsoleHelper.Error(string.Format("{0} || {1} || {2}", ex.Message, ex.StackTrace, ex.Data)); result = null; } return(result); }
public bool IsServiceAvailable() { bool result; try { CookieContainer cookieContainer = new CookieContainer(); IRequestHandler requestHandler = RequestHandlerFactory.Create("http://www.partslink24.com/", string.Empty, string.Empty, null); Task <HttpResponseMessage> responseMessage = requestHandler.GetSessionAsync("http://www.partslink24.com/", cookieContainer); string content = responseMessage.Result.Content.ReadAsStringAsync().Result; result = (!content.Contains("maintenance_general") && int.Parse(RequestProcessor.GetConfig("Partslink")) > 0); } catch (System.Exception ex) { ErrorLogHelper.AddErrorInLog("IsServiceAvailable()", ex.Message + "|" + ex.StackTrace); ConsoleHelper.Error(string.Format("{0} || {1} || {2}", ex.Message, ex.StackTrace, ex.Data)); result = false; } return(result); }
public System.IO.Stream DownloadUpdate() { System.IO.Stream result; string fileName = string.Empty; try { lock (RequestProcessor.SyncLoadNewUpdate) { fileName = System.IO.Path.Combine(ResourceManager.UpdateDirectory, new CatalogApi.Settings.File(ResourceManager.Archive).Name); if (!System.IO.Directory.Exists(ResourceManager.UpdateDirectory)) { System.IO.Directory.CreateDirectory(ResourceManager.UpdateDirectory); } else { ; } if (!System.IO.File.Exists(fileName)) { ZipFile.CreateFromDirectory(ResourceManager.UpdateDirectory, fileName); } else { ; } result = System.IO.File.OpenRead(fileName); } } catch (System.Exception ex) { ErrorLogHelper.AddErrorInLog("DownloadUpdate()", ex.Message + "|" + ex.StackTrace); ConsoleHelper.Error(string.Format("{0} || {1} || {2}", ex.Message, ex.StackTrace, ex.Data)); result = null; } return(result); }
protected void CloseSession(/*string url,*/ /*IRequestHandler reqHandler,*/ CookieContainer cookieContainer) { int result_close = 1; // по умолчанию - ничего не делаем try { if (m_requestHandler != null) { m_requestHandler.Close(cookieContainer).Wait(); result_close = 0; } else { //result_close = 1; //IRequestHandler request = RequestHandlerFactory.Create(url, string.Empty, string.Empty, null); // if (request != null) { // request.Close(cookieContainer).Wait(); // } else // ; } } catch (Exception e) { result_close = -1; string error_message = string.Empty; error_message = string.Format("BrandPortal::CloseSession (Portal={0}, cookies.Count={1})", this.GetType().FullName, cookieContainer.Count); ErrorLogHelper.AddErrorInLog(error_message , string.Format("{0} | {1}", e.Message, e.StackTrace)); ConsoleHelper.Warning(error_message); } finally { ConsoleHelper.Warning(string.Format("Session [Portal={0}, result={1}] was closed" , this.GetType().FullName //url , result_close == -1 ? "Error" : result_close == 0 ? "Success" : result_close == 1 ? "Passed" : "Unknown")); _session.Remove(this); } }
public void LogConnection(string machineName, string launcherVersion) { try { if (!RequestProcessor.UserStatistics.ContainsKey(machineName)) { RequestProcessor.UserStatistics.Add(machineName, System.DateTime.Now); ConsoleHelper.Info(string.Concat(new object[] { machineName, " Connected. ", launcherVersion, ". Total Connections: ", RequestProcessor.UserStatistics.Count })); } else if (RequestProcessor.UserStatistics.Remove(machineName)) { RequestProcessor.UserStatistics.Add(machineName, System.DateTime.Now); ConsoleHelper.Info(string.Concat(new object[] { machineName, " Connected. ", launcherVersion, ". Total Connections: ", RequestProcessor.UserStatistics.Count })); } else { ConsoleHelper.Error(machineName + " can't be deleted. Total Connections: " + RequestProcessor.UserStatistics.Count); } } catch (System.Exception ex) { ErrorLogHelper.AddErrorInLog("LogConnection()", ex.Message + "|" + ex.StackTrace); ConsoleHelper.Error(ex.Message + " || " + ex.StackTrace); } }
public void CloseSession(string url) { try { if (url.Contains("citroen")) { RequestProcessor.CitroenPortal.CloseSession(url); } else if (url.Contains("peugeot")) { RequestProcessor.PeugeotPortal.CloseSession(url); } else if (url.Contains("partslink24")) { RequestProcessor.PartslinkPortal.CloseSession(url); } else { if (!url.Contains("imtportal.gm")) { throw new System.Exception("Close session error"); } if (url.Contains("opel")) { RequestProcessor.OpelPortal.CloseSession(url.Replace("opel", string.Empty)); } if (url.Contains("chevrolet")) { RequestProcessor.ChevroletPortal.CloseSession(url.Replace("chevrolet", string.Empty)); } } } catch (System.Exception ex) { ErrorLogHelper.AddErrorInLog("CloseSession()", ex.Message + "|" + ex.StackTrace); ConsoleHelper.Error(string.Format("{0} || {1} || {2}", ex.Message, ex.StackTrace, ex.Data)); } }
private void OnLoaded(object sender, RoutedEventArgs routedEventArgs) { try { this.brand = (Brand)base.DataContext; if (this.brand.IconPath.ToLower().Contains("gaz")) { this.Alert.Visibility = Visibility.Visible; } base.Icon = new BitmapImage(new Uri("pack://application:,,,/Resources/FavInactive.ico")); this.categories.Clear(); foreach (BrandProvider provider in this.brand.Providers) { this.AddLaunchButton(this.brand, provider); } this.ImageHostControl.Source = UiHelper.LoadImage(this.brand.IconPath2Img); } catch (Exception exception) { ErrorLogHelper.AddErrorInLog("OnLoaded", exception.Message + " | " + exception.StackTrace); CatalogApi.Logging.Exception(exception); } }
private void CheckForUpdateAndStartProcess() { try { if (Directory.Exists("Temp")) { IoHelper.DirectoryClear("Temp"); } AccountManager.Account = RequestHelper.Client.GetUnoccupiedAccount(); launcherSettings = new SettingsFactory(categoryEventHandler).DownloadSettings(false, true); this.BuildWindow(); if (System.IO.File.Exists("Version.json")) { this.RefreshTitle(new Version(JsonConvert.DeserializeObject <VersionEntity>(FileHelper.OpenFile("Version.json")).Version).ToString()); } this.SetWindowVisibility(Visibility.Visible); } catch (Exception exception) { ErrorLogHelper.AddErrorInLog("CheckForUpdateAndStartProcess()", exception.Message + " | " + exception.StackTrace); MessageBox.Show(exception.Message + " | " + exception.StackTrace); } }
private void InitButtonClick(object sender, RoutedEventArgs e) { try { string url = ((ButtonModel)sender).DataContext.ToString(); if (url.StartsWith("http") || url.StartsWith("https")) { if (url.Contains("imtportal.gm")) { StartSeparateProcess(url); } else { string loginFromDB = SettingsFactory.GetLoginFromDB(((ButtonModel)sender).ProviderId); string pswFromDB = SettingsFactory.GetPswFromDB(((ButtonModel)sender).ProviderId); string content = ((ButtonModel)sender).Content; new BrowserLauncherView(url, content, this.time, loginFromDB, pswFromDB).Show(); } } else { string str6 = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), ResourceManager.Root, this.brand.NameAndFolder); using (Process process = new Process { StartInfo = { UseShellExecute = false, FileName = url, CreateNoWindow = true, Verb = url } }) { process.Start(); } } } catch (Exception exception) { ErrorLogHelper.AddErrorInLog("InitButtonClick", exception.Message + " | " + exception.StackTrace); MessageBox.Show(exception.Message + " | " + exception.StackTrace); new ReportWindow().ShowReportWindow(exception); } }
private static void StartSeparateProcess(string url, long providerId) { string fileNameBrowser = "BrowserExtension.exe" , fileNameSession = "Session_ChevroletOpelGroup.txt"; FileStream stream; StreamWriter writer; RequestHelper.Client.OpenSession(url, providerId, true); string cookies = RequestHelper.Client.GetCookies(url); //List<System.Net.Cookie> listCookies = JsonConvert.DeserializeObject<List<System.Net.Cookie>>(cookies); // куки передаем через командную строку if (url.Contains(ResourceManager.Urls[CatalogApi.UrlConstants.Key.ChevroletOpelGroupRoot]) == true) { using (stream = new FileStream(fileNameSession, FileMode.Create, FileAccess.Write)) { using (writer = new StreamWriter(stream)) { writer.Write(cookies); } } } // вариант №1(рабочий) using (Process process = new Process() { StartInfo = { FileName = fileNameBrowser , Arguments= string.Join(" ", new string[] { string.Format("mode={0}", "slave") , string.Format("url={0}", url) , string.Format("session={0}", fileNameSession) }) , CreateNoWindow= true , UseShellExecute= false } }) { if (process.Start() == false) { ErrorLogHelper.AddErrorInLog(string.Format("Process.Start: {0}", fileNameBrowser), "Unknown reason"); } else { ; } } //// вариант №2 (для отладки) //try { // Process process = new Process() { // StartInfo = // { // FileName = fileNameBrowser // , Arguments = string.Join(" ", new string[] {url, fileNameSession /*cookies*/}) // , CreateNoWindow = true // , UseShellExecute = false // } // }; // if (process.Start() == false) // ErrorLogHelper.AddErrorInLog("Process.Start: BrowserExtension.exe", "Unknown reason"); // else // ; //} catch (Exception e) { // ErrorLogHelper.AddErrorInLog(string.Format("Process.Start: {0}", fileNameBrowser), e.Message + " | " + e.StackTrace); // Logging.Exception(e, true); //} }
private void button_onClick(object sender, RoutedEventArgs e) { BrandProvider brandProvider = null; string url = string.Empty; try { brandProvider = (from item in this.brand.Providers where item.ProviderId == ((ButtonModel)sender).ProviderId select item).Cast <BrandProvider>()?.ElementAt(0); url = brandProvider.Uri; if (url.StartsWith("http") || url.StartsWith("https")) { if (url.Contains(ResourceManager.Urls[CatalogApi.UrlConstants.Key.ChevroletOpelGroupRoot]) == true) { string appKey = "ChevroletOpelGroupBrowser"; if (ConfigurationManager.AppSettings[appKey] == MODE_BROWSE.Separate.ToString()) { // вариант №1(отдельный броаузер) StartSeparateProcess(url, brandProvider.ProviderId); } else if (ConfigurationManager.AppSettings[appKey] == MODE_BROWSE.Common.ToString()) { // вариант №2 (как у всех остальных Brand) NewBrowserLauncherView(brandProvider); } else { ErrorLogHelper.AddErrorInLog("::button_onClick () - ...", string.Format("см. файл конфигурации key={0}", appKey)); MessageBox.Show(string.Format("Некорректные установки в файле конфигурации, key={0}", appKey)); } } else { NewBrowserLauncherView(brandProvider); } } else { url = MainWindow.GetPathBrandToProcess(url, brand.NameAndFolder); using (Process process = new Process { StartInfo = { UseShellExecute = false , FileName = url , CreateNoWindow= true , Verb = url } }) { process.Start(); } } } catch (Exception exception) { MessageBox.Show(string.Format("::button_onClick (url={1}, Commands={2}) - ...{0}Message={3}{0}StackTrace={4}" , Environment.NewLine , url, brandProvider == null ? "null" : brandProvider.Commands , exception.Message, exception.StackTrace)); ErrorLogHelper.AddErrorInLog(string.Format("::button_onClick (url={0}, Commands={1}) - ..." , url, brandProvider == null ? "null" : brandProvider.Commands) , string.Format("{0} | {1}", exception.Message, exception.StackTrace)); //new ReportWindow().ShowReportWindow(exception); } }
private void StartNewEventSession() { try { Logging(string.Format("::StartNewEventSession() - вход...")); base.Closing += delegate(object sender, System.ComponentModel.CancelEventArgs args) { if ((App.IsAssemblyRelease(Assembly.GetAssembly(this.GetType())) == false) || (this.isNormalShutdownMode == true)) { args.Cancel = false; foreach (BrowserLauncherView view in _dictBrowserLauncherView.Values) { view.Closing -= new CancelEventHandler(closingViewer <BrowserLauncherView>); view.Close(); } _dictBrowserLauncherView.Clear(); foreach (BrandLauncherView view in _dictBrandLauncherView.Values) { view.Closing -= new CancelEventHandler(closingViewer <BrandLauncherView>); view.Close(); } _dictBrandLauncherView.Clear(); MainWindow.FreeOccupiedAccount(); } else { args.Cancel = true; base.WindowState = WindowState.Minimized; base.ShowInTaskbar = true; if (this.currentBrandLauncher != null) { this.currentBrandLauncher.Visibility = Visibility.Hidden; } else { ; } } }; base.StateChanged += delegate //(object sender, System.EventArgs args) { try { if ((this.currentBrandLauncher != null) && ((this.currentBrandLauncher == null) || (this.currentBrandLauncher.Visibility == Visibility.Hidden)) ) { try { this.currentBrandLauncher.Visibility = Visibility.Visible; } catch (Exception) { } MainWindow.ShowWindow(new WindowInteropHelper(this.currentBrandLauncher).Handle, SwRestore); } } catch (System.Exception ex2) { ErrorLogHelper.AddErrorInLog("StartNewEventSession()", ex2.Message + " | " + ex2.StackTrace); MessageBox.Show(ex2.Message + " | " + ex2.StackTrace); } }; base.LocationChanged += delegate //(object sender, System.EventArgs args) { if (this.DownFlag) { this.currentBrandLauncher.Top = base.Top + base.Height; this.currentBrandLauncher.Left = base.Left + this.LeftLength; } if (this.TopFlag) { this.currentBrandLauncher.Top = base.Top - this.currentBrandLauncher.Height; this.currentBrandLauncher.Left = base.Left + this.LeftLength; } if (this.LeftFlag) { this.currentBrandLauncher.Left = base.Left - this.currentBrandLauncher.Width; this.currentBrandLauncher.Top = base.Top + this.TopLength; } if (this.RightFlag) { this.currentBrandLauncher.Left = base.Left + base.Width; this.currentBrandLauncher.Top = base.Top + this.TopLength; } }; Microsoft.Win32.SystemEvents.SessionEnding += delegate(object sender, Microsoft.Win32.SessionEndingEventArgs args) { Microsoft.Win32.SessionEndReasons arg_07_0 = args.Reason; MainWindow.FreeOccupiedAccount(); }; Logging(string.Format("::StartNewEventSession() - успех...")); } catch (System.Exception ex) { ErrorLogHelper.AddErrorInLog("StartNewEventSession()", ex.Message + " | " + ex.StackTrace); MessageBox.Show(ex.Message + " | " + ex.StackTrace); } }
private static void LoadUpdates() { string nameFileSettingVersion = string.Empty , nameFileAppVersion = string.Empty; Exception exception; try { nameFileSettingVersion = new File(ConfigurationManager.AppSettings["FileSettingVersion"]).Name; nameFileAppVersion = new File(ConfigurationManager.AppSettings["FileAppVersion"]).Name; if ((string.IsNullOrWhiteSpace(nameFileSettingVersion) == false) && (string.IsNullOrWhiteSpace(nameFileAppVersion) == false)) { using (AvtoritetEntities entities = new AvtoritetEntities()) { //if (!(entities.Database.Connection.State == ConnectionState.Closed)) //{ Version version = new Version(entities.VersionLog.FirstOrDefault().Value) , version2 = new Version(JsonConvert.DeserializeObject <VersionEntity>(FileHelper.OpenFile(nameFileAppVersion)).Version) , version3 = new Version(FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion); if (version > version2) { try { } catch (Exception exception1) { exception = exception1; ErrorLogHelper.AddErrorInLog("LoadUpdates()", string.Format("{0} | {1}", exception.Message, exception.StackTrace)); } } else { ; } if (!System.IO.File.Exists(nameFileSettingVersion)) { System.IO.File.WriteAllText(nameFileSettingVersion, "1"); } else { ; } int?settingVersion = entities.SettingUpdate.FirstOrDefault().SettingVersion; int?nullable2 = settingVersion; int num = int.Parse(System.IO.File.ReadAllText(nameFileSettingVersion)); int num2 = num; if ((nullable2.GetValueOrDefault() > num2) && (nullable2.HasValue == true)) { launcherSettings = new SettingsFactory(categoryEventHandler).DownloadSettings(true, true); System.IO.File.WriteAllText(nameFileSettingVersion, settingVersion.ToString()); HaveNewUpdate = true; } else { ; } //} //else //ErrorLogHelper.AddErrorInLog("Обновление приложения - LoadUpdates() - ...", string.Format("Состояние БД={0}", entities.Database.Connection.State.ToString())); } } else { ErrorLogHelper.AddErrorInLog("Обновление приложения - LoadUpdates() - ...", string.Format("Неизвестна версия приложения или версия конфигурация БД")); } ; } catch (Exception exception2) { exception = exception2; ErrorLogHelper.AddErrorInLog("Обновление приложения - LoadUpdates()", string.Format("{0} | {1}", exception.Message, exception.StackTrace)); MessageBox.Show(string.Format("{0}{1}{2}", Environment.NewLine, exception.Message, exception.StackTrace)); } }
private void button_onClick(Brand brandown) { LoadUpdates(); //minimizeMemory(); if (HaveNewUpdate) { this.BuildWindow(); HaveNewUpdate = false; } string url = ""; try { if (brandown != null) { if (brandown.MenuWindow) { if (_dictBrandLauncherView.ContainsKey(brandown.BrandId) == false) { EventNewBrandLauncherView?.Invoke(this.time, brandown); } else { _dictBrandLauncherView[brandown.BrandId].Activate(); } } else if (brandown.Providers.Count > 0) { url = brandown.Providers[0].Uri; if (IsUrlAsHttp(url) == true) { showBrowserLauncherView(this.time, brandown.Providers[0]); } else { url = GetPathBrandToProcess(url, brandown.NameAndFolder); using (Process process = new Process { StartInfo = { UseShellExecute = false , FileName = url , CreateNoWindow= true , Verb = url } }) { process.Start(); } } } } } catch (Exception e) { ErrorLogHelper.AddErrorInLog(string.Format("button_onClick (brand.Id={0}, provider.Id={1}, url={2}", brandown.BrandId, brandown.Providers[0].ProviderId, url) , string.Format("{0} | {1}", e.Message, e.StackTrace)); MessageBox.Show(string.Format("{0} | {1}", e.Message, e.StackTrace)); } //Func<CatalogApi.Settings.Brand, bool> predicate = null; ////LoadUpdates(); //minimizeMemory(); //if (HaveNewUpdate) //{ // this.BuildWindow(); // HaveNewUpdate = false; //} //Button d = (Button)sender; //int brandId = ButtonBehavior.GetBrandId(d); //if (this.brandLauncher != null) //{ // this.brandLauncher.Close(); //} //foreach (GroupSet set in launcherSettings.Groups) //{ // foreach (CatalogApi.Settings.GroupBox box in set.GroupBoxs) // { // string url = ""; // try // { // if (predicate == null) // { // predicate = t => t.BrandId == brandId; // } // CatalogApi.Settings.Brand brand = box.Brands.FirstOrDefault<CatalogApi.Settings.Brand>(predicate); // if (brand != null) // { // if (brand.MenuWindow) // { // BrandLauncherView view = new BrandLauncherView(this.time) // { // Top = Application.Current.MainWindow.Top, // Left = Application.Current.MainWindow.Left + base.Width, // Height = Application.Current.MainWindow.Height, // DataContext = brand, // Title = brand.NameAndFolder, // ShowActivated = false, // Owner = this // }; // this.brandLauncher = view; // this.brandLauncher.Show(); // } // else if (brand.Providers.Count > 0) // { // string loginFromDB = SettingsFactory.GetLoginFromDB(brand.Providers[0].ProviderId); // string pswFromDB = SettingsFactory.GetPswFromDB(brand.Providers[0].ProviderId); // string title = brand.Providers[0].Title; // url = brand.Providers[0].Uri; // if (url.StartsWith("http") || url.StartsWith("https")) // { // new BrowserLauncherView(url, title, this.time, loginFromDB, pswFromDB).Show(); // } // else // { // url = (url.StartsWith("http") || url.StartsWith("https")) ? url : Path.Combine(ResourceManager.Root, brand.NameAndFolder, url); // string str6 = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), ResourceManager.Root, brand.NameAndFolder); // using (Process process = new Process { StartInfo = { UseShellExecute = false, FileName = url, CreateNoWindow = true, Verb = url } }) // { // process.Start(); // } // } // } // } // } // catch (Exception exception) // { // ErrorLogHelper.AddErrorInLog("Button_Click", url + " | " + exception.Message + " | " + exception.StackTrace); // MessageBox.Show(exception.Message + url + " | " + exception.StackTrace); // } // } //} }