Esempio n. 1
0
        public void SendTextTo(Destinations destination, String text = null)
        {
            var f   = Utilities.CreateTemporalFileFromText(text);
            var res = new SendResults(1, destination);

            if (f != null)
            {
                var fileSet = PrimeFileSet.Create(new[] { f }, new PrimeParameters(Settings.Default));
                fileSet.Destination = destination;
                if (destination == Destinations.Custom)
                {
                    var fs = new FolderSelectDialog {
                        Title = "Select the destination folder"
                    };
                    if (!fs.ShowDialog())
                    {
                        return; // Conversion was cancel
                    }
                    fileSet.CustomDestination = fs.FileName;
                }
                else
                {
                    fileSet.CustomDestination = _emulatorFolder;
                }

                SendDataTo(fileSet);
                res.Add(SendResult.Success);
            }
            else
            {
                res.Add(SendResult.ErrorInvalidInput);
                res.ShowMsg(false, this);
            }
        }
Esempio n. 2
0
        private void backgroundWorkerSend_DoWork(object sender, DoWorkEventArgs e)
        {
            var fs       = (PrimeFileSet)e.Argument;
            var res      = new SendResults(fs.Files.Length, fs.Destination);
            var nullFile = new PrimeUsbData(new byte[] { 0x00 }, null);

            foreach (var file in fs.Files)
            {
                try
                {
                    var b = new PrimeProgramFile(file, Settings.Default);

                    try
                    {
                        if (b.IsValid)
                        {
                            var primeFile = new PrimeUsbData(b.Name, b.Data,
                                                             fs.Destination == Destinations.Calculator ? _calculator.OutputChunkSize : 0, Parameters);

                            switch (fs.Destination)
                            {
                            case Destinations.Calculator:
                                _calculator.Send(nullFile);
                                _calculator.Send(primeFile);
                                _calculator.Send(nullFile);
                                res.Add(SendResult.Success);
                                break;

                            case Destinations.UserFolder:
                            case Destinations.Custom:
                                primeFile.Save(Path.Combine(fs.CustomDestination, primeFile.Name + ".hpprgm"));
                                res.Add(SendResult.Success);
                                break;
                            }
                        }
                        else
                        {
                            res.Add(SendResult.ErrorInvalidFile);
                        }
                    }
                    catch
                    {
                        res.Add(SendResult.ErrorSend);
                    }
                }
                catch
                {
                    res.Add(SendResult.ErrorReading);
                }

                backgroundWorkerSend.ReportProgress(0, res);
            }

            e.Result = res;
        }
Esempio n. 3
0
        public void SendTextTo(Destinations destination, String text = null)
        {
            var f = Utilities.CreateTemporalFileFromText(text);
            var res = new SendResults(1, destination);

            if (f != null)
            {
                var fileSet = PrimeFileSet.Create(new[] {f}, new PrimeParameters(Settings.Default));
                fileSet.Destination = destination;
                if (destination == Destinations.Custom)
                {
                    var fs = new FolderSelectDialog {Title = "Select the destination folder"};
                    if (!fs.ShowDialog())
                        return; // Conversion was cancel

                    fileSet.CustomDestination = fs.FileName;
                }
                else
                    fileSet.CustomDestination = _emulatorFolder;

                SendDataTo(fileSet);
                res.Add(SendResult.Success);
            }
            else
            {
                res.Add(SendResult.ErrorInvalidInput);
                res.ShowMsg(false, this);
            }
        }
Esempio n. 4
0
        private void backgroundWorkerSend_DoWork(object sender, DoWorkEventArgs e)
        {
            var fs = (PrimeFileSet) e.Argument;
            var res = new SendResults(fs.Files.Length, fs.Destination);
            var nullFile = new PrimeUsbData(new byte[] {0x00}, null);
            foreach (var file in fs.Files)
            {
                try
                {
                    var b = new PrimeProgramFile(file, Settings.Default);

                    try
                    {
                        if (b.IsValid)
                        {
                            var primeFile = new PrimeUsbData(b.Name, b.Data,
                                fs.Destination == Destinations.Calculator ? _calculator.OutputChunkSize : 0, Parameters);

                            switch (fs.Destination)
                            {
                                case Destinations.Calculator:
                                    _calculator.Send(nullFile);
                                    _calculator.Send(primeFile);
                                    _calculator.Send(nullFile);
                                    res.Add(SendResult.Success);
                                    break;
                                case Destinations.UserFolder:
                                case Destinations.Custom:
                                    primeFile.Save(Path.Combine(fs.CustomDestination, primeFile.Name + ".hpprgm"));
                                    res.Add(SendResult.Success);
                                    break;
                            }
                        }
                        else
                            res.Add(SendResult.ErrorInvalidFile);
                    }
                    catch
                    {
                        res.Add(SendResult.ErrorSend);
                    }
                }
                catch
                {
                    res.Add(SendResult.ErrorReading);
                }

                backgroundWorkerSend.ReportProgress(0, res);
            }

            e.Result = res;
        }