예제 #1
0
        // load a family's data from the test data
        public void LoadFamilies()
        {
            Cd = new ColumnData();
            Fd = new ObservableCollection <FamilyData>();

            FamilyData fd;

            // get the first record
            KeyValuePair <string, List <Parameter> > k = TestData.TestFamilyData.First();

            int col = 0;

            // setup the column specifications
            foreach (Parameter p in k.Value)
            {
                ColumnSpec cs = CreateColumnSpec(p, col++);

                Cd.ColumnSpecs.Add(cs);
            }

            col = 0;

            // set up each row with the neme & set selected to false plus
            // the value for each parameter
            foreach (KeyValuePair <string, List <Parameter> > kvp in TestData.TestFamilyData)
            {
                AddRow(false, kvp.Key, kvp.Value);
            }

            UpdateTitles();
        }
예제 #2
0
        public static void AddHeader(Window w, Grid g, ColumnSpec h, int priorColWidth)
        {
            TextBlock tbk = new TextBlock();

            //			System.Drawing.Graphics x = System.Drawing.Graphics.FromImage(new Bitmap(1, 1));
            //
            ////			SizeF sz = x.MeasureString(h.ParamSpec.Name, ListBoxConfiguration.HeaderFont);
            ////			Debug.WriteLine("header length via graphics| " + h.ParamSpec.Name
            ////				+ " = " + sz);
            //
            //			Window w = new Window();
            //
            //
            //			TextBlock t = MainWindow.tx;
            //
            //
            //			t.Text = h.ParamSpec.Name;
            //
            //			t.TextWrapping = TextWrapping.NoWrap;
            //
            //			w.Content = t;
            //
            //			Debug.WriteLine("header length via textblock| " + h.ParamSpec.Name
            //				+ "= W| " + t.ActualWidth + " x H| " + t.ActualHeight );
            //
            //

            Style s = (Style)w.FindResource(ParameterVue.MainWindow.ColHeaderTbkStyleName);

            tbk.Style = s;
            tbk.Text  = h.ColumnTitle;
            tbk.HorizontalAlignment = h.ColumnAlignment;

            AddControlToEndOfGrid(g, tbk, priorColWidth);
        }
예제 #3
0
        public static string ToDhtmlxGridJsonCellData <T>(this T dataObject, ColumnSpec <T> columnSpec)
        {
            var cellAttributes = new Dictionary <string, string>();

            cellAttributes.Add("value", columnSpec.CalculateStringValue(dataObject));

            var title = columnSpec.CalculateTitle(dataObject);

            if (!String.IsNullOrWhiteSpace(title))
            {
                cellAttributes.Add("title", title);
            }

            var cssClass = columnSpec.CalculateCellCssClass(dataObject);

            if (!String.IsNullOrWhiteSpace(cssClass))
            {
                cellAttributes.Add("class", cssClass);
            }

            // if we only have a value, no need for the brackets
            if (cellAttributes.Count == 1)
            {
                return(cellAttributes.First().Value);
            }
            return(string.Format("{{{0}}}", string.Join(",", cellAttributes.Select(x => string.Format("\"{0}\":\"{1}\"", x.Key, x.Value)))));
        }
예제 #4
0
 public DisplayColumn(ViewInfo viewInfo, ColumnSpec columnSpec, ColumnDescriptor columnDescriptor)
 {
     ViewInfo = viewInfo;
     ColumnDescriptor = columnDescriptor;
     ColumnSpec = columnSpec;
     CollectionColumn = columnDescriptor == null ? null 
         : columnDescriptor.CollectionAncestor() ?? viewInfo.ParentColumn;
 }
예제 #5
0
        private ColumnSpec CreateColumnSpec(Parameter p, int colIdx)
        {
            ColumnSpec cs = new ColumnSpec(p, colIdx);

            cs.Choices = null;

            return(cs);
        }
예제 #6
0
 /// <summary>Snippet for GetColumnSpec</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetColumnSpecResourceNames()
 {
     // Create client
     AutoMlClient autoMlClient = AutoMlClient.Create();
     // Initialize request argument(s)
     ColumnSpecName name = ColumnSpecName.FromProjectLocationDatasetTableSpecColumnSpec("[PROJECT]", "[LOCATION]", "[DATASET]", "[TABLE_SPEC]", "[COLUMN_SPEC]");
     // Make the request
     ColumnSpec response = autoMlClient.GetColumnSpec(name);
 }
 /// <summary>Snippet for GetColumnSpec</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetColumnSpec()
 {
     // Create client
     AutoMlClient autoMlClient = AutoMlClient.Create();
     // Initialize request argument(s)
     string name = "projects/[PROJECT]/locations/[LOCATION]/datasets/[DATASET]/tableSpecs/[TABLE_SPEC]/columnSpecs/[COLUMN_SPEC]";
     // Make the request
     ColumnSpec response = autoMlClient.GetColumnSpec(name);
 }
예제 #8
0
 /// <summary>Snippet for UpdateColumnSpec</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void UpdateColumnSpec()
 {
     // Create client
     AutoMlClient autoMlClient = AutoMlClient.Create();
     // Initialize request argument(s)
     ColumnSpec columnSpec = new ColumnSpec();
     // Make the request
     ColumnSpec response = autoMlClient.UpdateColumnSpec(columnSpec);
 }
        /// <summary>Snippet for UpdateColumnSpecAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task UpdateColumnSpecAsync()
        {
            // Create client
            AutoMlClient autoMlClient = await AutoMlClient.CreateAsync();

            // Initialize request argument(s)
            ColumnSpec columnSpec = new ColumnSpec();
            // Make the request
            ColumnSpec response = await autoMlClient.UpdateColumnSpecAsync(columnSpec);
        }
예제 #10
0
        protected static IColumnSpec[] ReadColumnSpec(IFrameReader frameReader)
        {
            Stream        stream           = frameReader.ReadOnlyStream;
            MetadataFlags flags            = (MetadataFlags)stream.ReadInt();
            bool          globalTablesSpec = 0 != (flags & MetadataFlags.GlobalTablesSpec);

            int colCount = stream.ReadInt();

            string keyspace = null;
            string table    = null;

            if (globalTablesSpec)
            {
                keyspace = stream.ReadString();
                table    = stream.ReadString();
            }

            IColumnSpec[] columnSpecs = new IColumnSpec[colCount];
            for (int colIdx = 0; colIdx < colCount; ++colIdx)
            {
                string colKeyspace = keyspace;
                string colTable    = table;
                if (!globalTablesSpec)
                {
                    colKeyspace = stream.ReadString();
                    colTable    = stream.ReadString();
                }
                string     colName      = stream.ReadString();
                ColumnType colType      = (ColumnType)stream.ReadUShort();
                string     colCustom    = null;
                ColumnType colKeyType   = ColumnType.Custom;
                ColumnType colValueType = ColumnType.Custom;
                switch (colType)
                {
                case ColumnType.Custom:
                    colCustom = stream.ReadString();
                    break;

                case ColumnType.List:
                case ColumnType.Set:
                    colValueType = (ColumnType)stream.ReadUShort();
                    break;

                case ColumnType.Map:
                    colKeyType   = (ColumnType)stream.ReadUShort();
                    colValueType = (ColumnType)stream.ReadUShort();
                    break;
                }

                columnSpecs[colIdx] = new ColumnSpec(colIdx, colKeyspace, colTable, colName, colType, colCustom, colKeyType, colValueType);
            }

            return(columnSpecs);
        }
 /// <summary>Snippet for UpdateColumnSpec</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void UpdateColumnSpecRequestObject()
 {
     // Create client
     AutoMlClient autoMlClient = AutoMlClient.Create();
     // Initialize request argument(s)
     UpdateColumnSpecRequest request = new UpdateColumnSpecRequest
     {
         ColumnSpec = new ColumnSpec(),
         UpdateMask = new FieldMask(),
     };
     // Make the request
     ColumnSpec response = autoMlClient.UpdateColumnSpec(request);
 }
예제 #12
0
 /// <summary>Snippet for GetColumnSpec</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void GetColumnSpecRequestObject()
 {
     // Create client
     AutoMlClient autoMlClient = AutoMlClient.Create();
     // Initialize request argument(s)
     GetColumnSpecRequest request = new GetColumnSpecRequest
     {
         ColumnSpecName = ColumnSpecName.FromProjectLocationDatasetTableSpecColumnSpec("[PROJECT]", "[LOCATION]", "[DATASET]", "[TABLE_SPEC]", "[COLUMN_SPEC]"),
         FieldMask      = new FieldMask(),
     };
     // Make the request
     ColumnSpec response = autoMlClient.GetColumnSpec(request);
 }
예제 #13
0
 public void AddColumn(PropertyPath propertyPath)
 {
     List<ColumnSpec> columnSpecs = new List<ColumnSpec>(VisibleColumns.Select(col=>col.ColumnSpec));
     var newColumn = new ColumnSpec(propertyPath);
     if (listViewColumns.SelectedIndices.Count == 0)
     {
         columnSpecs.Add(newColumn);
     }
     else
     {
         columnSpecs.Insert(listViewColumns.SelectedIndices.Cast<int>().Min(), newColumn);
     }
     ColumnSpecs = columnSpecs;
 }
예제 #14
0
        private ListViewItem MakeListViewItem(ColumnSpec columnSpec)
        {
            var listViewItem     = new ListViewItem();
            var columnDescriptor = ParentColumn.ResolveDescendant(columnSpec.IdentifierPath);

            if (columnDescriptor == null)
            {
                listViewItem.Text = columnSpec.Caption ?? columnSpec.IdentifierPath.Name;
                listViewItem.Font = _strikeThroughFont;
            }
            else
            {
                listViewItem.Text = columnDescriptor.DisplayName;
            }
            return(listViewItem);
        }
예제 #15
0
        public static void AddColumn(Window w, DataGrid dg, ColumnSpec cs, Binding b)
        {
            DataGridColumn col = null;

            switch (cs.ColumnType)
            {
            case ColumnType.CHECKBOX:
            {
                col = new DataGridCheckBoxColumn();
                ((DataGridCheckBoxColumn)col).Binding = b;
                break;
            }

            case ColumnType.TEXTBOX:
            {
                col = new DataGridTextColumn();
                ((DataGridTextColumn)col).Binding = b;
                break;
            }

            case ColumnType.DROPDOWN:
            {
                col = new DataGridComboBoxColumn();
                ((DataGridComboBoxColumn)col).ItemsSource         = cs.Choices.ChoiceList;
                ((DataGridComboBoxColumn)col).SelectedItemBinding = b;
                break;
            }
            }

//			DataTemplate dt = (DataTemplate) w.FindResource("HeaderTemplate1");
            Style dt = (Style)w.FindResource("DataGridColumnHeaderStyle3");

            if (cs.ColumnWidth > 0)
            {
                col.Width = cs.ColumnWidth;
            }

            col.Header = cs;
//			col.HeaderTemplate = dt;
            col.HeaderStyle = dt;


            dg.Columns.Add(col);
        }
        public object GetObfuscatedValue(IObfuscationContext obfuscationContext, IColumnSpec columnSpec, IField field, object originalFieldValue)
        {
            IColumnSpec <TObfuscationStrategySpec> _columnSpec;
            object value;

            if ((object)obfuscationContext == null)
            {
                throw new ArgumentNullException(nameof(obfuscationContext));
            }

            if ((object)columnSpec == null)
            {
                throw new ArgumentNullException(nameof(columnSpec));
            }

            if ((object)field == null)
            {
                throw new ArgumentNullException(nameof(field));
            }

            if ((object)originalFieldValue == DBNull.Value)
            {
                originalFieldValue = null;
            }

            if ((object)columnSpec.ObfuscationStrategySpec == null)
            {
                throw new InvalidOperationException(string.Format("Specification missing: '{0}'.", nameof(columnSpec.ObfuscationStrategySpec)));
            }

            _columnSpec = new ColumnSpec <TObfuscationStrategySpec>(columnSpec);

            if ((object)_columnSpec.ObfuscationStrategySpec == null)
            {
                throw new InvalidOperationException(string.Format("Specification missing: '{0}'.", nameof(_columnSpec.ObfuscationStrategySpec)));
            }

            value = this.CoreGetObfuscatedValue(obfuscationContext, _columnSpec, field, originalFieldValue);

            return(value);
        }
예제 #17
0
        protected static IColumnSpec[] ReadColumnSpecs(int colCount, string keyspace, string table, bool globalTablesSpec, Stream stream)
        {
            IColumnSpec[] columnSpecs = new IColumnSpec[colCount];
            for (int colIdx = 0; colIdx < colCount; ++colIdx)
            {
                string colKeyspace = keyspace;
                string colTable    = table;
                if (!globalTablesSpec)
                {
                    colKeyspace = stream.ReadString();
                    colTable    = stream.ReadString();
                }

                string     colName      = stream.ReadString();
                ColumnType colType      = (ColumnType)stream.ReadUShort();
                string     colCustom    = null;
                ColumnType colKeyType   = ColumnType.Custom;
                ColumnType colValueType = ColumnType.Custom;
                switch (colType)
                {
                case ColumnType.Custom:
                    colCustom = stream.ReadString();
                    break;

                case ColumnType.List:
                case ColumnType.Set:
                    colValueType = (ColumnType)stream.ReadUShort();
                    break;

                case ColumnType.Map:
                    colKeyType   = (ColumnType)stream.ReadUShort();
                    colValueType = (ColumnType)stream.ReadUShort();
                    break;
                }

                columnSpecs[colIdx] = new ColumnSpec(colIdx, colKeyspace, colTable, colName, colType, colCustom, colKeyType, colValueType);
            }
            return(columnSpecs);
        }
예제 #18
0
 public NotIsNullCondition(ColumnSpec column)
 {
     this.column = column;
 }
예제 #19
0
 public NotFoundInDBException(ColumnSpec columnSpec, string value) : base("Object " + columnSpec.table.name + "[" + columnSpec.name + "=" + value + "] not found in db")
 {
 }
예제 #20
0
 public List <string> LoadIdsByConditions(ITableSpec table, Web.Core.DB.conditions.AbstractCondition conditions, Diapasone diapasone, JoinSpec[] joins, SortSpec[] sorts, ColumnSpec idSpec, bool allowHugeLists)
 {
     using (DbConnection connection = this.createConnection()) {
         using (DbCommand command = connection.CreateCommand()) {
             return(this._LoadIdsByConditions(command, table, conditions, diapasone, joins, sorts, idSpec, allowHugeLists));
         }
     }
 }
예제 #21
0
 private ColumnSpec ConvertReportColumn(ReportColumn reportColumn)
 {
     var identifierPath = PropertyPath.Root;
     var databindingTableAttribute = GetDatabindingTableAttribute(reportColumn);
     var component = reportColumn.Table;
     string oldCaption = null;
     foreach (string part in reportColumn.Column.Parts)
     {
         PropertyPath propertyPath;
         if (part.StartsWith(AnnotationDef.ANNOTATION_PREFIX))
         {
             string annotationName = AnnotationDef.GetColumnDisplayName(part);
             if (component == typeof (DbProteinResult))
             {
                 propertyPath = PropertyPath.Root.Property("Replicate").Property(AnnotationDef.ANNOTATION_PREFIX + annotationName); // Not L10N
             }
             else
             {
                 propertyPath = PropertyPath.Root.Property(AnnotationDef.ANNOTATION_PREFIX + annotationName);
             }
             oldCaption = annotationName;
             component = typeof (string);
         }
         else if (RatioPropertyAccessor.IsRatioOrRdotpProperty(part))
         {
             propertyPath = null;
             if (component == typeof (DbPeptideResult))
             {
                 const string prefixPeptideRatio = "ratio_Ratio"; // Not L10N
                 string labelName, standardName;
                 if (part.StartsWith(prefixPeptideRatio))
                 {
                     if (TryParseLabelNames(part.Substring(prefixPeptideRatio.Length), out labelName, out standardName))
                     {
                         propertyPath = PropertyPath.Root.Property(RatioPropertyDescriptor.MakePropertyName(
                             RatioPropertyDescriptor.RATIO_PREFIX, labelName, standardName));
                     }
                 }
                 const string prefixPeptideRdotp = "rdotp_DotProduct"; // Not L10N
                 if (part.StartsWith(prefixPeptideRdotp))
                 {
                     if (TryParseLabelNames(part.Substring(prefixPeptideRdotp.Length), out labelName, out standardName))
                     {
                         propertyPath = PropertyPath.Root.Property(RatioPropertyDescriptor.MakePropertyName(
                             RatioPropertyDescriptor.RDOTP_PREFIX, labelName, standardName));
                     }
                 }
             }
             else if (component == typeof (DbPrecursorResult))
             {
                 const string prefixPrecursorRatio = "ratio_TotalAreaRatioTo"; // Not L10N
                 const string prefixPrecursorRdotp = "rdotp_DotProductTo"; // Not L10N
                 if (part.StartsWith(prefixPrecursorRatio))
                 {
                     propertyPath = PropertyPath.Root.Property(
                         RatioPropertyDescriptor.MakePropertyName(RatioPropertyDescriptor.RATIO_PREFIX, part.Substring(prefixPrecursorRatio.Length)));
                 }
                 else if (part.StartsWith(prefixPrecursorRdotp))
                 {
                     propertyPath = PropertyPath.Root.Property(
                         RatioPropertyDescriptor.MakePropertyName(RatioPropertyDescriptor.RDOTP_PREFIX,
                             part.Substring(prefixPrecursorRdotp.Length)));
                 }
             }
             else if (component == typeof (DbTransitionResult))
             {
                 const string prefixTransitionRatio = "ratio_AreaRatioTo"; // Not L10N
                 if (part.StartsWith(prefixTransitionRatio))
                 {
                     propertyPath = PropertyPath.Root.Property(
                         RatioPropertyDescriptor.MakePropertyName(RatioPropertyDescriptor.RATIO_PREFIX,
                         part.Substring(prefixTransitionRatio.Length)));
                 }
             }
             component = typeof (double);
             oldCaption = null;
             if (null == propertyPath)
             {
                 Trace.TraceWarning("Unable to parse ratio property {0}", part); // Not L10N
                 propertyPath = PropertyPath.Root.Property(part);
             }
         }
     //                else if (component == typeof (DbProteinResult) && part == "ResultFile")
     //                {
     //                    propertyPath = PropertyPath.Parse("Results!*.Value");
     //                }
         else
         {
             PropertyInfo property = component.GetProperty(part);
             if (null == property)
             {
                 Trace.TraceWarning("Could not find property {0}", part); // Not L10N
                 continue;
             }
             propertyPath = PropertyPath.Root.Property(part);
             foreach (DatabindingColumnAttribute databindingColumn in
                 property.GetCustomAttributes(typeof (DatabindingColumnAttribute), true))
             {
                 if (null != databindingColumn.Name)
                 {
                     propertyPath = PropertyPath.Parse(databindingColumn.Name);
                     break;
                 }
             }
             oldCaption = property.Name;
             foreach (QueryColumn attr in property.GetCustomAttributes(typeof (QueryColumn), true))
             {
                 oldCaption = attr.FullName ?? oldCaption;
             }
             component = property.PropertyType;
         }
         identifierPath = identifierPath.Concat(propertyPath);
     }
     var columnDescriptor = GetColumnDescriptor(databindingTableAttribute, identifierPath);
     if (null == columnDescriptor)
     {
         return new ColumnSpec(identifierPath);
     }
     var columnSpec = new ColumnSpec(columnDescriptor.PropertyPath);
     var newCaption = DataSchema.GetColumnCaption(columnDescriptor).InvariantCaption;
     if (oldCaption != newCaption)
     {
         columnSpec = columnSpec.SetCaption(oldCaption);
     }
     return columnSpec;
 }
예제 #22
0
        static bool TryMakeColumnSpec(string name, feather.fbs.Type effectiveType, ref PrimitiveArray arrayDetails, string[] categoryLevels, DateTimePrecisionType precision, out ColumnSpec columnSpec, out string errorMessage)
        {
            var arrayOffset   = arrayDetails.Offset;
            var arrayLength   = arrayDetails.Length;
            var arrayNulls    = arrayDetails.NullCount;
            var arrayEncoding = arrayDetails.Encoding;

            // TODO (Dictionary Encoding)
            if (arrayEncoding != feather.fbs.Encoding.PLAIN)
            {
                throw new NotImplementedException();
            }
            // END TODO

            ColumnType type;
            bool       isNullable;

            if (!TryGetType(effectiveType, ref arrayDetails, precision, out type, out isNullable, out errorMessage))
            {
                columnSpec = default(ColumnSpec);
                return(false);
            }

            long numNullBytes = 0;

            if (isNullable)
            {
                numNullBytes = arrayLength / 8;
                if (arrayLength % 8 != 0)
                {
                    numNullBytes++;
                }
            }

            // a naive reading of the spec suggests that the null bitmask should be
            //   aligned based on the _type_ but it appears to always be long
            //   aligned.
            // this may be a bug in the spec
            int nullPadding = 0;

            if ((numNullBytes % FeatherMagic.NULL_BITMASK_ALIGNMENT) != 0)
            {
                nullPadding = FeatherMagic.NULL_BITMASK_ALIGNMENT - (int)(numNullBytes % FeatherMagic.NULL_BITMASK_ALIGNMENT);
            }
            var nullOffset = isNullable ? (arrayOffset) : -1;
            var dataOffset = !isNullable ? (arrayOffset) : (nullOffset + numNullBytes + nullPadding);

            columnSpec =
                new ColumnSpec
            {
                Name = name,
                NullBitmaskOffset = nullOffset,
                DataOffset        = dataOffset,
                Length            = arrayLength,
                Type           = type,
                CategoryLevels = categoryLevels,

                // only spin up this map if we've got categories to potentially map to
                CategoryEnumMap = categoryLevels != null ? new Dictionary <System.Type, CategoryEnumMapType>() : null
            };
            errorMessage = null;
            return(true);
        }
예제 #23
0
 public MultiValueCondition(ColumnSpec column, string[] values)
     : this(column, values, true)
 {
 }
예제 #24
0
 public MultiValueCondition(ColumnSpec column, string[] values, bool inclusive)
 {
     this.column    = column;
     this.values    = values;
     this.inclusive = inclusive;
 }
예제 #25
0
 public MultiValueCondition(ColumnSpec column, string[] values) : this(column, values, true)
 {
 }
예제 #26
0
 public void AddColumn(PropertyPath propertyPath)
 {
     List<ColumnSpec> columnSpecs = new List<ColumnSpec>(VisibleColumns.Select(col=>col.ColumnSpec));
     var newColumn = new ColumnSpec(propertyPath);
     if (listViewColumns.SelectedIndices.Count == 0)
     {
         columnSpecs.Add(newColumn);
     }
     else
     {
         columnSpecs.Insert(listViewColumns.SelectedIndices.Cast<int>().Min(), newColumn);
     }
     ColumnSpecs = columnSpecs;
 }
예제 #27
0
 public IsNullCondition(ColumnSpec column)
 {
     this.column = column;
 }
예제 #28
0
    public static List <T> CreateListFromSheet <T>(ScriptableObject parentObj, string filename, string sheetname) where T : ScriptableObject
    {
        Debug.Log(string.Format(
                      "Creating a list of type {0} from file {1} and sheet {2}", typeof(T).ToString(), filename, sheetname));

        List <ColumnSpec> specs = new List <ColumnSpec>();

        FieldInfo[] fields = typeof(T).GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
        if (fields.Length == 0)
        {
            Debug.LogError("Could not find any fields in class " + typeof(T).ToString());
        }
        foreach (var fieldInfo in fields)
        {
            Debug.Log(fieldInfo.ToString());
            //System.Attribute[] attrs = propInfo.GetCustomAttributes(true);
            object[] attrs = fieldInfo.GetCustomAttributes(true);
            if (attrs.Length == 0)
            {
                Debug.LogError("Could not find any attributes in class " + typeof(T).ToString());
            }
            int found = 0;
            foreach (var att in attrs)
            {
                ExcelColumnAttribute e = att as ExcelColumnAttribute;
                if (e != null)
                {
                    found += 1;
                    Debug.Log(att.ToString());
                    ColumnSpec spec = new ColumnSpec(
                        fieldInfo.FieldType,
                        e.startCol,
                        e.endCol,
                        fieldInfo.Name,
                        e.name != null ? e.name : fieldInfo.Name
                        );
                    specs.Add(spec);
                }
            }
            if (found == 0)
            {
                Debug.LogError("Could not find any ExcelColumn attributes in class " + typeof(T).ToString());
            }
        }

        // Now we have a column spec, we can go through the excel file and extract a bunch of objects

        DataTable dt = GetDataTableFromExcel(filename, sheetname);


        // Check that header has all of our expected fields
        foreach (ColumnSpec spec in specs)
        {
            DataColumn found   = null;
            string     colName = FormatColumnName(spec.columnName);
            foreach (DataColumn col in dt.Columns)
            {
                if (FormatColumnName(col.ColumnName) == colName)
                {
                    found = col;
                    break;
                }
            }

            if (found == null)
            {
                Debug.LogError(string.Format(
                                   "Spec error: File {0}, Sheet {1}: Couldn't find column named {2} (munged to {3})",
                                   filename, sheetname, spec.columnName, colName));
            }
            else
            {
                spec.startCol = found.Ordinal;
                spec.endCol   = found.Ordinal;
            }
        }



        // Create objects!
        var dataObjects = new List <T>();

        for (int r = 0; r < dt.Rows.Count; r++)
        {
            // All of the objects within our ScriptableObject must be ScriptableObjects themselves
            // because of Unity's serialization and inheritance bug
            T rowObj = (T)ScriptableObject.CreateInstance(typeof(T).Name);
            foreach (ColumnSpec spec in specs)
            {
                for (int c = spec.startCol; c <= spec.endCol; c++)
                {
                    Debug.Log(dt.Rows[r][c]);
                    Debug.Log(dt.Rows[r][c].GetType().ToString());
                    if (spec.isReq)
                    {
                        if (string.IsNullOrEmpty(dt.Rows[r][c].ToString()))
                        {
                            Debug.LogError(string.Format(
                                               "Spec error: File {0}, Sheet {1}, Row {2}, Column {3} (#{4}): Cannot be empty.",
                                               filename, sheetname, spec.startCol, r, spec.fieldName, c + 1));
                        }
                    }

                    FieldInfo rowObjFieldInfo = typeof(T).GetField(spec.fieldName, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);

                    if (rowObj == null)
                    {
                        Debug.Log("RowObj null");
                    }
                    if (rowObjFieldInfo == null)
                    {
                        Debug.Log("rowObjFieldInfo null for " + spec.fieldName + " for type " + typeof(T).ToString());
                    }

                    // Automagically try to cast to the target datatype
                    rowObjFieldInfo.SetValue(rowObj, Convert.ChangeType(dt.Rows[r][c], rowObjFieldInfo.FieldType));
                }
            }
            dataObjects.Add(rowObj);

            // To save this child ScriptableObject asset, we have to add it to the parent one
            AssetDatabase.AddObjectToAsset(rowObj, parentObj);

            // Hide these child assets so the container is the only selectable one
            rowObj.hideFlags = HideFlags.HideAndDontSave;
        }


        if (dataObjects.Count == 0)
        {
            Debug.LogError("Didn't load anything");
        }

        return(dataObjects);
    }
예제 #29
0
 public ComparisonCondition(ColumnSpec left, ComparisonType comparison, string right)
 {
     this.left       = left;
     this.comparison = comparison;
     this.right      = ColumnOrValue.createValue(right);
 }
예제 #30
0
        private List <string> _LoadIdsByConditions(DbCommand command, ITableSpec table, Web.Core.DB.conditions.AbstractCondition conditions, Diapasone diapasone, JoinSpec[] joins, SortSpec[] sorts, ColumnSpec idSpec, bool allowHugeLists)
        {
            using (var logger = this.CreateCommandExecutionLogger()) {
                command.CommandType = System.Data.CommandType.Text;

                var    conditionsCompiled = ConditionCompiler.Compile(conditions, this.traits);
                string queryConditions    = "";
                if (conditionsCompiled.Key != "")
                {
                    queryConditions = "WHERE " + conditionsCompiled.Key;
                }
                ParamsHolder paramsHolder = conditionsCompiled.Value;

                StringBuilder queryJoins = new StringBuilder();
                {
                    foreach (var join in joins)
                    {
                        queryJoins.Append(" JOIN ");
                        queryJoins.Append(join.additionalTableRaw.compile(this.traits));
                        queryJoins.Append(" ");
                        queryJoins.Append(join.additionalTable.compile(this.traits));
                        queryJoins.Append(" ON ");
                        queryJoins.Append(join.mainColumn.compile(this.traits));
                        queryJoins.Append(" = ");
                        queryJoins.Append(join.additionalTable.getIdSpec().compile(this.traits));
                    }
                }

                string querySorts = "";
                if (sorts.Length > 0)
                {
                    List <string> sortParts = new List <string>();
                    foreach (SortSpec sortSpec in sorts)
                    {
                        if (sortSpec.ascending)
                        {
                            sortParts.Add(sortSpec.column.compile(this.traits) + " ASC");
                        }
                        else
                        {
                            sortParts.Add(sortSpec.column.compile(this.traits) + " DESC");
                        }
                    }
                    querySorts = "ORDER BY " + string.Join(", ", sortParts.ToArray());
                }

                string queryMain = "FROM " + table.compile(this.traits) + " " + queryJoins + " " + queryConditions;

                foreach (KeyValuePair <string, string> kvp in paramsHolder.data)
                {
                    command.AddParameter(kvp.Key, kvp.Value);
                }

                if (!diapasone.total.HasValue)
                {
                    command.CommandText = logger.commandText = "SELECT COUNT(*) " + queryMain;
                    object rawCount;
                    //try {
                    rawCount = command.ExecuteScalar();
                    //} catch(Npgsql.NpgsqlException e) {
                    //throw new FLocalException("Error while trying to execute " + command.CommandText + ": " + e.Message);
                    //}
                    long count = (long)rawCount;
                    if (count < 1)
                    {
                        diapasone.total = 0;
                    }
                    else
                    {
                        diapasone.total = count;
                    }
                }

                if (diapasone.total.Value < 1)
                {
                    return(new List <string>());
                }
                else
                {
                    if (diapasone.total.Value > 1000 && diapasone.count < 0 && !allowHugeLists)
                    {
                        throw new CriticalException("huge list");
                    }
                    string queryLimits = "";
                    if (diapasone.count >= 0)
                    {
                        queryLimits = "LIMIT " + diapasone.count + " OFFSET " + diapasone.start;
                    }
                    command.CommandText = logger.commandText = "SELECT " + idSpec.compile(this.traits) + " " + queryMain + " " + querySorts + " " + queryLimits;

                    List <string> result = new List <string>();
                    using (DbDataReader reader = command.ExecuteReader()) {
                        while (reader.Read())
                        {
                            result.Add(reader.GetValue(0).ToString());
                        }
                    }
                    return(result);
                }
            }
        }
예제 #31
0
        internal static string ReadString(MemoryMappedViewAccessor view, long rowCount, ThreadLocal <byte[]> byteBuffer, ref ColumnSpec columnMetadata, long translatedRowIndex)
        {
            var dataOffset = columnMetadata.DataOffset;

            var stringOffsetOffset = dataOffset + translatedRowIndex * sizeof(int);
            var stringOffset       = view.ReadInt32(stringOffsetOffset);

            var nextStringOffsetOffset = dataOffset + (translatedRowIndex + 1) * sizeof(int);
            var nextStringOffset       = view.ReadInt32(nextStringOffsetOffset);

            var stringDataStart = dataOffset + (rowCount + 1) * sizeof(int);

            var stringDataPadding = 0;

            if (stringDataStart % FeatherMagic.ARROW_ALIGNMENT != 0)
            {
                stringDataPadding = FeatherMagic.ARROW_ALIGNMENT - (int)(stringDataStart % FeatherMagic.ARROW_ALIGNMENT);
            }
            stringDataStart += stringDataPadding;

            var stringDataStartIx = stringDataStart + stringOffset;
            var stringDataEndIx   = stringDataStart + nextStringOffset;

            var stringLengthLong = stringDataEndIx - stringDataStartIx;

            if (stringLengthLong == 0)
            {
                return("");
            }

            if (stringLengthLong < 0 || stringLengthLong > Int32.MaxValue)
            {
                throw new InvalidOperationException($"Tried to create a string with an absurd length {stringLengthLong:N0}");
            }

            var stringLength = (int)stringLengthLong;

            var buffer = byteBuffer?.Value;

            if (buffer == null || buffer.Length < stringLength)
            {
                int newSize;
                if (stringLength < 4096)
                {
                    newSize = stringLength;

                    // get it to the nearest power of two
                    //   only calculating for the first 32-bits
                    //   since the size check on stringLength
                    //   should exclude anything larger
                    newSize--;
                    newSize |= newSize >> 1;
                    newSize |= newSize >> 2;
                    newSize |= newSize >> 4;
                    newSize |= newSize >> 8;
                    newSize |= newSize >> 16;
                    newSize++;
                }
                else
                {
                    // round to nearest whole page size
                    newSize = (stringLength / 4096) * 4096 + (stringLength % 4096);
                }

                if (buffer == null)
                {
                    newSize = Math.Max(newSize, MIN_BYTE_BUFFER_SIZE);
                    buffer  = new byte[newSize];
                }
                else
                {
                    Array.Resize(ref buffer, newSize);
                }

                if (byteBuffer != null)
                {
                    byteBuffer.Value = buffer;
                }
            }

            view.ReadArray(stringDataStartIx, buffer, 0, stringLength);

            var ret = Encoding.UTF8.GetString(buffer, 0, stringLength);

            return(ret);
        }
예제 #32
0
        private ColumnSpec ConvertReportColumn(ReportColumn reportColumn)
        {
            var    identifierPath            = PropertyPath.Root;
            var    databindingTableAttribute = GetDatabindingTableAttribute(reportColumn);
            var    component  = reportColumn.Table;
            string oldCaption = null;

            foreach (string part in reportColumn.Column.Parts)
            {
                PropertyPath propertyPath;
                if (part.StartsWith(AnnotationDef.ANNOTATION_PREFIX))
                {
                    string annotationName = AnnotationDef.GetColumnDisplayName(part);
                    if (component == typeof(DbProteinResult))
                    {
                        propertyPath = PropertyPath.Root.Property(@"Replicate").Property(AnnotationDef.ANNOTATION_PREFIX + annotationName);
                    }
                    else
                    {
                        propertyPath = PropertyPath.Root.Property(AnnotationDef.ANNOTATION_PREFIX + annotationName);
                    }
                    oldCaption = annotationName;
                    component  = typeof(string);
                }
                else if (RatioPropertyAccessor.IsRatioOrRdotpProperty(part))
                {
                    propertyPath = null;
                    if (component == typeof(DbPeptideResult))
                    {
                        const string prefixPeptideRatio = "ratio_Ratio";
                        string       labelName, standardName;
                        if (part.StartsWith(prefixPeptideRatio))
                        {
                            if (TryParseLabelNames(part.Substring(prefixPeptideRatio.Length), out labelName, out standardName))
                            {
                                propertyPath = PropertyPath.Root.Property(RatioPropertyDescriptor.MakePropertyName(
                                                                              RatioPropertyDescriptor.RATIO_PREFIX, labelName, standardName));
                            }
                        }
                        const string prefixPeptideRdotp = "rdotp_DotProduct";
                        if (part.StartsWith(prefixPeptideRdotp))
                        {
                            if (TryParseLabelNames(part.Substring(prefixPeptideRdotp.Length), out labelName, out standardName))
                            {
                                propertyPath = PropertyPath.Root.Property(RatioPropertyDescriptor.MakePropertyName(
                                                                              RatioPropertyDescriptor.RDOTP_PREFIX, labelName, standardName));
                            }
                        }
                    }
                    else if (component == typeof(DbPrecursorResult))
                    {
                        const string prefixPrecursorRatio = "ratio_TotalAreaRatioTo";
                        const string prefixPrecursorRdotp = "rdotp_DotProductTo";
                        if (part.StartsWith(prefixPrecursorRatio))
                        {
                            propertyPath = PropertyPath.Root.Property(
                                RatioPropertyDescriptor.MakePropertyName(RatioPropertyDescriptor.RATIO_PREFIX, part.Substring(prefixPrecursorRatio.Length)));
                        }
                        else if (part.StartsWith(prefixPrecursorRdotp))
                        {
                            propertyPath = PropertyPath.Root.Property(
                                RatioPropertyDescriptor.MakePropertyName(RatioPropertyDescriptor.RDOTP_PREFIX,
                                                                         part.Substring(prefixPrecursorRdotp.Length)));
                        }
                    }
                    else if (component == typeof(DbTransitionResult))
                    {
                        const string prefixTransitionRatio = "ratio_AreaRatioTo";
                        if (part.StartsWith(prefixTransitionRatio))
                        {
                            propertyPath = PropertyPath.Root.Property(
                                RatioPropertyDescriptor.MakePropertyName(RatioPropertyDescriptor.RATIO_PREFIX,
                                                                         part.Substring(prefixTransitionRatio.Length)));
                        }
                    }
                    component  = typeof(double);
                    oldCaption = null;
                    if (null == propertyPath)
                    {
                        Trace.TraceWarning(@"Unable to parse ratio property {0}", part);
                        propertyPath = PropertyPath.Root.Property(part);
                    }
                }
//                else if (component == typeof (DbProteinResult) && part == "ResultFile")
//                {
//                    propertyPath = PropertyPath.Parse("Results!*.Value");
//                }
                else
                {
                    PropertyInfo property = component.GetProperty(part);
                    if (null == property)
                    {
                        Trace.TraceWarning(@"Could not find property {0}", part);
                        continue;
                    }
                    propertyPath = PropertyPath.Root.Property(part);
                    foreach (DatabindingColumnAttribute databindingColumn in
                             property.GetCustomAttributes(typeof(DatabindingColumnAttribute), true))
                    {
                        if (null != databindingColumn.Name)
                        {
                            propertyPath = PropertyPath.Parse(databindingColumn.Name);
                            break;
                        }
                    }
                    oldCaption = property.Name;
                    foreach (QueryColumn attr in property.GetCustomAttributes(typeof(QueryColumn), true))
                    {
                        oldCaption = attr.FullName ?? oldCaption;
                    }
                    component = property.PropertyType;
                }
                identifierPath = identifierPath.Concat(propertyPath);
            }
            var columnDescriptor = GetColumnDescriptor(databindingTableAttribute, identifierPath);

            if (null == columnDescriptor)
            {
                return(new ColumnSpec(identifierPath));
            }
            var columnSpec = new ColumnSpec(columnDescriptor.PropertyPath);
            var newCaption = DataSchema.GetColumnCaption(columnDescriptor).GetCaption(DataSchemaLocalizer.INVARIANT);

            if (oldCaption != newCaption)
            {
                columnSpec = columnSpec.SetCaption(oldCaption);
            }
            return(columnSpec);
        }
예제 #33
0
        static bool TryReadMetaData(MemoryMappedFile file, long size, out Metadata metadata, out string error)
        {
            if (size < FeatherMagic.MAGIC_HEADER_SIZE * 2)
            {
                metadata = default(Metadata);
                error    = $"File too small ({size:N0} bytes) to be a valid feather file";
                return(false);
            }

            using (var accessor = file.CreateViewAccessor())
            {
                var leadingHeader = accessor.ReadInt32(0);

                if (leadingHeader != FeatherMagic.MAGIC_HEADER)
                {
                    metadata = default(Metadata);
                    error    = $"Magic header malformed";
                    return(false);
                }

                var trailingHeader = accessor.ReadInt32(size - FeatherMagic.MAGIC_HEADER_SIZE);

                if (trailingHeader != FeatherMagic.MAGIC_HEADER)
                {
                    metadata = default(Metadata);
                    error    = $"Magic footer malformed";
                    return(false);
                }

                var metadataSize = accessor.ReadUInt32(size - FeatherMagic.MAGIC_HEADER_SIZE - sizeof(uint));

                var metadataStart = size - FeatherMagic.MAGIC_HEADER_SIZE - sizeof(uint) - metadataSize;
                if (metadataStart < FeatherMagic.MAGIC_HEADER_SIZE || metadataSize > int.MaxValue)
                {
                    metadata = default(Metadata);
                    error    = $"Metadata size ({metadataSize:N0}) is invalid";
                    return(false);
                }

                var metadataBytes = new byte[metadataSize];
                accessor.ReadArray(metadataStart, metadataBytes, 0, (int)metadataSize);

                // note: It'd be nice to not actually use flatbuffers for this,
                //   kind of a heavy (re)build dependency for reading, like, 4
                //   things
                var metadataBuffer = new ByteBuffer(metadataBytes);
                var metadataCTable = CTable.GetRootAsCTable(metadataBuffer);

                if (metadataCTable.Version != FeatherMagic.FEATHER_VERSION)
                {
                    error    = $"Unexpected version {metadataCTable.Version}, only {FeatherMagic.FEATHER_VERSION} is supported";
                    metadata = default(Metadata);
                    return(false);
                }

                if (metadataCTable.ColumnsLength <= 0)
                {
                    error    = $"Invalid number of columns: {metadataCTable.ColumnsLength:N0}";
                    metadata = default(Metadata);
                    return(false);
                }

                var columnSpecs = new ColumnSpec[metadataCTable.ColumnsLength];
                for (var i = 0; i < columnSpecs.Length; i++)
                {
                    var metadataColumn = metadataCTable.Columns(i).Value;
                    var name           = metadataColumn.Name;
                    var metadataType   = metadataColumn.MetadataType;

                    string[] categoryLevels         = null;
                    DateTimePrecisionType precision = default(DateTimePrecisionType);

                    var arrayDetails  = metadataColumn.Values.Value;
                    var effectiveType = arrayDetails.Type;

                    switch (metadataType)
                    {
                    case TypeMetadata.CategoryMetadata:
                        if (!TryReadCategoryLevels(accessor, ref metadataColumn, out categoryLevels, out error))
                        {
                            metadata = default(Metadata);
                            return(false);
                        }
                        break;

                    case TypeMetadata.TimestampMetadata:
                        if (arrayDetails.Type != feather.fbs.Type.INT64)
                        {
                            metadata = default(Metadata);
                            error    = $"Column {name} has Timestamp metadata, but isn't backed by an Int64 array";
                            return(false);
                        }

                        if (!TryReadTimestampPrecision(ref metadataColumn, out precision, out error))
                        {
                            metadata = default(Metadata);
                            return(false);
                        }

                        // note: this type is spec'd (https://github.com/wesm/feather/blob/master/cpp/src/feather/metadata.fbs#L25),
                        //  but it looks like R always writes it as an int64?
                        // Possibly a bug.
                        effectiveType = feather.fbs.Type.TIMESTAMP;

                        break;

                    case TypeMetadata.TimeMetadata:
                        if (arrayDetails.Type != feather.fbs.Type.INT64)
                        {
                            metadata = default(Metadata);
                            error    = $"Column {name} has Time metadata, but isn't backed by an Int64 array";
                            return(false);
                        }

                        if (!TryReadTimePrecision(ref metadataColumn, out precision, out error))
                        {
                            metadata = default(Metadata);
                            return(false);
                        }

                        // note: this type is spec'd (https://github.com/wesm/feather/blob/master/cpp/src/feather/metadata.fbs#L27),
                        //  but it looks like R always writes it as an int64?
                        // Possibly a bug.
                        effectiveType = feather.fbs.Type.TIME;

                        break;

                    case TypeMetadata.DateMetadata:
                        if (arrayDetails.Type != feather.fbs.Type.INT32)
                        {
                            metadata = default(Metadata);
                            error    = $"Column {name} has Time metadata, but isn't backed by an Int32 array";
                            return(false);
                        }

                        // note: this type is spec'd (https://github.com/wesm/feather/blob/master/cpp/src/feather/metadata.fbs#L26),
                        //  but it looks like R always writes it as an int32?
                        // Possibly a bug.
                        effectiveType = feather.fbs.Type.DATE;

                        break;

                    case TypeMetadata.NONE: break;
                    }

                    ColumnSpec column;
                    if (!TryMakeColumnSpec(name, effectiveType, ref arrayDetails, categoryLevels, precision, out column, out error))
                    {
                        metadata = default(Metadata);
                        return(false);
                    }

                    columnSpecs[i] = column;
                }

                metadata =
                    new Metadata
                {
                    Columns = columnSpecs,
                    NumRows = metadataCTable.NumRows
                };
                error = null;
                return(true);
            }
        }
예제 #34
0
 public ComparisonCondition(ColumnSpec left, ComparisonType comparison, string right)
 {
     this.left = left;
     this.comparison = comparison;
     this.right = ColumnOrValue.createValue(right);
 }
예제 #35
0
 public static string compile(this ColumnSpec column, IDBTraits traits)
 {
     return(column.table.compile(traits) + "." + traits.escapeIdentifier(column.name));
 }
예제 #36
0
 public MultiValueCondition(ColumnSpec column, string[] values, bool inclusive)
 {
     this.column = column;
     this.values = values;
     this.inclusive = inclusive;
 }