Exemple #1
0
        /// <summary>
        /// Sets properties and attributes of class in accordance with XML definition.
        /// </summary>
        /// <param name="Definition">XML definition</param>
        public override Task FromXml(XmlElement Definition)
        {
            this.name      = XML.Attribute(Definition, "name");
            this.exclusive = XML.Attribute(Definition, "exclusive", true);

            return(base.FromXml(Definition));
        }
Exemple #2
0
        /// <summary>
        /// Sets properties and attributes of class in accordance with XML definition.
        /// </summary>
        /// <param name="Definition">XML definition</param>
        public override async Task FromXml(XmlElement Definition)
        {
            this.rsaKeyName = new StringAttribute(XML.Attribute(Definition, "rsaKeyName"));
            this.rsaKeySize = XML.Attribute(Definition, "rsaKeySize", 0);

            foreach (XmlNode N in Definition.ChildNodes)
            {
                if (N is XmlElement E)
                {
                    if (!(this.value is null))
                    {
                        throw new Exception("The Sign element can only have one value child element.");
                    }

                    ISimulationNode Node = await Factory.Create(E, this, this.Model);

                    if (Node is IValue Value)
                    {
                        this.value = Value;
                    }
                    else
                    {
                        throw new Exception("The Sign element only accepts a value child element.");
                    }
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Sets properties and attributes of class in accordance with XML definition.
        /// </summary>
        /// <param name="Definition">XML definition</param>
        public override Task FromXml(XmlElement Definition)
        {
            this.domain          = XML.Attribute(Definition, "domain");
            this.userName        = XML.Attribute(Definition, "userName");
            this.apiKey          = XML.Attribute(Definition, "apiKey");
            this.secret          = XML.Attribute(Definition, "secret");
            this.alwaysConnected = XML.Attribute(Definition, "alwaysConnected", false);

            if (Definition.HasAttribute("port"))
            {
                this.port = XML.Attribute(Definition, "port", 0);
            }
            else
            {
                this.port = null;
            }

            this.allowCramMD5           = XML.Attribute(Definition, "allowCramMD5", false);
            this.allowDigestMD5         = XML.Attribute(Definition, "allowDigestMD5", false);
            this.allowEncryption        = XML.Attribute(Definition, "allowEncryption", true);
            this.allowPlain             = XML.Attribute(Definition, "allowPlain", false);
            this.allowScramSHA1         = XML.Attribute(Definition, "allowScramSHA1", true);
            this.allowScramSHA256       = XML.Attribute(Definition, "allowScramSHA256", true);
            this.requestRosterOnStartup = XML.Attribute(Definition, "requestRosterOnStartup", true);
            this.trustServer            = XML.Attribute(Definition, "trustServer", false);

            return(base.FromXml(Definition));
        }
Exemple #4
0
        /// <summary>
        /// Sets properties and attributes of class in accordance with XML definition.
        /// </summary>
        /// <param name="Definition">XML definition</param>
        public override Task FromXml(XmlElement Definition)
        {
            this.actor = XML.Attribute(Definition, "actor");
            this.queue = XML.Attribute(Definition, "queue");

            return(base.FromXml(Definition));
        }
Exemple #5
0
        /// <summary>
        /// Sets properties and attributes of class in accordance with XML definition.
        /// </summary>
        /// <param name="Definition">XML definition</param>
        public override Task FromXml(XmlElement Definition)
        {
            this.value = Definition.InnerText;
            this.label = XML.Attribute(Definition, "label");

            return(Task.CompletedTask);
        }
Exemple #6
0
        /// <summary>
        /// Sets properties and attributes of class in accordance with XML definition.
        /// </summary>
        /// <param name="Definition">XML definition</param>
        public override Task FromXml(XmlElement Definition)
        {
            this.condition  = XML.Attribute(Definition, "condition");
            this.expression = new Expression(this.condition);

            return(base.FromXml(Definition));
        }
Exemple #7
0
        internal RosterItem(XmlElement Item)
        {
            this.bareJid = XML.Attribute(Item, "jid");
            this.name    = XML.Attribute(Item, "name");

            switch (XML.Attribute(Item, "subscription"))
            {
            case "both":
                this.state = SubscriptionState.Both;
                break;

            case "to":
                this.state = SubscriptionState.To;
                break;

            case "from":
                this.state = SubscriptionState.From;
                break;

            case "none":
            case "":
                this.state = SubscriptionState.None;
                break;

            case "remove":
                this.state = SubscriptionState.Remove;
                break;

            default:
                this.state = SubscriptionState.Unknown;
                break;
            }

            switch (XML.Attribute(Item, "ask").ToLower())
            {
            case "subscribe":
                this.pendingSubscription = PendingSubscription.Subscribe;
                break;

            case "unsubscribe":
                this.pendingSubscription = PendingSubscription.Unsubscribe;
                break;

            default:
                this.pendingSubscription = PendingSubscription.None;
                break;
            }

            List <string> Groups = new List <string>();

            foreach (XmlNode N in Item.ChildNodes)
            {
                if (N.LocalName == "group")
                {
                    Groups.Add(N.InnerText);
                }
            }

            this.groups = Groups.ToArray();
        }
Exemple #8
0
 internal Identity(XmlElement E)
 {
     this.category = XML.Attribute(E, "category");
     this.type     = XML.Attribute(E, "type");
     this.name     = XML.Attribute(E, "name");
     this.language = XML.Attribute(E, "xml:lang");
 }
Exemple #9
0
        /// <summary>
        /// Sets properties and attributes of class in accordance with XML definition.
        /// </summary>
        /// <param name="Definition">XML definition</param>
        public override Task FromXml(XmlElement Definition)
        {
            this.topic = XML.Attribute(Definition, "topic");
            this.qos   = (MqttQualityOfService)XML.Attribute(Definition, "qos", MqttQualityOfService.AtMostOnce);

            return(Task.CompletedTask);
        }
        /// <summary>
        /// Sets properties and attributes of class in accordance with XML definition.
        /// </summary>
        /// <param name="Definition">XML definition</param>
        public override Task FromXml(XmlElement Definition)
        {
            this.unit       = XML.Attribute(Definition, "unit");
            this.nrDecimals = (byte)XML.Attribute(Definition, "nrDecimals", 0);

            return(base.FromXml(Definition));
        }
Exemple #11
0
        /// <summary>
        /// Sets properties and attributes of class in accordance with XML definition.
        /// </summary>
        /// <param name="Definition">XML definition</param>
        public override Task FromXml(XmlElement Definition)
        {
            this.category = XML.Attribute(Definition, "category");
            this.instance = XML.Attribute(Definition, "instance");
            this.counter  = XML.Attribute(Definition, "counter");

            if (Definition.HasAttribute("multiplier"))
            {
                this.multiplier = XML.Attribute(Definition, "multiplier", 1.0);
            }
            else
            {
                this.multiplier = null;
            }

            if (Definition.HasAttribute("divider"))
            {
                this.divider = XML.Attribute(Definition, "divider", 1.0);
            }
            else
            {
                this.divider = null;
            }

            return(Task.CompletedTask);
        }
Exemple #12
0
        private void IsFriendCallback(object Sender, IqResultEventArgs e)
        {
            object[]         P        = (object[])e.State;
            IsFriendCallback Callback = (IsFriendCallback)P[0];
            object           State    = P[1];
            string           JID;
            bool             Result;
            XmlElement       E = e.FirstElement;

            if (e.Ok && E != null && E.LocalName == "isFriendResponse" && E.NamespaceURI == NamespaceProvisioningDevice)
            {
                JID    = XML.Attribute(E, "jid");
                Result = XML.Attribute(E, "result", false);
            }
            else
            {
                Result = false;
                JID    = null;
            }

            IsFriendResponseEventArgs e2 = new IsFriendResponseEventArgs(e, State, JID, Result);

            try
            {
                Callback(this, e2);
            }
            catch (Exception ex)
            {
                Log.Critical(ex);
            }
        }
Exemple #13
0
        private void GetTokenResponse(object Sender, IqResultEventArgs e)
        {
            object[] P = (object[])e.State;
#if WINDOWS_UWP
            Certificate Certificate = (Certificate)P[0];
#else
            X509Certificate2 Certificate = (X509Certificate2)P[0];
#endif
            XmlElement E = e.FirstElement;

            if (e.Ok && E != null && E.LocalName == "getTokenChallenge" && E.NamespaceURI == NamespaceProvisioningToken)
            {
                int    SeqNr     = XML.Attribute(E, "seqnr", 0);
                string Challenge = E.InnerText;
                byte[] Bin       = System.Convert.FromBase64String(Challenge);

#if WINDOWS_UWP
                CryptographicKey Key = PersistedKeyProvider.OpenPublicKeyFromCertificate(Certificate,
                                                                                         Certificate.SignatureHashAlgorithmName, CryptographicPadding.RsaPkcs1V15);
                IBuffer Buffer = CryptographicBuffer.CreateFromByteArray(Bin);
                Buffer = CryptographicEngine.Decrypt(Key, Buffer, null);
                CryptographicBuffer.CopyToByteArray(Buffer, out Bin);
                string Response = System.Convert.ToBase64String(Bin);
#else
                Bin = Certificate.GetRSAPrivateKey().Decrypt(Bin, RSAEncryptionPadding.Pkcs1);
                string Response = System.Convert.ToBase64String(Bin);
#endif

                this.client.SendIqGet(this.provisioningServerAddress, "<getTokenChallengeResponse xmlns='" + NamespaceProvisioningToken + "' seqnr='" +
                                      SeqNr.ToString() + "'>" + Response + "</getTokenChallengeResponse>",
                                      this.GetTokenChallengeResponse, P);
            }
        }
Exemple #14
0
        /// <summary>
        /// Sets properties and attributes of class in accordance with XML definition.
        /// </summary>
        /// <param name="Definition">XML definition</param>
        public override Task FromXml(XmlElement Definition)
        {
            this.id = XML.Attribute(Definition, "id");
            this.n  = XML.Attribute(Definition, "N", 0.0);

            return(Task.CompletedTask);
        }
Exemple #15
0
        private void CancelHandler(object Sender, IqEventArgs e)
        {
            SensorDataServerRequest Request;
            string Id  = XML.Attribute(e.Query, "id");
            string Key = e.From + " " + Id;

            lock (this.requests)
            {
                if (this.requests.TryGetValue(Key, out Request))
                {
                    this.requests.Remove(Key);
                }
                else
                {
                    Request = null;
                }
            }

            if (Request != null && !Request.Started)
            {
                this.scheduler.Remove(Request.When);
            }

            e.IqResult(string.Empty);
        }
 /// <summary>
 /// Data Source Reference
 /// </summary>
 /// <param name="E">XML Definition.</param>
 public DataSourceReference(XmlElement E)
 {
     this.sourceID    = XML.Attribute(E, "src");
     this.name        = XML.Attribute(E, "name");
     this.hasChildren = XML.Attribute(E, "hasChildren", false);
     this.lastChanged = XML.Attribute(E, "lastChanged", DateTime.MinValue);
 }
        private void RemovedHandler(object Sender, IqEventArgs e)
        {
            XmlElement     E         = e.Query;
            string         NodeId    = XML.Attribute(E, "id");
            string         SourceId  = XML.Attribute(E, "src");
            string         Partition = XML.Attribute(E, "pt");
            ThingReference Node;

            if (string.IsNullOrEmpty(NodeId) && string.IsNullOrEmpty(SourceId) && string.IsNullOrEmpty(Partition))
            {
                Node = ThingReference.Empty;
            }
            else
            {
                Node = new ThingReference(NodeId, SourceId, Partition);
            }

            NodeEventArgs    e2 = new NodeEventArgs(e, Node);
            NodeEventHandler h  = this.Removed;

            if (h != null)
            {
                try
                {
                    h(this, e2);
                }
                catch (Exception ex)
                {
                    Log.Critical(ex);
                }
            }

            e.IqResult(string.Empty);
        }
Exemple #18
0
        internal static void ChunkReceived(object Sender, MessageEventArgs e)
        {
            string StreamId = XML.Attribute(e.Content, "streamId");
            string Key      = e.From + " " + StreamId;

            if (!chunkedStreams.TryGetValue(Key, out ChunkRecord Rec))
            {
                return;
            }

            int Nr = XML.Attribute(e.Content, "nr", 0);

            if (Nr < 0)
            {
                return;
            }

            bool Last = XML.Attribute(e.Content, "last", false);

            byte[] Data = Convert.FromBase64String(e.Content.InnerText);

            if (!Rec.ChunkReceived(Nr, Last, Data))
            {
                Rec.Dispose();
                chunkedStreams.Remove(Key);
            }
        }
Exemple #19
0
 /// <summary>
 /// Represents a published item.
 /// </summary>
 /// <param name="Node">Node name.</param>
 /// <param name="Xml">XML definition.</param>
 public PubSubItem(string Node, XmlElement Xml)
 {
     this.node      = Node;
     this.itemId    = XML.Attribute(Xml, "id");
     this.publisher = XML.Attribute(Xml, "publisher");
     this.payload   = Xml.InnerXml;
 }
Exemple #20
0
        /// <summary>
        /// Sets properties and attributes of class in accordance with XML definition.
        /// </summary>
        /// <param name="Definition">XML definition</param>
        public override Task FromXml(XmlElement Definition)
        {
            this.period     = XML.Attribute(Definition, "period", Duration.Zero);
            this.isPeriodic = this.period > Duration.Zero;

            return(base.FromXml(Definition));
        }
Exemple #21
0
        /// <summary>
        /// Sets properties and attributes of class in accordance with XML definition.
        /// </summary>
        /// <param name="Definition">XML definition</param>
        public override Task FromXml(XmlElement Definition)
        {
            this.id = XML.Attribute(Definition, "id");
            this.n  = XML.Attribute(Definition, "N", 0);

            return(base.FromXml(Definition));
        }
        /// <summary>
        /// Sets properties and attributes of class in accordance with XML definition.
        /// </summary>
        /// <param name="Definition">XML definition</param>
        public override Task FromXml(XmlElement Definition)
        {
            this.actor        = new StringAttribute(XML.Attribute(Definition, "actor"));
            this.availability = (Availability)XML.Attribute(Definition, "availability", Availability.Online);

            return(base.FromXml(Definition));
        }
        /// <summary>
        /// Sets properties and attributes of class in accordance with XML definition.
        /// </summary>
        /// <param name="Definition">XML definition</param>
        public override async Task FromXml(XmlElement Definition)
        {
            this.enumTypeName = XML.Attribute(Definition, "enumType");
            this.enumType     = Types.GetType(this.enumTypeName);

            if (this.enumType is null)
            {
                throw new Exception("Type not recognized: " + this.enumTypeName);
            }

            TypeInfo TI = this.enumType.GetTypeInfo();

            if (!TI.IsEnum)
            {
                throw new Exception("Type not an enumeration type: " + this.enumTypeName);
            }

            await base.FromXml(Definition);

            List <string> Labels = new List <string>();

            foreach (ISimulationNode Node in this.Children)
            {
                if (Node is Label Label)
                {
                    Labels.Add(Label.Value);
                }
            }

            this.labels = Labels.ToArray();
        }
Exemple #24
0
        /// <summary>
        /// Sets properties and attributes of class in accordance with XML definition.
        /// </summary>
        /// <param name="Definition">XML definition</param>
        public override Task FromXml(XmlElement Definition)
        {
            this.actor = new StringAttribute(XML.Attribute(Definition, "actor"));
            this.to    = new StringAttribute(XML.Attribute(Definition, "to"));

            return(base.FromXml(Definition));
        }
        /// <summary>
        /// Event arguments for responses to IQ queries.
        /// </summary>
        /// <param name="Response">Response element.</param>
        /// <param name="Id">ID attribute.</param>
        /// <param name="To">To attribute.</param>
        /// <param name="From">From attribute.</param>
        /// <param name="Ok">If response is a proper response (true), or an error response (false).</param>
        /// <param name="State">State object passed in the original request.</param>
        public IqResultEventArgs(XmlElement Response, string Id, string To, string From, bool Ok, object State)
        {
            XmlElement E;

            this.response  = Response;
            this.id        = Id;
            this.to        = To;
            this.from      = From;
            this.ok        = Ok;
            this.state     = State;
            this.errorCode = 0;

            if (!Ok && Response != null)
            {
                foreach (XmlNode N in Response.ChildNodes)
                {
                    E = N as XmlElement;
                    if (E is null)
                    {
                        continue;
                    }

                    if (E.LocalName == "error" && E.NamespaceURI == Response.NamespaceURI)
                    {
                        this.errorElement = E;
                        this.errorCode    = XML.Attribute(E, "code", 0);

                        switch (XML.Attribute(E, "type"))
                        {
                        case "auth":
                            this.errorType = ErrorType.Auth;
                            break;

                        case "cancel":
                            this.errorType = ErrorType.Cancel;
                            break;

                        case "continue":
                            this.errorType = ErrorType.Continue;
                            break;

                        case "modify":
                            this.errorType = ErrorType.Modify;
                            break;

                        case "wait":
                            this.errorType = ErrorType.Wait;
                            break;

                        default:
                            this.errorType = ErrorType.Undefined;
                            break;
                        }

                        this.stanzaError = XmppClient.GetStanzaExceptionObject(E);
                        this.errorText   = this.stanzaError.Message;
                    }
                }
            }
        }
Exemple #26
0
        /// <summary>
        /// Event argument for a bits-of-byte data request.
        /// </summary>
        /// <param name="e">IQ response.</param>
        public BitsOfBinaryEventArgs(IqResultEventArgs e)
            : base(e)
        {
            XmlElement E;

            if (e.Ok && (E = e.FirstElement) != null)
            {
                this.contentId   = XML.Attribute(E, "cid");
                this.contentType = XML.Attribute(E, "type");

                int MaxAge = XML.Attribute(E, "max-age", -1);
                if (MaxAge > 0)
                {
                    this.expires = DateTime.Now.AddSeconds(MaxAge);
                }

                this.data = Convert.FromBase64String(E.InnerText);
            }
            else
            {
                this.contentId   = null;
                this.contentType = null;
                this.data        = null;
                this.expires     = null;
            }
        }
Exemple #27
0
        private void UnblockPushHandler(object Sender, IqEventArgs e)
        {
            XmlElement E;
            string     JID;
            bool       Found = false;

            lock (this.blockList)
            {
                foreach (XmlNode N in e.Query.ChildNodes)
                {
                    E = N as XmlElement;
                    if (E != null && E.LocalName == "item")
                    {
                        Found = true;
                        JID   = XML.Attribute(E, "jid");
                        this.blockList.Remove(JID);
                    }
                }

                if (!Found)
                {
                    this.blockList.Clear();
                }
            }
        }
Exemple #28
0
        /// <summary>
        /// Sets properties and attributes of class in accordance with XML definition.
        /// </summary>
        /// <param name="Definition">XML definition</param>
        public override Task FromXml(XmlElement Definition)
        {
            this.name     = XML.Attribute(Definition, "name");
            this.variable = XML.Attribute(Definition, "variable");

            return(Task.CompletedTask);
        }
Exemple #29
0
        internal Section(DataForm Form, XmlElement E)
            : base(Form)
        {
            List <LayoutElement> Elements = new List <LayoutElement>();

            this.label = XML.Attribute(E, "label");

            foreach (XmlNode N in E.ChildNodes)
            {
                switch (N.LocalName)
                {
                case "text":
                    Elements.Add(new TextElement(this.Form, (XmlElement)N));
                    break;

                case "section":
                    Elements.Add(new Section(this.Form, (XmlElement)N));
                    break;

                case "fieldref":
                    Elements.Add(new FieldReference(this.Form, (XmlElement)N));
                    break;

                case "reportedref":
                    Elements.Add(new ReportedReference(this.Form));
                    break;
                }
            }

            this.staticElements = Elements.ToArray();
        }
Exemple #30
0
        /// <summary>
        /// Sets properties and attributes of class in accordance with XML definition.
        /// </summary>
        /// <param name="Definition">XML definition</param>
        public override Task FromXml(XmlElement Definition)
        {
            this.windowSize = XML.Attribute(Definition, "windowSize", 0);
            this.threshold  = XML.Attribute(Definition, "threshold", 0);
            this.smooth     = XML.Attribute(Definition, "smooth", false);
            this.logNotice  = XML.Attribute(Definition, "logNotice", true);
            this.max        = Definition.HasAttribute("max") ? XML.Attribute(Definition, "max", 0.0) : (double?)null;
            this.min        = Definition.HasAttribute("min") ? XML.Attribute(Definition, "min", 0.0) : (double?)null;

            if (this.windowSize < 1)
            {
                throw new Exception("Windows size must be positive.");
            }

            if (this.threshold < 1)
            {
                throw new Exception("Threshold must be positive.");
            }

            this.timespans = new DateTime[this.windowSize];
            this.values    = new double?[this.windowSize];
            this.sum       = 0;
            this.count     = 0;
            this.pos       = 0;
            this.avgPos    = this.count / 2;

            return(base.FromXml(Definition));
        }