Пример #1
0
        /// <summary>
        /// Saves the current <see cref="MshConsoleInfo"/> object to a file specified
        /// by <paramref name="path"/>. IsDirty is set to false once file is saved.
        /// </summary>
        /// <param name="path">
        /// If path is not an absolute path, then an absolute path is constructed by
        /// using Path.GetFullPath() API.
        /// </param>
        /// <exception cref="PSArgumentException">
        /// 1.Path does not specify proper file extension.
        /// </exception>
        /// <exception cref="PSArgumentNullException">
        /// 1. Path is null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// path contains one or more of the invalid characters defined in System.IO.Path.InvalidPathChars.
        /// </exception>
        internal void SaveAsConsoleFile(string path)
        {
            if (null == path)
            {
                throw PSTraceSource.NewArgumentNullException("path");
            }

            // Check whether the filename specified is an absolute path.
            string absolutePath = path;

            if (!Path.IsPathRooted(absolutePath))
            {
                absolutePath = Path.GetFullPath(Filename);
            }

            // Ignore case when looking for file extension.
            if (!absolutePath.EndsWith(StringLiterals.PowerShellConsoleFileExtension, StringComparison.OrdinalIgnoreCase))
            {
                s_mshsnapinTracer.TraceError("Console file {0} doesn't have the right extension {1}.", path, StringLiterals.PowerShellConsoleFileExtension);
                throw PSTraceSource.NewArgumentException("absolutePath", ConsoleInfoErrorStrings.BadConsoleExtension);
            }

            //ConsoleFileElement will write to file
            PSConsoleFileElement.WriteToFile(absolutePath, this.PSVersion, this.ExternalPSSnapIns);
            //update the console file variable
            Filename = absolutePath;
            IsDirty  = false;
        }
Пример #2
0
 internal void Save()
 {
     if (this.fileName == null)
     {
         throw PSTraceSource.NewInvalidOperationException("ConsoleInfoErrorStrings", "SaveDefaultError", new object[] { "" });
     }
     PSConsoleFileElement.WriteToFile(this.fileName, this.PSVersion, this.ExternalPSSnapIns);
     this.isDirty = false;
 }
Пример #3
0
        /// <summary>
        /// Saves the current <see cref="MshConsoleInfo"/> object to its console file.
        /// IsDirty is set to false once file is saved.
        /// </summary>
        /// <exception cref="PSInvalidOperationException">
        /// Msh is loaded with default mshsnapins. $console is currently empty.
        /// </exception>
        internal void Save()
        {
            if (null == Filename)
            {
                throw PSTraceSource.NewInvalidOperationException(ConsoleInfoErrorStrings.SaveDefaultError);
            }

            PSConsoleFileElement.WriteToFile(Filename, this.PSVersion, this.ExternalPSSnapIns);
            IsDirty = false;
        }
Пример #4
0
 internal void Save()
 {
     using (MshConsoleInfo.tracer.TraceMethod())
     {
         if (this.fileName == null)
         {
             throw MshConsoleInfo.tracer.NewInvalidOperationException("ConsoleInfoErrorStrings", "SaveDefaultError", (object)"");
         }
         PSConsoleFileElement.WriteToFile(this, this.fileName);
         this.isDirty = false;
     }
 }
Пример #5
0
 internal void SaveAsConsoleFile(string path)
 {
     using (MshConsoleInfo.tracer.TraceMethod())
     {
         string path1 = path != null ? path : throw MshConsoleInfo.tracer.NewArgumentNullException(nameof(path));
         if (!Path.IsPathRooted(path1))
         {
             path1 = Path.GetFullPath(this.fileName);
         }
         if (!path1.EndsWith(".psc1", StringComparison.OrdinalIgnoreCase))
         {
             MshConsoleInfo._mshsnapinTracer.TraceError("Console file {0} doesn't have the right extension {1}.", (object)path, (object)".psc1");
             throw MshConsoleInfo.tracer.NewArgumentException("absolutePath", "ConsoleInfoErrorStrings", "BadConsoleExtension", (object)"");
         }
         PSConsoleFileElement.WriteToFile(this, path1);
         this.fileName = path1;
         this.isDirty  = false;
     }
 }
Пример #6
0
        internal void SaveAsConsoleFile(string path)
        {
            if (path == null)
            {
                throw PSTraceSource.NewArgumentNullException("path");
            }
            string fullPath = path;

            if (!Path.IsPathRooted(fullPath))
            {
                fullPath = Path.GetFullPath(this.fileName);
            }
            if (!fullPath.EndsWith(".psc1", StringComparison.OrdinalIgnoreCase))
            {
                _mshsnapinTracer.TraceError("Console file {0} doesn't have the right extension {1}.", new object[] { path, ".psc1" });
                throw PSTraceSource.NewArgumentException("absolutePath", "ConsoleInfoErrorStrings", "BadConsoleExtension", new object[] { "" });
            }
            PSConsoleFileElement.WriteToFile(fullPath, this.PSVersion, this.ExternalPSSnapIns);
            this.fileName = fullPath;
            this.isDirty  = false;
        }