示例#1
0
        public IActionResult Add(Object dynObj)
        {
            try
            {
                if (dynObj.IsJsonElemen())
                {
                    String json = dynObj.ToString();
                    if (false == String.IsNullOrWhiteSpace(json))
                    {
                        using (var db_source = DataSourceCreator.Create(this._IConfig))
                        {
                            var model = db_source.AddObject(json);

                            return(Ok(model));
                        }
                    }
                }

                return(BadRequest("Unknown data"));
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                return(BadRequest(ex.Message));
            }
        }
示例#2
0
        public string Get()
        {
            DataSource dataSource = new DataSourceCreator(Name, KeyValues).Create();

            if (dataSource.GetType() == typeof(PagingDataSource))
            {
                PagingDataSource ds = dataSource as PagingDataSource;

                IEnumerable <string> jsonCollection;
                if (ds.Expands == null || ds.Expands.Length == 0)
                {
                    jsonCollection = ODataQuerier.GetPagingCollection(ds.Entity, ds.Select, ds.Filter, ds.Orderby, ds.Skip, ds.Top, ds.Parameters);
                }
                else
                {
                    jsonCollection = ODataQuerier.GetPagingCollection(ds.Entity, ds.Select, ds.Filter, ds.Orderby, ds.Skip, ds.Top, ds.Expands, ds.Parameters);
                }
                string json = string.Format("[{0}]", string.Join(",", jsonCollection));

                int count = ODataQuerier.Count(ds.Entity, ds.Filter, ds.Parameters);
                json = string.Format("{{\"@count\":{0},\"value\":{1}}}", count, json);
                return(json);
            }
            else if (dataSource.GetType() == typeof(CollectionDataSource))
            {
                CollectionDataSource ds = dataSource as CollectionDataSource;

                IEnumerable <string> jsonCollection;
                if (ds.Expands == null || ds.Expands.Length == 0)
                {
                    jsonCollection = ODataQuerier.GetCollection(ds.Entity, ds.Select, ds.Filter, ds.Orderby, ds.Parameters);
                }
                else
                {
                    jsonCollection = ODataQuerier.GetCollection(ds.Entity, ds.Select, ds.Filter, ds.Orderby, ds.Expands, ds.Parameters);
                }
                return(string.Format("[{0}]", string.Join(",", jsonCollection)));
            }
            else if (dataSource.GetType() == typeof(DefaultGetterDataSource))
            {
                DefaultGetterDataSource ds = dataSource as DefaultGetterDataSource;
                return(ODataQuerier.GetDefault(dataSource.Entity, ds.Select));
            }
            else if (dataSource.GetType() == typeof(CountDataSource))
            {
                CountDataSource ds    = dataSource as CountDataSource;
                int             count = ODataQuerier.Count(ds.Entity, ds.Filter, ds.Parameters);
                return(string.Format("{{\"Count\": {0}}}", count));
            }

            throw new NotSupportedException(dataSource.GetType().ToString());
        }
        private void GraphicsLayer_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "Graphics")
            {
                GraphicsLayer graphicsLayer = sender as GraphicsLayer;
                // Resetting internal graphic collection and respective event handlers:
                UnregisterGraphicCollectionEventHandlers();
                currentGraphicCollection = (sender as GraphicsLayer).Graphics;
                RegisterGraphicCollectionEventHandlers();

                SetItemsSource((GraphicsLayer != null && GraphicsLayer.Graphics != null) ? (IList <Graphic>)GraphicsLayer.Graphics : new List <Graphic>());
                ResetLayout();
                // Restoring previously selected graphics (if any):
                if (GraphicsLayer != null)
                {
                    RestorePreviousSelection(GraphicsLayer.SelectedGraphics);
                }
            }
            else if (e.PropertyName == "SelectionCount")
            {
                if (!isSelectionChangedFromFeatureDataGrid && SelectedItems != null && SelectedGraphics != null)
                {
                    if (SelectedGraphics.Count == 0)
                    {
                        SelectedItems.Clear();
                    }
                    var selectedItemsCount = SelectedItems.Count;
                    for (int i = selectedItemsCount - 1; i >= 0; i--)
                    {
                        var g = DataSourceCreator.GetGraphicSibling(SelectedItems[i]);
                        if (!g.Selected)
                        {
                            SelectedItems.Remove(SelectedItems[i]);
                        }
                    }
                    foreach (var g in SelectedGraphics)
                    {
                        var r = GetCorrespondingGridRow(g);
                        if (r != null && !SelectedItems.Contains(r))
                        {
                            SelectedItems.Add(r);
                        }
                    }
                }
                ShowNumberOfRecords();
            }
            else if (e.PropertyName == "HasEdits")
            {
                SetSubmitButtonEnableState();
            }
        }
        /// <summary>
        /// Gets the corresponding row in <see cref="FeatureDataGrid"/> for the graphic.
        /// </summary>
        /// <param name="graphic">The graphic.</param>
        /// <returns></returns>
        private object GetCorrespondingGridRow(Graphic graphic)
        {
            if (graphic != null && ItemsSource != null)
            {
                foreach (var item in ItemsSource)
                {
                    if (DataSourceCreator.GetGraphicSibling(item) == graphic)
                    {
                        return(item);
                    }
                }
            }

            return(null);
        }
示例#5
0
        public void RegisterRoute(int dataSourceId, DataSourceCreator creator)
        {
            lock (_initLockObj)
            {
                bool alreadyExists = _routingTable.ContainsKey(dataSourceId);

                if (alreadyExists)
                {
                    string errorMsg = String.Format("Route for the data source with ID = {0} is already registered", dataSourceId);
                    throw new InvalidOperationException(errorMsg);
                }

                _routingTable.Add(dataSourceId, creator);
            }
        }
示例#6
0
        public DataSource RouteQuery(Model.ArticleQuery query)
        {
            int targetDsId = query.DataSourceId;
            DataSourceCreator dsCreator = null;

            if (_routingTable.TryGetValue(targetDsId, out dsCreator))
            {
                DataSource createdDs = dsCreator(query);
                return(createdDs);
            }
            else
            {
                string errorMsg = String.Format("Error when trying to route the request: System cannot find the data source with ID = {0}", targetDsId);
                throw new InvalidOperationException(errorMsg);
            }
        }
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Controls.DataGrid.RowEditEnded"/> event.
        /// </summary>
        /// <param name="e">The event data.</param>
        protected override void OnRowEditEnded(DataGridRowEditEndedEventArgs e)
        {
            base.OnRowEditEnded(e);

            if (e.EditAction == DataGridEditAction.Commit)
            {
                Graphic relatedGraphic = DataSourceCreator.GetGraphicSibling(e.Row.DataContext);
                if (relatedGraphic != null)
                {
                    try
                    {
                        e.Row.RefreshGraphic(relatedGraphic, objectType);
                    }
                    catch { }
                }
            }
        }
        private void DatePicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            bool       wasDatePickerDataContextNull = false;
            DatePicker datePicker = sender as DatePicker;

            if (datePicker != null && datePicker.DataContext == null)
            {
                wasDatePickerDataContextNull = true;
                datePicker.DataContext       = datePickerDataContext;
            }

            if (datePicker != null && datePicker.DataContext != null &&
                columnForCellBeingEdited != null && columnForCellBeingEdited != "")
            {
                try
                {
                    if (!e.AddedItems[0].Equals(datePicker.DataContext.GetType().GetProperty(columnForCellBeingEdited).GetValue(datePicker.DataContext, null)))
                    {
                        DataSourceCreator.SetProperty(e.AddedItems[0], datePicker.DataContext,
                                                      datePicker.DataContext.GetType().GetProperty(columnForCellBeingEdited));
                        Graphic correspondingGraphic = DataSourceCreator.GetGraphicSibling(datePicker.DataContext);
                        if (correspondingGraphic != null &&
                            correspondingGraphic.Attributes.ContainsKey(columnForCellBeingEdited))
                        {
                            // Unsubscribing from graphic's AttributeValueChanged event to manually refresh corresponding row:
                            correspondingGraphic.AttributeValueChanged -= Graphic_AttributeValueChanged;
                            DateTime?selectedDate = e.AddedItems[0] as DateTime?;
                            DateTime?dateToSet    = null;
                            if (selectedDate != null)
                            {
                                dateToSet = new DateTime(selectedDate.Value.Ticks, selectedDate.Value.Kind);
                            }
                            correspondingGraphic.Attributes[columnForCellBeingEdited] = dateToSet;
                            if (wasDatePickerDataContextNull)
                            {
                                correspondingGraphic.RefreshRow(ItemsSource, GetGraphicIndexInGraphicsCollection(correspondingGraphic), objectType);
                                datePickerDataContext = null;
                            }
                            // Subscribing back to the graphic's AttributeValueChanged event:
                            correspondingGraphic.AttributeValueChanged += Graphic_AttributeValueChanged;
                        }
                    }
                }
                catch { }
            }
        }
 private void GoToVisualState(Graphic graphic, string stateName)
 {
     if (rowsPresenter != null && rowsPresenter.Children != null)
     {
         foreach (UIElement element in rowsPresenter.Children)
         {
             DataGridRow row = element as DataGridRow;
             if (row != null)
             {
                 Graphic g = DataSourceCreator.GetGraphicSibling(row.DataContext);
                 if (graphic.Equals(g))
                 {
                     VisualStateManager.GoToState(row, stateName, true);
                     break;
                 }
             }
         }
     }
 }
 /// <summary>
 /// Raises the <see cref="E:System.Windows.Controls.DataGrid.CellEditEnded"/> event.
 /// </summary>
 /// <param name="e">The event data.</param>
 protected override void OnCellEditEnded(DataGridCellEditEndedEventArgs e)
 {
     if (e.EditAction == DataGridEditAction.Commit)
     {
         Field field = e.Column.GetValue(FieldColumnProperty) as Field;
         if (field != null && featureLayer != null && featureLayer.LayerInfo != null)
         {
             if (field.Domain is CodedValueDomain ||
                 featureLayer.LayerInfo.TypeIdField == field.Name ||
                 FieldDomainUtils.IsDynamicDomain(field, featureLayer.LayerInfo))
             {
                 // When cell edit ends update the graphic with the cell change.
                 var xObject = e.Row.DataContext;
                 var graphic = DataSourceCreator.GetGraphicSibling(xObject);
                 xObject.RefreshGraphic(graphic, xObject.GetType());
             }
         }
     }
     base.OnCellEditEnded(e);
 }
示例#11
0
        private void LoadData()
        {
            var app = (App)Application.Current;
            //加载数据
            var offset      = 0;    // long.Parse(this.textOffset.Text);
            var limit       = 2000; // long.Parse(this.textLimit.Text);
            var constraints = new object[][]
            {
                new object[] { "_id", "in", this.recordIds }
            };

            app.ClientService.SearchModel(this.modelName, constraints, null, offset, limit, (ids, error) =>
            {
                app.ClientService.ReadModel(this.modelName, ids, this.fields, (records, readError) =>
                {
                    //我们需要一个唯一的字符串型 ID
                    this.ItemsSource = DataSourceCreator.ToDataSource(records);
                });
            });
        }
        /// <summary>
        /// Selects/deselects related graphic objects in the GraphicsLayer
        /// when related grid rows have been selected/deselected by the user.
        /// </summary>
        /// <param name="rowsToLookup"></param>
        /// <param name="shouldSelectGraphics"></param>
        private void SelectGraphics(IList rowsToLookup, bool shouldSelectGraphics)
        {
            foreach (object objRow in rowsToLookup)
            {
                Graphic graphic = DataSourceCreator.GetGraphicSibling(objRow);
                if (graphic != null && GraphicsLayer != null && GraphicsLayer.Contains(graphic))
                {
                    graphic.Selected = shouldSelectGraphics;

                    if (shouldSelectGraphics)
                    {
                        currentRecordNumber = GetRowIndexInRowsCollection(objRow);
                    }
                    else
                    {
                        if (SelectedGraphics.Count == 0)
                        {
                            currentRecordNumber = -1;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Updates contents of the ItemsSource when FeatureDataGrid's associated graphic collection changes.
        /// </summary>
        /// <param name="sender">Observable collection of Graphic.</param>
        /// <param name="e">Collection changed event arguments.</param>
        private void UpdateItemsSource(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            IList newItems = e.NewItems;
            IList oldItems = e.OldItems;

            if (ItemsSource == null)
            {
                SetItemsSource(sender as ObservableCollection <Graphic>);
            }
            else
            {
                if ((ItemsSource as PagedCollectionView) != null)
                {
                    object currentItem = (ItemsSource as PagedCollectionView).CurrentItem;
                    if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Reset)
                    {
                        var features = (from object a in ItemsSource select DataSourceCreator.GetGraphicSibling(a));
                        newItems = (sender as ObservableCollection <Graphic>).Except(features).ToList();
                        oldItems = features.Except(sender as ObservableCollection <Graphic>).ToList();
                    }
                    if (newItems != null && newItems.Count > 0)                         // New item(s) added
                    {
                        bool shouldResetItemsSource = false;

                        IEnumerator enumItemsSource = ItemsSource.GetEnumerator();
                        if (enumItemsSource != null)
                        {
                            if (enumItemsSource.MoveNext())
                            {
                                if (!AllAttributesMatch(enumItemsSource.Current.GetType().GetProperties(), (newItems[0] as Graphic).Attributes))
                                {
                                    shouldResetItemsSource = true;
                                }
                            }
                            else
                            {
                                shouldResetItemsSource = true;
                            }
                        }

                        if (shouldResetItemsSource)
                        {
                            UnregisterGraphicCollectionEventHandlers();
                            SetItemsSource(sender as ObservableCollection <Graphic>);
                            IEnumerator enumAddedGraphics = newItems.GetEnumerator();
                            while (enumAddedGraphics.MoveNext())
                            {
                                Graphic graphic = enumAddedGraphics.Current as Graphic;
                                if (graphic != null)
                                {
                                    graphic.AttributeValueChanged += Graphic_AttributeValueChanged;
                                }
                            }
                        }
                        else
                        {
                            IEnumerator    enumAddedGraphics = newItems.GetEnumerator();
                            List <Graphic> selected          = GraphicsLayer.SelectedGraphics.ToList();
                            while (enumAddedGraphics.MoveNext())
                            {
                                Graphic graphic = enumAddedGraphics.Current as Graphic;
                                if (graphic != null)
                                {
                                    if (graphic.Selected)
                                    {
                                        selected.Add(graphic);
                                    }
                                    ItemsSource.AddToDataSource(featureLayerInfo, graphic, objectType);
                                    graphic.AttributeValueChanged += Graphic_AttributeValueChanged;
                                }
                            }
                            RestorePreviousSelection(selected);
                        }
                    }
                    if (oldItems != null && oldItems.Count > 0)                         // Item(s) removed
                    {
                        int selCount = SelectedItems.Count;
                        // In Silverlight removing a graphic from the GraphicsCollection causes to lose current
                        // selection in both GraphicsLayer and the FeatureDataGrid.
                        // Preserving selected items in the FeatureDataGrid:
                        List <Graphic> selItems = new List <Graphic>(selCount);
                        for (int i = 0; i < selCount; i++)
                        {
                            var row     = SelectedItems[i];
                            var graphic = DataSourceCreator.GetGraphicSibling(row);
                            selItems.Add(graphic);
                        }
                        IEnumerator enumRemovedGraphics = oldItems.GetEnumerator();
                        while (enumRemovedGraphics.MoveNext())
                        {
                            Graphic graphic          = enumRemovedGraphics.Current as Graphic;
                            int     idxInItemsSource = GetRowIndexInItemsSource(graphic);
                            if (graphic != null && idxInItemsSource > -1)
                            {
                                if (graphic != null)
                                {
                                    selItems.Remove(graphic);
                                }
                                ItemsSource.RemoveFromDataSource(idxInItemsSource, objectType);
                                // RemoveFromDataSource() method causes first item in the ItemsSource to be selected when there were no
                                // items selected in the data grid. We should avoid this selection by removing it from the selection:
                                if (selCount == 0 && SelectedItems.Count == 1)
                                {
                                    SelectedItems.Clear();
                                }
                                graphic.AttributeValueChanged -= Graphic_AttributeValueChanged;
                                SelectedGraphics.Remove(graphic);
                            }
                        }
                        RestorePreviousSelection(selItems);
                    }
                }
                else
                {
                    // If exiting ItemsSource is not a PagedCollectionView then it was empty before
                    // just populate it with everything in GraphicsLayer.
                    SetItemsSource((GraphicsLayer != null && GraphicsLayer.Graphics != null) ? (IList <Graphic>)GraphicsLayer.Graphics : new List <Graphic>());
                }
            }
            ShowNumberOfRecords();
        }
 /// <summary>
 /// Get a row from the FeatureDataGrid and returns the matching
 /// Graphic for the row.
 /// </summary>
 /// <param name="row">Row object from FeatureDataGrid.ItemsSource collection</param>
 /// <returns>Graphic that represented by a row object</returns>
 public Graphic GetGraphicFromRow(object row)
 {
     return(DataSourceCreator.GetGraphicSibling(row));
 }
 private bool AreEqual(object item, Graphic graphic)
 {
     return(graphic.Equals(DataSourceCreator.GetGraphicSibling(item)));
 }
示例#16
0
        public XElement Get()
        {
            DataSource dataSource = new DataSourceCreator(Name, KeyValues).Create();

            if (dataSource.GetType() == typeof(PagingDataSource))
            {
                PagingDataSource ds = dataSource as PagingDataSource;

                IEnumerable <XElement> xCollection;
                XElement xsd;
                if (ds.Expands == null || ds.Expands.Length == 0)
                {
                    xCollection = ODataQuerier.GetPagingCollection(ds.Entity, ds.Select, ds.Filter, ds.Orderby, ds.Skip, ds.Top, ds.Parameters, out xsd);
                }
                else
                {
                    xCollection = ODataQuerier.GetPagingCollection(ds.Entity, ds.Select, ds.Filter, ds.Orderby, ds.Skip, ds.Top, ds.Expands, ds.Parameters, out xsd);
                }
                string   collectionName = GetCollectionName(Schema, ds.Entity);
                XElement element        = new XElement(collectionName, xCollection);
                element.SetAttributeValue(XNamespace.Xmlns + "i", XSI);

                int count = ODataQuerier.Count(ds.Entity, ds.Filter, ds.Parameters);

                return(Pack(element, count, xsd));
            }
            else if (dataSource.GetType() == typeof(CollectionDataSource))
            {
                CollectionDataSource ds = dataSource as CollectionDataSource;

                IEnumerable <XElement> xCollection;
                XElement xsd;
                if (ds.Expands == null || ds.Expands.Length == 0)
                {
                    xCollection = ODataQuerier.GetCollection(ds.Entity, ds.Select, ds.Filter, ds.Orderby, ds.Parameters, out xsd);
                }
                else
                {
                    xCollection = ODataQuerier.GetCollection(ds.Entity, ds.Select, ds.Filter, ds.Orderby, ds.Expands, ds.Parameters, out xsd);
                }
                string   collection = GetCollectionName(Schema, ds.Entity);
                XElement element    = new XElement(collection, xCollection);
                element.SetAttributeValue(XNamespace.Xmlns + "i", XSI);

                return(Pack(element, null, xsd));
            }
            else if (dataSource.GetType() == typeof(DefaultGetterDataSource))
            {
                DefaultGetterDataSource ds = dataSource as DefaultGetterDataSource;
                XElement element           = ODataQuerier.GetDefault(dataSource.Entity, ds.Select, out XElement xsd);
                element.SetAttributeValue(XNamespace.Xmlns + "i", XSI);
                return(Pack(element, null, xsd));
            }
            else if (dataSource.GetType() == typeof(CountDataSource))
            {
                CountDataSource ds    = dataSource as CountDataSource;
                int             count = ODataQuerier.Count(ds.Entity, ds.Filter, ds.Parameters);
                return(new XElement("Count", count));
            }

            throw new NotSupportedException(dataSource.GetType().ToString());
        }