/// <summary> /// Used to insert a new entry to the cache /// </summary> /// <typeparam name="V">Data type of Value</typeparam> /// <typeparam name="K">Data type of Key</typeparam> /// <param name="key">key</param> /// <param name="val">value</param> /// <param name="lifespaninMillis">Lifespan in milliseconds</param> /// <param name="maxIdleTimeinMillis">Maximum idle time in milliseconds</param> public void put <V, K>(K key, V val, int lifespaninMillis, int maxIdleTimeinMillis) { int lifespanSecs = TimeSpan.FromMilliseconds(lifespaninMillis).Seconds; int maxIdleSecs = TimeSpan.FromMilliseconds(maxIdleTimeinMillis).Seconds; PutOperation op = operationsFactory.newPutKeyValueOperation(serializer.serialize(key), serializer.serialize(val), lifespanSecs, maxIdleSecs); transport = transportFactory.getTransport(); try { byte[] result = (byte[])op.executeOperation(transport); } finally { transportFactory.releaseTransport(transport); } }
public void executeOperationTest() { Transport trans = new TCPTransport(System.Net.IPAddress.Loopback, 11222); Codec codec = new Codec(); Serializer s = new DefaultSerializer(); Serializer s2 = new DefaultSerializer(); //byte[] key = s.serialize("11"); byte[] key = s.serialize("key15"); //byte[] key=UTF8Encoding.UTF8.GetBytes("key10"); byte[] val = s.serialize("hexachlorocyclohexane777");//UTF8Encoding.UTF8.GetBytes("hexachlorocyclohexane777"); PutOperation target = new PutOperation(codec, key, null, 0, null, val, 0, 0); // TODO: Initialize to an appropriate value Transport transport = trans; byte[] expected = null; // TODO: Initialize to an appropriate value byte[] actual; actual = target.executeOperation(transport); Assert.AreEqual(expected, actual); }
public void executeOperationTest() { Transport trans = new TCPTransport(System.Net.IPAddress.Loopback, 11222); Codec codec = new Codec(); Serializer s = new DefaultSerializer(); Serializer s2 = new DefaultSerializer(); //byte[] key = s.serialize("11"); byte[] key = s.serialize("key15"); //byte[] key=UTF8Encoding.UTF8.GetBytes("key10"); byte[] val = s.serialize("hexachlorocyclohexane777"); //UTF8Encoding.UTF8.GetBytes("hexachlorocyclohexane777"); PutOperation target = new PutOperation(codec, key, null, 0, null, val, 0, 0); // TODO: Initialize to an appropriate value Transport transport = trans; byte[] expected = null; // TODO: Initialize to an appropriate value byte[] actual; actual = target.executeOperation(transport); Assert.AreEqual(expected, actual); }
internal virtual IList <UpdateOperation> GenerateUpdatesForNextIteration() { IList <UpdateOperation> updateOperations = new List <UpdateOperation>(); if (ToAdd.Count == 0 && ToRemove.Count == 0) { EndSignalConflict.set(true); return(updateOperations); } int operationsInIteration = ReadersShouldSee.Count < 1000 ? 100 : ReadersShouldSee.Count / 10; int count = 0; while (count < operationsInIteration && (ToAdd.Count > 0 || ToRemove.Count > 0)) { UpdateOperation operation; if (ToAdd.Count == 0) { operation = new RemoveOperation(_outerInstance, ToRemove.RemoveFirst()); } else if (ToRemove.Count == 0) { operation = new PutOperation(_outerInstance, ToAdd.RemoveFirst()); } else { bool remove = Random.NextDouble() > WritePercentage; if (remove) { operation = new RemoveOperation(_outerInstance, ToRemove.RemoveFirst()); } else { operation = new PutOperation(_outerInstance, ToAdd.RemoveFirst()); } } updateOperations.Add(operation); count++; } return(updateOperations); }
void AddAction() { var pickedTool = ToolPicker.GetPickedTool(); if (pickedTool == null) { return; } var position = GetPositionUnderMouse(); var op = CreateOp(pickedTool, position); if (op == previousAdd) { return; } previousAdd = op; world.PutBlock(op); audioSource.PlayOneShot(buildSfx[buildSfxIndex]); buildSfxIndex = (buildSfxIndex + 1) % buildSfx.Length; }
public bool IsInBounds(PutOperation op) => IsInBounds(op.cellX, op.cellZ);
private void UploadFiles(string[] files, Site binderSite, StorageEngine storageEngine, string destination) { foreach (var file in files) { //string directoryName = Path.GetDirectoryName(file); string fileName = Path.GetFileName(file); Console.Write(fileName.PadRight(45) + " "); try { using (var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read)) { var storageResponse = storageEngine.StoreFile(fileStream); var fileInfo = new FileInfo(file); var options = new CreateSiteFileVersionOptions() { Length = fileInfo.Length, FileModifiedTimeUtc = fileInfo.LastWriteTimeUtc, HiggsFileId = storageResponse.HiggsFileID, Name = fileName, StorageZoneId = fixedStorageZoneId.ToString() }; var url = binderSite.Region.EndpointUrl .AppendPathSegment("SiteNavigator") .AppendPathSegment(binderSite.Subdomain) .AppendPathSegment("Folder") .AppendPathSegment("Files") .SetQueryParam("path", destination) .SetQueryParam("api_key", AuthorisedSession.SessionToken); var addFileResponseMessage = new PutOperation<CreateSiteFileVersionOptions>(url) .WithRequest(options) .ResponseMessage; var siteFileModel = addFileResponseMessage.Content<SiteFileModel>(); if (siteFileModel.Length != fileInfo.Length) throw new ApplicationException("Uploaded file length does not match"); Console.WriteLine(addFileResponseMessage.StatusCode.ToString()); } } catch (Exception ex) { Console.WriteLine("ERROR: " + ex.Message); } } }