protected virtual IEnumerable selectedItems() { EMailAccountSyncFilter filter = Filter.Current; BqlCommand cmd = SelectedItems.View.BqlSelect; if (filter != null && filter.ServerID != null) { cmd = cmd.WhereAnd <Where <EMailSyncAccount.serverID, Equal <Current <EMailAccountSyncFilter.serverID> > > >(); } if (filter != null && !String.IsNullOrEmpty(filter.PolicyName)) { cmd = cmd.WhereAnd <Where <EMailSyncAccount.policyName, Equal <Current <EMailAccountSyncFilter.policyName> > > >(); } int totalRows = 0; int startRow = PXView.StartRow; PXView view = new PXView(this, false, cmd); view.Clear( ); foreach (PXResult <EMailSyncAccount, EMailSyncServer, EPEmployee, Contact> item in view.Select(PXView.Currents, PXView.Parameters, PXView.Searches, PXView.SortColumns, PXView.Descendings, PXView.Filters, ref startRow, PXView.MaximumRows, ref totalRows)) { Contact contact = item; EMailSyncAccount account = item; account.Address = (contact != null ? contact.EMail : null) ?? account.Address; //SelectedItems.Cache.SetStatus(account, PXEntryStatus.Notchanged); yield return(item); } }
private static bool DatesVerifier <TExport>(PXCache cache, PXFieldVerifyingEventArgs e) where TExport : IBqlField { EMailSyncAccount row = e.Row as EMailSyncAccount; if (row == null) { return(false); } var origDate = (DateTime?)cache.GetValueOriginal <TExport>(row); var newDate = (DateTime?)e.NewValue; if (origDate == null || newDate == null) { return(false); } if (newDate >= PXTimeZoneInfo.Now) { e.NewValue = origDate; cache.RaiseExceptionHandling <TExport>(row, origDate, new PXSetPropertyException(Messages.DateLessNow, PXErrorLevel.Error)); return(false); } if (newDate >= origDate) { cache.RaiseExceptionHandling <TExport>(row, newDate, new PXSetPropertyException(Messages.DateGreaterOld, PXErrorLevel.Warning)); } return(true); }
private static Tuple <EMailSyncServer, EMailSyncPolicy, PXSyncMailbox> GetConfig(int emailAccountID) { PXGraph graph = new PXGraph(); foreach (PXResult <EMailSyncAccount, EMailSyncServer, EMailAccount, EPEmployee, Contact> row in PXSelectJoin <EMailSyncAccount, InnerJoin <EMailSyncServer, On <EMailSyncServer.accountID, Equal <EMailSyncAccount.serverID> >, InnerJoin <EMailAccount, On <EMailAccount.emailAccountID, Equal <EMailSyncAccount.emailAccountID> >, LeftJoin <EPEmployee, On <EMailSyncAccount.employeeID, Equal <EPEmployee.bAccountID> >, LeftJoin <Contact, On <EPEmployee.defContactID, Equal <Contact.contactID>, And <EPEmployee.parentBAccountID, Equal <Contact.bAccountID> > > > > > >, Where <EMailSyncAccount.emailAccountID, Equal <Required <EMailSyncAccount.emailAccountID> > >, OrderBy <Asc <EMailSyncAccount.serverID, Asc <EMailSyncAccount.employeeID> > > > .SelectSingleBound(graph, null, emailAccountID)) { EMailSyncServer server = row; EMailSyncAccount account = row; Contact contact = row; EMailAccount eMailAccount = row; if (server == null || account == null || String.IsNullOrEmpty(account.Address)) { throw new PXException(Messages.EmailExchangeAccountNotFound); } if (server.IsActive != true) { throw new PXException(Messages.EmailExchangeAccountNotEnabled); } string address = (contact != null ? contact.EMail : null) ?? account.Address; PXSyncMailbox mailbox = new PXSyncMailbox(address, account.EmployeeID.Value, emailAccountID, new PXSyncMailboxPreset(null, null), new PXSyncMailboxPreset(null, null), eMailAccount.IncomingProcessing ?? false); string policyName = account.PolicyName ?? server.DefaultPolicyName; EMailSyncPolicy policy = PXSelect <EMailSyncPolicy, Where <EMailSyncPolicy.policyName, Equal <Required <EMailSyncPolicy.policyName> > > > .SelectSingleBound(graph, null, policyName); if (policy == null) { throw new PXException(Messages.EmailExchangePolicyNotFound, account.Address); } if (String.IsNullOrEmpty(server.ServerType) || !_exchangers.ContainsKey(server.ServerType)) { throw new PXException(Messages.EmailExchangeProviderNotFound); } return(Tuple.Create(server, policy, mailbox)); } throw new PXException(Messages.EmailExchangeAccountNotFound); }
private static void DatesSwapper <TExport, TImport>(PXCache cache, PXFieldUpdatedEventArgs e) where TExport : IBqlField where TImport : IBqlField { EMailSyncAccount row = e.Row as EMailSyncAccount; if (row == null) { return; } var state = cache.GetStateExt(row, typeof(TExport).Name) as PXFieldState; cache.SetValue <TImport>(row, state?.Value); }
protected void EMailSyncAccount_RowSelected(PXCache cache, PXRowSelectedEventArgs e) { EMailSyncAccount row = e.Row as EMailSyncAccount; Status.SetEnabled(row != null); if (row == null) { return; } ResetContacts.SetEnabled(row.IsContactsReset ?? false); ResetTasks.SetEnabled(row.IsTasksReset ?? false); ResetEvents.SetEnabled(row.IsEventsReset ?? false); ResetEmails.SetEnabled(row.IsEmailsReset ?? false); }
protected IEnumerable reset(PXAdapter adapter) { EMailAccountSyncFilter filter = Filter.Current; EMailSyncAccount account = SelectedItems.Current; if (filter == null || account == null) { return(adapter.Get()); } EMailSyncAccount accountCopy = (EMailSyncAccount)SelectedItems.Cache.CreateCopy(account); accountCopy.ContactsExportDate = null; accountCopy.ContactsExportFolder = null; accountCopy.ContactsImportDate = null; accountCopy.ContactsImportFolder = null; accountCopy.EmailsExportDate = null; accountCopy.EmailsExportFolder = null; accountCopy.EmailsImportDate = null; accountCopy.EmailsImportFolder = null; accountCopy.EventsExportDate = null; accountCopy.EventsExportFolder = null; accountCopy.EventsImportDate = null; accountCopy.EventsImportFolder = null; accountCopy.TasksExportDate = null; accountCopy.TasksExportFolder = null; accountCopy.TasksImportDate = null; accountCopy.TasksImportFolder = null; PXCache cache = this.Caches[typeof(EMailSyncAccount)]; cache.Update(accountCopy); cache.Persist(PXDBOperation.Update); SelectedItems.Cache.ClearQueryCache(); SelectedItems.View.Clear(); SelectedItems.Cache.Clear(); CurrentItem.View.RequestRefresh(); SelectedItems.View.RequestRefresh(); return(adapter.Get()); }
private void ToDefault(EMailSyncAccount row) { foreach (var field in new[] { typeof(EMailSyncAccount.contactsExportDate), typeof(EMailSyncAccount.contactsImportDate), typeof(EMailSyncAccount.tasksExportDate), typeof(EMailSyncAccount.tasksImportDate), typeof(EMailSyncAccount.eventsExportDate), typeof(EMailSyncAccount.eventsImportDate), typeof(EMailSyncAccount.emailsExportDate), typeof(EMailSyncAccount.emailsImportDate), }) { Caches[typeof(EMailSyncAccount)].SetValue(row, field.Name, Caches[typeof(EMailSyncAccount)].GetValueOriginal(row, field.Name)); } }
public IEnumerable syncAccounts() { List <EMailSyncAccount> rows = Base.SyncAccounts.Select().RowCast <EMailSyncAccount>().ToList(); if (Base.Servers.Current == null || Base.Servers.Current.AccountCD == null) { return(new EMailSyncAccount[0]); } Boolean isDirty = Base.SyncAccounts.Cache.IsDirty; foreach (PXResult <EPEmployee, Contact> employee in PXSelectJoin <EPEmployee, InnerJoin <Contact, On <EPEmployee.defContactID, Equal <Contact.contactID>, And <EPEmployee.parentBAccountID, Equal <Contact.bAccountID> > > >, Where <Contact.eMail, IsNotNull, And <Contact.userID, IsNotNull> > > .Select(Base)) { EMailSyncAccount row = new EMailSyncAccount(); row.ServerID = Base.Servers.Current.AccountID; row.EmployeeID = ((EPEmployee)employee).BAccountID; row.Address = ((Contact)employee).EMail; row.EmployeeCD = ((EPEmployee)employee).AcctName; row.OwnerID = ((EPEmployee)employee).UserID; if (Base.SyncAccounts.Cache.Locate(row) == null) { row.IsVitrual = true; row.SyncAccount = false; row = (EMailSyncAccount)Base.SyncAccounts.Cache.Insert(row); if (row == null) { continue; } Base.SyncAccounts.Cache.SetStatus(row, PXEntryStatus.Held); rows.Add(row); } } Base.SyncAccounts.Cache.IsDirty = isDirty; return(rows); }
protected IEnumerable clearLog(PXAdapter adapter) { EMailAccountSyncFilter filter = Filter.Current; EMailSyncAccount account = SelectedItems.Current; if (filter == null || account == null) { return(adapter.Get()); } PXDatabase.Delete <EMailSyncLog>( new PXDataFieldRestrict <EMailSyncLog.address>(account.Address), new PXDataFieldRestrict <EMailSyncLog.serverID>(account.ServerID)); OperationLog.View.RequestRefresh(); OperationLog.View.Clear(); return(adapter.Get()); }
protected IEnumerable resetWarning(PXAdapter adapter) { EMailAccountSyncFilter filter = Filter.Current; EMailSyncAccount account = SelectedItems.Current; if (filter == null || account == null) { return(adapter.Get()); } PXDatabase.Update <EMailSyncAccount>( new PXDataFieldAssign <EMailSyncAccount.hasErrors>(false), new PXDataFieldRestrict <EMailSyncAccount.serverID>(account.ServerID), new PXDataFieldRestrict <EMailSyncAccount.employeeID>(account.EmployeeID)); SelectedItems.View.RequestRefresh(); SelectedItems.View.Clear(); return(adapter.Get()); }
protected IEnumerable resetTasks(PXAdapter adapter) { EMailAccountSyncFilter filter = Filter.Current; EMailSyncAccount account = CurrentItem.Current; if (filter == null || account == null) { return(adapter.Get()); } PXLongOperation.StartOperation(this, delegate() { foreach (var result in TasksReferences .Select(account.TasksExportDate ?? new DateTime(1900, 1, 1)) .RowCast <EMailSyncReference>()) { Caches[typeof(EMailSyncReference)].Delete(result); } Caches[typeof(EMailSyncReference)].Persist(PXDBOperation.Delete); EMailSyncAccount accountCopy = (EMailSyncAccount)CurrentItem.Cache.CreateCopy(account); ToDefault(accountCopy); accountCopy.TasksExportDate = account.TasksExportDate; accountCopy.TasksExportFolder = null; accountCopy.TasksImportDate = account.TasksImportDate; accountCopy.TasksImportFolder = null; accountCopy.IsReset = true; Caches[typeof(EMailSyncAccount)].Update(accountCopy); Caches[typeof(EMailSyncAccount)].Persist(PXDBOperation.Update); }); ClearViews(); return(adapter.Get()); }
protected void EMailSyncAccount_RowSelected(PXCache cache, PXRowSelectedEventArgs e) { EMailSyncAccount row = e.Row as EMailSyncAccount; Status.SetEnabled(row != null); if (row == null) { return; } ResetContacts.SetEnabled(row.IsContactsReset ?? false); ResetTasks.SetEnabled(row.IsTasksReset ?? false); ResetEvents.SetEnabled(row.IsEventsReset ?? false); ResetEmails.SetEnabled(row.IsEmailsReset ?? false); if (row.HasErrors == true) { cache.RaiseExceptionHandling <EMailSyncAccount.address>(row, row.Address, new PXSetPropertyException( "Some items were not synchronized. Check synchronization status and log for more details.", PXErrorLevel.Warning)); } }
protected void ProcessInternal(ProcessingContext context) { Dictionary <int, List <int> > processing = new Dictionary <int, List <int> >( ); foreach (EMailSyncAccount account in context.Accounts) { List <int> list; if (!processing.TryGetValue(account.ServerID.Value, out list)) { processing[account.ServerID.Value] = list = new List <int>(); } list.Add(account.EmployeeID.Value); } foreach (int serverID in processing.Keys) { Dictionary <string, ProcessingBox> buckets = new Dictionary <string, ProcessingBox>(); EMailSyncServer server = null; foreach (PXResult <EMailSyncAccount, EMailSyncServer, EMailAccount, EPEmployee> row in PXSelectJoin <EMailSyncAccount, InnerJoin <EMailSyncServer, On <EMailSyncServer.accountID, Equal <EMailSyncAccount.serverID> >, InnerJoin <EMailAccount, On <EMailAccount.emailAccountID, Equal <EMailSyncAccount.emailAccountID> >, LeftJoin <EPEmployee, On <EMailSyncAccount.employeeID, Equal <EPEmployee.bAccountID> > > > >, Where <EMailSyncServer.accountID, Equal <Required <EMailSyncServer.accountID> >, And <EMailSyncAccount.address, IsNotNull> >, OrderBy <Asc <EMailSyncAccount.serverID, Asc <EMailSyncAccount.employeeID> > > > .Select(this, serverID)) { server = (EMailSyncServer)row; EMailSyncAccount account = (EMailSyncAccount)row; EMailAccount eMailAccount = (EMailAccount)row; if (!processing.ContainsKey(serverID) || !processing[serverID].Contains(account.EmployeeID.Value)) { continue; } string address = account.Address; EMailSyncPolicy policy = null; if (!String.IsNullOrEmpty(account.PolicyName)) { policy = context.Policies[account.PolicyName]; } if (policy == null && !String.IsNullOrEmpty(server.DefaultPolicyName)) { policy = context.Policies[server.DefaultPolicyName]; } if (policy == null) { throw new PXException(Messages.EmailExchangePolicyNotFound, account.Address); } ProcessingBox bucket; if (!buckets.TryGetValue(policy.PolicyName, out bucket)) { buckets[policy.PolicyName] = bucket = new ProcessingBox(policy); } if (policy.ContactsSync ?? false) { bucket.Contacts.Add( new PXSyncMailbox(address, account.EmployeeID.Value, account.EmailAccountID, new PXSyncMailboxPreset(account.ContactsExportDate, account.ContactsExportFolder), new PXSyncMailboxPreset(account.ContactsImportDate, account.ContactsImportFolder), eMailAccount.IncomingProcessing ?? false) { Reinitialize = account.ToReinitialize == true, IsReset = account.IsReset == true }); } if (policy.EmailsSync ?? false) { bucket.Emails.Add( new PXSyncMailbox(address, account.EmployeeID.Value, account.EmailAccountID, new PXSyncMailboxPreset(account.EmailsExportDate, account.EmailsExportFolder), new PXSyncMailboxPreset(account.EmailsImportDate, account.EmailsImportFolder), eMailAccount.IncomingProcessing ?? false) { Reinitialize = account.ToReinitialize == true, IsReset = account.IsReset == true }); } if (policy.TasksSync ?? false) { bucket.Tasks.Add( new PXSyncMailbox(address, account.EmployeeID.Value, account.EmailAccountID, new PXSyncMailboxPreset(account.TasksExportDate, account.TasksExportFolder), new PXSyncMailboxPreset(account.TasksImportDate, account.TasksImportFolder), eMailAccount.IncomingProcessing ?? false) { Reinitialize = account.ToReinitialize == true, IsReset = account.IsReset == true }); } if (policy.EventsSync ?? false) { bucket.Events.Add( new PXSyncMailbox(address, account.EmployeeID.Value, account.EmailAccountID, new PXSyncMailboxPreset(account.EventsExportDate, account.EventsExportFolder), new PXSyncMailboxPreset(account.EventsImportDate, account.EventsImportFolder), eMailAccount.IncomingProcessing ?? false) { Reinitialize = account.ToReinitialize == true, IsReset = account.IsReset == true }); } } if (server == null) { continue; } List <Exception> errors = new List <Exception>(); foreach (string policy in buckets.Keys) { ProcessingBox bucket = buckets[policy]; using (IEmailSyncProvider provider = PXEmailSyncHelper.GetExchanger(server, bucket.Policy)) { foreach (PXEmailSyncOperation.Operations operation in Enum.GetValues(typeof(PXEmailSyncOperation.Operations))) //do one time for all existing sync types { try { switch (operation) { case PXEmailSyncOperation.Operations.Emails: if (bucket.EmailsPending) { provider.EmailsSync(bucket.Policy, PXEmailSyncDirection.Parse(bucket.Policy.EmailsDirection), bucket.Emails); } break; case PXEmailSyncOperation.Operations.Contacts: if (bucket.ContactsPending) { provider.ContactsSync(bucket.Policy, PXEmailSyncDirection.Parse(bucket.Policy.ContactsDirection), bucket.Contacts); } break; case PXEmailSyncOperation.Operations.Tasks: if (bucket.TasksPending) { provider.TasksSync(bucket.Policy, PXEmailSyncDirection.Parse(bucket.Policy.TasksDirection), bucket.Tasks); } break; case PXEmailSyncOperation.Operations.Events: if (bucket.EventsPending) { provider.EventsSync(bucket.Policy, PXEmailSyncDirection.Parse(bucket.Policy.EventsDirection), bucket.Events); } break; } } catch (PXExchangeSyncItemsException ex) { if (bucket.Policy.SkipError == true) { continue; } if (ex.Errors.Count > 0) { foreach (string address in ex.Errors.Keys) { string message = String.Join(Environment.NewLine, ex.Errors[address].ToArray()); context.StoreError(serverID, address, message); } } } catch (PXExchangeSyncFatalException ex) { if (bucket.Policy.SkipError == true) { continue; } errors.Add(new PXException(Messages.EmailExchangeSyncOperationError, operation.ToString())); if (!String.IsNullOrEmpty(ex.Mailbox)) { context.StoreError(serverID, ex.Mailbox, ex.InnerMessage); } else { errors.Add(ex); } } catch (Exception ex) { if (bucket.Policy.SkipError == true) { continue; } errors.Add(new PXException(Messages.EmailExchangeSyncOperationError, operation.ToString())); errors.Add(ex); } } } } if (errors.Count > 0) { throw new PXException(String.Join(Environment.NewLine, errors.Select(e => e.Message).ToArray())); } } for (int index = 0; index < context.Accounts.Count; index++) { PXProcessing.SetInfo(index, ActionsMessages.RecordProcessed); } //handle exceptions if (context.Exceptions.Count > 0) { foreach (int index in context.Exceptions.Keys) { List <string> errors = context.Exceptions[index]; if (errors == null || errors.Count < 0) { continue; } PXProcessing.SetError(index, String.Join(Environment.NewLine, errors.ToArray( ))); } throw new PXException(Messages.EmailExchangeSyncFailed); } }
protected void EMailSyncAccount_RowSelected(PXCache cache, PXRowSelectedEventArgs e) { EMailSyncAccount row = e.Row as EMailSyncAccount; Status.SetEnabled(row != null); }