private static void BuildForSingleHandler(MiddlewareBuilderContext context) { // We only have a single handler, return the result of that var allHandlers = context.Descriptor.Handlers; var handler = allHandlers.Single(); var apmFrame = ActivityFrame.Start(ActivityKind.Internal, handler.HandlerType.NameInCode()); context.AppendFrames(apmFrame); var returnVariable = handler.Build(context, ExecutorReturnType.Return); if (returnVariable == null && context.Descriptor.RequiresReturnValue) { throw new InvalidOperationException( $@"Unable to build an executor for the operation {context.Descriptor} because the single handler registered, {handler}, did not return a variable but the operation has {nameof(context.Descriptor.RequiresReturnValue)} set to true. This can happen if an the only registered handler for an operation is one that is NOT of the same type (for example a handler IApiOperationHandler<ConcreteClass> for the operation IOperationInterface) where it cannot be guaranteed that the handler will be executed."); } if (returnVariable != null) { returnVariable.OverrideName("handlerResult"); context.AppendFrames(new OperationResultCastFrame(returnVariable)); } context.AppendFrames(apmFrame.Complete()); }
private void SiteBtn_Click(object sender, RoutedEventArgs e) { if (designation == "Owner") { ActivityFrame.Navigate(new Uri("View/Support.xaml", UriKind.Relative)); } else { MessageBox.Show("You are not authorized to access this section."); } }
public Parameters GenerateParameters(CodeFileCSharp input, Settings pluginSettings, IMetadataReader metadataReader, ILogger logger, IFileGroup <CodeFileCSharp, GroupItemDetails> fileGroup = null) { var cSharpFile = input as CodeFileCSharp; var propertyAdderActivity = new ActivityFrame(pluginId: AddPropertyPlugin.Plugin.PluginId); NodeRecord record; return(new Parameters() { PropertiesToDecorate = cSharpFile .SyntaxTree .GetRoot() .DescendantNodes() .OfType <PropertyDeclarationSyntax>() .Where(d => metadataReader.NodeIsGeneratedBy(cSharpFile.NodePathService.GetNodePath(d), propertyAdderActivity, out record)) }); }
private bool saveActivityToDB(List <ActivityDataFragment> activities) { Debug.WriteLine("[SyncData] Guardando fragmentos en BD. numero: " + activities.Count); List <ActivityFrame> frames = new List <ActivityFrame>(); foreach (var fragment in activities) { foreach (var data in fragment.Data) { // FIXME los ceros los guardo para saber cuando tengo un dia completo (1440) //if (data.Mode != (byte)ActivityCategory.Idle && data.Mode != (byte)ActivityCategory.NoData) { ActivityFrame frame = new ActivityFrame(data.Moment, data.Intensity, data.Steps, data.Mode, data.Runs); frames.Add(frame); } } } int ret = DB.AddActivityFrames(frames); Debug.WriteLine("[SyncData] Fragmento guardados en BD. numero: " + ret); return(true); }
private static void BuildForMultipleHandlers(MiddlewareBuilderContext context) { if (context.Descriptor.RequiresReturnValue) { throw new InvalidOperationException( $@"Unable to build an executor for the operation {context.Descriptor} because multiple handlers have been registered but the operation has {nameof(context.Descriptor.RequiresReturnValue)} set to true. When {nameof(context.Descriptor.RequiresReturnValue)} is true multiple handlers cannot be used as there is not one, obvious, return value that could be used. Handlers found: - {string.Join("\n - ", context.Descriptor.Handlers)} "); } foreach (var handler in context.Descriptor.Handlers) { var apmFrame = ActivityFrame.Start(ActivityKind.Internal, handler.HandlerType.NameInCode()); context.AppendFrames(apmFrame); handler.Build(context, ExecutorReturnType.NoReturn); context.AppendFrames(apmFrame.Complete()); } }
private void HomeBtn_Click(object sender, RoutedEventArgs e) { ActivityFrame.Navigate(new Uri("View/HomeIntro.xaml", UriKind.Relative)); }
private void ExpendituresButton_Click(object sender, RoutedEventArgs e) { ActivityFrame.Navigate(new Uri("View/ExpendituresPage.xaml", UriKind.Relative)); }
private void ManageStuffBtn_Click(object sender, RoutedEventArgs e) { ActivityFrame.Navigate(new Uri("View/ManageStuffPage.xaml", UriKind.Relative)); }
private void SaleCarBtn_Click(object sender, RoutedEventArgs e) { ActivityFrame.Navigate(new Uri("View/SalesPage.xaml", UriKind.Relative)); }
private void Init() { ActivityFrame.Navigate(new Uri("View/HomeIntro.xaml", UriKind.Relative)); }
private bool processSleep(DateTime date, bool force) { // comprobamos primero que este dia no este ya analizado var periodAlready = DB.GetSleepPeriods(date, date.AddHours(23).AddMinutes(59).AddSeconds(59)).FirstOrDefault(); if (periodAlready != null) { Debug.WriteLine("[ProcessSleep] el dia " + date.ToString() + " ya tiene un periodo"); return(true); } // cogemos los frames de ayer y hoy List <ActivityFrame> frames = DB.GetActivityFrames(date.AddDays(-1), date.AddHours(23).AddMinutes(59).AddSeconds(59)); // buscamos un grupo de 3 tras un grupo de 4 o 5 var framesToSearch = frames.Where(f => f.Mode != (byte)ActivityCategory.Idle && f.Mode != (byte)ActivityCategory.NoData); ActivityFrame startFrame = null; ActivityFrame endFrame = null; // recorremos todos los frames en busca del 3->4/5 y 4/5->3 // si por casualidad hay dos sueños en este bloque solo coge el segundo for (int i = 0; i < framesToSearch.Count() - 1; i++) { var f = framesToSearch.ElementAt(i); if (f.Mode == (byte)ActivityCategory.Awake) { var f2 = framesToSearch.ElementAt(i + 1); if ((f2.Mode == (byte)ActivityCategory.SleepWithMovement) || (f2.Mode == (byte)ActivityCategory.SleepWithoutMovement)) { startFrame = f; // una vez localizado el ultimo 3 del inicio retrocedemos hasta dar con el primero int j = i; while (true) { if (j == 0) { break; } var f3 = framesToSearch.ElementAt(j); if (f3.Mode == (byte)ActivityCategory.Awake) { startFrame = f3; } else { break; } j--; } } } if (f.Mode == (byte)ActivityCategory.SleepWithMovement || f.Mode == (byte)ActivityCategory.SleepWithoutMovement) { var f2 = framesToSearch.ElementAt(i + 1); if (f2.Mode == (byte)ActivityCategory.Awake) { endFrame = f2; // una vez localizado el primer 3 del final avanzamos hasta dar con el ultimo int j = i; while (true) { if (j == (framesToSearch.Count() - 1)) { break; } var f3 = framesToSearch.ElementAt(j); if (f3.Mode == (byte)ActivityCategory.Awake) { startFrame = f3; } else { break; } j++; } } } } if (startFrame == null || endFrame == null) { // FIXME a lo mejor hay veces que los 3 no existen y tendria que buscar por 4s o 5s y ya despues buscar 3s para completar Debug.WriteLine("[ProcessSleep] " + date.ToString() + " el frame de inicio o de final no existen, no hay datos de sueño validos"); return(false); } // una vez tenemos el inicio y el fin, procedemos a generar los bloques // FIXME por ahora lo hago tal cual estan los minutos, ya lo mejorare despues var sleeps = frames.Where(f => f.Mode == (byte)ActivityCategory.SleepWithMovement || f.Mode == (byte)ActivityCategory.SleepWithoutMovement) .Where(f => (f.TimeStamp > startFrame.TimeStamp) && (f.TimeStamp < endFrame.TimeStamp)); if (sleeps.Count() > 0) { // iteramos por cada frame, metiendo en una misma lista los que son del mismo tipo, para luego generar los periodos List <List <ActivityFrame> > sleepBlocks = new List <List <ActivityFrame> >(); List <ActivityFrame> currentBlock = new List <ActivityFrame>(); // FIXME tener en cuenta los AWAKE for (int i = 0; i < sleeps.Count(); i++) { // frame actual var current = sleeps.ElementAt(i); // si no hay frames en la lista if (currentBlock.Count == 0) { // lo añadimos directamente currentBlock.Add(current); continue; } // si la lista ya tiene frames vemos que sea del mismo tipo que el primero if (current.Mode == currentBlock.First().Mode) { // si lo es lo guardamos currentBlock.Add(current); continue; } // si es de diferente tipo guardamos la lista sleepBlocks.Add(currentBlock); // y creamos otra currentBlock = new List <ActivityFrame>(); // retrocedemos el indice para que en la siguiente vuelta coja el mismo frame i--; } // guardamos el ultimo bloque if (currentBlock.Count() > 0) { sleepBlocks.Add(currentBlock); } // ahora que tenemos los bloques los transformamos a clases especificas para guardar en la BD List <Sleep.LightSleepBlock> lightSleeps = new List <Sleep.LightSleepBlock>(); List <Sleep.DeepSleepBlock> deepSleeps = new List <Sleep.DeepSleepBlock>(); foreach (var block in sleepBlocks) { ActivityCategory mode = (ActivityCategory)block.First().Mode; DateTime start = block.Min(f => f.TimeStamp); DateTime end = block.Max(f => f.TimeStamp); if (mode == ActivityCategory.SleepWithMovement) { Sleep.LightSleepBlock section = new Sleep.LightSleepBlock(start, end); lightSleeps.Add(section); } if (mode == ActivityCategory.SleepWithoutMovement) { Sleep.DeepSleepBlock section = new Sleep.DeepSleepBlock(start, end); deepSleeps.Add(section); } } // una vez transformados creamos el periodo Sleep.SleepPeriod period = new Sleep.SleepPeriod(lightSleeps, deepSleeps); // FIXME por ahora le asigno awakeat inicial, el final ya vere como lo pongo period.AwakeAt = startFrame.TimeStamp; // y lo guardamos en la base de datos DB.AddSleepPeriod(period); // guardamos los bloques del periodo por separado (FIXME seguro?) DB.AddSleepBlocks(period.RetrieveBlocks()); return(true); } return(false); }
private void Generate( BlueprintApiOptions options, IServiceProvider serviceProvider, GeneratedMethod executeMethod, ApiOperationDescriptor operation, ApiDataModel model, IServiceScope serviceScope, bool isNested) { var operationContextVariable = executeMethod.Arguments[0]; var instanceFrameProvider = serviceProvider.GetRequiredService <InstanceFrameProvider>(); var dependencyInjectionVariableSource = new DependencyInjectionVariableSource(executeMethod, instanceFrameProvider); var castFrame = new ConcreteOperationCastFrame(operationContextVariable, operation.OperationType); var apiOperationContextSource = new ApiOperationContextVariableSource(operationContextVariable, castFrame.CastOperationVariable); var context = new MiddlewareBuilderContext( executeMethod, operation, model, serviceScope.ServiceProvider, instanceFrameProvider, isNested); // For the base Exception type we will add, as the first step, logging to the exception sinks. This frame DOES NOT // include a return frame, as we add that after all the other middleware builders have had chance to potentially add // more frames to perform other operations on unknown Exception context.RegisterUnhandledExceptionHandler(typeof(Exception), e => new Frame[] { // Exceptions do not escape from a pipeline because we always convert to a result type new PushExceptionToActivityFrame(e, false), }); executeMethod.Sources.Add(apiOperationContextSource); executeMethod.Sources.Add(dependencyInjectionVariableSource); foreach (var source in options.GenerationRules.VariableSources) { executeMethod.Sources.Add(source); } var startActivityFrame = ActivityFrame.Start(ActivityKind.Internal, operation.Name + (isNested ? "NestedPipeline" : "Pipeline")); executeMethod.Frames.Add(startActivityFrame); executeMethod.Frames.Add(castFrame); executeMethod.Frames.Add(new ErrorHandlerFrame(context)); executeMethod.Frames.Add(new BlankLineFrame()); foreach (var behaviour in this._builders) { if (isNested && !behaviour.SupportsNestedExecution) { continue; } if (behaviour.Matches(operation)) { executeMethod.Frames.Add(new CommentFrame(behaviour.GetType().Name)); behaviour.Build(context); executeMethod.Frames.Add(new BlankLineFrame()); } } // For the base Exception type we will add, as a last frame, a return of an OperationResult. context.RegisterUnhandledExceptionHandler(typeof(Exception), e => new[] { new ReturnFrame(new Variable(typeof(UnhandledExceptionOperationResult), $"new {typeof(UnhandledExceptionOperationResult).FullNameInCode()}({e})")), }); }