示例#1
0
文件: Caml.cs 项目: acharal/spsync
 public static List GetCamlList(this XElement xmlNode)
 {
     List list = new List();
     list.Name = xmlNode.Attribute("Title").Value;
     list.ID   = new Guid(xmlNode.Attribute("ID").Value);
     list.Description = xmlNode.AttributeValueOrDefault("Description");
     list.InternalName = xmlNode.Attribute("Name").Value;
     list.Version = Int32.Parse(xmlNode.Attribute("Version").Value);
     list.IsHidden = xmlNode.AttributeBoolOrFalse("Hidden");
     list.IsOrdered = xmlNode.AttributeBoolOrFalse("Ordered");
     return list;
 }
示例#2
0
        /*
        /// <summary>
        /// Adds to update batch the update items for each row in the table
        /// </summary>
        /// <param name="batch">the batch to append update items</param>
        /// <param name="table">the table to enumerate</param>
        /// <param name="command">the command to tag each update item</param>
        private void AddUpdateItems(UpdateBatch batch, DataTable table, string command)
        {
            if (batch == null)
                throw new ArgumentNullException("batch");
            if (table == null)
                throw new ArgumentNullException("table");

            if (command != UpdateCommands.Insert
                || command != UpdateCommands.Delete
                || command != UpdateCommands.Update)
                throw new ArgumentOutOfRangeException("command", "Invalid command");

            string clientIdColumn = GetClientColumnFromServerColumn("ID");

            if (command != UpdateCommands.Insert)
            {
                if (!table.Columns.Contains(clientIdColumn))
                    throw new InvalidOperationException("Column ID " + clientIdColumn + " is not contained to table");
            }

            foreach (DataRow row in table.Rows)
            {
                UpdateItem u = batch.CreateNewItem();
                u.Command = command;
                if (u.Command != UpdateCommands.Insert)
                {
                    u.ListItemID = (int)row[clientIdColumn];
                }

                if (u.Command != UpdateCommands.Delete)
                {
                    ListItem item = new ListItem();
                    Exception e;
                    MapDataRowToListItem(row, item, out e);

                    if (e != null && SyncTracer.IsErrorEnabled())
                        SyncTracer.Error(e.ToString());
                }

                batch.Add(u);
            }
        }
        */
        private bool ContainsFieldRefWithName(List<FieldRef> fieldRefs, string Name)
        {
            foreach (FieldRef f in fieldRefs)
                if (f.Name == Name)
                    return true;

            return false;
        }
示例#3
0
        private IEnumerable<string> GetViewFields()
        {
            List<string> viewFields = new List<string>();
            bool includeMetaInfo = IncludeProperties;

            foreach (string columnName in this.DataColumns)
            {
                if (columnName != null)
                {
                    if (IsMetaInfoProperty(columnName))
                    {
                        includeMetaInfo = true;
                    }
                    viewFields.Add(columnName);
                }
            }

            if (includeMetaInfo)
            {
                viewFields.Add("MetaInfo");
            }

            return viewFields;
        }
示例#4
0
        /// <summary>
        /// Fills the schema of the table consulting the schema of the sharepoint list.
        /// </summary>
        /// <param name="table">the DataTable object to change</param>
        /// <param name="connection">an open Sharepoint connection</param>
        protected void FillSchemaFromSharepoint(DataTable table, SpConnection connection)
        {
            if (table == null)
                throw new ArgumentNullException("table");

            ViewDef viewDef = null;
            ListDef listDef = null;

            if (this.ViewName != null)
            {
                viewDef = connection.GetViewSchema(this.ListName, this.ViewName);
                listDef = viewDef.ListDef;
            }
            else
            {
                listDef = connection.GetListSchema(this.ListName);
            }

            IList<DataColumn> primaryColumns = new List<DataColumn>();

            foreach (Field field in listDef.Fields)
            {
                DataColumn column;

                if (viewDef != null &&
                    viewDef.ViewFields.Count > 0 &&
                    !ContainsFieldRefWithName(viewDef.ViewFields, field.Name))
                    continue;

                if (!table.Columns.Contains(field.Name))
                {
                    column = new DataColumn();
                    table.Columns.Add(column);
                }
                else
                {
                    column = table.Columns[field.Name];
                }

                MapFromFieldToColumn(column, field);

                // sharepoint returns as primary key the ID
                // which is relevant to sharepoint list.
                if (field.IsPrimaryKey)
                    primaryColumns.Add(column);
            }

            bool primaryRemoved = false;

            if (DataColumns.Count > 0)
            {
                List<string> columnsToRemove = new List<string>();
                foreach (DataColumn tableColumn in table.Columns)
                {
                    if (!DataColumns.Contains(tableColumn.ColumnName))
                    {
                        columnsToRemove.Add(tableColumn.ColumnName);

                        if (primaryColumns.Contains(tableColumn))
                            primaryRemoved = true;
                    }
                }

                foreach (string tableColumn2 in columnsToRemove)
                    table.Columns.Remove(tableColumn2);
            }

            if (primaryColumns.Count > 0 && !primaryRemoved)
            {
                DataColumn[] primaryKey = new DataColumn[primaryColumns.Count];
                primaryColumns.CopyTo(primaryKey, 0);
                table.PrimaryKey = primaryKey;
            }

            table.TableName = this.TableName;
        }