Пример #1
0
        public void SendLog(ActionRequest request, State state)
        {
            var logs = new LogTable();

            logs.AddlogToTable(request, state);
        }
Пример #2
0
        public static void ProcessQueueMessage([QueueTrigger("siteprovisioningqueue")] ActionRequest actionRequest, TextWriter log)
        {
            try
            {
                //   Updatehelper.UpdateDashboard("Request receiveded.");

                Log.AddlogToTable(actionRequest, State.Provisioning);

                if (actionRequest.IsSiteCollection)
                {
                    CreateSiteCollection(actionRequest);
                    Updatehelper.UpdateProgressView("Provisioning", actionRequest);
                }
                else
                {
                    CreateSite(actionRequest);
                    Updatehelper.UpdateProgressView("Create site", actionRequest);
                }

                Log.AddlogToTable(actionRequest, State.Created);
                Console.WriteLine(actionRequest.Url + "/" + actionRequest.Name, actionRequest.Name, actionRequest.User);
                //var mail = new NotificationMail();
                //mail.SendMailNotification(actionRequest.Url + "/" + actionRequest.Name, actionRequest.Name, actionRequest.User);
                Updatehelper.UpdateProgressView("Done", actionRequest);
            }
            catch (Exception ex)
            {
                Log.AddlogToTable(actionRequest, State.Failed);
                Updatehelper.UpdateProgressView("Failed", actionRequest);

                Console.WriteLine(ex.ToString(), "Failed creating site: " + actionRequest.Url + "/" + actionRequest.Name,
                                  actionRequest.User);

                //var mail = new NotificationMail();
                //mail.SendMailNotification(ex.ToString(), "Failed creating site: " + actionRequest.Url + "/" + actionRequest.Name, actionRequest.User);

                if (actionRequest.IsSiteCollection)
                {
                    var tenantAdminUri = new Uri($"https://{actionRequest.TenantName}-admin.sharepoint.com");
                    var realm          = TokenHelper.GetRealmFromTargetUrl(tenantAdminUri);
                    var token          =
                        TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, tenantAdminUri.Authority,
                                                          realm).AccessToken;
                    using (var ctx = TokenHelper.GetClientContextWithAccessToken(tenantAdminUri.ToString(), token))
                    {
                        var manager = new SiteCollectionManager(actionRequest, ctx);
                        manager.TryDeleteSiteCollection();
                    }
                }
                else
                {
                    var tenantAdminUri = new Uri(actionRequest.Url);
                    var realm          = TokenHelper.GetRealmFromTargetUrl(tenantAdminUri);
                    var token          =
                        TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, tenantAdminUri.Authority,
                                                          realm).AccessToken;
                    using (var ctx = TokenHelper.GetClientContextWithAccessToken(tenantAdminUri.ToString(), token))
                    {
                        var manager = new SiteManager(actionRequest, ctx);
                        manager.TryDeleteSite();
                    }
                }
            }
        }