Exemplo n.º 1
0
    private static async Task MainAsync()
    {
        // Initialize logging with the default configuration
        Logging.Configure(
            new LoggingConfig(),
            new TestLogger()
            );

        using (var runtime = new Runtime(new RuntimeConfig {
            NumCoreThreads = 4
        }))
        {
            using (var server = new TcpServer(runtime, LinkErrorMode.Close, "127.0.0.1:20000"))
            {
                // ANCHOR: outstation_config
                // create an outstation configuration with default values
                var config = new OutstationConfig(
                    // outstation address
                    1024,
                    // master address
                    1
                    );
                // override the default application decoding level
                config.DecodeLevel.Application = AppDecodeLevel.ObjectValues;
                // ANCHOR_END: outstation_config

                var application    = new TestOutstationApplication();
                var information    = new TestOutstationInformation();
                var controlHandler = new TestControlHandler();
                var addressFilter  = AddressFilter.Any();
                var outstation     = server.AddOutstation(config, EventBufferConfig.AllTypes(10), application, information, controlHandler, addressFilter);

                // Setup initial points
                outstation.Transaction(new OutstationTransaction((db) =>
                {
                    for (ushort i = 0; i < 10; i++)
                    {
                        db.AddBinary(i, EventClass.Class1, new BinaryConfig());
                        db.AddDoubleBitBinary(i, EventClass.Class1, new DoubleBitBinaryConfig());
                        db.AddBinaryOutputStatus(i, EventClass.Class1, new BinaryOutputStatusConfig());
                        db.AddCounter(i, EventClass.Class1, new CounterConfig());
                        db.AddFrozenCounter(i, EventClass.Class1, new FrozenCounterConfig());
                        db.AddAnalog(i, EventClass.Class1, new AnalogConfig());
                        db.AddAnalogOutputStatus(i, EventClass.Class1, new AnalogOutputStatusConfig());
                        db.AddOctetString(i, EventClass.Class1);

                        var restart = new Flags(Flag.Restart);
                        db.UpdateBinary(new Binary(i, false, restart, Timestamp.InvalidTimestamp()), new UpdateOptions());
                        db.UpdateDoubleBitBinary(new DoubleBitBinary(i, DoubleBit.Indeterminate, restart, Timestamp.InvalidTimestamp()), new UpdateOptions());
                        db.UpdateBinaryOutputStatus(new BinaryOutputStatus(i, false, restart, Timestamp.InvalidTimestamp()), new UpdateOptions());
                        db.UpdateCounter(new Counter(i, 0, restart, Timestamp.InvalidTimestamp()), new UpdateOptions());
                        db.UpdateFrozenCounter(new FrozenCounter(i, 0, restart, Timestamp.InvalidTimestamp()), new UpdateOptions());
                        db.UpdateAnalog(new Analog(i, 0.0, restart, Timestamp.InvalidTimestamp()), new UpdateOptions());
                        db.UpdateAnalogOutputStatus(new AnalogOutputStatus(i, 0.0, restart, Timestamp.InvalidTimestamp()), new UpdateOptions());
                    }
                }));

                // Start the outstation
                server.Bind();

                var binaryValue             = false;
                var doubleBitBinaryValue    = DoubleBit.DeterminedOff;
                var binaryOutputStatusValue = false;
                var counterValue            = (uint)0;
                var frozenCounterValue      = (uint)0;
                var analogValue             = 0.0;
                var analogOutputStatusValue = 0.0;

                while (true)
                {
                    switch (await GetInputAsync())
                    {
                    case "x":
                        return;

                    case "bi":
                    {
                        outstation.Transaction(new OutstationTransaction((db) =>
                            {
                                binaryValue = !binaryValue;
                                db.UpdateBinary(new Binary(7, binaryValue, new Flags(Flag.Online), Timestamp.SynchronizedTimestamp(0)), new UpdateOptions());
                            }));
                        break;
                    }

                    case "dbbi":
                    {
                        outstation.Transaction(new OutstationTransaction((db) =>
                            {
                                doubleBitBinaryValue = doubleBitBinaryValue == DoubleBit.DeterminedOff ? DoubleBit.DeterminedOn : DoubleBit.DeterminedOff;
                                db.UpdateDoubleBitBinary(new DoubleBitBinary(7, doubleBitBinaryValue, new Flags(Flag.Online), Timestamp.SynchronizedTimestamp(0)), new UpdateOptions());
                            }));
                        break;
                    }

                    case "bos":
                    {
                        outstation.Transaction(new OutstationTransaction((db) =>
                            {
                                binaryOutputStatusValue = !binaryOutputStatusValue;
                                db.UpdateBinaryOutputStatus(new BinaryOutputStatus(7, binaryOutputStatusValue, new Flags(Flag.Online), Timestamp.SynchronizedTimestamp(0)), new UpdateOptions());
                            }));
                        break;
                    }

                    case "co":
                    {
                        outstation.Transaction(new OutstationTransaction((db) =>
                            {
                                db.UpdateCounter(new Counter(7, ++counterValue, new Flags(Flag.Online), Timestamp.SynchronizedTimestamp(0)), new UpdateOptions());
                            }));
                        break;
                    }

                    case "fco":
                    {
                        outstation.Transaction(new OutstationTransaction((db) =>
                            {
                                db.UpdateFrozenCounter(new FrozenCounter(7, ++frozenCounterValue, new Flags(Flag.Online), Timestamp.SynchronizedTimestamp(0)), new UpdateOptions());
                            }));
                        break;
                    }

                    case "ai":
                    {
                        outstation.Transaction(new OutstationTransaction((db) =>
                            {
                                db.UpdateAnalog(new Analog(7, ++analogValue, new Flags(Flag.Online), Timestamp.SynchronizedTimestamp(0)), new UpdateOptions());
                            }));
                        break;
                    }

                    case "aos":
                    {
                        outstation.Transaction(new OutstationTransaction((db) =>
                            {
                                db.UpdateAnalogOutputStatus(new AnalogOutputStatus(7, ++analogOutputStatusValue, new Flags(Flag.Online), Timestamp.SynchronizedTimestamp(0)), new UpdateOptions());
                            }));
                        break;
                    }

                    case "os":
                    {
                        outstation.Transaction(new OutstationTransaction((db) =>
                            {
                                db.UpdateOctetString(7, System.Text.Encoding.ASCII.GetBytes("Hello"), new UpdateOptions());
                            }));
                        break;
                    }

                    default:
                        Console.WriteLine("Unknown command");
                        break;
                    }
                }
            }
        }
    }
Exemplo n.º 2
0
		public AddressCompletionAdapter (Context context)
		{
			this.context = context;
			this.filter = new AddressFilter (context, this);
		}
Exemplo n.º 3
0
        public FilterBuilder WithAddress(Address address)
        {
            _address = new AddressFilter(address);

            return(this);
        }
Exemplo n.º 4
0
        public FilterBuilder WithAddresses(params Address[] addresses)
        {
            _address = new AddressFilter(addresses.ToHashSet());

            return(this);
        }
 public void List(AddressFilter filter, IParser parser)
 {
     addressDAL.List(filter, parser);
 }
 public void Get(AddressFilter filter, IParser parser)
 {
     addressDAL.Get(filter, parser);
 }
Exemplo n.º 7
0
 public Address Find(AddressFilter filter)
 {
     return(Set.FirstOrDefault(d => d.Id == filter.Id));
 }
Exemplo n.º 8
0
        public FilterBuilder WithAddresses(IEnumerable <Address> addresses)
        {
            _address = new AddressFilter(addresses.ToHashSet());

            return(this);
        }
        public async Task <IActionResult> GetAddressList([Required][FromQuery] AddressFilter filter, CancellationToken token)
        {
            var result = await queries.GetAddressAsync(filter, token);

            return(GenerateResponse(result));
        }
Exemplo n.º 10
0
        public async Task <IActionResult> OnGetAsync(string sortOrder, int?pageNumber)
        {
            AddressFilter filter = new AddressFilter();

            CurrentSort       = sortOrder;
            ZipCodeSort       = string.IsNullOrEmpty(sortOrder) ? "zip_desc" : "";
            CitySort          = sortOrder == "City" ? "city_desc" : "City";
            StreetAddressSort = sortOrder == "Street" ? "street_desc" : "Street";
            NameSort          = sortOrder == "Name" ? "name_desc" : "Name";

            filter.PageNumber = pageNumber ?? 0;
            filter.Active     = true;
            if (HttpContext.User.Identity.IsAuthenticated)
            {
                var user = await _userManager.GetUserAsync(HttpContext.User);

                if (_userManager.IsInRoleAsync(user, "Administrators").Result || _userManager.IsInRoleAsync(user, "Assistant").Result)
                {
                    filter.Active = false;
                }
            }

            switch (sortOrder)
            {
            case "zip_desc":
                filter.addressOrder = AddressFilter.AddressOrder.ZipCodeDescending;
                break;

            case "city_desc":
                filter.addressOrder = AddressFilter.AddressOrder.CityDescending;
                break;

            case "City":
                filter.addressOrder = AddressFilter.AddressOrder.CityAscending;
                break;

            case "street_desc":
                filter.addressOrder = AddressFilter.AddressOrder.StreetAddressDescending;
                break;

            case "Street":
                filter.addressOrder = AddressFilter.AddressOrder.StreetAddressAscending;
                break;

            case "name_desc":
                filter.addressOrder = AddressFilter.AddressOrder.NameDescending;
                break;

            case "Name":
                filter.addressOrder = AddressFilter.AddressOrder.NameAscending;
                break;

            case "":
                filter.addressOrder = AddressFilter.AddressOrder.ZipCodeAscending;
                break;

            default:
                filter.addressOrder = AddressFilter.AddressOrder.ZipCodeAscending;
                break;
            }

            _logger.LogInformation(LoggingEvents.ListItems, "List Addresses");
            Addresses = await _addressService.GetAddresses(filter);

            return(Page());
        }
Exemplo n.º 11
0
 extern public static void SetAddressFilteringMode(AddressFilter mode);
Exemplo n.º 12
0
 /// <summary>
 /// 分页查询Address信息
 /// </summary>
 public static QueryResult <Address> QueryAddressList(AddressFilter filter)
 {
     return(AddressDA.QueryAddressList(filter));
 }
Exemplo n.º 13
0
        public async Task <PagedResult <AddressDto> > GetAddresses(AddressFilter filter)
        {
            if (filter == null)
            {
                filter = new AddressFilter();
            }

            if (filter?.PageSize < 0)
            {
                filter.PageSize = null;
            }
            if (filter?.PageNumber < 0)
            {
                filter.PageNumber = null;
            }

            IQueryable <Address> addresses = _dbContext.Addresses;

            if (filter.Active)
            {
                addresses = addresses.Where(a => a.IsInUse == true);
            }

            switch (filter.addressOrder)
            {
            case AddressFilter.AddressOrder.ZipCodeAscending:
                addresses = addresses.OrderBy(a => a.ZipCode);
                break;

            case AddressFilter.AddressOrder.ZipCodeDescending:
                addresses = addresses.OrderByDescending(a => a.ZipCode);
                break;

            case AddressFilter.AddressOrder.CityAscending:
                addresses = addresses.OrderBy(a => a.City);
                break;

            case AddressFilter.AddressOrder.CityDescending:
                addresses = addresses.OrderByDescending(a => a.City);
                break;

            case AddressFilter.AddressOrder.StreetAddressAscending:
                addresses = addresses.OrderBy(a => a.StreetAddress);
                break;

            case AddressFilter.AddressOrder.StreetAddressDescending:
                addresses = addresses.OrderByDescending(a => a.StreetAddress);
                break;

            case AddressFilter.AddressOrder.NameAscending:
                addresses = addresses.OrderBy(a => a.Name);
                break;

            case AddressFilter.AddressOrder.NameDescending:
                addresses = addresses.OrderByDescending(a => a.Name);
                break;

            default:
                addresses = addresses.OrderBy(a => a.ZipCode);
                break;
            }

            int?Total = null;

            if (((filter?.PageSize) ?? 0) != 0)
            {
                filter.PageNumber = filter.PageNumber ?? 0;
                Total             = addresses.Count();
                addresses         = addresses.Skip(filter.PageNumber.Value * filter.PageSize.Value).Take(filter.PageSize.Value);
            }

            var results = await addresses
                          .Select(AddressDtoSelector)
                          .ToListAsync();

            return(new PagedResult <AddressDto>
            {
                Total = Total,
                PageNumber = filter.PageNumber,
                PageSize = filter.PageSize,
                Results = results
            });
        }
Exemplo n.º 14
0
 extern public static void SetAddressFilteringMode(AddressFilter mode);
Exemplo n.º 15
0
 public AddressCompletionAdapter(Context context)
 {
     this.context = context;
     this.filter  = new AddressFilter(context, this);
 }