Exemple #1
0
        private CamlFilters GetCustomFilters()
        {
            CamlFilters customFilters = new CamlFilters();

            if (string.IsNullOrEmpty(searchTextBox1.Text) == false)
            {
                if (this.SelectedFolder as SPFolder != null &&
                    (this.SelectedFolder as SPFolder).IsDocumentLibrary == true)
                {
                    customFilters.Add(new CamlFilter("FileLeafRef", FieldTypes.Text, CamlFilterTypes.Contains, searchTextBox1.Text));
                }
                else
                {
                    customFilters.Add(new CamlFilter("Title", FieldTypes.Text, CamlFilterTypes.Contains, searchTextBox1.Text));
                }
            }

            return(customFilters);
        }
        public int GetUserObjectAccessDetails(ISiteSetting siteSetting, Guid objectId, Guid userId)
        {
            IOrganizationService organizationService = GetClientContext(siteSetting);
            QueryExpression      query   = new QueryExpression("principalobjectaccess");
            CamlFilters          filters = new CamlFilters();

            filters.IsOr = false;
            filters.Add(new CamlFilter("objectid", FieldTypes.Text, CamlFilterTypes.Equals, objectId.ToString()));
            filters.Add(new CamlFilter("principalid", FieldTypes.Text, CamlFilterTypes.Equals, userId.ToString()));
            query.Criteria  = GetFilterExpression(filters);
            query.ColumnSet = new ColumnSet(true);
            EntityCollection items = organizationService.RetrieveMultiple(query);

            if (items.Entities.Count > 0)
            {
                string accessrightsmask          = items.Entities[0]["accessrightsmask"].ToString();
                string inheritedaccessrightsmask = items.Entities[0]["inheritedaccessrightsmask"].ToString();
            }

            return(0);
        }
        public CamlFilters GetFilters()
        {
            CamlFilters filters = new CamlFilters();

            filters.IsOr = false;
            List <CriteriaPaneItem> items = (List <CriteriaPaneItem>)CriteriaGrid.ItemsSource;

            foreach (CriteriaPaneItem item in items)
            {
                CamlFilters filters1 = new CamlFilters();
                filters1.IsOr = true;
                if (string.IsNullOrEmpty(item.Filter1) == false)
                {
                    CamlFilter filter = new CamlFilter(item.FieldInternalName, item.FieldType, CamlFilterTypes.Equals, item.Filter1);
                    filters1.Add(filter);
                }
                if (string.IsNullOrEmpty(item.Filter2) == false)
                {
                    CamlFilter filter = new CamlFilter(item.FieldInternalName, item.FieldType, CamlFilterTypes.Equals, item.Filter2);
                    filters1.Add(filter);
                }
                if (string.IsNullOrEmpty(item.Filter3) == false)
                {
                    CamlFilter filter = new CamlFilter(item.FieldInternalName, item.FieldType, CamlFilterTypes.Equals, item.Filter3);
                    filters1.Add(filter);
                }
                if (string.IsNullOrEmpty(item.Filter4) == false)
                {
                    CamlFilter filter = new CamlFilter(item.FieldInternalName, item.FieldType, CamlFilterTypes.Equals, item.Filter4);
                    filters1.Add(filter);
                }

                if (filters1.Filters.Count > 0)
                {
                    filters.Add(filters1);
                }
            }
            return(filters);
        }
Exemple #4
0
        private void SearchButton_Click(object sender, RoutedEventArgs e)
        {
            SiteSetting     siteSetting    = this.SiteSettings[SelectedDocumentTemplateMapping.Folder.SiteSettingID];
            IServiceManager serviceManager = ServiceManagerFactory.GetServiceManager(siteSetting.SiteSettingType);
            Folder          targetFolder   = serviceManager.GetFolder(siteSetting, SelectedDocumentTemplateMapping.Folder);

            int    itemCount;
            string listItemCollectionPositionNext = String.Empty;
            Folder selectedFolder   = targetFolder;
            IView  selectedView     = null;
            string sortedFieldName  = string.Empty;
            bool   isAsc            = true;
            int    currentPageIndex = 0;
            string currentListItemCollectionPositionNext = "0";

            CamlFilters customFilters = new CamlFilters();

            customFilters.IsOr = false;

            Dictionary <string, SearchFilters> searchFilters;

            if (radioButtonWord.IsChecked == true)
            {
                searchFilters = WordSearchFilters;
            }
            else if (radioButtonOutlook.IsChecked == true)
            {
                searchFilters = OutlookSearchFilters;
            }
            else
            {
                searchFilters = ExcelSearchFilters;
            }

            foreach (string key in searchFilters.Keys)
            {
                CamlFilter customFilter = new CamlFilter(searchFilters[key][0]);
                customFilters.Add(customFilter);
            }

            List <IItem> items = ApplicationContext.Current.GetListItems(siteSetting, selectedFolder, selectedView, sortedFieldName, isAsc, currentPageIndex, currentListItemCollectionPositionNext, customFilters, true, out listItemCollectionPositionNext, out itemCount);

            ApplicationContext.Current.BindSearchResultsToListViewControl(siteSetting, items, SearchResultDataGridView);
        }
        public List <IView> GetPersonalViews(ISiteSetting siteSetting, CRMEntity entity)
        {
            Logger.Warning("GetPersonalViews 0", "GetPersonalViews");

            List <IView>         views = new List <IView>();
            IOrganizationService organizationService = GetClientContext(siteSetting);

            // Dictionary to contain all the saved views
            Dictionary <Guid, Entity> dictPersonalViews = new Dictionary <Guid, Entity>();

            // retrieve first all the CRM Users
            QueryExpression systemUsers = new QueryExpression("systemuser");
            CamlFilters     filters1    = new CamlFilters();

            filters1.Add(new CamlFilter("isdisabled", FieldTypes.Text, CamlFilterTypes.Equals, "FALSE"));
            systemUsers.Criteria = GetFilterExpression(filters1);


            systemUsers.ColumnSet = new ColumnSet(true);
            EntityCollection userCollection = organizationService.RetrieveMultiple(systemUsers);

            Logger.Warning("GetPersonalViews 1", "GetPersonalViews");

            Logger.Warning("Count:" + userCollection.Entities.Count, "GetPersonalViews");
            int currentIndex = 0;

            // for each User we launch the query to retrieve the saved views
            foreach (Entity systemUser in userCollection.Entities)
            {
                try
                {
                    currentIndex++;
                    Logger.Warning("Index:" + currentIndex, "GetPersonalViews");

                    QueryExpression personalViews = new QueryExpression("userquery");
                    CamlFilters     filters       = new CamlFilters();
                    filters.Add(new CamlFilter("returnedtypecode", FieldTypes.Text, CamlFilterTypes.Equals, entity.LogicalName));
                    personalViews.Criteria = GetFilterExpression(filters);
                    Logger.Warning("GetPersonalViews 2" + entity.LogicalName, "GetPersonalViews");

                    personalViews.ColumnSet = new ColumnSet(true);

                    // we set the CallerId property to impersonate the current iteration user
                    //Logger.Warning("GetPersonalViews 3" + entity.LogicalName, "GetPersonalViews");
                    ((OrganizationServiceProxy)organizationService).CallerId = systemUser.Id;
                    //Logger.Warning("GetPersonalViews 4" + entity.LogicalName, "GetPersonalViews");
                    EntityCollection viewCollection = organizationService.RetrieveMultiple(personalViews);
                    //Logger.Warning("GetPersonalViews 5" + entity.LogicalName, "GetPersonalViews");

                    foreach (Entity personalView in viewCollection.Entities)
                    {
                        // we want a list without duplicates (shared views or automatically shared to SYSTEM and INTEGRATION users)
                        if (!dictPersonalViews.ContainsKey(personalView.Id))
                        {
                            dictPersonalViews.Add(personalView.Id, personalView);
                        }
                    }
                }
                catch (Exception ex1)
                {
                    Logger.Error(ex1, "GetPersonalViews");
                }
            }

            Logger.Warning("GetPersonalViews 6" + entity.LogicalName, "GetPersonalViews");

            // we can process the values (Entity objects) of the dictionary
            foreach (Entity personalView in dictPersonalViews.Values)
            {
                string          viewName       = personalView["name"].ToString();
                string          viewFetchXml   = personalView["fetchxml"].ToString();
                EntityReference viewOwnerIdRef = (EntityReference)personalView["ownerid"];


                CRMView view = new CRMView(personalView.Id.ToString(), viewName, siteSetting.ID, entity);
                views.Add(view);
            }
            Logger.Warning("GetPersonalViews 7" + entity.LogicalName, "GetPersonalViews");


            return(views);
        }
Exemple #6
0
        private void LoadTasks_Callback(object _item, DateTime dateTime)
        {
            object[]         args             = ((object[])_item);
            SiteSetting      siteSetting      = (SiteSetting)args[0];
            TaskListLocation taskListLocation = (TaskListLocation)args[1];
            ListView         tasksListView    = (ListView)args[2];
            List <string>    assignedTos      = (List <string>)args[3];
            List <string>    statuses         = (List <string>)args[4];
            List <string>    priorities       = (List <string>)args[5];
            Image            loadingImage     = (Image)args[6];
            Image            refreshImage     = (Image)args[7];

            List <Task> tasks = new List <Task>();

            CamlFilters customFilters = new CamlFilters();

            customFilters.IsOr = false;
            if (assignedTos.Count == 0)
            {
                customFilters.Add(new CamlFilter("AssignedTo", FieldTypes.Number, CamlFilterTypes.Equals, "[Me]"));
            }
            foreach (string filterValue in statuses)
            {
                customFilters.Add(new CamlFilter("Status", FieldTypes.Choice, CamlFilterTypes.NotEqual, filterValue));
            }
            foreach (string filterValue in priorities)
            {
                customFilters.Add(new CamlFilter("Priority", FieldTypes.Choice, CamlFilterTypes.NotEqual, filterValue));
            }

            int    itemCount;
            string listItemCollectionPositionNext = String.Empty;

            List <IItem> items = ServiceManagerFactory.GetServiceManager(siteSetting.SiteSettingType).GetListItems(siteSetting, taskListLocation.Folder, null, string.Empty, true, 0, string.Empty, customFilters, false, out listItemCollectionPositionNext, out itemCount);

            if (items.Count == 0)
            {
                Task emptyTask = new Task();
                emptyTask.Title = Languages.Translate("No items to display");
                tasks.Add(emptyTask);
            }
            foreach (IItem item in items)
            {
                Task task = new Task();
                task.SiteSettingID = siteSetting.ID;
                task.ID            = item.GetID();
                task.Title         = item.Title;
                if (item.Properties.ContainsKey("ows_Priority") == true)
                {
                    task.Priority = item.Properties["ows_Priority"];
                }
                if (item.Properties.ContainsKey("ows_Status") == true)
                {
                    task.Status = item.Properties["ows_Status"];
                }
                if (item.Properties.ContainsKey("ows_AssignedTo") == true)
                {
                    string assignedTo = item.Properties["ows_AssignedTo"];
                    if (string.IsNullOrEmpty(assignedTo) == false)
                    {
                        string[] assignedToArray = assignedTo.Split(new string[] { ";#" }, StringSplitOptions.None);
                        task.AssignedToID = int.Parse(assignedToArray[0]);
                        task.AssignedTo   = assignedToArray[1];
                    }
                }

                if (item.Properties.ContainsKey("ows_WorkflowLink") == true)
                {
                    string workflowLink = item.Properties["ows_WorkflowLink"];
                    if (string.IsNullOrEmpty(workflowLink) == false)
                    {
                        int titleStartIndex = workflowLink.IndexOf(",");
                        task.RelatedContentUrl   = workflowLink.Substring(0, titleStartIndex);
                        task.RelatedContentTitle = workflowLink.Substring(titleStartIndex + 1);
                    }
                }


                task.ListUrl = taskListLocation.Folder.GetUrl();
                tasks.Add(task);
            }

            this.TasksListView.Dispatcher.Invoke(DispatcherPriority.Input, new ThreadStart(() =>
            {
                CollectionViewSource cvs = new CollectionViewSource();
                cvs.Source = tasks;
                cvs.GroupDescriptions.Add(new PropertyGroupDescription("ListUrl"));

                this.TasksListView.ItemsSource = cvs.View;

                refreshImage.Visibility = System.Windows.Visibility.Visible;
                loadingImage.Visibility = System.Windows.Visibility.Collapsed;
            }));

            this.IsDataLoaded = true;
        }