protected void ExportMapDescription(PipelineItem inputSetup) { var payload = InitializePayload(); if (payload is IGraphBasedGeneratorPayload graphBasedGeneratorPayload) { var pipelineItems = new List <PipelineItem> { inputSetup }; PipelineRunner.Run(pipelineItems, graphBasedGeneratorPayload); var levelDescription = graphBasedGeneratorPayload.LevelDescription; var mapDescription = levelDescription.GetMapDescription(); var intMapDescription = GetIntMapDescription(mapDescription); var json = JsonConvert.SerializeObject(intMapDescription, Formatting.Indented, new JsonSerializerSettings() { PreserveReferencesHandling = PreserveReferencesHandling.All, TypeNameHandling = TypeNameHandling.Auto, }); var filename = "exportedMapDescription.json"; File.WriteAllText(filename, json); Debug.Log($"Map description exported to {filename}"); } else { throw new InvalidOperationException($"The payload must implement {nameof(IGraphBasedGeneratorPayload)} to export map descriptions"); } }
/// <summary> /// Perform any initialisation tasks /// </summary> /// <param name="pipelines">Application pipelines</param> /// <param name="context">The current context</param> public void Initialize(IPipelines pipelines, NancyContext context) { // On each request, store the NancyContext in the LogicalCallContext CallContext.LogicalSetData(NancyConfiguration.NancyContextDataSlot, context); var nancyConfiguration = NancyConfiguration.Settings; if (nancyConfiguration == null) { return; } var name = nancyConfiguration.PipelineName.Value; var sharpRaven = new PipelineItem(name, (nancyContext, exception) => { if (nancyConfiguration.CaptureExceptionOnError.Value) { var guid = this.ravenClient.CaptureException(exception); if (guid != null) { context.Items.Add(NancyConfiguration.SentryEventGuidKey, guid); exception.Data.Add(NancyConfiguration.SentryEventGuidKey, guid); } } return(null); }); pipelines.OnError.AddItemToStartOfPipeline(sharpRaven); }
private void LogFilteredFiles(PipelineItem skippedFileDescriptor) { var fileWhichExists = _existingFiles[skippedFileDescriptor.Hash]; _logger.LogWarning( $"File {skippedFileDescriptor.Descriptor.FullPath} has been identified as duplicate of {fileWhichExists?.FullPath}"); }
public void Process(PipelineItem item) { PipelineItemStatusResult statusResult; if (item == null) { statusResult = new PipelineItemStatusResult(PipelineItemStatus.Fail, "Pipeline item is null"); } else if (item.Data is IValidatable) { var validatableItem = item.Data as IValidatable; if (validatableItem.IsValid()) { statusResult = new PipelineItemStatusResult(PipelineItemStatus.Success); } else { statusResult = new PipelineItemStatusResult(PipelineItemStatus.Fail, "Pipeline item failed validation"); } } else { statusResult = new PipelineItemStatusResult(PipelineItemStatus.Fail, "Pipeline item's data is not of type IValidatable"); } item.SetStatusResult(statusResult); Result = item; }
private PipelineItem CalculateAndTransform(PipelineItem pipelineItemBase) { using var fileStream = _sourceFileRepoService .GetFilesContentAsStream(pipelineItemBase.Descriptor); pipelineItemBase.Hash = CalculateFileHash(fileStream); return(pipelineItemBase); }
private PipelineItem CheckIfFileAlreadyExistsTransform(PipelineItem pipelineItemBase) { var isNewKey = _existingFiles.TryAdd(pipelineItemBase.Hash, pipelineItemBase.Descriptor); if (!isNewKey) { pipelineItemBase.IsDuplicate = true; } return(pipelineItemBase); }
/// <summary> /// Perform any initialisation tasks /// </summary> public void Initialize(IPipelines pipelines) { var item = new PipelineItem<Func<NancyContext, Response>>("Static content", ctx => { return conventions .Select(convention => convention.Invoke(ctx, rootPathProvider.GetRootPath())) .FirstOrDefault(response => response != null); }); pipelines.BeforeRequest.AddItemToStartOfPipeline(item); }
public void Should_be_able_to_add_to_end_of_pipeline() { var item1 = new PipelineItem <Action <string> >("item1", s => { }); var item2 = new PipelineItem <Action <string> >("item2", s => { }); pipeline.AddItemToEndOfPipeline(item2); pipeline.AddItemToEndOfPipeline(item1); Assert.Equal(2, pipeline.Items.Count()); Assert.Same(item1, pipeline.Items.Last()); }
public void Initialize(IPipelines pipelines) { if (Client == null) return; var raygunItem = new PipelineItem<Func<NancyContext, Exception, Response>>("Raygun", (context, exception) => { Client.SendInBackground(context, exception); return null; }); pipelines.OnError.AddItemToStartOfPipeline(raygunItem); }
private PipelineItem EnrichPipeLineWithMetadata(PipelineItem pipelineItemBase) { if (_imageMetadataProviderService.IsSupportedImageFormat(pipelineItemBase.Descriptor.Ext)) { using var fileStream = _sourceFileRepoService.GetFilesContentAsStream(pipelineItemBase.Descriptor); pipelineItemBase.ImageMetaData = _imageMetadataProviderService.ExtractImageMetadata(fileStream); pipelineItemBase.FilePathMetadataInfo = _filePathMetadataExtractService.ExtractFilePathMetadata( pipelineItemBase.Descriptor.FullPath, pipelineItemBase.BaseDirPath); } return(pipelineItemBase); }
public void Should_be_able_to_remove_a_named_item() { var item1 = new PipelineItem <Action <string> >("item1", s => { }); var item2 = new PipelineItem <Action <string> >("item2", s => { }); pipeline.AddItemToEndOfPipeline(item1); pipeline.AddItemToEndOfPipeline(item2); pipeline.RemoveByName("item2"); Assert.Equal(1, pipeline.Items.Count()); Assert.Same(item1, pipeline.Items.First()); }
public void Should_replace_in_place_if_set_when_adding_at_index() { var existingItem = new PipelineItem <Action <string> >("item1", s => { }); var item1 = new PipelineItem <Action <string> >("item1", s => { }); var item2 = new PipelineItem <Action <string> >("item2", s => { }); pipeline.AddItemToEndOfPipeline(item2); pipeline.AddItemToEndOfPipeline(existingItem); pipeline.InsertItemAtPipelineIndex(0, item1, true); Assert.Equal(2, pipeline.Items.Count()); Assert.Same(item1, pipeline.Items.Last()); }
public void Should_remove_item_with_same_name_when_adding_to_end() { var existingItem = new PipelineItem <Action <string> >("item1", s => { }); var item1 = new PipelineItem <Action <string> >("item1", s => { }); var item2 = new PipelineItem <Action <string> >("item2", s => { }); pipeline.AddItemToEndOfPipeline(item2); pipeline.AddItemToEndOfPipeline(existingItem); pipeline.AddItemToEndOfPipeline(item1); Assert.Equal(2, pipeline.Items.Count()); Assert.Same(item1, pipeline.Items.Last()); }
public void Should_be_able_to_insert_after_a_named_item() { var item1 = new PipelineItem <Action <string> >("item1", s => { }); var item2 = new PipelineItem <Action <string> >("item2", s => { }); var item3 = new PipelineItem <Action <string> >("item3", s => { }); pipeline.AddItemToEndOfPipeline(item1); pipeline.AddItemToEndOfPipeline(item3); pipeline.InsertAfter("item1", item2); Assert.Same(item1, pipeline.Items.ElementAt(0)); Assert.Same(item2, pipeline.Items.ElementAt(1)); Assert.Same(item3, pipeline.Items.ElementAt(2)); }
public void Should_add_to_end_if_inserting_after_and_item_doesnt_exist() { var item1 = new PipelineItem <Action <string> >("item1", s => { }); var item2 = new PipelineItem <Action <string> >("item2", s => { }); var item3 = new PipelineItem <Action <string> >("item3", s => { }); pipeline.AddItemToEndOfPipeline(item1); pipeline.AddItemToEndOfPipeline(item3); pipeline.InsertAfter("nonexistant", item2); Assert.Same(item1, pipeline.Items.ElementAt(0)); Assert.Same(item3, pipeline.Items.ElementAt(1)); Assert.Same(item2, pipeline.Items.ElementAt(2)); }
public void Should_be_able_to_add_at_specific_index() { var item1 = new PipelineItem <Action <string> >("item1", s => { }); var item2 = new PipelineItem <Action <string> >("item2", s => { }); var item3 = new PipelineItem <Action <string> >("item3", s => { }); pipeline.AddItemToEndOfPipeline(item1); pipeline.AddItemToEndOfPipeline(item3); pipeline.InsertItemAtPipelineIndex(1, item2); Assert.Same(item1, pipeline.Items.ElementAt(0)); Assert.Same(item2, pipeline.Items.ElementAt(1)); Assert.Same(item3, pipeline.Items.ElementAt(2)); }
public void Initialize(IPipelines pipelines) { if (Client == null) { return; } var raygunItem = new PipelineItem <Func <NancyContext, Exception, dynamic> >("Raygun", (context, exception) => { Client.SendInBackground(context, exception); return(null); }); pipelines.OnError.AddItemToStartOfPipeline(raygunItem); }
/// <summary> /// Enables Csrf token generation. /// This is disabled by default. /// </summary> /// <param name="pipelines">Application pipelines</param> public static void Enable(IPipelines pipelines, CryptographyConfiguration cryptographyConfiguration = null) { cryptographyConfiguration = cryptographyConfiguration ?? CsrfApplicationStartup.CryptographyConfiguration; var postHook = new PipelineItem<Action<NancyContext>>( CsrfHookName, context => { if (context.Response == null || context.Response.Cookies == null || context.Request.Method.Equals("OPTIONS", StringComparison.OrdinalIgnoreCase)) { return; } if (context.Items.ContainsKey(CsrfToken.DEFAULT_CSRF_KEY)) { context.Response.Cookies.Add(new NancyCookie(CsrfToken.DEFAULT_CSRF_KEY, (string)context.Items[CsrfToken.DEFAULT_CSRF_KEY], true)); return; } if (context.Request.Cookies.ContainsKey(CsrfToken.DEFAULT_CSRF_KEY)) { var decodedValue = HttpUtility.UrlDecode(context.Request.Cookies[CsrfToken.DEFAULT_CSRF_KEY]); var cookieToken = CsrfApplicationStartup.ObjectSerializer.Deserialize(decodedValue) as CsrfToken; if (CsrfApplicationStartup.TokenValidator.CookieTokenStillValid(cookieToken)) { context.Items[CsrfToken.DEFAULT_CSRF_KEY] = decodedValue; return; } } var token = new CsrfToken { CreatedDate = DateTime.Now, }; token.CreateRandomBytes(); token.CreateHmac(cryptographyConfiguration.HmacProvider); var tokenString = CsrfApplicationStartup.ObjectSerializer.Serialize(token); context.Items[CsrfToken.DEFAULT_CSRF_KEY] = tokenString; context.Response.Cookies.Add(new NancyCookie(CsrfToken.DEFAULT_CSRF_KEY, tokenString, true)); }); pipelines.AfterRequest.AddItemToEndOfPipeline(postHook); }
/// <summary> /// Enables Csrf token generation. /// This is disabled by default. /// </summary> /// <param name="pipelines">Application pipelines</param> public static void Enable(IPipelines pipelines, CryptographyConfiguration cryptographyConfiguration = null) { cryptographyConfiguration = cryptographyConfiguration ?? CsrfApplicationStartup.CryptographyConfiguration; var postHook = new PipelineItem <Action <NancyContext> >( CsrfHookName, context => { if (context.Response == null || context.Response.Cookies == null || context.Request.Method.Equals("OPTIONS", StringComparison.OrdinalIgnoreCase)) { return; } if (context.Items.ContainsKey(CsrfToken.DEFAULT_CSRF_KEY)) { context.Response.Cookies.Add(new NancyCookie(CsrfToken.DEFAULT_CSRF_KEY, (string)context.Items[CsrfToken.DEFAULT_CSRF_KEY], true)); return; } if (context.Request.Cookies.ContainsKey(CsrfToken.DEFAULT_CSRF_KEY)) { var decodedValue = HttpUtility.UrlDecode(context.Request.Cookies[CsrfToken.DEFAULT_CSRF_KEY]); var cookieToken = CsrfApplicationStartup.ObjectSerializer.Deserialize(decodedValue) as CsrfToken; if (CsrfApplicationStartup.TokenValidator.CookieTokenStillValid(cookieToken)) { context.Items[CsrfToken.DEFAULT_CSRF_KEY] = decodedValue; return; } } var token = new CsrfToken { CreatedDate = DateTime.Now, }; token.CreateRandomBytes(); token.CreateHmac(cryptographyConfiguration.HmacProvider); var tokenString = CsrfApplicationStartup.ObjectSerializer.Serialize(token); context.Items[CsrfToken.DEFAULT_CSRF_KEY] = tokenString; context.Response.Cookies.Add(new NancyCookie(CsrfToken.DEFAULT_CSRF_KEY, tokenString, true)); }); pipelines.AfterRequest.AddItemToEndOfPipeline(postHook); }
public void Should_remove_item_with_same_name_when_adding_at_index() { var existingItem = new PipelineItem <Action <string> >("item2", s => { }); var item1 = new PipelineItem <Action <string> >("item1", s => { }); var item2 = new PipelineItem <Action <string> >("item2", s => { }); var item3 = new PipelineItem <Action <string> >("item3", s => { }); pipeline.AddItemToEndOfPipeline(item1); pipeline.AddItemToEndOfPipeline(item3); pipeline.AddItemToEndOfPipeline(existingItem); pipeline.InsertItemAtPipelineIndex(1, item2); Assert.Same(item1, pipeline.Items.ElementAt(0)); Assert.Same(item2, pipeline.Items.ElementAt(1)); Assert.Same(item3, pipeline.Items.ElementAt(2)); }
/// <summary> /// Enables Csrf token generation. /// </summary> /// <remarks>This is disabled by default.</remarks> /// <param name="pipelines">The application pipelines.</param> /// <param name="cryptographyConfiguration">The cryptography configuration. This is <see langword="null" /> by default.</param> /// <param name="useSecureCookie">Set the CSRF cookie secure flag. This is <see langword="false"/> by default</param> public static void Enable(IPipelines pipelines, CryptographyConfiguration cryptographyConfiguration = null, bool useSecureCookie = false) { cryptographyConfiguration = cryptographyConfiguration ?? CsrfApplicationStartup.CryptographyConfiguration; var postHook = new PipelineItem <Action <NancyContext> >( CsrfHookName, context => { if (context.Response == null || context.Response.Cookies == null || context.Request.Method.Equals("OPTIONS", StringComparison.OrdinalIgnoreCase)) { return; } object value; if (context.Items.TryGetValue(CsrfToken.DEFAULT_CSRF_KEY, out value)) { context.Response.Cookies.Add(new NancyCookie( CsrfToken.DEFAULT_CSRF_KEY, (string)value, true, useSecureCookie)); return; } string cookieValue; if (context.Request.Cookies.TryGetValue(CsrfToken.DEFAULT_CSRF_KEY, out cookieValue)) { var cookieToken = ParseToCsrfToken(cookieValue); if (CsrfApplicationStartup.TokenValidator.CookieTokenStillValid(cookieToken)) { context.Items[CsrfToken.DEFAULT_CSRF_KEY] = cookieValue; return; } } var tokenString = GenerateTokenString(cryptographyConfiguration); context.Items[CsrfToken.DEFAULT_CSRF_KEY] = tokenString; context.Response.Cookies.Add(new NancyCookie(CsrfToken.DEFAULT_CSRF_KEY, tokenString, true, useSecureCookie)); }); pipelines.AfterRequest.AddItemToEndOfPipeline(postHook); }
/// <summary> /// Enables Csrf token generation. /// This is disabled by default. /// </summary> /// <param name="pipelines">Application pipelines</param> public static void Enable(IPipelines pipelines, CryptographyConfiguration cryptographyConfiguration = null) { cryptographyConfiguration = cryptographyConfiguration ?? CsrfApplicationStartup.CryptographyConfiguration; var postHook = new PipelineItem<Action<NancyContext>>( CsrfHookName, context => { if (context.Response == null || context.Response.Cookies == null || context.Request.Method.Equals("OPTIONS", StringComparison.OrdinalIgnoreCase)) { return; } if (context.Items.ContainsKey(CsrfToken.DEFAULT_CSRF_KEY)) { context.Response.Cookies.Add(new NancyCookie(CsrfToken.DEFAULT_CSRF_KEY, (string)context.Items[CsrfToken.DEFAULT_CSRF_KEY], true)); return; } if (context.Request.Cookies.ContainsKey(CsrfToken.DEFAULT_CSRF_KEY)) { var cookieValue = context.Request.Cookies[CsrfToken.DEFAULT_CSRF_KEY]; var cookieToken = CsrfApplicationStartup.ObjectSerializer.Deserialize(cookieValue) as CsrfToken; if (CsrfApplicationStartup.TokenValidator.CookieTokenStillValid(cookieToken)) { context.Items[CsrfToken.DEFAULT_CSRF_KEY] = cookieValue; return; } } var tokenString = GenerateTokenString(cryptographyConfiguration); context.Items[CsrfToken.DEFAULT_CSRF_KEY] = tokenString; context.Response.Cookies.Add(new NancyCookie(CsrfToken.DEFAULT_CSRF_KEY, tokenString, true)); }); pipelines.AfterRequest.AddItemToEndOfPipeline(postHook); }
/// <summary> /// Enables Csrf token generation. /// This is disabled by default. /// </summary> /// <param name="pipelines">Application pipelines</param> public static void Enable(IPipelines pipelines, CryptographyConfiguration cryptographyConfiguration = null) { cryptographyConfiguration = cryptographyConfiguration ?? CsrfApplicationStartup.CryptographyConfiguration; var postHook = new PipelineItem <Action <NancyContext> >( CsrfHookName, context => { if (context.Response == null || context.Response.Cookies == null || context.Request.Method.Equals("OPTIONS", StringComparison.OrdinalIgnoreCase)) { return; } if (context.Items.ContainsKey(CsrfToken.DEFAULT_CSRF_KEY)) { context.Response.Cookies.Add(new NancyCookie(CsrfToken.DEFAULT_CSRF_KEY, (string)context.Items[CsrfToken.DEFAULT_CSRF_KEY], true)); return; } if (context.Request.Cookies.ContainsKey(CsrfToken.DEFAULT_CSRF_KEY)) { var cookieValue = context.Request.Cookies[CsrfToken.DEFAULT_CSRF_KEY]; var cookieToken = CsrfApplicationStartup.ObjectSerializer.Deserialize(cookieValue) as CsrfToken; if (CsrfApplicationStartup.TokenValidator.CookieTokenStillValid(cookieToken)) { context.Items[CsrfToken.DEFAULT_CSRF_KEY] = cookieValue; return; } } var tokenString = GenerateTokenString(cryptographyConfiguration); context.Items[CsrfToken.DEFAULT_CSRF_KEY] = tokenString; context.Response.Cookies.Add(new NancyCookie(CsrfToken.DEFAULT_CSRF_KEY, tokenString, true)); }); pipelines.AfterRequest.AddItemToEndOfPipeline(postHook); }
/// <summary> /// Enables Csrf token generation. /// This is enabled automatically so there should be no reason to call this manually. /// </summary> /// <param name="pipelines">Application pipelines</param> public static void Enable(IPipelines pipelines) { var postHook = new PipelineItem <Action <NancyContext> >( CsrfHookName, context => { if (context.Response == null || context.Response.Cookies == null) { return; } if (context.Items.ContainsKey(CsrfToken.DEFAULT_CSRF_KEY)) { context.Response.Cookies.Add(new NancyCookie(CsrfToken.DEFAULT_CSRF_KEY, (string)context.Items[CsrfToken.DEFAULT_CSRF_KEY], true)); return; } if (context.Request.Cookies.ContainsKey(CsrfToken.DEFAULT_CSRF_KEY)) { context.Items[CsrfToken.DEFAULT_CSRF_KEY] = HttpUtility.UrlDecode(context.Request.Cookies[CsrfToken.DEFAULT_CSRF_KEY]); return; } var token = new CsrfToken { CreatedDate = DateTime.Now, }; token.CreateRandomBytes(); token.CreateHmac(CsrfStartup.CryptographyConfiguration.HmacProvider); var tokenString = CsrfStartup.ObjectSerializer.Serialize(token); context.Items[CsrfToken.DEFAULT_CSRF_KEY] = tokenString; context.Response.Cookies.Add(new NancyCookie(CsrfToken.DEFAULT_CSRF_KEY, tokenString, true)); }); pipelines.AfterRequest.AddItemToEndOfPipeline(postHook); }
static Jsonp() { JsonpItem = new PipelineItem<Action<NancyContext>>("JSONP", PrepareJsonp); }
/// <summary> /// Builds a list of PipelineItems /// </summary> /// <param name="cycle">Zero-based program cycle number</param> /// <param name="instructions">Instructions for pipeline</param> /// <returns></returns> private static List <PipelineItem> BuildPipelineItems(int cycle, List <string> instructions) { var pipelineItems = new List <PipelineItem>(); for (int i = 0; i < instructions.Count; i++) { var instr = instructions[i]; long? inputA = null; long? inputB = null; DevicePort?inputASource = null; DevicePort?inputBSource = null; string outputFormula = null; if (i > 0) { switch (instr ?? "") { case "set0": outputFormula = "0"; break; case "set1": outputFormula = "1"; break; case "seta": inputA = Mux3Model.OutputCalc(Bank.Bank_A, cycle - i + 1).Value; inputASource = DevicePort.Mux_3A; outputFormula = "A"; break; case "setb": inputB = Mux3Model.OutputCalc(Bank.Bank_B, cycle - i + 1).Value; inputBSource = DevicePort.Mux_3B; outputFormula = "B"; break; case "nega": inputA = Mux3Model.OutputCalc(Bank.Bank_A, cycle - i + 1).Value; inputASource = DevicePort.Mux_3A; outputFormula = "-A"; break; case "negb": inputB = Mux3Model.OutputCalc(Bank.Bank_B, cycle - i + 1).Value; inputBSource = DevicePort.Mux_3B; outputFormula = "-B"; break; case "passrama": inputA = DataRamModel.OutputCalc(Bank.Bank_A, cycle - i + 1).Value; inputASource = DevicePort.DataRam_A; outputFormula = "Ram A"; break; case "passramb": inputB = DataRamModel.OutputCalc(Bank.Bank_B, cycle - i + 1).Value; inputBSource = DevicePort.DataRam_B; outputFormula = "Ram B"; break; case "add": inputA = Mux3Model.OutputCalc(Bank.Bank_A, cycle - i + 1).Value; inputASource = DevicePort.Mux_3A; inputB = Mux3Model.OutputCalc(Bank.Bank_B, cycle - i + 1).Value; inputBSource = DevicePort.Mux_3B; outputFormula = "A+B"; break; case "tdeca": inputA = Mux3Model.OutputCalc(Bank.Bank_A, cycle - i + 1).Value; inputASource = DevicePort.Mux_3A; outputFormula = "A-1"; break; case "suba": inputA = Mux3Model.OutputCalc(Bank.Bank_A, cycle - i + 1).Value; inputASource = DevicePort.Mux_3A; inputB = Mux3Model.OutputCalc(Bank.Bank_B, cycle - i + 1).Value; inputBSource = DevicePort.Mux_3B; outputFormula = "B-A"; break; case "subb": inputA = Mux3Model.OutputCalc(Bank.Bank_A, cycle - i + 1).Value; inputASource = DevicePort.Mux_3A; inputB = Mux3Model.OutputCalc(Bank.Bank_B, cycle - i + 1).Value; inputBSource = DevicePort.Mux_3B; outputFormula = "A-B"; break; case "absa": inputA = Mux3Model.OutputCalc(Bank.Bank_A, cycle - i + 1).Value; inputASource = DevicePort.Mux_3A; outputFormula = "abs(A)"; break; case "absb": inputB = Mux3Model.OutputCalc(Bank.Bank_B, cycle - i + 1).Value; inputBSource = DevicePort.Mux_3B; outputFormula = "abs(B)"; break; case "addabsa": inputA = Mux3Model.OutputCalc(Bank.Bank_A, cycle - i + 1).Value; inputASource = DevicePort.Mux_3A; inputB = Mux3Model.OutputCalc(Bank.Bank_B, cycle - i + 1).Value; inputBSource = DevicePort.Mux_3B; outputFormula = "abs(A)+B"; break; case "addabsb": inputA = Mux3Model.OutputCalc(Bank.Bank_A, cycle - i + 1).Value; inputASource = DevicePort.Mux_3A; inputB = Mux3Model.OutputCalc(Bank.Bank_B, cycle - i + 1).Value; inputBSource = DevicePort.Mux_3B; outputFormula = "A+abs(B)"; break; case "hold": outputFormula = "ALU Hold"; break; case "englobals": outputFormula = ""; break; case "ensatrnd": outputFormula = ""; break; case "ensem": outputFormula = ""; break; case "setsem": outputFormula = ""; break; case "clearsem": outputFormula = ""; break; case "tsuba": inputA = Mux3Model.OutputCalc(Bank.Bank_A, cycle - i + 1).Value; inputASource = DevicePort.Mux_3A; inputB = Mux3Model.OutputCalc(Bank.Bank_B, cycle - i + 1).Value; inputBSource = DevicePort.Mux_3B; outputFormula = "B-A thr"; break; case "tsubb": inputA = Mux3Model.OutputCalc(Bank.Bank_A, cycle - i + 1).Value; inputASource = DevicePort.Mux_3A; inputB = Mux3Model.OutputCalc(Bank.Bank_B, cycle - i + 1).Value; inputBSource = DevicePort.Mux_3B; outputFormula = "A-B thr"; break; case "taddabsa": inputA = Mux3Model.OutputCalc(Bank.Bank_A, cycle - i + 1).Value; inputASource = DevicePort.Mux_3A; inputB = Mux3Model.OutputCalc(Bank.Bank_B, cycle - i + 1).Value; inputBSource = DevicePort.Mux_3B; outputFormula = "A+abs(B) thr"; break; case "taddabsb": inputA = Mux3Model.OutputCalc(Bank.Bank_A, cycle - i + 1).Value; inputASource = DevicePort.Mux_3A; inputB = Mux3Model.OutputCalc(Bank.Bank_B, cycle - i + 1).Value; inputBSource = DevicePort.Mux_3B; outputFormula = "A+abs(B) thr"; break; case "sqlcmp": inputA = Mux3Model.OutputCalc(Bank.Bank_A, cycle - i + 1).Value; inputASource = DevicePort.Mux_3A; outputFormula = "A -> sqlcmp"; break; case "sqlcnt": inputA = Mux3Model.OutputCalc(Bank.Bank_A, cycle - i + 1).Value; inputASource = DevicePort.Mux_3A; outputFormula = "A>>16 -> sqcval"; break; case "sqa": inputA = Mux3Model.OutputCalc(Bank.Bank_A, cycle - i + 1).Value; inputASource = DevicePort.Mux_3A; outputFormula = "Squelch(A)"; break; case "sqb": inputB = Mux3Model.OutputCalc(Bank.Bank_B, cycle - i + 1).Value; inputBSource = DevicePort.Mux_3B; outputFormula = "Squelch(B)"; break; } } var pipelineItem = new PipelineItem(); var lvA = new LabeledValue <long?>("In A:"); lvA.Value = inputA.HasValue ? inputA.Value : (long?)null; lvA.FormattedValue = FormatValue(VALUE_WIDTH, lvA.Value); pipelineItem.InputA = lvA; var lvB = new LabeledValue <long?>("In B:"); lvB.Value = inputB.HasValue ? inputB.Value : (long?)null; lvB.FormattedValue = FormatValue(VALUE_WIDTH, lvB.Value); pipelineItem.InputB = lvB; var lvASrc = new LabeledValue <DevicePort?>("Src A:"); lvASrc.Value = inputASource == DevicePort.Default ? (DevicePort?)null : inputASource; lvASrc.FormattedValue = lvASrc.Value.ToString(); pipelineItem.InputASource = lvASrc; var lvBSrc = new LabeledValue <DevicePort?>("Src B:"); lvBSrc.Value = inputBSource == DevicePort.Default ? (DevicePort?)null : inputBSource; lvBSrc.FormattedValue = lvBSrc.Value.ToString(); pipelineItem.InputBSource = lvBSrc; var lvOutputFormula = new LabeledValue <string>("Equation:"); lvOutputFormula.Value = outputFormula; lvOutputFormula.FormattedValue = outputFormula; pipelineItem.OutputFormula = lvOutputFormula; pipelineItems.Add(pipelineItem); } return(pipelineItems); }
/// <summary> /// Enables Csrf token generation. /// This is enabled automatically so there should be no reason to call this manually. /// </summary> /// <param name="pipelines">Application pipelines</param> public static void Enable(IPipelines pipelines) { var postHook = new PipelineItem<Action<NancyContext>>( CsrfHookName, context => { if (context.Response == null || context.Response.Cookies == null) { return; } if (context.Items.ContainsKey(CsrfToken.DEFAULT_CSRF_KEY)) { context.Response.Cookies.Add(new NancyCookie(CsrfToken.DEFAULT_CSRF_KEY, (string)context.Items[CsrfToken.DEFAULT_CSRF_KEY], true)); return; } if (context.Request.Cookies.ContainsKey(CsrfToken.DEFAULT_CSRF_KEY)) { context.Items[CsrfToken.DEFAULT_CSRF_KEY] = HttpUtility.UrlDecode(context.Request.Cookies[CsrfToken.DEFAULT_CSRF_KEY]); return; } var token = new CsrfToken { CreatedDate = DateTime.Now, }; token.CreateRandomBytes(); token.CreateHmac(CsrfStartup.CryptographyConfiguration.HmacProvider); var tokenString = CsrfStartup.ObjectSerializer.Serialize(token); context.Items[CsrfToken.DEFAULT_CSRF_KEY] = tokenString; context.Response.Cookies.Add(new NancyCookie(CsrfToken.DEFAULT_CSRF_KEY, tokenString, true)); }); pipelines.AfterRequest.AddItemToEndOfPipeline(postHook); }
public void Execute( PipelineTaskStep <TItem> step, TaskStepExecutionContext context, IProgress <byte> progress, CancellationToken cancellation) { var events = context.EventsBag.TryGetEvents <PipelineExecutionEvents>(); var dataflowExecutionContext = new DataflowExecutionContext { StepContext = context, Events = events, TotalBlockDurations = new ConcurrentDictionary <string, TimeSpan>( step.Blocks.Select(x => x.Name).Distinct().Select( x => new KeyValuePair <string, TimeSpan>(x, TimeSpan.Zero))) }; var pipeline = _dataflowPipelineBuilder.Build(step, dataflowExecutionContext, progress, cancellation); var itemNumber = 0; var totalInputMaterializationDuration = TimeSpan.Zero; using (var inputEnumerator = step.Input.Input.GetEnumerator()) { while (true) { var sw = Stopwatch.StartNew(); if (!inputEnumerator.MoveNext()) { sw.Stop(); break; } var pipelineItem = new PipelineItem <TItem> { Number = ++itemNumber, Item = inputEnumerator.Current, ProcessingStopwatch = sw }; var materializationDuration = sw.Elapsed; totalInputMaterializationDuration += materializationDuration; events?.OnItemStarted(pipelineItem.Number, pipelineItem.Item, materializationDuration, step, context.Task); pipeline.InputBlock.SendAsync(pipelineItem).Wait(); cancellation.ThrowIfCancellationRequested(); } } pipeline.InputBlock.Complete(); try { pipeline.Completion.Wait(); } catch (AggregateException e) { var flat = e.Flatten(); if (flat.InnerExceptions.Count == 1) { throw flat.InnerExceptions[0]; } throw flat; } events?.OnPipelineEnded(totalInputMaterializationDuration, dataflowExecutionContext.TotalBlockDurations, step, context.Task); }
/// <summary> /// Create a new instance of this device for the given cycle /// </summary> /// <param name="bankID">BankID of the device</param> /// <param name="cycle">Zero-based program cycle number</param> public Mux3Model(Bank bankID, int cycle) : base(bankID, cycle, VALUE_WIDTH, 0, PIPELINE_DELAY) { // name name = bankID == Bank.Bank_A ? DevicePort.Mux_3A.ToString() : DevicePort.Mux_3B.ToString(); // instructions instructions.Add(InstrForCycle(bankID, cycle)); instructions.Add(InstrForCycle(bankID, cycle - 1)); // connectionInputs connectionInputs = Connections(bankID, cycle); // output output = OutputCalc(bankID, cycle); // pipelineItems pipelineItems = new List <PipelineItem>(); for (int i = 0; i < instructions.Count; i++) { var instr = instructions[i]; DevicePort activeInput = DevicePort.Default; long? activeValue = null; if (i == 1) { switch (instr) { case "ba": // Bus to ALU case "sa": // Shifter to ALU case "bra": // Bus to RAM, RAM to ALU case "sra": // Shifter to RAM, RAM to ALU activeInput = bankID == Bank.Bank_A ? DevicePort.Mux_2A : DevicePort.Mux_2B; activeValue = Mux2Model.OutputCalc(bankID, cycle).Value; break; case "brm": // Bus to RAM, to MAC case "srm": // Shifter to RAM to MAC activeInput = DevicePort.MAC; activeValue = MACModel.OutputCalc(cycle).Value; break; default: break; } } var pipelineItem = new PipelineItem(); var lvValue = new LabeledValue <long?>("In:"); lvValue.Value = activeValue.HasValue ? activeValue.Value : (long?)null; lvValue.FormattedValue = FormatValue(VALUE_WIDTH, lvValue.Value); pipelineItem.Input = lvValue; var lvValueSrc = new LabeledValue <DevicePort?>("Src:"); lvValueSrc.Value = activeInput == DevicePort.Default ? (DevicePort?)null : activeInput; lvValueSrc.FormattedValue = lvValueSrc.Value.ToString(); pipelineItem.InputSource = lvValueSrc; PipelineItems.Add(pipelineItem); } }
public void Process(PipelineItem item) { throw new NotImplementedException(); }
/// <summary> /// Create a new instance of this device for the given cycle /// </summary> /// <param name="cycle">Zero-based program cycle number</param> public MACModel(int cycle) : base(Bank.NotApplicable, cycle, VALUE_WIDTH, 0, PIPELINE_DELAY) { // name name = DevicePort.MAC.ToString(); // instructions instructions.Add(ActiveInstr(cycle)); // [t-2] instructions.Add(ActiveInstr(cycle - 1)); // [t-1] instructions.Add(ActiveInstr(cycle - 2)); // [now] // connectionInputs connectionInputs = Connections(cycle); // output output = OutputCalc(cycle); // pipelineItems pipelineItems = new List <PipelineItem>(); for (int i = 0; i < instructions.Count; i++) { var instr = instructions[i]; long? aluValue = null; long? a = null; long? b = null; string outputFormula = null; int? accum = null; switch (instr) { case "loadalu": if (i > 0) { // Adds the previous ALU output (from the shifter) to the product and starts a new accumulation. aluValue = DFBState.GetCySimulatorPrivateField <long?>(cycle - i + 1, "aluout"); a = DFBState.GetCySimulatorPrivateField <long?>(cycle - i + 1, "a2mux"); b = DFBState.GetCySimulatorPrivateField <long?>(cycle - i + 1, "b2mux"); if (i == PIPELINE_DELAY) { outputFormula = "a * b + [Prev ALU]"; } } break; case "clra": if (i > 0) { // Clears the accumulator and stores the current product a = DFBState.GetCySimulatorPrivateField <long?>(cycle - i + 1, "a2mux"); b = DFBState.GetCySimulatorPrivateField <long?>(cycle - i + 1, "b2mux"); if (i == PIPELINE_DELAY) { accum = 0; outputFormula = "a * b"; } } break; case "hold": if (i > 0) { // Holds the value in the accumulator from the previous cycle. No multiply if (i == PIPELINE_DELAY) { accum = Convert.ToInt32(OutputCalc(cycle - i + 1).Value); outputFormula = "Accum"; } } break; case "macc": if (i > 0) { // Multiplies the values on mux2 of side A and side B. // Adds the product to the current value of the accumulator. a = DFBState.GetCySimulatorPrivateField <long?>(cycle - i + 1, "a2mux"); b = DFBState.GetCySimulatorPrivateField <long?>(cycle - i + 1, "b2mux"); if (i == PIPELINE_DELAY) { accum = Convert.ToInt32(OutputCalc(cycle - i + 1).Value); outputFormula = "a * b + Accum"; } } break; } var pipelineItem = new PipelineItem(); var lvAluValue = new LabeledValue <long?>("Prev ALU:"); lvAluValue.Value = aluValue.HasValue ? aluValue.Value : (long?)null; lvAluValue.FormattedValue = FormatValue(VALUE_WIDTH, lvAluValue.Value); pipelineItem.AluValue = lvAluValue; var lvA = new LabeledValue <long?>("a:"); lvA.Value = a.HasValue ? a.Value : (long?)null; lvA.FormattedValue = FormatValue(VALUE_WIDTH, lvA.Value); pipelineItem.A = lvA; var lvB = new LabeledValue <long?>("b:"); lvB.Value = b.HasValue ? b.Value : (long?)null; lvB.FormattedValue = FormatValue(VALUE_WIDTH, lvB.Value); pipelineItem.B = lvB; var lvOutputFormula = new LabeledValue <string>("Formula:"); lvOutputFormula.Value = outputFormula; lvOutputFormula.FormattedValue = outputFormula; pipelineItem.OutputFormula = lvOutputFormula; var lvAccum = new LabeledValue <int?>("Accum:"); lvAccum.Value = accum.HasValue ? accum.Value : (int?)null; lvAccum.FormattedValue = FormatValue(VALUE_WIDTH, lvAccum.Value); pipelineItem.Accumulator = lvAccum; pipelineItems.Add(pipelineItem); } }