public void FirstOrDefaultOnFourTuple() { const int expected = 42; var t = new Tuple<int, int, int, int>(42, 1, 1, 1); int actual = t.FirstOrDefault(); Assert.AreEqual(expected, actual); }
public void FirstOrDefaultOnThreeTuple() { const int expected = 42; var t = new Tuple <int, int, int>(42, 1, 1); int actual = t.FirstOrDefault(); Assert.AreEqual(expected, actual); }
public void StoreWithoutIncludeTest() { using (var session = Domain.OpenSession()) using (var transaction = session.OpenTransaction()) { var businessUnitIds = session.Query.All <BusinessUnit>().Select(bu => bu.Id).ToList(); var bounds = new Tuple <DateTime, DateTime, string> [26]; for (int i = 0; i < bounds.Length; i++) { bounds[i] = new Tuple <DateTime, DateTime, string>(DateTime.UtcNow, DateTime.UtcNow, ""); } var list = session.Query.All <Job>() .Select(job => new { BusinessUnitId = job.BusinessUnit.Id, Month = bounds.FirstOrDefault().Item3 }) .ToList(); } }
public void IncludeThenStoreTest() { Require.AllFeaturesSupported(ProviderFeatures.TemporaryTables); using (var session = Domain.OpenSession()) using (var transaction = session.OpenTransaction()) { var businessUnitIds = session.Query.All <BusinessUnit>().Select(bu => bu.Id).ToList(); var bounds = new Tuple <DateTime, DateTime, string> [26]; for (int i = 0; i < bounds.Length; i++) { bounds[i] = new Tuple <DateTime, DateTime, string>(DateTime.UtcNow, DateTime.UtcNow, ""); } var list = session.Query.All <Job>() .Where(job => job.BusinessUnit.Id.In(businessUnitIds)) .Select(job => new { BusinessUnitId = job.BusinessUnit.Id, Month = bounds.FirstOrDefault().Item3 }) .ToList(); } }
private static TypeTo AddHeaders <TypeFrom, TypeTo>(TypeFrom headersFrom, HttpWebRequest webRequest) where TypeFrom : NameValueCollection where TypeTo : NameValueCollection, new() { TypeTo webHeaders = new TypeTo(); foreach (var key in headersFrom.AllKeys) { var setValue = true; if (webHeaders is WebHeaderCollection && webRequest != null) { WebHeaderCollection convertTo = webHeaders as WebHeaderCollection; if (WebHeaderCollection.IsRestricted(key)) { var currentKey = key.ToLower().Trim(); var lookup = new Tuple <string, string> [13]; lookup[0] = new Tuple <string, string>("accept", "Accept"); lookup[1] = new Tuple <string, string>("connection", "Connection"); lookup[2] = new Tuple <string, string>("content-length", "ContentLength"); lookup[3] = new Tuple <string, string>("content-type", "ContentType"); lookup[4] = new Tuple <string, string>("date", "Date"); lookup[5] = new Tuple <string, string>("expect", "Expect"); lookup[6] = new Tuple <string, string>("host", "Host"); lookup[7] = new Tuple <string, string>("if-modified-since", "IfModifiedSince"); lookup[8] = new Tuple <string, string>("range", "Range"); lookup[9] = new Tuple <string, string>("referrer", "Referrer"); lookup[10] = new Tuple <string, string>("transfer-encoding", "TransferEncoding"); lookup[11] = new Tuple <string, string>("user-agent", "UserAgent"); lookup[11] = new Tuple <string, string>("proxy-connection", "KeepAlive"); var match = lookup.FirstOrDefault(x => x.Item1 == currentKey); if (match != null) { setValue = false; try { if (headersFrom[key].ToLower() == "keep-alive") { webRequest.GetType().InvokeMember("KeepAlive", BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty, Type.DefaultBinder, webRequest, new object[] { true }); } else { webRequest.GetType().InvokeMember(match.Item2, BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty, Type.DefaultBinder, webRequest, new object[] { headersFrom[key] }); } } catch (Exception) { } } } } if (setValue) { try { if (Array.IndexOf(webHeaders.AllKeys, key) != -1) { webHeaders[key] = headersFrom[key]; } else { webHeaders.Add(key, headersFrom[key]); } } catch (Exception) { } } } return(webHeaders); }
static public void GenerateCheatTable(Adresses a) { #if DEBUG Tuple <string, string, int, bool>[] info = new Tuple <string, string, int, bool>[] { new Tuple <string, string, int, bool>("bypassHackDetection", "Array of byte", 6, true), new Tuple <string, string, int, bool>("wallHackDetection", "Array of byte", 6, true), new Tuple <string, string, int, bool>("wallHack", "Array of byte", 200, true), new Tuple <string, string, int, bool>("wallBase", "Array of byte", 200, true), new Tuple <string, string, int, bool>("pickupRange1", "Array of byte", 3, false), new Tuple <string, string, int, bool>("pickupRange2", "Array of byte", 3, false), new Tuple <string, string, int, bool>("Base", "4 Bytes", 0, true), new Tuple <string, string, int, bool>("baseCam", "4 Bytes", 0, true), new Tuple <string, string, int, bool>("wallBase", "4 Bytes", 0, true), new Tuple <string, string, int, bool>("id", "String", 99, true), new Tuple <string, string, int, bool>("x", "Float", 0, false), new Tuple <string, string, int, bool>("y", "Float", 0, false), }; Debug.Listeners.Remove(Program.ListenerConsole); Debug.Listeners.Remove(Program.ListenerLog); Debug.Listeners.Add(new TextWriterTraceListener(new System.IO.StreamWriter("table.ct", false).BaseStream, "CheatTable")); BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly; int i = 0; Debug.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); Debug.WriteLine("<CheatTable CheatEngineTableVersion=\"28\">"); Debug.Indent(); Debug.WriteLine("<CheatEntries>"); Debug.Indent(); Debug.WriteLine("<CheatEntry>"); Debug.Indent(); Debug.WriteLine("<ID>" + i + "</ID>"); i++; Debug.WriteLine("<Description>\"" + DateTime.Now + "\"</Description>"); Debug.WriteLine("<Options moHideChildren=\"1\" moAllowManualCollapseAndExpand=\"1\"/>"); Debug.WriteLine("<LastState Value=\"\" Activated=\"1\" RealAddress=\"00000000\"/>"); Debug.WriteLine("<GroupHeader>1</GroupHeader>"); Debug.WriteLine("<CheatEntries>"); foreach (FieldInfo prop in typeof(Adresses).GetFields(flags)) { Tuple <string, string, int, bool> selected = info.FirstOrDefault(x => x.Item1 == prop.Name); if (selected == null) { selected = new Tuple <string, string, int, bool>(prop.Name, "4 Bytes", 0, false); } Debug.WriteLine("<CheatEntry>"); Debug.Indent(); Debug.WriteLine("<ID>" + i + "</ID>"); Debug.WriteLine("<Description>\"" + prop.Name + "\"</Description>"); Debug.WriteLine("<VariableType>" + selected.Item2 + "</VariableType>"); if (selected.Item4 && selected.Item1 != "String") { Debug.WriteLine("<ShowAsHex>1</ShowAsHex>"); } if (selected.Item2 == "Array of byte") { Debug.WriteLine("<ByteLength>" + selected.Item3 + "</ByteLength>"); } if (selected.Item2 == "String") { Debug.WriteLine("<Length>" + selected.Item3 + "</Length>"); Debug.WriteLine("<Unicode>0</Unicode>"); Debug.WriteLine("<CodePage>0</CodePage>"); Debug.WriteLine("<ZeroTerminate>1</ZeroTerminate>"); } Debug.WriteLine("<Address>" + ((int)prop.GetValue(a)).ToString("X4") + "</Address>"); Debug.Unindent(); Debug.WriteLine("</CheatEntry>"); i++; } Debug.Unindent(); Debug.WriteLine("</CheatEntries>"); Debug.Unindent(); Debug.WriteLine("</CheatEntry>"); Debug.Unindent(); Debug.WriteLine("</CheatEntries>"); Debug.WriteLine("<UserdefinedSymbols/>"); Debug.Unindent(); Debug.WriteLine("</CheatTable>"); Debug.Flush(); Debug.Listeners.Remove("CheatTable"); Debug.Listeners.Add(Program.ListenerConsole); Debug.Listeners.Add(Program.ListenerLog); string s = Path.GetFullPath(@"table.ct"); string t = Path.GetFullPath(@"..\..\..\table.ct"); try { System.IO.File.Copy(s, t, true); } catch (Exception) { } #endif }
/// <summary> /// This adds ioIndex to one of finalLinks /// </summary> /// <param name="closestBrainIndex">Index of the brain that is closest to the IO. There is no extra burden for linking to this one</param> /// <param name="brainBrainBurdens"> /// Item1=Index of other brain /// Item2=Link resistance (burden) between closestBrainIndex and this brain /// </param> private static void AddIOLink(BrainBurden[] finalLinks, int ioIndex, double ioSize, int closestBrainIndex, Tuple<int, double>[] brainBrainBurdens) { // Figure out the cost of adding the link to the various brains Tuple<int, double>[] burdens = new Tuple<int, double>[finalLinks.Length]; for (int cntr = 0; cntr < finalLinks.Length; cntr++) { int brainIndex = finalLinks[cntr].Index; // this is likely always the same as cntr, but since that object has brainIndex as a property, I feel safer using it // Adding to the closest brain has no exta cost. Adding to any other brain has a cost based on the // distance between the closest brain and that other brain double linkCost = 0d; if (brainIndex != closestBrainIndex) { //TODO: Link every brain to every other brain, then get rid of this if statement var matchingBrain = brainBrainBurdens.FirstOrDefault(o => o.Item1 == brainIndex); if (matchingBrain == null) { continue; } linkCost = matchingBrain.Item2; } // LinkCost + IOStorageCost burdens[cntr] = Tuple.Create(cntr, linkCost + BrainBurden.CalculateBurden(finalLinks[cntr].IOSize + ioSize, finalLinks[cntr].Size)); } int cheapestIndex = burdens. Where(o => o != null). OrderBy(o => o.Item2).First().Item1; finalLinks[cheapestIndex].AddIOLink(ioIndex); }
private AsteroidOrMineralDefinition[] DetermineDestroyedChildrenMinerals(HullVoronoiExploder_Response shards, double overDamage, Vector3D parentRadius, double minChildRadius, Func<double, ITriangleIndexed[], double> getMassByRadius, Func<double, MineralDNA[]> getMineralsByDestroyedMass) { const double MAXOVERDMG = 13; // overdamage of 1 is the smallest value (the asteroid was barely destroyed). Larger values are overkill, and the asteroid becomes more fully destroyed if (shards == null || shards.Shards == null || shards.Shards.Length == 0) { // There was problem, so just pop out some minerals return DetermineDestroyedChildrenMinerals_Minerals(parentRadius, getMassByRadius, getMineralsByDestroyedMass); } Random rand = StaticRandom.GetRandomForThread(); #region calculate volumes var shardVolumes = shards.Shards. Select(o => { Vector3D radius = GetEllipsoidRadius(o.Hull_Centered); return new { Radius = radius, Volume = GetEllipsoidVolume(radius) }; }). ToArray(); // Figure out how much volume should permanently be destroyed double parentVolume = GetEllipsoidVolume(parentRadius); double volumeToDestroy = GetVolumeToDestroy(parentVolume, overDamage, MAXOVERDMG); #endregion double destroyedVolume = 0; bool[] shouldSelfDestruct = new bool[shards.Shards.Length]; #region detect too small // Get rid of any that are too small //TODO: Also get rid of any that are too thin for (int cntr = 0; cntr < shards.Shards.Length; cntr++) { if (shards.Shards[cntr].Radius < minChildRadius) { shouldSelfDestruct[cntr] = true; destroyedVolume += shardVolumes[cntr].Volume; } } #endregion if (destroyedVolume < volumeToDestroy) { #region remove more // Find the shards that could be removed var candidates = Enumerable.Range(0, shards.Shards.Length). Select(o => new { Index = o, Shard = shards.Shards[o], Volume = shardVolumes[o] }). Where(o => !shouldSelfDestruct[o.Index] && o.Volume.Volume < volumeToDestroy - destroyedVolume). OrderBy(o => o.Volume.Volume). ToList(); while (candidates.Count > 0 && destroyedVolume < volumeToDestroy) { // Figure out which to self destruct (the rand power will favor inicies closer to zero) int index = UtilityCore.GetIndexIntoList(rand.NextPow(2), candidates.Count); // Remove it shouldSelfDestruct[candidates[index].Index] = true; destroyedVolume += candidates[index].Volume.Volume; candidates.RemoveAt(index); // Remove the items at the end that are now too large index = candidates.Count - 1; while (index >= 0) { if (candidates[index].Volume.Volume < volumeToDestroy - destroyedVolume) { break; // it's sorted, so the rest will also be under } else { candidates.RemoveAt(index); index--; } } } #endregion } #region distribute minerals // Figure out the mineral value of the destroyed volume MineralDNA[] mineralDefinitions = null; if (destroyedVolume > 0 && getMineralsByDestroyedMass != null) { double inferredRadius = GetEllipsoidRadius(destroyedVolume); double destroyedMass = getMassByRadius(inferredRadius, null); if (destroyedMass > 0) { mineralDefinitions = getMineralsByDestroyedMass(destroyedMass); } } // Figure out which of the temp asteroids should contain minerals var packedMinerals = new Tuple<int, MineralDNA[]>[0]; if (mineralDefinitions != null && mineralDefinitions.Length > 0) { int[] destroyedIndicies = Enumerable.Range(0, shouldSelfDestruct.Length). Where(o => shouldSelfDestruct[o]). ToArray(); packedMinerals = DistributeMinerals(mineralDefinitions, destroyedIndicies); } #endregion #region final array AsteroidOrMineralDefinition[] retVal = new AsteroidOrMineralDefinition[shards.Shards.Length]; for (int cntr = 0; cntr < retVal.Length; cntr++) { Vector3D velocity = new Vector3D(0, 0, 0); if (shards.Velocities != null && shards.Velocities.Length == shards.Shards.Length) { velocity = shards.Velocities[cntr]; } //NOTE: Only position is needed (The first attempt created random asteroids and pulled them apart. This second attempt //doesn't need to pull them apart) PartSeparator_Part part = new PartSeparator_Part(new[] { new Point3D() }, 0, shards.Shards[cntr].Center_ParentCoords, Quaternion.Identity); //MineralDNA[] mineralsAfter = packedMinerals?.FirstOrDefault(o => o.Item1 == cntr)?.Item2; MineralDNA[] mineralsAfter = null; if (packedMinerals != null) { var found = packedMinerals.FirstOrDefault(o => o.Item1 == cntr); if (found != null) { mineralsAfter = found.Item2; } } retVal[cntr] = new AsteroidOrMineralDefinition(part, shards.Shards[cntr].Hull_Centered, shards.Shards[cntr].Radius, velocity, shouldSelfDestruct[cntr], mineralsAfter); } #endregion return retVal; }
private void DrawApiDetailGUI() { var info = contents.FirstOrDefault(x => x.Id == selectionId); using (new ContentsScope()) { using (new EditorGUILayout.VerticalScope()) { if (info != null) { var tabData = new Tuple <string, string>[] { Tuple.Create("Result", info.Result), Tuple.Create("Exception", info.Exception.ToString()), Tuple.Create("StackTrace", info.StackTrace), Tuple.Create("Header", info.Headers), Tuple.Create("UriParam", info.UriParams), Tuple.Create("Body", info.Body), }; var tabs = new List <string>(); foreach (var data in tabData) { if (data.Item2.IsNullOrEmpty()) { continue; } tabs.Add(data.Item1); } var tabToggles = tabs.Where(x => !x.IsNullOrEmpty()).ToArray(); using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar)) { EditorGUI.BeginChangeCheck(); detailTabIndex = GUILayout.Toolbar(detailTabIndex, tabToggles, new GUIStyle(EditorStyles.toolbarButton), GUI.ToolbarButtonSize.FitToContents); if (EditorGUI.EndChangeCheck()) { EditorGUI.FocusTextInControl(string.Empty); } } var tabName = tabToggles.ElementAtOrDefault(detailTabIndex); var selectionTab = tabData.FirstOrDefault(x => x.Item1 == tabName); using (var scrollView = new EditorGUILayout.ScrollViewScope(detailScrollPosition)) { var vector = detailStyle.CalcSize(new GUIContent(selectionTab.Item2)); var layoutOption = new GUILayoutOption[] { GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(true), GUILayout.MinWidth(vector.x), GUILayout.MinHeight(vector.y) }; EditorGUILayout.SelectableLabel(selectionTab.Item2, detailStyle, layoutOption); detailScrollPosition = scrollView.scrollPosition; } } } } }
/// <summary> /// This adds ioIndex to one of finalLinks /// </summary> /// <param name="closestBrainIndex">Index of the brain that is closest to the IO. There is no extra burden for linking to this one</param> /// <param name="brainBrainBurdens"> /// Item1=Index of other brain /// Item2=Link resistance (burden) between closestBrainIndex and this brain /// </param> private static void AddIOLink(BrainBurden[] finalLinks, int ioIndex, double ioSize, int closestBrainIndex, Tuple<int, double>[] brainBrainBurdens) { // Figure out the cost of adding the link to the various brains List<Tuple<int, double>> burdens = new List<Tuple<int, double>>(); for (int cntr = 0; cntr < finalLinks.Length; cntr++) { if (finalLinks[cntr].IOLinks.Contains(ioIndex)) { // This only happens when extra links are requested continue; } int brainIndex = finalLinks[cntr].Index; // this is likely always the same as cntr, but since that object has brainIndex as a property, I feel safer using it // Adding to the closest brain has no exta cost. Adding to any other brain has a cost based on the // distance between the closest brain and that other brain double linkCost = 0d; if (brainIndex != closestBrainIndex) { var matchingBrain = brainBrainBurdens.FirstOrDefault(o => o.Item1 == brainIndex); if (matchingBrain == null) { //NOTE: All brain-brain distances should be passed in, so this should never happen continue; } linkCost = matchingBrain.Item2; } // LinkCost + IOStorageCost burdens.Add(Tuple.Create(cntr, linkCost + BrainBurden.CalculateBurden(finalLinks[cntr].IOSize + ioSize, finalLinks[cntr].Size))); } if (burdens.Count == 0) { // This io has already been added to all brains return; } int cheapestIndex = burdens. OrderBy(o => o.Item2).First().Item1; finalLinks[cheapestIndex].AddIOLink(ioIndex); }