Ejemplo n.º 1
0
        public static string ResolveFilePath(string filePath, InvokeGraphRequest command, bool isLiteralPath)
        {
            string path = null;

            try
            {
                var filePaths = new List <string>();
                if (isLiteralPath)
                {
                    filePaths.Add(
                        command.SessionState.Path.GetUnresolvedProviderPathFromPSPath(filePath, out _, out _));
                }
                else
                {
                    filePaths.AddRange(command.SessionState.Path.GetResolvedProviderPathFromPSPath(filePath, out _));
                }

                path = filePaths[0];
            }
            catch (ItemNotFoundException)
            {
                path = null;
            }

            return(path);
        }
        internal static void SaveStreamToFile(this Stream baseResponseStream, string filePath,
                                              InvokeGraphRequest invokeGraphRequest, CancellationToken token)
        {
            // If the web cmdlet should resume, append the file instead of overwriting.
            const FileMode fileMode = FileMode.Create;

            using (var output = new FileStream(filePath, fileMode, FileAccess.Write, FileShare.Read))
            {
                baseResponseStream.WriteToStream(output, invokeGraphRequest, token);
            }
        }