Пример #1
0
        public void ThenAnArgumentExceptionIsRaised()
        {
            var environmentWrapper = new Mock <IEnvironmentWrapper>();

            environmentWrapper.Setup(x => x.GetEnvironmentVariable("PATH", PathTarget.User, string.Empty)).Returns("test");

            var subject = new PathWrapper(new NullLog(), environmentWrapper.Object);

            Assert.Throws <ArgumentNullException>(() => { subject.Remove(new DirectoryPath("test"), null); });
        }
        private MemoryMappedFileSystem(BufferStore buffers)
        {
            _buffers = buffers;

            _allocator = new SlabAllocator(buffers.Blocks.BlockSize, (int)buffers.Blocks.BlockCount);

            File      = new File(this);
            Directory = new Directory(this);
            Path      = new PathWrapper();
        }
Пример #3
0
        public static MemberInfo GetMemberInfoRecursively(Type searchType, string path,
                                                          BindingFlags bindingFlags = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
        {
            if (searchType == null)
            {
                return(null);
            }

            try
            {
                PathWrapper  pathWrapper       = new PathWrapper(path);
                MemberInfo   currentMemberInfo = null;
                MemberInfo[] memberInfoGroup;

                while (pathWrapper.CurrentPathPoint != null)
                {
                    memberInfoGroup = searchType.GetMember(pathWrapper.CurrentPathPoint, bindingFlags);
                    if (memberInfoGroup == null || memberInfoGroup.Length == 0)
                    {
                        return(null);
                    }
                    currentMemberInfo = memberInfoGroup[0];



                    if (currentMemberInfo is FieldInfo)
                    {
                        searchType = (currentMemberInfo as FieldInfo).FieldType;
                        if (searchType.IsGenericType)
                        {
                            searchType = searchType.GetGenericArguments()[0];
                            pathWrapper.Next(); //Skip "Array"
                            pathWrapper.Next(); //Skip "data[n]"
                        }
                    }
                    else
                    {
                        break;//Terminate iterating when encounter non-field member
                    }
                    pathWrapper.Next();
                }
                if (pathWrapper.Next())
                {
                    //Not finished yet
                    return(null);
                }

                return(currentMemberInfo);
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
                return(null);
            }
        }
Пример #4
0
        internal string GetDefaultStandbyFile(string databaseName)
        {
            if (string.IsNullOrEmpty(databaseName))
            {
                return(string.Empty);
            }
            var folderpath = GetDefaultBackupFolder();
            var filename   = SanitizeFileName(databaseName) + "_RollbackUndo_" + GetServerCurrentDateTime().ToString("yyyy-MM-dd_HH-mm-ss") + ".bak";

            return(PathWrapper.Combine(folderpath, filename));
        }
 public FileSystem()
 {
     DriveInfo         = new DriveInfoFactory(this);
     DirectoryInfo     = new DirectoryInfoFactory(this);
     FileInfo          = new FileInfoFactory(this);
     Path              = new PathWrapper(this);
     File              = new FileWrapper(this);
     Directory         = new DirectoryWrapper(this);
     FileStream        = new FileStreamFactory();
     FileSystemWatcher = new FileSystemWatcherFactory();
 }
Пример #6
0
        void Deserialize(XElement node)
        {
            if (!node.Name.LocalName.Equals("TestCase"))
            {
                throw new ServerErrorException();
            }

            Path          = new PathWrapper(node.Element("TestPath"));
            Name          = TestSerializer.ReadTestName(node.Element("TestName"));
            HasParameters = bool.Parse(node.Attribute("HasParameters").Value);
            HasChildren   = bool.Parse(node.Attribute("HasChildren").Value);
        }
Пример #7
0
        public void ThenThePathIsSetToTheMachineAndUserPath()
        {
            var environmentWrapper = new Mock <IEnvironmentWrapper>();

            environmentWrapper.Setup(x => x.GetEnvironmentVariable("PATH", PathTarget.User, string.Empty)).Returns("us;er");
            environmentWrapper.Setup(x => x.GetEnvironmentVariable("PATH", PathTarget.Machine, string.Empty)).Returns("mach;ine");

            var subject = new PathWrapper(new NullLog(), environmentWrapper.Object);

            subject.Reload();

            environmentWrapper.Verify(x => x.SetEnvironmentVariable("PATH", "mach;ine;us;er", PathTarget.Process), Times.Once);
        }
Пример #8
0
        public void ThenANewPathIsAddedWithTheValue()
        {
            var environmentWrapper = new Mock <IEnvironmentWrapper>();

            environmentWrapper.Setup(x => x.GetEnvironmentVariable("PATH", PathTarget.User, string.Empty)).Returns(string.Empty);

            var subject = new PathWrapper(new NullLog(), environmentWrapper.Object);

            subject.Add(new DirectoryPath("test"), new PathSettings {
                Target = PathTarget.User
            });

            environmentWrapper.Verify(x => x.SetEnvironmentVariable("PATH", "test", PathTarget.User), Times.Once);
        }
Пример #9
0
        public void ThenThePathIsNotModified()
        {
            var environmentWrapper = new Mock <IEnvironmentWrapper>();

            environmentWrapper.Setup(x => x.GetEnvironmentVariable("PATH", PathTarget.Machine, string.Empty)).Returns("test;test2");

            var subject = new PathWrapper(new NullLog(), environmentWrapper.Object);

            subject.Add("test", new PathSettings {
                Target = PathTarget.Machine
            });

            environmentWrapper.Verify(x => x.SetEnvironmentVariable(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <PathTarget>()), Times.Never);
        }
Пример #10
0
        public void ThenTheCorrectPathIsReturned()
        {
            var environmentWrapper = new Mock <IEnvironmentWrapper>();

            environmentWrapper.Setup(x => x.GetEnvironmentVariable("PATH", PathTarget.User, string.Empty)).Returns("us;er");
            environmentWrapper.Setup(x => x.GetEnvironmentVariable("PATH", PathTarget.Machine, string.Empty)).Returns("mach;ine");

            var subject = new PathWrapper(new NullLog(), environmentWrapper.Object);
            var result  = subject.Get(new PathSettings {
                Target = PathTarget.Machine
            });

            Assert.That(result, Is.EqualTo("mach;ine"));
        }
Пример #11
0
        public void ThenTheItemIsAddedToTheEndOfThePath()
        {
            var environmentWrapper = new Mock <IEnvironmentWrapper>();

            environmentWrapper.Setup(x => x.GetEnvironmentVariable("PATH", PathTarget.Process, string.Empty)).Returns("test;test2");

            var subject = new PathWrapper(new NullLog(), environmentWrapper.Object);

            subject.Add("value", new PathSettings {
                Target = PathTarget.Process
            });

            environmentWrapper.Verify(x => x.SetEnvironmentVariable("PATH", "test;test2;value", PathTarget.Process), Times.Once);
        }
        public void ThenTheItemIsRemovedFromThePath()
        {
            var environmentWrapper = new Mock <IEnvironmentWrapper>();

            environmentWrapper.Setup(x => x.GetEnvironmentVariable("PATH", PathTarget.Machine, string.Empty)).Returns("test;test2");

            var subject = new PathWrapper(new NullLog(), environmentWrapper.Object);

            subject.Remove("test", new PathSettings {
                Target = PathTarget.Machine
            });

            environmentWrapper.Verify(x => x.SetEnvironmentVariable("PATH", "test2", PathTarget.Machine), Times.Once);
        }
Пример #13
0
        public void Method_Should_Check_File_Exists()
        {
            string executableLocation = Path.GetDirectoryName(
                Assembly.GetExecutingAssembly().Location);
            string      pathA        = Path.Combine(executableLocation, "Test.txt");
            string      pathB        = Path.Combine(executableLocation, "Test.pdf");
            PathWrapper pathWrapperA = new PathWrapper(pathA);
            PathWrapper pathWrapperB = new PathWrapper(pathB);

            pathWrapperA.PathExists();
            pathWrapperA.PathExists();
            Assert.AreEqual(true, pathWrapperA.PathExists());
            Assert.AreEqual(false, pathWrapperB.PathExists());
        }
Пример #14
0
        public void ThenNothingIsRemovedFromThePath()
        {
            var environmentWrapper = new Mock <IEnvironmentWrapper>();

            environmentWrapper.Setup(x => x.GetEnvironmentVariable("PATH", PathTarget.Process, string.Empty)).Returns(string.Empty);

            var subject = new PathWrapper(new NullLog(), environmentWrapper.Object);

            subject.Remove(new DirectoryPath("test"), new PathSettings {
                Target = PathTarget.Process
            });

            environmentWrapper.Verify(x => x.SetEnvironmentVariable(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <PathTarget>()), Times.Never);
        }
Пример #15
0
        public void ThenTheEnvironmentVariableTargetIsDefaultedToUser()
        {
            var environmentWrapper = new Mock <IEnvironmentWrapper>();

            environmentWrapper.Setup(x => x.GetEnvironmentVariable("PATH", PathTarget.User, string.Empty)).Returns("test;test2");

            var subject = new PathWrapper(new NullLog(), environmentWrapper.Object);

            subject.Add("value", new PathSettings {
                Target = null
            });

            environmentWrapper.Verify(x => x.SetEnvironmentVariable("PATH", "test;test2;value", PathTarget.User), Times.Once);
        }
Пример #16
0
        /// <summary>
        /// Returns a default location for tail log backup
        /// If the first backup media is from Microsoft Azure, a Microsoft Azure url for the Tail log backup file is returned
        /// </summary>
        internal string GetDefaultTailLogbackupFile(string databaseName, RestorePlan restorePlan)
        {
            if (string.IsNullOrEmpty(databaseName) || restorePlan == null)
            {
                return(string.Empty);
            }
            if (restorePlan.TailLogBackupOperation != null && restorePlan.TailLogBackupOperation.Devices != null)
            {
                restorePlan.TailLogBackupOperation.Devices.Clear();
            }
            string      folderpath       = string.Empty;
            BackupMedia firstBackupMedia = this.GetFirstBackupMedia(restorePlan);
            string      filename         = this.SanitizeFileName(databaseName) + "_LogBackup_" + this.GetServerCurrentDateTime().ToString("yyyy-MM-dd_HH-mm-ss") + ".bak";

            if (firstBackupMedia != null && firstBackupMedia.MediaType == DeviceType.Url)
            {
                // the uri will use the same container as the container of the first backup media
                Uri uri;
                if (Uri.TryCreate(firstBackupMedia.MediaName, UriKind.Absolute, out uri))
                {
                    UriBuilder uriBuilder = new UriBuilder();
                    uriBuilder.Scheme = uri.Scheme;
                    uriBuilder.Host   = uri.Host;
                    if (uri.AbsolutePath.Length > 0)
                    {
                        string[] parts   = uri.AbsolutePath.Split('/');
                        string   newPath = string.Join("/", parts, 0, parts.Length - 1);
                        if (newPath.EndsWith("/"))
                        {
                            newPath = newPath.Substring(0, newPath.Length - 1);
                        }
                        uriBuilder.Host = uriBuilder.Host + newPath;
                    }
                    uriBuilder.Path = filename;
                    string urlFilename = uriBuilder.Uri.AbsoluteUri;
                    if (restorePlan.TailLogBackupOperation != null && restorePlan.TailLogBackupOperation.Devices != null)
                    {
                        restorePlan.TailLogBackupOperation.Devices.Add(new BackupDeviceItem(urlFilename, DeviceType.Url));
                    }
                    return(urlFilename);
                }
            }
            folderpath = this.GetDefaultBackupFolder();
            if (restorePlan.TailLogBackupOperation != null && restorePlan.TailLogBackupOperation.Devices != null)
            {
                restorePlan.TailLogBackupOperation.Devices.Add(new BackupDeviceItem(PathWrapper.Combine(folderpath, filename), DeviceType.File));
            }
            return(PathWrapper.Combine(folderpath, filename));
        }
        /// <summary>
        /// Returns the folder where result files should be written
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static string GetResultsFolder(this VisualStudio.TestTools.UnitTesting.TestContext context)
        {
            var path = Environment.GetEnvironmentVariable("RESULTS_FOLDER");

            if (string.IsNullOrEmpty(path))
            {
                path = context.Properties.ContainsKey("resultsFolder") ? context.Properties["resultsFolder"].ToString() : null;
            }
            if (string.IsNullOrEmpty(path))
            {
                path = PathWrapper.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                path = PathWrapper.Combine(path, "results");
            }
            return(path);
        }
Пример #18
0
        public static IFileSystem Fake(IEnumerable <string> fileList)
        {
            var files       = fileList.ToArray();
            var directories = AllDirectories(files).Distinct().ToArray();

            var fileSystem = Substitute.For <IFileSystem>();
            var path       = new PathWrapper(fileSystem);
            var file       = Substitute.For <IFile>();

            var directory = FakeDirectory(directories, path, files);

            fileSystem.Path.Returns(path);
            fileSystem.Directory.Returns(directory);
            fileSystem.File.Returns(file);
            return(fileSystem);
        }
        public FileManagerTests()
        {
            _environment = new Mock <IHostingEnvironment>();
            _formFile    = new Mock <IFormFile>();

            _pathWrapper       = new PathWrapper();
            _directoryWrapper  = new DirectoryWrapper();
            _fileWrapper       = new FileWrapper();
            _fileSystemWrapper = new FileSystemWrapper(_fileWrapper, _directoryWrapper, _pathWrapper);
            _sut = new FileManager(_environment.Object, _fileSystemWrapper);

            if (!Directory.Exists("C:\\UnitTestFolder"))
            {
                Directory.CreateDirectory("C:\\UnitTestFolder");
            }
        }
Пример #20
0
 void initialize()
 {
     leftWrappers   = new PathWrapper[ai.leftPaths.Length];
     centerWrappers = new PathWrapper[ai.centerPaths.Length];
     rightWrappers  = new PathWrapper[ai.rightPaths.Length];
     middleWrappers = new PathWrapper[ai.middlePaths.Length];
     for (int i = 0; i < leftWrappers.Length; i++)
     {
         leftWrappers[i] = new PathWrapper(ai.leftPaths[i], Vector3.Distance(this.transform.position, ai.leftPaths[i].transform.position));
     }
     for (int i = 0; i < centerWrappers.Length; i++)
     {
         centerWrappers[i] = new PathWrapper(ai.centerPaths[i], Vector3.Distance(this.transform.position, ai.centerPaths[i].transform.position));
     }
     for (int i = 0; i < rightWrappers.Length; i++)
     {
         rightWrappers[i] = new PathWrapper(ai.rightPaths[i], Vector3.Distance(this.transform.position, ai.rightPaths[i].transform.position));
     }
     for (int i = 0; i < middleWrappers.Length; i++)
     {
         middleWrappers[i] = new PathWrapper(ai.middlePaths[i], Vector3.Distance(this.transform.position, ai.middlePaths[i].transform.position));
     }
 }
        /// <summary>
        /// Get the initial directory for the browse folder dialog
        /// </summary>
        /// <param name="serverConnection">The connection to the server</param>
        /// <returns></returns>
        public static string GetBrowseStartPath(ServerConnection serverConnection)
        {
            string result = String.Empty;

            // if (US.Current.SSMS.TaskForms.ServerFileSystem.LastPath.TryGetValue(serverConnection.TrueName, out result))
            // {
            //     return result;
            // }

            if ((result == null) || (result.Length == 0))
            {
                // try and fetch the default location from SMO...
                Microsoft.SqlServer.Management.Smo.Server server = new Microsoft.SqlServer.Management.Smo.Server(serverConnection);
                result = server.Settings.DefaultFile;

                if ((result == null) || (result.Length == 0))
                {
                    // if the default file property doesn't return a string,
                    // use the location of the model database's data file.
                    Enumerator enumerator = new Enumerator();
                    Request    request    = new Request();
                    request.Urn    = "Server/Database[@Name='model']/FileGroup[@Name='PRIMARY']/File";
                    request.Fields = new string[1] {
                        "FileName"
                    };
                    DataSet dataSet = enumerator.Process(serverConnection, request);

                    if (0 < dataSet.Tables[0].Rows.Count)
                    {
                        string path = dataSet.Tables[0].Rows[0][0].ToString();
                        result = PathWrapper.GetDirectoryName(path);
                    }
                }
            }

            return(result);
        }
Пример #22
0
 private void UpdateDbFiles()
 {
     try
     {
         foreach (DbFile dbFile in this.DbFiles)
         {
             string fileName = this.GetTargetDbFilePhysicalName(dbFile.PhysicalName);
             if (!dbFile.DbFileType.Equals("Log"))
             {
                 if (!string.IsNullOrEmpty(this.DataFilesFolder))
                 {
                     dbFile.PhysicalNameRelocate = PathWrapper.Combine(this.DataFilesFolder, fileName);
                 }
                 else
                 {
                     dbFile.PhysicalNameRelocate = fileName;
                 }
             }
             else
             {
                 if (!string.IsNullOrEmpty(this.LogFilesFolder))
                 {
                     dbFile.PhysicalNameRelocate = PathWrapper.Combine(this.LogFilesFolder, fileName);
                 }
                 else
                 {
                     dbFile.PhysicalNameRelocate = fileName;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         this.ActiveException = ex;
     }
 }
 public GetIplayerDownloadFactory()
 {
     _pathWrapper = new PathWrapper();
 }
Пример #24
0
 public YoutubeDownloadFactory()
 {
     _pathWrapper = new PathWrapper();
 }
Пример #25
0
        public static object GetFieldObjectRecursively(object target, string path)
        {
            if (target == null)
            {
                return(null);
            }

            Type searchType = target.GetType();

            if (searchType == null)
            {
                return(null);
            }

            try
            {
                PathWrapper pathWrapper      = new PathWrapper(path);
                FieldInfo   currentFieldInfo = null;

                while (pathWrapper.CurrentPathPoint != null)
                {
                    if (searchType.IsGenericType)
                    {
                        searchType = searchType.GetGenericArguments()[0];

                        pathWrapper.Next();//Skip "Array"
                        string ppoint = pathWrapper.CurrentPathPoint;
                        ppoint = ppoint.Replace("data[", "");
                        ppoint = ppoint.Replace("]", "");
                        int index = int.Parse(ppoint);
                        target = (target as IList)[index];
                        pathWrapper.Next();//Skip "data[n]"

                        if (string.IsNullOrEmpty(pathWrapper.CurrentPathPoint))
                        {
                            return(target);
                        }
                        else
                        {
                            currentFieldInfo = searchType.GetField(pathWrapper.CurrentPathPoint);
                            if (currentFieldInfo == null)
                            {
                                return(null);
                            }

                            target = currentFieldInfo.GetValue((target as IList)[index]);
                        }
                    }
                    else
                    {
                        currentFieldInfo = searchType.GetField(pathWrapper.CurrentPathPoint);
                        if (currentFieldInfo == null)
                        {
                            return(null);
                        }

                        target = currentFieldInfo.GetValue(target);
                    }

                    if (target == null)
                    {
                        return(null);
                    }

                    searchType = target.GetType();

                    pathWrapper.Next();
                }

                return(target);
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
                return(null);
            }
        }
Пример #26
0
 public PluginHandlerTest()
 {
     fileSystem  = new System.IO.Abstractions.FileSystem();
     pathWrapper = new PathWrapper(fileSystem);
 }
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        internal static void Initialize()
        {
            TraceService.WriteLine("NinjaController::Initialize");

            try
            {
                if (initialized == false)
                {
                    TraceService.WriteLine("NinjaController::Initialize AutoRegister");

                    //// only auto register classes in this assembly.
                    TinyIoCContainer container = TinyIoCContainer.Current;

                    string location = Assembly.GetExecutingAssembly().Location;

                    TraceService.WriteLine("NinjaController::Initialize Assembly Location=" + location);

                    PathBase pathBase  = new PathWrapper();
                    string   directory = pathBase.GetDirectoryName(location);

                    TraceService.WriteLine("NinjaController::Initialize NinjaCoder.MvvmCross.dll");

                    string path = directory + @"\NinjaCoder.MvvmCross.dll";

                    if (File.Exists(path))
                    {
                        //// NinjaCoder for MvvmCross interfaces.
                        container.AutoRegister(Assembly.LoadFrom(path));
                    }
                    else
                    {
                        TraceService.WriteError(path + " does not exist");
                    }

                    //// we only want one instance of the VisualStudio class.
                    container.Register <VisualStudioService>().AsSingleton();

                    //// register the types that aren't auto-registered by TinyIoC.
                    container.Register <ITranslator <string, CodeConfig> >(new CodeConfigTranslator());
                    container.Register <ITranslator <string, CodeSnippet> >(new CodeSnippetTranslator());
                    container.Register <ITranslator <XElement, Plugin> >(new PluginTranslator());
                    container.Register <ITranslator <string, Plugins> >(new PluginsTranslator());
                    container.Register <ITranslator <string, CommandsList> >(new CommandsListTranslator());
                    container.Register <ITranslator <string, CustomRenderers> >(new CustomRenderersTranslator());

                    //// file io abstraction
                    container.Register <IFileSystem>(new FileSystem());

                    TraceService.WriteLine("NinjaController::Initialize Scorchio.Infrastructure.dll");

                    path = directory + @"\Scorchio.Infrastructure.dll";

                    if (File.Exists(path))
                    {
                        //// Scorchio.Infrastructure interfaces.
                        container.AutoRegister(Assembly.LoadFrom(path));
                    }
                    else
                    {
                        TraceService.WriteError(path + " does not exist");
                    }

                    TraceService.WriteLine("NinjaController::Initialize AccentTranslator");

                    //// register the types that aren't auto-registered by TinyIoC.
                    container.Register <ITranslator <IList <Accent>, IEnumerable <AccentColor> > >(new AccentTranslator());

                    TraceService.WriteLine("NinjaController::Initialize Scorchio.VisualStudio.dll");

                    path = directory + @"\Scorchio.VisualStudio.dll";

                    if (File.Exists(path))
                    {
                        //// Scorchio.VisualStudio interfaces.
                        container.AutoRegister(Assembly.LoadFrom(path));
                    }
                    else
                    {
                        TraceService.WriteError(path + " does not exist");
                    }

                    initialized = true;
                }

                TraceService.WriteLine("NinjaController::Initialize end");
            }
            catch (ReflectionTypeLoadException exception)
            {
                TraceService.WriteError("ReflectionTypeLoadException=" + exception);

                foreach (Exception ex in exception.LoaderExceptions)
                {
                    TraceService.WriteError("ReflectionTypeLoadException=" + ex);
                }
            }
            catch (Exception exception)
            {
                TraceService.WriteError("Exception=" + exception);

                if (exception.InnerException != null)
                {
                    ReflectionTypeLoadException loadException = exception.InnerException as ReflectionTypeLoadException;

                    if (loadException != null)
                    {
                        foreach (Exception ex in loadException.LoaderExceptions)
                        {
                            TraceService.WriteError("ReflectionTypeLoadException=" + ex);
                        }
                    }
                }
            }
        }