Esempio n. 1
0
        public static void RefreshShortCodes()
        {
            MessageDataAccessor dataBinding = new MessageDataAccessor();

            using (var service = new MyMobileAPIService.APISoapClient())
            {
                foreach (var account in dataBinding.GetAccounts())
                {
                    bool recordsProcessed;

                    do
                    {
                        recordsProcessed = false;

                        ShortCodeSettingsEntity settings = dataBinding.GetShortCodeSettings(account.AccountId);
                        if (settings != null)
                        {
                            ShortCodeServiceCallEntity data = new ShortCodeServiceCallEntity()
                                {
                                    Settings = settings
                                };

                            string xmlString = Serializer.SerializeXml<ShortCodeServiceCallEntity>(data);

                            string resultXml = service.ShortCode_Get_STR_STR(account.Username, account.Password, xmlString);

                            SaveXmlStringToFile(resultXml,"SHORTCODES");

                            ShortCodeResultEntity results = Serializer.DeserializeXml<ShortCodeResultEntity>(resultXml);

                            if (results.Results != null)
                            {
                                results.Results.ForAll(m =>
                                {
                                    dataBinding.InsertMessageDetail(m);
                                });

                                int latestID = results.Results.Max(r => r.ChangeId);

                                dataBinding.UpdateShortCodeSettingsLatestID(latestID, account.AccountId);

                                recordsProcessed = results.Results.Length > 0;
                            }
                        }
                    } while (recordsProcessed);
                }
            }
        }