private async Task <ValidateResult> ValidateSPOUserID(UserAuthorizationQuery state, object value)
        {
            string _inputSPOUserID = Convert.ToString(value);
            var    result          = new ValidateResult {
                IsValid = false, Value = _inputSPOUserID
            };

            SharePointPrimary obj = new SharePointPrimary(state.SiteCollectionURL);

            result.IsValid = obj.IsValidSPOUser(_inputSPOUserID);
            if (!result.IsValid)
            {
                result.Feedback = $"I could not find your profile {_inputSPOUserID} in our O365 tenant. " +
                                  "\r\r If you are an external user, please raise your request in the 'External User Access' option" +
                                  "\r\r or enter a valid user id.";
            }
            else
            {
                // call method to check permission
                string _userPermission = obj.CheckUserPermission(state.SiteCollectionURL, _inputSPOUserID);
                if (string.IsNullOrEmpty(_userPermission))
                {
                    result.Feedback = "Yes. I have found your profile in our O365 tenant. ";// +
                }
                //"\r\r To know more about permission, please visit : "+ Constants.RoleTypeMSDN;
                else
                {
                    result.Feedback = $"Looks like you already have some permissions assigned to you : " +
                                      $"\r\r {_userPermission}";  // +
                }
                // "\r\r To know more about permission,please visit : " + Constants.RoleTypeMSDN;
            }

            return(result);
        }
示例#2
0
        private async Task <ValidateResult> ValidateSiteCollectionURL(SiteCreationQuery state, object value)
        {
            string _inputSiteCollectionTitle = Convert.ToString(value);
            var    result = new ValidateResult {
                IsValid = false, Value = _inputSiteCollectionTitle
            };

            SharePointPrimary obj = new SharePointPrimary();

            result.IsValid = obj.DoesContainSpecialCharacter(_inputSiteCollectionTitle);

            if (result.IsValid)
            {
                result.IsValid = !obj.DoesURLExist(_inputSiteCollectionTitle);
                if (!result.IsValid)
                {
                    result.Feedback = $"A site collection with url '{_inputSiteCollectionTitle}' is already present in our tenant. Try something different.";
                }
                else
                {
                    result.Feedback = "The site title is available to use.";
                }
            }
            else
            {
                result.Feedback = "Special characters are not allowed in site collection URL.";
            }

            return(result);
        }
        private async Task ResumeUserAuthorizationDialog(IDialogContext context, IAwaitable <UserAuthorizationQuery> result)
        {
            try
            {
                var    resultFromUserAuthorization = await result;
                string _strURL              = resultFromUserAuthorization.SiteCollectionURL;
                string _strUserID           = resultFromUserAuthorization.SPOUserID;
                int    _intRoleype          = Convert.ToInt32(resultFromUserAuthorization.SharepointOnlineRole);
                bool   _isPermissionGranted = false;

                SharePointPrimary obj = new SharePointPrimary();


                if (!string.IsNullOrEmpty(_strURL) && !string.IsNullOrEmpty(_strUserID) && (_intRoleype != 255))
                {
                    try
                    {
                        _isPermissionGranted = obj.HasPermissionGrantedToUser(_strURL, _strUserID, _intRoleype);

                        if (_isPermissionGranted)
                        {
                            await context.PostAsync($"Access granted \U00002705 Please browse the site url '{_strURL}' ");

                            context.Done("Done");
                        }
                        else
                        {
                            await context.PostAsync("Permission could not be granted \U0001F641 . Please try again later.");

                            context.Done("Not Done");
                        }
                    }
                    catch (Exception ex)
                    {
                        context.Fail(new TooManyAttemptsException("Unable to grant permission to user \U0001F641 . Please try again later."));
                    }
                }
            }
            catch (TooManyAttemptsException)
            {
                await context.PostAsync("Sorry \U0001F641 , I am unable to understand you. Let us try again.");
            }
        }
示例#4
0
        private async Task ResumeSiteCreationDialog(IDialogContext context, IAwaitable <SiteCreationQuery> result)
        {
            var               resultFromSiteCreation = await result;
            string            _strSiteTitle          = resultFromSiteCreation.SiteCollectionTitle;
            string            _strPrimaryAdmin       = resultFromSiteCreation.PrimarySiteCollectionAdmin;
            SharePointPrimary obj = new SharePointPrimary();

            try
            {
                if (!string.IsNullOrEmpty(_strSiteTitle) && !string.IsNullOrEmpty(_strPrimaryAdmin))
                {
                    try
                    {
                        Task <bool> _isCreated = obj.IsSiteCollectionCreated(_strSiteTitle, _strPrimaryAdmin);

                        Attachment attachment = new Attachment();
                        attachment.ContentType = "application/pdf";
                        attachment.ContentUrl  = Constants.RootSiteCollectionURL + "" + Constants.ManagedPath + "" + _strSiteTitle;
                        attachment.Name        = _strSiteTitle;

                        var replyMessage = context.MakeMessage();
                        replyMessage.Attachments = new List <Attachment> {
                            attachment
                        };

                        await context.PostAsync("I have started creating your site collection. It may take 5 - 10 minutes to complete the process." +
                                                "\r\r Please browse the site ['SOHA_" + _strSiteTitle + "'](" + Constants.RootSiteCollectionURL + "" + Constants.ManagedPath + "" + _strSiteTitle + ") after sometime.");

                        //await context.PostAsync("Please browse the site '" + Constants.RootSiteCollectionURL + "" + Constants.ManagedPath + "" + _strSiteTitle + "' after sometime.");
                        context.Done("Done");
                    }
                    catch (Exception)
                    {
                        context.Fail(new Exception("Unable to create site collection."));
                        await context.PostAsync("Sorry \U0001F641 , I am unable to create site collection for you. Let us try again.");
                    }
                }
            }
            catch (TooManyAttemptsException)
            {
                await context.PostAsync("Sorry \U0001F641 , I am unable to understand you. Let us try again.");
            }
        }
示例#5
0
        private async Task <ValidateResult> ValidatePrimaryAdmin(SiteCreationQuery state, object value)
        {
            string _inputSPOUserID = Convert.ToString(value);
            var    result          = new ValidateResult {
                IsValid = false, Value = _inputSPOUserID
            };

            SharePointPrimary obj = new SharePointPrimary();

            result.IsValid = obj.IsValidSPOUser(_inputSPOUserID);
            if (!result.IsValid)
            {
                result.Feedback = $"I could not find the site collection administrator's profile {_inputSPOUserID} in our O365 tenant. ";
            }
            else
            {
                result.Feedback = "Yes. I have found the primary site collection administrator's profile in our O365 tenant. ";
            }
            return(result);
        }
示例#6
0
        private async Task <ValidateResult> ValidateSiteCollectionURL(ExternalSharingQuery state, object value)
        {
            string _inputSiteCollectionURL = Convert.ToString(value);
            var    result = new ValidateResult {
                IsValid = false, Value = _inputSiteCollectionURL
            };

            SharePointPrimary obj = new SharePointPrimary(_inputSiteCollectionURL);

            result.IsValid = obj.IsValidSiteCollectionURL();
            if (!result.IsValid)
            {
                result.Feedback = $"This site {_inputSiteCollectionURL} does not exist in our O365 tenant. Please enter a valid URL.";
            }
            else
            {
                result.Feedback = "Yes. I have found this site collection in our O365 tenant.";
            }

            return(result);
        }
        private async Task <ValidateResult> ValidateSPOUserID(SiteQuotaChangeQuery state, object value)
        {
            string _inputSPOUserID = Convert.ToString(value);
            var    result          = new ValidateResult {
                IsValid = false, Value = _inputSPOUserID
            };

            SharePointPrimary obj = new SharePointPrimary(state.SiteCollectionURL);

            result.IsValid = obj.IsValidSPOUser(_inputSPOUserID);
            if (!result.IsValid)
            {
                result.Feedback = $"I could not find the profile {_inputSPOUserID} in our O365 tenant. ";
            }
            else
            {
                result.Feedback = "Yes, I have found your profile in our O365 tenant.";
            }

            return(result);
        }
示例#8
0
        private async Task ResumeUserProfileDialog(IDialogContext context, IAwaitable <ProfileUpdateQuery> result)
        {
            try
            {
                var resultFromUserProfile = await result;

                string _strUserID        = resultFromUserProfile.SPOUserID;
                string _strProperty      = Convert.ToString(resultFromUserProfile.UserProfilePropertyToUpdate);
                bool   _isProfileUpdated = false;

                SharePointPrimary obj = new SharePointPrimary();

                try
                {
                    _isProfileUpdated = obj.IsUserProfilePropertyUpdated(_strUserID, _strProperty);

                    if (_isProfileUpdated)
                    {
                        await context.PostAsync($"Profile Updated \U00002705  ");

                        context.Done("Done");
                    }
                    else
                    {
                        await context.PostAsync("Profile could not be updated \U0001F641 Please try again later.");

                        context.Done("Not Done");
                    }
                }
                catch (Exception ex)
                {
                    context.Fail(new TooManyAttemptsException("Unable to user profile \U0001F641 Please try again later."));
                }
            }
            catch (TooManyAttemptsException)
            {
                await context.PostAsync("Sorry \U0001F641 I am unable to understand you. Let us try again.");
            }
        }
示例#9
0
        private async Task ResumeExternalSharingDialog(IDialogContext context, IAwaitable <ExternalSharingQuery> result)
        {
            try
            {
                var    resultFromExtrnalSharing = await result;
                string _strURL                         = resultFromExtrnalSharing.SiteCollectionURL;
                string _strUserID                      = resultFromExtrnalSharing.SPOExternalUserID;
                bool   _isPermissionGranted            = false;
                bool   _isSiteCollectionSharingEnabled = false;
                bool   _isTenantSharingEnabled         = false;

                try
                {
                    SharePointPrimary obj = new SharePointPrimary(_strURL);

                    List <string> lstSiteCollectionAdmins = new List <string>();
                    lstSiteCollectionAdmins = obj.GetSiteCollectionAdmins();
                    string strSiteCollectionAdmins = string.Empty;

                    foreach (var eachAdmin in lstSiteCollectionAdmins)
                    {
                        strSiteCollectionAdmins += eachAdmin + "; ";
                    }

                    _isTenantSharingEnabled = obj.IsTenantExternalSharingEnabled();
                    if (_isTenantSharingEnabled)
                    {
                        _isSiteCollectionSharingEnabled = obj.IsSiteCollectionExternalSharingEnabled(_strURL);
                        if (_isSiteCollectionSharingEnabled)
                        {
                            _isPermissionGranted = obj.HasAccessGrantedToExternalUser(_strURL, _strUserID);

                            if (_isPermissionGranted)
                            {
                                await context.PostAsync($"Access granted \U00002705 An email is sent to '{_strUserID}' ");

                                //context.Done("External Access granted.");
                                context.Done("Done");
                            }
                            else
                            {
                                await context.PostAsync("Permission could not be granted. Please try again later.");

                                //context.Done("External Access could not be granted.");
                                context.Done("Not Done");
                            }
                        }
                        else
                        {
                            await context.PostAsync($"Access could not be granted as External Sharing is disabled for this Site Collection.");

                            await context.PostAsync($"Please reach out to one of the Site Collection Adminstrators listed below:" +
                                                    "\r\r" + strSiteCollectionAdmins);

                            //context.Done("Access could not be granted. External Sharing is disabled for this Site Collection.");
                            context.Done("Not Done");
                        }
                    }
                    else
                    {
                        await context.PostAsync($"Access could not be granted as External Sharing is disabled at our Tenant level. ");

                        await context.PostAsync($"Please reach out to one of the Site Collection Adminstrators listed below:" +
                                                "\r\r" + strSiteCollectionAdmins);

                        //context.Done("Access could not be granted. External Sharing is disabled at our Tenant level.");
                        context.Done("Not Done");
                    }
                }
                catch (Exception)
                {
                    context.Fail(new Exception("Unable to grant permission to user \U0001F641 . Please try again later."));
                }
            }
            catch (TooManyAttemptsException)
            {
                await context.PostAsync("Sorry \U0001F641 , I am unable to understand you. Let us try again.");
            }
        }
        private async Task ResumeArticleSearchDialog(IDialogContext context, IAwaitable <ArticleSearchQuery> result)
        {
            try
            {
                var    resultFromArticleSearch = await result;
                string _strhelpArticle         = Convert.ToString(resultFromArticleSearch.HelpArticle);
                int    _iLearningMaterial      = Convert.ToInt32(resultFromArticleSearch.LearningMaterial);

                try
                {
                    SharePointPrimary             obj          = new SharePointPrimary();
                    Dictionary <ListItem, string> searchedDocs = new Dictionary <ListItem, string>();

                    if (_iLearningMaterial == 2)
                    {
                        searchedDocs = obj.SearchLearningVideoByTopic(_strhelpArticle);
                        if (searchedDocs.Count > 0)
                        {
                            if (searchedDocs.Count == 1)
                            {
                                await context.PostAsync($"I have found {searchedDocs.Count} video on your search topic \U0001F44D ");
                            }
                            else
                            {
                                await context.PostAsync($"I have found {searchedDocs.Count} videos on your search topic \U0001F44D ");
                            }

                            foreach (var eachDoc in searchedDocs)
                            {
                                try
                                {
                                    var videoCard = new VideoCard();
                                    videoCard.Title    = eachDoc.Key.FieldValuesAsHtml["Title"];
                                    videoCard.Subtitle = eachDoc.Key.FieldValuesAsHtml["SubTitle"];
                                    videoCard.Text     = eachDoc.Key.FieldValuesAsHtml["VideoSetDescription"];

                                    string _previewImageBase64 = obj.GetImage(eachDoc.Key.FieldValuesAsText["AlternateThumbnailUrl"].Split(',')[0].ToString(), _iLearningMaterial);


                                    if (!string.IsNullOrEmpty(_previewImageBase64))
                                    {
                                        videoCard.Image = new ThumbnailUrl(
                                            url: _previewImageBase64,
                                            alt: "Learning Video");
                                    }

                                    //string _videoBase64 = obj.GetVideo("https://avaindcollabsl.sharepoint.com/sites/SOHA_HelpRepository/VideoRepository/Build%20a%20Chat%20Bot%20with%20Azure%20Bot%20Service/buildachatbotwithazurebotservice_high.mp4");

                                    //string _videoBase64 = obj.GetVideo(eachDoc.Value);


                                    if (!string.IsNullOrEmpty(eachDoc.Value))
                                    {
                                        videoCard.Media = new List <MediaUrl> {
                                            new MediaUrl("https://sec.ch9.ms/ch9/a7a4/10df13cf-a7ac-40a2-b713-6fcc935ba7a4/buildachatbotwithazurebotservice.mp4")
                                        };

                                        videoCard.Buttons = new List <CardAction> {
                                            new CardAction(
                                                type: ActionTypes.OpenUrl,
                                                title: "Learn more",
                                                value: "https://channel9.msdn.com/Blogs/MVP-Azure/build-a-chatbot-with-azure-bot-service")
                                        };
                                    }


                                    //if (!string.IsNullOrEmpty(/*eachDoc.Value*/_videoBase64))
                                    //{
                                    //    videoCard.Media = new List<MediaUrl> { new MediaUrl(_videoBase64) };

                                    //    videoCard.Buttons = new List<CardAction> { new CardAction(
                                    //    type  : ActionTypes.OpenUrl,
                                    //    title : "Learn more",
                                    //    value : eachDoc.Value) };
                                    //}

                                    Microsoft.Bot.Connector.Attachment attachment = new Microsoft.Bot.Connector.Attachment();
                                    var replyMessage = context.MakeMessage();
                                    attachment = videoCard.ToAttachment();
                                    replyMessage.Attachments.Add(attachment);

                                    await context.PostAsync(replyMessage);
                                }
                                catch (Exception ex)
                                {
                                    await context.PostAsync(ex.Message);
                                }
                            }

                            await context.PostAsync("Hope you have found the result informative. Do you want to search for any other topic?");

                            context.Wait(MessageReceived);
                        }
                        else
                        {
                            await context.PostAsync($"No video found. Do you want to search for any other topic?");

                            context.Wait(MessageReceived);
                        }
                    }
                    else if (_iLearningMaterial == 1)
                    {
                        searchedDocs = obj.SearchHelpArticleonTopic(_strhelpArticle);
                        if (searchedDocs.Count > 0)
                        {
                            if (searchedDocs.Count == 1)
                            {
                                await context.PostAsync($"I have found {searchedDocs.Count} article on your search topic \U0001F44D ");
                            }
                            else
                            {
                                await context.PostAsync($"I have found {searchedDocs.Count} articles on your search topic \U0001F44D ");
                            }

                            foreach (var eachDoc in searchedDocs)
                            {
                                Microsoft.Bot.Connector.Attachment attachment = new Microsoft.Bot.Connector.Attachment();

                                var replyMessage = context.MakeMessage();

                                var heroCard = new HeroCard();

                                string _previewImageBase64 = obj.GetImage(eachDoc.Value.ToString(), _iLearningMaterial);

                                heroCard.Title    = eachDoc.Key.DisplayName;
                                heroCard.Subtitle = "by Avanade Collab SL Capability";
                                heroCard.Text     = eachDoc.Key.FieldValuesAsHtml["KpiDescription"];
                                heroCard.Buttons  = new List <CardAction> {
                                    new CardAction(ActionTypes.OpenUrl, "Read more", value: Constants.RootSiteCollectionURL + eachDoc.Key.File.ServerRelativeUrl)
                                };

                                if (!string.IsNullOrEmpty(_previewImageBase64))
                                {
                                    heroCard.Images = new List <CardImage> {
                                        new CardImage(_previewImageBase64)
                                    }
                                }
                                ;


                                attachment = heroCard.ToAttachment();
                                replyMessage.Attachments.Add(attachment);

                                await context.PostAsync(replyMessage);
                            }

                            await context.PostAsync("Hope you have found the result informative. Do you want to search for any other topic?");

                            context.Wait(MessageReceived);
                        }
                        else
                        {
                            await context.PostAsync($"No document found. Do you want to search for any other topic?");

                            context.Wait(MessageReceived);
                        }
                    }
                }
                catch (TooManyAttemptsException)
                {
                    context.Fail(new TooManyAttemptsException("Unable to find any help document."));
                }
            }
            catch (TooManyAttemptsException)
            {
                await context.PostAsync("Sorry \U0001F641 , I am unable to understand you. Let us try again.");
            }
        }
        private async Task ResumeSiteQuotaDialog(IDialogContext context, IAwaitable <SiteQuotaChangeQuery> result)
        {
            try
            {
                var    resultFromSiteQuotaChange = await result;
                string _strURL    = resultFromSiteQuotaChange.SiteCollectionURL;
                string _strUserID = resultFromSiteQuotaChange.SPOUserID;
                //int _intNewQuota = Convert.ToInt32(resultFromSiteQuotaChange.NewStorageQuota);
                int _intNewQuota = 1;

                if (!string.IsNullOrEmpty(_strURL) && !string.IsNullOrEmpty(_strUserID) && (_intNewQuota != 0))
                {
                    try
                    {
                        SharePointPrimary obj      = new SharePointPrimary(_strURL);
                        bool isSiteCollectionAdmin = obj.IsSiteCollectionAdmin(_strUserID);
                        if (isSiteCollectionAdmin)
                        {
                            bool isStorageUpdated = obj.IsSiteCollectionStorageQuotaUpdated(_strURL, _intNewQuota);
                            //context.Done("Storage Quota Updated.");
                            if (isStorageUpdated)
                            {
                                await context.PostAsync($"The Storage Quota for the Site Collection '{_strURL}' is being updated. Please refresh it after sometime.");

                                context.Done("Done");
                            }
                            else
                            {
                                await context.PostAsync("Storage quota could not be updated \U0001F641 . Please try again later.");

                                context.Done("Not Done");
                            }
                        }
                        else
                        {
                            List <string> lstSiteCollectionAdmins = new List <string>();
                            lstSiteCollectionAdmins = obj.GetSiteCollectionAdmins();
                            string strSiteCollectionAdmins = string.Empty;

                            foreach (var eachAdmin in lstSiteCollectionAdmins)
                            {
                                strSiteCollectionAdmins += eachAdmin + ";";
                            }

                            await context.PostAsync($"I just found out that you are not authorized to update the Storage Quota of the Site Collection '{_strURL}'");

                            await context.PostAsync($"Please reach out to one of the Site Collection Adminstrators listed below:" +
                                                    "\r\r" + strSiteCollectionAdmins);

                            context.Done("Not Done");
                        }
                    }
                    catch (Exception)
                    {
                        context.Fail(new TooManyAttemptsException("Unable to update Storage Quota \U0001F641 . Please try again later."));
                    }
                }
            }
            catch (TooManyAttemptsException)
            {
                await context.PostAsync("Sorry \U0001F641 , I am unable to understand you. Let us try again.");
            }
        }