public void updatePosition(Droplet d) { Vector2 oldPos = d.pos; d.pos = oldPos + d.direction; d.correctedPos = new Vector2((int)d.pos.x, (int)d.pos.y); }
void Awake() { cam = Camera.main; cam.GetComponent <CameraEventRelay>().RenderImageEvent += OnRenderImage; droplets = new Droplet[9]; for (int i = 0; i < droplets.Length; i++) { droplets[i] = new Droplet(); } gradTexture = new Texture2D(2048, 1, TextureFormat.Alpha8, false); gradTexture.wrapMode = TextureWrapMode.Clamp; gradTexture.filterMode = FilterMode.Bilinear; for (var i = 0; i < gradTexture.width; i++) { var x = 1.0f / gradTexture.width * i; var a = waveform.Evaluate(x); gradTexture.SetPixel(i, 0, new Color(a, a, a, a)); } gradTexture.Apply(); material = new Material(shader); material.hideFlags = HideFlags.DontSave; material.SetTexture("_GradTex", gradTexture); UpdateShaderParameters(); }
public void updateDirection(Droplet d) { int currentIndex = VectToInt(d.correctedPos); int NEIndex = VectToInt(d.correctedPos + Vector2.one); int EIndex = VectToInt(d.correctedPos + Vector2.right); int NIndex = VectToInt(d.correctedPos + Vector2.up); Vector2 offset = d.pos - d.correctedPos; //Debug.Log(currentIndex); //Debug.Log(NEIndex); //Debug.Log( d.ToString()); /*Debug.Log("e " + heightMap[EIndex] + " at index " + EIndex); * Debug.Log("ne " + heightMap[NEIndex] + " at index " + NEIndex); * Debug.Log("n " + heightMap[NIndex] + " at index " + NIndex); * Debug.Log("cur " + heightMap[currentIndex] + " at index " + currentIndex);*/ float gradX = (heightMap[EIndex] - heightMap[currentIndex]) * (1 - offset.y) + (heightMap[NEIndex] - heightMap[NIndex]) * offset.y; float gradY = (heightMap[NIndex] - heightMap[currentIndex]) * (1 - offset.x) + (heightMap[NEIndex] - heightMap[EIndex]) * offset.x; Vector2 gradient = new Vector2(gradX, gradY); //Debug.Log("offset: " + offset); //Debug.Log("gradient: " + gradient); Vector2 newDirection = d.direction * inertia - gradient * (1 - inertia); newDirection.Normalize(); //Debug.Log("new direction: " + newDirection); d.direction = newDirection; }
public bool Stage(Droplet droplet, Instance instance) { bool rv = false; using (FileData file = GetStagedApplicationFile(droplet.ExecutableUri)) { if (null != file) { InstancePaths paths = GetInstancePaths(instance); Directory.CreateDirectory(paths.DropletsPath); Directory.CreateDirectory(paths.BaseAppPath); using (var gzipStream = new GZipInputStream(file.FileStream)) { var tarArchive = TarArchive.CreateInputTarArchive(gzipStream); tarArchive.ExtractContents(paths.DropletsPath); tarArchive.Close(); } var instanceApplicationDirInfo = new DirectoryInfo(paths.BaseAppPath); Utility.CopyDirectory(new DirectoryInfo(paths.DropletsPath), instanceApplicationDirInfo); rv = true; } } return(rv); }
void Awake() { cam = GetComponent <Camera>();//获取相机组件 if (cam == null) { Debug.Log("error it is null"); } droplet = new Droplet(); gradTexture = new Texture2D(2048, 1, TextureFormat.Alpha8, false) { wrapMode = TextureWrapMode.Clamp, filterMode = FilterMode.Bilinear }; for (var i = 0; i < gradTexture.width; i++) { var x = 1.0f / gradTexture.width * i; var a = waveform.Evaluate(x); gradTexture.SetPixel(i, 0, new Color(a, a, a, a)); }//初始化振幅贴图(也就是把waveform曲线初始化到gradTexture上面) gradTexture.Apply(); material = new Material(shader) { hideFlags = HideFlags.DontSave }; material.SetTexture("_GradTex", gradTexture); UpdateShaderParameters(); }
public async Task <Droplet> CreateDropletAsync(int userId, CreateDropletRequest request) { // check key name, or all keys var result = await _apiClient.CreateDroplet(request); var droplet = new Droplet(result); var size = new Size(result.Size); var regions = new List <Region>(); foreach (string region in result.Size.Regions) { regions.Add(new Region() { Name = region }); } var tags = new List <Tag>(); foreach (string tag in result.Tags) { tags.Add(new Tag() { Name = tag }); } await UpdateTags(userId, tags); await UpdateRegions(userId, regions); return(await CreateDropletRecord(userId, droplet, size, tags, regions)); }
public void Catch(Droplet block) { uint degree = (uint)block.Degree; if (degree > _maxCaughtDegree) { _maxCaughtDegree = degree; } if (degree < _minCaughtDegree) { _minCaughtDegree = degree; } if (_drops.ContainsKey (degree) == false) { _drops.Add (degree, new List<Droplet> ()); } List<Droplet> dropList = _drops [degree]; for (int dropIndex=0; dropIndex<dropList.Count; dropIndex++) { if (dropList[dropIndex].Equals (block) == true) { // If any drops the same, dont even bother putting in list return; } } _drops [degree].Add (block); CaughtDroplets++; }
public Server CreateServer(string name, string size, string image, string region, string sshKeyId) { try { var droplet = new Droplet { Image = image, Name = name, Region = region, Size = size, SshKeys = new List <object> { sshKeyId } }; var createdDroplet = _client.Droplets.Create(droplet).Result; var server = DigitalOceanMapper.MapDropletToServer(createdDroplet); server.CloudProvider = _cloudProvider; return(server); } catch (Exception e) { _logger.Error(e); return(null); } }
void Awake() { droplets = new Droplet[3]; for (byte b = 0; b < 3; droplets[b] = new Droplet(), b++) { ; } gradTexture = new Texture2D(2048, 1, TextureFormat.Alpha8, false); gradTexture.wrapMode = TextureWrapMode.Clamp; gradTexture.filterMode = FilterMode.Bilinear; for (var i = 0; i < gradTexture.width; i++) { var x = 1.0f / gradTexture.width * i; var a = waveform.Evaluate(x); gradTexture.SetPixel(i, 0, new Color(a, a, a, a)); } gradTexture.Apply(); material = new Material(shader); material.hideFlags = HideFlags.DontSave; material.SetTexture("_GradTex", gradTexture); UpdateShaderParameters(); }
void Start() { if (camera == null) { Debug.Log(" Camera is null "); } droplets = new Droplet[3]; /* Initialize ripple data */ for (int i = 0; i < droplets.Length; i++) { droplets[i] = new Droplet(); } gradTexture = new Texture2D(2048, 1, TextureFormat.Alpha8, false); gradTexture.wrapMode = TextureWrapMode.Clamp; gradTexture.filterMode = FilterMode.Bilinear; /* Initialize the amplitude map (that is, initialize the waveform curve to gradTexture) */ for (var i = 0; i < gradTexture.width; i++) { var x = 1.0f / gradTexture.width * i; var a = waveform.Evaluate(x); gradTexture.SetPixel(i, 0, new Color(a, a, a, a)); } gradTexture.Apply(); material = new Material(shader); material.hideFlags = HideFlags.DontSave; material.SetTexture("_GradTex", gradTexture); UpdateShaderParameters(); }
/// <summary> /// Maps the digital ocean droplet to the server model. /// </summary> /// <param name="droplet">The digital ocean droplet</param> /// <returns></returns> internal static Server MapDropletToServer(Droplet droplet) { var ipv4 = droplet.Networks.V4.Select(ip => new IpAddress { Ip = ip.IpAddress, Name = string.Empty, Version = 4, Netmask = ip.Netmask, Gateway = ip.Gateway }).ToList(); var ipv6 = droplet.Networks.V6.Select(ip => new IpAddress { Ip = ip.IpAddress, Name = string.Empty, Version = 6, Netmask = ip.Netmask.ToString(), Gateway = ip.Gateway }).ToList(); return(new Server { CloudId = droplet.Id.ToString(), InstallationScript = null, InstallationScriptLocation = null, IpAddresses = ipv4.Union(ipv6).ToList(), MainIpAddress = droplet.Networks.V4.FirstOrDefault()?.IpAddress, Name = droplet.Name }); }
void Awake() { droplets = new Droplet[3]; droplets[0] = new Droplet(); droplets[1] = new Droplet(); droplets[2] = new Droplet(); mainCamera = GetComponent <Camera>(); gradTexture = new Texture2D(2048, 1, TextureFormat.Alpha8, false); gradTexture.wrapMode = TextureWrapMode.Clamp; gradTexture.filterMode = FilterMode.Bilinear; for (int i = 0; i < gradTexture.width; i++) { float x = 1.0f / gradTexture.width * i; float a = waveform.Evaluate(x); gradTexture.SetPixel(i, 0, new Color(a, a, a, a)); } gradTexture.Apply(); material = new Material(shader); material.hideFlags = HideFlags.DontSave; material.SetTexture("_GradTex", gradTexture); UpdateShaderParameters(); }
float CalculateHeight(Droplet droplet) { int LLNodeX = (int)droplet.x; int LLNodeZ = (int)droplet.z; float xPosOff = droplet.x - LLNodeX; float zPosOff = droplet.z - LLNodeZ; try { float heightLLNode = heightmap[LLNodeX, LLNodeZ]; float heightULNode = heightmap[LLNodeX, LLNodeZ + 1]; float heightLRNode = heightmap[LLNodeX + 1, LLNodeZ]; float heightURNode = heightmap[LLNodeX + 1, LLNodeZ + 1]; float bilinearBot = (1 - xPosOff) * heightLLNode + xPosOff * heightLRNode; float bilinearTop = (1 - xPosOff) * heightULNode + xPosOff * heightURNode; float heightDroplet = (1 - zPosOff) * bilinearBot + zPosOff * bilinearTop; return(heightDroplet); } catch { Debug.Log(droplet.x + ", " + droplet.z + ", " + droplet.stepsTaken); } return(0); }
void Start() { //c = GetComponent<Camera>();//获取相机组件 if (c == null) { Debug.Log("error it is null"); } droplets = new Droplet[3]; for (int i = 0; i < droplets.Length; i++) { droplets[i] = new Droplet(); }//初始化涟漪数据 gradTexture = new Texture2D(2048, 1, TextureFormat.Alpha8, false); gradTexture.wrapMode = TextureWrapMode.Clamp; gradTexture.filterMode = FilterMode.Bilinear; for (var i = 0; i < gradTexture.width; i++) { var x = 1.0f / gradTexture.width * i; var a = waveform.Evaluate(x); gradTexture.SetPixel(i, 0, new Color(a, a, a, a)); }//初始化振幅贴图(也就是把waveform曲线初始化到gradTexture上面) gradTexture.Apply(); material = new Material(shader); material.hideFlags = HideFlags.DontSave; material.SetTexture("_GradTex", gradTexture); UpdateShaderParameters(); }
private async Task SyncDropletsInfo(int userId) { var droplets = await _apiClient.GetDropletsList(); var apiDroplets = new List <Droplet>(); var dbDroplets = await _dbContext.Droplets .Include(t => t.DropletTags) .Where(t => t.WorkflowState != WorkflowStates.Removed) .ToListAsync(); var storedDroplets = dbDroplets .GroupBy(g => g.DoUid) .Select(m => m.OrderByDescending(h => h.Version).First()); foreach (var d in droplets) { var droplet = new Droplet(d); apiDroplets.Add(droplet); var size = new Size(d.Size); var regions = new List <Region>(); foreach (string region in d.Size.Regions) { regions.Add(new Region() { Name = region }); } var tags = new List <Tag>(); foreach (string tag in d.Tags) { tags.Add(new Tag() { Name = tag }); } await UpdateTags(userId, tags); await UpdateRegions(userId, regions); var dbDroplet = storedDroplets.FirstOrDefault(t => t.DoUid == droplet.DoUid); // add new droplet if (dbDroplet == null) { await CreateDropletRecord(userId, droplet, size, tags, regions); continue; } await UpdateDroplet(userId, droplet, dbDroplet, size); } // remove missing droplets foreach (var item in storedDroplets) { await RemoveDropletRecord(userId, apiDroplets, item); } }
private void ProcessDeaUpdate(string message, string reply) { if (shutting_down) { return; } log.Debug(Resources.Agent_ProcessDeaUpdate_Fmt, message); Droplet droplet = Message.FromJson <Droplet>(message); dropletManager.ForAllInstances(droplet.ID, (instance) => { string[] currentUris = instance.Uris.ToArrayOrNull(); // NB: will create new array instance.Uris = droplet.Uris; var toRemove = currentUris.Except(droplet.Uris); var toAdd = droplet.Uris.Except(currentUris); UnregisterWithRouter(instance, toRemove.ToArray()); RegisterWithRouter(instance, toAdd.ToArray()); }); TakeSnapshot(); }
public override string Render(Droplet point, LongRng rng) { // Sets random character for each point point.symbol = (char)(rng.NextInt(93) + 33); string strOut = ""; if (point.magnitude == 0) { strOut = ("\x1b[38;2;0;0;0m"); // return ConsoleColor.black; } else if (point.magnitude < point.length - 3) { strOut = ("\x1b[38;2;0;255;0m"); // return ConsoleColor.green; } else if (point.magnitude < point.length) { strOut = ("\x1b[38;2;127;255;127m"); // return ConsoleColor.grey; } else { strOut = ("\x1b[38;2;255;255;255m"); // return ConsoleColor.white; } if (strOut != lastColour) { lastColour = strOut; } else { strOut = ""; } return(strOut + point.symbol); }
void Awake() { cam = Camera.main; /*if (goToCamera) * { * RippleEffect ripple = cam.gameObject.AddComponent(typeof(RippleEffect)) as RippleEffect; * ripple = this; * Destroy(this); * return; * }*/ droplets = new Droplet[3]; droplets[0] = new Droplet(); droplets[1] = new Droplet(); droplets[2] = new Droplet(); gradTexture = new Texture2D(2048, 1, TextureFormat.Alpha8, false); gradTexture.wrapMode = TextureWrapMode.Clamp; gradTexture.filterMode = FilterMode.Bilinear; for (var i = 0; i < gradTexture.width; i++) { var x = 1.0f / gradTexture.width * i; var a = waveform.Evaluate(x); gradTexture.SetPixel(i, 0, new Color(a, a, a, a)); } gradTexture.Apply(); material = new Material(shader); material.hideFlags = HideFlags.DontSave; material.SetTexture("_GradTex", gradTexture); UpdateShaderParameters(); }
// Manages direction and actions of droplet such as direction, lifetime and sediment private void RunDropletCycle(Droplet newDrop) { for (int lifetime = 0; lifetime < dropletLifetime; lifetime++) { int nodeX = (int)newDrop.posX; int nodeY = (int)newDrop.posY; int dropletIndex = nodeY * currentMapSize + nodeX; float cellOffsetX = newDrop.posX - nodeX; float cellOffsetY = newDrop.posY - nodeY; // Gets Droplet's height and direction HeightAndGradient heightAndGradient = CalculateHeightAndGradient(newDrop.posX, newDrop.posY); // Update droplet newDrop.directionX = (newDrop.directionX * inertia - heightAndGradient.gradientX * (1 - inertia)); newDrop.directionY = (newDrop.directionY * inertia - heightAndGradient.gradientY * (1 - inertia)); float len = Mathf.Sqrt(newDrop.directionX * newDrop.directionX + newDrop.directionY * newDrop.directionY); if (len != 0) { newDrop.directionX /= len; newDrop.directionY /= len; } newDrop.posX += newDrop.directionX; newDrop.posY += newDrop.directionY; // Check if droplet is on map if ((newDrop.directionX == 0 && newDrop.directionY == 0) || newDrop.posX < 0 || newDrop.posX >= currentMapSize - 1 || newDrop.posY < 0 || newDrop.posY >= currentMapSize - 1) { break; } CalculateSediment(newDrop, heightAndGradient, dropletIndex, cellOffsetX, cellOffsetY); } }
private async Task ChooseImage(Message message) { var digitalOceanApi = _digitalOceanClientFactory.GetInstance(message.From.Id); var images = await digitalOceanApi.Images.GetAll(ImageType.Distribution); _sessionRepo.Update(message.From.Id, session => { var droplet = new Droplet { Name = message.Text, }; var createDroplet = new CreateDroplet { Droplet = droplet, Images = images }; session.Data = createDroplet; session.State = SessionState.WaitChooseImageDroplet; }); var page = _pageFactory.GetInstance <ImagePage>(); var pageModel = page.GetPage(message.From.Id, 0); var sendMessage = await _telegramBotClient.SendTextMessageAsync(message.Chat.Id, pageModel.Message, ParseMode.Markdown, replyMarkup : pageModel.Keyboard); _handlerCallbackRepo.Update(message.From.Id, callback => { callback.MessageId = sendMessage.MessageId; callback.UserId = message.From.Id; callback.HandlerType = GetType().FullName; }); }
public void Init(Camera cam) { this.cam = cam; droplets = new Droplet[3]; droplets[0] = new Droplet(); droplets[1] = new Droplet(); droplets[2] = new Droplet(); gradTexture = new Texture2D(2048, 1, TextureFormat.Alpha8, false); gradTexture.wrapMode = TextureWrapMode.Clamp; gradTexture.filterMode = FilterMode.Bilinear; for (var i = 0; i < gradTexture.width; i++) { var x = 1.0f / gradTexture.width * i; var a = waveform.Evaluate(x); gradTexture.SetPixel(i, 0, new Color(a, a, a, a)); } gradTexture.Apply(); material.hideFlags = HideFlags.None; material.SetTexture("_GradTex", gradTexture); //InvokeRepeating("Emitt", 2f, 2f); UpdateShaderParameters(); }
Droplet SpawnDroplet() { Droplet drop = Instantiate(precipitPrefab, transform); precipList.Add(drop); return(drop); }
public float getHeight(Droplet d) { //Debug.Log("in height " + d.ToString()); int currentIndex = VectToInt(d.correctedPos); int NEIndex = VectToInt(d.correctedPos + Vector2.one); int EIndex = VectToInt(d.correctedPos + Vector2.right); int NIndex = VectToInt(d.correctedPos + Vector2.up); Vector2 offset = d.pos - d.correctedPos; //Debug.Log(currentIndex + " in height"); float height = heightMap[currentIndex] * (1 - offset.x) * (1 - offset.y); //if(EIndex < heightMap.Length) height += heightMap[EIndex] * offset.x * (1 - offset.y); //if(NIndex < heightMap.Length) height += heightMap[NIndex] * (1 - offset.x) * offset.y; //if(NEIndex < heightMap.Length) height += heightMap[NEIndex] * offset.x * offset.y; /*Debug.Log("e " + heightMap[EIndex] + " at index " + EIndex); * Debug.Log("ne " + heightMap[NEIndex] + " at index " + NEIndex); * Debug.Log("n " + heightMap[NIndex] + " at index " + NIndex); * Debug.Log("cur " + heightMap[currentIndex] + " at index " + currentIndex);*/ return(height); }
public OriginCube(Vector3Int fromTowerOrigin, Vector3Int orientation, Droplet parentDroplet) : base(null, fromTowerOrigin) { ParentDroplet = parentDroplet; CubeGameObject = Instantiate(parentDroplet.ParentTower.CubePrefab, parentDroplet.ParentTower.CubePositionToAbsolute(fromTowerOrigin), Quaternion.identity); Orientation = orientation; OriginCube = this; }
void Update() { if (Time.timeSinceLevelLoad > (timeLastDrop + (1f / precipitFallRate))) { Droplet nextDrop = GetListedDroplet(); ResetDroplet(nextDrop); timeLastDrop = Time.timeSinceLevelLoad; } }
public override void _Input(InputEvent @event) { if (@event is InputEventMouse eventMouseMove) { var camera = (Camera)GetNode("/root/World/Camera"); var from = camera.ProjectRayOrigin(eventMouseMove.Position); var to = from + camera.ProjectRayNormal(eventMouseMove.Position) * rayLength; var raycast = (RayCast)GetNode("/root/World/RayCast"); raycast.Translation = from; raycast.CastTo = to; var collision_point = raycast.GetCollisionPoint(); mousePosition = collision_point; } if (@event is InputEventMouseButton eventMouseButton && eventMouseButton.Pressed && eventMouseButton.ButtonIndex == 1) { var camera = (Camera)GetNode("/root/World/Camera"); var from = camera.ProjectRayOrigin(eventMouseButton.Position); var to = from + camera.ProjectRayNormal(eventMouseButton.Position) * rayLength; var raycast = (RayCast)GetNode("/root/World/RayCast"); raycast.Translation = from; raycast.CastTo = to; var collision_point = raycast.GetCollisionPoint(); var tool = GetCurrentTool(); if (tool == ToolSelected.WATER) { if (_currentWaterCapacity >= WaterShotCost) { _currentWaterCapacity -= WaterShotCost; GD.Print("Shoooting water"); Droplet droplet = (Droplet)waterProjectile.Instance(); droplet.SetPositionAndDirection(this.GetTranslation(), collision_point); GetNode("/root/World").AddChild(droplet); } } else if (tool == ToolSelected.DIRT) { if (_currentDirtCapacity >= DirtShotCost) { _currentDirtCapacity -= DirtShotCost; GD.Print("Shoooting dirt"); DirtBall dirtball = (DirtBall)dirtProjectile.Instance(); dirtball.SetPositionAndDirection(this.GetTranslation(), collision_point); GetNode("/root/World").AddChild(dirtball); } } } if (@event is InputEventAction eventAction && eventAction.Action == "water" && eventAction.Pressed) { GD.Print("Pouring out that sweet H2Flow"); _currentWaterCapacity += 20; } }
// Spawn a new droplet of the requested color, in the requested position public void Drop(LiquidBase color, Vector3 worldPos) { Droplet newDroplet = Instantiate(dropletTemplate); newDroplet.name = "Droplet"; newDroplet.transform.position = worldPos; newDroplet.color = color; newDroplet.gameObject.SetActive(true); }
// Creates rain based on iterations set public void Erode(float[] map, int mapSize, int numIterations = 1) { Initialize(mapSize, map); for (int iteration = 0; iteration < numIterations; iteration++) { //Create random droplet on map Droplet newDrop = CalculateDroplet(); RunDropletCycle(newDrop); } }
// Start is called before the first frame update void Start() { rb = GetComponent <Rigidbody2D>(); dashAquired = false; dropletRef = GetComponent <Droplet>(); ppCameraRef = GameObject.Find("Main Camera").GetComponent <CameraController>(); spriteRef = GetComponent <SpriteRenderer>(); startSequence = true; endTile.SetActive(false); settingAudio = true; }
void ResetDroplet(Droplet dp) { Vector3 dropletPosition = internalBeamTransform.position; //dropletPosition += internalBeamTransform.right * -10f; dropletPosition += internalBeamTransform.up * Random.Range(-5f, 5f); dp.transform.position = dropletPosition; dp.GetComponent <Rigidbody2D>().velocity = internalBeamTransform.transform.right * fallSpeed; dp.bActive = true; dp.SetDropletEnabled(true); }
private void _Erode() { for (int i = 0; i < 100 * brush.Power; i++) { // Start at a random point inside the brush. var x = brush.Position.x + (TileSize / 2f) + (2 * (float)rng.NextDouble() - 1) * brush.Radius; var y = brush.Position.y + (TileSize / 2f) + (2 * (float)rng.NextDouble() - 1) * brush.Radius; x = Mathf.Min(Mathf.Max(x, 0), TileSize - 1); y = Mathf.Min(Mathf.Max(y, 0), TileSize - 1); Droplet.Simulate(terrainImg, x, y); } }
void Awake() { droplets = new Droplet[3]; droplets[0] = new Droplet(); droplets[1] = new Droplet(); droplets[2] = new Droplet(); gradTexture = new Texture2D(2048, 1, TextureFormat.Alpha8, false); gradTexture.wrapMode = TextureWrapMode.Clamp; gradTexture.filterMode = FilterMode.Bilinear; for (var i = 0; i < gradTexture.width; i++) { var x = 1.0f / gradTexture.width * i; var a = waveform.Evaluate(x); gradTexture.SetPixel(i, 0, new Color(a, a, a, a)); } gradTexture.Apply(); material = new Material(shader); material.hideFlags = HideFlags.DontSave; material.SetTexture("_GradTex", gradTexture); UpdateShaderParameters(); }
public void SetupEnvironment(Droplet droplet, Instance instance) { Configuration c = getConfiguration(instance); if (null != c) { AppSettingsSection appSettingsSection = c.GetSection("appSettings") as AppSettingsSection; if (null != appSettingsSection) { var appSettings = appSettingsSection.Settings; replaceSetting(appSettings, "HOME", Path.Combine(config.AppDir, instance.Staged)); var applicationDict = new Dictionary<string, object> { { "instance_id", droplet.ID }, { "instance_index", droplet.InstanceIndex }, { "name", droplet.Name }, { "uris", droplet.Uris }, { "users", droplet.Users }, { "version", droplet.Version }, { "runtime", droplet.Runtime }, }; string vcapApplicationJson = JsonConvert.SerializeObject(applicationDict); replaceSetting(appSettings, "VCAP_APPLICATION", vcapApplicationJson); if (false == droplet.Services.IsNullOrEmpty()) { string vcapServicesJson = JsonConvert.SerializeObject(droplet.Services.ToDictionary(s => s.Label)); replaceSetting(appSettings, "VCAP_SERVICES", vcapServicesJson); } replaceSetting(appSettings, "VCAP_APP_HOST", config.LocalIPAddress.ToString()); // TODO appSettingsSection.Settings["VCAP_APP_PORT"].Value if (false == droplet.Env.IsNullOrEmpty()) { foreach (string env in droplet.Env) { string[] envSplit = env.Split(new[] { '=' }); if (false == envSplit.IsNullOrEmpty() && envSplit.Length == 2) { string key = envSplit[0]; string value = envSplit[1]; replaceSetting(appSettings, key, value); } } } } c.Save(); } }
public void BindServices(Droplet droplet, Instance instance) { if (false == droplet.Services.IsNullOrEmpty()) { Configuration c = getConfiguration(instance); if (null != c) { ConnectionStringsSection connectionStringsSection = c.GetSection("connectionStrings") as ConnectionStringsSection; if (null != connectionStringsSection) { foreach (Service svc in droplet.Services.Where(s => s.IsMSSqlServer)) { if (null != svc.Credentials) { var creds = new Credentials(svc.Credentials); SqlConnectionStringBuilder builder; ConnectionStringSettings defaultConnectionStringSettings = connectionStringsSection.ConnectionStrings["Default"]; if (null == defaultConnectionStringSettings) { builder = new SqlConnectionStringBuilder(); } else { builder = new SqlConnectionStringBuilder(defaultConnectionStringSettings.ConnectionString); } builder.DataSource = creds.Host; builder.ConnectTimeout = 30; if (creds.Password.IsNullOrWhiteSpace() || creds.Username.IsNullOrWhiteSpace()) { builder.IntegratedSecurity = true; } else { builder.IntegratedSecurity = false; builder.UserID = creds.Username; builder.Password = creds.Password; } if (false == creds.Name.IsNullOrWhiteSpace()) { builder.InitialCatalog = creds.Name; } if (null == defaultConnectionStringSettings) { connectionStringsSection.ConnectionStrings.Add(new ConnectionStringSettings("Default", builder.ConnectionString)); } else { defaultConnectionStringSettings.ConnectionString = builder.ConnectionString; } break; } } } c.Save(); } } }
private void UpdateDroplet(Droplet droplet) { var originalDroplet = this.powers.FirstOrDefault(d => droplet.Id == d.Id); if (ReferenceEquals(null, originalDroplet)) { this.powers.Add(droplet); return; } originalDroplet.Update(droplet); }
public Droplet Encode() { Droplet encodingBlock = null; int d = 0; int[] generatedNeighbours; int currentNeighbour; _trackingDist.Generate (); d = _trackingDist.Degree (); generatedNeighbours = _trackingDist.Neighbours (); encodingBlock = new Droplet(d, BlockSize); for (int numNeighbours=0; numNeighbours<d; numNeighbours++) { currentNeighbour = generatedNeighbours [numNeighbours]; encodingBlock.AddNeighbour(currentNeighbour); if (numNeighbours == 0) { encodingBlock.Data = _data[currentNeighbour]; } else { XorInto (encodingBlock.Data, _data [currentNeighbour]); } } return (encodingBlock); }
private void PrintDrop(Droplet d) { Console.Write ("> D: {0}, N: ", d.Neighbours.Count); for (int i=0; i<d.Neighbours.Count; i++) { Console.Write ("{0},", d.Neighbours [i]); } Console.WriteLine (); }
private bool Solve(Droplet d, List<int> neighbours, out int solved) { int solvingFor; int neighbourIndex; bool isUseful = false; bool didSolve; solved = 0; for (int index=0; index<neighbours.Count; index++) { solvingFor = neighbours [index]; if (_decodedData [solvingFor] == null) { // Setup the block we are about to decode _decodedData [solvingFor] = new byte[_blockSize]; Array.Copy (d.Data, _decodedData[solvingFor], _blockSize); didSolve = true; // Try solve this one for (int othersIndex=0; othersIndex<neighbours.Count; othersIndex++) { if (othersIndex == index) { continue; } neighbourIndex = neighbours [othersIndex]; if (_decodedData [neighbourIndex] == null) { // We cant solve, bomb out _decodedData [solvingFor] = null; isUseful = true; didSolve = false; break; } XorInto (_decodedData [solvingFor], _decodedData [neighbourIndex]); } if (didSolve == true) { solved++; } } } return isUseful; }
public Droplet Encode() { Droplet encodingBlock = null; int d=0, neighbourOffset; d = _dist.Degree (); encodingBlock = new Droplet(d, BlockSize); for (int numNeighbours=1; numNeighbours<=d; numNeighbours++) { // Get a block offset do { neighbourOffset = _neighbourSelector.Next (K); // Loop until we generate a neighbour that isn't already in the list } while (encodingBlock.Neighbours.Contains (neighbourOffset) == true); encodingBlock.AddNeighbour(neighbourOffset); if (numNeighbours == 1) { encodingBlock.Data = _data[neighbourOffset]; } else { XorInto (encodingBlock.Data, _data [neighbourOffset]); } } return (encodingBlock); }