Ejemplo n.º 1
0
        private int GetNeueNummer()
        {
            int    Rid;
            string RechnungID = (DateTime.Now.Year).ToString() + "5000";

            Int32.TryParse(RechnungID, out Rid);

            var q = this.priProRechnungTableAdapter.ScalarQueryMaxID();

            if (q != null)
            {
                int liefer;
                if (Int32.TryParse(q.ToString(), out liefer))
                {
                    Rid = liefer + 1;
                }

                // die Jahreszahlumstellung
                string LidJahrString       = Rid.ToString().Substring(0, 4);
                string aktuellesJahrString = (DateTime.Now.Year).ToString();
                if (LidJahrString.Equals(aktuellesJahrString) == false)
                {
                    string neuLid = (DateTime.Now.Year).ToString() + "0001";
                    Int32.TryParse(neuLid, out Rid);
                }
            }



            return(Rid);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sends a text packet.
        /// </summary>
        /// <param name="Packet">Text packet.</param>
        /// <param name="DeliveryCallback">Optional method to call when packet has been delivered.</param>
        public override async Task <bool> SendAsync(string Packet, EventHandler DeliveryCallback)
        {
            if (this.terminated)
            {
                return(false);
            }

            try
            {
                LinkedList <KeyValuePair <string, EventHandler> > Queued = null;
                StringBuilder Xml;
                long          Rid;
                int           ClientIndex = -1;
                bool          AllInactive = false;
                bool          Restart     = false;
                bool          HasSniffers = this.xmppClient.HasSniffers;
                int           i;

                if (Packet.StartsWith("<?"))
                {
                    Packet  = null;
                    Restart = true;
                }

                do
                {
                    lock (this.httpClients)
                    {
                        if (ClientIndex < 0)
                        {
                            for (ClientIndex = 0; ClientIndex < this.requests; ClientIndex++)
                            {
                                if (!this.active[ClientIndex])
                                {
                                    break;
                                }
                            }

                            if (ClientIndex >= this.requests)
                            {
                                if (!string.IsNullOrEmpty(Packet))
                                {
                                    this.xmppClient?.Information("Outbound stanza queued.");
                                    this.outputQueue.AddLast(new KeyValuePair <string, EventHandler>(Packet, DeliveryCallback));
                                }

                                if (Queued != null)
                                {
                                    LinkedListNode <KeyValuePair <string, EventHandler> > Loop = Queued.Last;

                                    while (Loop != null)
                                    {
                                        this.outputQueue.AddFirst(Loop.Value);
                                        Loop = Loop.Previous;
                                    }
                                }

                                return(true);
                            }

                            this.active[ClientIndex] = true;

                            if (this.outputQueue.First != null)
                            {
                                Queued           = this.outputQueue;
                                this.outputQueue = new LinkedList <KeyValuePair <string, EventHandler> >();
                            }
                        }

                        Rid = this.rid++;

                        Xml = new StringBuilder();

                        Xml.Append("<body rid='");
                        Xml.Append(Rid.ToString());
                        Xml.Append("' sid='");
                        Xml.Append(this.sid);
                        Xml.Append("' key='");
                        Xml.Append(this.keys.First.Value);

                        this.keys.RemoveFirst();
                        if (this.keys.First is null)
                        {
                            this.GenerateKeysLocked();

                            Xml.Append("' newkey='");
                            Xml.Append(this.keys.First.Value);
                            this.keys.RemoveFirst();
                        }
                    }

#if ECHO
                    Xml.Append("' echo='");
                    Xml.Append(ClientIndex.ToString());
#endif
                    Xml.Append("' xmlns='");
                    Xml.Append(HttpBindNamespace);

                    if (Restart)
                    {
                        Xml.Append("' xmpp:restart='true' xmlns:xmpp='");
                        Xml.Append(BoshNamespace);
                    }

                    Xml.Append("'>");

                    if (Queued != null)
                    {
                        foreach (KeyValuePair <string, EventHandler> P in Queued)
                        {
                            await this.RaiseOnSent(P.Key);

                            Xml.Append(P.Key);

                            if (P.Value != null)
                            {
                                try
                                {
                                    P.Value(this, new EventArgs());
                                }
                                catch (Exception ex)
                                {
                                    Log.Critical(ex);
                                }
                            }
                        }
                    }

                    if (Packet != null)
                    {
                        await this.RaiseOnSent(Packet);

                        Xml.Append(Packet);

                        if (DeliveryCallback != null)
                        {
                            try
                            {
                                DeliveryCallback(this.xmppClient, new EventArgs());
                            }
                            catch (Exception ex)
                            {
                                Log.Critical(ex);
                            }
                        }

                        Packet           = null;
                        DeliveryCallback = null;
                    }

                    Xml.Append("</body>");

                    string s = Xml.ToString();

                    if (this.disposed)
                    {
                        break;
                    }

                    if (HasSniffers)
                    {
                        this.xmppClient?.TransmitText(s);
                    }

                    HttpContent Content = new StringContent(s, System.Text.Encoding.UTF8, "text/xml");

                    this.bindingInterface.NextPing = DateTime.Now.AddSeconds(this.waitSeconds + 5);

                    HttpResponseMessage Response = await this.httpClients[ClientIndex].PostAsync(this.url, Content);
                    Response.EnsureSuccessStatusCode();

                    lock (this.httpClients)
                    {
                        if (this.outputQueue.First != null)
                        {
                            Queued           = this.outputQueue;
                            this.outputQueue = new LinkedList <KeyValuePair <string, EventHandler> >();
                        }
                        else
                        {
                            AllInactive = true;
                            Queued      = null;

                            for (i = 0; i < this.requests; i++)
                            {
                                if (i != ClientIndex && this.active[i])
                                {
                                    AllInactive = false;
                                    break;
                                }
                            }

                            if (!AllInactive)
                            {
                                this.active[ClientIndex] = false;
                                ClientIndex = -1;
                            }
                        }
                    }

                    Stream Stream = await Response.Content.ReadAsStreamAsync();                     // Regardless of status code, we check for XML content.

                    byte[] Bin = await Response.Content.ReadAsByteArrayAsync();

                    string   CharSet = Response.Content.Headers.ContentType.CharSet;
                    Encoding Encoding;

                    if (string.IsNullOrEmpty(CharSet))
                    {
                        Encoding = Encoding.UTF8;
                    }
                    else
                    {
                        Encoding = System.Text.Encoding.GetEncoding(CharSet);
                    }

                    string XmlResponse = Encoding.GetString(Bin).Trim();

                    if (this.xmppClient.HasSniffers)
                    {
                        this.xmppClient.ReceiveText(XmlResponse);
                    }

                    await this.BodyReceived(XmlResponse, false);
                }while (!this.disposed && (Queued != null || (AllInactive && this.xmppClient.State == XmppState.Connected)));

                if (ClientIndex >= 0)
                {
                    lock (this.httpClients)
                    {
                        this.active[ClientIndex] = false;
                    }
                }
            }
            catch (Exception ex)
            {
                this.bindingInterface?.ConnectionError(ex);
            }

            return(true);
        }
Ejemplo n.º 3
0
 public override String ToString()
 {
     return(rid.ToString());
 }
Ejemplo n.º 4
0
 public override string ToString()
 {
     return(Rid.ToString());
 }