public void GetRoleDefinitionCreator(ClientContext ctx, string roleName, AppManifestBase manifest) { if (manifest == null) { return; } var existingRoleDefinitions = manifest.RoleDefinitions; existingRoleDefinitions = existingRoleDefinitions ?? new Dictionary <string, RoleDefinitionCreator>(); var creator = GetRoleDefinitionFromSite(ctx, roleName); if (creator != null) { OnVerboseNotify($"Got field creation information for {roleName}"); existingRoleDefinitions[roleName] = creator; } else { OnVerboseNotify($"NO INFORMATION FOUND FOR {roleName}"); } manifest.RoleDefinitions = existingRoleDefinitions; }
public AppManifestBase RemoveFileCreator(ClientContext ctx, Web web, string fileWebRelativeUrl, AppManifestBase existingManifest) { if (!fileWebRelativeUrl.StartsWith("/")) { fileWebRelativeUrl = "/" + fileWebRelativeUrl; } fileWebRelativeUrl = fileWebRelativeUrl.Replace("%20", " "); if (existingManifest?.FileCreators == null || !existingManifest.FileCreators.ContainsKey(fileWebRelativeUrl)) { return(existingManifest); } existingManifest.FileCreators.Remove(fileWebRelativeUrl); if (existingManifest.StorageType == StorageTypes.AzureStorage) { var azureStorageInfo = existingManifest.GetAzureStorageInfo(); var blobStorage = new BlobStorage(azureStorageInfo.Account, azureStorageInfo.AccountKey, azureStorageInfo.Container); blobStorage.DeleteBlob(fileWebRelativeUrl); } //TODO: File system deletion return(existingManifest); }
public static AppManifestBase GetManifestFromAzureStorage(string storageAccount, string accountKey, string container) { //Get or create the container var blobStorage = new BlobStorage(storageAccount, accountKey, container); var manifestJson = string.Empty; //Load or create a new manifest AppManifestBase appManifest; try { manifestJson = blobStorage.DownloadText("manifest.json"); } catch { // ignored } if (string.IsNullOrEmpty(manifestJson)) { appManifest = new AppManifestBase(); } else { var js = new JavaScriptSerializer(); appManifest = (AppManifestBase)js.Deserialize(manifestJson, typeof(AppManifestBase)); } //Set the storage info appManifest.SetAzureStorageInfo(storageAccount, accountKey, container); return(appManifest); }
private void ProvisionNavigation(AppManifestBase manifest) { if (manifest.Navigation != null) { var navigationManager = new NavigationManager(_ctx, _web) { ClearLeftMenu = manifest.Navigation.ClearLeftMenu, ClearTopMenu = manifest.Navigation.ClearTopMenu, TopNavigationNodes = manifest.Navigation.TopNavigationNodes, LeftNavigationNodes = manifest.Navigation.LeftNavigationNodes }; navigationManager.Notify += Provisioner_Notify; //App webs don't have oob menus. Create menus on host web if (_isHostWeb) { navigationManager.Provision(); } //but create a custom action to inject the nav via JavaScript for app webs { manifest.CustomActionCreators["IQAppWebNavigation"] = navigationManager.CreateNavigationUserCustomAction(manifest.Navigation); } } }
public void GetFieldCreator(ClientContext ctx, Web web, string fieldName, AppManifestBase manifest) { try { var existingFieldCreators = manifest.Fields; existingFieldCreators = existingFieldCreators ?? new Dictionary <string, string>(); var field = GetField(ctx, web, fieldName); if (field != null) { OnVerboseNotify($"Got field creation information for {fieldName}"); var schemaXml = FieldTokenizer.DoTokenSubstitutionsAndCleanSchema(ctx, field); existingFieldCreators[field.InternalName] = schemaXml; } else { OnVerboseNotify($"No information found for {fieldName}"); } manifest.Fields = existingFieldCreators; } catch (Exception ex) { OnVerboseNotify($"Error getting schema for {fieldName} - {ex}"); } }
private void ProvisionClassicWorkflows(AppManifestBase manifest) { if (manifest.ClassicWorkflowCreators == null || manifest.ClassicWorkflowCreators.Count == 0) { return; } var cm = new ClassicWorkflowManager { Creators = manifest.ClassicWorkflowCreators }; cm.Notify += Provisioner_Notify; //App identities can't call the web service to register the workflow if (_ctx.AuthenticationMode != ClientAuthenticationMode.Anonymous) { //Normal call with credentials cm.CreateAll(_ctx); } else //So create a self destructing custom action to register via the browser { var userCustomActionTitle = "AppWorkflowAssociationCustomAction" + manifest.ManifestName; //manifest.CustomActionCreators = manifest.CustomActionCreators != null ? manifest.CustomActionCreators : new Dictionary<string, CustomActionCreatorBase>(); manifest.CustomActionCreators[userCustomActionTitle] = cm.CreateAppWorkflowAssociationCustomAction(_ctx, _web, manifest.ClassicWorkflowCreators, userCustomActionTitle); } }
private void GetRelatedFileCreators(ClientContext ctx, Web web, AppManifestBase appManifest, string downloadFolderPath, string pageContent) { OnVerboseNotify("Looking for related files from page content"); var pageContentHtmlDoc = new HtmlDocument(); pageContentHtmlDoc.LoadHtml(pageContent); var anchors = pageContentHtmlDoc.DocumentNode.CssSelect("a"); var images = pageContentHtmlDoc.DocumentNode.CssSelect("img"); foreach (var anchor in anchors) { var url = anchor.Attributes["href"].Value; if (web.ServerRelativeUrl != "/") { url = url.Replace(web.ServerRelativeUrl, ""); } ProcessRelatedFile(ctx, web, appManifest, downloadFolderPath, url); } foreach (var img in images) { var url = img.Attributes["src"].Value; if (web.ServerRelativeUrl != "/") { url = url.Replace(web.ServerRelativeUrl, ""); } ProcessRelatedFile(ctx, web, appManifest, downloadFolderPath, url); } }
private void ProvisionFiles(AppManifestBase appManifest) { var fileManager = new FileManager(); fileManager.Notify += Provisioner_Notify; fileManager.ProvisionAll(_ctx, _web, appManifest); }
private void ApplySettings(AppManifestBase manifest) { if (manifest.Settings != null && manifest.Settings.Count > 0) { List settingsList; try { settingsList = Ctx.Site.RootWeb.Lists.GetByTitle("Settings"); Ctx.Load(settingsList, l => l.Title); } catch { return; } foreach (var key in manifest.Settings.Keys) { if (!SettingExists(key, settingsList)) { var listItem = settingsList.AddItem(new ListItemCreationInformation()); listItem["Title"] = key; listItem["Value"] = manifest.Settings[key]; listItem.Update(); } Ctx.ExecuteQueryRetry(); } } }
public void Provision(ClientContext ctx, Web web, string manifestJsonFileAbsolutePath) { try { IsHostWeb = !WebHasAppinstanceId(web); Ctx = ctx; Web = web; var json = File.ReadAllText(manifestJsonFileAbsolutePath); //TODO: Deal with fallout from Version problem var manifest = AppManifestBase.GetManifestFromJson(json); manifest.BaseFilePath = !string.IsNullOrEmpty(manifest.BaseFilePath) ? manifest.BaseFilePath : Path.GetDirectoryName(manifestJsonFileAbsolutePath); try { Provision(ctx, web, manifest); } catch (Exception ex) { var newEx = new Exception("Error provisioning to web at " + Web.Url, ex); throw newEx; } } catch (Exception ex) { var newEx = new Exception("Error provisioning to web at " + Web.Url, ex); throw newEx; } }
public string GetCreator(ClientContext ctx, Web web, string title, AppManifestBase manifest, CreatorTypes creatorType) { OnVerboseNotify("START Getting " + title); switch (creatorType) { case CreatorTypes.Field: return(GetFieldCreator(ctx, title, manifest)); case CreatorTypes.ContentType: return(GetContentTypeCreator(ctx, title, manifest)); case CreatorTypes.List: return(GetListCreator(ctx, web, title, manifest)); case CreatorTypes.RoleDefinition: return(GetRoleDefinitionCreator(ctx, title, manifest)); case CreatorTypes.Group: return(GetGroupCreator(ctx, title, manifest)); case CreatorTypes.Navigation: return(GetNavigationCreator(ctx, web, title, manifest)); case CreatorTypes.RemoteEvents: return(GetRemoteEventRegistrationsCreator(ctx, web, manifest)); case CreatorTypes.LookAndFeel: return(GetLookAndFeelCreator(ctx, web, manifest)); } OnVerboseNotify("END Getting " + title); return(string.Empty); }
public void GetGroupCreator(ClientContext ctx, string groupName, AppManifestBase manifest) { if (manifest == null) { return; } var existingGroups = manifest.GroupCreators; existingGroups = existingGroups ?? new Dictionary <string, GroupCreator>(); var creator = GetGroupCreatorFromSite(ctx, groupName); if (creator != null) { OnVerboseNotify($"Got group creation information for {groupName}"); existingGroups[groupName] = creator; } else { OnVerboseNotify("NO INFORMATION FOUND FOR " + groupName); } manifest.GroupCreators = existingGroups; }
public void GetRoleDefinitionCreators(ClientContext ctx, AppManifestBase manifest) { if (manifest == null) { return; } manifest.RoleDefinitions = GetRoleDefinitionsFromSite(ctx); }
private void RemoveFeatures(AppManifestBase manifest) { var featureManager = new FeatureManager { FeaturesToRemove = manifest.RemoveFeatures }; featureManager.Notify += Provisioner_Notify; featureManager.ConfigureFeatures(_ctx, _web); }
private void AddFeatures(AppManifestBase manifest) { var featureManager = new FeatureManager { FeaturesToAdd = manifest.AddFeatures }; featureManager.Notify += Provisioner_Notify; featureManager.ConfigureFeatures(Ctx, Web); }
private void ApplyDocumentTemplates(AppManifestBase manifest) { if (manifest.ListCreators != null && manifest.ListCreators.Count > 0) { foreach (var listCreator in manifest.ListCreators.Values) { listCreator.UpdateDocumentTemplate(_ctx); } } }
public string GetRoleDefinitionCreators(ClientContext ctx) { var manifest = new AppManifestBase(); GetRoleDefinitionCreators(ctx, manifest); var js = new JavaScriptSerializer(); return(js.Serialize(manifest.RoleDefinitions)); }
private void AttachEvents(AppManifestBase manifest) { if (manifest.RemoteEventRegistrationCreators == null || manifest.RemoteEventRegistrationCreators.Count == 0) { return; } var manager = new RemoteEventRegistrationManager(); manager.Notify += Provisioner_Notify; manager.CreateEventHandlers(_ctx, _web, manifest.RemoteEventRegistrationCreators, manifest.RemoteHost); }
private void ProvisionGroups(AppManifestBase manifest) { if (manifest.GroupCreators != null && manifest.GroupCreators.Count > 0) { var groupManager = new GroupManager { GroupCreators = manifest.GroupCreators }; groupManager.Notify += Provisioner_Notify; groupManager.ProvisionGroups(_ctx, _web); } }
private void CheckForUserCustomActions(ListCreator listCreator, List list, ClientContext ctx, AppManifestBase appManifest) { var builder = new CustomActionCreatorBuilder(); appManifest.ListCreators = new Dictionary <string, ListCreator> { [listCreator.Title] = new ListCreator() }; builder.GetCustomActionCreators(ctx, list, listCreator.Title, appManifest); listCreator.CustomActionCreators = appManifest.ListCreators[listCreator.Title].CustomActionCreators; }
private void ProvisionRoleDefinitions(AppManifestBase manifest) { if (manifest.RoleDefinitions != null && manifest.RoleDefinitions.Count > 0) { var roleDefinitionManager = new RoleDefinitionManager(_ctx, _web) { RoleDefinitions = manifest.RoleDefinitions }; roleDefinitionManager.Notify += Provisioner_Notify; roleDefinitionManager.Provision(); } }
private void ProvisionLookAndFeel(AppManifestBase manifest) { if (manifest.LookAndFeel == null) { return; } var lfm = new LookAndFeelManager(); lfm.Notify += Provisioner_Notify; lfm.ProvisionLookAndFeel(manifest, _ctx, _web); }
public string GetNavigationCreator(ClientContext ctx, Web web, string navigationCollection) { var manifest = new AppManifestBase(); GetNavigationCreator(ctx, web, navigationCollection, manifest); var collection = navigationCollection == "Left" ? manifest.Navigation.LeftNavigationNodes : manifest.Navigation.TopNavigationNodes; var js = new JavaScriptSerializer(); return(js.Serialize(collection)); }
private void ProvisionFields(AppManifestBase manifest) { if (manifest.Fields != null && manifest.Fields.Count > 0) { var fm = new FieldManager { FieldDefinitions = manifest.Fields }; fm.Notify += Provisioner_Notify; //Fields should always be provisioned into the root or app web fm.CreateAll(_ctx); } }
private void ProvisionContentTypes(AppManifestBase manifest) { if (manifest.ContentTypeCreators != null && manifest.ContentTypeCreators.Count > 0) { var cm = new ContentTypeManager { Creators = manifest.ContentTypeCreators }; cm.Notify += Provisioner_Notify; //ContentTypes should always be provisioned into the root or app web cm.CreateAll(_ctx); } }
private void ProvisionLists(AppManifestBase manifest) { if (manifest.ListCreators != null && manifest.ListCreators.Count > 0) { var lm = new ListInstanceManager(_ctx, _web, _isHostWeb) { Creators = manifest.ListCreators }; lm.Notify += Provisioner_Notify; lm.CreateAll(); } }
private void ProvisionCustomActions(AppManifestBase manifest) { if (manifest.CustomActionCreators != null && manifest.CustomActionCreators.Count > 0) { var actionMan = new CustomActionManager(_ctx, _web) { CustomActions = manifest.CustomActionCreators }; actionMan.Notify += Provisioner_Notify; actionMan.CreateAll(); } }
public string GetListCreator(ClientContext ctx, Web web, string listName) { var manifest = new AppManifestBase(); GetListCreator(ctx, web, listName, manifest); if (manifest.ListCreators.ContainsKey(listName)) { var js = new JavaScriptSerializer(); return(js.Serialize(manifest.ListCreators[listName])); } OnVerboseNotify("NO INFORMATION FOUND FOR " + listName); return(string.Empty); }
private void CheckForRemoteEvents(ListCreator listCreator, List list, ClientContext ctx, AppManifestBase appManifest) { var builder = new RemoteEventRegistrationCreatorBuilder(); appManifest.ListCreators = new Dictionary <string, ListCreator> { [listCreator.Title] = new ListCreator() }; builder.GetRemoteEventRegistrationCreators(ctx, list, listCreator.Title, appManifest); listCreator.RemoteEventRegistrationCreators = appManifest.ListCreators[listCreator.Title].RemoteEventRegistrationCreators; }
private void ProcessRelatedFile(ClientContext ctx, Web web, AppManifestBase appManifest, string downloadFolderPath, string url) { OnVerboseNotify("Processing related file " + url); var fileName = GetFileName(url); if (appManifest.FileCreators.ContainsKey(fileName)) { return; } GetFileCreator(ctx, web, url, downloadFolderPath, appManifest, true); }