コード例 #1
0
ファイル: Program.cs プロジェクト: TBag/O365CSOMAlerts
        private static void CreateMyAlert(ClientContext context)
        {
            Console.ForegroundColor = ConsoleColor.White;

            Web web = context.Web;

            context.Load(web);
            context.Load(web.Lists);

            User currentUser = context.Web.CurrentUser;

            context.Load(currentUser);
            context.Load(currentUser.Alerts);
            context.Load(currentUser.Alerts,
                         lists => lists.Include(
                             list => list.Title,
                             list => list.ListID));

            context.ExecuteQuery();

            AlertCreationInformation myNewAlert = new AlertCreationInformation();

            myNewAlert.List             = context.Web.Lists.GetByTitle("Documents");
            myNewAlert.AlertFrequency   = AlertFrequency.Daily;
            myNewAlert.AlertTime        = DateTime.Today.AddDays(1);
            myNewAlert.AlertType        = AlertType.List;
            myNewAlert.AlwaysNotify     = false;
            myNewAlert.DeliveryChannels = AlertDeliveryChannel.Email;
            myNewAlert.EventType        = AlertEventType.All;
            myNewAlert.Filter           = "0";
            myNewAlert.Status           = AlertStatus.On;
            myNewAlert.Title            = "My new alert created at : " + DateTime.Now.ToString();
            myNewAlert.User             = currentUser;

            var newAlertGuid = currentUser.Alerts.Add(myNewAlert);

            currentUser.Update();

            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Creating alert for user " + currentUser.Title);
            Console.WriteLine("");

            context.ExecuteQuery();

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("New alert created with ID = " + newAlertGuid.Value.ToString());
            Console.WriteLine("");
        }
コード例 #2
0
ファイル: GetAlert.cs プロジェクト: veniti/PnP-PowerShell
        protected override void ExecuteCmdlet()
        {
            List list = null;

            if (List != null)
            {
                list = List.GetList(SelectedWeb);
            }

            var alert = new AlertCreationInformation();

            User user;

            if (null != User)
            {
                user = User.GetUser(ClientContext);
                if (user == null)
                {
                    throw new ArgumentException("Unable to find user", "Identity");
                }
            }
            else
            {
                user = SelectedWeb.CurrentUser;
            }

            user.EnsureProperty(u => u.Alerts.IncludeWithDefaultProperties(a => a.ListID));
            if (list != null && !string.IsNullOrWhiteSpace(Title))
            {
                WriteObject(user.Alerts.Where(l => l.ListID == list.Id && l.Title == Title), true);
            }
            else if (list != null)
            {
                WriteObject(user.Alerts.Where(l => l.ListID == list.Id), true);
            }
            else if (!string.IsNullOrWhiteSpace(Title))
            {
                WriteObject(user.Alerts.Where(l => l.Title == Title), true);
            }
            else
            {
                WriteObject(user.Alerts, true);
            }
        }
コード例 #3
0
        protected override void ExecuteCmdlet()
        {
            List list = null;

            if (List != null)
            {
                list = List.GetList(SelectedWeb);
            }
            if (list != null)
            {
                var alert = new AlertCreationInformation();

                User user;
                if (null != User)
                {
                    user = User.GetUser(ClientContext);
                    if (user == null)
                    {
                        throw new ArgumentException("Unable to find user", "Identity");
                    }
                }
                else
                {
                    user = SelectedWeb.CurrentUser;
                }

                alert.AlertFrequency   = Frequency;
                alert.AlertType        = AlertType.List;
                alert.AlwaysNotify     = false;
                alert.DeliveryChannels = DeliveryMethod;
                var filterValue = Convert.ChangeType(Filter, Filter.GetTypeCode()).ToString();
                alert.Filter = filterValue;

                // setting the value of Filter sometimes does not work (CSOM < Jan 2017, ...?), so we use a known workaround
                // reference: http://toddbaginski.com/blog/how-to-create-office-365-sharepoint-alerts-with-the-client-side-object-model-csom/
                var properties = new Dictionary <string, string>()
                {
                    { "FilterIndex", filterValue }
                    //Send Me an alert when:
                    // 0 = Anything Changes
                    // 1 = Someone else changes a document
                    // 2 = Someone else changes a document created by me
                    // 3 = Someone else changes a document modified by me
                };
                alert.Properties = properties;

                alert.List      = list;
                alert.Status    = AlertStatus.On;
                alert.Title     = Title;
                alert.User      = user;
                alert.EventType = ChangeType;
                if (Time != DateTime.MinValue)
                {
                    alert.AlertTime = Time;
                }

                user.Alerts.Add(alert);
                ClientContext.ExecuteQueryRetry();
                WriteObject(alert);
            }
            else
            {
                throw new ArgumentException("Unable to find list", "List");
            }
        }