//public bool Exists(T obj)
        //{
        //    return this.Container.ContainsValue(obj);
        //}

        public bool Exists(T obj)
        {
            var existing = (from c in this.Container
                            where c.Value.Equals(obj) &&
                            DateTime.Now.Subtract(c.Key) < this.ExpireTime
                            select c).ToList();

#if DEBUG
            ConsoleMe.WriteLine("------------------------DEBUG LOG----------------------------");
            ConsoleMe.WriteLine("T is " + obj.ToString());
            ConsoleMe.WriteLine("There are {0} objects in array: ", this.Container.Count);
            foreach (var item in this.Container)
            {
                ConsoleMe.WriteLine(string.Format("Key: {0}, value: {1}",
                                                  item.Key.ToLongTimeString(), item.Value.ToString()));
            }
            ConsoleMe.WriteLine("------------------------END LOG----------------------------");
#endif
            if (existing != null && existing.Count > 0)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
 void CheckerLogWrite(string value, bool fWrite = false)
 {
     ConsoleMe.WriteLine(string.Format("Receiver: {0}\t{1}", this.ReceiverMan.NickName, value));
     if (fWrite)
     {
         ConsoleMe.WriteToLogFile();
     }
 }
Exemplo n.º 3
0
        private static void IsANewDay()
        {
            LogFile curLogFile = ConsoleMe.LogFileInstance;

            ConsoleMe.LogFileInstance.StartNewInstance();
            LogFile newLogFile = ConsoleMe.LogFileInstance;

            if (!curLogFile.Equals(newLogFile))
            {
                ConsoleMe.WriteLine("\n--------------------- Switch to a new day! ---------------------\n");
            }
        }
        public bool Send(out string strOut)
        {
            bool result = false;

            string strRequest = GetRequestURL();

            if (!string.IsNullOrEmpty(strRequest))
            {
                string            res = null;
                FeitionReturnCode obj = null;
                try
                {
                    res = WebStreamService.GetResponseStringFromURL(strRequest);
                    obj = JsonConvert.DeserializeObject <FeitionReturnCode>(res);
                }
                catch
                {
                    ConsoleMe.WriteLine("FeitionWebRequest: send request failed.");
                }

                if (obj != null)
                {
                    strOut = obj.ToString();
                    if (obj.Result.Trim() == "0")
                    {
                        result = true;
                    }
                    else
                    {
                        strOut += string.Format(" Result code: {0}", obj.Result);
                        ConsoleMe.WriteLine();
                    }
                }
                else
                {
                    // Deserialized failed? check the string result directly.
                    if (res.Contains("{\"result\":0"))
                    {
                        result = true;
                    }

                    strOut = res;
                }
            }
            else
            {
                strOut = "Invalid Feition request.";
            }

            return(result);
        }
Exemplo n.º 5
0
        public bool Send()
        {
            // Before sending message, clean up the message body.
            if (!AppendSuffix())
            {
                ConsoleMe.WriteLine("The message body is empty.");
                return(false);
            }

#if FeitionPoster
            int       FailedTimes    = 0;
            const int MaxFailedTimes = 5;

LStart:
            FeitionWebRequest request = new FeitionWebRequest(
                FeitionPublic.UserName,
                FeitionPublic.Password,
                this.Receiver,
                this.Message);

            string strOut;
            bool   status = request.Send(out strOut);
            ConsoleMe.WriteLine("Feition Poster: Send time: " + DateTime.Now.ToLongTimeString());
            ConsoleMe.WriteLine("Result: " + strOut);

            if (!status && FailedTimes < MaxFailedTimes)
            {
                FailedTimes++;
                ConsoleMe.WriteLine(string.Format("Failed to send message '{0}', failed times: {1}", this.Message, FailedTimes));
                ConsoleMe.WriteLine(string.Format("Try to resend to receiver {0}....", this.Receiver));
                goto LStart;
            }
#else
            ConsoleMe.WriteLine("\n(Use ConsoleMe instead of Feition Poster).");
#endif
            ConsoleMe.WriteLine(this.ToString() + "\n");

            return(true);
        }
        public static void CustomizedHRWNCheckerReceiver()
        {
            ConsoleMe.WriteLine("\n----------------------------------------------------");
            ConsoleMe.WriteLine("High Risk Weather Notification (HRWN) is running....\n");
#if DEBUG
            ConsoleMe.WriteLine("[DEBUG MODE]\n");
#endif

            var list = HRWNReceiver.Instance.GetReceivers();
            foreach (var man in list)
            {
                man.Format();
                ConsoleMe.WriteLine("User: {0}, number: {1}", man.UserName, man.FeitionAccount);

                HRWNChecker checker = new HRWNChecker(man);
#if DEBUG
                //checker.StartOnce();
                checker.Start();
#else
                checker.Start();
#endif
            }
        }
Exemplo n.º 7
0
        bool LoadTextConverterFile()
        {
            bool result = false;

            string filename = "";
            string value    = ConfigurationManager.AppSettings["AQIReadableTextConverterFile"];

            if (!string.IsNullOrEmpty(value) && File.Exists(value))
            {
                filename = value;
            }

            if (!string.IsNullOrEmpty(filename))
            {
                using (FileStream stream = new FileStream(filename, FileMode.Open))
                {
                    var serializer = new XmlSerializer(typeof(PM25Thresholds));

                    object resultObj;
                    resultObj = serializer.Deserialize(stream);
                    if (resultObj != null)
                    {
                        thresholds = resultObj as PM25Thresholds;
                        result     = true;
                    }
                }
            }

            if (!result)
            {
                ConsoleMe.WriteLine("Failed to load AQI readable text converter file {0}.", value ?? "");
                ConsoleMe.ReadyToExit();
            }

            return(result);
        }
Exemplo n.º 8
0
        private bool LoadReceiverConfigFile()
        {
            bool result = false;

            string filename = "";
            string value    = ConfigurationManager.AppSettings["HRWNReceiverConfig"];

            if (!string.IsNullOrEmpty(value) && File.Exists(value))
            {
                filename = value;
            }

            if (!string.IsNullOrEmpty(filename))
            {
                using (FileStream stream = new FileStream(filename, FileMode.Open))
                {
                    var serializer = new XmlSerializer(typeof(HRWNReceiverConfig));

                    object resultObj;
                    resultObj = serializer.Deserialize(stream);
                    if (resultObj != null)
                    {
                        ReceiverConfig = resultObj as HRWNReceiverConfig;
                        result         = true;
                    }
                }
            }

            if (!result)
            {
                ConsoleMe.WriteLine("Failed to load HRWN receiver config file {0}.", value ?? "");
                ConsoleMe.ReadyToExit();
            }

            return(result);
        }
Exemplo n.º 9
0
        private static void SwitcherDisableLog()
        {
#if !RiskRangeEnabled
            ConsoleMe.WriteLine("RiskRangeEnabled is disabled.");
#endif
        }