private List <SolutionModel> PrepareSolutions() { var solutions = new List <SolutionModel>(); List <List <SolutionModel> > solutionsCombination = new List <List <SolutionModel> >(); foreach (var demand in _networkModel.Demands) { solutionsCombination.Add(PrepareOneDemandPathCombinations(demand)); } List <List <int> > indexesCombinations = new List <List <int> >(); foreach (var solutionCombination in solutionsCombination) { indexesCombinations.Add(AdditionalFunctions.FillListWithIndexes(solutionCombination.Count)); } List <List <int> > indexesCombinationsCartesianResult = new List <List <int> >(); indexesCombinationsCartesianResult = AdditionalFunctions.GetPermutations(indexesCombinations); foreach (var indexesCombination in indexesCombinationsCartesianResult) { solutions.Add(PrepareSolution(solutionsCombination, indexesCombination)); } return(solutions); }
public Watch(MovementType type, Brands brand, Colours colour, AdditionalFunctions additionalFunction, double price) { TypeM = type; Brand = brand; Colour = colour; AdditionalFunction = additionalFunction; Price = price; }
public List <SolutionModel> PrepareSolutionsWithLinkCapacities() { List <SolutionModel> solutions = PrepareSolutions(); foreach (var solution in solutions) { solution.LinkCapacities = AdditionalFunctions.CalculateLinksCapacities(_networkModel, solution); } return(solutions); }
/// <summary> /// The create automatically. /// </summary> /// <returns> /// The <see cref="bool"/>. /// </returns> public static bool IsProjectCreated() { Log.Enter(typeof(Project), MethodBase.GetCurrentMethod().Name); bool result = ProgramFunctions.IsMenuAvailable(); result &= DtmFunctions.IsMenuAvailable(); result &= AdditionalFunctions.IsMenuAvailable(); result &= DeviceReport.IsMenuAvailable(); System.Threading.Thread.Sleep(10000); return(result); }
private void addMarker(GMapMarker marker, string toolTip) { GMapOverlay markersOverlay_i = new GMapOverlay("markersLayer"); markersOverlay = markersOverlay_i; if (!AdditionalFunctions.isEmpty(toolTip)) { marker.ToolTipMode = MarkerTooltipMode.OnMouseOver; marker.ToolTipText = toolTip; } markersOverlay_i.Markers.Add(marker); map.Overlays.Add(markersOverlay); // Adding markers overlay to the map }
private List <List <int> > PrepareCombinations(int demandVolume, int numberOfPaths) { List <List <int> > combinations = new List <List <int> >(); List <int> singleCombination = new List <int>(); for (int i = 0; i <= demandVolume; i++) { singleCombination.Add(i); } for (int i = 0; i < numberOfPaths; i++) { combinations.Add(singleCombination); } return(AdditionalFunctions.GetPermutations(combinations).Where(x => x.Sum() == demandVolume).ToList()); }
private List <SolutionModel> PrepareOneDemandPathCombinations(DemandModel demand) { var oneDemandPathCombinations = new List <SolutionModel>(); var combinationsNumber = AdditionalFunctions.GetBinaryCoefficient(demand.NumberOfPaths + demand.DemandVolume - 1, demand.DemandVolume); List <List <int> > combinations = PrepareCombinations(demand.DemandVolume, demand.NumberOfPaths); for (int i = 0; i < combinationsNumber; i++) { var xes = new Dictionary <PModel, int>(); foreach (var path in demand.Paths) { xes.Add(new PModel(demand.DemandId, path.PathId), combinations.ElementAt(i).ElementAt(path.PathId - 1)); } oneDemandPathCombinations.Add(new SolutionModel(xes)); } return(oneDemandPathCombinations); }
public IActionResult Comparing(string[] array) { CleanNotUsedData(4); if (array.Length == 0) { return(PartialView("_Error")); } db.FirstDatabase.SelectedColumns.Clear(); db.SecondDatabase.SelectedColumns.Clear(); var min = Math.Min(db.FirstDatabase.TableColumns.Count, db.SecondDatabase.TableColumns.Count); for (var i = 0; i < min; i++) { db.FirstDatabase.SelectedColumns.Add(db.FirstDatabase.TableColumns[i]); foreach (var column in db.SecondDatabase.TableColumns) { if (column.Name == array[i] && AdditionalFunctions.IsTypesComparable(column.Type, db.FirstDatabase.TableColumns[i].Type)) { db.SecondDatabase.SelectedColumns.Add(column); break; } } } if (db.FirstDatabase.SelectedColumns.Count != db.SecondDatabase.SelectedColumns.Count) { return(PartialView("_Error")); } if (db.ReadDataFromDb()) { db.ComparingResult = db.CompareFullData(); } else { return(PartialView("_Error")); } return(PartialView("_Comparing", db)); }
private void signInBtn_Click(object sender, EventArgs e) { // Check with the Database the username and the password and move to the HomePage || AdminPage Employee resEmp = new DatabaseConnector().logInEmp(usernameText, AdditionalFunctions.MD5(AdditionalFunctions.MD5(passwordText))); if (resEmp != null) { if (resEmp.role == ConstVars.Roles.ADMIN) { // WinForms navigation needs to be like this AdminPage adminPage = new AdminPage(resEmp); adminPage.TopLevel = false; Controls.Clear(); Controls.Add(adminPage); adminPage.Show(); } else { MapPage mPage = new MapPage(resEmp); mPage.Show(); Hide(); } } }
/// <summary> /// The run. /// </summary> /// <param name="functionName"> /// The function name. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public bool Run(string functionName) { Logging.Enter(this, MethodBase.GetCurrentMethod().Name); return(AdditionalFunctions.OpenAdditionalFunction(functionName)); }
public override bool ConnectToFile(string location = null) { try { port = AdditionalFunctions.GetAvailablePort(3306); var DestinationPath = Path.GetDirectoryName(location) + $"\\data{port}\\"; LocalInstance = Directory.GetParent(DestinationPath).Parent.Parent.Parent.FullName + "\\MySQLInstance\\data\\"; //Now Create all of the directories foreach (string dirPath in Directory.GetDirectories(LocalInstance, "*", SearchOption.AllDirectories)) { Directory.CreateDirectory(dirPath.Replace(LocalInstance, DestinationPath)); } //Copy all the files & Replaces any files with the same name foreach (string newPath in Directory.GetFiles(LocalInstance, "*.*", SearchOption.AllDirectories)) { File.Copy(newPath, newPath.Replace(LocalInstance, DestinationPath), true); } string fileName = Directory.GetParent(LocalInstance).Parent.FullName + "\\my.ini"; var file = File.ReadAllText(fileName); file = file.Replace("MY_PORT", port.ToString()); file = file.Replace("MY_LOCATION", DestinationPath.Replace("\\", "/")); File.WriteAllText(DestinationPath + @"\my.ini", file); Process.Start(new ProcessStartInfo { FileName = Directory.GetParent(LocalInstance).Parent.FullName + @"\bin\mysqld.exe", Arguments = $"--install MySQL{port} --defaults-file=" + '"' + DestinationPath.Replace(@"\", "/") + "my.ini" + '"', Verb = "runas", UseShellExecute = true, WindowStyle = ProcessWindowStyle.Hidden }).WaitForExit(); Process.Start(new ProcessStartInfo { FileName = "net.exe", Arguments = $"start MYSQL{port}", Verb = "runas", UseShellExecute = true, WindowStyle = ProcessWindowStyle.Hidden }).WaitForExit(); if (ConnectToServer(port)) { var DbList = GetDatabasesList(); MySqlScript script = new MySqlScript((connection as MySqlConnection), File.ReadAllText(location)); script.Delimiter = ";"; Stopwatch sw = new Stopwatch(); sw.Start(); script.Execute(); sw.Stop(); var NewDbName = GetDatabasesList().Except(DbList).First(); ConnectToDatabase(NewDbName, port); SelectedDatabase = NewDbName; ConType = Connection_Type.File; return(true); } throw new Exception(); } catch (Exception e) { return(false); } }
private void createCarBtn_Click(object sender, EventArgs e) { if (createCarBtn.Text == "Update" && carId != null) { if ( !AdditionalFunctions.isEmpty(code) && !AdditionalFunctions.isEmpty(model) && !AdditionalFunctions.isEmpty(creationDate) && !AdditionalFunctions.isEmpty(driverId) && isChanged ) { try { bool res = db.updateCar( new Car( AdditionalFunctions.trimFlWhitespaces(code), AdditionalFunctions.trimFlWhitespaces(model), new SqlDate(AdditionalFunctions.trimFlWhitespaces(creationDate)), AdditionalFunctions.trimFlWhitespaces(driverId) ), carId); if (res) { Close(); parent.refreshTable(TabChooser.Cars); } else { MessageBox.Show("Error occord with Car's update, Please try again later."); Close(); } } catch (Exception ex) { MessageBox.Show("Error occord with Car's update, Please try again later."); Close(); } } else { if (!isChanged) { MessageBox.Show("No data has changed, If you want to close please click the X button on the top"); } else { MessageBox.Show("One of the fields are not filled, Please fill and try again."); } } } else { if ( !AdditionalFunctions.isEmpty(code) && !AdditionalFunctions.isEmpty(model) && !AdditionalFunctions.isEmpty(creationDate) && !AdditionalFunctions.isEmpty(driverId) ) { bool res = db.addNewCar(new Car( AdditionalFunctions.trimFlWhitespaces(code), AdditionalFunctions.trimFlWhitespaces(model), new SqlDate(AdditionalFunctions.trimFlWhitespaces(creationDate)), AdditionalFunctions.trimFlWhitespaces(driverId) )); if (res) { Close(); parent.refreshTable(TabChooser.Cars); } else { MessageBox.Show("Error occord with Car's creation, Please try again later."); Close(); } } else { MessageBox.Show("One of the fields are not filled, Please fill and try again."); } } }
private void submitButton_Click(object sender, EventArgs e) { if ( !AdditionalFunctions.isEmpty(id) && !AdditionalFunctions.isEmpty(name) && !AdditionalFunctions.isEmpty(birth_date) && !AdditionalFunctions.isEmpty(role) && !AdditionalFunctions.isEmpty(username) && !AdditionalFunctions.isEmpty(password) && !AdditionalFunctions.isEmpty(secPassword) && !AdditionalFunctions.isEmpty(phoneNumber) && !AdditionalFunctions.isEmpty(gender) && !AdditionalFunctions.isEmpty(street) && !AdditionalFunctions.isEmpty(house_num) && !AdditionalFunctions.isEmpty(city) && !AdditionalFunctions.isEmpty(zip_code) && isChanged ) { if (password == secPassword) { if (submitButton.Text == "Update") { try { bool res = db.updateEmployee( new Employee( id, name, new SqlDate(birth_date), role, username, password, phoneNumber, new Address( street, int.Parse(house_num), city, zip_code, 0.0, 0.0 ) ), address, addressID ); if (res) { Close(); parent.refreshTable(TabChooser.Employees); } else { MessageBox.Show($"Error occord with { name }'s update, Please try again later."); Close(); } } catch (Exception ex) { MessageBox.Show($"Error occord with { name }'s update, Please try again later."); Close(); } } else { db.addNewEmploeey( new Employee( id, name, new SqlDate(birth_date), role, username, AdditionalFunctions.MD5(AdditionalFunctions.MD5(password)), phoneNumber, gender, address ) ); } } } else { if (!isChanged) { MessageBox.Show("No data has changed, If you want to close please click the X button on the top"); } else { MessageBox.Show("One of the fields are not filled, Please fill and try again."); } if (AdditionalFunctions.isEmpty(id)) { idTextBox.BackColor = Color.Red; } } }
private void addNewATMButton_Click(object sender, EventArgs e) { if ( atmSize != (int)AtmSize.NONE && capacity > 0 && !AdditionalFunctions.isEmpty(brand) && !AdditionalFunctions.isEmpty(street) && !AdditionalFunctions.isEmpty(houseNumber) && !AdditionalFunctions.isEmpty(zipCode) && !AdditionalFunctions.isEmpty(city) && !AdditionalFunctions.isEmpty(lat) && !AdditionalFunctions.isEmpty(lng) && isChanged ) { // Add new changes into the database Address addr = new Address( AdditionalFunctions.trimFlWhitespaces(street), int.Parse(AdditionalFunctions.trimFlWhitespaces(houseNumber)), AdditionalFunctions.trimFlWhitespaces(city), AdditionalFunctions.trimFlWhitespaces(zipCode), AdditionalFunctions.isEmpty(AdditionalFunctions.trimFlWhitespaces(lat)) ? 0.0 : double.Parse(lat), AdditionalFunctions.isEmpty(AdditionalFunctions.trimFlWhitespaces(lng)) ? 0.0 : double.Parse(lng) ); if (addNewATMButton.Text == "Update") { try { bool res = db.updateATM( new ATM( addr, capacity, (int)atmSize, brand ), db.getAddressByID(baseAddressId), atmId, baseAddressId ); MessageBox.Show($"ATM number {atmId} updated successfuly"); Close(); } catch (Exception ex) { Console.WriteLine(ex); MessageBox.Show("Error occord with ATM's update, Please try again later."); Close(); } } else { bool res = db.addNewATM( new ATM( addr, capacity, (int)atmSize, AdditionalFunctions.trimFlWhitespaces(brand) ) ); } } else { if (!isChanged) { MessageBox.Show("No data has changed, If you want to close please click the X button on the top"); } else { MessageBox.Show("One of the fields are not filled, Please fill and try again."); } } }
bool AddUserToActiveConnections(ref networkServer.networkClientInterface ClientInterface, string ApplicationHash, string ComputerID, string architecture, String language, double version) { if (!CCstData.InstanceExists(ApplicationHash)) { //Instance does not exist. The player must have manipulated the protocol! CCstData.GetInstance(ApplicationID).Logger.writeInLog(1, LogCategory.CRITICAL, Support.LoggerType.SERVER, String.Format("Invalid application hash received in authentification protocol! ComputerID: {0}, ApplicationHash: {1}", ComputerID, ApplicationHash)); return(false); } if (CCstData.GetInstance(ApplicationHash).LatestClientVersion != version) { CCstData.GetInstance(ApplicationID).Logger.writeInLog(3, LogCategory.ERROR, Support.LoggerType.CLIENT, String.Format("Invalid version! Having {0}, expected {1}. Hardware ID {2}", version, CCstData.GetInstance(ApplicationHash).LatestClientVersion, ComputerID)); SendProtocol("201;35;Antihack Client version outdated!", ClientInterface); return(false); } ////Check if user is already connected //foreach (networkServer.networkClientInterface item in ActiveConnections) //{ // if(item.User.ID==ComputerID // && item.User.Application.Hash==ApplicationHash) // { // //User is already registered // CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.OK, Support.LoggerType.CLIENT, "Authentification: User is already added to list!"); // SendProtocol("201;2;Still logged in. Please try again", ClientInterface); // return false; // } //} CCstData.GetInstance(ApplicationID).Logger.writeInLog(4, LogCategory.OK, Support.LoggerType.DATABASE, "Authentification: Checking user in the database"); EPlayer dataClient = SPlayer.Authenticate(ComputerID, ApplicationHash, architecture, language, ClientInterface.IP.ToString()); CCstData.GetInstance(ApplicationID).Logger.writeInLog(4, LogCategory.OK, Support.LoggerType.DATABASE, "Authentification: User found!"); if (dataClient == null) { //If a computer ID exists multiple times in the database, a null object is returned CCstData.GetInstance(ApplicationID).Logger.writeInLog(1, LogCategory.CRITICAL, Support.LoggerType.DATABASE, "Authentification: Hardware ID exists multiple times in the database"); SendProtocol("201;3;Contact Admin", ClientInterface); return(false); } dataClient.Application.Hash = ApplicationHash; //Check if user is banned if (dataClient.isBanned == true) { //Do something and dont let him enter CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.OK, Support.LoggerType.SERVER, String.Format("Authentification: Banned user tried to authentificate. User: {0}", dataClient.ID)); //Send protocol to client that user is banned SendProtocol("201;4;Too many hacks", ClientInterface); return(false); } //Add EPlayer to ClientInterface and to the list ClientInterface.User = dataClient; //Generate unique Session ID for network communication CCstData.GetInstance(ApplicationID).Logger.writeInLog(3, LogCategory.OK, Support.LoggerType.SERVER, "Authentification: Start creating a unique session ID"); while (true) { string SessionID = AdditionalFunctions.GenerateSessionID(CCstData.GetInstance(ApplicationHash).SessionIDLength); //Checks if that connection exists already. Gives back the amount of matching ClientInterfaces if (ActiveConnections.Where(Client => Client.SessionID == SessionID).ToList().Count == 0) { ClientInterface.SessionID = SessionID; CCstData.GetInstance(ApplicationID).Logger.writeInLog(3, LogCategory.OK, Support.LoggerType.SERVER, String.Format("New user authentificated! HardwareID: {0}, Session ID: {1}", dataClient.ID, SessionID)); break; } } //Add the new connection to the list of connected connections ClientInterface.SetPingTimer(CCstData.GetInstance(dataClient.Application.ID).PingTimer, KickUser); bool IpExistsAlready = false; foreach (var Client in ActiveConnections) { if (Client.IP == ClientInterface.IP) { IpExistsAlready = true; } } //Linux takes ages to connect. Therefore contact the client before it sends another request if (!IpExistsAlready) { if (!CCstData.GetInstance(ApplicationID).GameDLL.AllowUser(ClientInterface.IP, ClientInterface.User.ID)) { //Do something and dont let him enter CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.ERROR, Support.LoggerType.GAMEDLL, String.Format("Linux exception failed. User: {0}", dataClient.ID)); //Send protocol to client that user is banned SendProtocol("201;30;Access verification failed", ClientInterface); return(false); } } else { CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.OK, Support.LoggerType.SERVER, String.Format("Authentication: IP already exists ({0})", ClientInterface.IP.ToString())); } ActiveConnections.Add(ClientInterface); SendProtocol("200;" + ClientInterface.SessionID, ClientInterface); CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.OK, Support.LoggerType.SERVER, String.Format("Authenticated new user. Computer ID: {0}, Session ID: {1}", ClientInterface.User.ID, ClientInterface.SessionID)); /*if (!IpExistsAlready) * { * //If there is already an IP exception, we dont need another * try * { * ClientInterface.unixSshConnectorAccept.Connect(); * } * catch (Exception) * { * * } * if (ClientInterface.unixSshConnectorAccept.IsConnected) * { * List<int> Ports = new List<int>(); * Ports.Add(50001); * Ports.Add(50002); * Ports.Add(50003); * Ports.Add(50004); * Ports.Add(50005); * Ports.Add(50006); * Ports.Add(50007); * Ports.Add(50008); * Ports.Add(50009); * Ports.Add(50010); * Ports.Add(50011); * Ports.Add(50012); * Ports.Add(50013); * Ports.Add(50014); * Ports.Add(50015); * Ports.Add(50016); * Ports.Add(50017); * Ports.Add(50018); * Ports.Add(50019); * Ports.Add(50020); * string LinuxPorts = ""; * foreach (int item in Ports) * { * LinuxPorts += "iptables -I INPUT -p tcp -s " + ClientInterface.IP + " --dport " + item + " -j ACCEPT && "; * } * if(LinuxPorts.Length > 0) * { * LinuxPorts = LinuxPorts.TrimEnd(' '); * LinuxPorts = LinuxPorts.TrimEnd('&'); * using (SshCommand Result = ClientInterface.unixSshConnectorAccept.RunCommand(LinuxPorts)) * { * if (Result.Error.Length > 0) * CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.ERROR, Support.LoggerType.GAMEDLL, "Linux exception failed! Session ID: " + ClientInterface.SessionID + ", Error: " + Result.Error); * else * CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.OK, Support.LoggerType.GAMEDLL, "Linux exception successful. Session ID: " + ClientInterface.SessionID + ", Result: " + Result.Result); * } * } * * ClientInterface.unixSshConnectorAccept.Disconnect(); * } * else * { * //Fehlerinfo * CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.ERROR, Support.LoggerType.CLIENT, "Client could not be connected to the Linux Server. Session ID: " + ClientInterface.SessionID); * return false; * } * } * else * { * string AllIPs = ""; * foreach (var item in ActiveConnections) * { * AllIPs += String.Format(" User: {0}, IP: {1} -", item.User.ID, item.IP); * } * CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.OK, Support.LoggerType.SERVER, String.Format("Authentication: IP already exists ({0})", AllIPs)); * }*/ return(true); }