public PowerActivator() { if (mResources == null) mResources = (ManagerResources)GameObject.FindObjectOfType(typeof(ManagerResources)); Goals = new Dictionary<ResourcesID, float> (); }
//-------------------------------------------// protected override bool OpenConnection() { switch (FileMode) { case FileMode.OpenOrCreate: case FileMode.CreateNew: case FileMode.Create: try { _fileStream = new FileStream(Path, FileMode, FileAccess, FileShare, BufferSize); } catch (Exception ex) { Log.Warning(this + " FileStream could not be created. " + ex.Messages()); State = ConnectionState.Broken; } break; case FileMode.Open: case FileMode.Append: case FileMode.Truncate: try { // ensure the path exists ManagerResources.CreateFilePath(Path); // get the file stream _fileStream = new FileStream(Path, FileMode, FileAccess, FileShare, BufferSize); } catch (Exception ex) { Log.Warning(this + " FileStream could not be created. " + ex.Messages()); State = ConnectionState.Broken; } break; } return(!State.Is(ConnectionState.Broken)); }
/// <summary> /// End the processing of web pages. /// </summary> public void Stop() { _lock.Take(); // if not running - skip if (!Running) { _lock.Release(); return; } // no longer running Running = false; _updater.Run = false; // stop and dispose of all Crawlers foreach (Crawler crawler in Crawlers) { crawler.Dispose(); } // dispose of the collection Crawlers.Dispose(); _lock.Release(); // load the configuration ManagerResources.LoadConfig(Path, new Act <Configuration>(OnConfigSave)); }
//----------------------------------// /// <summary> /// Start a web site and server with the specified path as the root directory. /// </summary> public HttpSite(string path) { if (string.IsNullOrEmpty(path)) { Log.Warning("No path specified for site. A path should be set."); } // persist and clean the path Path = Fs.Combine(path); // get the configuration for the web site ManagerResources.LoadConfig(Fs.Combine(Path, "site.config"), new Act <Configuration>(OnConfiguration)); // create the authentication dictionary Authentication = new Dictionary <string, HttpRequirement>(); // create the redirects collection Redirects = new Dictionary <string, HttpRedirect>(); // create the cache _cache = new Cache <string, WebResource>(Global.Megabyte * 100, r => r.Size); _onAccessDenied = new ActionPop <HttpRequest>(); _onInvalidResource = new ActionPop <HttpRequest>(); _defaultSendOptions = new HttpSendOptions { ContentType = "text/html" }; }
private void ResBtn_Clicked(GUIItem item) { Button btn = item as Button; Group costGroup = btn.Tag as Group; String cost_name = costGroup.Tag as String; MouseUI mUI = _Manager.GetComponent <MouseUI>()._ModGet_Manager().GetComponent <MouseUI>(); EntityCost cost = Costs.GetEntityCost(cost_name); foreach (GUIItem costItem in costGroup.Items) { TextField txt = null; if (costItem is TextField) { txt = costItem as TextField; } else if (costItem is Group) { foreach (GUIItem gItem in ((Group)costItem).Items) { if (gItem is TextField) { txt = gItem as TextField; break; } } } if (txt != null) { String resource = txt.Tag as String; int val; if (int.TryParse(txt.Text, out val)) { Debug.Log("Setting " + resource + " of " + cost_name + " to " + val); cost.SetCost(resource, val); } else { txt.Text = cost.GetCost(resource).ToString(); Debug.Log("Failed to set " + resource + " of " + cost_name + ": Not a Number"); } } } Costs.SetEntityCost(cost); if (mUI != null) { mUI.updateBuildInfomation("ButtonBuild" + cost.Internal_Name); } ManagerResources res = _Manager.GetComponent <ManagerResources>(); if (res != null && res._ModGet_TileMap() != null) { res.updateResourcePanel(res._ModGet_TileMap()); } }
public void AddWall(Vector2 position, Rectangle textureOffset) { if (ManagerResources.CompareGold(managerUnits.index, 100)) { ManagerResources.ReduceGold(managerUnits.index, 100); managerUnits.managerMap.AddWalls(position, textureOffset); } }
/// <summary> /// Get average statistics of the drive of the specified directory path. Resulting value units /// are bytes and per second. /// Note : This method writes a Megabyte to the Stream and then clears it. /// </summary> public static void GetStreamStats(string directory, out uint seeks, out uint writes, out uint reads) { // create a test file string filePath = ManagerResources.CreateFilePath(directory, ".drivetest"); // get a stream to the created test file Teple <LockShared, ByteBuffer> resource; ManagerConnections.Get <ByteBuffer, ConnectionLocal>(filePath, out resource); ByteBuffer stream = resource.ArgB; // get a seek, read and write speed for the Author Timekeeper time = new Timekeeper(); // write a Megabyte time.Start(); stream.Write(Generic.Series <byte>((int)Global.Megabyte, 50)); stream.Stream.Flush(); time.Stop(); // derive the number of bytes written per second writes = (uint)(Global.Megabyte / (time.Milliseconds / 1000)); // perform a number of seeks time.Start(); for (int i = 1000; i >= 0; --i) { stream.Position = 0; stream.Write((byte)0); stream.Stream.Flush(); stream.Position = (long)Global.Megabyte - 1L; stream.Write((byte)0); stream.Stream.Flush(); } time.Stop(); // derive the number of seeks per second seeks = (uint)(1000 / (time.Milliseconds / 1000)); stream.Position = 0; // read the Megabyte time.Start(); stream.ReadBytes((int)Global.Megabyte); stream.Stream.Flush(); time.Stop(); // derive the number of bytes read per second reads = (uint)(Global.Megabyte / (time.Milliseconds / 1000)); // release the connection resource.ArgA.Release(); // remove the files File.Delete(filePath); }
private void Awake() { if (Instance != null) { DestroyImmediate (this.gameObject); return; } Instance = this; DontDestroyOnLoad (gameObject); }
public void Update() { if (worker.workState == WorkigState.WORKING && goldMine.workers.Count > 0) { goldMine.animations.Change("working"); elapsed += 0.1f; if (elapsed >= 10) { worker.workState = WorkigState.GO_TO_WORK; cityHall = managerBuildings.buildings.Find((b) => (b.information as InformationBuilding).Type == Util.Buildings.TOWN_HALL || (b.information as InformationBuilding).Type == Util.Buildings.GREAT_HALL) as CityHall; if (cityHall == null) { goldMine.Fire(); } else { if (currentState == State.MINER) { worker.Move((int)cityHall.Position.X / 32, (int)cityHall.Position.Y / 32); worker.animations.currentAnimation = Util.AnimationType.GOLD; goldMine.QUANITY -= 100; goldMine.animations.Change("normal"); currentState = State.TOWN_HALL; } else { worker.Move((int)goldMine.Position.X / 32, (int)goldMine.Position.Y / 32); worker.animations.currentAnimation = Util.AnimationType.WALKING; ManagerResources.ReduceGold(managerUnits.index, -100); if (goldMine.QUANITY <= 0) { goldMine.Fire(); } goldMine.animations.Change("working"); currentState = State.MINER; } } elapsed = 0; } } }
public virtual void Update() { animations.Update(); progress.Update(); progress.position = position + new Vector2(0, height); progress.HP(information.HitPoints, information.HitPointsTotal); if (ui != null) { ui.Update(); } if (information.HitPoints > 0) { if (transition) { UpdateTransition(); if (target != null) { int adjustX = ((int)target.position.X - (int)position.X) / 32; int adjustY = ((int)target.position.Y - (int)position.Y) / 32; if (Math.Abs(adjustX) > information.Range || Math.Abs(adjustY) > information.Range) { transition = false; } } } else if (animations.currentAnimation != AnimationType.DYING) { animations.Stop(); } } if (animations.currentAnimation != AnimationType.DYING && information.HitPoints <= 0) { selected = false; animations.currentAnimation = AnimationType.DYING; animations.isLooping = false; animations.Play("dying"); ManagerResources.ReduceFood(managerUnits.index, -1); } if (information.HitPoints > 0) { Combat(); } }
public bool execute() { if (!go && ManagerResources.CompareGold(managerUnits.index, informationUnit.CostGold) && ManagerResources.CompareFood(managerUnits.index, informationUnit.CostFood)) { ManagerResources.ReduceGold(managerUnits.index, informationUnit.CostGold); ManagerResources.ReduceFood(managerUnits.index, informationUnit.CostFood); go = true; completed = false; remove = false; return(true); } return(false); }
/// <summary> /// Start crawling the web with the current parameters. /// </summary> public void Start() { _lock.Take(); // has the crawl started? if (Running) { // yes, skip the start _lock.Release(); return; } Running = true; Log.Debug("Starting crawl"); _lock.Release(); // load the configuration ManagerResources.LoadConfig(Path, new Act <Configuration>(OnConfigLoad)); }
/// <summary> /// On completion of a urls file being parsed completely. Saves the completed /// state in the configuration. /// </summary> internal void OnCompleteUrlFile(string path) { _lock.Take(); // load the configuration Configuration config = ManagerResources.LoadConfig(Path); Node node = config.Node; // have any root url files been defined? if (node["Files"].ArraySet) { // yes, iterate the specified url files foreach (Node pathNode in node["Files"].Array) { // does the node represent the completed file path? if (pathNode.String == path) { // yes, set the parsed state pathNode["Parsed"].Bool = true; // save the config config.Save(); _lock.Release(); return; } } } else { // no, set the first element of the node array Node pathNode = node["Files"][0]; pathNode.String = path; pathNode["Parsed"].Bool = true; // save the config config.Save(); } Log.Warning("Completed urls file was not found in the crawler configuration."); _lock.Release(); }
public bool execute() { if (ManagerResources.CompareGold(managerUnits.index, building.information.CostGold)) // && ManagerResources.CompareFood(managerUnits.index, building.information.CostWood)) { ManagerResources.ReduceGold(managerUnits.index, building.information.CostGold); if ((building.information as InformationBuilding).Type == Util.Buildings.CHICKEN_FARM || (building.information as InformationBuilding).Type == Util.Buildings.PIG_FARM) { ManagerResources.ReduceFood(managerUnits.index, -5); } builder.workState = WorkigState.WAITING_PLACE; building.builder(); return(true); } return(false); }
/// <summary> /// Pass the 'inStream' through exiftool and write the output to the 'outStream'. /// </summary> private void ReadTemporaryFile(Stream file) { // get a buffer byte[] buffer = BufferCache.Get(); // read from the stream int count = file.Read(buffer, 0, Global.BufferSizeLocal); // write the buffer to the output stream Output.Write(buffer, 0, count); // is this the final buffer? if (count < Global.BufferSizeLocal) { // yes, dispose of the file stream file.Dispose(); // reset the buffer BufferCache.Set(buffer); Success = true; // run callback OnComplete.Run(); // should the file be removed? if (_removeTempFile) { ManagerResources.RemoveFile(Path); } } else { // no, reset the buffer BufferCache.Set(buffer); // add a task to clear the metadata ManagerUpdate.Control.AddSingle(ReadTemporaryFile, file); } }
/// <summary> /// Run the medadata removal process. /// </summary> public void Run() { bool found = false; if (_coordinator.Buffer != null) { while (_coordinator.BufferIndex < _coordinator.BufferCount) { if (_coordinator.ReadySearch.Next(_coordinator.Buffer[_coordinator.BufferIndex])) { ++_coordinator.BufferIndex; found = true; break; } ++_coordinator.BufferIndex; } if (_coordinator.BufferIndex == _coordinator.BufferCount) { _coordinator.Buffer = null; } } if (!found) { // read the {ready} flag from the exiftool var buffer = BufferCache.Get(); var process = _coordinator.Process.TakeItem(); int count = process.StandardOutput.BaseStream.Read(buffer, 0, Global.BufferSizeLocal); // while there are bytes in the process standard output while (count > 0) { int index = 0; while (index < count) { // check the buffer for the {ready} flag if (_coordinator.ReadySearch.Next(buffer[index])) { ++index; // are there bytes in the buffer? if (index == count) { // no, persist the buffer BufferCache.Set(buffer); } else { // yes, remember the buffer and position _coordinator.Buffer = buffer; _coordinator.BufferIndex = index; _coordinator.BufferCount = count; } found = true; break; } ++index; } if (found) { break; } count = process.StandardOutput.BaseStream.Read(buffer, 0, Global.BufferSizeLocal); } _coordinator.Process.Release(); } // should the file be read? if (Output == null) { // no, run callback OnComplete.Run(); // should the file be removed? if (_removeTempFile) { ManagerResources.RemoveFile(Path); } return; } FileStream fileStream; try { fileStream = new FileStream(Path, FileMode.Open, FileAccess.Read, FileShare.Read); } catch (IOException ex) { // if the file is still being used if (ex.HResult == -2147024864) { // try twice more ManagerUpdate.Iterant.AddSingle(TryReadTemporaryFile, 0); return; } throw; } // get a stream to the clean file ManagerUpdate.Control.AddSingle(ReadTemporaryFile, fileStream); }
/// <summary> /// Run the medadata removal process. /// </summary> public void Run() { var stream = new ByteBuffer(new MemoryStream()); bool found = false; if (_coordinator.Buffer != null) { while (_coordinator.BufferIndex < _coordinator.BufferCount) { var bit = _coordinator.Buffer[_coordinator.BufferIndex]; stream.Write(bit); ++_coordinator.BufferIndex; if (_coordinator.ReadySearch.Next(bit)) { found = true; break; } } if (_coordinator.BufferIndex == _coordinator.BufferCount) { _coordinator.Buffer = null; } } if (!found) { // read the {ready} flag from the exiftool var buffer = BufferCache.Get(); var process = _coordinator.Process.TakeItem(); int count = process.StandardOutput.BaseStream.Read(buffer, 0, Global.BufferSizeLocal); // while there are bytes in the process standard output while (count > 0) { int index = 0; while (index < count) { // check the buffer for the {ready} flag var bit = buffer[index]; stream.Write(bit); ++index; if (_coordinator.ReadySearch.Next(bit)) { // the flag has been found - are there bytes in the buffer? if (index == count) { BufferCache.Set(buffer); } else { // yes, remember the buffer _coordinator.Buffer = buffer; _coordinator.BufferIndex = index; _coordinator.BufferCount = count; } found = true; break; } } if (found) { break; } count = process.StandardOutput.BaseStream.Read(buffer, 0, Global.BufferSizeLocal); } _coordinator.Process.Release(); } // should the file be removed? if (_removeTempFile) { ManagerResources.RemoveFile(Path); } // reset the stream position stream.Position = 0; // create the metadata dictionary for the callback Metadata = new Dictionary <MetaKey, string>(); // while there are more bytes to read while (stream.Position < stream.WriteEnd) { string key; try { // read the key of the key value pair key = stream.ReadString(Chars.Colon); } catch { // ignore and break break; } // trim the key key = key.TrimSpace(); // no, read the value of the key-value pair var value = stream.ReadString(Chars.NewLine).TrimSpace(); if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(value)) { Log.Debug("Missing metadata '" + key + "' : '" + value + "'."); continue; } // parse the key and assign key-value pair MetaKey metaKey; if (MetaKeys.Map.TryGetValue(key, out metaKey)) { // determine how to parse the metadata value switch (metaKey) { case MetaKey.FileSize: { // determine the scale of the file size var splitFileSize = value.Split(value.IndexOf(Chars.Space)); switch (splitFileSize.ArgB) { case "bytes": Metadata[metaKey] = splitFileSize.ArgA; break; case "MB": Metadata[metaKey] = ((int)(splitFileSize.ArgA.ToDouble() * Global.Megabyte)).ToString(); break; case "kB": Metadata[metaKey] = ((int)(splitFileSize.ArgA.ToDouble() * Global.Kilobyte)).ToString(); break; case "GB": Metadata[metaKey] = ((int)(splitFileSize.ArgA.ToDouble() * Global.Gigabyte)).ToString(); break; default: Log.Error("Unknown file size scale of media '" + value + "'."); break; } } break; case MetaKey.Duration: { // check for (approx) suffix int index = value.IndexOf(Chars.Space); if (index != -1) { value = value.Substring(0, index); } var splitDuration = value.Split(Chars.Colon); // determine the type of duration if (splitDuration.Length == 1) { Metadata[metaKey] = ((int)(splitDuration[0].ToDouble() * 1000)).ToString(); } else { // parse each component int time = splitDuration[0].ToInt32() * 60 * 60 * 1000; time += splitDuration[1].ToInt32() * 60 * 1000; time += splitDuration[2].ToInt32() * 1000; // assign the time value Metadata[metaKey] = time.ToString(); } } break; case MetaKey.Bitrate: { // determine the scale of the file size var splitBitrate = value.Split(value.IndexOf(Chars.Space)); switch (splitBitrate.ArgB) { case "bps": Metadata[metaKey] = splitBitrate.ArgA; break; case "kbps": Metadata[metaKey] = ((int)(splitBitrate.ArgA.ToDouble() * Global.Kilobyte)).ToString(); break; case "Mbps": Metadata[metaKey] = ((int)(splitBitrate.ArgA.ToDouble() * Global.Megabyte)).ToString(); break; default: Log.Warning("Unknown bitrate scale of media '" + value + "'."); break; } } break; default: // assign the mime type directly Metadata[metaKey] = value; break; } } else { Log.Warning("Unrecognized metadata key '" + key + " : " + value + "'."); } } // dispose of the byte stream stream.Close(); // run callback OnComplete.Run(); }
private System.Collections.IEnumerator UpdateTiles(Tiles shipTiles, ManagerJobs managerJobs, ManagerOptions managerOptions, GameObject tileMap, List <TileData> hull, List <TileData> floor, TileData shipCore, List <TileData> other) { bool deadCrewEndGame = true; try { if (managerOptions != null) { deadCrewEndGame = managerOptions.deadCrewEndGame; managerOptions.deadCrewEndGame = false; } } catch (Exception ex) { this.DisplayError(ex); _Manager.GetComponent <ManagerMenu>().toggleMainMenu(); _IsImporting = false; yield break; } yield return(new WaitForSeconds(0.01f)); Structures structures = null; int cargoGold = 0; int cargoMetal = 0; int cargoSilicon = 0; int cargoWater = 0; int cargoFood = 0; int cargoCredits = 0; try { structures = tileMap.GetComponent <Structures>(); cargoGold = structures.structure[0].reservesGold; cargoMetal = structures.structure[0].reservesMetal; cargoSilicon = structures.structure[0].reservesSilicon; cargoWater = structures.structure[0].reservesWater; cargoFood = structures.structure[0].reservesFood; cargoCredits = structures.structure[0].credits; List <Vector2> tilesToRemove = new List <Vector2>(); for (int x = shipTiles.tiles.GetLowerBound(0); x <= shipTiles.tiles.GetUpperBound(0); x++) { for (int y = shipTiles.tiles.GetLowerBound(1); y <= shipTiles.tiles.GetUpperBound(1); y++) { if (String.IsNullOrEmpty(shipTiles.tiles[x, y].toBecome) && String.IsNullOrEmpty(shipTiles.tiles[x, y].tileType) && String.IsNullOrEmpty(shipTiles.tiles[x, y].structureType)) { continue; } tilesToRemove.Add(new Vector2(x, y)); } } TileHelper.RemoveTiles(tilesToRemove); } catch (Exception ex) { this.DisplayError(ex); _Manager.GetComponent <ManagerMenu>().toggleMainMenu(); _IsImporting = false; yield break; } yield return(new WaitForSeconds(0.01f)); if (hull.Count > 0) { try { TileHelper.BuildTiles(hull); } catch (Exception ex) { this.DisplayError(ex); _Manager.GetComponent <ManagerMenu>().toggleMainMenu(); _IsImporting = false; yield break; } yield return(new WaitForSeconds(0.01f)); } if (floor.Count > 0) { try { TileHelper.BuildTiles(floor); } catch (Exception ex) { this.DisplayError(ex); _Manager.GetComponent <ManagerMenu>().toggleMainMenu(); _IsImporting = false; yield break; } yield return(new WaitForSeconds(0.01f)); } if (shipCore != null) { try { TileHelper.BuildTiles(shipCore); } catch (Exception ex) { this.DisplayError(ex); _Manager.GetComponent <ManagerMenu>().toggleMainMenu(); _IsImporting = false; yield break; } yield return(new WaitForSeconds(0.01f)); } if (other.Count > 0) { try { TileHelper.BuildTiles(other); } catch (Exception ex) { this.DisplayError(ex); _Manager.GetComponent <ManagerMenu>().toggleMainMenu(); _IsImporting = false; yield break; } yield return(new WaitForSeconds(0.01f)); } try { shipTiles.updateTileColors(); shipTiles.updateTileMesh("All"); Crew crew = tileMap.GetComponent <Crew>(); foreach (GameObject crewMember in crew.crewList) { crewMember.transform.position = new Vector3(shipCore.X, crewMember.transform.position.y, shipCore.Y); } } catch (Exception ex) { this.DisplayError(ex); _Manager.GetComponent <ManagerMenu>().toggleMainMenu(); _IsImporting = false; yield break; } yield return(new WaitForSeconds(0.01f)); try { if (managerOptions != null) { managerOptions.deadCrewEndGame = deadCrewEndGame; } ManagerResources managerResources = _Manager.GetComponent <ManagerResources>(); structures.structure[0].reservesGold = 0; structures.structure[0].reservesMetal = 0; structures.structure[0].reservesSilicon = 0; structures.structure[0].reservesWater = 0; structures.structure[0].reservesFood = 0; structures.structure[0].credits = 0; structures.structure[0].cargoCurrent = 0; managerResources.updateResourceReserves("Gold", cargoGold, tileMap, ""); managerResources.updateResourceReserves("Metal", cargoMetal, tileMap, ""); managerResources.updateResourceReserves("Silicon", cargoSilicon, tileMap, ""); managerResources.updateResourceReserves("Water", cargoWater, tileMap, ""); managerResources.updateResourceReserves("Food", cargoFood, tileMap, ""); managerResources.updateCredits(cargoCredits, false); } catch (Exception ex) { this.DisplayError(ex); _Manager.GetComponent <ManagerMenu>().toggleMainMenu(); _IsImporting = false; yield break; } yield return(new WaitForSeconds(0.01f)); _Manager.GetComponent <ManagerMenu>().toggleMainMenu(); _IsImporting = false; }
private void Start() { Me = transform; if (!TransferLine) TransferLine = GameObject.Find("TransferLine").GetComponent<LineRenderer>(); mPlanet = (ManagerPlanet)GameObject.FindObjectOfType(typeof(ManagerPlanet)); mResources = (ManagerResources)GameObject.FindObjectOfType(typeof(ManagerResources)); maxResources = Random.Range(minRandomResources, maxRandomResources); }