public void tearDown() { MsSql msSql = new MsSql(); TestResults testResults = new TestResults(); DateTime nowTime = new DateTime(); nowTime = DateTime.Now; string nowTimeStr = nowTime.ToLongDateString(); testResults.TestName = "Test " + nowTimeStr; testResults.TestRunnigTime = nowTimeStr; if (TestContext.CurrentContext.Result.Outcome.Status.Equals(TestStatus.Failed)) { testResults.TestResult = "Failed"; testResults.TestErrorMessage = TestContext.CurrentContext.Result.Message; } else { testResults.TestResult = "Passed"; testResults.TestErrorMessage = "Test Passed"; } msSql.Add(testResults); msSql.CloseAllConnections(); }
/// <summary> /// <para>Top saling test</para> /// </summary> public void TopSalling() { ChromeOptions options = new ChromeOptions(); options.PageLoadStrategy = PageLoadStrategy.None; using (ChromeDriver dr = new ChromeDriver(Directory.GetCurrentDirectory(), options)) { SuperPage.phones = new Phone[144]; HelpClass helper = new HelpClass(); var mainPage = new MainPage(dr); mainPage.GoToMainPage(); try { mainPage.CloseAdvertasing(); } catch { } var searchPage1 = mainPage.GoToTheSearchPhones(); searchPage1.FindAndWriteTopPhones(); var searchPage2 = searchPage1.GoToSecondPage(); searchPage2.FindAndWriteTopPhones(); var searchPage3 = searchPage2.GoToThirdPage(); searchPage3.FindAndWriteTopPhones(); AliGoods[] aliGoods = new AliGoods[SuperPage.countPhone]; helper.ConverterStructGoodsToClass(aliGoods); aliGoods.Clone(); MsSql msSql = new MsSql(); msSql.ClearTable("aligoods"); msSql.AddRange(aliGoods); ArrayList getsFromDataBase = new ArrayList(); getsFromDataBase = msSql.GetAll("aliGoods"); int countphone = 0; foreach (AliGoods element in getsFromDataBase) { Assert.IsTrue(element.EqualsGoods(aliGoods[countphone++])); } msSql.CloseAllConnections(); } }
private static void ShareSecurity(string ServerName) { // MSSQL VERBINDUNG var mssql = new MsSql(); ConnectionOptions myConnectionOptions = new ConnectionOptions(); myConnectionOptions.Impersonation = ImpersonationLevel.Impersonate; myConnectionOptions.Authentication = AuthenticationLevel.Packet; ManagementScope myManagementScope = new ManagementScope(@"\\" + ServerName + @"\root\cimv2", myConnectionOptions); myManagementScope.Connect(); if (!myManagementScope.IsConnected) { Console.WriteLine("could not connect"); } else { ManagementObjectSearcher myObjectSearcher = new ManagementObjectSearcher(myManagementScope.Path.ToString(), "SELECT * FROM Win32_LogicalShareSecuritySetting"); var shareList = myObjectSearcher.Get(); foreach (ManagementObject share in shareList) { Console.WriteLine("--------------------------------"); Console.WriteLine(share["Name"] as string); InvokeMethodOptions options = new InvokeMethodOptions(); ManagementBaseObject outParamsMthd = share.InvokeMethod("GetSecurityDescriptor", null, options); ManagementBaseObject descriptor = outParamsMthd["Descriptor"] as ManagementBaseObject; ManagementBaseObject[] dacl = descriptor["DACL"] as ManagementBaseObject[]; #region Holt die PathID der Freigabe string sql = "SELECT _path_id FROM fs.shares WHERE _unc_path_name = '\\\\" + ServerName + "\\" + share["Name"] + "'"; SqlCommand cmd = new SqlCommand(sql, mssql.Con); // Öffnet die SQL Verbindung, führt die Abfrage durch und schließt die Verbindung wieder mssql.Open(); var _path_id = cmd.ExecuteScalar(); #endregion foreach (ManagementBaseObject ace in dacl) { try { ManagementBaseObject trustee = ace["Trustee"] as ManagementBaseObject; Console.WriteLine( trustee["Domain"] as string + @"\" + trustee["Name"] as string + " (" + trustee["SIDString"] + ") : " + ace["AccessMask"] as string + " " + ace["AceType"] as string + " -- " + ace["AceFlags"] ); // Der SQL Befehl zum INSERT in die Datenbank sql = $"INSERT INTO fs.share_aces (_sid, _rights, _type, _flags, _path_id) " + $"OUTPUT INSERTED._ace_id " + $"VALUES (@Sid, @Rights, @Type, @Flags, @PathId) "; cmd = new SqlCommand(sql, mssql.Con); // Hängt die Parameter an cmd.Parameters.AddWithValue("@Sid", trustee["SIDString"] as string); cmd.Parameters.AddWithValue("@Rights", Convert.ToInt32(ace["AccessMask"])); cmd.Parameters.AddWithValue("@Type", Convert.ToInt32(ace["AceType"])); cmd.Parameters.AddWithValue("@Flags", Convert.ToInt32(ace["AceFlags"])); cmd.Parameters.AddWithValue("@PathId", (int)_path_id); // Öffnet die SQL Verbindung //mssql.Open(); // Führt die Query aus var ace_id = (int)cmd.ExecuteScalar(); //Schließt die Verbindung //mssql.Close(); } catch (Exception error) { Console.WriteLine("Error: " + error.ToString()); } } mssql.Close(); } } }