public static void WriteLine(this IStandardStreamWriter writer, string value)
        {
            if (writer is null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            writer.Write(value);
            writer.Write(Environment.NewLine);
        }
Ejemplo n.º 2
0
        internal static void WriteLine(this IStandardStreamWriter writer, string?value, bool avoidExtraNewLine)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            writer.Write(value);
            if (!avoidExtraNewLine || (!value?.EndsWith(NewLine) ?? false))
            {
                writer.Write(NewLine);
            }
        }
Ejemplo n.º 3
0
 private static void ClearCurrent(StringBuilder sb, IStandardStreamWriter consoleOut)
 {
     if (sb.Length > 0)
     {
         consoleOut.Write(Enumerable.Repeat("\b \b", sb.Length).ToCsv(""));
         sb.Length = 0;
     }
 }
Ejemplo n.º 4
0
        public static void WriteLine(this IStandardStreamWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            writer.Write(NewLine);
        }
Ejemplo n.º 5
0
        public static void VerboseWrite(this IStandardStreamWriter writer, string value = "")
        {
            if (!Globals.Verbose)
            {
                return;
            }

            writer.Write(value);
        }
Ejemplo n.º 6
0
        public static void ReportProgress(this IStandardStreamWriter writer, int percentage)
        {
            var mode = 1;

            if (percentage is 100)
            {
                mode = 0;
            }

            writer.Write($"\x1B]9;4;{mode};{percentage}\x1B\\");
        }
Ejemplo n.º 7
0
 public static void Write(this IStandardStreamWriter writer, object?value)
 {
     writer.Write(value?.ToString());
 }
Ejemplo n.º 8
0
        protected override async Task <int> InvokeAsync(InvocationContext context, IStandardStreamWriter console, DeviceController device)
        {
            var kit                   = context.ParseResult.ValueForOption <int>("kit");
            var triggerRoot           = device.Schema.GetTriggerRoot(kit, trigger: 1);
            var deviceData            = ModuleData.FromLogicalRootNode(triggerRoot);
            var modelData             = ModuleData.FromLogicalRootNode(triggerRoot);
            var defaultValuesSnapshot = modelData.CreateSnapshot();

            var deviceDataRoot = new DataTreeNode(deviceData, triggerRoot);
            await device.LoadDescendants(deviceDataRoot, targetAddress : null, progressHandler : null, CancellationToken.None);

            var originalSnapshot     = deviceData.CreateSnapshot();
            var instrumentField      = device.Schema.GetMainInstrumentField(kit, trigger: 1);
            var modelInstrumentField = (InstrumentDataField)modelData.GetDataField(instrumentField);

            var instrumentContainers = triggerRoot.DescendantFieldContainers();

            var differences = new List <Difference>();
            var logger      = new ConsoleLogger(console);

            try
            {
                // Reset the device to an empty snapshot
                deviceData.LoadSnapshot(defaultValuesSnapshot, logger);
                await device.SaveDescendants(deviceDataRoot, targetAddress : null, progressHandler : null, CancellationToken.None);

                foreach (var instrument in device.Schema.PresetInstruments)
                {
                    // Make the change on the real module and load the data.
                    // Assumption: the segment containing the instrument itself (e.g. KitPadInst) doesn't
                    // have any implicit model changes to worry about.
                    await device.SetInstrumentAsync(kit, trigger : 1, instrument, CancellationToken.None);

                    await device.LoadDescendants(deviceDataRoot, targetAddress : null, progressHandler : null, CancellationToken.None);

                    // Make the change in the model.
                    modelData.LoadSnapshot(defaultValuesSnapshot, logger);
                    modelInstrumentField.Instrument = instrument;

                    // Compare the two.
                    bool anyDifferences = false;
                    foreach (var container in instrumentContainers)
                    {
                        // We won't compare InstrumentDataField, TempoDataField or StringDataField this way, but that's okay.
                        var realFields  = deviceData.GetDataFields(container).SelectMany(ExpandOverlays).OfType <NumericDataFieldBase>().ToList();
                        var modelFields = modelData.GetDataFields(container).SelectMany(ExpandOverlays).OfType <NumericDataFieldBase>().ToList();
                        if (realFields.Count != modelFields.Count)
                        {
                            console.WriteLine($"Major failure: for instrument {instrument.Id} ({instrument.Group} / {instrument.Name}), found {realFields.Count} real fields and {modelFields.Count} model fields in container {container.Path}");
                            return(1);
                        }

                        foreach (var pair in realFields.Zip(modelFields))
                        {
                            var real  = pair.First;
                            var model = pair.Second;
                            if (real.SchemaField != model.SchemaField)
                            {
                                console.WriteLine($"Major failure: for instrument {instrument.Id} ({instrument.Group} / {instrument.Name}), mismatched schema field for {container.Path}: {real.SchemaField.Name} != {model.SchemaField.Name}");
                                return(1);
                            }
                            var realValue      = real.RawValue;
                            var predictedValue = model.RawValue;
                            if (realValue != predictedValue)
                            {
                                anyDifferences = true;
                                differences.Add(new Difference(instrument, container, real.SchemaField, realValue, predictedValue));
                            }
                        }
                    }
                    console.Write(anyDifferences ? "!" : ".");
                }
            }
            finally
            {
                // Restore the original data
                deviceData.LoadSnapshot(originalSnapshot, logger);
                await device.SaveDescendants(deviceDataRoot, targetAddress : null, progressHandler : null, CancellationToken.None);
            }
            console.WriteLine();
            foreach (var difference in differences)
            {
                console.WriteLine(difference.ToString());
            }
            console.WriteLine($"Total differences: {differences.Count}");
            return(0);

            IEnumerable <IDataField> ExpandOverlays(IDataField field) =>
            field is OverlayDataField odf ? odf.CurrentFieldList.Fields : Enumerable.Repeat(field, 1);
        }
Ejemplo n.º 9
0
 public static void HideCursor(this IStandardStreamWriter writer) => writer.Write("\x1B[?25l");
Ejemplo n.º 10
0
 public static IStandardStreamWriter AtomicWriteLine(this IStandardStreamWriter writer, string message)
 {
     writer.Write(message + Environment.NewLine);
     return(writer);
 }
Ejemplo n.º 11
0
 public static void EraseCharacters(this IStandardStreamWriter writer, int count) => writer.Write($"\x1B[{count}X");
Ejemplo n.º 12
0
 public static void SetHorizontalPosition(this IStandardStreamWriter writer, int position) => writer.Write($"\x1B[{position}G");
Ejemplo n.º 13
0
 public override void Write(char value)
 {
     _writer.Write(value.ToString());
 }
 public static void WriteIndented(
     this IStandardStreamWriter writer,
     string text,
     int level  = 1,
     int indent = DefaultIndent) =>
 WriteIndented(s => writer.Write(s), text, level, indent);
Ejemplo n.º 15
0
 internal static void WriteLine(this IStandardStreamWriter streamWriter)
 {
     streamWriter.Write(Environment.NewLine);
 }
Ejemplo n.º 16
0
 internal static void WriteLine(this IStandardStreamWriter streamWriter, string message)
 {
     streamWriter.Write(message);
     streamWriter.WriteLine();
 }
Ejemplo n.º 17
0
 public static void ShowCursor(this IStandardStreamWriter writer) => writer.Write("\x1B[?25h");