コード例 #1
0
        public void AddFile(string path, VirtualFileData virtualFile)
        {
            var fixedPath = FixPath(path, true);

            lock (_files)
            {
                if (FileExists(fixedPath))
                {
                    var isReadOnly = (_files[fixedPath].Attributes & FileAttributes.ReadOnly) ==
                                     FileAttributes.ReadOnly;
                    var isHidden = (_files[fixedPath].Attributes & FileAttributes.Hidden) == FileAttributes.Hidden;

                    if (isReadOnly || isHidden)
                    {
                        throw new UnauthorizedAccessException(string.Format(CultureInfo.InvariantCulture,
                                                                            StringResources.Manager.GetString("ACCESS_TO_THE_PATH_IS_DENIED") ?? throw new InvalidOperationException(), path));
                    }
                }

                var directoryPath = Path.GetDirectoryName(fixedPath);

                if (!_directory.Exists(directoryPath))
                {
                    AddDirectory(directoryPath);
                }

                _files[fixedPath] = virtualFile;
            }
        }
コード例 #2
0
        public void AddFile(string path, MockFileData mockFile)
        {
            string fixedPath = FixPath(path);

            lock (_files)
            {
                if (FileExists(fixedPath))
                {
                    bool isReadOnly = (_files[fixedPath].Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly;
                    bool isHidden   = (_files[fixedPath].Attributes & FileAttributes.Hidden) == FileAttributes.Hidden;

                    if (isReadOnly || isHidden)
                    {
                        throw new UnauthorizedAccessException(string.Format(CultureInfo.InvariantCulture, Properties.Resources.ACCESS_TO_THE_PATH_IS_DENIED, path));
                    }
                }

                string directoryPath = Path.GetDirectoryName(fixedPath);

                if (!_directory.Exists(directoryPath))
                {
                    AddDirectory(directoryPath);
                }

                _files[fixedPath] = mockFile;
            }
        }