private void Update(EvaluationContext context) { var content = Content.GetValue(context); var filepath = Filepath.GetValue(context); if (content != _lastContent) { Log.Debug("Writing file " + filepath); try { File.WriteAllText(filepath, content); } catch (Exception e) { Log.Error($"Failed to write file {filepath}:" + e.Message); } _lastContent = content; } else { Log.Debug("Just updating???"); } Result.Value = Content.GetValue(context); OutFilepath.Value = filepath; // Forward so it can be triggered }
private void Update(EvaluationContext context) { var triggerUpdate = TriggerUpdate.GetValue(context); var filepath = Filepath.GetValue(context); try { Result.Value = File.ReadAllText(filepath); } catch (Exception e) { Log.Error($"Failed to read file {filepath}:" + e.Message); } }
private void Update(EvaluationContext context) { var filePath = Filepath.GetValue(context); var filterCharacters = FilterCharacters.GetValue(context); var brightnessTable = SortAsciiLetters(filePath, filterCharacters); if (brightnessTable == null) { return; } //Log.Debug("Generating texture"); var sampleCount = brightnessTable.Length; const int entrySizeInBytes = sizeof(float); var listSizeInBytes = sampleCount * entrySizeInBytes; var bufferSizeInBytes = 1 * listSizeInBytes; using (var dataStream = new DataStream(bufferSizeInBytes, true, true)) { var texDesc = new Texture2DDescription() { Width = sampleCount, Height = 1, ArraySize = 1, BindFlags = BindFlags.ShaderResource, Usage = ResourceUsage.Default, MipLevels = 1, CpuAccessFlags = CpuAccessFlags.None, Format = Format.R32_Float, SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0), }; var filterOutFactor = (256f - filterCharCount) / 256; for (var sampleIndex = 0; sampleIndex < sampleCount; sampleIndex++) { var index = (int)(sampleIndex * filterOutFactor).Clamp(0, sampleCount); dataStream.Write((float)brightnessTable[index].Index / 256f); } dataStream.Position = 0; var dataRectangles = new DataRectangle[] { new DataRectangle(dataStream.DataPointer, listSizeInBytes) }; Utilities.Dispose(ref MappingTexture.Value); MappingTexture.Value = new Texture2D(ResourceManager.Instance().Device, texDesc, dataRectangles); } }