コード例 #1
0
        public Model.TimeZone FindTimezoneByState(string state)
        {
            Model.TimeZone rtnVal  = null;
            string         unknown = "UNKNOWN";

            var result =
                from t in this.TimeZones
                join ac in this.AreaCodes
                on t.TimeZoneId equals ac.TimeZoneId
                where ac.StateOrProvice == state
                select t;

            if (result == null || result.Count() == 0)
            {
                return(null);
            }

            foreach (var tz in result)
            {
                if (tz.ReferenceText != unknown)
                {
                    rtnVal = (Model.TimeZone)tz;
                    break;
                }
            }

            return(rtnVal);
        }
コード例 #2
0
        private Model.TimeZone GetTimezoneFromService(int areaCode)
        {
            Model.TimeZone rtnValTimeZone = null;

            try
            {
                TimeZoneServer.USZipSoapClient caller = new TimeZoneServer.USZipSoapClient("USZipSoap");
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(caller.GetInfoByAreaCode(areaCode.ToString()).OuterXml);

                //<NewDataSet><Table><CITY>Wheaton</CITY><STATE>MN</STATE><ZIP>56296</ZIP><AREA_CODE>320</AREA_CODE><TIME_ZONE>C</TIME_ZONE></Table><Table>...
                string      queryString = string.Format("Table[AREA_CODE = {0}]", areaCode);
                XmlNodeList list        = doc.DocumentElement.SelectNodes(queryString);

                if (list != null)
                {
                    foreach (XmlNode areaCodeNode in list)
                    {
                        string state        = areaCodeNode.SelectSingleNode("STATE").InnerXml;
                        string timeZoneChar = areaCodeNode.SelectSingleNode("TIME_ZONE").InnerXml.ToUpper();
                        if (timeZoneChar == "K")
                        {
                            var alaskTimeZone =
                                from at in _repository.TimeZones
                                where at.ReferenceText.Contains("ALASKA")
                                select at;

                            if (alaskTimeZone != null && alaskTimeZone.Count() > 0)
                            {
                                rtnValTimeZone = (Model.TimeZone)alaskTimeZone.First();
                            }
                        }
                        else
                        {
                            var queryResult =
                                from t in _repository.TimeZones
                                where t.ReferenceText.StartsWith(timeZoneChar)
                                select t;

                            if (queryResult != null && queryResult.Count() > 0)
                            {
                                rtnValTimeZone = (Model.TimeZone)queryResult.First();
                            }
                        }

                        break;
                    }
                }

                _result = string.Format("Your timezone is {0}", rtnValTimeZone.ReferenceText);
            }
            catch (Exception exp)
            {
                _result = "Unable to determine your timezone";
            }


            return(rtnValTimeZone);
        }
コード例 #3
0
ファイル: TimeZonesUCVM.cs プロジェクト: eFr1t/BuzyaIssue
        public void Add()
        {
            Model.TimeZone item = new Model.TimeZone();
            TimeZoneRepository.Instance.SetItem(item);

            TimeZones.Add(item);
            SelectedTimeZone = item;
        }
コード例 #4
0
        private Model.TimeZone GetTimeZone()
        {
            Model.TimeZone rtnVal   = null;
            int            areaCode = _phoneNumber.Substring(0, 3).ToInt(0);

            //Look in the database to see if we have the timezone for this areacode
            rtnVal = _repository.FindTimezoneByAreaCode(areaCode);

            if (rtnVal == null || rtnVal.IsUnknownTimeZone && _state.isNullOrEmpty() == false)
            {
                //We don't know the timezone for this areacode, let's
                //check the database to see if we have another areacode in the same state as this areacode
                //and get the timezone for that other areacode
                Model.TimeZone stateTimeZone = _repository.FindTimezoneByState(_state);
                if (stateTimeZone != null && stateTimeZone.IsUnknownTimeZone == false)
                {
                    //We either don't have a record for this AREA CODE OR the AREA CODE on file  has an "unknown" timezone
                    //However, we do have an different areacode, in the same state as the areacode specified, and we do know
                    //what timezone the other areacode is in, so update (or insert) this areacode based on the states timezone
                    this.SaveTimeZoneAreaCode(areaCode, stateTimeZone.TimeZoneId);
                    rtnVal = stateTimeZone;
                }
            }

            //See if we need to call the webservice or not
            if (rtnVal == null)
            {
                // Call the 3rd part webservice to get the timzeone for this areacode.
                rtnVal = this.GetTimezoneFromService(areaCode);
                if (rtnVal != null)
                {
                    //The webservice returned a timezone for the specified areacde
                    //Save the areacode in the database and assign it to the speicifed timezone
                    this.SaveTimeZoneAreaCode(areaCode, rtnVal.TimeZoneId);

                    //Find any areacodes we have in our database that have an 'UNKNOWN' timezone
                    //that are in the same state as this areacode and update their timezone to
                    //this timezone
                    _repository.UpdateUnknownTimezones(_state, rtnVal.TimeZoneId);
                }
                else
                {
                    //The 3rd party webservice did not find a timezone for the areacode,
                    //save the areacode in the database as unknown
                    rtnVal = _repository.FindTimezoneByReferenceText("UNKNOWN");
                    if (rtnVal != null)
                    {
                        this.SaveTimeZoneAreaCode(areaCode, rtnVal.TimeZoneId);
                    }
                }
            }

            return(rtnVal);
        }
コード例 #5
0
 private static int CompareTimeZonesByHour(Model.TimeZone x, Model.TimeZone y)
 {
     if (x == null && y == null)
     {
         return(0);
     }
     else if (x == null)
     {
         return(-1);
     }
     else if (y == null)
     {
         return(1);
     }
     else if (x.UTCHourValue == y.UTCHourValue)
     {
         return(0);
     }
     else
     {
         return(x.UTCHourValue > y.UTCHourValue ? 1 : -1);
     }
 }
コード例 #6
0
ファイル: ServerService.cs プロジェクト: eFr1t/BuzyaIssue
 public bool UpdateTimeZone(Model.TimeZone item)
 {
     //admin check
     return(TimeZoneRepository.Instance.UpdateItem(item));
 }
コード例 #7
0
ファイル: ServerService.cs プロジェクト: eFr1t/BuzyaIssue
 public bool SetTimeZone(Model.TimeZone item)
 {
     //admin check
     return(TimeZoneRepository.Instance.SetItem(item));
 }
コード例 #8
0
ファイル: ProxyServer.cs プロジェクト: eFr1t/BuzyaIssue
 bool IBaseRepository <Model.TimeZone> .UpdateItem(Model.TimeZone item)
 {
     return(Channel.UpdateTimeZone(item));
 }
コード例 #9
0
ファイル: ProxyServer.cs プロジェクト: eFr1t/BuzyaIssue
 bool IBaseRepository <Model.TimeZone> .SetItem(Model.TimeZone item)
 {
     return(Channel.SetTimeZone(item));
 }
コード例 #10
0
 private void TimeZoneTest()
 {
     Model.TimeZone tz = this.GetTimeZone();
     _repository.SaveChanges();
     _result = "Your timezone is " + tz.ReferenceText;
 }