Exemplo n.º 1
0
        }//UpdateBalanceData()


        public static void listConnectedBalances( ICswResources CswResources, CswNbtBalanceReturn Return, object Request )
        {

            CswNbtResources NbtResources = (CswNbtResources) CswResources;
            Return.Data.BalanceList = new Collection<SerialBalance>();


            CswNbtMetaDataObjectClass BalanceOC = NbtResources.MetaData.getObjectClass( CswEnumNbtObjectClass.BalanceClass );
            if( null != BalanceOC )
            {

                CswNbtView ExistingBalancesView = new CswNbtView( NbtResources );
                ExistingBalancesView.ViewName = "Connected Balances";
                CswNbtViewRelationship BalanceRel = ExistingBalancesView.AddViewRelationship( BalanceOC, true );
                //only add to the list of returned balances if it has had an announcement in the last 11 minutes
                ExistingBalancesView.AddViewPropertyAndFilter( BalanceRel, BalanceOC.getObjectClassProp( CswNbtObjClassBalance.PropertyName.LastActive ),
                                        SubFieldName: CswEnumNbtSubFieldName.Value,
                                        Value: DateTime.Now.Subtract( TimeSpan.FromMinutes( 11 ) ).ToString(),
                                        FilterMode: CswEnumNbtFilterMode.GreaterThan );

                //only add to the list of returned balances if it is Operational
                ExistingBalancesView.AddViewPropertyAndFilter( BalanceRel, BalanceOC.getObjectClassProp( CswNbtObjClassBalance.PropertyName.Operational ),
                                        SubFieldName: CswEnumNbtSubFieldName.Checked,
                                        Value: CswEnumTristate.True,
                                        FilterMode: CswEnumNbtFilterMode.Equals );

                ExistingBalancesView.AddViewPropertyAndFilter( BalanceRel, BalanceOC.getObjectClassProp( CswNbtObjClassBalance.PropertyName.Quantity ),
                                        SubFieldName: CswEnumNbtSubFieldName.Value,
                                        Value: "0",
                                        FilterMode: CswEnumNbtFilterMode.NotEquals );

                ICswNbtTree BalanceTree = NbtResources.Trees.getTreeFromView( ExistingBalancesView, true, false, false );
                int BalanceCount = BalanceTree.getChildNodeCount();
                if( BalanceCount > 0 )
                {
                    BalanceTree.goToRoot();
                    for( int i = 0; i < BalanceCount; i++ )
                    {
                        BalanceTree.goToNthChild( i );
                        CswNbtObjClassBalance Balance = BalanceTree.getCurrentNode();

                        Return.Data.BalanceList.Add( new SerialBalance
                        {
                            NbtName = Balance.Name.Text,
                            CurrentWeight = Balance.Quantity.Quantity,
                            UnitOfMeasurement = Balance.Quantity.CachedUnitName,
                            NodeId = Balance.NodeId.ToString(),
                            IsActive = ( Balance.LastActive.DateTimeValue + TimeSpan.FromMinutes( 10 ) > DateTime.Now ),
                        } );

                        BalanceTree.goToParentNode();

                    } //for ( int i = 0; i < BalanceCount; i++ )
                } //if( BalanceCount > 0 )

            } //if ( null != BalanceOC )
        }//listConnectedBalances( ICswResources CswResources, CswNbtBalanceReturn Return, object Request )
Exemplo n.º 2
0
        } // registerBalanceConfiguration()




        public static void getBalanceInformation( ICswResources CswResources, CswNbtBalanceReturn Return, string Request )
        {

            CswNbtResources NbtResources = (CswNbtResources) CswResources;
            Return.Data.BalanceList = new Collection<SerialBalance>();
            CswPrimaryKey BalanceKey = new CswPrimaryKey();
            BalanceKey.FromString( Request );


            CswNbtObjClassBalance Balance = NbtResources.Nodes[BalanceKey];

            Return.Data.BalanceList.Add( new SerialBalance
            {
                NbtName = Balance.Name.Text,
                CurrentWeight = Balance.Quantity.Quantity,
                UnitOfMeasurement = Balance.Quantity.CachedUnitName,
                NodeId = Balance.NodeId.ToString(),
                IsActive = (Balance.LastActive.DateTimeValue + TimeSpan.FromMinutes(10) > DateTime.Now),
            } );


        }//getBalanceInformation( ICswResources CswResources, CswNbtBalanceReturn Return, string Request )
Exemplo n.º 3
0
        public static void UpdateBalanceData( ICswResources CswResources, SerialBalance Return, SerialBalance Request )
        {

            CswNbtResources NbtResources = (CswNbtResources) CswResources;

            CswNbtMetaDataObjectClass BalanceOC = NbtResources.MetaData.getObjectClass( CswEnumNbtObjectClass.BalanceClass );
            if( null != BalanceOC )
            {
                CswNbtMetaDataObjectClassProp BalanceNameOCP = BalanceOC.getObjectClassProp( CswNbtObjClassBalance.PropertyName.Name );
                CswNbtObjClassBalance Balance;


                Action<CswNbtNode> UpdateBalance = delegate( CswNbtNode NewNode )
                {
                    CswNbtObjClassBalance thisBalance = NewNode;
                    thisBalance.Name.Text = Request.NbtName;
                    thisBalance.Quantity.Quantity = Request.CurrentWeight;
                    thisBalance.LastActive.DateTimeValue = DateTime.Now;
                    thisBalance.Device.Text = Request.DeviceDescription;
                    thisBalance.Manufacturer.Text = Request.Manufacturer;
                    thisBalance.Operational.Checked = CswConvert.ToTristate( Request.Operational );
                    thisBalance.BalanceConfiguration.RelatedNodeId = _findConfigurationWithName( NbtResources, Request.Configuration ).NodeId;

                    CswNbtObjClassUnitOfMeasure Unit = _mapUnitToNode( NbtResources, Request.UnitOfMeasurement );

                    if( null != Unit )
                    {
                        thisBalance.Quantity.UnitId = Unit.NodeId;
                    }
                };


                if( string.IsNullOrEmpty(Request.NodeId) )
                {
                    CswNbtView ExistingBalancesView = new CswNbtView( NbtResources );
                    ExistingBalancesView.ViewName = "Existing Balances";
                    CswNbtViewRelationship BalanceRel = ExistingBalancesView.AddViewRelationship( BalanceOC, false );
                    ExistingBalancesView.AddViewPropertyAndFilter( BalanceRel, BalanceNameOCP,
                                                                   Value: Request.NbtName,
                                                                   FilterMode: CswEnumNbtFilterMode.Equals );
                    ICswNbtTree ExistingBalancesTree = NbtResources.Trees.getTreeFromView( ExistingBalancesView, false, true, true );


                    if( ExistingBalancesTree.getChildNodeCount() == 0 )
                    {
                        //there is no balance with this name yet. Make a new one.
                        CswNbtMetaDataNodeType BalanceNT = BalanceOC.FirstNodeType;
                        Balance = NbtResources.Nodes.makeNodeFromNodeTypeId( BalanceNT.NodeTypeId, UpdateBalance );
                    }
                    else
                    {
                        //this balance already exists, grab a reference to it.
                        ExistingBalancesTree.goToNthChild( 0 );
                        Balance = ExistingBalancesTree.getCurrentNode();
                        UpdateBalance( Balance.Node );
                        Balance.postChanges( false );

                    }
                }//if null == request.nodeid
                else
                {
                    Balance = NbtResources.Nodes[new CswPrimaryKey( "nodes", Convert.ToInt32( Request.NodeId ) )];
                    UpdateBalance( Balance.Node );
                    Balance.postChanges( false );
                }

                //return the requested balance back, plus what nodeId it was assigned
                Return = Request;
                Return.NodeId = Balance.NodeId.PrimaryKey.ToString();

            }//if ( null != BalanceOC )

        }//UpdateBalanceData()