示例#1
0
        public void TestSerializeListDef()
        {
            var listDef = new ListDef("my name")
                          .ChangeDisplayProperty("prop1")
                          .ChangeIdProperty("prop2")
                          .ChangeProperties(new[]
            {
                new AnnotationDef("ann1",
                                  AnnotationDef.AnnotationTargetSet.OfValues(AnnotationDef.AnnotationTarget.peptide,
                                                                             AnnotationDef.AnnotationTarget.precursor_result),
                                  AnnotationDef.AnnotationType.text, new[] { "one", "two" }),
            });
            var roundTrip = RoundTrip(listDef);

            Assert.AreEqual(listDef, roundTrip);
        }
示例#2
0
        public ListData GetListDef()
        {
            var listDef = new ListDef(tbxListName.Text);

            listDef = listDef.ChangeProperties(_listProperties.Select(prop => prop.AnnotationDef));
            listDef = listDef.ChangeIdProperty(comboIdProperty.SelectedItem as string);
            listDef = listDef.ChangeDisplayProperty(comboDisplayProperty.SelectedItem as string);
            if (_listDefOriginal == null || _listDefOriginal.RowCount == 0)
            {
                return(new ListData(listDef));
            }
            var columNameMap = _listProperties.Where(prop => !string.IsNullOrEmpty(prop.OriginalName))
                               .ToDictionary(prop => prop.Name, prop => prop.OriginalName);

            return(_listDefOriginal.ChangeListDef(listDef, columNameMap));
        }
示例#3
0
 private void SetListDef(ListDef listDef)
 {
     tbxListName.Text = listDef.Name;
     if (!string.IsNullOrEmpty(listDef.Name))
     {
         tbxListName.ReadOnly = true;
     }
     foreach (var property in listDef.Properties)
     {
         _listProperties.Add(new ListProperty(property));
     }
     colPropertyType.Items.Clear();
     foreach (var propertyType in ListPropertyType.ListPropertyTypes(_existing))
     {
         colPropertyType.Items.Add(propertyType);
     }
     PopulatePropertyDropdown(comboIdProperty, listDef.IdProperty);
     PopulatePropertyDropdown(comboDisplayProperty, listDef.DisplayProperty);
 }
示例#4
0
        public void TestListDataExceptions()
        {
            var listDef = new ListDef("test").ChangeProperties(new[]
            {
                new AnnotationDef("text", AnnotationDef.AnnotationTargetSet.EMPTY, AnnotationDef.AnnotationType.text, null),
                new AnnotationDef("number", AnnotationDef.AnnotationTargetSet.EMPTY, AnnotationDef.AnnotationType.number, null),
                new AnnotationDef("true_false", AnnotationDef.AnnotationTargetSet.EMPTY, AnnotationDef.AnnotationType.true_false, null)
            });
            var columns = new ColumnData[]
            {
                new ColumnData.Strings(new[] { "one", "two", "three", "four" }),
                new ColumnData.Doubles(new double?[] { 1, 2, 3, 4 }),
                new ColumnData.Booleans(new[] { true, false, true, false }),
            };
            var listData = new ListData(listDef, columns);

            Assert.IsNotNull(listData.ChangeListDef(listDef.ChangeIdProperty("text"), null));
            Assert.IsNotNull(listData.ChangeListDef(listDef.ChangeIdProperty("number"), null));
            EnsureDetailException <ListExceptionDetail>(() => listData.ChangeListDef(listDef.ChangeIdProperty("true_false"), null));
            VerifySerialization(listData);
        }
示例#5
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;
        }