public void loadData(uint startRow, uint maxRows) {
     var repository = new IssueTrackingRepository(view.ViewFields.Select(f => f.Id));
     var queryBuilder = new CAMLQueryBuilder();
     if (!string.IsNullOrEmpty(view.Status)) {
         queryBuilder.AddEqual(SPBuiltInFieldName.IssueStatus, view.Status);
     }
     var queryString = queryBuilder.Build();
     var table = repository.Get(queryString, startRow, maxRows);
     table.Columns.Add("Title");
     table.Columns.Add("Identity");
     table.Columns.Add("NavigateUrl");
     foreach (DataRow row in table.Rows) {
         using (SPWeb web = Web.Site.OpenWeb(new Guid(row["WebId"].ToString()))) {
             row["Title"] = row[view.ViewFields.FirstOrDefault().Id.ToString()];
             row["Identity"] = new JavaScriptSerializer().Serialize(
                 new RelatedItem() {
                     WebId = row["WebId"].ToString(),
                     ListId = row["ListId"].ToString(),
                     ItemId = int.Parse(row["ID"].ToString())
                 });
             var url = string.Format("{0}listform.aspx?ListId={1}&PageType=6&ID={2}&Source={3}",
                 SPUtility.GetWebLayoutsFolder(web), row["ListId"], row["ID"], HttpUtility.UrlDecode(HttpContext.Current.Request.Url.PathAndQuery));
             row["NavigateUrl"] = url;
         }
     }
     view.Items = table;
 }
Esempio n. 2
0
        private static SPView CreatePromotionsOnlyView(SPWeb currentWeb, SPList pagesList)
        {
            //Create View that only shows PromotionPage content type instances
            CAMLQueryBuilder queryBuilder = new CAMLQueryBuilder();

            queryBuilder.FilterByContentType(PromotionPageContentType);
            string queryBuilderBuildQuery = queryBuilder.Build().Query;

            //Add fields to list

            SPField productSkuField    = currentWeb.Site.RootWeb.Fields[new Guid(ProductSkuFieldId)];
            SPField promotionNameField = currentWeb.Site.RootWeb.Fields[new Guid(PromotionNameFieldId)];

            if (!pagesList.Fields.ContainsField(productSkuField.InternalName))
            {
                pagesList.Fields.Add(productSkuField);
            }
            if (!pagesList.Fields.ContainsField(promotionNameField.InternalName))
            {
                pagesList.Fields.Add(promotionNameField);
            }

            //Add fields to view using FieldId GUIDs
            StringCollection viewFields = new StringCollection();

            viewFields.Add(currentWeb.Site.RootWeb.Fields[new Guid(LinkFilenameFieldId)].InternalName); //LinkFilename)
            viewFields.Add(productSkuField.InternalName);                                               //ProductSkuField
            viewFields.Add(promotionNameField.InternalName);                                            //PromotionNameField

            SPView promotionsOnlyView = pagesList.Views.Add(PromotionOnlyView, viewFields, queryBuilderBuildQuery, 100, true, false);

            promotionsOnlyView.Update();

            return(promotionsOnlyView);
        }
        public void CanAddCustomEqualFilter()
        {
            CAMLQueryBuilder target = new CAMLQueryBuilder();

            target.AddEqual("Name", "Test", "CustomType");

            SPQuery query = target.Build();

            Assert.AreEqual("<Where><Eq><FieldRef Name='Name'/><Value Type='CustomType'>Test</Value></Eq></Where>", query.Query);
        }
        public void CanConstructSimpleCAMLQuery()
        {
            CAMLQueryBuilder target = new CAMLQueryBuilder();

            target.AddEqual("Name", "Value");

            SPQuery query = target.Build();

            Assert.AreEqual("<Where><Eq><FieldRef Name='Name'/><Value Type='Text'>Value</Value></Eq></Where>", query.Query);
        }
        public void CanFilterOnContentType()
        {
            CAMLQueryBuilder target = new CAMLQueryBuilder();

            target.FilterByContentType("ContentTypeName");

            SPQuery query = target.Build();

            Assert.AreEqual("<Where><Eq><FieldRef Name='ContentType'/><Value Type='Text'>ContentTypeName</Value></Eq></Where>", query.Query);
        }
        public void CanConstructNotEqualsCAMLQueryUsingInt()
        {
            CAMLQueryBuilder target = new CAMLQueryBuilder();

            target.AddNotEqual("Name", 123);

            SPQuery query = target.Build();

            Assert.AreEqual("<Where><Neq><FieldRef Name='Name'/><Value Type='Integer'>123</Value></Neq></Where>", query.Query);
        }
        public void CanFilterUsingIdWithInt()
        {
            CAMLQueryBuilder target       = new CAMLQueryBuilder();
            Guid             expectedGuid = Guid.NewGuid();

            target.AddEqual(expectedGuid, 123);

            SPQuery query = target.Build();

            Assert.AreEqual(string.Format("<Where><Eq><FieldRef ID='{0}'/><Value Type='Integer'>123</Value></Eq></Where>", expectedGuid.ToString()), query.Query);
        }
        public void CanConstructNotEqualsCAMLQueryUsingDateTime()
        {
            CAMLQueryBuilder target           = new CAMLQueryBuilder();
            string           expectedDateTime = SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.MinValue);

            target.AddNotEqual("Name", DateTime.MinValue);

            SPQuery query = target.Build();

            Assert.AreEqual(string.Format("<Where><Neq><FieldRef Name='Name'/><Value Type='DateTime'>{0}</Value></Neq></Where>", expectedDateTime), query.Query);
        }
        public void CanConstructQueryWithMultipleFields()
        {
            CAMLQueryBuilder target = new CAMLQueryBuilder();

            target.AddEqual("Name", "Value");
            target.AddEqual("Name2", "Value2");

            SPQuery query = target.Build();

            Assert.AreEqual("<Where><And><Eq><FieldRef Name='Name'/><Value Type='Text'>Value</Value></Eq><Eq><FieldRef Name='Name2'/><Value Type='Text'>Value2</Value></Eq></And></Where>", query.Query);
        }
        public void CanAddCustomFilter()
        {
            CAMLQueryBuilder target = new CAMLQueryBuilder();

            target.AddFilter(new CAMLFilter {
                FilterExpression = "foo"
            });

            SPQuery query = target.Build();

            Assert.AreEqual("<Where>foo</Where>", query.Query);
        }
        public void CanFilterUsingIdWithDateTime()
        {
            CAMLQueryBuilder target           = new CAMLQueryBuilder();
            Guid             expectedGuid     = Guid.NewGuid();
            string           expectedDateTime = SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.MinValue);

            target.AddEqual(expectedGuid, DateTime.MinValue);

            SPQuery query = target.Build();

            Assert.AreEqual(string.Format("<Where><Eq><FieldRef ID='{0}'/><Value Type='DateTime'>{1}</Value></Eq></Where>", expectedGuid.ToString(), expectedDateTime), query.Query);
        }
        public void CanUseIntegersAndDateTimes()
        {
            CAMLQueryBuilder target = new CAMLQueryBuilder();

            target.AddEqual("Name", 1);
            target.AddEqual("Name2", new DateTime(2000, 11, 22));

            SPQuery query = target.Build();

            string expectedDateTime = SPUtility.CreateISO8601DateTimeFromSystemDateTime(new DateTime(2000, 11, 22));
            string expectedQuery    =
                string.Format(
                    "<Where><And><Eq><FieldRef Name='Name'/><Value Type='Integer'>1</Value></Eq>" +
                    "<Eq><FieldRef Name='Name2'/><Value Type='DateTime'>{0}</Value></Eq></And></Where>",
                    expectedDateTime);

            Assert.AreEqual(expectedQuery, query.Query);
        }
Esempio n. 13
0
        public IList <PartnerPromotionEntity> GetAllMyPromos()
        {
            List <PartnerPromotionEntity> partnerPromotions = new List <PartnerPromotionEntity>();

            CAMLQueryBuilder camlQueryBuilder = new CAMLQueryBuilder();

            camlQueryBuilder.FilterByContentType(ContentTypeName);
            SPQuery spQuery = camlQueryBuilder.Build();
            SPListItemCollection collection = promotionsList.GetItems(spQuery);

            foreach (SPListItem item in collection)
            {
                PartnerPromotionEntity partnerPromotion = ListItemFieldMapper.CreateEntity(item);
                partnerPromotion.PromotionUrl = string.Format(CultureInfo.CurrentCulture, "{0}/{1}/{2}",
                                                              promotionsWebUrl, ListName, item["LinkFilename"]);
                partnerPromotions.Add(partnerPromotion);
            }

            return(partnerPromotions);
        }
Esempio n. 14
0
        public PartnerPromotionEntity GetBySku(string sku)
        {
            CAMLQueryBuilder camlQueryBuilder = new CAMLQueryBuilder();

            camlQueryBuilder.AddEqual("ProductSkuField", sku);

            SPListItemCollection collection = promotionsList.GetItems(camlQueryBuilder.Build());

            if (collection != null && collection.Count > 0)
            {
                SPListItem             firstListItem    = collection[0];
                PartnerPromotionEntity partnerPromotion = ListItemFieldMapper.CreateEntity(firstListItem);
                partnerPromotion.PromotionUrl = string.Format(CultureInfo.CurrentCulture, "{0}/{1}/{2}",
                                                              promotionsWebUrl, ListName, firstListItem["LinkFilename"]);

                return(partnerPromotion);
            }

            return(null);
        }
        private static SPListItem ExecutePartnertSiteDirectoryQuery(SPList siteCollectiongMappingList, string partnerId)
        {
            SPListItem       itemFound        = null;
            CAMLQueryBuilder camlQueryBuilder = new CAMLQueryBuilder();

            camlQueryBuilder.AddEqual(FieldIds.PartnerFieldId, partnerId);

            SPQuery query  = camlQueryBuilder.Build();
            ILogger logger = SharePointServiceLocator.Current.GetInstance <ILogger>();

            logger.TraceToDeveloper(string.Format(CultureInfo.CurrentCulture,
                                                  "PartnerSiteDirectory FindPartnerMappingForCurrentPartner CAML: {0}",
                                                  query.Query));

            SPListItemCollection items = siteCollectiongMappingList.GetItems(query);

            if (items.Count > 0)
            {
                itemFound = items[0];
            }

            return(itemFound);
        }
        public IEnumerable <PartnerSiteDirectoryEntry> GetAllPartnerSites()
        {
            List <PartnerSiteDirectoryEntry> partnerSiteDirectoryEntries = new List <PartnerSiteDirectoryEntry>();

            // Query for items in the Site Directory where the Partner field contains some value
            CAMLQueryBuilder camlQueryBuilder = new CAMLQueryBuilder();

            camlQueryBuilder.AddNotEqual("PartnerDirectoryPartnerField", string.Empty);
            SPQuery query  = camlQueryBuilder.Build();
            ILogger logger = SharePointServiceLocator.Current.GetInstance <ILogger>();

            logger.TraceToDeveloper(string.Format(CultureInfo.CurrentCulture,
                                                  "PartnerSiteDirectory FindPartnerMappingForCurrentPartner CAML: {0}",
                                                  query.Query));

            using (SPSite site = new SPSite(partnerDirectoryUrl))
            {
                using (SPWeb siteDirectory = site.OpenWeb())
                {
                    SPList siteCollectionMappingList = siteDirectory.Lists["Sites"];
                    SPListItemCollection items       = siteCollectionMappingList.GetItems(query);

                    foreach (SPListItem item in items)
                    {
                        PartnerSiteDirectoryEntry partnerSiteDirectoryEntry = new PartnerSiteDirectoryEntry();
                        partnerSiteDirectoryEntry.PartnerId = (string)item["PartnerDirectoryPartnerField"];
                        string url = item["URL"].ToString();
                        partnerSiteDirectoryEntry.SiteCollectionUrl = url.Split(",".ToCharArray())[0];
                        partnerSiteDirectoryEntry.Title             = (string)item["Title"];

                        partnerSiteDirectoryEntries.Add(partnerSiteDirectoryEntry);
                    }
                }
            }
            return(partnerSiteDirectoryEntries);
        }
        /// <summary>
        /// Retrieve the configuration for the specified business event.
        /// </summary>
        /// <param name="businessEvent">The business event to get the configuration for</param>
        /// <returns>The business event's configuration. </returns>
        public BusinessEventTypeConfiguration GetBusinessEventTypeConfiguration(string businessEvent)
        {
            IHierarchicalConfig hierarchicalConfig = SharePointServiceLocator.Current.GetInstance <IHierarchicalConfig>();
            string adminWebUrl = hierarchicalConfig.GetByKey <string>(Constants.SubSiteCreationConfigSiteKey, ConfigLevel.CurrentSPFarm);

            if (string.IsNullOrEmpty(adminWebUrl))
            {
                throw new SubSiteCreationException(string.Format(CultureInfo.CurrentCulture, ConfigSiteNotFoundMessage, Constants.SubSiteCreationConfigSiteKey));
            }

            using (SPSite site = new SPSite(adminWebUrl))
            {
                using (SPWeb adminWeb = site.OpenWeb())
                {
                    SPList           businessEventSiteTemplateList = adminWeb.Lists[Constants.BusinessEventTypeConfigListName];
                    CAMLQueryBuilder camlQueryBuilder = new CAMLQueryBuilder();
                    camlQueryBuilder.AddEqual(FieldIds.BusinessEventFieldId, businessEvent);

                    SPListItemCollection items = businessEventSiteTemplateList.GetItems(camlQueryBuilder.Build());

                    if (items.Count > 0)
                    {
                        return(ListItemFieldMapper.CreateEntity(items[0]));
                    }
                    else
                    {
                        throw new SubSiteCreationException(string.Format(CultureInfo.CurrentCulture, ConfigDataNotFoundMessage, businessEvent));
                    }
                }
            }
        }
 public string BuildQueryString() {
     var queryBuilder = new CAMLQueryBuilder();
     switch (view.QueryScope) {
         case "ByBlaming":
             queryBuilder = queryBuilder
                 .AddCurrentUser(SPBuiltInFieldName.AssignedTo)
                 .AddBeginsWith(SPBuiltInFieldName.ContentTypeId, view.ContentTypeBeginsWithId);
             break;
         case "CanBlaiming":
             queryBuilder = queryBuilder
                 .AddCurrentUser(SPBuiltInFieldName.Author)
                 .AddNotEqual("_x9690__x60a3__x72b6__x6001_", "保存")
                 .AddNotEqual("_x9690__x60a3__x72b6__x6001_", "关闭")
                 .AddEqual("_x662f__x5426__x8ffd__x8d23_", false)
                 .AddBeginsWith(SPBuiltInFieldName.ContentTypeId, view.ContentTypeBeginsWithId);
             break;
         case "HasBlaming":
             queryBuilder = queryBuilder
                 .AddCurrentUser(SPBuiltInFieldName.Author)
                 .AddNotEqual("_x9690__x60a3__x72b6__x6001_", "保存")
                 .AddNotEqual("_x9690__x60a3__x72b6__x6001_", "关闭")
                 .AddEqual("_x662f__x5426__x8ffd__x8d23_", true)
                 .AddBeginsWith(SPBuiltInFieldName.ContentTypeId, view.ContentTypeBeginsWithId);
             break;
         case "ByForfeit":
             queryBuilder = queryBuilder
                 .AddCurrentUser(SPBuiltInFieldName.AssignedTo)
                 .AddBeginsWith(SPBuiltInFieldName.ContentTypeId, view.ContentTypeBeginsWithId);
             break;
         case "CanForfeit":
             queryBuilder = queryBuilder
                 .AddCurrentUser(SPBuiltInFieldName.Author)
                 .AddNotEqual("_x9690__x60a3__x72b6__x6001_", "保存")
                 .AddNotEqual("_x9690__x60a3__x72b6__x6001_", "关闭")
                 .AddEqual("_x662f__x5426__x7f5a__x6b3e_", false)
                 .AddBeginsWith(SPBuiltInFieldName.ContentTypeId, view.ContentTypeBeginsWithId);
             break;
         case "HasForfeit":
             queryBuilder = queryBuilder
                 .AddCurrentUser(SPBuiltInFieldName.Author)
                 .AddNotEqual("_x9690__x60a3__x72b6__x6001_", "保存")
                 .AddNotEqual("_x9690__x60a3__x72b6__x6001_", "关闭")
                 .AddEqual("_x662f__x5426__x7f5a__x6b3e_", true)
                 .AddBeginsWith(SPBuiltInFieldName.ContentTypeId, view.ContentTypeBeginsWithId);
             break;
         case "CanClosed":
             queryBuilder = queryBuilder
                 .AddCurrentUser(SPBuiltInFieldName.Author)
                 .AddEqual("_x9690__x60a3__x72b6__x6001_", "销号")
                 .AddBeginsWith(SPBuiltInFieldName.ContentTypeId, view.ContentTypeBeginsWithId);
             break;
         default:
             break;
     }
     return queryBuilder.Build();
 }