private void GetSizeFromMonitor(Screen monitor)
        {
            this.SuspendUI = true;
            ScreenColourSettings settings1 = this.Settings;
            Rectangle            bounds1   = monitor.Bounds;
            int x1 = bounds1.X;

            bounds1 = monitor.Bounds;
            int   y1     = bounds1.Y;
            Point point1 = new Point(x1, y1);

            settings1.TopLeft = point1;
            ScreenColourSettings settings2 = this.Settings;
            Rectangle            bounds2   = monitor.Bounds;
            int x2 = bounds2.X;

            bounds2 = monitor.Bounds;
            int width = bounds2.Width;
            int x3    = x2 + width;

            bounds2 = monitor.Bounds;
            int y2 = bounds2.Y;

            bounds2 = monitor.Bounds;
            int   height = bounds2.Height;
            int   y3     = y2 + height;
            Point point2 = new Point(x3, y3);

            settings2.BottomRight = point2;
            this.SetPositionTextBoxesFromSettings();
            this.SuspendUI = false;
            ProcessorBase.SaveSettings <ScreenColourSettings>(this.Settings, (string)null);
        }
Beispiel #2
0
        private void cbConfigs_SelectedIndexChanged(object sender, EventArgs e)
        {
            while (_settings.Sounds.Any(x => x.WaveOut != null))
            {
                foreach (var sound in _settings.Sounds.Where(x => x.WaveOut != null))
                {
                    sound.StartStopRequest = StartStop.Stop;
                }
                Thread.Sleep(1);
            }
            var s = new SoundGeneratorSettings();

            ProcessorBase.LoadSettings(ref s, cbConfigs.SelectedItem + "." + _settings.FileExtension);

            _settings.SelectedLabels = s.SelectedLabels;
            _settings.OnTimes        = s.OnTimes;
            _settings.OffTimes       = s.OffTimes;
            _settings.Volume         = s.Volume;
            _settings.Sounds         = s.Sounds;

            // start any sounds as necessary
            foreach (var sound in _settings.Sounds.Where(x => x.Started && x.WaveOut == null))
            {
                sound.StartStopRequest = StartStop.Start;
            }

            SetupUI();
        }
Beispiel #3
0
        public override bool Initialize(List <IProcessorInput> inputs, string parameters, ILogger logger)
        {
            if (Models.InputItemInteractivBrokerModel.IB == null)
            {
                return(false);
            }
            this.logger = logger;
            ParametersParser parser = CreateParser(parameters);

            simtradeid = parser.GetInt("SimTrade_ID");
            if (simtradeid < 0 || simtradeid > Model.Project.Outputs.Count)
            {
                return(false);
            }
            tradeId = parser.GetInt("TradeID");
            tradeTerminal.FirstBroker = new ModelsAT.BrokerMT(tradeId);
            tradeTerminal.FirstBroker.setBrokerParam("Name", parser.GetString("MT_name"));
            tradeTerminal.FirstBroker.setOrderParam("MKT");
            tradeTerminal.SecondBroker = new ModelsAT.BrokerIBOptionPair(tradeId, Models.InputItemInteractivBrokerModel.IB);
            tradeTerminal.SecondBroker.setBrokerParam("Put", parser.GetString("IB_Put_name"));
            tradeTerminal.SecondBroker.setBrokerParam("Call", parser.GetString("IB_Call_name"));
            tradeTerminal.SecondBroker.setBrokerParam("Volume", parser.GetString("Volume_IB"));
            tradeTerminal.SecondBroker.setBrokerParam("LimitPrice", parser.GetString("LMT_Price_IB"));
            tradeTerminal.SecondBroker.setOrderParam(parser.GetString("OrderType_IB"));
            SimTrade = Model.Project.Proccesors[simtradeid];
            SimTrade.ProcessorAction += EventHandler;
            if (parser.GetInt("IsReal") == 1)
            {
                tradeTerminal.FirstBroker.isReal  = true;
                tradeTerminal.SecondBroker.isReal = true;
            }
            Model.OutputsInitializeEnd += InitializeHandler;
            return(true);
        }
Beispiel #4
0
        public void InitializeHandler()
        {
            Gap = Model.Project.Proccesors[gappos];
            Gap.ProcessorAction += PositionHandler;
            ZigZag_1             = Model.Project.Proccesors[zigzagid_1];
            ZigZag_2             = Model.Project.Proccesors[zigzagid_2];
            switch (trader_type)
            {
            case (TradeType.STANDART):
                ZigZag_1.ProcessorAction += EventHandler_1;
                ZigZag_2.ProcessorAction += EventHandler_2;
                break;

            case (TradeType.IN_OUT):
                ZigZag_1.ProcessorAction += EventHandler_1_type2;
                ZigZag_2.ProcessorAction += EventHandler_2_type2;
                break;

            default:
                ZigZag_1.ProcessorAction += EventHandler_1_type2;
                ZigZag_2.ProcessorAction += EventHandler_2_type2;
                ZigZag_2_2 = Model.Project.Proccesors[zigzagid_2_2];
                ZigZag_2_2.ProcessorAction += EventHandler_2_2_type2;
                break;
            }
            Model.OutputsInitializeEnd -= InitializeHandler;
        }
        private void button2_Click(object sender, EventArgs e)
        {
            var f = new AssignAreaToBulbForm(Settings.LabelsAndLocations);

            f.ShowDialog();

            Settings.LabelsAndLocations = f.LabelsAndLocations;
            ProcessorBase.SaveSettings(Settings, null);
        }
Beispiel #6
0
        private void button2_Click(object sender, EventArgs e)
        {
            var f = new AssignAreaToBulbForm(Settings.LabelsAndLocations.Where(x => lbLabels.SelectedItems.Contains(x.Label)).ToList());

            f.ShowDialog();

            Settings.LabelsAndLocations.RemoveAll(x => f.LabelsAndLocations.Any(y => y.Label == x.Label));
            Settings.LabelsAndLocations.AddRange(f.LabelsAndLocations);
            ProcessorBase.SaveSettings(Settings, null);
        }
Beispiel #7
0
        public void CopyAndDeleteTempFile_Success()
        {
            Mock <ProcessorBase> mockProcessor = new Mock <ProcessorBase>();
            ProcessorBase        processor     = mockProcessor.Object;
            string tmpFile = Path.GetTempFileName();

            File.WriteAllText(tmpFile, "This is the output text.");
            processor.CopyAndDeleteTempFile(tmpFile, GetCurrentTestResultsFilePath("out.txt"), true, false);
            Assert.IsFalse(File.Exists(tmpFile));
        }
Beispiel #8
0
 public void InitializeHandler()
 {
     Gap = Model.Project.Proccesors[gappos];
     Gap.ProcessorAction += PositionHandler;
     ZigZag                       = Model.Project.Proccesors[zigzagid];
     ZigZagSmall                  = Model.Project.Proccesors[zigzagidsmall];
     ZigZag.ProcessorAction      += EventHandlerBig;
     ZigZagSmall.ProcessorAction += EventHandlerSmall;
     Model.OutputsInitializeEnd  -= InitializeHandler;
 }
Beispiel #9
0
        /// <summary>
        /// Attached Progress event and takes care of forwarding cancellation requests to the processor.
        /// </summary>
        /// <param name="processor"></param>
        protected void AttachProcessorEvents(ProcessorBase processor)
        {
            processor.Progress += (sender, e) =>
            {
                if (CancelRequested)
                {
                    e.Cancel = true;
                    return;
                }

                ReportProgress(e.Progress);
            };
        }
        /// <summary>
        /// Processes the image using a pixel buffer
        /// </summary>
        /// <param name="pixelBuffer">The pixel buffer to use</param>
        /// <param name="sourceWidth">The source image width</param>
        /// <param name="sourceHeight">The source image height</param>
        /// <param name="sourceStride">The source data stride</param>
        /// <returns>The processed pixel buffer</returns>
        protected override byte[] Process(byte[] pixelBuffer, int sourceWidth, int sourceHeight, int sourceStride)
        {
            ColorSubstitutionParameters parameters = this.DynamicParameter;

            byte sourceRed = 0, sourceGreen = 0, sourceBlue = 0, sourceAlpha = 0;
            int  resultRed = 0, resultGreen = 0, resultBlue = 0;

            byte newRedValue   = parameters.ReplaceWith.R;
            byte newGreenValue = parameters.ReplaceWith.G;
            byte newBlueValue  = parameters.ReplaceWith.B;

            byte redFilter   = parameters.ToReplace.R;
            byte greenFilter = parameters.ToReplace.G;
            byte blueFilter  = parameters.ToReplace.B;

            for (int k = 0; k < pixelBuffer.Length; k += 4)
            {
                sourceAlpha = pixelBuffer[k + 3];

                if (sourceAlpha != 0)
                {
                    sourceBlue  = pixelBuffer[k];
                    sourceGreen = pixelBuffer[k + 1];
                    sourceRed   = pixelBuffer[k + 2];

                    if ((sourceBlue < blueFilter + parameters.Threshold &&
                         sourceBlue > blueFilter - parameters.Threshold) &&
                        (sourceGreen < greenFilter + parameters.Threshold &&
                         sourceGreen > greenFilter - parameters.Threshold) &&
                        (sourceRed < redFilter + parameters.Threshold &&
                         sourceRed > redFilter - parameters.Threshold))
                    {
                        resultBlue = blueFilter - sourceBlue + newBlueValue;
                        resultBlue = ProcessorBase.Guard(resultBlue);

                        resultGreen = greenFilter - sourceGreen + newGreenValue;
                        resultGreen = ProcessorBase.Guard(resultGreen);

                        resultRed = redFilter - sourceRed + newRedValue;
                        resultRed = ProcessorBase.Guard(resultRed);

                        pixelBuffer[k]     = (byte)resultBlue;
                        pixelBuffer[k + 1] = (byte)resultGreen;
                        pixelBuffer[k + 2] = (byte)resultRed;
                        pixelBuffer[k + 3] = sourceAlpha;
                    }
                }
            }

            return(pixelBuffer);
        }
Beispiel #11
0
        public void CopyAndDeleteTempFile_Overwrites()
        {
            Mock <ProcessorBase> mockProcessor = new Mock <ProcessorBase>();
            ProcessorBase        processor     = mockProcessor.Object;
            string tmpFile = Path.GetTempFileName();

            File.WriteAllText(tmpFile, "This is the final text.");
            string outputPath = GetCurrentTestResultsFilePath("out.txt");

            // This should be overwritten.
            File.WriteAllText(outputPath, "This text will be overwritten.");
            processor.CopyAndDeleteTempFile(tmpFile, outputPath, true, false);
            Assert.IsFalse(File.Exists(tmpFile));
        }
Beispiel #12
0
        public void GetProcessingResultFromCopyAndDeleteTempFile_Successs()
        {
            Mock <ProcessorBase> mockProcessor = new Mock <ProcessorBase>();
            ProcessorBase        processor     = mockProcessor.Object;
            string tmpFile = Path.GetTempFileName();

            File.WriteAllText(tmpFile, "This is the final text.");
            string           outputPath = GetCurrentTestResultsFilePath("out.txt");
            ProcessingResult result     = processor.GetProcessingResultFromCopyAndDeleteTempFile(
                null, outputPath, tmpFile, true, true);

            Assert.IsFalse(File.Exists(tmpFile));
            Assert.AreEqual(ProcessingResultType.Success, result.Type);
        }
Beispiel #13
0
        private void F_ResizeEnd(object sender, EventArgs e)
        {
            if (MouseButtons == MouseButtons.Left)
            {
                return;
            }

            SuspendUI            = true;
            Settings.TopLeft     = new Point(_f.Location.X + 7, _f.Location.Y);
            Settings.BottomRight = new Point(_f.Location.X + _f.Size.Width - 6, _f.Location.Y + _f.Size.Height - 6);
            SetPositionTextBoxesFromSettings();
            SuspendUI = false;

            ProcessorBase.SaveSettings(Settings, null);
        }
Beispiel #14
0
        public void CopyAndDeleteTempFile_DoesNotOverwrite()
        {
            Mock <ProcessorBase> mockProcessor = new Mock <ProcessorBase>();
            ProcessorBase        processor     = mockProcessor.Object;
            string tmpFile = Path.GetTempFileName();

            File.WriteAllText(tmpFile, "This temp file will not overwrite the existing file.");
            string outputPath = GetCurrentTestResultsFilePath("out.txt");

            // This should not be overwritten.
            File.WriteAllText(outputPath, "This file will not be overwritten.");
            bool copied = processor.CopyAndDeleteTempFile(tmpFile, outputPath, false, false);

            Assert.IsFalse(File.Exists(tmpFile));
            Assert.IsFalse(copied);
        }
Beispiel #15
0
        public void CopyAndDeleteTempFile_MovesToRecycleBin()
        {
            Mock <ProcessorBase> mockProcessor = new Mock <ProcessorBase>();
            ProcessorBase        processor     = mockProcessor.Object;
            string tmpFile = Path.GetTempFileName();

            File.WriteAllText(tmpFile, "This is the final text.");
            string outputPath = GetCurrentTestResultsFilePath("out.txt");

            // This will be moved to the Recycle Bin.
            File.WriteAllText(outputPath, "This file will be moved to the Recycle Bin.");
            bool copied = processor.CopyAndDeleteTempFile(tmpFile, outputPath, false, true);

            Assert.IsFalse(File.Exists(tmpFile));
            Assert.IsTrue(copied);
        }
Beispiel #16
0
        private void pos_TextChanged(object sender, EventArgs e)
        {
            if (SuspendUI)
            {
                return;
            }

            SuspendUI = true;

            int tlxval       = 0,
                tlyval       = 0,
                brxval       = 0,
                bryval       = 0,
                fadeval      = 150,
                delayval     = 50,
                brightval    = 32767,
                satval       = 32767,
                minbrightval = 0,
                minsatval    = 0,
                kelvinval    = 3500;

            int.TryParse(tlx.Text, out tlxval);
            int.TryParse(tly.Text, out tlyval);
            int.TryParse(brx.Text, out brxval);
            int.TryParse(bry.Text, out bryval);
            int.TryParse(fade.Text, out fadeval);
            int.TryParse(delay.Text, out delayval);
            int.TryParse(saturation.Text, out satval);
            int.TryParse(brightness.Text, out brightval);
            int.TryParse(tbSaturationMin.Text, out minsatval);
            int.TryParse(tbBrightnessMin.Text, out minbrightval);
            int.TryParse(tbKelvin.Text, out kelvinval);

            Settings.TopLeft       = new Point(tlxval, tlyval);
            Settings.BottomRight   = new Point(brxval, bryval);
            Settings.Fade          = Math.Max(fadeval, 0);
            Settings.Delay         = Math.Max(delayval, 0);
            Settings.Saturation    = Math.Min(satval, 65535);
            Settings.Brightness    = Math.Min(brightval, 65535);
            Settings.MinSaturation = Math.Min(Math.Max(minsatval, 0), Settings.Saturation);
            Settings.MinBrightness = Math.Min(Math.Max(minbrightval, 0), Settings.Brightness);
            Settings.Kelvin        = Math.Min(Math.Max(kelvinval, 2500), 9000);

            SuspendUI = false;
            ProcessorBase.SaveSettings(Settings, null);
        }
Beispiel #17
0
        public void GetProcessingResultFromCopyAndDeleteTempFile_Failure()
        {
            Mock <ProcessorBase> mockProcessor = new Mock <ProcessorBase>();
            ProcessorBase        processor     = mockProcessor.Object;
            string tmpFile = Path.GetTempFileName();

            File.WriteAllText(tmpFile, "This temp file will not overwrite the existing file.");
            string outputPath = GetCurrentTestResultsFilePath("out.txt");

            // This should not be overwritten.
            File.WriteAllText(outputPath, "This file will not be overwritten.");
            ProcessingResult result = processor.GetProcessingResultFromCopyAndDeleteTempFile(
                null, outputPath, tmpFile, false, false);

            Assert.IsFalse(File.Exists(tmpFile));
            Assert.AreEqual(ProcessingResultType.Failure, result.Type);
        }
Beispiel #18
0
        private void pos_TextChanged(object sender, EventArgs e)
        {
            if (SuspendUI)
            {
                return;
            }

            SuspendUI = true;

            int tlxval       = 0,
                tlyval       = 0,
                brxval       = 0,
                bryval       = 0,
                fadeval      = 400,
                delayval     = 50,
                brightval    = 32767,
                satval       = 32767,
                minbrightval = 0,
                minsatval    = 0;

            int.TryParse(tlx.Text, out tlxval);
            int.TryParse(tly.Text, out tlyval);
            int.TryParse(brx.Text, out brxval);
            int.TryParse(bry.Text, out bryval);
            int.TryParse(fade.Text, out fadeval);
            int.TryParse(delay.Text, out delayval);
            int.TryParse(saturation.Text, out satval);
            int.TryParse(brightness.Text, out brightval);
            int.TryParse(tbSaturationMin.Text, out minsatval);
            int.TryParse(tbBrightnessMin.Text, out minbrightval);

            Settings.TopLeft       = new Point(tlxval, tlyval);
            Settings.BottomRight   = new Point(brxval, bryval);
            Settings.Fade          = fadeval;
            Settings.Delay         = delayval;
            Settings.Saturation    = satval;
            Settings.Brightness    = brightval;
            Settings.MinSaturation = minsatval;
            Settings.MinBrightness = minbrightval;

            SuspendUI = false;

            ProcessorBase.SaveSettings(Settings, null);
        }
Beispiel #19
0
 public void InitializeHandler()
 {
     SimTrade = Model.Project.Proccesors[simtradeid];
     SimTrade.ProcessorAction   += EventHandler;
     Model.OutputsInitializeEnd -= InitializeHandler;
 }
Beispiel #20
0
        private void F_ResizeEnd(object sender, EventArgs e)
        {
            if (MouseButtons == MouseButtons.Left)
            {
                return;
            }

            SuspendUI            = true;
            Settings.TopLeft     = new Point(_f.Location.X + 7, _f.Location.Y);
            Settings.BottomRight = new Point(_f.Location.X + _f.Size.Width - 6, _f.Location.Y + _f.Size.Height - 6);
            SetPositionTextBoxesFromSettings();
            SuspendUI = false;
            if (Settings.MultiColourZones.Any())
            {
                // send colour to first zone so can match to an area
                foreach (var label in Settings.SelectedLabels)
                {
                    var zones    = Settings.LabelsAndLocations.Single(x => x.Label == label).Zones;
                    var location = Settings.LabelsAndLocations.Single(x => x.Label == label).ScreenLocation;
                    if (zones > 1 && location == ScreenLocation.None)
                    {
                        // set first zone to green
                        var payload = new SetColourZonesPayload
                        {
                            start_index = new byte[1] {
                                0
                            },
                            end_index = new byte[1] {
                                0
                            },
                            Kelvin             = 3500,
                            TransitionDuration = 150,
                            Hue        = (int)Color.FromArgb(255, 0, 200, 0).GetHue(),
                            Saturation = 65535,
                            Brightness = 65535,
                            // don't apply yet
                            apply = new byte[1] {
                                0
                            }
                        };
                        BulbController.SetColour(label, payload, false);

                        // set rest of zones to off
                        payload = new SetColourZonesPayload
                        {
                            start_index = new byte[1] {
                                1
                            },
                            end_index = new byte[1] {
                                (byte)(zones - 1)
                            },
                            Kelvin             = 3500,
                            TransitionDuration = 150,
                            Hue        = 0,
                            Saturation = 0,
                            Brightness = 0,
                            // apply
                            apply = new byte[1] {
                                1
                            }
                        };
                        BulbController.SetColour(label, payload, false);
                    }
                }
            }
            ProcessorBase.SaveSettings(Settings, null);
        }