示例#1
0
        internal static object SharepointJoinedToLong(string obj, CultureInfo cultureInfo)
        {
            string value = (string)SharepointHelpers.SecondJoinedValue(obj, cultureInfo);

            if (string.IsNullOrEmpty(value))
            {
                return(null);
            }
            return(long.Parse((string)SharepointHelpers.SecondJoinedValue(obj, cultureInfo)));
        }
示例#2
0
        internal static XmlNode GenerateQueryCAML(QueryFilter query)
        {
            XmlDocument xmlDocument = new SafeXmlDocument();
            XmlNode     xmlNode     = xmlDocument.CreateElement("Query");

            if (query != null)
            {
                xmlNode.AppendChild(xmlDocument.CreateElement("Where"));
                xmlNode.ChildNodes[0].AppendChild(SharepointHelpers.GenerateQueryCAMLHelper(query, xmlDocument, 0));
            }
            return(xmlNode);
        }
示例#3
0
        public virtual object TryGetProperty(PropertyDefinition propDef)
        {
            DocumentLibraryPropertyDefinition documentLibraryPropertyDefinition = propDef as DocumentLibraryPropertyDefinition;

            if (documentLibraryPropertyDefinition != null && documentLibraryPropertyDefinition.PropertyId == DocumentLibraryPropertyId.Id)
            {
                return(this.Id);
            }
            return(SharepointHelpers.GetValuesFromCAMLView(this.Schema, this.DataNode, this.CultureInfo, new PropertyDefinition[]
            {
                propDef
            })[0]);
        }
示例#4
0
        internal static XmlNode GetNodeForItem(SharepointSession session, SharepointDocumentLibraryItemId itemId)
        {
            XmlNode result;

            using (Lists lists = new Lists(session.Uri.ToString()))
            {
                lists.Credentials = CredentialCache.DefaultCredentials;
                XmlNode     query        = SharepointHelpers.GenerateQueryCAML(new ComparisonFilter(ComparisonOperator.Equal, SharepointDocumentLibraryItemSchema.ID, itemId.ItemId));
                XmlNode     queryOptions = SharepointHelpers.GenerateQueryOptionsXml(itemId.ParentDirectoryStructure);
                XmlNode     viewFields   = SharepointHelpers.GenerateViewFieldCAML(SharepointDocumentSchema.Instance, SharepointDocumentSchema.Instance.AllProperties.Keys);
                XmlNode     listItems    = lists.GetListItems(itemId.ListName, null, query, viewFields, "2", queryOptions);
                XmlNodeList xmlNodeList  = listItems.SelectNodes("/rs:data/z:row", SharepointHelpers.SharepointNamespaceManager);
                result = ((xmlNodeList.Count == 1) ? xmlNodeList[0] : null);
            }
            return(result);
        }
示例#5
0
        private static SharepointList ReadHelper(XmlNode node, SharepointSession session, SharepointListId spListId)
        {
            object[] valuesFromCAMLView = SharepointHelpers.GetValuesFromCAMLView(SharepointListSchema.Instance, node, null, new PropertyDefinition[]
            {
                SharepointListSchema.Name,
                SharepointListSchema.ListType,
                SharepointListSchema.PredefinedListType
            });
            ListBaseType listBaseType = (ListBaseType)valuesFromCAMLView[1];

            spListId.Cache = new KeyValuePair <string, XmlNode>?(new KeyValuePair <string, XmlNode>(session.Identity.Name, node));
            if (listBaseType == ListBaseType.DocumentLibrary)
            {
                return(new SharepointDocumentLibrary(spListId, session, node));
            }
            return(new SharepointList(spListId, session, node));
        }
示例#6
0
        internal static XmlNode GenerateQueryOptionsXml(IList <string> itemHierarchy)
        {
            string folderPath = null;

            if (itemHierarchy != null && itemHierarchy.Count > 0)
            {
                StringBuilder stringBuilder = new StringBuilder();
                for (int i = 0; i < itemHierarchy.Count; i++)
                {
                    if (stringBuilder.Length > 0)
                    {
                        stringBuilder.Append("/");
                    }
                    stringBuilder.Append(itemHierarchy[i]);
                }
                folderPath = stringBuilder.ToString();
            }
            return(SharepointHelpers.GenerateQueryOptionsXml(folderPath));
        }
示例#7
0
 internal static ITableView InternalGetView(QueryFilter query, SortBy[] sortBy, DocumentLibraryQueryOptions queryOptions, PropertyDefinition[] propsToReturn, SharepointSession session, SharepointListId listId)
 {
     EnumValidator.ThrowIfInvalid <DocumentLibraryQueryOptions>(queryOptions, "queryOptions");
     if (propsToReturn == null)
     {
         throw new ArgumentNullException("propsToReturn");
     }
     if (propsToReturn.Length == 0)
     {
         throw new ArgumentException("propsToReturn");
     }
     return(Utils.DoSharepointTask <ArrayTableView>(session.Identity, new SharepointListId(listId.ListName, listId.SiteUri, listId.CultureInfo, UriFlags.SharepointList), listId, true, Utils.MethodType.GetView, delegate
     {
         XmlNode xmlNode = null;
         using (Lists lists = new Lists(listId.SiteUri.ToString()))
         {
             lists.Credentials = CredentialCache.DefaultCredentials;
             XmlNode query2 = null;
             QueryFilter queryFilter = null;
             if (queryOptions == DocumentLibraryQueryOptions.Files)
             {
                 queryFilter = new ComparisonFilter(ComparisonOperator.Equal, SharepointDocumentLibraryItemSchema.FileSystemObjectType, 0);
             }
             else if (queryOptions == DocumentLibraryQueryOptions.Folders)
             {
                 queryFilter = new ComparisonFilter(ComparisonOperator.Equal, SharepointDocumentLibraryItemSchema.FileSystemObjectType, 1);
             }
             if (query != null && queryFilter != null)
             {
                 query = new AndFilter(new QueryFilter[]
                 {
                     queryFilter,
                     query
                 });
             }
             else if (queryFilter != null)
             {
                 query = queryFilter;
             }
             if (query != null)
             {
                 query2 = SharepointHelpers.GenerateQueryCAML(query);
             }
             XmlNode viewFields = SharepointHelpers.GenerateViewFieldCAML(SharepointDocumentSchema.Instance, SharepointDocumentSchema.Instance.AllProperties.Keys);
             if (listId.CultureInfo == null)
             {
                 SharepointList sharepointList = SharepointList.Read(session, listId);
                 listId.CultureInfo = sharepointList.GetRegionalSettings();
             }
             SharepointDocumentLibraryItemId sharepointDocumentLibraryItemId = listId as SharepointDocumentLibraryItemId;
             XmlNode queryOptions2;
             if (sharepointDocumentLibraryItemId != null)
             {
                 queryOptions2 = SharepointHelpers.GenerateQueryOptionsXml(sharepointDocumentLibraryItemId.ItemHierarchy);
             }
             else
             {
                 queryOptions2 = SharepointHelpers.GenerateQueryOptionsXml(null);
             }
             xmlNode = lists.GetListItems(listId.ListName, null, query2, viewFields, Utils.GetViewMaxRows.ToString(), queryOptions2);
         }
         List <object[]> list = new List <object[]>();
         foreach (object obj in xmlNode.SelectNodes("/rs:data/z:row", SharepointHelpers.SharepointNamespaceManager))
         {
             XmlNode xmlNode2 = (XmlNode)obj;
             object[] valuesFromCAMLView = SharepointHelpers.GetValuesFromCAMLView(SharepointDocumentSchema.Instance, xmlNode2, listId.CultureInfo, new PropertyDefinition[]
             {
                 SharepointDocumentLibraryItemSchema.FileSystemObjectType,
                 SharepointDocumentLibraryItemSchema.ID,
                 SharepointDocumentLibraryItemSchema.EncodedAbsoluteUri
             });
             int num = 0;
             int num2 = num + 1;
             int num3 = num2 + 1;
             bool flag = valuesFromCAMLView[num] is bool && (bool)valuesFromCAMLView[num];
             UriFlags uriFlags = flag ? UriFlags.SharepointFolder : UriFlags.SharepointDocument;
             Uri uri = (Uri)valuesFromCAMLView[num3];
             List <string> list2 = new List <string>();
             for (int i = listId.SiteUri.Segments.Length; i < uri.Segments.Length; i++)
             {
                 list2.Add(Uri.UnescapeDataString(uri.Segments[i]));
             }
             SharepointDocumentLibraryItemId sharepointDocumentLibraryItemId2 = new SharepointDocumentLibraryItemId((string)valuesFromCAMLView[num2], listId.ListName, listId.SiteUri, listId.CultureInfo, uriFlags, list2);
             sharepointDocumentLibraryItemId2.Cache = new KeyValuePair <string, XmlNode>?(new KeyValuePair <string, XmlNode>(session.Identity.Name, xmlNode2));
             object[] valuesFromCAMLView2 = SharepointHelpers.GetValuesFromCAMLView(SharepointDocumentSchema.Instance, xmlNode2, listId.CultureInfo, propsToReturn);
             object obj2 = null;
             for (int j = 0; j < propsToReturn.Length; j++)
             {
                 if (((DocumentLibraryPropertyDefinition)propsToReturn[j]).PropertyId == DocumentLibraryPropertyId.Id)
                 {
                     valuesFromCAMLView2[j] = sharepointDocumentLibraryItemId2;
                 }
                 else if (propsToReturn[j] == SharepointDocumentSchema.VersionControl)
                 {
                     if (obj2 == null)
                     {
                         string text = SharepointHelpers.GetValuesFromCAMLView(SharepointDocumentSchema.Instance, xmlNode2, listId.CultureInfo, new PropertyDefinition[]
                         {
                             SharepointDocumentSchema.CheckedOutUserId
                         })[0] as string;
                         object obj3 = SharepointHelpers.GetValuesFromCAMLView(SharepointDocumentSchema.Instance, xmlNode2, listId.CultureInfo, new PropertyDefinition[]
                         {
                             SharepointDocumentSchema.VersionId
                         })[0];
                         if (obj3 is int && !flag)
                         {
                             obj2 = new VersionControl(!string.IsNullOrEmpty(text), text, (int)obj3);
                         }
                         else
                         {
                             obj2 = new PropertyError(propsToReturn[j], PropertyErrorCode.NotFound);
                         }
                     }
                     valuesFromCAMLView2[j] = obj2;
                 }
             }
             list.Add(valuesFromCAMLView2);
         }
         return new ArrayTableView(null, sortBy, propsToReturn, list);
     }));
 }
 private ITableView InternalGetView(ListBaseType listBaseType, PredefinedListType predefinedListType, SortBy[] sortBy, params PropertyDefinition[] propsToReturn)
 {
     if (propsToReturn == null)
     {
         throw new ArgumentNullException("propsToReturn");
     }
     if (propsToReturn.Length == 0)
     {
         throw new ArgumentException("propsToReturn");
     }
     EnumValidator.ThrowIfInvalid <ListBaseType>(listBaseType, "listBaseType");
     EnumValidator.ThrowIfInvalid <PredefinedListType>(predefinedListType, "listBaseType");
     if (listBaseType != ListBaseType.Any && predefinedListType != PredefinedListType.Any)
     {
         throw new ArgumentException("listBaseType && predefinedListType");
     }
     return(Utils.DoSharepointTask <ArrayTableView>(this.Identity, this.Id, (SharepointSiteId)this.Id, true, Utils.MethodType.GetView, delegate
     {
         List <object[]> list = new List <object[]>();
         ArrayTableView result;
         using (Lists lists = new Lists(this.Uri.ToString()))
         {
             lists.Credentials = CredentialCache.DefaultCredentials;
             foreach (object obj in lists.GetListCollection().SelectNodes("/sp:List", SharepointHelpers.SharepointNamespaceManager))
             {
                 XmlNode xmlNode = (XmlNode)obj;
                 object[] valuesFromCAMLView = SharepointHelpers.GetValuesFromCAMLView(SharepointListSchema.Instance, xmlNode, null, new PropertyDefinition[]
                 {
                     SharepointListSchema.ID,
                     SharepointListSchema.ListType,
                     SharepointListSchema.PredefinedListType,
                     SharepointListSchema.IsHidden
                 });
                 int num = 0;
                 int num2 = num + 1;
                 int num3 = num2 + 1;
                 int num4 = num3 + 1;
                 string text = valuesFromCAMLView[num] as string;
                 if (text != null && valuesFromCAMLView[num2] is int && valuesFromCAMLView[num3] is int && valuesFromCAMLView[num4] is bool && !(bool)valuesFromCAMLView[num4])
                 {
                     ListBaseType listBaseType2 = (ListBaseType)valuesFromCAMLView[num2];
                     PredefinedListType predefinedListType2 = (PredefinedListType)valuesFromCAMLView[num3];
                     if ((listBaseType == ListBaseType.Any || listBaseType == listBaseType2) && (predefinedListType == PredefinedListType.Any || predefinedListType == predefinedListType2))
                     {
                         SharepointListId sharepointListId;
                         if (listBaseType2 == ListBaseType.DocumentLibrary)
                         {
                             sharepointListId = new SharepointListId(text, this.Uri, null, UriFlags.SharepointDocumentLibrary);
                         }
                         else
                         {
                             sharepointListId = new SharepointListId(text, this.Uri, null, UriFlags.SharepointList);
                         }
                         sharepointListId.Cache = new KeyValuePair <string, XmlNode>?(new KeyValuePair <string, XmlNode>(this.Identity.Name, xmlNode));
                         object[] valuesFromCAMLView2 = SharepointHelpers.GetValuesFromCAMLView(SharepointListSchema.Instance, xmlNode, null, propsToReturn);
                         for (int i = 0; i < propsToReturn.Length; i++)
                         {
                             DocumentLibraryPropertyDefinition documentLibraryPropertyDefinition = propsToReturn[i] as DocumentLibraryPropertyDefinition;
                             if (documentLibraryPropertyDefinition != null)
                             {
                                 if (documentLibraryPropertyDefinition.PropertyId == DocumentLibraryPropertyId.Id)
                                 {
                                     valuesFromCAMLView2[i] = sharepointListId;
                                 }
                                 else if (documentLibraryPropertyDefinition.PropertyId == DocumentLibraryPropertyId.Uri)
                                 {
                                     Uri uri = SharepointHelpers.GetValuesFromCAMLView(SharepointListSchema.Instance, xmlNode, null, new PropertyDefinition[]
                                     {
                                         SharepointListSchema.DefaultViewUri
                                     })[0] as Uri;
                                     if (uri != null)
                                     {
                                         valuesFromCAMLView2[i] = new UriBuilder(sharepointListId.SiteUri.Scheme, sharepointListId.SiteUri.Host, sharepointListId.SiteUri.Port, uri.ToString()).Uri;
                                     }
                                 }
                             }
                         }
                         list.Add(valuesFromCAMLView2);
                     }
                 }
             }
             result = new ArrayTableView(null, sortBy, propsToReturn, list);
         }
         return result;
     }));
 }
示例#9
0
 internal static object[] GetValuesFromCAMLView(Schema schema, XmlNode xmlNode, CultureInfo cultureInfo, params PropertyDefinition[] propertyDefinitions)
 {
     return(SharepointHelpers.GetValuesFromCAMLView(schema, xmlNode, cultureInfo, (IList <PropertyDefinition>)propertyDefinitions));
 }
示例#10
0
 internal static object SharepointIsFolderToBool(string obj, CultureInfo cultureInfo)
 {
     return((int)SharepointHelpers.SharepointJoinedToInt(obj, cultureInfo) != 0);
 }
示例#11
0
 internal static object SharepointJoinedToDateTime(string obj, CultureInfo cultureInfo)
 {
     return(SharepointHelpers.SharepointToDateTime((string)SharepointHelpers.SecondJoinedValue(obj, cultureInfo), cultureInfo));
 }
示例#12
0
        private static XmlNode GenerateQueryCAMLHelper(QueryFilter query, XmlDocument xmlDoc, int depth)
        {
            if (depth >= SharepointHelpers.MaxFilterHierarchyDepth)
            {
                throw new ArgumentException("filter");
            }
            XmlNode xmlNode = null;

            if (query is AndFilter)
            {
                AndFilter andFilter = (AndFilter)query;
                using (ReadOnlyCollection <QueryFilter> .Enumerator enumerator = andFilter.Filters.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        QueryFilter query2 = enumerator.Current;
                        if (xmlNode == null)
                        {
                            xmlNode = SharepointHelpers.GenerateQueryCAMLHelper(query2, xmlDoc, depth + 1);
                        }
                        else
                        {
                            XmlNode newChild = xmlNode;
                            xmlNode = xmlDoc.CreateElement("And");
                            xmlNode.AppendChild(newChild);
                            xmlNode.AppendChild(SharepointHelpers.GenerateQueryCAMLHelper(query2, xmlDoc, depth + 1));
                        }
                    }
                    return(xmlNode);
                }
            }
            if (query is OrFilter)
            {
                OrFilter orFilter = (OrFilter)query;
                using (ReadOnlyCollection <QueryFilter> .Enumerator enumerator2 = orFilter.Filters.GetEnumerator())
                {
                    while (enumerator2.MoveNext())
                    {
                        QueryFilter query3 = enumerator2.Current;
                        if (xmlNode == null)
                        {
                            xmlNode = SharepointHelpers.GenerateQueryCAMLHelper(query3, xmlDoc, depth + 1);
                        }
                        else
                        {
                            XmlNode newChild2 = xmlNode;
                            xmlNode = xmlDoc.CreateElement("Or");
                            xmlNode.AppendChild(newChild2);
                            xmlNode.AppendChild(SharepointHelpers.GenerateQueryCAMLHelper(query3, xmlDoc, depth + 1));
                        }
                    }
                    return(xmlNode);
                }
            }
            if (!(query is ComparisonFilter))
            {
                throw new NotSupportedException(Strings.ExFilterNotSupported(query.GetType()));
            }
            ComparisonFilter comparisonFilter = (ComparisonFilter)query;

            switch (comparisonFilter.ComparisonOperator)
            {
            case ComparisonOperator.Equal:
                xmlNode = xmlDoc.CreateElement("Eq");
                break;

            case ComparisonOperator.NotEqual:
                xmlNode = xmlDoc.CreateElement("Neq");
                break;

            case ComparisonOperator.LessThan:
                xmlNode = xmlDoc.CreateElement("Lt");
                break;

            case ComparisonOperator.LessThanOrEqual:
                xmlNode = xmlDoc.CreateElement("Leq");
                break;

            case ComparisonOperator.GreaterThan:
                xmlNode = xmlDoc.CreateElement("Gt");
                break;

            case ComparisonOperator.GreaterThanOrEqual:
                xmlNode = xmlDoc.CreateElement("Geq");
                break;

            default:
                throw new InvalidOperationException("Invalid comparison operator");
            }
            SharepointPropertyDefinition sharepointPropertyDefinition = (SharepointPropertyDefinition)comparisonFilter.Property;

            xmlNode.InnerXml = string.Format("<FieldRef Name=\"{0}\" /><Value Type=\"{1}\">{2}</Value>", sharepointPropertyDefinition.SharepointName, sharepointPropertyDefinition.FieldTypeAsString, sharepointPropertyDefinition.ToSharepoint(comparisonFilter.PropertyValue, null));
            return(xmlNode);
        }