public RelativeHumidityMeasurement(AttributesCollection coll)
		{
			MeasuredValue = float.NaN;
			MinMeasuredValue = float.NaN;
			MaxMeasuredValue = float.NaN;
			Tolerance = float.NaN;
			if (coll.ContainsKey(0x0000))
			{
				var attr = coll[0x0000];
				if (attr.DataType == ZigbeeDataType.UInt16)
					MeasuredValue = ((ushort)attr.Data) / 100f;
			}
			if (coll.ContainsKey(0x0001))
			{
				var attr = coll[0x0001];
				if (attr.DataType == ZigbeeDataType.UInt16)
					MinMeasuredValue = ((ushort)attr.Data) / 100f;
			}
			if (coll.ContainsKey(0x0002))
			{
				var attr = coll[0x0002];
				if (attr.DataType == ZigbeeDataType.UInt16)
					MaxMeasuredValue = ((ushort)attr.Data) / 100f;
			}
			if (coll.ContainsKey(0x0003))
			{
				var attr = coll[0x0003];
				if (attr.DataType == ZigbeeDataType.UInt16)
					Tolerance = ((ushort)attr.Data) / 100f;
			}
		}
Пример #2
0
        void RetrieveAttributes(object attr)
        {
            var attributes = (IEnumerable <AttributeDefinition>)attr;

            AttributesCollection.AddRange(attributes);
            IsLoaded = true;
        }
Пример #3
0
        public void Given_Non_Member_Access_Expression_Throws()
        {
            var attrs = new AttributesCollection();

            Assert.Throws <NotSupportedException>(() => attrs[() => User.Name + "123"]);
            Assert.Throws <NotSupportedException>(() => attrs[() => User.Name + "123"] = "123");
        }
Пример #4
0
        public void When_Attribute_Not_Found_Should_Throw_AttributeMissingException()
        {
            var values    = new AttributesCollection();
            var condition = new Condition(() => User.Name == "John");

            Assert.Throws <AttributeMissingException>(() => condition.Evaluate(values));
        }
Пример #5
0
        public void Should_Evaluate_With_Given_Attribute_Values()
        {
            var attributes = new AttributesCollection();
            var condition  = new Condition(() => Document.Revision == 1);

            attributes[() => Document.Revision] = 0;
            condition.Evaluate(attributes).Should().BeFalse();

            attributes[() => Document.Revision] = 1;
            condition.Evaluate(attributes).Should().BeTrue();

            condition = new Condition(() => 1 <= Document.Revision);

            attributes[() => Document.Revision] = 0;
            condition.Evaluate(attributes).Should().BeFalse();

            attributes[() => Document.Revision] = 1;
            condition.Evaluate(attributes).Should().BeTrue();

            attributes[() => Document.Revision] = 2;
            condition.Evaluate(attributes).Should().BeTrue();

            condition = new Condition(() => User.IsBlocked);

            attributes[() => User.IsBlocked] = true;
            condition.Evaluate(attributes).Should().BeTrue();

            attributes[() => User.IsBlocked] = false;
            condition.Evaluate(attributes).Should().BeFalse();
        }
Пример #6
0
        public void Given_Index_For_Non_String_Type_Should_Work()
        {
            var attrs = new AttributesCollection
            {
                [() => Document.Revision] = 1
            };

            attrs[() => Document.Revision].Should().Be(1);
        }
Пример #7
0
        public void Given_Index_From_Non_Attributes_Class_Throws()
        {
            var attrs = new AttributesCollection();

            Assert.Throws <NotSupportedException>(() =>
                                                  attrs[() => NotAttributes.Group]);
            Assert.Throws <NotSupportedException>(() =>
                                                  attrs[() => NotAttributes.Group] = 123);
        }
Пример #8
0
        protected override void LoadInternal(bool attach = true)
        {
            if (!IsLoaded)
            {
                DataAccessManager.Instance.RetrieveAttributes(this, RetrieveAttributes);
            }

            if (attach)
            {
                AttributesCollection.AttachListView(CustomProvider.Instance.GetCustomList <CustomListViewControl <AttributeDefinition> >());
            }
        }
Пример #9
0
        public void Should_Return_True_When_Condition_And_Target_Match(bool targetMatch, bool conditionMatch, bool expectedResult)
        {
            var target    = new Condition(() => Values.TargetMatch);
            var condition = new Condition(() => Values.ConditionMatch);
            var rule      = new Rule(Effect.Permit, target, condition);
            var values    = new AttributesCollection
            {
                [() => Values.ConditionMatch] = conditionMatch,
                [() => Values.TargetMatch]    = targetMatch
            };

            rule.Evaluate(values).Should().Be(expectedResult);
        }
Пример #10
0
 public HtmlControlFromString(string html)
 {
     _document.LoadHtml(html);
     if (_document.DocumentNode.ChildNodes.Count > 0)
     {
         _htmlElement = _document.DocumentNode.ChildNodes[0];
         Attributes   = new AttributesCollection(_htmlElement);
         Attributes.AttributeChanged += new EventHandler(Attributes_AttributeChanged);
         SetHtml();
     }
     else
     {
         throw new InvalidOperationException("Argument does not contain a valid html element.");
     }
 }
Пример #11
0
        public void Should_Not_Evaluate_Complex_Conditions()
        {
            var attributes = new AttributesCollection
            {
                [() => User.Name]         = "John",
                [() => User.IsBlocked]    = false,
                [() => Document.Revision] = 1
            };

            var condition = new Condition(() =>
                                          User.Name != "John" &&
                                          User.IsBlocked &&
                                          Document.Revision > 0);

            condition.Evaluate(attributes).Should().BeFalse();
        }
Пример #12
0
        /// <summary>
        /// Test new MakeRequest
        /// </summary>
        public void Run()
        {
            state      = 0;
            phone      = "27026503011810";
            account    = "938744";
            attributes = new AttributesCollection();
            attributes.Add("id2", "9521822210");
            int r = MakeRequest(0);

            if (r == 0)
            {
                Console.WriteLine(stRequest);
            }
            else
            {
                Console.WriteLine($"Err = {r}");
            }
        }
Пример #13
0
        public void Should_Get_Set_Attribute_Value_By_Expression_Indexer()
        {
            var attrs = new AttributesCollection
            {
                [() => User.Name] = "John"
            };

            attrs[() => User.Name].Should().Be("John");

            ((IReadOnlyDictionary <string, object>)attrs)["User.Name"].Should().Be("John");

            attrs.Count.Should().Be(1);

            attrs.Keys.ToArray().Should().BeEquivalentTo("User.Name");

            attrs.Values.Cast <string>().ToArray().Should().BeEquivalentTo("John");

            attrs.ContainsKey("User.Name").Should().BeTrue();
            attrs.ContainsKey("Document.Revision").Should().BeFalse();

            object value;

            attrs.TryGetValue("User.Name", out value).Should().BeTrue();
            ((string)value).Should().Be("John");

            attrs.ToArray()
            .Should().HaveCount(1);

            IEnumerable a          = attrs;
            var         enumerator = a.GetEnumerator();

            enumerator.MoveNext().Should().BeTrue();
            enumerator.Current.Should().BeOfType <KeyValuePair <string, object> >();
            enumerator.Should().NotBeNull();
            var kvp = (KeyValuePair <string, object>)enumerator.Current;

            kvp.Key.Should().Be("User.Name");
            kvp.Value.Should().Be("John");
        }
Пример #14
0
 public TemperatureMeasurement(AttributesCollection coll)
 {
     MeasuredValue    = float.NaN;
     MinMeasuredValue = float.NaN;
     MaxMeasuredValue = float.NaN;
     Tolerance        = float.NaN;
     if (coll.ContainsKey(0x0000))
     {
         var attr = coll[0x0000];
         if (attr.DataType == ZigbeeDataType.Int16)
         {
             MeasuredValue = ((short)attr.Data) / 100f;
         }
     }
     if (coll.ContainsKey(0x0001))
     {
         var attr = coll[0x0001];
         if (attr.DataType == ZigbeeDataType.Int16)
         {
             MinMeasuredValue = ((short)attr.Data) / 100f;
         }
     }
     if (coll.ContainsKey(0x0002))
     {
         var attr = coll[0x0002];
         if (attr.DataType == ZigbeeDataType.Int16)
         {
             MaxMeasuredValue = ((short)attr.Data) / 100f;
         }
     }
     if (coll.ContainsKey(0x0003))
     {
         var attr = coll[0x0003];
         if (attr.DataType == ZigbeeDataType.UInt16)
         {
             Tolerance = ((ushort)attr.Data) / 100f;
         }
     }
 }
Пример #15
0
        /// <summary>
        /// Создание запроса. Скрывает базовый код.
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        public override int MakeRequest(int state)
        {
            string acnt = !string.IsNullOrEmpty(Account) ? Account : !string.IsNullOrEmpty(Card) ? Card : Phone;

            if (State == 0)
            {
                if (string.IsNullOrEmpty(acnt) || string.IsNullOrEmpty(pointid) || string.IsNullOrEmpty(Gateway))
                {
                    state   = 0;
                    errCode = 2;
                    errDesc = string.Format(ServerGateMessages.Err_NoDefaults, state);
                    RootLog($"Account=\"{Account}\"\r\nPhone=\"{Phone}\"\r\nCard=\"{Card}\"\r\nPointid=\"{pointid}\"\r\nGateway=\"{Gateway}\"");
                    RootLog(ErrDesc);
                    return(1);
                }

                if (Amount == decimal.MinusOne)
                {
                    state   = 0;
                    errCode = 2;
                    errDesc = ServerGateMessages.Err_NoAmount;
                    RootLog($"Pointid=\"{pointid}\"\r\nGateway=\"{Gateway}\"");
                    RootLog(ServerGateMessages.Err_NoAmount);
                    return(1);
                }
            }

            if (Pcdate == DateTime.MinValue)
            {
                pcdate = DateTime.Now;
            }
            int    lTz   = Tz != -1 ? Tz : Settings.Tz;
            string sDate = XConvert.AsDate(pcdate) + string.Format("+{0:D2}00", lTz);

            string sAmount     = Math.Round(Amount * 100).ToString();
            string sAmountAll  = Math.Round(AmountAll * 100).ToString();
            string check       = MakeCheckNumber();
            string sAttributes = "";

            stRequest = @"<?xml version=""1.0"" encoding=""utf-8""?>";

            if (state == 0)                                                          // Payment
            {
                if (!string.IsNullOrEmpty(Account) && !string.IsNullOrEmpty(Number)) // Атрибуты: id1 = account, id2 = number
                {
                    if (Attributes == null)
                    {
                        attributes = new AttributesCollection();
                    }
                    attributes.Add("id2", Number);
                }
                else if (!string.IsNullOrEmpty(Account) && !string.IsNullOrEmpty(Phone)) // Id1 и phone
                {
                    if (Attributes == null)
                    {
                        attributes = new AttributesCollection();
                    }
                    attributes.Add("phone", Phone);
                }

                foreach (string name in Attributes.Keys)
                {
                    sAttributes += $@"<attribute name=""{name}"" value=""{Attributes[name]}"" />";
                }

                stRequest += $@"<request point=""{pointid}"">";
                stRequest += $@"<payment id=""{Tid}"" sum=""{sAmount}"" check=""{check}"" service=""{Gateway}"" account=""{acnt}"" date=""{sDate}"">";
                if (!string.IsNullOrEmpty(sAttributes))
                {
                    stRequest += $"{sAttributes}";
                }
                stRequest += "</payment></request>";
            }
            else if (state == 3) // Status
            {
                stRequest += $"<request point=\"{pointid}\"><status id=\"{Tid}\" /></request>";
            }
            else
            {
                errDesc = string.Format(ServerGateMessages.Err_UnknownState, state);
                state   = 0;
                errCode = 2;
                RootLog(ErrDesc);
                return(1);
            }

            // ReportRequest();

            return(0);
        }
Пример #16
0
        public GWXsolllaRequest(GWRequest src) : base(src)
        {
            provider = src.Provider;

            templateName = src.TemplateName;

            tid            = src.Tid;
            transaction    = src.Transaction;
            terminal       = src.Terminal;
            terminalType   = src.TerminalType;
            realTerminalId = src.RealTerminalId;
            service        = src.Service;
            gateway        = src.Gateway;
            operdate       = src.Operdate;
            pcdate         = src.Pcdate;
            terminalDate   = src.TerminalDate;
            tz             = src.Tz;
            transaction    = src.Transaction;
            checkNumber    = src.CheckNumber;
            oid            = src.Oid;
            cur            = src.Cur;

            session = Properties.Settings.Default.SessionPrefix + tid.ToString();
            // session = src.Session;

            state = src.State;

            lastcode = src.Lastcode;
            lastdesc = src.Lastdesc;
            times    = src.Times;

            phone        = src.Phone;
            phoneParam   = src.PhoneParam;
            account      = src.Account;
            accountParam = src.AccountParam;
            card         = src.Card;

            amount    = src.Amount;
            amountAll = src.AmountAll;
            number    = src.Number;
            orgname   = src.Orgname;
            docnum    = src.Docnum;
            docdate   = src.Docdate;
            purpose   = src.Purpose;
            fio       = src.Fio;
            address   = src.Address;
            agree     = 1;
            contact   = src.Contact;
            inn       = src.Inn;
            comment   = src.Comment;

            acceptdate = src.Acceptdate;
            acceptCode = src.AcceptCode;
            outtid     = src.Outtid;
            addinfo    = src.AddInfo;
            errMsg     = src.ErrMsg;
            opname     = src.Opname;
            opcode     = src.Opcode;

            pause = src.Pause;

            kpp      = src.Kpp;
            payerInn = src.PayerInn;
            ben      = src.Ben;
            bik      = src.Bik;
            tax      = src.Tax;
            kbk      = src.KBK;
            okato    = src.OKATO;
            payType  = src.PayType;
            reason   = src.Reason;

            statusType = src.StatusType;
            startDate  = src.StartDate;
            endDate    = src.EndDate;

            attributes = new AttributesCollection();
            attributes.Add(src.Attributes);


            InitializeComponents();
        }
Пример #17
0
		public ReportAttributesResponse(byte[] payload)
			: base(payload)
		{
			int start = IsManufacturerSpecific ? 9 : 8;
			var attr = new List<AttributeRecord>(AttributeCount);
			for (int i = 0; i < AttributeCount; i++)
			{
				int length = 0;
				AttributeRecord rec = new AttributeRecord(payload, start, out length);
				attr.Add(rec);
				start += length;
			}
			Attributes = new AttributesCollection(attr);
		}
Пример #18
0
        /// <summary>
        /// Создание запроса. Скрывает базовый код.
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        public override int MakeRequest(int state)
        {
            string acnt = !string.IsNullOrEmpty(Account) ? Account : !string.IsNullOrEmpty(Card) ? Card : Phone;

            if (State == 0)
            {
                if (string.IsNullOrEmpty(acnt) || string.IsNullOrEmpty(pointid) || string.IsNullOrEmpty(Gateway))
                {
                    state   = 0;
                    errCode = 2;
                    errDesc = string.Format(Messages.Err_NoDefaults, state);
                    RootLog($"Account=\"{Account}\"\r\nPhone=\"{Phone}\"\r\nCard=\"{Card}\"\r\nPointid=\"{pointid}\"\r\nGateway=\"{Gateway}\"");
                    RootLog(ErrDesc);
                    return(1);
                }

                if (Amount == decimal.MinusOne)
                {
                    state   = 0;
                    errCode = 2;
                    errDesc = Messages.Err_NoAmount;
                    RootLog($"Pointid=\"{pointid}\"\r\nGateway=\"{Gateway}\"");
                    RootLog(Messages.Err_NoAmount);
                    return(1);
                }
            }

            if (Pcdate == DateTime.MinValue)
            {
                pcdate = DateTime.Now;
            }
            int    lTz   = Tz != -1? Tz: Settings.Tz;
            string sDate = XConvert.AsDate(pcdate) + string.Format("+{0:D2}00", lTz);

            string sAmount     = Math.Round(Amount * 100).ToString();
            string sAmountAll  = Math.Round(AmountAll * 100).ToString();
            string check       = MakeCheckNumber();
            string sAttributes = "";

            stRequest = Properties.Resources.Template_XmlHeader + "\r\n";

            if (state == 0) // Payment
            {
                /*
                 * <request point="{0}">
                 *      <payment account="{1}" service="{2}" sum="{3}" sum-in="{4}" id="{5}" check="{6}" date="{7}">
                 *      <attribute name="id2" value="{8}" />
                 *      </payment>
                 * </request>
                 */

                if (!string.IsNullOrEmpty(Account) && !string.IsNullOrEmpty(Number)) // Атрибуты: id1 = account, id2 = number
                {
                    if (Attributes == null)
                    {
                        attributes = new AttributesCollection();
                    }
                    attributes.Add("id2", Number);
                }
                else if (!string.IsNullOrEmpty(Account) && !string.IsNullOrEmpty(Phone)) // Id1 и phone
                {
                    if (Attributes == null)
                    {
                        attributes = new AttributesCollection();
                    }
                    attributes.Add("phone", Phone);
                }

                foreach (string name in Attributes.Keys)
                {
                    sAttributes += $@"<attribute name=""{name}"" value=""{Attributes[name]}"" />";
                }

                stRequest += $@"<request point=""{pointid}"">";
                stRequest += $@"<payment id=""{Tid}"" sum=""{sAmount}"" sum-in=""{sAmountAll}"" check=""{check}"" service=""{Gateway}"" account=""{acnt}"" date=""{sDate}""";
                if (Terminal != int.MinValue)
                {
                    stRequest += $@" terminal-vps-id=""{Terminal}""";
                }
                stRequest += ">";
                if (!string.IsNullOrEmpty(sAttributes))
                {
                    stRequest += $"{sAttributes}";
                }
                stRequest += "</payment></request>";

                /*
                 * if (Gateway == "1668")
                 *                      stRequest += string.Format(Properties.Resources.Template_Payment_1668, pointid, Card, Gateway, sAmount, sAmountAll, Tid, MakeCheckNumber(), sDate, Phone);
                 *              // Единый кошелёк
                 *              else if (Gateway == "458")
                 *                      {
                 *                      if (Account.Length > 10 || (Account.Length == 10 && Account.Substring(0) != "9")) // Лицевой счёт
                 *                              stRequest += string.Format(Properties.Resources.Template_Id1, pointid, Account, Gateway, sAmount, sAmountAll, Tid, MakeCheckNumber(), sDate);
                 *                      else // Номер телефона
                 *                              stRequest += string.Format(Properties.Resources.Template_Id1, pointid, Gateway, sAmount, sAmountAll, Tid, MakeCheckNumber(), sDate, Account);
                 *                      }
                 *              else if (!string.IsNullOrEmpty(Account) && !string.IsNullOrEmpty(Number)) // Атрибуты: id1 = account, id2 = number
                 *  stRequest += string.Format(Properties.Resources.Template_Payment_Id1Id2, pointid, Gateway, sAmount, sAmountAll, Tid, MakeCheckNumber(), sDate, Account, Number);
                 *              else
                 * if (!string.IsNullOrEmpty(Account) && !string.IsNullOrEmpty(Phone)) // Id1 и phone
                 *                      stRequest += string.Format(Properties.Resources.Template_Payment_Id1Phone, pointid, Gateway, sAmount, sAmountAll, Tid, MakeCheckNumber(), sDate, Account, Phone);
                 *              else if (string.IsNullOrEmpty(Account) && string.IsNullOrEmpty(Phone) && Attributes?.Count > 0) // Есть дополнительные атрибуты
                 *                      {
                 *                      StringBuilder sb = new StringBuilder();
                 *                      sb.Append($"<request point=\"{pointid}\">\r\n");
                 *                      sb.AppendFormat("\t<payment account=\"{0}\" service=\"{1}\" sum=\"{2}\" sum-in=\"{3}\" id=\"{4}\" check=\"{5}\" date={6}>\r\n",
                 *                              string.IsNullOrEmpty(Phone) ? Account : Phone,	// Номер телефона или счёта
                 *                              Gateway,										// Номер шлюза ЕКТ
                 *                              sAmount,					                    // amount
                 *                              sAmountAll,                                     // summary_amount
                 *                              Tid.ToString(),
                 *                              MakeCheckNumber(),								// Номер чека
                 *                              sDate											// Время платежа
                 *                              );
                 *                      // Добавляется коллекция атрибутов
                 *                      foreach (string name in Attributes.Keys)
                 *      sb.Append($"\t\t<attribute name=\"{name}\" value=\"{Attributes[name]}\" />\r\n");
                 *  sb.Append("\t/<payment>\r\n");
                 *                      sb.Append("/<request>");
                 *                      stRequest += sb.ToString();
                 *                      }
                 *              else
                 *                      {
                 *                      StringBuilder sb = new StringBuilder();
                 *                      // Добавляется коллекция атрибутов
                 *                      foreach (string name in Attributes.Keys)
                 *                              sb.Append($"\t\t<attribute name=\"{name}\" value=\"{Attributes[name]}\" />\r\n");
                 *                      stRequest += string.Format(Properties.Resources.Template_Payment, pointid,
                 *                              string.IsNullOrEmpty(Phone) ? Account : Phone, Gateway, // Номер сервиса ЕКТ,
                 *                              sAmount,
                 *      AmountAll == -1? sAmount: sAmountAll,
                 *                              Tid,
                 *      MakeCheckNumber(),
                 *      sDate,
                 *      sb.ToString());
                 *                      }
                 */
            }
            else if (state == 3)             // Status
            {
                stRequest += string.Format(Properties.Resources.Template_Status, pointid, Tid);
            }
            else
            {
                errDesc = string.Format(Messages.Err_UnknownState, state);
                state   = 0;
                errCode = 2;
                RootLog(ErrDesc);
                return(1);
            }

            // ReportRequest();

            return(0);
        }
Пример #19
0
 protected override void UnLoadInternal()
 {
     AttributesCollection.DetachListView();
 }
Пример #20
0
	public static object SetDictionaryValue (object self, SymbolId name, object value)
	{
		IAttributesCollection dict = new AttributesCollection ();
		return dict [name] = value;
	}
Пример #21
0
    public static object SetDictionaryValue(object self, SymbolId name, object value)
    {
        IAttributesCollection dict = new AttributesCollection();

        return(dict [name] = value);
    }
 public static AttributesCollection GetAll() {
     resourceSchema.Dal.Attributes dbo = null;
     try {
         dbo = new resourceSchema.Dal.Attributes();
         System.Data.DataSet ds = dbo.Attributes_Select_All();
         AttributesCollection collection = new AttributesCollection();
         if (GlobalTools.IsSafeDataSet(ds)) {
             for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1)) {
                 Attributes obj = new Attributes();
                 obj.Fill(ds.Tables[0].Rows[i]);
                 if ((obj != null)) {
                     collection.Add(obj);
                 }
             }
         }
         return collection;
     }
     catch (System.Exception ) {
         throw;
     }
     finally {
         if ((dbo != null)) {
             dbo.Dispose();
         }
     }
 }