public JumpToWindowViewModel(Tuple<int,int[]>[] threads) { CloseWindowCommand=new Command(CloseWindow,()=>SelectedThread!=null); this.threads=threads; SelectedThread=threads.First(); SelectedResNumber=SelectedThread.Item2.First(); }
public void FirstOnThreeTuple() { const int expected = 42; var t = new Tuple<int, int, int>(42, 1, 1); int actual = t.First(); Assert.AreEqual(expected, actual); }
public static string AsString(Tuple<string, object>[] keyValues) { return keyValues.Count() == 1 ? keyValues.First().Item2 as string : keyValues.Select(k => string.Format("{0}='{1}'", k.Item1, k.Item2)) .Aggregate((c, n) => c + "," + n); }
public void FirstOnOneTuple() { const int expected = 42; var t = new Tuple <int>(42); int actual = t.First(); Assert.AreEqual(expected, actual); }
public bool IsStatusTypeChangeValid(StatusRecord changedRecord, ModelStateDictionary modelState) { if (changedRecord == null) { throw new ArgumentNullException("changedRecord"); } if (modelState == null) { throw new ArgumentNullException("modelState"); } var statusRecords = this.statusRepository.Table.Where(c => c.Deleted == false).ToList(); var statusNames = new Tuple <int, string>[] { new Tuple <int, string>(StatusRecord.NewStatus, "New"), new Tuple <int, string>(StatusRecord.OpenStatus, "In Progress"), new Tuple <int, string>(StatusRecord.DeferredStatus, "Deferred"), new Tuple <int, string>(StatusRecord.PendingInputStatus, "Pending input"), new Tuple <int, string>(StatusRecord.ClosedStatus, "Completed") }; var oldRecord = statusRecords.FirstOrDefault(c => c.Id == changedRecord.Id); if (oldRecord != null) { statusRecords.Remove(oldRecord); } statusRecords.Add(changedRecord); var statusTypes = new[] { StatusRecord.NewStatus, StatusRecord.OpenStatus, StatusRecord.DeferredStatus, StatusRecord.PendingInputStatus, StatusRecord.ClosedStatus }; foreach (var statusType in statusTypes) { var recordsWithThisStatusType = statusRecords.Where(c => c.StatusTypeId == statusType).ToList(); if (recordsWithThisStatusType.Count > 1) { modelState.AddModelError("StatusTypeId", "It is not allowed to have two status with the same StatusType"); return(false); } if (recordsWithThisStatusType.Count == 0) { var statusName = statusNames.First(c => c.Item1 == statusType).Item2; modelState.AddModelError("StatusTypeId", "It is not allowed to remove a basic StatusType:" + statusName); return(false); } } return(true); }
private static bool IsStupidBrowser(Tuple<string, decimal>[] current, NancyContext context) { // If there's one or less accept headers then we can't be a stupid // browser so just bail out early if (current.Length <= 1) { return false; } var maxScore = current.First().Item2; if (IsPotentiallyBrokenBrowser(context.Request.Headers.UserAgent) && !current.Any(h => h.Item2 == maxScore && string.Equals(HtmlContentType, h.Item1, StringComparison.OrdinalIgnoreCase))) { return true; } return false; }
public void Setup() { //TODO: this became an integration test - proper ProjectionCoreService and ProjectionManager testing is required as well _bus.Subscribe(_consumer); _processingQueues = GivenProcessingQueues(); var queues = _processingQueues.ToDictionary(v => v.Item5, v => (IPublisher)v.Item1); _managerMessageDispatcher = new ProjectionManagerMessageDispatcher(queues); _manager = new ProjectionManager( GetInputQueue(), GetInputQueue(), queues, _timeProvider, ProjectionType.All, _ioDispatcher, _initializeSystemProjections); _coordinator = new ProjectionCoreCoordinator( ProjectionType.All, ProjectionCoreWorkersNode.CreateTimeoutSchedulers(queues.Count), queues.Values.ToArray(), _bus, Envelope); _bus.Subscribe<ProjectionManagementMessage.Internal.CleanupExpired>(_manager); _bus.Subscribe<ProjectionManagementMessage.Internal.Deleted>(_manager); _bus.Subscribe<CoreProjectionStatusMessage.Started>(_manager); _bus.Subscribe<CoreProjectionStatusMessage.Stopped>(_manager); _bus.Subscribe<CoreProjectionStatusMessage.Prepared>(_manager); _bus.Subscribe<CoreProjectionStatusMessage.Faulted>(_manager); _bus.Subscribe<CoreProjectionStatusMessage.StateReport>(_manager); _bus.Subscribe<CoreProjectionStatusMessage.ResultReport>(_manager); _bus.Subscribe<CoreProjectionStatusMessage.StatisticsReport>(_manager); _bus.Subscribe<CoreProjectionManagementMessage.SlaveProjectionReaderAssigned>(_manager); _bus.Subscribe<CoreProjectionStatusMessage.ProjectionWorkerStarted>(_manager); _bus.Subscribe<ProjectionManagementMessage.Command.Post>(_manager); _bus.Subscribe<ProjectionManagementMessage.Command.UpdateQuery>(_manager); _bus.Subscribe<ProjectionManagementMessage.Command.GetQuery>(_manager); _bus.Subscribe<ProjectionManagementMessage.Command.Delete>(_manager); _bus.Subscribe<ProjectionManagementMessage.Command.GetStatistics>(_manager); _bus.Subscribe<ProjectionManagementMessage.Command.GetState>(_manager); _bus.Subscribe<ProjectionManagementMessage.Command.GetResult>(_manager); _bus.Subscribe<ProjectionManagementMessage.Command.Disable>(_manager); _bus.Subscribe<ProjectionManagementMessage.Command.Enable>(_manager); _bus.Subscribe<ProjectionManagementMessage.Command.Abort>(_manager); _bus.Subscribe<ProjectionManagementMessage.Command.SetRunAs>(_manager); _bus.Subscribe<ProjectionManagementMessage.Command.Reset>(_manager); _bus.Subscribe<ProjectionManagementMessage.Command.StartSlaveProjections>(_manager); _bus.Subscribe<ClientMessage.WriteEventsCompleted>(_manager); _bus.Subscribe<ClientMessage.ReadStreamEventsBackwardCompleted>(_manager); _bus.Subscribe<ClientMessage.DeleteStreamCompleted>(_manager); _bus.Subscribe<SystemMessage.StateChangeMessage>(_manager); _bus.Subscribe<SystemMessage.SystemCoreReady>(_manager); _bus.Subscribe<ProjectionManagementMessage.ReaderReady>(_manager); _bus.Subscribe( CallbackSubscriber.Create<ProjectionManagementMessage.Starting>( starting => _queue.Publish(new ProjectionManagementMessage.ReaderReady()))); _bus.Subscribe<SystemMessage.StateChangeMessage>(_coordinator); _bus.Subscribe<SystemMessage.SystemCoreReady>(_coordinator); if (GetInputQueue() != _processingQueues.First().Item2) { _bus.Subscribe<PartitionProcessingResultBase>(_managerMessageDispatcher); _bus.Subscribe<CoreProjectionManagementControlMessage>( _managerMessageDispatcher); _bus.Subscribe<PartitionProcessingResultOutputBase>(_managerMessageDispatcher); _bus.Subscribe<ReaderSubscriptionManagement.SpoolStreamReading>(_managerMessageDispatcher); } foreach(var q in _processingQueues) SetUpCoreServices(q.Item5, q.Item1, q.Item2, q.Item3, q.Item4); //Given(); WhenLoop(); }
private void GenerateSyncCode( Type type, CodeWriter.CodeWriter w, Type[] baseTypes, Tuple<Type, List<Tuple<MethodInfo, Tuple<string, string>>>>[] typeInfos) { // NoReply Interface var baseSynces = baseTypes.Select(t => Utility.GetActorSyncInterfaceName(t)); var baseSyncesInherit = baseSynces.Any() ? string.Join(", ", baseSynces) : "IInterfacedActorSync"; w._($"[AlternativeInterface(typeof({type.GetSymbolDisplay(typeless: true)}))]"); using (w.B($"public interface {Utility.GetActorSyncInterfaceName(type)}{type.GetGenericParameters()} : {baseSyncesInherit}{type.GetGenericConstraintClause()}")) { foreach (var m in typeInfos.First().Item2) { var method = m.Item1; var parameters = method.GetParameters(); var paramStr = string.Join(", ", parameters.Select(p => p.GetParameterDeclaration(true))); var returnType = method.ReturnType.GenericTypeArguments.FirstOrDefault(); var returnTypeLiteral = (returnType != null) ? returnType.GetSymbolDisplay(true) : "void"; w._($"{returnTypeLiteral} {method.Name}{method.GetGenericParameters()}({paramStr}){method.GetGenericConstraintClause()};"); } } }
private void GenerateRefCode( Type type, CodeWriter.CodeWriter w, Type[] baseTypes, Tuple<Type, List<Tuple<MethodInfo, Tuple<string, string>>>>[] typeInfos) { // NoReply Interface var baseNoReplys = baseTypes.Select(t => Utility.GetNoReplyInterfaceName(t)); var baseNoReplysInherit = baseNoReplys.Any() ? " : " + string.Join(", ", baseNoReplys) : ""; using (w.B($"public interface {Utility.GetNoReplyInterfaceName(type)}{type.GetGenericParameters()}{baseNoReplysInherit}{type.GetGenericConstraintClause()}")) { foreach (var m in typeInfos.First().Item2) { var method = m.Item1; var parameters = method.GetParameters(); var paramStr = string.Join(", ", parameters.Select(p => p.GetParameterDeclaration(true))); w._($"void {method.Name}{method.GetGenericParameters()}({paramStr}){method.GetGenericConstraintClause()};"); } } // ActorRef var refClassName = Utility.GetActorRefClassName(type); var refClassGenericName = refClassName + type.GetGenericParameters(); var noReplyInterfaceName = Utility.GetNoReplyInterfaceName(type); var noReplyInterfaceGenericName = noReplyInterfaceName + type.GetGenericParameters(); using (w.B($"public class {refClassName}{type.GetGenericParameters()} : InterfacedActorRef, {type.GetSymbolDisplay()}, {noReplyInterfaceName}{type.GetGenericParameters()}{type.GetGenericConstraintClause()}")) { // InterfaceType property w._($"public override Type InterfaceType => typeof({type.GetSymbolDisplay()});"); w._(); // Constructors using (w.B($"public {refClassName}() : base(null)")) { } using (w.B($"public {refClassName}(IRequestTarget target) : base(target)")) { } using (w.B($"public {refClassName}(IRequestTarget target, IRequestWaiter requestWaiter, TimeSpan? timeout = null) : base(target, requestWaiter, timeout)")) { } // With Helpers using (w.B($"public {noReplyInterfaceGenericName} WithNoReply()")) { w._("return this;"); } using (w.B($"public {refClassGenericName} WithRequestWaiter(IRequestWaiter requestWaiter)")) { w._($"return new {refClassGenericName}(Target, requestWaiter, Timeout);"); } using (w.B($"public {refClassGenericName} WithTimeout(TimeSpan? timeout)")) { w._($"return new {refClassGenericName}(Target, RequestWaiter, timeout);"); } // IInterface message methods foreach (var t in typeInfos) { var payloadTableClassName = Utility.GetPayloadTableClassName(t.Item1) + type.GetGenericParameters(); foreach (var m in t.Item2) { var method = m.Item1; var payloadTypes = m.Item2; var parameters = method.GetParameters(); var parameterTypeNames = string.Join(", ", parameters.Select(p => p.GetParameterDeclaration(true))); var parameterInits = string.Join(", ", parameters.Select(Utility.GetParameterAssignment)); var returnType = method.ReturnType.GenericTypeArguments.FirstOrDefault(); // Request Methods var returnTaskType = (returnType != null) ? $"Task<{returnType.GetSymbolDisplay(true)}>" : "Task"; var prototype = $"public {returnTaskType} {method.Name}{method.GetGenericParameters()}({parameterTypeNames}){method.GetGenericConstraintClause()}"; using (w.B(prototype)) { using (w.i("var requestMessage = new RequestMessage {", "};")) { w._($"InvokePayload = new {payloadTableClassName}.{payloadTypes.Item1}{method.GetGenericParameters()} {{ {parameterInits} }}"); } if (returnType != null) w._($"return SendRequestAndReceive<{returnType.GetSymbolDisplay(true)}>(requestMessage);"); else w._($"return SendRequestAndWait(requestMessage);"); } } } // IInterface_NoReply message methods foreach (var t in typeInfos) { var interfaceName = Utility.GetNoReplyInterfaceName(t.Item1); var interfaceGenericName = interfaceName + t.Item1.GetGenericParameters(); var payloadTableClassName = Utility.GetPayloadTableClassName(t.Item1) + type.GetGenericParameters(); foreach (var m in t.Item2) { var method = m.Item1; var payloadTypes = m.Item2; var parameters = method.GetParameters(); var parameterTypeNames = string.Join(", ", parameters.Select(p => p.GetParameterDeclaration(false))); var parameterInits = string.Join(", ", parameters.Select(Utility.GetParameterAssignment)); // Request Methods using (w.B($"void {interfaceGenericName}.{method.Name}{method.GetGenericParameters()}({parameterTypeNames})")) { using (w.i("var requestMessage = new RequestMessage {", "};")) { w._($"InvokePayload = new {payloadTableClassName}.{payloadTypes.Item1}{method.GetGenericParameters()} {{ {parameterInits} }}"); } w._("SendRequest(requestMessage);"); } } } } // Protobuf-net specialized if (Options.UseProtobuf) { var surrogateClassName = Utility.GetSurrogateClassName(type); w._("[ProtoContract]"); using (w.B($"public class {surrogateClassName}")) { w._($"[ProtoMember(1)] public IRequestTarget Target;"); w._(); w._("[ProtoConverter]"); using (w.B($"public static {surrogateClassName} Convert({type.Name} value)")) { w._($"if (value == null) return null;"); w._($"return new {surrogateClassName} {{ Target = (({refClassName})value).Target }};"); } w._("[ProtoConverter]"); using (w.B($"public static {type.Name} Convert({surrogateClassName} value)")) { w._($"if (value == null) return null;"); w._($"return new {refClassName}(value.Target);"); } } } }
public static Tuple<Tuple<DateTime, RollResultItem>[], Tuple<DateTime, RollResultItem>[]> IntersectDates(Tuple<DateTime, RollResultItem>[] series1, Tuple<DateTime, RollResultItem>[] series2) { var commonDates = series1.Select(s => s.Item1).Concat(series2.Select(s => s.Item1)).Distinct(); var list1 = new List<Tuple<DateTime, RollResultItem>>(); var list2 = new List<Tuple<DateTime, RollResultItem>>(); foreach (var date in commonDates) { if (series1.Any(s => s.Item1 == date)) list1.Add(series1.First(s => s.Item1 == date)); else list1.Add(new Tuple<DateTime, RollResultItem>(date, new RollResultItem(){Value = double.NaN})); if (series2.Any(s => s.Item1 == date)) list2.Add(series2.First(s => s.Item1 == date)); else list2.Add(new Tuple<DateTime, RollResultItem>(date, new RollResultItem() { Value = double.NaN })); } return new Tuple<Tuple<DateTime, RollResultItem>[], Tuple<DateTime, RollResultItem>[]>(list1.ToArray(), list2.ToArray()); }
private static GunAmmoGroup[] GetAmmoGroupings_Assign(IEnumerable<GunGroup> guns, AmmoBox[] boxesDescending, Tuple<long, long, double>[] ammo_gun_distance) { // Build a structure that can be added to var retVal = guns. Select(o => new { Gun = o, Boxes = new List<AmmoBox>() }). ToArray(); for (int cntr = 0; cntr < boxesDescending.Length; cntr++) { double boxVolume = boxesDescending[cntr].QuantityMax; double boxMinDimension = Math1D.Min(boxesDescending[cntr].ScaleActual.X, boxesDescending[cntr].ScaleActual.Y, boxesDescending[cntr].ScaleActual.Z); long boxToken = boxesDescending[cntr].Token; // Find the gun that most needs this box var bestMatch = retVal. Where(o => o.Gun.DemandPerGun <= boxVolume && o.Gun.Caliber <= boxMinDimension). // only look at guns that could use this box Select(o => { var capacityFirings = Get_Capacity_Firings(o.Boxes, o.Gun); // Add up the distance between the box and all the guns in this group double distance = o.Gun.Guns.Sum(p => ammo_gun_distance.First(q => q.Item1 == boxToken && q.Item2 == p.Token).Item3); return new { Item = o, Capacity = capacityFirings.Item1, // the current amount of capacity this gun has Firings = capacityFirings.Item2, // how many shots can be fired based on this capacity Distance = distance, }; }). //TODO: Figure out how to come up with a scoring system that takes distance into account OrderBy(o => o.Firings). // order by guns with the smallest amount of available shots ThenByDescending(o => o.Item.Gun.DemandTotal). // if there's a tie, choose the greediest gun First(); // Give this box to the chosen set of guns bestMatch.Item.Boxes.Add(boxesDescending[cntr]); } return retVal. Select(o => new GunAmmoGroup(o.Gun, o.Boxes.ToArray(), Convert.ToInt32(Math.Floor(Get_Capacity_Firings(o.Boxes, o.Gun).Item2)))). ToArray(); }