示例#1
0
 private void HandleSitePolicy(ProvisioningTemplate provisioningTemplate, SiteRequestInformation siteRequest)
 {
     if (!string.IsNullOrWhiteSpace(siteRequest.SitePolicy))
     {
         provisioningTemplate.SitePolicy = siteRequest.SitePolicy;
     }
 }
        /// <summary>
        /// Sends a Notification that the Site was created
        /// </summary>
        /// <param name="info"></param>
        protected void SendSuccessEmail(SiteRequestInformation info)
        {
            //TODO CLEAN UP EMAILS
            try
            {
                StringBuilder       _admins  = new StringBuilder();
                SuccessEmailMessage _message = new SuccessEmailMessage();
                _message.SiteUrl   = info.Url;
                _message.SiteOwner = info.SiteOwner.Name;
                _message.Subject   = "Notification: Your new SharePoint site is ready";

                _message.To.Add(info.SiteOwner.Name);
                foreach (var admin in info.AdditionalAdministrators)
                {
                    _message.Cc.Add(admin.Name);
                    _admins.Append(admin.Name);
                    _admins.Append(" ");
                }
                _message.SiteAdmin = _admins.ToString();
                EmailHelper.SendNewSiteSuccessEmail(_message);
            }
            catch (Exception ex)
            {
                Log.Error("Provisioning.Job.SiteProvisioningJob.SendSuccessEmail",
                          "There was an error sending email. The Error Message: {0}, Exception: {1}",
                          ex.Message,
                          ex);
            }
        }
示例#3
0
        public SiteRequestInformation GetSiteRequestMock()
        {
            var _owner = new SiteUser()
            {
                Name = "*****@*****.**"
            };
            //Add addtional Users
            List <SiteUser> _additionalAdmins = new List <SiteUser>();
            SiteUser        _admin1           = new SiteUser();

            _admin1.Name = "*****@*****.**";
            SiteUser _admin2 = new SiteUser();

            //  _admin2.Email = "*****@*****.**";
            _admin2.Name = "*****@*****.**";
            _additionalAdmins.Add(_admin1);
            _additionalAdmins.Add(_admin2);

            var _siteInfo = new SiteRequestInformation()
            {
                Title       = "Test Title",
                Description = "Test Description",
                Template    = "CT2",
                Url         = "https://spsites.contoso.com/sites/B3",
                SitePolicy  = "HBI",
                SiteOwner   = _owner,
                AdditionalAdministrators = _additionalAdmins,
                EnableExternalSharing    = true,
                SharePointOnPremises     = true
            };

            return(_siteInfo);
        }
示例#4
0
 private void HandleSitePolicy(ProvisioningTemplate provisioningTemplate, SiteRequestInformation siteRequest)
 {
     if(!string.IsNullOrWhiteSpace(siteRequest.SitePolicy))
     {
         provisioningTemplate.SitePolicy = siteRequest.SitePolicy;
     }
 }
示例#5
0
 /// <summary>
 /// Member to handle the Url of custom actions
 /// </summary>
 /// <param name="provisioningTemplate"></param>
 /// <param name="siteRequest"></param>
 private void HandleCustomActions(ProvisioningTemplate provisioningTemplate, SiteRequestInformation siteRequest)
 {
     if (provisioningTemplate.CustomActions != null)
     {
         //handle site custom actions
         foreach (var _siteCustomActions in provisioningTemplate.CustomActions.SiteCustomActions)
         {
             //IF ITS A SCRIPT SRC WE DO NOT WANT TO MODIFY
             if (!string.IsNullOrEmpty(_siteCustomActions.Url))
             {
                 var _escapedURI = Uri.EscapeUriString(siteRequest.Url);
                 _siteCustomActions.Url = string.Format(_siteCustomActions.Url, _escapedURI);
             }
         }
         //handle web custom actions
         foreach (var _webActions in provisioningTemplate.CustomActions.WebCustomActions)
         {
             //IF ITS A SCRIPT SRC WE DO NOT WANT TO MODIFY
             if (!string.IsNullOrEmpty(_webActions.Url))
             {
                 var _escapedURI = Uri.EscapeUriString(siteRequest.Url);
                 _webActions.Url = string.Format(_webActions.Url, _escapedURI);
             }
         }
     }
 }
示例#6
0
 /// <summary>
 /// Member to handle the Url of custom actions
 /// </summary>
 /// <param name="provisioningTemplate"></param>
 /// <param name="siteRequest"></param>
 private void HandleCustomActions(ProvisioningTemplate provisioningTemplate, SiteRequestInformation siteRequest)
 {
     if (provisioningTemplate.CustomActions != null)
     {
         //handle site custom actions
         foreach (var _siteCustomActions in provisioningTemplate.CustomActions.SiteCustomActions)
         {
             //IF ITS A SCRIPT SRC WE DO NOT WANT TO MODIFY
             if (!string.IsNullOrEmpty(_siteCustomActions.Url))
             {
                 var _escapedURI = Uri.EscapeUriString(siteRequest.Url);
                 _siteCustomActions.Url = string.Format(_siteCustomActions.Url, _escapedURI);
             }
         }
         //handle web custom actions
         foreach( var _webActions in provisioningTemplate.CustomActions.WebCustomActions)
         {
             //IF ITS A SCRIPT SRC WE DO NOT WANT TO MODIFY
             if (!string.IsNullOrEmpty(_webActions.Url))
             {
                  var _escapedURI = Uri.EscapeUriString(siteRequest.Url);
                 _webActions.Url = string.Format(_webActions.Url, _escapedURI);
             }
         }
     }
 }
示例#7
0
 private void HandleAdditionalAdministrators(ProvisioningTemplate provisioningTemplate, SiteRequestInformation siteRequest)
 {
    foreach(var _Admin in siteRequest.AdditionalAdministrators)
    {
        User _user = new User();
        _user.Name = _Admin.Name;
        provisioningTemplate.Security.AdditionalAdministrators.Add(_user);
    }
 }
示例#8
0
 internal ProvisioningTemplate HandleProvisioningTemplate(ProvisioningTemplate provisioningTemplate, SiteRequestInformation siteRequest)
 {
     this.HandleExternalSharing(provisioningTemplate, siteRequest);
     this.HandleSitePolicy(provisioningTemplate, siteRequest);
     this.HandleAdditionalAdministrators(provisioningTemplate, siteRequest);
     this.HandlePropertyBagEntries(provisioningTemplate, siteRequest);
     this.HandleCustomActions(provisioningTemplate, siteRequest);
     return provisioningTemplate;
 }
示例#9
0
        private void HandlePropertyBagEntries(ProvisioningTemplate provisioningTemplate, SiteRequestInformation siteRequest)
        {
            Dictionary<string, string> _props = JsonConvert.DeserializeObject<Dictionary<string, string>>(siteRequest.PropertiesJSON);

            foreach(var prop in _props)
            {
                PropertyBagEntry _pb = new PropertyBagEntry();
                _pb.Key = prop.Key;
                _pb.Value = prop.Value;
                provisioningTemplate.PropertyBagEntries.Add(_pb);
            }
        }
示例#10
0
 private void HandleExternalSharing(ProvisioningTemplate provisioningTemplate, SiteRequestInformation siteRequest)
 {
     //EXTERNAL SHARING CUSTOM ACTION MUST BE DEFINED IN TEMPLATE. IF THE SITE REQUEST DOES NOT HAVE EXTERNAL SHARING ENABLE WE WILL REMOVE THE CUSTOM ACCTION
     if(!siteRequest.EnableExternalSharing)
     {
         if(provisioningTemplate.CustomActions != null)
         {
             //FIND THE CUSTOM ACTION CA_SITE_EXTERNALSHARING
             var _externalSharingCA = provisioningTemplate.CustomActions.SiteCustomActions.FirstOrDefault(t => t.Title == "CA_SITE_EXTERNALSHARING");
             if(_externalSharingCA != null)
             {
                 provisioningTemplate.CustomActions.SiteCustomActions.Remove(_externalSharingCA);
             }
         }
     }
 }
示例#11
0
        public bool DoesSiteRequestExist(string url)
        {
            SiteRequestInformation _siteRequest = null;
            bool _returnResult = false;

            UsingContext(client =>
            {
                try
                {
                    Task <Task <Database> > _taskResult = Task.FromResult <Task <Database> >(this.GetOrCreateDatabaseAsync(client));
                    Database _db;

                    if (!_taskResult.IsFaulted)
                    {
                        if (!_taskResult.Result.IsFaulted)
                        {
                            _db = _taskResult.Result.Result;
                            var _dbCollectionTasks = Task.FromResult(this.GetOrCreateCollectionAsync(client, _db.SelfLink, DB_COLLECTION_ID));
                            if (!_dbCollectionTasks.Result.IsFaulted)
                            {
                                _siteRequest = this.GetSiteRequestByUrl(client, _dbCollectionTasks.Result.Result.DocumentsLink, url);
                                if (_siteRequest == null)
                                {
                                    _returnResult = false;
                                }
                                else
                                {
                                    _returnResult = true;
                                }
                            }
                        }
                    }
                }
                catch (DocumentClientException de)
                {
                    Exception baseException = de.GetBaseException();
                    Log.Error("AzureDocDbRequestManager", "{0} error occurred: {1}, Message: {2}", de.StatusCode, de.Message, baseException.Message);
                }
                catch (Exception ex)
                {
                    Exception baseException = ex.GetBaseException();
                    Log.Error("AzureDocDbRequestManager", "Error: {0}, Message: {1}", ex.Message, baseException.Message);
                }
            });
            return(_returnResult);
        }
示例#12
0
        /// <summary>
        /// Internal Member to Update Request and Status properties Azure DocumentDB by url
        /// </summary>
        /// <param name="client"></param>
        /// <param name="selfLink"></param>
        /// <param name="request"></param>
        /// <param name="status"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        private Document UpdateSiteRequestStatusByUrl(DocumentClient client, string selfLink, SiteRequestInformation request, SiteRequestStatus status, string message)
        {
            dynamic  requestDocument = client.CreateDocumentQuery <Document>(selfLink).Where(d => d.Id == request.Id).AsEnumerable().FirstOrDefault();
            Document _d             = requestDocument; //Cast to Document to get the Selflink property
            Document _dReturnResult = null;
            SiteRequestInformation _requestToUpdate = requestDocument;

            if (!string.IsNullOrEmpty(message))
            {
                _requestToUpdate.RequestStatusMessage = message;
            }
            _requestToUpdate.EnumStatus = status;
            var savedRequestTask = Task.FromResult(client.ReplaceDocumentAsync(_d.SelfLink, _requestToUpdate));

            if (!savedRequestTask.Result.IsFaulted)
            {
                _dReturnResult = savedRequestTask.Result.Result;
            }
            return(_dReturnResult);
        }
示例#13
0
        public void AddRequest(SiteRequestInformation siteRequest, ClientContext ctx)
        {
            Web  _web  = ctx.Web;
            List _list = _web.Lists.GetByTitle(Lists.SiteRepositoryTitle);
            ListItemCreationInformation _listItemCreation = new ListItemCreationInformation();
            ListItem _record = _list.AddItem(_listItemCreation);

            _record[SiteRequestFields.Title]       = siteRequest.Title;
            _record[SiteRequestFields.Description] = siteRequest.Description;
            _record[SiteRequestFields.Template]    = siteRequest.Template;
            _record[SiteRequestFields.State]       = siteRequest.RequestStatus;
            _record[SiteRequestFields.Url]         = siteRequest.Url;
            _record[SiteRequestFields.TimeZone]    = siteRequest.TimeZoneId;
            FieldUserValue _siteOwner = FieldUserValue.FromUser(siteRequest.SiteOwner.Email);

            _record[SiteRequestFields.Owner] = _siteOwner;

            _record.Update();
            ctx.ExecuteQuery();
        }
示例#14
0
        public static SiteRequestInformation ToSiteRequestInformation(SiteRequest request)
        {
            var _owner = new SiteUser()
            {
                Name = request.PrimaryOwner
            };

            List <SiteUser> _additionalAdmins = new List <SiteUser>();

            foreach (var secondaryOwner in request.AdditionalAdministrators)
            {
                if (!string.IsNullOrEmpty(secondaryOwner))
                {
                    var _sharePointUser = new SiteUser();
                    _sharePointUser.Name = secondaryOwner;
                    _additionalAdmins.Add(_sharePointUser);
                }
            }

            var _newRequest = new SiteRequestInformation();

            _newRequest.Title       = request.Title;
            _newRequest.Description = request.Description;
            _newRequest.Url         = request.Url;
            _newRequest.TimeZoneId  = request.TimeZoneID;
            _newRequest.Lcid        = request.lcid;
            _newRequest.Template    = request.Template;
            _newRequest.SitePolicy  = request.SitePolicy;
            _newRequest.SiteOwner   = _owner;
            _newRequest.AdditionalAdministrators = _additionalAdmins;
            _newRequest.SharePointOnPremises     = request.SharePointOnPremises;
            _newRequest.BusinessCase             = request.BusinessCase;
            _newRequest.EnableExternalSharing    = request.EnableExternalSharing;

            if (request.Properties != null)
            {
                //Serialize Property Bag Entries
                _newRequest.PropertiesJSON = JsonConvert.SerializeObject(request.Properties);
            }
            return(_newRequest);
        }
示例#15
0
        public void CreateNewSiteRequest(SiteRequestInformation siteRequest)
        {
            siteRequest.EnumStatus = SiteRequestStatus.New;
            UsingContext(client =>
            {
                try
                {
                    Task <Task <Database> > _taskResult = Task.FromResult <Task <Database> >(this.GetOrCreateDatabaseAsync(client));
                    Database _db;

                    if (!_taskResult.IsFaulted)
                    {
                        if (!_taskResult.Result.IsFaulted)
                        {
                            _db = _taskResult.Result.Result;
                            var _dbCollectionTasks = Task.FromResult(this.GetOrCreateCollectionAsync(client, _db.SelfLink, DB_COLLECTION_ID));
                            if (!_dbCollectionTasks.Result.IsFaulted)
                            {
                                var _siteInfo = this.GetSiteRequestByUrl(client, _dbCollectionTasks.Result.Result.DocumentsLink, siteRequest.Url);
                                if (_siteInfo == null)
                                {
                                    var doc = this.SaveNewRequest(client, _dbCollectionTasks.Result.Result.SelfLink, siteRequest);
                                }
                            }
                        }
                    }
                }
                catch (DocumentClientException de)
                {
                    Exception baseException = de.GetBaseException();
                    Log.Error("AzureDocDbRequestManager", "{0} error occurred: {1}, Message: {2}", de.StatusCode, de.Message, baseException.Message);
                }
                catch (Exception ex)
                {
                    Exception baseException = ex.GetBaseException();
                    Log.Error("AzureDocDbRequestManager", "Error: {0}, Message: {1}", ex.Message, baseException.Message);
                }
            });
        }
示例#16
0
        public void CreateNewSiteRequest(SiteRequestInformation siteRequest)
        {
            siteRequest.EnumStatus = SiteRequestStatus.New;
            UsingContext(client =>
            {
                try
                {
                    Task<Task<Database>> _taskResult = Task.FromResult<Task<Database>>(this.GetOrCreateDatabaseAsync(client));
                    Database _db;

                    if (!_taskResult.IsFaulted)
                    {
                        if (!_taskResult.Result.IsFaulted)
                        {
                            _db = _taskResult.Result.Result;
                            var _dbCollectionTasks = Task.FromResult(this.GetOrCreateCollectionAsync(client, _db.SelfLink, DB_COLLECTION_ID));
                            if (!_dbCollectionTasks.Result.IsFaulted)
                            {
                                var _siteInfo = this.GetSiteRequestByUrl(client, _dbCollectionTasks.Result.Result.DocumentsLink, siteRequest.Url);
                                if (_siteInfo == null)
                                {
                                    var doc = this.SaveNewRequest(client, _dbCollectionTasks.Result.Result.SelfLink, siteRequest);
                                }
                            }
                        }
                    }
                }
                catch (DocumentClientException de)
                {
                    Exception baseException = de.GetBaseException();
                    Log.Error("AzureDocDbRequestManager", "{0} error occurred: {1}, Message: {2}", de.StatusCode, de.Message, baseException.Message);
                }
                catch (Exception ex)
                {
                    Exception baseException = ex.GetBaseException();
                    Log.Error("AzureDocDbRequestManager", "Error: {0}, Message: {1}", ex.Message, baseException.Message);
                }
             });
        }
示例#17
0
        protected void btnCreate_Click(object sender, EventArgs e)
        {
            var    spContext = SharePointContextProvider.Current.GetSharePointContext(Context);
            string newWebUrl = string.Empty;

            using (ClientContext ctx = spContext.CreateUserClientContextForSPHost())
            {
                SharePointUser currentUser;
                ctx.Load(ctx.Web.CurrentUser);
                ctx.ExecuteQuery();

                var user = ctx.Web.CurrentUser;
                currentUser = new SharePointUser()
                {
                    Email = user.Email,
                    Login = user.LoginName,
                    Name  = user.Title
                };


                var siteRequestInfo = new SiteRequestInformation()
                {
                    Title       = this.txtTitle.Text,
                    Description = this.txtDescription.Text,
                    EnumStatus  = SiteRequestStatus.New,
                    Template    = "STS#0",
                    SiteOwner   = currentUser,
                };

                siteRequestInfo.Url = string.Format(@"{0}{1}", this.lblBasePath.Text, siteRequestInfo.Title);
                LabHelper _helper = new LabHelper();
                _helper.AddRequest(siteRequestInfo, ctx);
            }


            Response.Redirect(Page.Request["SPHostUrl"]);
        }
示例#18
0
        /// <summary>
        /// Sends an Failure Email Notification
        /// </summary>
        /// <param name="info"></param>
        /// <param name="errorMessage"></param>
        protected void SendFailureEmail(SiteRequestInformation info, string errorMessage)
        {
            try
            {
                StringBuilder       _admins  = new StringBuilder();
                FailureEmailMessage _message = new FailureEmailMessage();
                _message.SiteUrl      = info.Url;
                _message.SiteOwner    = info.SiteOwner.Name;
                _message.Subject      = "Alert: Your new SharePoint site request had a problem.";
                _message.ErrorMessage = errorMessage;
                _message.To.Add(info.SiteOwner.Name);

                if (!string.IsNullOrEmpty(this._settings.SupportEmailNotification))
                {
                    string[] supportAdmins = this._settings.SupportEmailNotification.Split(';');
                    foreach (var supportAdmin in supportAdmins)
                    {
                        _message.To.Add(supportAdmin);
                    }
                }
                foreach (var admin in info.AdditionalAdministrators)
                {
                    _message.Cc.Add(admin.Name);
                    _admins.Append(admin.Name);
                    _admins.Append(" ");
                }
                _message.SiteAdmin = _admins.ToString();
                EmailHelper.SendFailEmail(_message);
            }
            catch (Exception ex)
            {
                Log.Error("Provisioning.Job.SiteProvisioningJob.SendSuccessEmail",
                          "There was an error sending email. The Error Message: {0}, Exception: {1}",
                          ex.Message,
                          ex);
            }
        }
示例#19
0
        /// <summary>
        /// Internal Member to save a new site request
        /// </summary>
        /// <param name="client"></param>
        /// <param name="collectionLink"></param>
        /// <param name="info"></param>
        /// <returns></returns>
        private Document SaveNewRequest(DocumentClient client, string collectionLink, SiteRequestInformation info )
        {
            //If Settings are set to autoapprove then automatically approve the requests
            if (_manager.GetAppSettings().AutoApprove)
            {
                 info.RequestStatus = SiteRequestStatus.Approved.ToString();
                 info.ApprovedDate = DateTime.Now;
            }
            else
            {
                info.RequestStatus = SiteRequestStatus.New.ToString();
            }
            info.SubmitDate = DateTime.Now;

            var saveDocumentTask = Task.FromResult(client.CreateDocumentAsync(collectionLink, info));
            Document document = null;
            if(!saveDocumentTask.IsFaulted)
            {
                document = saveDocumentTask.Result.Result;
            }

            return document;
        }
示例#20
0
        /// <summary>
        /// Internal Member to Update Request and Status properties Azure DocumentDB by url 
        /// </summary>
        /// <param name="client"></param>
        /// <param name="selfLink"></param>
        /// <param name="request"></param>
        /// <param name="status"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        private Document UpdateSiteRequestStatusByUrl(DocumentClient client, string selfLink, SiteRequestInformation request, SiteRequestStatus status, string message)
        {

            dynamic requestDocument = client.CreateDocumentQuery<Document>(selfLink).Where(d => d.Id == request.Id).AsEnumerable().FirstOrDefault();
            Document _d = requestDocument; //Cast to Document to get the Selflink property
            Document _dReturnResult = null;
            SiteRequestInformation _requestToUpdate = requestDocument;
            if(!string.IsNullOrEmpty(message))
            {
                _requestToUpdate.RequestStatusMessage = message;
            }
            _requestToUpdate.EnumStatus = status;
            var savedRequestTask = Task.FromResult(client.ReplaceDocumentAsync(_d.SelfLink, _requestToUpdate));

            if (!savedRequestTask.Result.IsFaulted)
            {
                _dReturnResult = savedRequestTask.Result.Result;
            }
            return _dReturnResult;
        }
示例#21
0
        public void CreateNewSiteRequest(SiteRequestInformation siteRequest)
        {
            UsingContext(ctx =>
            {
                var web = ctx.Web;

                if (!web.ListExists(SiteRequestList.TITLE))
                {
                    this.HandleSiteRequestList(ctx);
                }

                List list = web.Lists.GetByTitle(SiteRequestList.TITLE);
                ListItemCreationInformation _listItemCreation = new ListItemCreationInformation();
                ListItem _record = list.AddItem(_listItemCreation);
                _record[SiteRequestFields.TITLE]                = siteRequest.Title;
                _record[SiteRequestFields.DESCRIPTION_NAME]     = siteRequest.Description;
                _record[SiteRequestFields.TEMPLATE_NAME]        = siteRequest.Template;
                _record[SiteRequestFields.URL_NAME]             = siteRequest.Url;
                _record[SiteRequestFields.LCID_NAME]            = siteRequest.Lcid;
                _record[SiteRequestFields.TIMEZONE_NAME]        = siteRequest.TimeZoneId;
                _record[SiteRequestFields.POLICY_NAME]          = siteRequest.SitePolicy;
                _record[SiteRequestFields.EXTERNALSHARING_NAME] = siteRequest.EnableExternalSharing;
                _record[SiteRequestFields.ONPREM_REQUEST_NAME]  = siteRequest.SharePointOnPremises;
                _record[SiteRequestFields.BC_NAME]              = siteRequest.BusinessCase;
                _record[SiteRequestFields.PROPS_NAME]           = siteRequest.PropertiesJSON;
                //If Settings are set to autoapprove then automatically approve the requests
                if (_manager.GetAppSettings().AutoApprove)
                {
                    _record[SiteRequestFields.PROVISIONING_STATUS_NAME] = SiteRequestStatus.Approved.ToString();
                    _record[SiteRequestFields.APPROVEDDATE_NAME]        = DateTime.Now;
                }
                else
                {
                    _record[SiteRequestFields.PROVISIONING_STATUS_NAME] = SiteRequestStatus.New.ToString();
                }

                FieldUserValue _siteOwner             = FieldUserValue.FromUser(siteRequest.SiteOwner.Name);
                _record[SiteRequestFields.OWNER_NAME] = _siteOwner;

                //Additional Admins
                if (siteRequest.AdditionalAdministrators != null)
                {
                    if (siteRequest.AdditionalAdministrators.Count > 0)
                    {
                        FieldUserValue[] _additionalAdmins = new FieldUserValue[siteRequest.AdditionalAdministrators.Count];
                        int _index = 0;
                        foreach (SiteUser _user in siteRequest.AdditionalAdministrators)
                        {
                            FieldUserValue _adminFieldUser = FieldUserValue.FromUser(_user.Name);
                            _additionalAdmins[_index]      = _adminFieldUser;
                            _index++;
                        }
                        _record[SiteRequestFields.ADD_ADMINS_NAME] = _additionalAdmins;
                    }
                }

                _record.Update();
                ctx.ExecuteQuery();
                Log.Info("Provisioning.Common.Data.Impl.UpdateRequestStatus", PCResources.SiteRequestNew_Successfull, siteRequest.Url);
            }
                         );
        }
示例#22
0
        private SiteRequestInformation GetSiteRequestByCaml(string camlQuery, string filter)
        {
            SiteRequestInformation _siteRequest = null;

            UsingContext(ctx =>
            {
                CamlQuery _caml = new CamlQuery();
                _caml.ViewXml   = string.Format(camlQuery, filter);
                var web         = ctx.Web;

                if (!web.ListExists(SiteRequestList.TITLE))
                {
                    this.HandleSiteRequestList(ctx);
                }

                var list = ctx.Web.Lists.GetByTitle(SiteRequestList.TITLE);
                var _listItemCollection = list.GetItems(_caml);

                ctx.Load(_listItemCollection,
                         eachItem => eachItem.Include(
                             item => item,
                             item => item[SiteRequestFields.TITLE],
                             item => item[SiteRequestFields.DESCRIPTION_NAME],
                             item => item[SiteRequestFields.TEMPLATE_NAME],
                             item => item[SiteRequestFields.POLICY_NAME],
                             item => item[SiteRequestFields.URL_NAME],
                             item => item[SiteRequestFields.OWNER_NAME],
                             item => item[SiteRequestFields.PROVISIONING_STATUS_NAME],
                             item => item[SiteRequestFields.ADD_ADMINS_NAME],
                             item => item[SiteRequestFields.LCID_NAME],
                             item => item[SiteRequestFields.EXTERNALSHARING_NAME],
                             item => item[SiteRequestFields.PROVISIONING_STATUS_NAME],
                             item => item[SiteRequestFields.ONPREM_REQUEST_NAME],
                             item => item[SiteRequestFields.LCID_NAME],
                             item => item[SiteRequestFields.TIMEZONE_NAME],
                             item => item[SiteRequestFields.BC_NAME],
                             item => item[SiteRequestFields.PROPS_NAME],
                             item => item[SiteRequestFields.STATUSMESSAGE_NAME]));
                ctx.ExecuteQuery();

                if (_listItemCollection.Count > 0)
                {
                    ListItem _item = _listItemCollection.First();

                    _siteRequest = new SiteRequestInformation()
                    {
                        Title       = this.BaseSet(_item, SiteRequestFields.TITLE),
                        Description = this.BaseSet(_item, SiteRequestFields.DESCRIPTION_NAME),
                        Template    = this.BaseSet(_item, SiteRequestFields.TEMPLATE_NAME),
                        SitePolicy  = this.BaseSet(_item, SiteRequestFields.POLICY_NAME),
                        Url         = this.BaseSet(_item, SiteRequestFields.URL_NAME),
                        SiteOwner   = this.BaseSetUser(ctx, _item, SiteRequestFields.OWNER_NAME),
                        AdditionalAdministrators = this.BaseSetUsers(ctx, _item, SiteRequestFields.ADD_ADMINS_NAME),
                        EnableExternalSharing    = this.BaseGet <bool>(_item, SiteRequestFields.EXTERNALSHARING_NAME),
                        RequestStatus            = this.BaseSet(_item, SiteRequestFields.PROVISIONING_STATUS_NAME),
                        Lcid                 = this.BaseSetUint(_item, SiteRequestFields.LCID_NAME),
                        TimeZoneId           = this.BaseSetInt(_item, SiteRequestFields.TIMEZONE_NAME),
                        SharePointOnPremises = this.BaseGet <bool>(_item, SiteRequestFields.ONPREM_REQUEST_NAME),
                        BusinessCase         = this.BaseSet(_item, SiteRequestFields.BC_NAME),
                        PropertiesJSON       = this.BaseSet(_item, SiteRequestFields.PROPS_NAME),
                        RequestStatusMessage = this.BaseSet(_item, SiteRequestFields.STATUSMESSAGE_NAME)
                    };
                }
            });

            return(_siteRequest);
        }
示例#23
0
 private void HandleExternalSharing(ProvisioningTemplate provisioningTemplate, SiteRequestInformation siteRequest)
 {
     //EXTERNAL SHARING CUSTOM ACTION MUST BE DEFINED IN TEMPLATE. IF THE SITE REQUEST DOES NOT HAVE EXTERNAL SHARING ENABLE WE WILL REMOVE THE CUSTOM ACCTION
     if (!siteRequest.EnableExternalSharing)
     {
         if (provisioningTemplate.CustomActions != null)
         {
             //FIND THE CUSTOM ACTION CA_SITE_EXTERNALSHARING
             var _externalSharingCA = provisioningTemplate.CustomActions.SiteCustomActions.FirstOrDefault(t => t.Title == "CA_SITE_EXTERNALSHARING");
             if (_externalSharingCA != null)
             {
                 provisioningTemplate.CustomActions.SiteCustomActions.Remove(_externalSharingCA);
             }
         }
     }
 }
示例#24
0
 private void HandleAdditionalAdministrators(ProvisioningTemplate provisioningTemplate, SiteRequestInformation siteRequest)
 {
     foreach (var _Admin in siteRequest.AdditionalAdministrators)
     {
         User _user = new User();
         _user.Name = _Admin.Name;
         provisioningTemplate.Security.AdditionalAdministrators.Add(_user);
     }
 }
示例#25
0
        private void HandlePropertyBagEntries(ProvisioningTemplate provisioningTemplate, SiteRequestInformation siteRequest)
        {
            Dictionary <string, string> _props = JsonConvert.DeserializeObject <Dictionary <string, string> >(siteRequest.PropertiesJSON);

            foreach (var prop in _props)
            {
                PropertyBagEntry _pb = new PropertyBagEntry();
                _pb.Key   = prop.Key;
                _pb.Value = prop.Value;
                provisioningTemplate.PropertyBagEntries.Add(_pb);
            }
        }
示例#26
0
        /// <summary>
        /// Internal Member to save a new site request
        /// </summary>
        /// <param name="client"></param>
        /// <param name="collectionLink"></param>
        /// <param name="info"></param>
        /// <returns></returns>
        private Document SaveNewRequest(DocumentClient client, string collectionLink, SiteRequestInformation info)
        {
            //If Settings are set to autoapprove then automatically approve the requests
            if (_manager.GetAppSettings().AutoApprove)
            {
                info.RequestStatus = SiteRequestStatus.Approved.ToString();
                info.ApprovedDate  = DateTime.Now;
            }
            else
            {
                info.RequestStatus = SiteRequestStatus.New.ToString();
            }
            info.SubmitDate = DateTime.Now;

            var      saveDocumentTask = Task.FromResult(client.CreateDocumentAsync(collectionLink, info));
            Document document         = null;

            if (!saveDocumentTask.IsFaulted)
            {
                document = saveDocumentTask.Result.Result;
            }

            return(document);
        }
示例#27
0
 internal ProvisioningTemplate HandleProvisioningTemplate(ProvisioningTemplate provisioningTemplate, SiteRequestInformation siteRequest)
 {
     this.HandleExternalSharing(provisioningTemplate, siteRequest);
     this.HandleSitePolicy(provisioningTemplate, siteRequest);
     this.HandleAdditionalAdministrators(provisioningTemplate, siteRequest);
     this.HandlePropertyBagEntries(provisioningTemplate, siteRequest);
     this.HandleCustomActions(provisioningTemplate, siteRequest);
     return(provisioningTemplate);
 }