Exemple #1
0
        /// <summary>
        /// This function will create the server call in respond to different button click
        /// </summary>
        public void CallButtonClickEvent()
        {
            // Build up method element
            var methodElement = _controlHarness.MethodElement;

            ComposeMethodXml(methodElement);

            //inspect for Datacontext to set server context
            if (this.DataContext != null)
            {
                DynamicDataObject dynamicObject = this.DataContext as DynamicDataObject;
                string            contextKey    = dynamicObject["id"].ToString();
                string            myContextType = dynamicObject["type"].ToString();

                var elementList = new XElement[2];

                var contextElement = CreateRequestElement(Common.Requests.SetContext);
                contextElement.SetAttributeValue(Common.IDAttrib, contextKey);
                contextElement.SetAttributeValue(Common.Data.RowType, myContextType);
                contextElement.SetAttributeValue(Common.SetIdFromContextAttribute, "1");

                SetContextObject(contextElement);
                elementList[0] = contextElement;
                elementList[1] = methodElement;
                _controlHarness.SendXml(elementList);
            }
            else
            {
                _controlHarness.SendXml(methodElement);
            }
        }
        protected override void OnChecked(RoutedEventArgs e)
        {
            base.OnChecked(e);

            if (!dontUpdateValue && ParentPanel != null && DataContext != null)
            {
                DynamicDataObject data = (DynamicDataObject)DataContext;
                ParentPanel.UpdateSelectedValue(data["id"].ToString());
            }
        }
        private void RadioButtonPanelItem_Loaded(object sender, RoutedEventArgs e)
        {
            if (ParentPanel != null && DataContext != null)
            {
                DynamicDataObject data = (DynamicDataObject)DataContext;

                if (ParentPanel.SelectedValue == data["id"].ToString())
                {
                    dontUpdateValue = true;
                    this.IsChecked  = true;
                    dontUpdateValue = false;
                }
            }
        }
Exemple #4
0
        protected void SendContextToServer(bool setContextID, string action)
        {
            //TODO Clean up or delete
            //setCurrentContext();

            string contextKey    = null;
            string myContextType = null;

            if (this.SelectedItem != null)
            {
                DynamicDataObject dynamicObject = this.SelectedItem as DynamicDataObject;
                contextKey    = dynamicObject[Common.IDAttrib].ToString();
                myContextType = dynamicObject[Common.Data.RowType].ToString();
            }

            var elementList = new XElement[2];

            var contextElement = CreateRequestElement(Common.Requests.SetContext);

            contextElement.SetAttributeValue(Common.IDAttrib, contextKey);
            contextElement.SetAttributeValue(Common.Data.RowType, myContextType);

            //if (setContextID)
            contextElement.SetAttributeValue(Common.Data.SetIdFromContext, "1");

            XElement actionElement = CreateRequestElement(Common.Requests.MenuAction);

            if (string.IsNullOrEmpty(action))
            {
                actionElement.SetAttributeValue(Common.DefaultAction, "1");
            }
            else
            {
                actionElement.SetAttributeValue(Common.MenuAction, action);
            }

            SetContextObject(contextElement);
            SetContextObject(actionElement);
            elementList[0] = contextElement;
            elementList[1] = actionElement;
            _controlHarness.SendXml(elementList);

            if (ContextChanging != null)
            {
                ContextChanging(this, new EventArgs());
            }
        }
        private List <DynamicDataObject> GetCollectionFromData(XElement data)
        {
            List <DynamicDataObject> collection = new List <DynamicDataObject>();

            try
            {
                // Get Definition references
                var columnDefintions = data.Element(Common.Data.Columns);
                var rows             = data.Element(Common.Data.Rows);

                //Server has nulled the data, exit
                if (rows == null || columnDefintions == null)
                {
                    return(collection);
                }

                //Process Rows
                var rowNode = rows.FirstNode as XElement;

                while (rowNode != null)
                {
                    if (rowNode is XElement)
                    {
                        var rowData = rowNode;

                        // Create dynamic object instance to build up
                        var dataObject = new DynamicDataObject();
                        dataObject[Common.IDAttrib]     = rowNode.Attribute(Common.IDAttrib).Value;
                        dataObject[Common.Data.RowType] = rowNode.Attribute(Common.Data.RowType).Value;

                        // Add dynamic object properties based on cell definition
                        XElement columnDef = (XElement)columnDefintions.FirstNode;

                        while (columnDef != null)
                        {
                            string cellid = columnDef.Attribute(Common.IDAttrib).Value;
                            string field  = columnDef.Attribute(Common.Data.ColumnField).Value;

                            if (!string.IsNullOrEmpty(field))
                            {
                                //string value = rowData.Element("Cell" + cellid).Value;
                                string value = rowData.Elements("Cell").Where(x => x.Attribute(Common.IDAttrib).Value == cellid).FirstOrDefault().Value;

                                // Create property and assign value
                                dataObject[field.Replace('.', '_')] = value;
                            }

                            columnDef = (XElement)columnDef.NextNode;
                        }

                        // Add to the collection
                        collection.Add(dataObject);
                    }
                    rowNode = rowNode.NextNode as XElement;
                }
            }
            finally
            {
            }

            return(collection);
        }
Exemple #6
0
        protected override void Handle(ActionExecutingContext context, ObjectResult result)
        {
            if (!ResultValueIsEnumerable || !ResultValueCount.HasValue)
            {
                return;
            }

            if (!_globalPaths && !_onlyForThesePaths.Any(p => p.EqualsEx(context.HttpContext.Request.Path)))
            {
                return;
            }

            // Im tired, but i can not see WHY when doing it this way, camelcasing does not occur on anthying added.
            //////var dynamicResult = new DynamicDataObject();
            //////var token = JToken.FromObject(result.Value);

            //////if (token is JObject t)
            //////    foreach (var p in t.Properties())
            //////        dynamicResult.AddProperty(p.Name, p.Value.ToString());
            //////else
            //////    throw new FormatException("Reuslts must have a root property, somthing like d => new { Data = myResults }.");

            //////dynamicResult.AddProperty(
            //////    "Pagination",
            //////    _paginationBuilder.Build(ResultValueCount.Value, context)
            //////);

            //////result.Value = dynamicResult;

            //////var value = result.Value;
            //////var type = value.GetType();
            //////var prop = type.GetProperties().First();
            //////var dynamicResult = new DynamicDataObject();
            //////var propValue = prop.GetValue(value);

            //////dynamicResult.AddProperty(prop.Name, propValue).AddProperty(
            //////    "Pagination",
            //////    _paginationBuilder.Build(ResultValueCount.Value, context)
            //////);

            //////result.Value = dynamicResult;

            var value         = result.Value;
            var type          = value.GetType();
            var props         = type.GetProperties();
            var dynamicResult = new DynamicDataObject();

            foreach (var pi in props)
            {
                var propValue = pi.GetValue(value);

                dynamicResult.AddProperty(pi.Name, propValue);
            }

            dynamicResult.AddProperty(
                "Pagination",
                _paginationBuilder.Build(ResultValueCount.Value, context)
                );

            result.Value = dynamicResult;
        }
Exemple #7
0
        public void PublishData(XElement data)
        {
            List <DynamicDataObject> collection = new List <DynamicDataObject>();

            _isPublishing = true;

            try
            {
                //Clear existing
                collection.Clear();

                // Get Definition references
                var columnDefintions = data.Element(Common.Data.Columns);
                var rows             = data.Element(Common.Data.Rows);

                //Server has nulled the data, exit
                if (rows == null || columnDefintions == null)
                {
                    this.View = new GridView();
                    return;
                }

                var gridView = new GridView();

                XElement columnDef = (XElement)columnDefintions.FirstNode;

                while (columnDef != null)
                {
                    var column = new GridViewColumn();
                    column.Header = columnDef.GetAttributeValue(Common.Data.ColumnLabel);

                    string propertyName = MapColumnToProperty(columnDef);
                    string bindingPath  = string.Format(propertyName, "[{0}]");
                    column.DisplayMemberBinding = new Binding(bindingPath);

                    string columnWidthString = columnDef.GetAttributeValue(Common.Data.ColumnWidth);
                    int    columnWidth       = 100;
                    int.TryParse(columnWidthString, out columnWidth);
                    if (columnWidth < 0)
                    {
                        columnWidth = 100;
                    }
                    column.Width = columnWidth;

                    gridView.Columns.Add(column);

                    columnDef = (XElement)columnDef.NextNode;
                }

                this.View = gridView;

                //Process Rows
                var rowNode = rows.FirstNode as XElement;

                while (rowNode != null)
                {
                    if (rowNode is XElement)
                    {
                        var rowData = (XElement)rowNode;

                        // Create dynamic object instance to build up
                        var dataObject = new DynamicDataObject();
                        dataObject[Common.IDAttrib]     = rowNode.Attribute(Common.IDAttrib).Value;
                        dataObject[Common.Data.RowType] = rowNode.Attribute(Common.Data.RowType).Value;

                        // Add dynamic object properties based on cell definition
                        XElement cell = (XElement)columnDefintions.FirstNode;

                        while (cell != null)
                        {
                            string cellid = cell.Attribute(Common.IDAttrib).Value;
                            string field  = MapColumnToProperty(cell);

                            //string value = rowData.Element("Cell" + cellid).Value;
                            string value = rowData.Elements("Cell").Where(x => x.Attribute(Common.IDAttrib).Value == cellid).FirstOrDefault().Value;

                            // Create property and assign value
                            dataObject[field] = value;

                            cell = (XElement)cell.NextNode;
                        }

                        // Add to the collection
                        collection.Add(dataObject);
                    }
                    rowNode = rowNode.NextNode as XElement;
                }
            }
            finally
            {
                //lastKey = null;
                SelectedIndex = -1;
                _isPublishing = false;
            }

            // Set the local data source
            this.ItemsSource = collection;
        }
        private List<DynamicDataObject> GetCollectionFromData(XElement data)
        {
            List<DynamicDataObject> collection = new List<DynamicDataObject>();

            try
            {
                // Get Definition references
                var columnDefintions = data.Element(Common.Data.Columns);
                var rows = data.Element(Common.Data.Rows);

                //Server has nulled the data, exit
                if (rows == null || columnDefintions == null)
                    return collection;

                //Process Rows
                var rowNode = rows.FirstNode as XElement;

                while (rowNode != null)
                {
                    if (rowNode is XElement)
                    {
                        var rowData = rowNode;

                        // Create dynamic object instance to build up
                        var dataObject = new DynamicDataObject();
                        dataObject[Common.IDAttrib] = rowNode.Attribute(Common.IDAttrib).Value;
                        dataObject[Common.Data.RowType] = rowNode.Attribute(Common.Data.RowType).Value;

                        // Add dynamic object properties based on cell definition
                        XElement columnDef = (XElement)columnDefintions.FirstNode;

                        while (columnDef != null)
                        {
                            string cellid = columnDef.Attribute(Common.IDAttrib).Value;
                            string field = columnDef.Attribute(Common.Data.ColumnField).Value;

                            if (!string.IsNullOrEmpty(field))
                            {
                                //string value = rowData.Element("Cell" + cellid).Value;
                                string value = rowData.Elements("Cell").Where(x => x.Attribute(Common.IDAttrib).Value == cellid).FirstOrDefault().Value;

                                // Create property and assign value
                                dataObject[field.Replace('.', '_')] = value;
                            }

                            columnDef = (XElement)columnDef.NextNode;
                        }

                        // Add to the collection
                        collection.Add(dataObject);
                    }
                    rowNode = rowNode.NextNode as XElement;
                }
            }
            finally
            {
            }

            return collection;
        }
Exemple #9
0
        private List <DynamicDataObject> ConvertPublicationToCollection(XElement data)
        {
            List <DynamicDataObject> collection = new List <DynamicDataObject>();

            try
            {
                // Get Definition references
                var columnDefintions = data.Element(Common.Data.Columns);
                var rows             = data.Element(Common.Data.Rows);

                //Server has nulled the data, exit
                if (rows == null || columnDefintions == null)
                {
                    return(collection);
                }

                //Process Rows
                var rowNode = rows.FirstNode as XElement;

                while (rowNode != null)
                {
                    if (rowNode is XElement)
                    {
                        var rowData = rowNode;

                        // Create dynamic object instance to build up
                        var dataObject = new DynamicDataObject();
                        dataObject[Common.IDAttrib]     = rowNode.Attribute(Common.IDAttrib).Value;
                        dataObject[Common.Data.RowType] = rowNode.Attribute(Common.Data.RowType).Value;

                        // Add dynamic object properties based on cell definition
                        XElement columnDef = (XElement)columnDefintions.FirstNode;

                        while (columnDef != null)
                        {
                            string cellid = columnDef.Attribute(Common.IDAttrib).Value;
                            string field  = null; // columnDef.GetAttributeValue(Common.Data.ColumnField);

                            if (string.IsNullOrEmpty(field))
                            {
                                field = "__CELL" + cellid;
                            }

                            //string value = rowData.Element("Cell" + cellid).Value;
                            string value = rowData.Elements("Cell").Where(x => x.Attribute(Common.IDAttrib).Value == cellid).FirstOrDefault().Value;

                            // Create property and assign value
                            string propertyName = field.Replace('.', '_');

                            if (columnDef.GetAttributeValue(Common.Datatypes.AttribName) == Common.Datatypes.Boolean)
                            {
                                dataObject[propertyName] = Common.boolValue(value);
                            }
                            else
                            {
                                dataObject[propertyName] = value;
                            }

                            columnDef = (XElement)columnDef.NextNode;
                        }

                        // Add to the collection
                        collection.Add(dataObject);
                    }
                    rowNode = rowNode.NextNode as XElement;
                }
            }
            catch { }

            return(collection);
        }
        public void PublishData(XElement data)
        {
            List<DynamicDataObject> collection = new List<DynamicDataObject>();

            _isPublishing = true;

            try
            {
                //Clear existing
                collection.Clear();

                // Get Definition references
                var columnDefintions = data.Element(Common.Data.Columns);
                var rows = data.Element(Common.Data.Rows);

                //Server has nulled the data, exit
                if (rows == null || columnDefintions == null)
                {
                    this.View = new GridView();
                    return;
                }

                var gridView = new GridView();

                XElement columnDef = (XElement)columnDefintions.FirstNode;

                while (columnDef != null)
                {
                    var column = new GridViewColumn();
                    column.Header = columnDef.GetAttributeValue(Common.Data.ColumnLabel);

                    string propertyName = MapColumnToProperty(columnDef);
                    string bindingPath = string.Format(propertyName, "[{0}]");
                    column.DisplayMemberBinding = new Binding(bindingPath);

                    string columnWidthString = columnDef.GetAttributeValue(Common.Data.ColumnWidth);
                    int columnWidth = 100;
                    int.TryParse(columnWidthString, out columnWidth);
                    if (columnWidth < 0) columnWidth = 100;
                    column.Width = columnWidth;

                    gridView.Columns.Add(column);

                    columnDef = (XElement)columnDef.NextNode;
                }

                this.View = gridView;

                //Process Rows
                var rowNode = rows.FirstNode as XElement;

                while (rowNode != null)
                {
                    if (rowNode is XElement)
                    {
                        var rowData = (XElement)rowNode;

                        // Create dynamic object instance to build up
                        var dataObject = new DynamicDataObject();
                        dataObject[Common.IDAttrib] = rowNode.Attribute(Common.IDAttrib).Value;
                        dataObject[Common.Data.RowType] = rowNode.Attribute(Common.Data.RowType).Value;

                        // Add dynamic object properties based on cell definition
                        XElement cell = (XElement)columnDefintions.FirstNode;

                        while (cell != null)
                        {
                            string cellid = cell.Attribute(Common.IDAttrib).Value;
                            string field = MapColumnToProperty(cell);

                            //string value = rowData.Element("Cell" + cellid).Value;
                            string value = rowData.Elements("Cell").Where(x => x.Attribute(Common.IDAttrib).Value == cellid).FirstOrDefault().Value;

                            // Create property and assign value
                            dataObject[field] = value;

                            cell = (XElement)cell.NextNode;
                        }

                        // Add to the collection
                        collection.Add(dataObject);
                    }
                    rowNode = rowNode.NextNode as XElement;
                }
            }
            finally
            {
                //lastKey = null;
                SelectedIndex = -1;
                _isPublishing = false;
            }

            // Set the local data source
            this.ItemsSource = collection;
        }