示例#1
0
 public PromptForm(ref GHI.Glide.Display.Window window, ref DisplayDriver43 displayTE35, ref IDriveProvider sdCard, ref GHIElectronics.TinyCLR.Devices.UsbHost.UsbHostController usbHost) : base(ref window)
 {
     //this.usbClientEDP = usbClientEDP;
     this.usbHost     = usbHost;
     this.sdCard      = sdCard;
     this.displayTE35 = displayTE35;
 }
示例#2
0
        public static void DeregisterDriveProvider(IDriveProvider provider)
        {
            if (provider == null)
            {
                throw new ArgumentNullException();
            }

            lock (DriveInfo.driveProviders) {
                var n = default(string);

                foreach (DictionaryEntry p in DriveInfo.driveProviders)
                {
                    if (p.Value == provider)
                    {
                        n = (string)p.Key;
                        break;
                    }
                }

                if (n == null)
                {
                    throw new ArgumentException();
                }

                DriveInfo.driveProviders.Remove(n);
                DriveInfo.driveNames.Push(n);
            }
        }
示例#3
0
 public GvShell(ref DisplayDriver43 displayTE35, ref IDriveProvider sdCard, ref GHIElectronics.TinyCLR.Devices.UsbHost.UsbHostController usbHost)
 {
     this.displayTE35 = displayTE35;
     this.usbHost     = usbHost;
     //this.usbClientEDP = usbClientEdp;
     this.sdCard = sdCard;
     Screen      = displayTE35.Screen; //new Bitmap(ScreenWidth, ScreenHeight);
     ClearScreen();
     MaxLine     = ScreenHeight / 20;
     CurrentLine = 0;
     CurrentFont = Resources.GetFont(Resources.FontResources.NinaB);
     CurrentPath = "\\";// "\\SD\\";
     DataLines   = new ArrayList();
     for (int i = 0; i < MaxLine; i++)
     {
         DataLines.Add(string.Empty);
     }
     TypedCommand = string.Empty; if (basic == null)
     {
         if (basic == null)
         {
             basic              = new SBASIC();
             basic.Print       += Basic_Print;
             basic.ClearScreen += Basic_ClearScreen;
         }
     }
 }
示例#4
0
        public static IDriveProvider RegisterDriveProvider(IDriveProvider provider)
        {
            if (provider == null)
            {
                throw new ArgumentNullException();
            }

            var root = string.Empty;

            lock (DriveInfo.driveProviders) {
                if (DriveInfo.driveNames == null)
                {
                    var s = new Stack();

                    for (var i = 'Z'; i >= 'A'; i--)
                    {
                        s.Push(i + ":\\");
                    }

                    DriveInfo.driveNames = s;
                }

                root = (string)DriveInfo.driveNames.Pop();

                DriveInfo.driveProviders.Add(root, provider);
            }

            provider.Initialize(root);

            return(provider);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="StaticFileMiddleware"/> class.
        /// </summary>
        /// <param name="options">The <see cref="DefaultFilesOptions"/> used to configure the middleware.</param>
        public DefaultFilesMiddleware(DefaultFilesOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _options       = options;
            _driveProvider = _options.DriveProvider;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="StaticFileMiddleware"/> class.
        /// </summary>
        /// <param name="options">The <see cref="StaticFileOptions"/> used to configure the middleware.</param>
        public StaticFileMiddleware(StaticFileOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _options             = options;
            _driveProvider       = _options.DriveProvider;
            _contentTypeProvider = _options.ContentTypeProvider ?? new DefaultContentTypeProvider();
        }
示例#7
0
        public DriveInfo(string driveName)
        {
            lock (DriveInfo.driveProviders) {
                if (!DriveInfo.driveProviders.Contains(driveName))
                {
                    throw new ArgumentException();
                }

                this.provider = (IDriveProvider)DriveInfo.driveProviders[driveName];

                this.Name = driveName;
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="StaticFileMiddleware"/> class.
        /// </summary>
        /// <param name="loggerFactory">The factory used to create loggers.</param>
        /// <param name="options">The <see cref="StaticFileOptions"/> used to configure the middleware.</param>
        public StaticFileMiddleware(ILoggerFactory loggerFactory, StaticFileOptions options)
        {
            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _logger = loggerFactory.CreateLogger("Bytewizer.TinyCLR.Http");

            _options             = options;
            _driveProvider       = _options.DriveProvider;
            _contentTypeProvider = _options.ContentTypeProvider ?? new DefaultContentTypeProvider();
        }
示例#9
0
        public static void Initialize()
        {
            if (_initialized)
            {
                return;
            }

            lock (_lock)
            {
                if (_initialized)
                {
                    return;
                }

                Controller = StorageController.FromName(SC20260.StorageController.SdCard);
                Drive      = FileSystem.Mount(Controller.Hdc);
            }

            _initialized = true;
        }
示例#10
0
        public FileStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize)
        {
            // This will perform validation on path
            this._fileName = Path.GetFullPath(path);

            // make sure mode, access, and share are within range
            if (mode < FileMode.CreateNew || mode > FileMode.Append ||
                access < FileAccess.Read || access > FileAccess.ReadWrite ||
                share < FileShare.None || share > FileShare.ReadWrite)
            {
                throw new ArgumentOutOfRangeException();
            }

            // Get wantsRead and wantsWrite from access, note that they cannot both be false
            this.wantsRead  = (access & FileAccess.Read) == FileAccess.Read;
            this.wantsWrite = (access & FileAccess.Write) == FileAccess.Write;

            // You can't open for readonly access (wantsWrite == false) when
            // mode is CreateNew, Create, Truncate or Append (when it's not Open or OpenOrCreate)
            if (mode != FileMode.Open && mode != FileMode.OpenOrCreate && !this.wantsWrite)
            {
                throw new ArgumentException();
            }

            // We need to register the share information prior to the actual file open call (the NativeFileStream ctor)
            // so subsequent file operation on the same file will behave correctly
            this._fileRecord = FileSystemManager.AddToOpenList(this._fileName, (int)access, (int)share);

            try {
                this.drive = DriveInfo.GetForPath(this._fileName);
                var attributes = this.drive.GetAttributes(this._fileName);
                var exists     = ((uint)attributes != 0xFFFFFFFF);
                this.isReadOnly = (exists) ? (((FileAttributes)attributes) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly : false;

                // If the path specified is an existing directory, fail
                if (exists && ((((FileAttributes)attributes) & FileAttributes.Directory) == FileAttributes.Directory))
                {
                    throw new IOException("", (int)IOException.IOExceptionErrorCode.UnauthorizedAccess);
                }

                // The seek limit is 0 (the beginning of the file) for all modes except Append
                this._seekLimit = 0;


                switch (mode)
                {
                case FileMode.CreateNew:     // if the file exists, IOException is thrown
                    if (exists)
                    {
                        throw new IOException("", (int)IOException.IOExceptionErrorCode.PathAlreadyExists);
                    }
                    this._nativeFileStream = this.drive.OpenFile(this._fileName, bufferSize);
                    break;

                case FileMode.Create:     // if the file exists, it should be overwritten
                    this._nativeFileStream = this.drive.OpenFile(this._fileName, bufferSize);
                    if (exists)
                    {
                        this._nativeFileStream.Length = 0;
                    }
                    break;

                case FileMode.Open:     // if the file does not exist, IOException/FileNotFound is thrown
                    if (!exists)
                    {
                        throw new IOException("", (int)IOException.IOExceptionErrorCode.FileNotFound);
                    }
                    this._nativeFileStream = this.drive.OpenFile(this._fileName, bufferSize);
                    break;

                case FileMode.OpenOrCreate:     // if the file does not exist, it is created
                    this._nativeFileStream = this.drive.OpenFile(this._fileName, bufferSize);
                    break;

                case FileMode.Truncate:     // the file would be overwritten. if the file does not exist, IOException/FileNotFound is thrown
                    if (!exists)
                    {
                        throw new IOException("", (int)IOException.IOExceptionErrorCode.FileNotFound);
                    }
                    this._nativeFileStream        = this.drive.OpenFile(this._fileName, bufferSize);
                    this._nativeFileStream.Length = 0;
                    break;

                case FileMode.Append:     // Opens the file if it exists and seeks to the end of the file. Append can only be used in conjunction with FileAccess.Write
                    // Attempting to seek to a position before the end of the file will throw an IOException and any attempt to read fails and throws an NotSupportedException
                    if (access != FileAccess.Write)
                    {
                        throw new ArgumentException();
                    }
                    this._nativeFileStream = this.drive.OpenFile(this._fileName, bufferSize);
                    this._seekLimit        = this._nativeFileStream.Seek(0, SeekOrigin.End);
                    break;

                    // We've already checked the mode value previously, so no need for default
                    //default:
                    //    throw new ArgumentOutOfRangeException();
                }

                // Now that we have a valid NativeFileStream, we add it to the FileRecord, so it could gets clean up
                // in case an eject or force format
                this._fileRecord.NativeFileStream = this._nativeFileStream;

                // Make sure the requests (wantsRead / wantsWrite) matches the filesystem capabilities (canRead / canWrite)
                if ((this.wantsRead && !this.CanRead) || (this.wantsWrite && !this.CanWrite))
                {
                    throw new IOException("", (int)IOException.IOExceptionErrorCode.UnauthorizedAccess);
                }
            }
            catch {
                // something went wrong, clean up and re-throw the exception
                if (this._nativeFileStream != null)
                {
                    this._nativeFileStream.Close();
                }

                FileSystemManager.RemoveFromOpenList(this._fileRecord);

                throw;
            }
        }