public static int GetNumberOfTypeResources(resourseTypes type, string sourceCode) { int counter = 0; string mask = ""; mask = GetMatchMaskValue(type); Regex regex = new Regex(mask); // ok MatchCollection matches = regex.Matches(sourceCode); if (matches.Count > 0) { foreach (Match match in matches) { counter++; } } return counter; }
/* * * * Считает количество объектов в dataSource по типу * */ int ReturnNumberOfObjects(resourseTypes type, string dataSource) { int counter = 0; string mask = ""; mask = ResourceSAMP.GetMatchMaskValue(type); Regex regex = new Regex(mask); // ok MatchCollection matches = regex.Matches(dataSource); if (matches.Count > 0) { foreach (Match match in matches) { counter++; } } return counter; }
public ResourceTypeValue(resourseTypes resvalue) { _resvalue = resvalue; }
// collectors private /*KeyValuePair<List<ResourceSAMP>, int>*/List<ResourceSAMP> CollectAllTypeResourcesFromCode(resourseTypes type, string sourceCode) { List<ResourceSAMP> Storage = new List<ResourceSAMP>(); Regex regex; MatchCollection matches; regex = new Regex(ResourceTools.GetMatchMaskValue(type)); // set up regex pattern as is a mask of this type matches = regex.Matches(sourceCode); // get all type mathces if (matches.Count > 0) // matches of this type exists { foreach (Match match in matches) // foreaching matches with this type { ResourceSAMP newRes = null; try { // eject args from matched string string novaStr = match.Value.Replace(")", ""); for (int additionalSize = 0; additionalSize < ResourceTools.MAX_ADDITIONAL_SIZE; additionalSize++) { novaStr += ", #"; // provide tryParse in MakeObject } // string[] args = novaStr.Split(new char[] { ',' }, StringSplitOptions.None); switch (type) { case resourseTypes.AddStaticVehicle: { newRes = new AddedStaticVehicle(args); break; } case resourseTypes.AddStaticVehicleEx: { newRes = new AddedStaticVehicleEx(args); break; } case resourseTypes.CreateDynamicObject: { newRes = new CreatedDynamicObject(args); break; } case resourseTypes.CreateObject: { newRes = new CreatedObject(args); break; } case resourseTypes.CreateVehicle: { newRes = new CreatedVehicle(args); break; } case resourseTypes.RemoveBuildingForPlayer: { newRes = new RemovedBuildingForPlayer(args); break; } } Storage.Add(newRes); } catch (Exception e) // cannot build object from an iterated match { consoleHandler.WriteLine(String.Format(FindResource("i_MapLoader_cannotReadLine").ToString(), type.ToString(), match.Value, e.ToString())); //newRes = null; break; } } } /* return new KeyValuePair<List<ResourceSAMP>, int> ( Storage, Storage.Count ); * */ return Storage; }
public void E_OnMapTypeResourcesNumberUpdatingCancelled(int mapId, resourseTypes type, bool isSuccess, string excComment = null) // mapProcessor { if (isSuccess) consoleHandler.WriteLine(String.Format(FindResource("i_MapController_mapResourcesCountsUpdated").ToString(), type.ToString(), mapId)); else { consoleHandler.WriteLine(String.Format(FindResource("i_MapController_mapResourcesCountsNotUpdated").ToString(), type.ToString(), mapId)); if(excComment != null) { consoleHandler.Write(String.Format(FindResource("c_General_reason").ToString(), excComment)); } } }
// update map type' resources number in mysql private bool updateMapResourcesNumberInMySQL(int mapId, resourseTypes type, int newValue, bool openConnection, bool startTransaction) { try { if (openConnection) { sqlClient.getConn().Open(); } MySqlCommand cmd; if (startTransaction) { cmd = new MySqlCommand("START TRANSACTION", sqlClient.getConn()); cmd.ExecuteNonQuery(); } cmd = new MySqlCommand(String.Format(@" UPDATE `ssmm_maps` SET `Map{0}Count` = '{1}' WHERE `MapID` = {2}", type.ToString(), newValue, mapId ), sqlClient.getConn()); cmd.ExecuteNonQuery(); MAP thisMap = getMapById(mapId); thisMap.resourcesCount[type] = newValue; if (startTransaction) { cmd = new MySqlCommand("COMMIT", sqlClient.getConn()); cmd.ExecuteNonQuery(); } if (openConnection) { sqlClient.getConn().Close(); } appHandler.E_OnMapTypeResourcesNumberUpdatingCancelled(mapId, type, true); } catch(Exception e) { appHandler.E_OnMapTypeResourcesNumberUpdatingCancelled(mapId, type, false, e.ToString()); } return true; }
// send resources of this type to mysql private bool sendTypeResourcesToMySQL(resourseTypes type, List<ResourceSAMP> resources, int mapId) { int currentPackId = 0; MySqlCommand cmd; string QUERY_STRING = ""; int i = 0; int max = resources.Count; foreach (ResourceSAMP res in resources) { if (currentPackId == 0) QUERY_STRING = res.getInsertString(); QUERY_STRING += res.getValueString(mapId); try { if (currentPackId >= ResourceTools.MAX_PACK_SIZE) // time to load { cmd = new MySqlCommand(QUERY_STRING, sqlClient.getConn()); cmd.ExecuteNonQuery(); //Console.WriteLine("Больше паксайц"); // reset currentPackId = 0; } else if (i == max - 1) // latest element. Finish loading { //Console.WriteLine("Последний элемент"); cmd = new MySqlCommand(QUERY_STRING, sqlClient.getConn()); cmd.ExecuteNonQuery(); } else { //Console.WriteLine("Пакуем"); QUERY_STRING += ","; currentPackId++; } } catch (Exception e) { appHandler.E_OnMapResourceSendingCancelled(mapId, type, false, e.ToString()); return false; } i++; } appHandler.E_OnMapResourceSendingCancelled(mapId, type, true); return true; }