Example #1
0
        public async Task AddQuery(SList list)
        {
            if (list == null)
            {
                return;
            }
            if (list.Fields?.Count == 0)
            {
                try
                {
                    StatusNotification.NotifyWithProgress("Prepairing list: " + list.Title);
                    await list.Web.Client.FillListFields(list);

                    StatusNotification.Notify("List ready");
                }
                catch (Exception)
                {
                    StatusNotification.Notify("Prepairing list failed");
                    return;
                }
            }

            this.SelectedIndex = this.Items.Add(
                new ClosableTabItem
            {
                HeaderText = list.Title,
                Content    = new QueryTab(list)
                {
                    Margin = new Thickness(4)
                }
            });

            CommandManager.InvalidateRequerySuggested();
        }
Example #2
0
        protected override IEnumerable <Control> InitializeControls(string oldValue)
        {
            var controls = base.InitializeControls(oldValue);

            _control.DisplayMemberPath = "Name";
            _control.SelectedValuePath = "Id";

            _control.DropDownOpened += async(sender, args) =>
            {
                if (Field.List.ContentTypes == null || Field.List.Web.ContentTypes == null)
                {
                    StatusNotification.NotifyWithProgress("Loading Content Types");
                    await Field.List.Web.Client.FillContentTypes(Field.List);

                    StatusNotification.Notify("Content Types loaded");
                }

                var contentTypes = Field.List.ContentTypes
                                   .OrderBy(ct => ct.Name)
                                   .Concat(Field.List.Web.ContentTypes.OrderBy(ct => ct.Name));

                _control.ItemsSource =
                    contentTypes.Select(ct => new
                {
                    ct.Id,
                    Name = Field.List.ContentTypes.Contains(ct) ? "List." + ct.Name : ct.Name
                });
            };

            return(controls);
        }
Example #3
0
        private async void ucConnectButton_Click(object sender, RoutedEventArgs e)
        {
            Telemetry.Instance.Native?.TrackEvent("Connect.OK", new Dictionary <string, string>
            {
                { "ProviderType", Model.ProviderType.ToString() },
            });

            var client = SharePointProviderFactory.Create(Model.ProviderType);

            try
            {
                Model.IsConnecting = true;
                StatusNotification.NotifyWithProgress("Connecting...");

                if (await client.Connect(Model.SharePointWebUrl, Model.UserName, Model.UserPassword) != null)
                {
                    Client = client;
                    Model.AddNewUrl(Model.SharePointWebUrl);
                    Model.AddUserToHistory(Model.UserName);
                    Model.Save();

                    OnDialogResult(client);
                }
                StatusNotification.Notify("Connected");
            }
            catch (Exception ex)
            {
                Model.ErrorMessage = "Error: " + ExceptionHandler.HandleConnection(ex);
            }

            Model.IsConnecting = false;
        }
Example #4
0
        private async void SaveChangesCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            Telemetry.Instance.Native?.TrackEvent("Main.SaveChanges");
            var dirtyItems = ucQueries.SelectedQueryTab.ucItems.GetDirtyItems();
            var index      = 0;

            try
            {
                foreach (var listItem in dirtyItems)
                {
                    StatusNotification.Notify("Updating item with id: " + listItem.Id, ++index, dirtyItems.Count);

                    try
                    {
                        await listItem.Update();
                    }
                    catch
                    {
                        listItem.CancelChanges();

                        if (dirtyItems.Last() == listItem)
                        {
                            MessageBox.Show("Couldn't update item with id: " + listItem.Id, "SmartCAML",
                                            MessageBoxButton.OK, MessageBoxImage.Information);
                        }
                        else if (
                            MessageBox.Show(
                                "Couldn't update item with id: " + listItem.Id + "\n\n Would you like to continue?",
                                "SmartCAML",
                                MessageBoxButton.OKCancel, MessageBoxImage.Question) != MessageBoxResult.OK)
                        {
                            break;
                        }
                    }
                }

                StatusNotification.Notify("Update completed");
            }
            catch (Exception ex)
            {
                StatusNotification.Notify("Update failed");
                ExceptionHandler.Handle(ex, "The request failed.");
            }
        }
Example #5
0
        private async void RunQueryCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            Telemetry.Instance.Native?.TrackEvent("Main.RunQuery");
            Telemetry.Instance.Native?.TrackMetric("RunQuery", 1);

            var query = ucQueries.SelectedQueryTab.GetQuery();

            try
            {
                var list = ucQueries.SelectedQueryTab.List;
                StatusNotification.NotifyWithProgress("Quering list: " + list.Title);

                var items = await ucWebs.GetClient(list.Web).ExecuteQuery(query, Config.PageSize);

                ucQueries.SelectedQueryTab.QueryResult(items);

                StatusNotification.Notify("Retrived items: " + items.Count);
            }
            catch (Exception ex)
            {
                StatusNotification.Notify("Quering failed");
                ExceptionHandler.Handle(ex, "The request failed.");
            }
        }