Esempio n. 1
0
        private static List <Currencies> tab;//wszystkie elementy tabeli w liscie

        public static async void PeriodicWork()
        {
            DateTime presentDate = DateTime.UtcNow;

            try
            {
                presentDate = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(presentDate, "Central European Standard Time");
            }
            catch (Exception e)
            {
                var t = e.Message;
            }

            DateTime docDate;

            try
            {
                docDate = PrepareData.GetDocumentDate(url_tableA);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            var licContext = new LicencjatContext();

            tab = licContext.AllCurrencies.ToList();

            var timeWindow = new DateTime(presentDate.Year, presentDate.Month, presentDate.Day, 12, 30, 00); //12, 30, 00
            var noon       = new DateTime(presentDate.Year, presentDate.Month, presentDate.Day, 12, 00, 00); //12, 00, 00

            CultureInfo.CurrentCulture = new CultureInfo("en-US");

            if (presentDate.CompareTo(noon) < 0)
            {
                isSent = false;
            }

            if (docDate.Day == presentDate.Day &&
                presentDate.CompareTo(timeWindow) < 0 &&
                presentDate.CompareTo(noon) >= 0 &&
                isSent == false)
            {
                if (tab.Count != 0)
                {
                    await SelectUsersAndSendPush();
                }
                isSent = true;
            }
        }
Esempio n. 2
0
        private static async Task SelectUsersAndSendPush() //static void
        {
            foreach (var user in tab)
            {
                var xmlDocA = PrepareData.FormatXMLtoUTF8(url_tableA);
                var xmlDocB = PrepareData.FormatXMLtoUTF8(url_tableB);

                var listUserTags = new List <string>();

                if (!xmlDocA.HasChildNodes || !xmlDocB.HasChildNodes)
                {
                    throw new Exception("Dokument nie posiada węzłów");
                }

                var listUserCurrencies = new List <string>
                {
                    user.FirstCurrency,
                    user.SecondCurrency,
                    user.ThirdCurrency,
                    user.FourthCurrency,
                    user.FifthCurrency
                };

                for (var i = 0; i < listUserCurrencies.Count; i++)
                {
                    if (listUserCurrencies[i] != null)
                    {
                        if (xmlDocA.
                            SelectSingleNode("/tabela_kursow/pozycja/nazwa_waluty[text()='" + listUserCurrencies[i] + "']") == null)
                        {
                            var innerNode = xmlDocB.SelectSingleNode(
                                "/tabela_kursow/pozycja/nazwa_waluty[text()='"
                                + listUserCurrencies[i]
                                + "']"
                                );
                            var pNode = innerNode.ParentNode;
                            var rate  = pNode.LastChild.InnerText;
                            var tag   = SelectWhatToPush(user.UserID, rate, listUserCurrencies[i]);

                            if (tag != string.Empty)
                            {
                                listUserTags.Add(tag);
                            }

                            await SendPushAsync("gcm", "Kurswaluty " + listUserCurrencies[i] + " uległ zmianie", tag);
                        }
                        else
                        {
                            var innerNode = xmlDocA.SelectSingleNode(
                                "/tabela_kursow/pozycja/nazwa_waluty[text()='"
                                + listUserCurrencies[i]
                                + "']"
                                );
                            var pNode = innerNode.ParentNode;
                            var rate  = pNode.LastChild.InnerText;
                            var tag   = SelectWhatToPush(user.UserID, rate, listUserCurrencies[i]);

                            if (tag != string.Empty)
                            {
                                var mess = "Kurs waluty " + listUserCurrencies[i] + " uległ zmianie";
                                await SendPushAsync("gcm", mess, tag);
                            }
                        }
                    }
                }
            }
        }