예제 #1
0
 public SambaController(ILogger <SystemInformationController> logger, IConfiguration config, IOptions <ConfigEnvironment> envOpt)
 {
     if (envOpt.Value.UseSsh)
     {
         var credentials = new OSCommander.Dtos.SshCredentials(
             config["Ssh:Host"],
             config["Ssh:Username"],
             config["Ssh:Password"]);
         _samba = new Samba(logger, credentials);
     }
     else
     {
         _samba = new Samba(logger);
     }
 }
예제 #2
0
        public SambaModule() : base("/samba")
        {
            Post["/apply"] = x => {
                Samba.Apply();
                return(HttpStatusCode.OK);
            };

            Post["/start"] = x => {
                Samba.Start();
                return(HttpStatusCode.OK);
            };

            Post["/set"] = x => {
                string data    = Request.Form.Data;
                var    objects = JsonConvert.DeserializeObject <SambaModel>(data);
                Application.CurrentConfiguration.Services.Samba = objects;
                ConfigRepo.Save();
                return(HttpStatusCode.OK);
            };
        }
예제 #3
0
파일: SambaTests.cs 프로젝트: h4570/armnas
 /// <exception cref="T:System.ArgumentException">is a zero-length string, contains only white space, or contains one or more invalid characters as defined by <see cref="F:System.IO.Path.InvalidPathChars" />.</exception>
 /// <exception cref="T:System.ArgumentNullException">is <see langword="null" />.</exception>
 /// <exception cref="T:System.IO.PathTooLongException">The specified path, file name, or both exceed the system-defined maximum length.</exception>
 /// <exception cref="T:System.NotSupportedException">is in an invalid format.</exception>
 public SambaTests()
 {
     _good      = new Samba(SambaServiceMock.GetGood());
     _exception = new Samba(SambaServiceMock.GetWithCommandException());
     _empty     = new Samba(SambaServiceMock.GetWithEmptyResponses());
 }
예제 #4
0
        static async Task Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.Error.WriteLine("Missing firmware name argument");
                Environment.Exit(1);
            }

            var fwFile = args[0];

            byte[] fwData = null;
            Console.Write("Checking firmware... ");
            try {
#if WINDOWS_UWP
                var file = await StorageFile.GetFileFromPathAsync(fwFile);

                var buf = await FileIO.ReadBufferAsync(file);

                fwData = buf.ToArray();
#else
                fwData = File.ReadAllBytes(fwFile);
#endif
                Firmware.Validate(fwData);
                Console.WriteLine("OK.");
            }
            catch (Exception ex) {
                handleError(ex);
            }

            Samba device = null;

            try {
                var devices = await Samba.FindAllAsync();

                device = devices.FirstOrDefault();
                if (device == null)
                {
                    Console.Error.WriteLine("NXT not found. Is it properly plugged in via USB?");
                    Environment.Exit(1);
                }
            }
            catch (Exception ex) {
                handleError(ex);
            }

            try {
                nxt = await device.OpenAsync();
            }
            catch (Exception ex) {
                handleError(ex);
            }

            Console.WriteLine("NXT device in reset mode located and opened.");
            Console.WriteLine("Starting firmware flash procedure now...");

            try {
                using (var progress = new ProgressHelper("flashing")) {
                    await device.FlashAsync(fwData, progress);
                }
            }
            catch (Exception ex) {
                handleError(ex);
            }

            Console.WriteLine("Firmware flash complete.");

            try {
                await device.GoAsync(0x00100000);
            }
            catch (Exception ex) {
                handleError(ex);
            }

            Console.WriteLine("New firmware started!");

            try {
                nxt.Dispose();
            }
            catch (Exception ex) {
                handleError(ex);
            }
        }
예제 #5
0
        static void Main(string[] args)
        {
            var conf = "conf/ffcm_c.properties";

            if (args.Length > 0)
            {
                conf = args[0];
            }
            var cfg = new FCfg();

            cfg.Load(conf, true);
            cfg.Print();
            var addr = cfg.Val("srv_addr", "");

            if (addr.Length < 1)
            {
                Console.WriteLine("the srv_addr is not setted");
                Environment.Exit(1);
                return;
            }
            L.I("starting ffcm...");

            //Samba.
            var lambah = new LambdaEvnH();
            var ffcm   = new DocCov("FFCM", cfg, new SckDailer(addr).Dail, lambah);
            var ffcmh  = new FFCM(ffcm, ffcm.Srv);

            ffcm.InitConfig();
            ffcm.StartMonitor();
            ffcm.StartWindowCloser();
            ffcm.Start();
            ffcm.StartProcSrv();
            var activated = false;

            if (cfg.Val("samba", "N") == "Y")
            {
                L.I("start initial samba...");
                var samba = Samba.AddVolume2(cfg.Val("samba_vol", ""), cfg.Val("samba_uri", ""),
                                             cfg.Val("samba_user", ""), cfg.Val("samba_pwd", ""),
                                             cfg.Val("samba_paths", ""));
                samba.Fail = (s, e) =>
                {
                    ffcm.ChangeStatus(DTM_C.DCS_UNACTIVATED);
                    activated = false;
                };
                samba.Success = (s) =>
                {
                    if (!activated)
                    {
                        ffcm.ChangeStatus(DTM_C.DCS_ACTIVATED);
                        activated = true;
                    }
                };
                new Thread(run_samba).Start();
            }
            else
            {
                activated = true;
            }
            lambah.OnLogin = (nr, token) =>
            {
                if (activated)
                {
                    ffcm.ChangeStatus(DTM_C.DCS_ACTIVATED);
                }
            };
            lambah.EndCon = (nr) =>
            {
                ffcm.ChangeStatus(DTM_C.DCS_UNACTIVATED);
            };
            var reboot = cfg.Val("reboot", "");

            if (reboot.Length > 0)
            {
                ProcKiller.Shared.OnHavingNotKill = (c) =>
                {
                    string output;
                    Exec.exec(out output, reboot);
                };
            }
            new Thread(run_hb).Start(ffcm);
            ffcm.Wait();
        }
예제 #6
0
 static void run_samba(object s)
 {
     Samba.LoopChecker();
 }
예제 #7
0
        static async Task <int> Main(string[] args)
        {
            if (args.Length > 1)
            {
                Console.Error.WriteLine("Too many arguments");
                return(1);
            }

            if (args.Length < 1)
            {
                Console.Error.WriteLine("Missing firmware file argument");
                return(1);
            }

            var fwFile = args[0];

            byte[] fwData = null;
            Console.Write("Reading firmware file... ");
            try {
                fwData = File.ReadAllBytes(fwFile);
                Firmware.Validate(fwData);
                Console.WriteLine("OK.");
            }
            catch (Exception ex) {
                Console.Error.WriteLine(ex.Message);
                return(1);
            }

            Console.Write("Searching for NXTs... ");
            var findFwDevicesTask     = Samba.FindAllAsync();
            var findNxtUsbDevicesTask = NxtDevice.FindAllUsbAsync();

            var fwDevices  = (await findFwDevicesTask).ToList();
            var nxtDevices = (await findNxtUsbDevicesTask).ToList();

            var totalCount = fwDevices.Count + nxtDevices.Count;

            if (totalCount == 0)
            {
                Console.Error.WriteLine("None found.");
                return(1);
            }
            Console.WriteLine("OK.");

            var message = $"Finished flashing {{0}} of {totalCount}";

            using (var progressBar = new ProgressBar(totalCount, string.Format(message, 0))) {
                async Task rebootToFirmwareMode(NxtDevice device)
                {
                    using (var childProgressBar = progressBar.Spawn(1, "Starting firmware loader...")) {
                        try {
                            using (var nxt = await device.ConnectAsync()) {
                                if (await nxt.SendCommandAsync(SystemCommand.Boot()))
                                {
                                    // TODO: search for firmware device
                                }
                                else
                                {
                                    // TODO: error message
                                }
                            }
                        }
                        catch {
                        }
                    }
                }

                await Task.WhenAll(nxtDevices.Select(d => rebootToFirmwareMode(d)));

                async Task loadFirmware(Samba device)
                {
                    var childProgressBar = new ProgressHelper(progressBar, $"NXT on {device.PortName}");

                    try {
                        using (await device.OpenAsync()) {
                            // Write the firmware to flash memory
                            await device.FlashAsync(fwData, childProgressBar);

                            childProgressBar.ReportSuccess();
                            // reboot NXT
                            await device.GoAsync(0x00100000);
                        }
                    }
                    catch (Exception ex) {
                        childProgressBar.ReportError(ex.Message);
                    }
                    // hmm... possible race condition with progressBar.CurrentTick
                    progressBar.Tick(string.Format(message, progressBar.CurrentTick + 1));
                }

                await Task.WhenAll(fwDevices.Select(d => loadFirmware(d)));
            }

            return(0);
        }