コード例 #1
0
        static void AccountSync()
        {
            int page        = 1;
            var crmAccounts = crm.GetAccounts(500, page);

            void Execute()
            {
                foreach (var account in crmAccounts.Entities)
                {
                    try
                    {
                        FreshdeskAccountForCreation freshdeskAccount = accountMapper.CreateAccount(account);

                        if (account.Contains("isw_freshdeskid"))
                        {
                            long freshdeskId = long.Parse(account["isw_freshdeskid"].ToString());
                            freshdesk.UpdateAccount(freshdeskId, freshdeskAccount);
                        }
                        else
                        {
                            FreshdeskAccountDto createdFreshdeskAccount = freshdesk.CreateAccount(freshdeskAccount);

                            if (createdFreshdeskAccount != null)
                            {
                                Entity accountEntity = accountMapper.CreateAccount(createdFreshdeskAccount);

                                crm.UpsertAccount(accountEntity);
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            do
            {
                Execute();
                page++;

                if (crmAccounts.MoreRecords)
                {
                    crmAccounts = crm.GetAccounts(500, page, crmAccounts.PagingCookie);
                }
                else
                {
                    break;
                }
            } while (crmAccounts.MoreRecords);

            UpdateAppsettings("AccountLastSyncDate", 2);
        }