private void CheckParams(string[] args, ref ValueCollection collection)
                {
                    for (int i = 0; i < args.Length; i++)
                    {
                        if (i >= Params.Count)
                        {
                            break;
                        }

                        var arg   = args[i];
                        var param = Params[i];

                        if (param.Greedy)
                        {
                            collection.Add(param.Name, new ParamValue {
                                Value = string.Join(" ", args, i, args.Length - i)
                            });
                            break;
                        }

                        object value;
                        bool   result = CheckAndConvert(arg, param.Type, out value);
                        collection.Add(param.Name, new ParamValue {
                            Value = value, IsInvalid = !result
                        });
                    }
                }
Exemple #2
0
        public void MapAttributesForJoin(string FlowRuleName, CSEntry csentry, ref ValueCollection values)
        {
            AttributeType  type;
            IList <object> sourceValues = this.GetSourceValuesForImport(csentry, out type);
            IList <object> returnValues = Transform.ExecuteTransformChain(this.Transforms, sourceValues);

            foreach (object value in returnValues)
            {
                switch (type)
                {
                case AttributeType.Binary:
                    values.Add(TypeConverter.ConvertData <byte[]>(value));
                    break;

                case AttributeType.Integer:
                    values.Add(TypeConverter.ConvertData <long>(value));
                    break;

                case AttributeType.String:
                    values.Add(TypeConverter.ConvertData <string>(value));
                    break;

                case AttributeType.Reference:
                case AttributeType.Boolean:
                case AttributeType.Undefined:
                    throw new UnknownOrUnsupportedDataTypeException();
                }
            }
        }
Exemple #3
0
        public void SimpleEncodingDataGetsEncoded()
        {
            var chart = GetLineChartForTesting();

            chart.Encoding = Encoding.SimpleEncoding;
            var values = new ValueCollection();

            for (var i = 0; i < 63; i++)
            {
                values.Add(new ValueInformation()
                {
                    Value = i
                });
            }

            chart.DataSets = new DataSetCollection()
            {
                new ChartDataSet()
                {
                    Values = values
                }
            };



            var expectedValue = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";



            var url = chart.GetURL();


            Assert.IsTrue(url.Contains(GetTestableValue(expectedValue)));
        }
 internal static ValueCollection <T> AddFluently <T>(this ValueCollection <T> list, params T[] elements)
 {
     foreach (var element in elements)
     {
         list.Add(element);
     }
     return(list);
 }
        public static IDictionary <String, IDictionary <String, ValueList> > GetMappedValueListsWithPath(this GraphMap graphMap, ValueListMaps valueListMaps, String templateId, int templateIndex, String parentClassId, int parentClassIndex, IDictionary <String, IDictionary <String, ValueList> > valueList = null)
        {
            if (valueList == null)
            {
                valueList = new Dictionary <String, IDictionary <String, ValueList> >();
            }

            var classTemplateMap = graphMap.GetClassTemplateMap(parentClassId, parentClassIndex);



            if (classTemplateMap != null)
            {
                var template = classTemplateMap.templateMaps.SingleOrDefault(x => (x.id == templateId && x.index == templateIndex));
                if (template != null)
                {
                    foreach (var role in template.roleMaps.Where(x => !String.IsNullOrWhiteSpace(x.propertyName)))
                    {
                        if (role.type == RoleType.ObjectProperty)
                        {
                            string path = (string.IsNullOrEmpty(classTemplateMap.classMap.path) ? "" : classTemplateMap.classMap.path) + "/" + classTemplateMap.classMap.id.ToString() + "/" + template.id.ToString() + "/" + role.id.ToString();
                            Dictionary <String, ValueList> valListDict = new Dictionary <String, ValueList>();
                            ValueMaps       valueMaps = GetValueListMap(valueListMaps, role.valueListName);
                            ValueList       valList   = new ValueList();
                            ValueCollection valCol    = new ValueCollection();
                            valList.name = role.valueListName;
                            foreach (var item in valueMaps)
                            {
                                ValueItem valItem = new ValueItem();
                                valItem.label = item.label;
                                valItem.value = item.internalValue;
                                valItem.uri   = item.uri;
                                valCol.Add(valItem);
                            }
                            valList.values = valCol;
                            valListDict.Add(role.propertyName, valList);
                            valueList.Add(path, valListDict);
                        }
                    }
                    foreach (var role in template.roleMaps.Where(x => x.classMap != null))
                    {
                        var classTemplate = graphMap.GetClassTemplateMap(role.classMap.id, role.classMap.index);
                        foreach (var tmpl in classTemplate.templateMaps)
                        {
                            if (tmpl != null)
                            {
                                graphMap.GetMappedValueListsWithPath(valueListMaps, tmpl.id, tmpl.index, role.classMap.id, role.classMap.index, valueList);
                            }
                        }
                    }
                }
            }
            return(valueList);
        }
Exemple #6
0
        void IMASynchronization.MapAttributesForJoin(string flowRuleName, CSEntry csentry, ref ValueCollection values)
        {
            FlowRuleParameters parameters = this.GetParameters(flowRuleName, FlowRuleType.Join);

            if (!parameters.ShouldFlow(csentry, null))
            {
                throw new DeclineMappingException();
            }

            AttributeType  type;
            IList <object> sourceValues = this.GetSourceValuesForImport(parameters, csentry, out type);
            IList <object> returnValues = Transform.ExecuteTransformChain(parameters.Transforms, sourceValues);

            foreach (object value in returnValues)
            {
                switch (type)
                {
                case AttributeType.Binary:
                    values.Add(TypeConverter.ConvertData <byte[]>(value));
                    break;

                case AttributeType.Integer:
                    values.Add(TypeConverter.ConvertData <long>(value));
                    break;

                case AttributeType.String:
                    values.Add(TypeConverter.ConvertData <string>(value));
                    break;

                case AttributeType.Reference:
                case AttributeType.Boolean:
                case AttributeType.Undefined:
                    throw new UnknownOrUnsupportedDataTypeException();
                }
            }
        }
Exemple #7
0
 public void InvokeMapJoinRule(JoinRule rule, CSEntry csentry, ref ValueCollection values)
 {
     Tracer.TraceInformation("enter-invokemapjoinrule {0}", rule.Name);
     try
     {
         object targetValue = null;
         foreach (Value value in rule.SourceExpression.Source)
         {
             if (value.GetType().Equals(typeof(MultiValueAttribute)))
             {
                 MultiValueAttribute attr = (MultiValueAttribute)value;
                 object mv = attr.GetValueOrDefault(Direction.Import, csentry, null);
                 targetValue = attr.Transform(mv, TransformDirection.Source);
             }
             if (value.GetType().Equals(typeof(Attribute)))
             {
                 Attribute attr         = (Attribute)value;
                 object    concateValue = attr.GetValueOrDefault(Direction.Import, csentry, null);
                 concateValue = attr.Transform(concateValue, TransformDirection.Source);
                 targetValue  = targetValue as string + concateValue;
                 attr         = null;
                 continue;
             }
             if (value.GetType().Equals(typeof(Constant)))
             {
                 targetValue = targetValue + ((Constant)value).Value;
                 continue;
             }
         }
         Tracer.TraceInformation("add-invokemapjoinrule-value rule: {0}, value: '{1}'", rule.Name, targetValue);
         values.Add(targetValue as string);
     }
     catch (Exception ex)
     {
         Tracer.TraceError("invokemapjoinrule {0}", ex.GetBaseException());
         throw ex;
     }
     finally
     {
         Tracer.TraceInformation("exit-invokemapjoinrule {0}", rule.Name);
     }
 }
 /// <summary>
 /// sample function - potential join candidates and add them to the values collection
 /// </summary>
 /// <param name="csentry"></param>
 /// <param name="values"></param>
 private void ConstructJoinsSample(CSEntry csentry, ref ValueCollection values)
 {
     values.Add(csentry.DN);
     values.Add(csentry.RDN);
     values.Add(csentry.ObjectType);
 }
Exemple #9
0
        public static (ValueCollection, ValueCollection) CreateValueCollection(Configuration configuration)
        {
            var collection = new ValueCollection {
                MeasuredValue.Empty(configuration)
            };

            var dailyCollection = new ValueCollection {
                MeasuredValue.Empty(configuration)
            };

            var reserveTimer = 1;
            var reservePool  = configuration.ReservePoolSize;
            var questTimer   = 1;
            var dailyPool    = 0;
            var questPool    = 0;
            var dayCount     = configuration.GeneralAllXDays;

            for (int day = 1; day <= configuration.GeneralTotalDays; day++)
            {
                dailyPool += dailyPool == 0
                    ? configuration.DailyMaxGain
                    : configuration.DailyMinGain;

                if (questPool < configuration.QuestsPoolSize)
                {
                    questPool = Math.Min(questPool + configuration.QuestsDailyGain, configuration.QuestsPoolSize);
                }

                if (dayCount == configuration.GeneralAllXDays)
                {
                    dayCount = 1;

                    for (int minute = 1; minute < Math.Min(1440, configuration.GeneralTotalMinutes + 1); minute++)
                    {
                        var oldValue = collection.Last();

                        var newValue = new MeasuredValue
                        {
                            ReservePool = oldValue.ReservePool,
                            QuestsLeft  = oldValue.QuestsLeft,
                            DailyPool   = dailyPool,
                            Minute      = minute + ((day - 1) * 1440),
                            Bfp         = oldValue.Bfp,
                            Day         = day
                        };

                        if (minute < configuration.GeneralMinutesPerDay + 1)
                        {
                            if (dailyPool > 0)
                            {
                                var gainFromDaily = dailyPool / (configuration.DailyDuration - minute + 1);
                                newValue.Bfp += gainFromDaily;
                                dailyPool    -= gainFromDaily;
                            }
                            else
                            {
                                if (reservePool >= configuration.ReserveDrainPerMinute)
                                {
                                    newValue.Bfp += configuration.ReserveDrainPerMinute;
                                    reservePool  -= configuration.ReserveDrainPerMinute;
                                }
                                else if (reservePool > 0)
                                {
                                    newValue.Bfp += reservePool;
                                    reservePool   = 0;
                                }
                            }
                        }

                        //Reserve Gain
                        reserveTimer++;
                        if (reserveTimer == configuration.ReserveMinutesPerGain)
                        {
                            if (reservePool < configuration.ReservePoolSize)
                            {
                                reservePool++;
                            }

                            reserveTimer = 0;
                        }

                        //Quests
                        if (questPool > 0)
                        {
                            questTimer++;

                            if (questTimer == configuration.QuestsMinutesPerQuest)
                            {
                                questPool    -= 1;
                                newValue.Bfp += configuration.QuestsBfpPerQuest;
                                questTimer    = 0;
                            }
                        }

                        newValue.DailyPool   = dailyPool;
                        newValue.ReservePool = reservePool;
                        newValue.QuestsLeft  = questPool;

                        collection.Add(newValue);
                    }
                }
                else
                {
                    dayCount++;
                }

                dailyCollection.Add(collection.Last());
            }
            return(collection, dailyCollection);
        }
Exemple #10
0
        // Performs the logic for the steam sensor, occurs every scan cycle
        public async void scanDevice()
        {
            var random = new Random();

            // Set the Temperature property value in the range of 400-440
            //var temperature = 20 * random.NextDouble();
            var temperature = (cp.ReadTemperature() / 100.0);
            // Set the Pressure property value in the range of 18-23
            //var humidity = 18 + 5 * random.NextDouble();
            var humidity = (cp.ReadHumidity() / 100.0);

            // Add a random double value from 0.0-1.0 to the total flow
            _totalFlow += random.NextDouble();

            // Set the InletValve property value to true by default
            var inletValveStatus = true;

            // If the current second value is divisible by 15, set the InletValve property value to false
            var seconds = DateTime.Now.Second;

            if ((seconds % 15) == 0)
            {
                inletValveStatus = false;
            }

            // Set the property values
            base.setProperty("Temperature", temperature);
            base.setProperty("Timestamp", DateTime.Now);
            base.setProperty("Humidity", humidity);
            base.setProperty("Potenciometer", _rotaryValue);
            base.setProperty("Movement", _counter);
            base.setProperty("TotalFlow", this._totalFlow);
            base.setProperty("InletValve", inletValveStatus);

            // Get the TemperatureLimmit property value from memory
            var temperatureLimit = (double)getProperty("TemperatureLimit").getValue().getValue();

            // Set the FaultStatus property value if the TemperatureLimit value is exceeded
            // and it is greater than zero
            var faultStatus = temperatureLimit > 0 && temperature > temperatureLimit;

            // If the sensor has a fault...
            if (faultStatus)
            {
                // Get the previous value of the fault from the property
                // This is the current value because it hasn't been set yet
                // This is done because we don't want to send the event every time it enters the fault state,
                // only send the fault on the transition from non-faulted to faulted
                var previousFaultStatus = (bool)getProperty("FaultStatus").getValue().getValue();

                // If the current value is not faulted, then create and queue the event
                if (!previousFaultStatus)
                {
                    // Set the event information of the defined data shape for the event
                    var eventInfo = new ValueCollection();
                    eventInfo.Add(CommonPropertyNames.PROP_MESSAGE, new StringPrimitive("Temperature at " + temperature + " was above limit of " + temperatureLimit));
                    // Queue the event
                    base.queueEvent("SteamSensorFault", DateTime.UtcNow, eventInfo);
                }
            }

            // Set the fault status property value
            base.setProperty("FaultStatus", faultStatus);

            try {
                // Update the subscribed properties and events to send any updates to Thingworx
                // Without calling these methods, the property and event updates will not be sent
                // The numbers are timeouts in milliseconds.
                base.updateSubscribedProperties(15000);

                LoggerFactory.Log(Logger, TraceEventType.Critical, "Current Temperature limit: {0}", temperatureLimit);
                LoggerFactory.Log(Logger, TraceEventType.Critical,
                                  "PUSHED PROPERTY UPDATES \n   " +
                                  "Temperature: {0} \n   " +
                                  "Humidity: {1} \n   " +
                                  "TotalFlow: {2} \n   " +
                                  "InletValve :{3} \n   " +
                                  "FaultStatus : {4} \n\n",
                                  temperature, humidity, _totalFlow, inletValveStatus, faultStatus);

                base.updateSubscribedEvents(6000);
            } catch (Exception ex) {
                // handle exception as appropriate
            }
        }