当前位置: 首页>>代码示例>>C#>>正文


C# Management.Path类代码示例

本文整理汇总了C#中System.Management.Path的典型用法代码示例。如果您正苦于以下问题:C# Path类的具体用法?C# Path怎么用?C# Path使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Path类属于System.Management命名空间,在下文中一共展示了Path类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetSessionStateItem

 internal override void SetSessionStateItem(Path name, object value, bool writeItem)
 {
     PSVariable variable = null;
     if (value != null)
     {
         variable = value as PSVariable;
         if (variable == null)
         {
             variable = new PSVariable(name, value);
         }
         else if (String.Compare(name, variable.Name, true, System.Globalization.CultureInfo.CurrentCulture) != 0)
         {
             PSVariable var = new PSVariable(name, variable.Value, variable.Options, variable.Attributes);
             var.Description = variable.Description;
             variable = var;
         }
     }
     else
     {
         variable = new PSVariable(name, null);
     }
     // TODO: can be Force'ed
     PSVariable item = base.SessionState.SessionStateGlobal.SetVariable(variable) as PSVariable;
     if (writeItem && (item != null))
     {
         WriteItemObject(item, item.Name, false);
     }
 }
开发者ID:b333z,项目名称:Pash,代码行数:28,代码来源:VariableProvider.cs

示例2: LoadModuleByName

 internal PSModuleInfo LoadModuleByName(string name, bool loadToGlobalScope, bool importMembers = true)
 {
     // TODO: where do we handle FileNotFoundExceptions etc?
     var path = new Path(name).NormalizeSlashes();
     if (name.Contains(path.CorrectSlash) || path.HasExtension())
     {
         // check if it's already loaded
         var moduleInfo = _executionContext.SessionState.LoadedModules.Get(path);
         if (moduleInfo != null)
         {
             return moduleInfo;
         }
         // load it otherwise
         moduleInfo = LoadModuleByPath(path);
         // modules are loaded either to global or module scope, never to local scope
         var targetScope = loadToGlobalScope ? ModuleIntrinsics.ModuleImportScopes.Global
                                             : ModuleIntrinsics.ModuleImportScopes.Module;
         _executionContext.SessionState.LoadedModules.Add(moduleInfo, targetScope);
         if (importMembers)
         {
             _executionContext.SessionState.LoadedModules.ImportMembers(moduleInfo, targetScope);
         }
         return moduleInfo;
     }
     // otherwise we'd need to look in our module paths for a module
     throw new NotImplementedException("Currently you can only a specific module file, not installed modules");
 }
开发者ID:mauve,项目名称:Pash,代码行数:27,代码来源:ModuleLoader.cs

示例3: SetSessionStateItem

 internal override void SetSessionStateItem(Path path, object value, bool writeItem)
 {
     if (value == null)
     {
         Environment.SetEnvironmentVariable(path, null);
     }
     else
     {
         if (value is DictionaryEntry)
         {
             value = ((DictionaryEntry)value).Value;
         }
         string str = value as string;
         if (str == null)
         {
             str = PSObject.AsPSObject(value).ToString();
         }
         Environment.SetEnvironmentVariable(path, str);
         DictionaryEntry item = new DictionaryEntry(path, str);
         if (writeItem)
         {
             WriteItemObject(item, path, false);
         }
     }
 }
开发者ID:b333z,项目名称:Pash,代码行数:25,代码来源:EnvironmentProvider.cs

示例4: CalculateFullPath

        public static string CalculateFullPath(Path curLocation, Path changeCommandStr)
        {
            // TODO: sburnicki rewrite that stuff with pathintrinsics
            var changeCommand = (changeCommandStr ?? string.Empty).NormalizeSlashes();
            var currentLocation = curLocation.NormalizeSlashes();

            bool applyParts = false;
            Path resultPath;

            // use the input 'changeCommand' path if it's 
            // 'rooted' otherwise we go from the currentLocation
            if (changeCommand.HasDrive())
            {
                // windows case where changeCommand == "/" or "\" but the currentLocation has a "C:" drive
                string currentLocationDrive = currentLocation.GetDrive();
                if (changeCommand.StartsWithSlash() && !changeCommand.GetDrive().Equals(currentLocationDrive, StringComparison.InvariantCultureIgnoreCase))
                {
                    resultPath = new Path(currentLocation.CorrectSlash, currentLocation.WrongSlash, string.Format("{0}:{1}", currentLocationDrive, changeCommand));
                }
                else
                {
                    resultPath = changeCommand;
                }
            }
            else
            {
                applyParts = true;
                resultPath = currentLocation;
            }

            var correctSeparator = Char.Parse(currentLocation.CorrectSlash);
            var changeParts = changeCommand.ToString().Split(correctSeparator).Where(s => !string.IsNullOrEmpty(s));

            foreach (var part in changeParts)
            {
                // ignore single dot as it does nothing...
                if (part == ".")
                {
                    continue;
                }

                // ignore trying to go up a dir from the root dir
                if (part == ".." && resultPath.IsRootPath())
                {
                    continue;
                }

                if (part == "..")
                {
                    resultPath = resultPath.GetParentPath(currentLocation.GetDrive());
                }
                else if (applyParts)
                {
                    resultPath = resultPath.Combine(part);
                }
            }

            return resultPath.ApplyDriveSlash();
        }
开发者ID:mauve,项目名称:Pash,代码行数:59,代码来源:PathNavigation.cs

示例5: GetSessionStateItem

        internal override object GetSessionStateItem(Path name)
        {
            // TODO: deal with empty path
            if (string.Equals("variable:" + name.CorrectSlash, name, StringComparison.CurrentCultureIgnoreCase))
                return true;

            return SessionState.SessionStateGlobal.GetVariable(name);
        }
开发者ID:b333z,项目名称:Pash,代码行数:8,代码来源:VariableProvider.cs

示例6: GetSessionStateItem

 internal override object GetSessionStateItem(Path name)
 {
     string environmentVariable = Environment.GetEnvironmentVariable(name);
     if (environmentVariable != null)
     {
         return new DictionaryEntry(name, environmentVariable);
     }
     return null;
 }
开发者ID:b333z,项目名称:Pash,代码行数:9,代码来源:EnvironmentProvider.cs

示例7: ShouldApplyNavigation

        public void ShouldApplyNavigation(string normalSlash, string currentLocation, string changeCommand, string expectedFullPath, string errorMessage)
        {
            var currLocation = new Path(normalSlash, normalSlash == "\\" ? "/" : "\\", currentLocation);
            var changePath = new Path(normalSlash, normalSlash == "\\" ? "/" : "\\", changeCommand);

            var result = PathNavigation.CalculateFullPath(currLocation, changePath);

            result.ShouldEqual(expectedFullPath, errorMessage);

        }
开发者ID:mauve,项目名称:Pash,代码行数:10,代码来源:PathNavigationTests.cs

示例8: GetSessionStateItem

 internal override object GetSessionStateItem(Path name)
 {
     Path path = PathIntrinsics.RemoveDriveName(name);
     path = path.TrimStartSlash();
     string environmentVariable = Environment.GetEnvironmentVariable(path);
     if (environmentVariable != null)
     {
         return new DictionaryEntry(path, environmentVariable);
     }
     return null;
 }
开发者ID:Ventero,项目名称:Pash,代码行数:11,代码来源:EnvironmentProvider.cs

示例9: LoadModuleByPath

        private PSModuleInfo LoadModuleByPath(Path path)
        {
            // ALWAYS derive from global scope: the Scope parameter only defines where stuff is imported to
            var sessionState = new SessionState(_executionContext.SessionStateGlobal.RootSessionState);
            sessionState.IsScriptScope = true;
            sessionState.PSVariable.Set("PSScriptRoot", path.GetDirectory());
            var moduleInfo = new PSModuleInfo(path, path.GetFileNameWithoutExtension(), sessionState);
            sessionState.SetModule(moduleInfo);

            LoadFileIntoModule(moduleInfo, path);
            return moduleInfo;
        }
开发者ID:mauve,项目名称:Pash,代码行数:12,代码来源:ModuleLoader.cs

示例10: NormalizeRelativePath

        protected override string NormalizeRelativePath(string path, string basePath)
        {
            var normPath = new Path(path).NormalizeSlashes();
            var normBase = new Path(basePath).NormalizeSlashes();
            if (!normPath.StartsWith(normBase))
            {
                var ex = new PSArgumentException("Path is outside of base path!", "PathOutsideBasePath",
                    ErrorCategory.InvalidArgument);
                WriteError(ex.ErrorRecord);
                return null;
            }

            return new Path(path.Substring(basePath.Length)).TrimStartSlash().ToString();
        }
开发者ID:mauve,项目名称:Pash,代码行数:14,代码来源:FileSystemProvider.cs

示例11: LoadFileIntoModule

        private void LoadFileIntoModule(PSModuleInfo moduleInfo, Path path)
        {
            // prevents accidental loops while loading a module
            moduleInfo.NestingDepth++;
            if (moduleInfo.NestingDepth > 10)
            {
                var msg = "The module is too deeply nested. A module can be only nested 10 times. Make sure to check" +
                    " the loading order of your module";
                throw new PSInvalidOperationException(msg, "Modules_ModuleTooDeeplyNested",
                    ErrorCategory.InvalidOperation);
            }

            moduleInfo.Path = path; // update path for nested modules
            var stringComparer = StringComparer.InvariantCultureIgnoreCase;
            var ext = path.GetExtension();
            if (_scriptExtensions.Contains(ext, stringComparer))
            {
                moduleInfo.ModuleType = ModuleType.Script;
                LoadScriptModule(moduleInfo, path); // actually load the script
            }
            else if (_binaryExtensions.Contains(ext, stringComparer))
            {
                moduleInfo.ModuleType = ModuleType.Binary;
                LoadBinaryModule(moduleInfo, path);
            }
            else if (_manifestExtensions.Contains(ext, stringComparer))
            {
                moduleInfo.ModuleType = ModuleType.Manifest;
                LoadManifestModule(moduleInfo, path);
            }
            else
            {
                var msg = "The extension '" + ext + "' is currently not supported";
                throw new PSInvalidOperationException(msg, "Modules_InvalidFileExtension",
                                                      ErrorCategory.InvalidOperation, null, false);
            }
            moduleInfo.ValidateExportedMembers();
        }
开发者ID:mauve,项目名称:Pash,代码行数:38,代码来源:ModuleLoader.cs

示例12: SetItem

 protected override void SetItem(Path name, object value)
 {
     throw new NotImplementedException();
 }
开发者ID:,项目名称:,代码行数:4,代码来源:

示例13: RenameItem

 protected override void RenameItem(Path name, Path newName)
 {
     throw new NotImplementedException();
 }
开发者ID:,项目名称:,代码行数:4,代码来源:

示例14: RemoveItem

 protected override void RemoveItem(Path path, bool recurse)
 {
     throw new NotImplementedException();
 }
开发者ID:,项目名称:,代码行数:4,代码来源:

示例15: NewItem

 protected override void NewItem(Path path, string type, object newItem)
 {
     throw new NotImplementedException();
 }
开发者ID:,项目名称:,代码行数:4,代码来源:


注:本文中的System.Management.Path类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。