Exemplo n.º 1
0
 private LfsOperationData(LfsOperations operation, LfsEntityType type)
 {
     Operation        = operation;
     Type             = type;
     FileSystemNumber = InvalidFileSystemNumber;
     Uid = InvalidUid;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a new instance of the exception.
 /// </summary>
 /// <param name="message">The error message that explains the reason for the exception.</param>
 /// <param name="entityType">The kind of file system entity the error pertains to.</param>
 /// <param name="globalFileSystemNumber">The file system number (GDN, GFN, GKN) of the entry that the error pertains to.</param>
 /// <param name="targetDeviceId">Unique ID of the target device of the operation when the error occurred. If <c>null</c> or empty, target device information is not available, or no target was involved.</param>
 /// <param name="innerException">The exception that is the cause of the current exception, or <c>null</c> if no inner exception is specified.</param>
 protected FailedOperationException(string message, LfsEntityType entityType, uint globalFileSystemNumber, string targetDeviceId, System.Exception innerException)
     : base(message, innerException)
 {
     EntityType             = entityType;
     GlobalFileSystemNumber = globalFileSystemNumber;
     TargetDeviceId         = targetDeviceId;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of GatherDifferencesDescriptor.
 /// </summary>
 /// <param name="entityType">The type of the file system entities this descriptor works with.</param>
 /// <param name="targetFileSystemTable">The LFS file system table to be compared against a reference version.</param>
 /// <param name="comparer">The comparison function to use to determine if a reference and target file system entity are different.</param>
 /// <param name="validator">The validation function to use to determine if an entry is valid.</param>
 /// <param name="ignorer">The function to use to determine whether to ignore an entry for computing differences.</param>
 public GatherDifferencesDescriptor(LfsEntityType entityType, FixedSizeCollection <T> targetFileSystemTable, FileSystemEntryComparer <T> comparer, FileSystemEntryValidator <T> validator, Predicate <T> ignorer)
 {
     TargetFileSystemTable = targetFileSystemTable;
     Compare    = comparer;
     Validate   = validator ?? AlwaysValid;
     Ignore     = ignorer ?? NeverIgnore;
     EntityType = entityType;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="INTV.LtoFlash.Model.LfsUpdateOperation"/> class.
 /// </summary>
 /// <param name="fileSystem">The file system.</param>
 /// <param name="operation">The nature of the operation.</param>
 /// <param name="entityType">The kind of file system entity involved on the operation.</param>
 /// <param name="entityId">The identifier (GDN, GFN, GKN) of the entity involved inthe operation.</param>
 public LfsUpdateOperation(FileSystem fileSystem, LfsOperations operation, LfsEntityType entityType, ushort entityId)
 {
     FileSystem  = fileSystem;
     Operation   = operation;
     Directories = new HashSet <byte>();
     Files       = new HashSet <ushort>();
     Forks       = new HashSet <ushort>();
     Failures    = new HashSet <LfsOperationFailure>();
 }
Exemplo n.º 5
0
        /// <summary>
        /// Wraps the given exception as the InnerException if it is not already a FailedOperationException.
        /// </summary>
        /// <param name="error">The error to wrap.</param>
        /// <param name="entityType">The kind of file system entity the error pertains to.</param>
        /// <param name="globalFileSystemNumber">The file system number (GDN, GFN, GKN) of the entry that the error pertains to.</param>
        /// <param name="targetDeviceId">The unique ID of the device involved in the operation. If empty or <c>null</c>, the error is not targeting actual hardware.</param>
        /// <returns>If <paramref name="error"/> is a <see cref="FailedOperationException"/>, then it is returned unchanged, otherwise it is the inner exception for a new <see cref="FailedOperationException"/>.</returns>
        public static FailedOperationException WrapIfNeeded(System.Exception error, LfsEntityType entityType, uint globalFileSystemNumber, string targetDeviceId)
        {
            var failedComparison = error as FailedOperationException;

            if (failedComparison == null)
            {
                failedComparison = new FailedOperationException(error.Message, entityType, globalFileSystemNumber, targetDeviceId, error);
            }
            return(failedComparison);
        }
 /// <summary>
 /// Initializes a new instance of of the InconsistentFileSystemException class.
 /// </summary>
 /// <param name="entityType">The type of the file system entity that could not be located.</param>
 /// <param name="globalFileSystemNumber">The global file system identifier of the entity that could not be located.</param>
 /// <param name="targetDeviceId">The unique ID of the device whose file system is in an inconsistent state.</param>
 /// <param name="innerException">The exception that is the cause of the current exception, or <c>null</c> if no such exception exists.</param>
 public InconsistentFileSystemException(LfsEntityType entityType, uint globalFileSystemNumber, string targetDeviceId, System.Exception innerException)
     : this(string.Format(Resources.Strings.FileSystem_InconsistencyError_Format, entityType, globalFileSystemNumber), entityType, globalFileSystemNumber, targetDeviceId, innerException)
 {
 }
 /// <summary>
 /// Initializes a new instance of of the InconsistentFileSystemException class.
 /// </summary>
 /// <param name="entityType">The type of the file system entity that could not be located.</param>
 /// <param name="globalFileSystemNumber">The global file system identifier of the entity that could not be located.</param>
 /// <param name="targetDeviceId">The unique ID of the device whose file system is in an inconsistent state.</param>
 /// <param name="customErrorFormat">Custom error format for the message. Must have {0} for entity type and {1} for global file system number.</param>
 public InconsistentFileSystemException(LfsEntityType entityType, uint globalFileSystemNumber, string targetDeviceId, string customErrorFormat)
     : this(string.Format(customErrorFormat, entityType, globalFileSystemNumber), entityType, globalFileSystemNumber, targetDeviceId, null)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="INTV.LtoFlash.InconsistentFileSystemException"/> class.
 /// </summary>
 /// <param name="message">Custom message for the inconsistency.</param>
 /// <param name="entityType">The type of the file system entity that could not be located.</param>
 /// <param name="globalFileSystemNumber">The global file system identifier of the entity that could not be located.</param>
 /// <param name="targetDeviceId">The unique ID of the device whose file system is in an inconsistent state.</param>
 public InconsistentFileSystemException(string message, LfsEntityType entityType, uint globalFileSystemNumber, string targetDeviceId)
     : this(message, entityType, globalFileSystemNumber, targetDeviceId, null)
 {
 }
 /// <summary>
 /// Initializes a new instance of of the InconsistentFileSystemException class.
 /// </summary>
 /// <param name="entityType">The type of the file system entity that could not be located.</param>
 /// <param name="globalFileSystemNumber">The global file system identifier of the entity that could not be located.</param>
 /// <param name="targetDeviceId">The unique ID of the device whose file system is in an inconsistent state.</param>
 public InconsistentFileSystemException(LfsEntityType entityType, uint globalFileSystemNumber, string targetDeviceId)
     : this(entityType, globalFileSystemNumber, targetDeviceId, Resources.Strings.FileSystem_InconsistencyError_Format)
 {
 }
Exemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of GatherDifferencesDescriptor.
 /// </summary>
 /// <param name="entityType">The type of the file system entities this descriptor works with.</param>
 /// <param name="targetFileSystemTable">The LFS file system table to be compared against a reference version.</param>
 /// <param name="comparer">The comparison function to use to determine if a reference and target file system entity are different.</param>
 public GatherDifferencesDescriptor(LfsEntityType entityType, FixedSizeCollection <T> targetFileSystemTable, FileSystemEntryComparer <T> comparer)
     : this(entityType, targetFileSystemTable, comparer, AlwaysValid)
 {
 }
 /// <summary>
 /// Initializes a new instance of DeleteOperationData.
 /// </summary>
 /// <param name="taskData">Task data for error reporting.</param>
 /// <param name="targetType">The entry type being deleted.</param>
 public DeleteOperationData(ExecuteDeviceCommandAsyncTaskData taskData, LfsEntityType targetType)
     : base(LfsOperations.Remove, taskData)
 {
     TargetType = targetType;
 }
 /// <summary>
 /// If the operation should update the file system's dirty flags, and hasn't done so already, do so.
 /// </summary>
 /// <param name="currentDirtyFlags">The current dirty flags on the file system.</param>
 /// <param name="fileSystem">The file system being updated.</param>
 /// <param name="taskData">Task data for displaying updates, tracking success, etc.</param>
 /// <param name="globalFileSystemNumber">If an error occurs, the entity type and its global file system number value are used to report the error.</param>
 /// <param name="operation">The kind of file system operation being done.</param>
 /// <param name="targetType">The kind of file system entity involved in the operation.</param>
 /// <returns>The new dirty flags.</returns>
 private static LfsDirtyFlags UpdateFileSystemDirtyState(this LfsDirtyFlags currentDirtyFlags, FileSystem fileSystem, ExecuteDeviceCommandAsyncTaskData taskData, uint globalFileSystemNumber, LfsOperations operation, LfsEntityType targetType)
 {
     if (taskData.Succeeded && !currentDirtyFlags.HasFlag(LfsDirtyFlags.FileSystemUpdateInProgress))
     {
         currentDirtyFlags |= LfsDirtyFlags.FileSystemUpdateInProgress;
         taskData.Succeeded = SetDirtyFlags.Create(currentDirtyFlags).Execute <bool>(taskData.Device.Port, taskData);
     }
     if (!taskData.Succeeded && currentDirtyFlags.HasFlag(LfsDirtyFlags.FileSystemUpdateInProgress))
     {
         var errorFormatString = Resources.Strings.FileSystem_InconsistencyError_Format;
         if (operation == LfsOperations.Remove)
         {
             errorFormatString = Resources.Strings.FileSystem_InconsistencyError_Deleting_Format;
         }
         else if (operation == LfsOperations.Add)
         {
             errorFormatString = Resources.Strings.FileSystem_InconsistencyError_Creating_Format;
         }
         else if (operation == LfsOperations.Update)
         {
             errorFormatString = Resources.Strings.FileSystem_InconsistencyError_Updating_Format;
         }
         throw new InconsistentFileSystemException(targetType, globalFileSystemNumber, errorFormatString);
     }
     fileSystem.Status = currentDirtyFlags;
     return(currentDirtyFlags);
 }
Exemplo n.º 13
0
 private LfsOperationData(LfsOperations operation, LfsEntityType type, IGlobalFileSystemEntry fileSystemEntry)
     : this(operation, type)
 {
     Uid = fileSystemEntry.Uid;
     FileSystemNumber = InvalidFileSystemNumber;
 }
Exemplo n.º 14
0
 /// <summary>
 /// Initializes a new instance of GatherDifferencesDescriptor.
 /// </summary>
 /// <param name="entityType">The type of the file system entities this descriptor works with.</param>
 /// <param name="targetFileSystemTable">The LFS file system table to be compared against a reference version.</param>
 /// <param name="comparer">The comparison function to use to determine if a reference and target file system entity are different.</param>
 /// <param name="validator">The validation function to use to determine if an entry is valid.</param>
 public GatherDifferencesDescriptor(LfsEntityType entityType, FixedSizeCollection <T> targetFileSystemTable, FileSystemEntryComparer <T> comparer, FileSystemEntryValidator <T> validator)
     : this(entityType, targetFileSystemTable, comparer, validator, NeverIgnore)
 {
 }
 /// <summary>
 /// Initializes a new instance of of the InconsistentFileSystemException class.
 /// </summary>
 /// <param name="message">Custom message for the inconsistency.</param>
 /// <param name="entityType">The type of the file system entity that could not be located.</param>
 /// <param name="globalFileSystemNumber">The global file system identifier of the entity that could not be located.</param>
 /// <param name="targetDeviceId">The unique ID of the device whose file system is in an inconsistent state.</param>
 /// <param name="innerException">The exception that is the cause of the current exception, or <c>null</c> if no such exception exists.</param>
 private InconsistentFileSystemException(string message, LfsEntityType entityType, uint globalFileSystemNumber, string targetDeviceId, System.Exception innerException)
     : base(message, entityType, globalFileSystemNumber, targetDeviceId, innerException)
 {
 }
Exemplo n.º 16
0
        /// <summary>
        /// Record a failed update operation.
        /// </summary>
        /// <param name="entryType">The kind of entry whose update operation failed.</param>
        /// <param name="id">The LFS identifier of the entity.</param>
        /// <param name="name">User-facing name of the entity.</param>
        /// <param name="exception">The error that occurred.</param>
        /// <param name="targetDeviceId">The unique ID of the target device involved in the operation.</param>
        public void RecordFailure(LfsEntityType entryType, ushort id, string name, Exception exception, string targetDeviceId)
        {
            var error = FailedOperationException.WrapIfNeeded(exception, entryType, id, targetDeviceId);

            RecordFailure(name, error);
        }
 /// <summary>
 /// Initializes a new instance of of the InconsistentFileSystemException class.
 /// </summary>
 /// <param name="entityType">The type of the file system entity that could not be located.</param>
 /// <param name="targetDeviceId">The unique ID of the device whose file system is in an inconsistent state.</param>
 public InconsistentFileSystemException(LfsEntityType entityType, string targetDeviceId)
     : this(string.Format(System.Globalization.CultureInfo.CurrentCulture, Resources.Strings.FileSystem_InconsistencyError_MissingEntry_Format, entityType), entityType, uint.MaxValue, targetDeviceId)
 {
 }
Exemplo n.º 18
0
        /// <summary>
        /// Checks to see if the given destination can accept more items.
        /// </summary>
        /// <param name="destination">The destination for another file system entry.</param>
        /// <param name="entityType">The type if the file system entry (fork, file, directory).</param>
        /// <param name="count">The number of new entries of the given type.</param>
        /// <param name="addingNewItems">If <c>true</c>, indicates new entries are being added; if <c>false</c>, items are moving from one location to another.</param>
        /// <param name="reasonForFailure">Receives error description.</param>
        /// <returns><c>true</c> if <paramref name="destination"/> is able to accept at least <paramref name="count"/> new items.</returns>
        internal static bool FileSystemCanAcceptMoreItems(IFile destination, LfsEntityType entityType, int count, bool addingNewItems, out string reasonForFailure)
        {
            reasonForFailure = string.Empty;
            var directory = destination as Folder;
            var file      = destination as FileNode;
            var canAccept = (directory != null) || (file != null);

            if (canAccept)
            {
                var destinationType = (directory != null) ? LfsEntityType.Directory : ((file != null) ? LfsEntityType.File : LfsEntityType.Unknown);
                System.Diagnostics.Debug.Assert(destinationType != LfsEntityType.Unknown, "Unknown destination for new file system entry.");
                var fileSystem = file.FileSystem;
                switch (entityType)
                {
                case LfsEntityType.Directory:
                    // If we're operating on directories, they must go inside another directory.
                    canAccept = (count + directory.Size) <= FileSystemConstants.MaxItemCount;
                    if (!canAccept)
                    {
                        reasonForFailure = string.Format(Resources.Strings.AddItemRejected_TooManyFiles_Format, FileSystemConstants.MaxItemCount);
                    }
                    if (addingNewItems && canAccept)
                    {
                        // New directory requires space in GDT and GFT.
                        canAccept &= (count + fileSystem.Directories.ItemsInUse) <= GlobalDirectoryTable.TableSize;
                        if (!canAccept)
                        {
                            reasonForFailure = string.Format(Resources.Strings.AddItemRejected_TooManyFolders_Format, GlobalDirectoryTable.TableSize);
                        }
                        if (canAccept)
                        {
                            canAccept &= (count + fileSystem.Files.ItemsInUse) <= GlobalFileTable.TableSize;
                            if (!canAccept)
                            {
                                reasonForFailure = string.Format(Resources.Strings.AddItemRejected_TooManyFileSystemFiles_Format, GlobalFileTable.TableSize);
                            }
                        }
                    }
                    break;

                case LfsEntityType.File:
                    // If we're operating on files, they must go inside a directory.
                    canAccept = (count + directory.Size) <= FileSystemConstants.MaxItemCount;
                    if (!canAccept)
                    {
                        reasonForFailure = string.Format(Resources.Strings.AddItemRejected_TooManyFiles_Format, FileSystemConstants.MaxItemCount);
                    }
                    if (addingNewItems && canAccept)
                    {
                        // New files require space in the GFT and GKT -- useful files typically use *at least* one fork for our purposes,
                        // though, strictly speaking, not all files require a fork. (E.g. the file for the root directory.)
                        canAccept &= (count + fileSystem.Files.ItemsInUse) <= GlobalFileTable.TableSize;
                        if (!canAccept)
                        {
                            reasonForFailure = string.Format(Resources.Strings.AddItemRejected_TooManyFileSystemFiles_Format, GlobalFileTable.TableSize);
                        }
                        if (canAccept)
                        {
                            canAccept &= (count + fileSystem.Forks.ItemsInUse) <= GlobalForkTable.TableSize;
                            if (!canAccept)
                            {
                                reasonForFailure = string.Format(Resources.Strings.AddItemRejected_TooManyForks_Format, GlobalForkTable.TableSize);
                            }
                        }
                    }
                    break;

                case LfsEntityType.Fork:
                    // Forks go within files - so we only need to check fork table.
                    if (addingNewItems)
                    {
                        canAccept = (count + fileSystem.Forks.ItemsInUse) <= GlobalForkTable.TableSize;
                        if (!canAccept)
                        {
                            reasonForFailure = string.Format(Resources.Strings.AddItemRejected_TooManyForks_Format, GlobalForkTable.TableSize);
                        }
                    }
                    break;

                default:
                    canAccept        = false;
                    reasonForFailure = string.Format(Resources.Strings.AddItemRejected_UnknownFileSystemEntityType_Format, entityType);
                    break;
                }
            }
            else
            {
                if ((directory == null) && (file == null))
                {
                    reasonForFailure = Resources.Strings.AddItemRejected_InvalidFolderAndFile;
                }
                else if (directory == null)
                {
                    reasonForFailure = Resources.Strings.AddItemRejected_InvalidFolder;
                }
                else if (file == null)
                {
                    reasonForFailure = Resources.Strings.AddItemRejected_InvalidFile;
                }
            }
            return(canAccept);
        }
Exemplo n.º 19
0
 /// <summary>
 /// Initialize a new instance of IncompatibleRomException.
 /// </summary>
 /// <param name="rom">The ROM that cannot execute on the target device.</param>
 /// <param name="requiredDeviceId">Unique ID of the device needed to execute the ROM.</param>
 /// <param name="targetDeviceId">Unique ID of the device upon which ROM execution will fail.</param>
 /// <param name="entityType">The type of the file system entity that is incompatible.</param>
 /// <param name="globalFileSystemNumber">The global file system identifier of the entity that is incompatible.</param>
 public IncompatibleRomException(IRom rom, string requiredDeviceId, string targetDeviceId, LfsEntityType entityType, uint globalFileSystemNumber)
     : base(string.Format(Resources.Strings.IncompatibleRomException_MessageFormat, rom.RomPath, requiredDeviceId, targetDeviceId), entityType, globalFileSystemNumber, targetDeviceId, null)
 {
     Rom = rom;
     RequiredDeviceId = requiredDeviceId;
 }