示例#1
0
        // Implementation of the ContentConnector interface support from the parent class.

        protected override XmlElement UploadFile(ContentContainerInfo container, string name,
                                                 Stream content)
        {
            var source = RawAddItem(container, name, ItemType.File);

            SaveContent(source, content);
            SaveSite(source);
            return(source);
        }
示例#2
0
 public FileInfo AddFile(ContentContainerInfo container, string name, Stream content)
 {
     if (container == null)
         throw new ArgumentNullException("container");
     if (name == null)
         throw new ArgumentNullException("name");
     if (name.IsEmpty())
         throw new ArgumentException("The name of a new file must not be empty.");
     if (content == null)
         throw new ArgumentNullException("content");
     var file = AddFileDirectly(container, name, content);
     AddCachedItem(file, container);
     return file;
 }
示例#3
0
        // Implementation of the ContentConnector interface support from the parent class.

        protected override XmlElement UploadFile(ContentContainerInfo container, string name,
                                                 Stream content)
        {
            Log.Verbose("Adding the file {0} to /{1}.", name, container.Path);
            var url = PathUtility.JoinPath(Drive.WebUrl, container.Path, name);

            using (var client = GetClient()) {
                var response = client.UploadData(url, "PUT", content.ReadBytes());
            }
            var relativePath = PathUtility.JoinPath(container.ListRelativePath, name);

            return(QueryItem(container.List, relativePath));
            //CopyResult[] results;
            //GetService<Copy>(container.List.Web.Path).CopyIntoItems(
            //    name, new[] { url }, null, content.ReadBytes(), out results);
            //return GetCopiedItem(container, results);
        }
示例#4
0
        public FileInfo AddFile(ContentContainerInfo container, string name, Stream content)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name.IsEmpty())
            {
                throw new ArgumentException("The name of a new file must not be empty.");
            }
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }
            var file = AddFileDirectly(container, name, content);

            AddCachedItem(file, container);
            return(file);
        }
示例#5
0
 // Abstract methods to support the direct SharePoint content creation.
 protected abstract FileInfo AddFileDirectly(ContentContainerInfo container, string name,
                                             Stream content);
示例#6
0
        public IContentWriter GetContentWriter(string path)
        {
            EnsureLog();
            var parameters = (ContentWriterParameters)DynamicParameters;
            ContentContainerInfo container = null;
            string name = null;
            Info   item;

            // The Set-Content cmdlet should be able to create a file too; not only to overwrite
            // an existing one or add a new version. If the item is not found its parent will be
            // tried to create a new file in.
            try {
                item = GetObject(path);
            } catch {
                var parent = PathUtility.GetParentPath(path, out name);
                item      = GetObject(parent);
                container = item as ContentContainerInfo;
                if (container == null)
                {
                    throw new ApplicationException(
                              "The parent item on the path is no file container.");
                }
            }
            ContentInfo content = null;

            // If an item was found at the entered path it must be a file.
            if (container == null)
            {
                content = item as ContentInfo;
                if (content == null)
                {
                    throw new ApplicationException("This item supports no content.");
                }
            }
            var writer = parameters.UsingByteEncoding ? new ContentWriter() :
                         new ContentWriter(parameters.GetEncoding());

            // The provider is no notified when the caller finishes sending the content.
            // It is not possible to open a channel to SharePoint and send there byte after byte.
            // SharePoint has the interface which accepts a stream to read from. That's why we
            // unfortunately have to buffer the entire content and when it is complete send it
            // to SharePoint. Closing the returned writer is already five minutes after twelve
            // o'clock but I didn't find anything better.
            writer.Closed += (sender, args) => {
                if (ShouldProcess(path, "Set Content"))
                {
                    if (content != null)
                    {
                        try {
                            content.Save(args.Content);
                        } catch (Exception exception) {
                            WriteError(new ErrorRecord(exception, "WritingContentFailed",
                                                       ErrorCategory.ResourceUnavailable, content));
                        }
                    }
                    else
                    {
                        try {
                            container.AddFile(name, args.Content);
                        } catch (Exception exception) {
                            WriteError(new ErrorRecord(exception, "WritingContentFailed",
                                                       ErrorCategory.ResourceUnavailable, path));
                        }
                    }
                }
            };
            return(writer);
        }
示例#7
0
        // Abstract methods to support the direct SharePoint content creation which return raw
        // information about the new object in same XML format as the querying methods above.

        protected abstract XmlElement UploadFile(ContentContainerInfo container, string name,
                                                 Stream content);
示例#8
0
        // Implementation of the ContentConnector interface support. Methods creating a new file
        // use the same raw XML information to handle caching and returning the new file as the
        // object creating methods above.

        protected override FileInfo AddFileDirectly(ContentContainerInfo container, string name,
                                                    Stream content)
        {
            return((FileInfo)CreateItemInfo(container.List, UploadFile(container, name, content)));
        }
示例#9
0
 // Implementation of the ContentConnector interface support from the parent class.
 protected override XmlElement UploadFile(ContentContainerInfo container, string name,
                                          Stream content)
 {
     var source = RawAddItem(container, name, ItemType.File);
     SaveContent(source, content);
     SaveSite(source);
     return source;
 }
示例#10
0
 // Implementation of the ContentConnector interface support. Methods creating a new file
 // use the same raw XML information to handle caching and returning the new file as the
 // object creating methods above.
 protected override FileInfo AddFileDirectly(ContentContainerInfo container, string name,
                                             Stream content)
 {
     return (FileInfo) CreateItemInfo(container.List, UploadFile(container, name, content));
 }
示例#11
0
 // Abstract methods to support the direct SharePoint content creation which return raw
 // information about the new object in same XML format as the querying methods above.
 protected abstract XmlElement UploadFile(ContentContainerInfo container, string name,
                                          Stream content);
示例#12
0
        // Abstract methods to support the direct SharePoint content creation.

        protected abstract FileInfo AddFileDirectly(ContentContainerInfo container, string name,
                                                    Stream content);