Exemplo n.º 1
0
        private static SectionConfiguration AddSectionConfiguration(DeviceElement adaptDeviceElement, DeviceElementHierarchy deviceHierarchy, AgGateway.ADAPT.ApplicationDataModel.ADM.Catalog catalog)
        {
            SectionConfiguration sectionConfiguration = new SectionConfiguration();

            //Description
            sectionConfiguration.Description = $"{deviceHierarchy.DeviceElement.Device.DeviceDesignator} : {deviceHierarchy.DeviceElement.DeviceElementDesignator}";


            //Device Element ID
            sectionConfiguration.DeviceElementId = adaptDeviceElement.Id.ReferenceId;

            //Width & Offsets
            if (deviceHierarchy.Width != null)
            {
                sectionConfiguration.SectionWidth = deviceHierarchy.WidthRepresentation;
            }

            sectionConfiguration.Offsets = new List <NumericRepresentationValue>();
            if (deviceHierarchy.XOffset != null)
            {
                sectionConfiguration.InlineOffset = deviceHierarchy.XOffsetRepresentation;
                sectionConfiguration.Offsets.Add(deviceHierarchy.XOffsetRepresentation);
            }
            if (deviceHierarchy.YOffset != null)
            {
                sectionConfiguration.LateralOffset = deviceHierarchy.YOffsetRepresentation;
                sectionConfiguration.Offsets.Add(deviceHierarchy.YOffsetRepresentation);
            }

            catalog.DeviceElementConfigurations.Add(sectionConfiguration);
            return(sectionConfiguration);
        }
        private void Initialize()
        {
            var pluginConfiguration =
                new SectionConfiguration().GetInstance <AuthenticationTypeConfiguration>(
                    "BTL.Applications/AuthRequestTypeSettings");

            AuthenticationContexts = pluginConfiguration.SectionCollection;
        }
Exemplo n.º 3
0
        private static SectionConfiguration AddSectionConfiguration(DeviceElement adaptDeviceElement, DeviceElementHierarchy deviceHierarchy, AgGateway.ADAPT.ApplicationDataModel.ADM.Catalog catalog)
        {
            SectionConfiguration sectionConfiguration = new SectionConfiguration();

            //Description
            sectionConfiguration.Description = $"{deviceHierarchy.DeviceElement.Device.DeviceDesignator} : {deviceHierarchy.DeviceElement.DeviceElementDesignator}";


            //Device Element ID
            sectionConfiguration.DeviceElementId = adaptDeviceElement.Id.ReferenceId;

            NumericRepresentationValue width   = deviceHierarchy.WidthRepresentation;
            NumericRepresentationValue xOffset = deviceHierarchy.XOffsetRepresentation;
            NumericRepresentationValue yOffset = deviceHierarchy.YOffsetRepresentation;

            if (adaptDeviceElement.DeviceElementType == DeviceElementTypeEnum.Bin)
            {
                //A bin carries no geometry information and should inherit width from its parent and carry 0 offsets from its parent.
                width   = deviceHierarchy.Parent.WidthRepresentation;
                xOffset = 0.AsNumericRepresentationValue("0086", deviceHierarchy.RepresentationMapper);
                yOffset = 0.AsNumericRepresentationValue("0087", deviceHierarchy.RepresentationMapper);
            }

            //Width & Offsets
            sectionConfiguration.SectionWidth = width;
            sectionConfiguration.Offsets      = new List <NumericRepresentationValue>();
            if (xOffset != null)
            {
                sectionConfiguration.InlineOffset = xOffset;
                sectionConfiguration.Offsets.Add(xOffset);
            }
            if (yOffset != null)
            {
                sectionConfiguration.LateralOffset = yOffset;
                sectionConfiguration.Offsets.Add(yOffset);
            }

            catalog.DeviceElementConfigurations.Add(sectionConfiguration);
            return(sectionConfiguration);
        }
Exemplo n.º 4
0
        public static T GetInstance <T>(this SectionConfiguration sectionConfiguration, string section)
            where T : ISectionConfiguration, new()
        {
            //Declare object
            var retValue = new T();

            //Read configuration for provided section
            var configurationSection = (SectionConfiguration)ConfigurationManager.GetSection(section);

            //return null if there is no section specified
            if (configurationSection == null)
            {
                return(retValue);
            }

            //read the settings to the return object
            foreach (SectionConfigurationElement setting in configurationSection.Settings)
            {
                retValue.FillProperty(setting);
            }

            return(retValue);
        }
        protected override void Load(ContainerBuilder builder)
        {
            base.Load(builder);

            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            builder.RegisterType <ExConfigurationManager>().As <IExConfigurationManager>().SingleInstance();
            builder.RegisterType <ThemeProvider>().As <IThemeProvider>().SingleInstance();
            builder.RegisterType <FormsAuthenticationService>().As <IFormsAuthenticationService>().InstancePerDependency();

            // authentication instances
            builder.RegisterType <FacebookUserInformation>().As <IFacebookAuthRequestRole>().PropertiesAutowired();
            builder.RegisterType <FacebookClient>().AsSelf();
            builder.RegisterType <TwitterUserInformation>().AsImplementedInterfaces().PropertiesAutowired();
            builder.RegisterType <GoogleUserInformation>().AsImplementedInterfaces().PropertiesAutowired();

            // Facade instances
            builder.RegisterType <AppSecurityFacade>().AsImplementedInterfaces().InstancePerDependency();
            builder.RegisterType <AppAuthenticationFacade>().AsImplementedInterfaces().InstancePerDependency();

            var mySettings = SectionConfiguration.GetInstance <MySettings>(MySettings.SECTION_NAME);

            builder.RegisterInstance(mySettings).As <MySettings>();
        }
Exemplo n.º 6
0
        private void ExportDeviceProperties(ISODeviceElement isoDeviceElement, DeviceElement adaptDeviceElement)
        {
            //Connectors
            if (isoDeviceElement.ChildDeviceElements != null)
            {
                foreach (ISODeviceElement connectorElement in isoDeviceElement.ChildDeviceElements.Where(d => d.DeviceElementType == ISODeviceElementType.Connector))
                {
                    int?connectorID = TaskDataMapper.InstanceIDMap.GetADAPTID(connectorElement.DeviceElementId);
                    if (connectorID.HasValue)
                    {
                        Connector  connector = DataModel.Catalog.Connectors.First(c => c.Id.ReferenceId == connectorID.Value);
                        HitchPoint hitch     = DataModel.Catalog.HitchPoints.FirstOrDefault(h => h.Id.ReferenceId == connector.HitchPointId);
                        if (hitch != null && hitch.ReferencePoint != null)
                        {
                            ExportDeviceProperty(connectorElement, hitch.ReferencePoint.XOffset, ++_devicePropertyObjectID);
                            ExportDeviceProperty(connectorElement, hitch.ReferencePoint.YOffset, ++_devicePropertyObjectID);
                            ExportDeviceProperty(connectorElement, hitch.ReferencePoint.ZOffset, ++_devicePropertyObjectID);
                        }
                    }
                }
            }

            //Device Element Widths & Offsets
            IEnumerable <DeviceElementConfiguration> configs = DataModel.Catalog.DeviceElementConfigurations.Where(c => c.DeviceElementId == adaptDeviceElement.Id.ReferenceId);

            foreach (DeviceElementConfiguration config in configs)
            {
                if (config is MachineConfiguration)
                {
                    MachineConfiguration machineConfig     = config as MachineConfiguration;
                    ISODeviceElement     navigationElement = isoDeviceElement.Device.DeviceElements.FirstOrDefault(d => d.DeviceElementType == ISODeviceElementType.Navigation);
                    if (navigationElement == null)
                    {
                        if (machineConfig.GpsReceiverXOffset != null)
                        {
                            ExportDeviceProperty(navigationElement, machineConfig.GpsReceiverXOffset, ++_devicePropertyObjectID);
                        }
                        if (machineConfig.GpsReceiverYOffset != null)
                        {
                            ExportDeviceProperty(navigationElement, machineConfig.GpsReceiverYOffset, ++_devicePropertyObjectID);
                        }
                        if (machineConfig.GpsReceiverZOffset != null)
                        {
                            ExportDeviceProperty(navigationElement, machineConfig.GpsReceiverZOffset, ++_devicePropertyObjectID);
                        }
                    }
                }
                else if (config is ImplementConfiguration)
                {
                    ImplementConfiguration implementConfig = config as ImplementConfiguration;
                    if (implementConfig.Width != null)
                    {
                        ExportDeviceProperty(isoDeviceElement, implementConfig.Width, ++_devicePropertyObjectID);
                    }
                    if (implementConfig.Offsets != null)
                    {
                        implementConfig.Offsets.ForEach(o => ExportDeviceProperty(isoDeviceElement, o, ++_devicePropertyObjectID));
                    }
                }
                else if (config is SectionConfiguration)
                {
                    SectionConfiguration sectionConfig = config as SectionConfiguration;
                    if (sectionConfig.InlineOffset != null)
                    {
                        ExportDeviceProperty(isoDeviceElement, sectionConfig.InlineOffset, ++_devicePropertyObjectID);
                    }
                    if (sectionConfig.LateralOffset != null)
                    {
                        ExportDeviceProperty(isoDeviceElement, sectionConfig.LateralOffset, ++_devicePropertyObjectID);
                    }
                    if (sectionConfig.SectionWidth != null)
                    {
                        ExportDeviceProperty(isoDeviceElement, sectionConfig.SectionWidth, ++_devicePropertyObjectID);
                    }
                }
            }
        }
        private static void GetPlantingData(OperationData opData, Catalog catalog)
        {
            // Get the distance meter from the Machine/Vehicle level
            WorkingData distanceMeter = null;

            IEnumerable <DeviceElementUse> machineDEUs = opData.GetDeviceElementUses(0);

            foreach (DeviceElementUse deu in machineDEUs)
            {
                IEnumerable <WorkingData> workingDatas = deu.GetWorkingDatas();
                foreach (WorkingData meter in workingDatas)
                {
                    switch (meter.Representation.Code)
                    {
                    case "vrDistanceTraveled":
                        distanceMeter = meter;
                        break;
                    }
                }
            }

            // Get the row-level meters for determining status, seeding rates, and product assignment for each row
            IEnumerable <DeviceElementUse> rowDEUs = opData.GetDeviceElementUses(2);
            List <RowConfiguration>        rows    = new List <RowConfiguration>();

            NumericWorkingData exampleRowMeter = null;

            foreach (DeviceElementUse deu in rowDEUs)
            {
                // Link to the catalog.DeviceElementConfigurations in order to determine the width of the row.
                //  Row widths are always in inches
                SectionConfiguration rowConfig = catalog.DeviceElementConfigurations.Find(x => x.Id.ReferenceId == deu.DeviceConfigurationId) as SectionConfiguration;
                RowConfiguration     row       = new RowConfiguration()
                {
                    widthIn = rowConfig.SectionWidth.Value.Value
                };

                IEnumerable <WorkingData> workingDatas = deu.GetWorkingDatas();
                foreach (WorkingData meter in workingDatas)
                {
                    switch (meter.Representation.Code)
                    {
                    case "dtRecordingStatus":
                        row.statusMeter = meter;
                        break;

                    case "vrSeedRateMassActual":
                    case "vrSeedRateSeedsActual":
                        row.appRateMeter = meter;
                        exampleRowMeter  = meter as NumericWorkingData;
                        break;

                    case "vrProductIndex":
                        row.productIndexMeter = meter;
                        break;
                    }
                }

                rows.Add(row);
            }

            string rateUnits = "";

            if (exampleRowMeter != null)
            {
                rateUnits = exampleRowMeter.UnitOfMeasure.Code;
            }

            // Initialize the productSummary dictionary
            //  Each product used in the planting operation is identified in the opData.ProductIds list.
            Dictionary <int, ProductSummary> productSummaryByProductId = new Dictionary <int, ProductSummary>();

            foreach (int productId in opData.ProductIds)
            {
                ProductSummary productSummary = new ProductSummary();
                productSummary.product = catalog.Products.Find(x => x.Id.ReferenceId == productId);

                productSummaryByProductId[productId] = productSummary;
            }

            // Keep track of the default productId.
            //  Single-product applications will only specify one product and will not use vrProductIndex meters
            int defaultProductId = opData.ProductIds[0];

            // Loop through all the spatial records
            IEnumerable <SpatialRecord> spatialRecords = opData.GetSpatialRecords();

            foreach (SpatialRecord spatialRecord in spatialRecords)
            {
                NumericRepresentationValue distance = spatialRecord.GetMeterValue(distanceMeter) as NumericRepresentationValue;
                double distanceFt = distance.Value.Value;

                // Loop through each row - we need to examine the status, product assignment, and rate of each row individually
                foreach (RowConfiguration row in rows)
                {
                    EnumeratedValue rowStatus = spatialRecord.GetMeterValue(row.statusMeter) as EnumeratedValue;
                    if (rowStatus.Value.Value == "Off")
                    {
                        // Skip inactive rows
                        continue;
                    }

                    int productId = defaultProductId;
                    if (row.productIndexMeter != null)
                    {
                        // Check to see which product is currently being planted by the current row unit
                        //  Only used for split planter and multi-hybrid planter
                        NumericRepresentationValue productIndex = spatialRecord.GetMeterValue(row.productIndexMeter) as NumericRepresentationValue;
                        if (productIndex != null)
                        {
                            productId = (int)productIndex.Value.Value;
                        }
                    }

                    // Calculate the number of acres covered by this row unit at this point in time
                    double acres = row.CalculateAcres(distanceFt);
                    productSummaryByProductId[productId].totalAcres += acres;

                    if (row.appRateMeter != null)
                    {
                        NumericRepresentationValue appRate = spatialRecord.GetMeterValue(row.appRateMeter) as NumericRepresentationValue;
                        if (appRate != null)
                        {
                            double rate   = appRate.Value.Value; // seeds/ac or lbs/ac
                            double amount = rate * acres;        // seeds or lbs
                            productSummaryByProductId[productId].totalAmount += amount;
                        }
                    }
                }
            }

            Console.WriteLine("Planting Sumamry by Variety.  Rate Units: " + rateUnits);
            foreach (ProductSummary productSummary in productSummaryByProductId.Values)
            {
                Console.WriteLine(productSummary.ToString());
            }
        }
        public void SetWidthsAndOffsetsFromSpatialData(IEnumerable <ISOSpatialRow> isoRecords, DeviceElementConfiguration config, RepresentationMapper representationMapper)
        {
            //Set values on this object and associated DeviceElementConfiguration
            if (Width == null)
            {
                Width = GetWidthFromSpatialData(isoRecords, DeviceElement.DeviceElementId, representationMapper);
            }

            if (config.Offsets == null)
            {
                config.Offsets = new List <NumericRepresentationValue>();
            }

            if (XOffset == null)
            {
                XOffset = GetXOffsetFromSpatialData(isoRecords, DeviceElement.DeviceElementId, representationMapper);
                if (XOffsetRepresentation != null)
                {
                    config.Offsets.Add(XOffsetRepresentation);
                }
            }

            if (YOffset == null)
            {
                YOffset = GetYOffsetFromSpatialData(isoRecords, DeviceElement.DeviceElementId, representationMapper);
                if (YOffsetRepresentation != null)
                {
                    config.Offsets.Add(YOffsetRepresentation);
                }
            }

            if (ZOffset == null)
            {
                ZOffset = GetZOffsetFromSpatialData(isoRecords, DeviceElement.DeviceElementId, representationMapper);
                if (ZOffsetRepresentation != null)
                {
                    config.Offsets.Add(ZOffsetRepresentation);
                }
            }

            //Update config values as appropriate
            if (this.DeviceElement.DeviceElementType == ISODeviceElementType.Navigation)
            {
                MachineConfiguration machineConfig = config as MachineConfiguration;
                if (machineConfig.GpsReceiverXOffset == null)
                {
                    machineConfig.GpsReceiverXOffset = XOffsetRepresentation;
                }
                if (machineConfig.GpsReceiverYOffset == null)
                {
                    machineConfig.GpsReceiverYOffset = YOffsetRepresentation;
                }
                if (machineConfig.GpsReceiverZOffset == null)
                {
                    machineConfig.GpsReceiverZOffset = ZOffsetRepresentation;
                }
            }
            else
            {
                if (config is SectionConfiguration)
                {
                    SectionConfiguration sectionConfig = config as SectionConfiguration;
                    if (sectionConfig.SectionWidth == null)
                    {
                        sectionConfig.SectionWidth = WidthRepresentation;
                    }
                    if (sectionConfig.InlineOffset == null)
                    {
                        sectionConfig.InlineOffset = XOffsetRepresentation;
                    }
                    if (sectionConfig.LateralOffset == null)
                    {
                        sectionConfig.LateralOffset = YOffsetRepresentation;
                    }
                }
                else if (config is ImplementConfiguration)
                {
                    ImplementConfiguration implementConfig = config as ImplementConfiguration;
                    if (implementConfig.Width == null)
                    {
                        implementConfig.Width = WidthRepresentation;
                    }
                }
            }
        }
        public static void DescribeImplement(Catalog catalog, LoggedData loggedData)
        {
            Console.WriteLine();
            Console.WriteLine("-----------------------");
            Console.WriteLine("Equipment Configuration");
            Console.WriteLine("-----------------------");
            Console.WriteLine();


            //A LoggedData will have a single EquipmentConfigurationGroup that contains any EquipmentConfigurations in the file
            EquipmentConfigurationGroup equipConfigGroup = loggedData.EquipmentConfigurationGroup;

            //The configuration of the equipment can vary by each region, although it is likely that the equipment configuration remains consistent across many regions
            //Any distinct configurations represented in the field operation will be EquipmentConfigurations within this group
            List <EquipmentConfiguration> distinctConfigurations = equipConfigGroup.EquipmentConfigurations;

            Console.WriteLine($"Field operation has {distinctConfigurations.Count} distinct equipment configuration(s).");
            Console.WriteLine();

            //While a single OperationData object supports a list of EquipmentConfigurations, the 2020 plugin will always reference a single EquipmentConfiguration on any one OperationData.
            //This allows the consumer to predictively map data based a known equipment definition for that data.

            //Going deeper on the first OperationData
            Console.WriteLine("The first region and OperationData within the field operation has this configuration:");
            EquipmentConfiguration equipConfig = distinctConfigurations.SingleOrDefault(c => c.Id.ReferenceId == loggedData.OperationData.First().EquipmentConfigurationIds.Single());

            //The equipment configuration maps to 2 connectors, explaining what machinery was hitched together
            Connector connector1 = catalog.Connectors.SingleOrDefault(c => c.Id.ReferenceId == equipConfig.Connector1Id);
            Connector connector2 = catalog.Connectors.SingleOrDefault(c => c.Id.ReferenceId == equipConfig.Connector2Id);

            //Each connector contains two pieces of information, the DeviceElementConfiguration that connector/hitch is a part of, and metadata on a specific hitch point.
            DeviceElementConfiguration deviceElementConfiguration1 = catalog.DeviceElementConfigurations.SingleOrDefault(c => c.Id.ReferenceId == connector1.DeviceElementConfigurationId);
            HitchPoint hitchPoint1 = catalog.HitchPoints.SingleOrDefault(h => h.Id.ReferenceId == connector1.HitchPointId);

            DeviceElementConfiguration deviceElementConfiguration2 = catalog.DeviceElementConfigurations.SingleOrDefault(c => c.Id.ReferenceId == connector2.DeviceElementConfigurationId);
            HitchPoint hitchPoint2 = catalog.HitchPoints.SingleOrDefault(h => h.Id.ReferenceId == connector2.HitchPointId);

            //DeviceElementConfigurations are a polymorphic object within ADAPT.
            //A DeviceElementConfiguration may be of type
            //  MachineConfiguration (describing a tractor/vehicle)
            //  ImplementConfiguration (describing an entire implement)
            //  SectionConfiguration (describing a subsection or individual row of an implement)

            //DeviceElementConfigurations are part of a 3-object hierarchy that describes a piece of equipment
            //1. DeviceModel - A high-level description of the equipment: brand, manufacturer, description.   Any single piece of equipment has only 1 device model.
            //2. DeviceElement -A hierarchical descripion part of the equipment: brand, manufacturer, description, and type of element (section, machine, implement, etc.).
            //                  A DeviceElement maps to a single DeviceModel, and may be a parent and/or child of other DeviceElements.
            //                  E.g., each section is a child of the root implement DeviceElement
            //3. DeviceElementConfigurations - The DeviceElementConfiguration is an extension of the DeviceElement, each mapping to a single DeviceElement,
            //                                  but having specific phyproperties such as width and offsets.

            //The 2020 equipment configuration will always have a Machine/Vehicle as the Connector1 and an Implement as the Connector2.
            MachineConfiguration   vehicleConfiguration   = deviceElementConfiguration1 as MachineConfiguration;
            ImplementConfiguration implementConfiguration = deviceElementConfiguration2 as ImplementConfiguration;

            HitchPoint vehicleHitch   = hitchPoint1;
            HitchPoint implementHitch = hitchPoint2;

            //The DeviceElements expose the hierarchy between parts of the equipment
            Console.WriteLine();
            Console.WriteLine("Vehicle DeviceElement Hierarchy:");
            DeviceElement vehicleDeviceElement = catalog.DeviceElements.SingleOrDefault(d => d.Id.ReferenceId == vehicleConfiguration.DeviceElementId);

            DescribeDeviceHierarchy(catalog, vehicleDeviceElement, 0, new List <DeviceElement>());

            Console.WriteLine();
            Console.WriteLine("Implement DeviceElement Hierarchy:");
            List <DeviceElement> implementChildElements = new List <DeviceElement>();
            DeviceElement        implementDeviceElement = catalog.DeviceElements.SingleOrDefault(d => d.Id.ReferenceId == implementConfiguration.DeviceElementId);

            DescribeDeviceHierarchy(catalog, implementDeviceElement, 0, implementChildElements);

            Console.WriteLine();


            Console.WriteLine();
            Console.WriteLine("-----------------------");
            Console.WriteLine("Implement Width Values");
            Console.WriteLine("-----------------------");
            Console.WriteLine();

            //The Implement and Section DeviceElementConfigurations carry width information.
            Console.WriteLine($"The {implementConfiguration.Description} is {implementConfiguration.PhysicalWidth.Value.Value} {implementConfiguration.PhysicalWidth.Value.UnitOfMeasure.Code} wide.");
            foreach (DeviceElement childElement in implementChildElements)
            {
                DeviceElementConfiguration deviceElementConfiguration = catalog.DeviceElementConfigurations.SingleOrDefault(c => c.DeviceElementId == childElement.Id.ReferenceId);
                if (deviceElementConfiguration != null)
                {
                    SectionConfiguration sectionConfiguration = deviceElementConfiguration as SectionConfiguration;
                    if (sectionConfiguration != null)
                    {
                        Console.WriteLine($"{sectionConfiguration.Description} is {sectionConfiguration.SectionWidth.Value.Value} {sectionConfiguration.SectionWidth.Value.UnitOfMeasure.Code} wide.");
                    }
                }
            }


            Console.WriteLine();
            Console.WriteLine("-----------------------");
            Console.WriteLine("Equipment Offset Values");
            Console.WriteLine("-----------------------");
            Console.WriteLine();

            //Various offset values describe where each device element is located vs. other elements via data on the device element configuration

            //Vehicle GPS Receiver
            DescribeOffset("GPS Receiver", vehicleConfiguration.GpsReceiverXOffset, vehicleConfiguration.GpsReceiverYOffset, "tractor reference point (center of rear axle)");

            //Tractor hitch offset
            DescribeOffset("vehicle hitch point", vehicleHitch.ReferencePoint.XOffset, vehicleHitch.ReferencePoint.YOffset, "tractor reference point (center of rear axle)");

            //Implement hitch offset
            DescribeOffset("implement hitch point", implementHitch.ReferencePoint.XOffset, implementHitch.ReferencePoint.YOffset, "implement reference point (center of implement)");

            //Implmement control point offset (inverse of the prior)
            DescribeOffset("implement control point offset", implementConfiguration.ControlPoint.XOffset, implementConfiguration.ControlPoint.YOffset, "tractor hitch point");

            //Section offsets (measured to center of each section)
            foreach (DeviceElement childElement in implementChildElements)
            {
                DeviceElementConfiguration deviceElementConfiguration = catalog.DeviceElementConfigurations.SingleOrDefault(c => c.DeviceElementId == childElement.Id.ReferenceId);
                if (deviceElementConfiguration != null)
                {
                    SectionConfiguration sectionConfiguration = deviceElementConfiguration as SectionConfiguration;
                    if (sectionConfiguration != null)
                    {
                        DescribeOffset($"{childElement.Description} offset", sectionConfiguration.InlineOffset, sectionConfiguration.LateralOffset, "tractor hitch point");
                    }
                }
            }
        }