Example #1
0
 public void ChangeDatabaseTest()
 {
     string server = string.Empty; // TODO: Initialize to an appropriate value
     SpConnection target = new SpConnection(server); // TODO: Initialize to an appropriate value
     string databaseName = string.Empty; // TODO: Initialize to an appropriate value
     target.ChangeDatabase(databaseName);
     Assert.Inconclusive("A method that does not return a value cannot be verified.");
 }
Example #2
0
 public void BeginTransactionTest1()
 {
     string server = string.Empty; // TODO: Initialize to an appropriate value
     SpConnection target = new SpConnection(server); // TODO: Initialize to an appropriate value
     IDbTransaction expected = null; // TODO: Initialize to an appropriate value
     IDbTransaction actual;
     actual = target.BeginTransaction();
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
Example #3
0
 public SpTransaction(SpConnection connection)
 {
     _Connection = connection;
 }
Example #4
0
 public SpTransaction(SpConnection connection)
 {
     _Connection = connection;
 }
Example #5
0
 public void SpConnectionConstructorTest()
 {
     string server = string.Empty; // TODO: Initialize to an appropriate value
     SpConnection target = new SpConnection(server);
     Assert.Inconclusive("TODO: Implement code to verify target");
 }
Example #6
0
 public void StateTest()
 {
     string server = string.Empty; // TODO: Initialize to an appropriate value
     SpConnection target = new SpConnection(server); // TODO: Initialize to an appropriate value
     ConnectionState actual;
     actual = target.State;
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
Example #7
0
 public void CreateCommandTest()
 {
     string server = string.Empty; // TODO: Initialize to an appropriate value
     SpConnection target = new SpConnection(server); // TODO: Initialize to an appropriate value
     IDbCommand expected = null; // TODO: Initialize to an appropriate value
     IDbCommand actual;
     actual = target.CreateCommand();
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
Example #8
0
 public void OpenTest()
 {
     string server = string.Empty; // TODO: Initialize to an appropriate value
     SpConnection target = new SpConnection(server); // TODO: Initialize to an appropriate value
     target.Open();
     Assert.Inconclusive("A method that does not return a value cannot be verified.");
 }
Example #9
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;
        }
Example #10
0
 public void ConnectionStringTest()
 {
     string server = string.Empty; // TODO: Initialize to an appropriate value
     SpConnection target = new SpConnection(server); // TODO: Initialize to an appropriate value
     string expected = string.Empty; // TODO: Initialize to an appropriate value
     string actual;
     target.ConnectionString = expected;
     actual = target.ConnectionString;
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
Example #11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inserts"></param>
        /// <param name="updates"></param>
        /// <param name="deletes"></param>
        /// <param name="connection"></param>
        /// #UPLOAD 3
        public void Update(DataTable changes, SpConnection connection, out Collection<SyncConflict> errors)
        {
            errors = new Collection<SyncConflict>();

            if (changes == null)
                throw new ArgumentNullException("changes");

            if (connection == null)
                throw new ArgumentNullException("connection");

            int _batchSize = 25;
            int segmentsCount = (int)Math.Round( Math.Ceiling((double)changes.Rows.Count/ _batchSize),0);

            if (IgnoreColumnsOnUpdate != null)
            {
                // case to be handled
                // cannot remove Sharepoint ID.
                // cannot remove Primary Key of DataTable?

                foreach (string ignoredColumn in IgnoreColumnsOnUpdate)
                {
                    string clientColumn = GetClientColumnFromServerColumn(ignoredColumn);
                    if (clientColumn != null &&
                        changes.Columns.Contains(clientColumn))
                    {
                        changes.Columns.Remove(clientColumn);
                    }
                }
            }

            DataTable changesTotal = changes.Copy();

            for (int i = 0; i < segmentsCount; i++)
            {
                changes.Rows.Clear();

                CopyRows(changesTotal, changes, i * _batchSize, _batchSize);

                //SEND SEGMENT
                UpdateBatch batch = new UpdateBatch();

                string clientIdColumn = GetClientColumnFromServerColumn("ID");

                if (!changes.Columns.Contains(clientIdColumn))
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Messages.ColumnIDNotContained, clientIdColumn));

                IDictionary<int, DataRow> IdMapping = new Dictionary<int, DataRow>();

                foreach (DataRow row in changes.Rows)
                {
                    UpdateItem u = batch.CreateNewItem();

                    switch (row.RowState)
                    {
                        case DataRowState.Added:
                            u.Command = UpdateCommands.Insert;
                            break;
                        case DataRowState.Deleted:
                            u.Command = UpdateCommands.Delete;
                            break;
                        case DataRowState.Modified:
                            u.Command = UpdateCommands.Update;
                            break;
                        case DataRowState.Unchanged:
                            continue;
                    }

                    if (u.Command == UpdateCommands.Delete)
                        row.RejectChanges();

                    if (u.Command != UpdateCommands.Insert)
                    {
                        if (!(row[clientIdColumn] is DBNull))
                        {
                            u.ListItemID = (int)row[clientIdColumn];
                        }
                        else
                        {
                            continue;
                        }
                    }

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

                        MapDataRowToListItem(row, item, out e);
                        u.ChangedItemData = item;
                        if (e != null && SyncTracer.IsErrorEnabled())
                            SyncTracer.Error(e.ToString());
                    }

                    batch.Add(u);
                    IdMapping[u.ID] = row;

                    if (u.Command == UpdateCommands.Delete)
                        row.Delete();
                }

                if (batch.Count != 0)
                {
                    //try
                    //{
                        UpdateResults results = connection.UpdateListItems(this.ListName, batch);
                        // FIX: errors must be handled appropriately
                        foreach (UpdateResult r in results)
                        {
                            if (!r.IsSuccess())
                            {
                                if (!IdMapping.ContainsKey(r.UpdateItemID))
                                    throw new InvalidOperationException(
                                        String.Format(CultureInfo.CurrentCulture, Messages.NoIDMapping, r.UpdateItemID));

                                DataRow clientRow = IdMapping[r.UpdateItemID];
                                errors.Add(CreateSyncError(r, clientRow));
                            }
                        }
                    //}
                    //catch (Exception ex)
                    //{
                    ////usually connection error
                    //    foreach (UpdateItem item in batch)
                    //    {
                    //        if (!IdMapping.ContainsKey(item.ID))
                    //            throw new InvalidOperationException(
                    //                String.Format(CultureInfo.CurrentCulture, Messages.NoIDMapping, r.UpdateItemID));

                    //        DataRow clientRow = IdMapping[item.ID];
                    //        errors.Add(CreateSyncError(new UpdateResult(, clientRow));
                    //    }
                    //}
                }
                //END SEND SEGMENT
            }

            if (errors.Count == 0)
                errors = null;
        }
Example #12
0
        /// #DOWNLOAD
        public SpSyncAnchor SelectIncremental(SpSyncAnchor anchor, int rowLimit, SpConnection connection,
            DataTable changeTable)
        {
            //#DOWNLOAD in batches - step 3

            if (anchor == null)
                throw new ArgumentNullException("anchor");
            if (connection == null)
                throw new ArgumentNullException("connection");

            QueryOptions queryOptions = new QueryOptions()
            {
                PagingToken = anchor.PagingToken,
                DateInUtc = false
            };

            IEnumerable<string> viewFields = GetViewFields();

            ChangeBatch changes = connection.GetListItemChangesSinceToken(
                this.ListName,
                this.ViewName,
                FilterClause,
                viewFields,
                IncludeProperties,
                rowLimit,
                queryOptions,
                anchor.NextChangesToken);

            foreach (ListItem item in changes.ChangedItems)
            {
                DataRow row = changeTable.NewRow();
                Exception e;
                MapListItemToDataRow(item, row, out e);
                if (e != null)
                {
                    if (SyncTracer.IsErrorEnabled())
                        SyncTracer.Error(e.ToString());
                }
                changeTable.Rows.Add(row);
                row.AcceptChanges();
                row.SetModified();
            }

            foreach (ChangeItem item in changes.ChangeLog)
            {
                string clientColumnName = GetClientColumnFromServerColumn("ID");
                if (ChangeCommands.IsDelete(item.Command))
                {
                    DataRow row = changeTable.NewRow();
                    // FIX: Probably the ID is not mapped at all to the client table
                    row[clientColumnName] = item.ListItemID;
                    changeTable.Rows.Add(row);
                    row.AcceptChanges();
                    row.Delete();
                }
            }

            return CalculateNextAnchor(anchor, changes);
        }
Example #13
0
        /// <summary>
        ///  Fills the tables insertTbl, updateTbl, deleteTbl with the changes fetch by the sharepoint server
        ///  since a change token 
        /// </summary>
        /// <param name="anchor">the anchor to specify the change token</param>
        /// <param name="rowLimit">the maximum number of rows to fetch </param>
        /// <param name="connection">the connection to the sharepoint server</param>
        /// <param name="insertTbl">the DataTable to append the rows that have been inserted</param>
        /// <param name="updateTbl">the DataTable to append the rows that have been updated</param>
        /// <param name="deleteTbl">the DataTable to append the rows that have been deleted</param>
        /// <remarks>
        /// Because of the response of the sharepoint changelog we cannot identify the updates from the inserts.
        /// So, no record will be added to the updateTbl.
        /// </remarks>
        /// <returns>the new SpSyncAnchor object to be used in subsequent calls</returns>
        /// #DOWNLOAD
        public SpSyncAnchor SelectIncremental(SpSyncAnchor anchor, int rowLimit, SpConnection connection,
            DataTable insertTbl, DataTable updateTbl, DataTable deleteTbl)
        {
            if (anchor == null)
                throw new ArgumentNullException("anchor");
            if (connection == null)
                throw new ArgumentNullException("connection");

            QueryOptions queryOptions = new QueryOptions()
            {
                PagingToken = anchor.PagingToken,
                DateInUtc = false
            };

            IEnumerable<string> viewFields = GetViewFields();

            ChangeBatch changes = connection.GetListItemChangesSinceToken(
                this.ListName,
                this.ViewName,
                FilterClause,
                viewFields,
                IncludeProperties,
                rowLimit,
                queryOptions,
                anchor.NextChangesToken);

            if (insertTbl != null)
            {
                foreach (ListItem item in changes.ChangedItems)
                {
                    DataRow row = insertTbl.NewRow();
                    Exception e;
                    MapListItemToDataRow(item, row, out e);
                    if (e != null)
                    {
                        if (SyncTracer.IsErrorEnabled())
                            SyncTracer.Error(e.ToString());
                    }
                    insertTbl.Rows.Add(row);
                }
            }

            // FIX: Cannot identify the updates from the inserts.

            if (deleteTbl != null)
            {
                foreach (ChangeItem item in changes.ChangeLog)
                {
                    if (ChangeCommands.IsDelete(item.Command))
                    {
                        DataRow row = deleteTbl.NewRow();
                        // FIX: Probably the ID is not mapped at all to the client table
                        row[deleteTbl.PrimaryKey[0]] = item.ListItemID;
                        deleteTbl.Rows.Add(row);
                    }
                }
            }
            insertTbl.AcceptChanges(); // COMMITCHANGES
            updateTbl.AcceptChanges();
            deleteTbl.AcceptChanges();
            return CalculateNextAnchor(anchor, changes);
        }
Example #14
0
        /// #DOWNLOAD (not in batches)
        public SpSyncAnchor SelectAll(SpSyncAnchor anchor, int rowLimit, DataTable dataTable, SpConnection connection)
        {
            if (anchor == null)
                throw new ArgumentNullException("anchor");

            if (connection == null)
                throw new ArgumentNullException("connection");

            if (dataTable == null)
                throw new ArgumentNullException("dataTable");

            QueryOptions queryOptions = new QueryOptions()
            {
                PagingToken = anchor.PagingToken,
                DateInUtc = false
            };

            IEnumerable<string> viewFields = GetViewFields();

            ListItemCollection listItems = connection.GetListItems(
                this.ListName,
                this.ViewName,
                this.FilterClause,
                viewFields,
                IncludeProperties,
                rowLimit,
                queryOptions);

            if (dataTable != null)
            {
                foreach (ListItem item in listItems)
                {
                    DataRow row = dataTable.NewRow();
                    Exception e;
                    MapListItemToDataRow(item, row, out e);
                    if (e != null)
                    {
                        if (SyncTracer.IsErrorEnabled())
                            SyncTracer.Error(e.ToString());
                    }
                    dataTable.Rows.Add(row);
                }
            }
            dataTable.AcceptChanges();
            return CalculateNextAnchor(anchor, listItems.NextPage);
        }
Example #15
0
        /// <summary>
        /// Populates the schema information for the table that is specified in TableName.
        /// </summary>
        /// <param name="table">the table to populate</param>
        /// <param name="connection">the connection object to sharepoint</param>
        /// <returns>a datatable object that contains the schema information</returns>
        public DataTable FillSchema(DataTable table, SpConnection connection)
        {
            if (connection == null)
                throw new ArgumentNullException("connection");

            if (table == null)
            {
                table = new DataTable();
                table.Locale = CultureInfo.InvariantCulture;
            }

            FillSchemaFromSharepoint(table, connection);

            if (IncludeProperties && DataColumns.Count > 0)
            {
                foreach (string dataColumn in DataColumns)
                {
                    string fieldName = GetServerColumnFromClientColumn(dataColumn);
                    if (IsMetaInfoProperty(fieldName))
                    {
                        DataColumn column = new DataColumn(dataColumn, typeof(String));
                        SetDataColumnExtendedProperty(column, "DataTypeName", "nvarchar");
                        SetDataColumnExtendedProperty(column, "ColumnLength", "50");

                        if (column.ColumnName == this.RowGuidColumn)
                        {
                            column.DataType = typeof(Guid);
                            SetDataColumnExtendedProperty(column, "RowGuidCol", true);
                            SetDataColumnExtendedProperty(column, "DataTypeName", "uniqueidentifier");
                        }
                        table.Columns.Add(column);
                    }
                }
            }

            MapFromServerToClient(table);

            return table;
        }