예제 #1
0
        public IContentWriter GetContentWriter(string path)
        {
            var item = GetDynamicParamValue(ItemParam, (Item)null);

            if (item == null)
            {
                item = GetItemInternal(path, false).FirstOrDefault();

                if (item == null && !ItemContentReaderWriterBase.IsMediaPath(path))
                {
                    WriteInvalidPathError(path);
                    return(null);
                }
            }
            else
            {
                path = item.GetProviderPath();
            }

            var extension = GetDynamicParamValue(ExtensionParam, string.Empty);
            var encoding  = GetDynamicParamValue(EncodingParam, FileSystemCmdletProviderEncoding.Unknown);

            string language;
            int    version;

            GetVersionAndLanguageParams(out version, out language);

            return(new ItemContentWriter(this, item, path, encoding, extension, IsDynamicParamSet(RawParam),
                                         IsDynamicParamSet(FileBasedParam), IsDynamicParamSet(VersionedParam), language));
        }
예제 #2
0
        public IContentWriter GetContentWriter(string path)
        {
            var item = GetDynamicParamValue(ItemParam, (Item)null);

            if (item == null)
            {
                item = GetItemInternal(path, false).FirstOrDefault();

                if (item == null && !ItemContentReaderWriterBase.IsMediaPath(path))
                {
                    WriteInvalidPathError(path);
                    return(null);
                }
            }
            else
            {
                path = item.GetProviderPath();
            }

            var extension = GetDynamicParamValue(ExtensionParam, string.Empty);
            var encoding  = GetDynamicParamValue(EncodingParam, FileSystemCmdletProviderEncoding.Unknown);

            string[] language;
            int      version;

            GetVersionAndLanguageParams(out version, out language);

            if (language.Length != 1)
            {
                var exception = new IOException($"Cannot Write content to more than 1 language at a time.");
                WriteError(new ErrorRecord(exception, ErrorIds.InvalidOperation.ToString(), ErrorCategory.InvalidArgument,
                                           path));
            }
            return(new ItemContentWriter(this, item, path, encoding, extension, IsDynamicParamSet(RawParam),
                                         IsDynamicParamSet(FileBasedParam), IsDynamicParamSet(VersionedParam), language[0]));
        }