コード例 #1
0
 public static async Task <TermModel> GetTermModelForTermInfoAsync <TContext>(
     this SpClientContext <TContext> clientContext,
     ITaxonomyService taxonomyService,
     TermInfo termInfo) where TContext : SpClientContext <TContext> =>
 termInfo != null ? await taxonomyService.GetTermAsync(
     clientContext.ClientContext,
     termInfo.TermSetId,
     termInfo.TermGuid) : null;
コード例 #2
0
        public static async Task <TermSetModel> GetTermSetModelForFieldAsync <TContext, TEntity>(
            this SpClientContext <TContext> clientContext,
            ITaxonomyService taxonomyService,
            Expression <Func <TContext, ISpList <TEntity> > > listSelector,
            Expression <Func <TEntity, object> > propertySelector) where TContext : SpClientContext <TContext>
        {
            var metaField = clientContext.GetMetaFieldForProperty(listSelector, propertySelector);

            return(await taxonomyService.GetTermSetAsync(clientContext.ClientContext, metaField.TermSetId.ToString()));
        }
コード例 #3
0
        protected void UploadFile(string file, string documentFolder)
        {
            if (!System.IO.Path.IsPathRooted(file))
            {
                file = System.IO.Path.Combine(SessionState.Path.CurrentLocation.Path, file);
            }
            WriteObject($"Uploading {file} to {documentFolder}...");
            WriteVerbose($"ClientId:{ClientId} ClientSecret:{new String('*', ClientSecret.Length)}");
            WriteVerbose($"Url: {Url}");
            WriteVerbose($"DocumentFolder: {documentFolder} File: {file}");
            if (ShouldProcess("Uploading file"))
            {
                try
                {
                    using (var cc = SpClientContext.GetClientContext(c =>
                    {
                        c.Url = Url;
                        c.ClientId = ClientId;
                        c.ClientSecret = ClientSecret;
                    }))
                    {
                        var folder = cc.Web.GetFolderByServerRelativeUrl(documentFolder);
                        cc.Load(cc.Web);
                        cc.Load(folder, f => f.Files);
                        var newFile = new FileCreationInformation
                        {
                            ContentStream = System.IO.File.OpenRead(file),
                            Url           = System.IO.Path.GetFileName(file),
                            Overwrite     = true
                        };

                        var uploadFile = folder.Files.Add(newFile);
                        cc.Load(uploadFile);
                        cc.ExecuteQuery();
                    }
                    WriteObject($"Uploaded {file} to {documentFolder}");
                }
                catch (Exception e)
                {
                    WriteError(new ErrorRecord(e, "UploadFile", ErrorCategory.WriteError, new
                    {
                        Url,
                        file,
                        DocumentFolder = documentFolder
                    }));
                }
            }
        }
コード例 #4
0
        protected override void ProcessRecord()
        {
            if (!Path.IsPathRooted(File))
            {
                File = Path.Combine(SessionState.Path.CurrentLocation.Path, File);
            }

            if (Script != null && !Path.IsPathRooted(Script))
            {
                Script = Path.Combine(SessionState.Path.CurrentLocation.Path, Script);
            }

            WriteObject($"Uploading {File} to {ListId}...");
            WriteVerbose($"ClientId:{ClientId} ClientSecret:{new String('*', ClientSecret.Length)}");
            WriteVerbose($"Url: {Url}");
            WriteVerbose($"File: {File} Script: {Script}");
            try
            {
                if (!IO.File.Exists(File))
                {
                    WriteError(new ErrorRecord(new FileNotFoundException($"The file {File} was not found.", File), "MissingFile", ErrorCategory.WriteError, new
                    {
                        Url,
                        ListId,
                        File,
                        Script
                    }));
                    return;
                }

                using (var cc = SpClientContext.GetClientContext(c =>
                {
                    c.Url = Url;
                    c.ClientId = ClientId;
                    c.ClientSecret = ClientSecret;
                }))
                {
                    var item = AddOrGetListItem(cc);

                    item["WikiField"] = IO.File.ReadAllText(File);

                    item.Update();
                    cc.ExecuteQuery();
                    WriteVerbose("Updated wiki content");

                    if (string.IsNullOrEmpty(Script))
                    {
                        WriteVerbose("No script to add.");
                    }
                    else
                    {
                        if (!IO.File.Exists(Script))
                        {
                            WriteError(new ErrorRecord(new FileNotFoundException($"The file {Script} was not found.", Script), "MissingFile", ErrorCategory.WriteError, new
                            {
                                Url,
                                ListId,
                                File,
                                Script
                            }));
                            return;
                        }

                        AddScript(cc, item);
                        WriteVerbose($"Added script");
                    }
                }
                WriteObject($"Uploaded {File} to {ListId}");
            }
            catch (Exception e)
            {
                WriteError(new ErrorRecord(e, "UploadFile", ErrorCategory.WriteError, new
                {
                    Url,
                    ListId,
                    File,
                    Script
                }));
            }
        }