示例#1
0
 /// <summary>
 /// Gets the file system dirty flags from a Locutus device.
 /// </summary>
 /// <param name="device">The target Locutus device whose file system dirty flags are to be retrieved.</param>
 /// <param name="errorHandler">Error handler, used to report errors to the user.</param>
 public static void GetFileSystemFlags(this Device device, DeviceCommandErrorHandler errorHandler)
 {
     if (device.IsSafeToStartCommand())
     {
         var executeCommandTaskData = new ExecuteDeviceCommandAsyncTaskData(device, ProtocolCommandId.LfsGetFileSystemStatusFlags)
         {
             OnSuccess = (c, p, r) => device.FileSystemFlags = (LfsDirtyFlags)r,
             OnFailure = errorHandler
         };
         executeCommandTaskData.StartTask(GetFileSystemFlags);
     }
 }
 /// <summary>
 /// Sets the device's owner.
 /// </summary>
 /// <param name="device">The device whose owner is to be set.</param>
 /// <param name="newOwner">The new owner for the device.</param>
 /// <param name="errorHandler">Error handler to report any problems.</param>
 public static void UpdateDeviceOwner(this Device device, string newOwner, DeviceCommandErrorHandler errorHandler)
 {
     if (device.IsSafeToStartCommand())
     {
         var executeCommandTaskData = new ExecuteDeviceCommandAsyncTaskData(device, ProtocolCommandId.MultistagePseudoCommand)
         {
             Title          = Resources.Strings.DeviceMultistageCommand_UpdateDeviceOwner_Title,
             FailureMessage = Resources.Strings.SetDeviceOwnerCommand_ErrorMessage,
             OnFailure      = errorHandler,
             OnSuccess      = (c, p, r) => device.Owner = newOwner,
             Data           = newOwner
         };
         executeCommandTaskData.StartTask(UpdateDeviceOwner);
     }
 }
示例#3
0
 /// <summary>
 /// Reformats the file system on a Locutus device.
 /// </summary>
 /// <param name="device">The target Locutus device whose file system is to be reformatted.</param>
 /// <param name="errorHandler">Error handler, used to report errors to the user.</param>
 /// <param name="onComplete">Action to execute when reformat operation is complete. This value may be <c>null</c>.</param>
 public static void ReformatFileSystem(this Device device, DeviceCommandErrorHandler errorHandler, Action onComplete)
 {
     if (device.IsSafeToStartCommand())
     {
         var reformatFileSystemTaskData = new ExecuteDeviceCommandAsyncTaskData(device, ProtocolCommandId.LfsReformatFileSystem)
         {
             OnSuccess = (c, p, r) =>
             {
                 var results = (Tuple <FileSystem, FileSystemStatistics>)r;
                 device.FileSystem           = results.Item1;
                 device.FileSystemStatistics = results.Item2;
                 if (onComplete != null)
                 {
                     onComplete();
                 }
             },
             OnFailure = errorHandler
         };
         reformatFileSystemTaskData.StartTask(ReformatFileSystem);
     }
 }
示例#4
0
 /// <summary>
 /// Retrieves the error and crash logs as needed from the target device.
 /// </summary>
 /// <param name="device">Target of the command.</param>
 /// <param name="onCompleteHandler">Called upon successful completion of the operation. This argument may be <c>null</c>.</param>
 /// <param name="errorHandler">Error handler, used to report errors to the user.</param>
 public static void GetErrorAndCrashLogs(this Device device, Action <ErrorLog, CrashLog> onCompleteHandler, DeviceCommandErrorHandler errorHandler)
 {
     if (device.IsSafeToStartCommand())
     {
         var executeCommandTaskData = new ExecuteDeviceCommandAsyncTaskData(device, ProtocolCommandId.MultistagePseudoCommand)
         {
             Title     = Resources.Strings.DeviceMultistageCommand_GetErrorAndCrashLogs_Title,
             OnSuccess = (c, p, r) =>
             {
                 var results = (Tuple <ErrorLog, CrashLog>)r;
                 if (onCompleteHandler != null)
                 {
                     onCompleteHandler(results.Item1, results.Item2);
                 }
                 device.ErrorLog = results.Item1;
                 device.CrashLog = results.Item2;
             },
             OnFailure = errorHandler
         };
         executeCommandTaskData.StartTask(GetErrorAndCrashLogs);
     }
 }
        /// <summary>
        /// Retrieves the file system from a Locutus device.
        /// </summary>
        /// <param name="device">The device whose file system is being retrieved.</param>
        /// <param name="operationTitle">Title to show in the progress bar.</param>
        /// <param name="onCompleteHandler">Called upon successful completion of the operation. This argument may be <c>null</c>.</param>
        /// <param name="errorHandler">Error handler, used to report errors to the user.</param>
        public static void RetrieveFileSystem(this Device device, string operationTitle, DeviceCommandCompleteHandler onCompleteHandler, DeviceCommandErrorHandler errorHandler)
        {
            if (device.IsSafeToStartCommand())
            {
                var executeCommandTaskData = new ExecuteDeviceCommandAsyncTaskData(device, ProtocolCommandId.LfsDownloadGlobalTables)
                {
                    Title = operationTitle,

                    OnFailure = errorHandler
                };
                executeCommandTaskData.OnSuccess = (c, p, r) =>
                {
                    device.FileSystem = (FileSystem)r;
                    if (onCompleteHandler != null)
                    {
                        onCompleteHandler(c, p, r);
                    }
                };
                executeCommandTaskData.StartTask(RetrieveFileSystem, 1.5);
            }
        }
示例#6
0
 /// <summary>
 /// Downloads a ROM to Locutus to be executed immediately.
 /// </summary>
 /// <param name="device">The target Locutus device to receive and execute the given ROM.</param>
 /// <param name="programRom">The ROM to play.</param>
 /// <param name="programName">The friendly name of the program to run.</param>
 /// <param name="errorHandler">Error handler, used to report errors to the user.</param>
 public static void DownloadAndPlay(this Device device, IRom programRom, string programName, DeviceCommandErrorHandler errorHandler)
 {
     if (device.IsSafeToStartCommand())
     {
         var executeCommandTaskData = new ExecuteDeviceCommandAsyncTaskData(device, ProtocolCommandId.DownloadAndPlay)
         {
             Title = string.Format(Resources.Strings.DeviceCommand_DownloadAndPlay_TitleFormat, programName),
             ProgressUpdateMode = ExecuteDeviceCommandProgressUpdateMode.Custom,
             FailureMessage     = string.Format(Resources.Strings.DeviceCommand_DownloadAndPlay_FailedFormat, programName),
             OnFailure          = errorHandler,
             Data = programRom
         };
         executeCommandTaskData.StartTask(DownloadAndPlay);
     }
 }
示例#7
0
 /// <summary>
 /// Executes a backup of the file system on a Locutus device.
 /// </summary>
 /// <param name="device">The device whose data is to be backed up.</param>
 /// <param name="backupDirectory">The directory in which to do the backup.</param>
 /// <param name="onCompleteHandler">Called upon successful completion of the operation. This argument may be <c>null</c>.</param>
 /// <param name="errorHandler">Function to call if an error occurs. If it returns <c>true</c>, the error is considered handled</param>
 public static void BackupFileSystem(this Device device, string backupDirectory, DeviceCommandCompleteHandler onCompleteHandler, DeviceCommandErrorHandler errorHandler)
 {
     if (device.IsSafeToStartCommand())
     {
         var executeCommandTaskData = new ExecuteDeviceCommandAsyncTaskData(device, ProtocolCommandId.MultistagePseudoCommand)
         {
             Title = Resources.Strings.DeviceMultistageCommand_BackupFileSystem_Title,
             ProgressUpdateMode = ExecuteDeviceCommandProgressUpdateMode.Custom,
             Data      = backupDirectory,
             OnSuccess = onCompleteHandler,
             OnFailure = errorHandler
         };
         executeCommandTaskData.StartTask(BackupFileSystem, true, 0.5);
     }
 }
        /// <summary>
        /// Downloads the host system's MenuLayout file system content to a Locutus device.
        /// </summary>
        /// <param name="device">The target Locutus device whose file system is to be updated to match that of the host PC.</param>
        /// <param name="hostMenuLayout">The host PC MenuLayout to push down to Locutus.</param>
        /// <param name="onCompleteHandler">Called upon successful completion of the operation. This argument may be <c>null</c>.</param>
        /// <param name="errorHandler">Error handler, used to report errors to the user.</param>
        public static void SyncHostToDevice(this Device device, MenuLayout hostMenuLayout, DeviceCommandCompleteHandler onCompleteHandler, DeviceCommandErrorHandler errorHandler)
        {
            if (device.IsSafeToStartCommand())
            {
                var executeCommandTaskData = new ExecuteDeviceCommandAsyncTaskData(device, ProtocolCommandId.MultistagePseudoCommand)
                {
                    Title = Resources.Strings.DeviceMultistageCommand_UpdatingFiles_Title,
                    ProgressUpdateMode = ExecuteDeviceCommandProgressUpdateMode.Custom,

                    // First bool is whether to reset menu position data (true => REMOVE IT).
                    // Second bool is whether to update root file name (false => RETAIN IT).
                    Data      = new Tuple <MenuLayout, bool, bool>(hostMenuLayout, true, false),
                    OnSuccess = onCompleteHandler,
                    OnFailure = errorHandler
                };
                executeCommandTaskData.StartTask(SyncHostToDevice, true, 1);
            }
        }
示例#9
0
 /// <summary>
 /// Remove the secondary firmware from the device (i.e. revert to factory version.).
 /// </summary>
 /// <param name="device">Target of the command.</param>
 /// <param name="onCompleteHandler">Called upon successful completion of the operation. This argument may be <c>null</c>.</param>
 /// <param name="errorHandler">Error handler, used to report errors to the user.</param>
 public static void RemoveSecondaryFirmware(this Device device, DeviceCommandCompleteHandler onCompleteHandler, DeviceCommandErrorHandler errorHandler)
 {
     if (device.IsSafeToStartCommand())
     {
         var executeCommandTaskData = new ExecuteDeviceCommandAsyncTaskData(device, ProtocolCommandId.FirmwareEraseSecondary)
         {
             OnSuccess = (c, p, r) => device.GetFirmwareRevisions(onCompleteHandler, errorHandler),
             OnFailure = errorHandler
         };
         executeCommandTaskData.StartTask(RemoveSecondaryFirmware);
     }
 }
示例#10
0
 /// <summary>
 /// Get the factory, active, and secondary firmware versions.
 /// </summary>
 /// <param name="device">Target of the command.</param>
 /// <param name="onCompleteHandler">Called upon successful completion of the operation. This argument may be <c>null</c>.</param>
 /// <param name="errorHandler">Error handler, used to report errors to the user.</param>
 public static void GetFirmwareRevisions(this Device device, DeviceCommandCompleteHandler onCompleteHandler, DeviceCommandErrorHandler errorHandler)
 {
     if (device.IsSafeToStartCommand())
     {
         var executeCommandTaskData = new ExecuteDeviceCommandAsyncTaskData(device, ProtocolCommandId.FirmwareGetRevisions)
         {
             OnSuccess = (c, p, r) =>
             {
                 device.FirmwareRevisions = (FirmwareRevisions)r;
                 if (onCompleteHandler != null)
                 {
                     onCompleteHandler(c, p, r);
                 }
             },
             OnFailure = errorHandler
         };
         executeCommandTaskData.StartTask(GetFirmwareRevisions);
     }
 }
 /// <summary>
 /// Updates the device configuration settings.
 /// </summary>
 /// <param name="device">The target Locutus device whose configuration is to be set.</param>
 /// <param name="newConfigurationFlags">The new configuration data.</param>
 /// <param name="onCompleteHandler">Success handler, used to report successful execution of the command.</param>
 /// <param name="errorHandler">Error handler, used to report errors to the user.</param>
 public static void SetConfiguration(this Device device, DeviceStatusFlags newConfigurationFlags, DeviceCommandCompleteHandler onCompleteHandler, DeviceCommandErrorHandler errorHandler)
 {
     if (device.IsSafeToStartCommand())
     {
         var executeCommandTaskData = new ExecuteDeviceCommandAsyncTaskData(device, ProtocolCommandId.SetConfiguration)
         {
             Data      = newConfigurationFlags,
             OnSuccess = onCompleteHandler,
             OnFailure = errorHandler
         };
         executeCommandTaskData.StartTask(SetConfiguration);
     }
 }
 /// <summary>
 /// Synchronizes the host system's MenuLayout to match the contents of a Locutus device.
 /// </summary>
 /// <param name="device">The Locutus device whose file system is to be imposed upon the Menu Layout of the host PC.</param>
 /// <param name="hostMenuLayout">The host PC MenuLayout to be brought in sync with Locutus.</param>
 /// <param name="ignoreInconsistentFileSystem">If <c>true</c> and the device's file system is in an inconsistent state, do the sync anyway.</param>
 /// <param name="onCompleteHandler">Called upon successful completion of the operation. This argument may be <c>null</c>.</param>
 /// <param name="errorHandler">Error handler, used to report errors to the user.</param>
 public static void SyncDeviceToHost(this Device device, MenuLayout hostMenuLayout, bool ignoreInconsistentFileSystem, DeviceCommandCompleteHandler onCompleteHandler, DeviceCommandErrorHandler errorHandler)
 {
     if (device.IsSafeToStartCommand())
     {
         ////var configuration = SingleInstanceApplication.Instance.GetConfiguration<Configuration>();
         var customData             = new Tuple <MenuLayout, bool>(hostMenuLayout, ignoreInconsistentFileSystem);
         var executeCommandTaskData = new ExecuteDeviceCommandAsyncTaskData(device, ProtocolCommandId.MultistagePseudoCommand)
         {
             Title = Resources.Strings.DeviceMultistageCommand_SyncingToFiles_Title,
             ProgressUpdateMode = ExecuteDeviceCommandProgressUpdateMode.Custom,
             Data      = customData,
             OnSuccess = onCompleteHandler,
             OnFailure = errorHandler
         };
         executeCommandTaskData.StartTask(SyncDeviceToHost, true, 1);
     }
 }
示例#13
0
 /// <summary>
 /// Update firmware on the device.
 /// </summary>
 /// <param name="device">Target of the command.</param>
 /// <param name="firmwarePath">Path on local file system to the firmware update.</param>
 /// <param name="newVersion">New version of the firmware, used for validation.</param>
 /// <param name="onCompleteHandler">Called upon successful completion of the operation. This argument may be <c>null</c>.</param>
 /// <param name="errorHandler">Error handler, used to report errors to the user.</param>
 public static void UpdateFirmware(this Device device, string firmwarePath, int newVersion, DeviceCommandCompleteHandler onCompleteHandler, DeviceCommandErrorHandler errorHandler)
 {
     if (device.IsSafeToStartCommand())
     {
         var data = new Tuple <string, int>(firmwarePath, newVersion);
         var executeCommandTaskData = new ExecuteDeviceCommandAsyncTaskData(device, ProtocolCommandId.MultistagePseudoCommand)
         {
             Title     = Resources.Strings.DeviceMultistageCommand_UpdateFirmware_Title,
             Data      = data,
             OnSuccess = (c, p, r) => device.GetFirmwareRevisions(onCompleteHandler, errorHandler),
             OnFailure = errorHandler
         };
         executeCommandTaskData.StartTask(UpdateFirmware, 0.55);
     }
 }
示例#14
0
 public static void GetErrorLog(this Device device, Action <ErrorLog> onCompleteHandler, DeviceCommandErrorHandler errorHandler)
 {
     if (device.IsSafeToStartCommand())
     {
         var executeCommandTaskData = new ExecuteDeviceCommandAsyncTaskData(device, ProtocolCommandId.DownloadErrorLog)
         {
             OnSuccess = (c, p, r) =>
             {
                 device.ErrorLog = (ErrorLog)r;
                 if (onCompleteHandler != null)
                 {
                     onCompleteHandler(device.ErrorLog);
                 }
             },
             OnFailure = errorHandler
         };
         executeCommandTaskData.StartTask(GetErrorLog);
     }
 }