/// <summary>
    /// Handles the OnClick event of the cmdAbort control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void cmdAbort_OnClick(object sender, EventArgs e)
    {
        IImportHistory importHistory = BindingSource.Current as IImportHistory;

        AbortImport(importHistory);
        Response.Redirect(string.Format("ImportHistory.aspx?entityid={0}", importHistory.Id));
    }
Пример #2
0
    private IList <IImportHistoryItem> GetHistoryItems(IImportHistory importHistory, string itemType, string sortField, bool ascending)
    {
        IList <IImportHistoryItem>       items    = null;
        IRepository <IImportHistoryItem> repItems = EntityFactory.GetRepository <IImportHistoryItem>();
        IQueryable         qryItems = (IQueryable)repItems;
        IExpressionFactory expItems = qryItems.GetExpressionFactory();

        Sage.Platform.Repository.ICriteria critItems = qryItems.CreateCriteria();
        critItems.Add(expItems.Eq("ImportHistoryId", importHistory.Id));
        if (!string.IsNullOrEmpty(itemType))
        {
            critItems.Add(expItems.Eq("ItemType", itemType));
        }
        if (!String.IsNullOrEmpty(sortField))
        {
            if (ascending)
            {
                critItems.AddOrder(expItems.Asc(sortField));
            }
            else
            {
                critItems.AddOrder(expItems.Desc(sortField));
            }
        }

        items = critItems.List <IImportHistoryItem>();
        return(items);
    }
 /// <summary>
 /// Aborts the import.
 /// </summary>
 /// <param name="importHistory">The import history.</param>
 private void AbortImport(IImportHistory importHistory)
 {
     try
     {
         IRepository <IImportHistory> rep        = EntityFactory.GetRepository <IImportHistory>();
         IQueryable         qry                  = (IQueryable)rep;
         IExpressionFactory ep                   = qry.GetExpressionFactory();
         Sage.Platform.Repository.ICriteria crit = qry.CreateCriteria();
         crit.Add(ep.Eq("Id", importHistory.Id));
         IProjections projections = qry.GetProjectionsFactory();
         crit.SetProjection(projections.Property("ProcessState"));
         object state = crit.UniqueResult();
         if (state != null)
         {
             ImportProcessState processState = (ImportProcessState)Enum.Parse(typeof(ImportProcessState), state.ToString());
             if (!processState.Equals(ImportProcessState.Completed) || !processState.Equals(ImportProcessState.Abort))
             {
                 SetProcessState(importHistory.Id.ToString(), Enum.GetName(typeof(ImportProcessState), ImportProcessState.Abort), "Aborted");
             }
         }
     }
     catch (Exception)
     {
         //throw new ApplicationException("Error getting process state");
     }
 }
    /// <summary>
    /// Transforms to target object.
    /// </summary>
    /// <param name="itemId">The item</param>
    /// <returns></returns>
    private IMatchDuplicateProvider GetDuplicateProvider(string itemId)
    {
        IImportHistoryItem    item            = Sage.Platform.EntityFactory.GetById <IImportHistoryItem>(itemId);
        IImportHistory        importHistory   = Sage.Platform.EntityFactory.GetById <IImportHistory>(item.ImportHistoryId);
        ImportTemplateManager templateManager = new ImportTemplateManager(importHistory.Data, Type.GetType(importHistory.EntityType));
        ImportCSVOptions      csvOptions      = new ImportCSVOptions();

        templateManager.LoadImportSourceOptions(csvOptions);
        StringBuilder sb = new StringBuilder();

        if (csvOptions.FirstRowColHeader)
        {
            string colheader    = string.Empty;
            int    lastColIndex = templateManager.SourceProperties.Count;
            int    index        = 0;
            foreach (ImportSourceProperty sp in templateManager.SourceProperties)
            {
                index++;
                colheader = colheader + Convert.ToString(csvOptions.Qualifier) + sp.FieldName +
                            Convert.ToString(csvOptions.Qualifier);
                if (lastColIndex != index)
                {
                    colheader = colheader + Convert.ToString(csvOptions.Delimiter);
                }
            }
            sb.AppendLine(colheader);
        }
        sb.AppendLine(item.Data);
        ImportCSVReader sourceReader = GetCSVReader(sb.ToString());

        sourceReader.Options = csvOptions;

        ImportTransformationManager transformationManager =
            new ImportTransformationManager(templateManager.EntityManager.EntityType, templateManager.ImportMaps,
                                            templateManager.TargetPropertyDefaults);

        //Calculated properties?
        transformationManager.TransformationProvider = new ImportTransformationProvider();
        sourceReader.MoveToNext();
        object targetEntityObj = Sage.Platform.EntityFactory.Create(templateManager.EntityManager.EntityType);

        transformationManager.FillEntity(sourceReader.CurrentRecord, targetEntityObj);

        //Need to make this more generic
        IMatchDuplicateProvider dupProvider = new LeadDuplicateProvider();

        dupProvider.AdvancedOptions           = templateManager.MatchAdvancedOptions;
        dupProvider.AdvancedOptions.AutoMerge = false;
        foreach (string filter in templateManager.MatchFilters)
        {
            dupProvider.SetActiveFilter(filter, true);
        }
        MatchEntitySource entitySource = new MatchEntitySource(templateManager.EntityManager.EntityType, targetEntityObj);

        dupProvider.EntitySource = entitySource;

        return(dupProvider);
    }
Пример #5
0
    /// <summary>
    /// Loads the form.
    /// </summary>
    private void LoadForm()
    {
        IImportHistory importHistory = BindingSource.Current as IImportHistory;

        if (importHistory != null)
        {
            grdHistoryLog.DataSource = GetHistoryItems(importHistory, "", "CreateDate", true); //importHistory.ImportHistoryItems;
            grdHistoryLog.DataBind();
        }
    }
    /// <summary>
    /// Loads the form.
    /// </summary>
    private void LoadForm()
    {
        IImportHistory importHistory = BindingSource.Current as IImportHistory;

        if (importHistory != null)
        {
            txtImportFileName.Text         = importHistory.Description;
            txtStatus.Text                 = importHistory.Status;
            txtImportId.Text               = importHistory.ImportNumber;
            txtTemplate.Text               = importHistory.Template;
            dtpStartDate.DateTimeValue     = importHistory.CreateDate;
            dtpCompleteDate.DateTimeValue  = importHistory.ModifyDate;
            usrStartedBy.LookupResultValue = importHistory.CreateUser;
            txtTotalRecords.Text           = importHistory.RecordCount.ToString();
            txtRecordsProcessed.Text       = importHistory.ProcessedCount.ToString();
            txtRecordsImported.Text        = importHistory.ImportedCount.ToString();
            txtTotalErrors.Text            = importHistory.ErrorCount.ToString();
            txtWarningCount.Text           = importHistory.WarningCount.ToString();
            txtDuplicateCount.Text         = importHistory.DuplicateCount.ToString();
            txtMergedCount.Text            = importHistory.MergeCount.ToString();

            var    entityType = Type.GetType(importHistory.EntityType);
            string entityName = entityType.Name[0] == 'I' ? entityType.Name.Substring(1) : entityType.Name;
            lnkLink.NavigateUrl = string.Format(@"~/{0}.aspx?gid={1}&modeid=list", entityName, importHistory.PrimaryEntityGroup);
            if (!string.IsNullOrEmpty(importHistory.ProcessState))
            {
                try
                {
                    ImportProcessState processState = (ImportProcessState)Enum.Parse(typeof(ImportProcessState), importHistory.ProcessState);
                    if ((processState.Equals(ImportProcessState.Completed)) || (processState.Equals(ImportProcessState.Abort)))
                    {
                        cmdAbort.Visible = false;
                    }
                    else
                    {
                        cmdAbort.Visible = true;
                    }
                }
                catch (Exception ex)
                {
                    log.Error("Unexpected error in LoadForm().", ex);
                    cmdAbort.Visible = false;
                }
            }
        }
    }
    /// <summary>
    /// Loads the form.
    /// </summary>
    private void LoadForm()
    {
        IImportHistory importHistory = BindingSource.Current as IImportHistory;

        if (importHistory != null)
        {
            txtImportFileName.Text         = importHistory.Description;
            txtStatus.Text                 = importHistory.Status;
            txtImportId.Text               = importHistory.ImportNumber;
            txtTemplate.Text               = importHistory.Template;
            dtpStartDate.DateTimeValue     = importHistory.CreateDate;
            dtpCompleteDate.DateTimeValue  = importHistory.ModifyDate;
            usrStartedBy.LookupResultValue = importHistory.CreateUser;
            txtTotalRecords.Text           = importHistory.RecordCount.ToString();
            txtRecordsProcessed.Text       = importHistory.ProcessedCount.ToString();
            txtRecordsImported.Text        = importHistory.ImportedCount.ToString();
            txtTotalErrors.Text            = importHistory.ErrorCount.ToString();
            txtWarningCount.Text           = importHistory.WarningCount.ToString();
            txtDuplicateCount.Text         = importHistory.DuplicateCount.ToString();
            txtMergedCount.Text            = importHistory.MergeCount.ToString();
            if (!string.IsNullOrEmpty(importHistory.ProcessState))
            {
                try
                {
                    ImportProcessState processState = (ImportProcessState)Enum.Parse(typeof(ImportProcessState), importHistory.ProcessState);
                    if ((processState.Equals(ImportProcessState.Completed)) || (processState.Equals(ImportProcessState.Abort)))
                    {
                        cmdAbort.Visible = false;
                    }
                    else
                    {
                        cmdAbort.Visible = true;
                    }
                }
                catch (Exception ex)
                {
                    log.Error("Unexpected error in LoadForm().", ex);
                    cmdAbort.Visible = false;
                }
            }
        }
    }
Пример #8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        IImportHistory importHistory = BindingSource.Current as IImportHistory;

        if (importHistory != null)
        {
            txtImportID.Text             = importHistory.Id.ToString();
            txtImportDate.Text           = importHistory.CreateDate.ToString();
            txtStatus.Text               = importHistory.Status;
            txtImportLeads.Text          = importHistory.ImportedCount.ToString();
            txtAutoMergedDuplicates.Text = importHistory.MergeCount.ToString();
            txtUnresolvedDuplicates.Text = importHistory.DuplicateCount.ToString();
            txtErrors.Text               = importHistory.ErrorCount.ToString();

            DataTable dtImportHistory = importHistory.GetHistoryItems() as DataTable;
            grdHistoryItems.DataSource = dtImportHistory;
            grdHistoryItems.DataBind();
            string data = importHistory.Data;
        }
    }
    /// <summary>
    /// Handles the Click event of the cmdAssignImportHistory control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void cmdAssignImportHistory_Click(object sender, EventArgs e)
    {
        ImportManager importManager = Page.Session["importManager"] as ImportManager;

        if (importManager == null)
        {
            return;
        }
        WebPortalPage portalPage = Page as WebPortalPage;

        if (portalPage != null)
        {
            IImportHistory importHistory = EntityFactory.Create <IImportHistory>();
            importHistory.Status         = GetLocalResourceObject("importStatus_Processing").ToString();
            importHistory.ProcessedCount = 0;
            importHistory.Save();
            importManager.ImportHistory = importHistory;
            portalPage.ClientContextService.CurrentContext.Remove("ImportHistoryId");
            portalPage.ClientContextService.CurrentContext.Add("ImportHistoryId", importHistory.Id.ToString());
        }
    }
Пример #10
0
    /// <summary>
    /// Starts the import process inside its own thread.
    /// </summary>
    public void StartImportProcess()
    {
        ImportManager importManager = Page.Session["importManager"] as ImportManager;

        if (importManager == null)
        {
            return;
        }
        try
        {
            SetImportSourceValue();
            AddJob(importManager);
            AddCrossReferenceMananager(importManager);

            WebPortalPage portalPage = Page as WebPortalPage;
            if (portalPage != null)
            {
                IImportHistory importHistory = EntityFactory.Create <IImportHistory>();
                importHistory.Status         = GetLocalResourceObject("importStatus_Processing").ToString();
                importHistory.ProcessedCount = 0;
                importHistory.Save();
                lblHeader.Text               = GetLocalResourceObject("lblHeader_ProcessStarted.Caption").ToString();
                lblImportNumber.Visible      = true;
                lnkImportHistoryCaption.Text = String.Format(" {0}-{1}", importHistory.Alternatekeyprefix, importHistory.Alternatekeysuffix);
                lnkImportHistory.HRef        = String.Format("..\\..\\ImportHistory.aspx?entityid='{0}'&modeid=Detail", importHistory.Id);
                lblImportLeadsWizard.Visible = true;
                importManager.ImportHistory  = importHistory;
                portalPage.ClientContextService.CurrentContext.Remove("ImportHistoryId");
                portalPage.ClientContextService.CurrentContext.Add("ImportHistoryId", importHistory.Id.ToString());
            }
        }
        catch (Exception ex)
        {
            log.Error("The call to StepProcessRequest.StartImportProcess() failed", ex);
        }
    }
 /// <summary>
 /// Aborts the import.
 /// </summary>
 /// <param name="importHistory">The import history.</param>
 private void AbortImport(IImportHistory importHistory)
 {
     try
     {
         IRepository<IImportHistory> rep = EntityFactory.GetRepository<IImportHistory>();
         IQueryable qry = (IQueryable)rep;
         IExpressionFactory ep = qry.GetExpressionFactory();
         Sage.Platform.Repository.ICriteria crit = qry.CreateCriteria();
         crit.Add(ep.Eq("Id", importHistory.Id));
         IProjections projections = qry.GetProjectionsFactory();
         crit.SetProjection(projections.Property("ProcessState"));
         object state = crit.UniqueResult();
         if (state != null)
         {
             ImportProcessState processState = (ImportProcessState)Enum.Parse(typeof(ImportProcessState), state.ToString());
             if (!processState.Equals(ImportProcessState.Completed) || !processState.Equals(ImportProcessState.Abort))
                 SetProcessState(importHistory.Id.ToString(), Enum.GetName(typeof(ImportProcessState), ImportProcessState.Abort), "Aborted");
         }
     }
     catch (Exception)
     {
         //throw new ApplicationException("Error getting process state");
     }
 }
    /// <summary>
    /// Loads the form.
    /// </summary>
    private void LoadForm()
    {
        try
        {
            if (Page.Visible && chkShowDuplicates.Checked)
            {
                IImportHistory importHistory = BindingSource.Current as IImportHistory;
                if (importHistory != null)
                {
                    ImportTemplateManager templateManager = new ImportTemplateManager(importHistory.Data, Type.GetType(importHistory.EntityType));
                    ImportCSVOptions      csvOptions      = new ImportCSVOptions();
                    templateManager.LoadImportSourceOptions(csvOptions);
                    IList <IImportHistoryItem> items = Sage.SalesLogix.ImportHistory.Rules.GetHistoryItems(importHistory, "DUPLICATE", "CreateDate", true);

                    if (items != null && items.Count > 0)
                    {
                        IImportHistoryItem fItem      = items[0];
                        string             sQualifier = string.Empty;
                        if (fItem.Data.Contains(csvOptions.Qualifier.ToString()))
                        {
                            sQualifier = Convert.ToString(csvOptions.Qualifier);
                        }

                        StringBuilder sb = new StringBuilder();
                        if (csvOptions.FirstRowColHeader)
                        {
                            string colheader = string.Empty;
                            colheader = string.Format("{0}{1}{2}{3}", sQualifier, "Id", sQualifier, csvOptions.Delimiter);
                            int lastColIndex = templateManager.SourceProperties.Count;
                            int index        = 0;
                            foreach (ImportSourceProperty sp in templateManager.SourceProperties)
                            {
                                index++;
                                colheader = sp.FieldName.Equals("Id", StringComparison.InvariantCultureIgnoreCase)
                                                ? colheader + sQualifier + sp.FieldName + "_" + index + sQualifier
                                                : colheader + sQualifier + sp.FieldName + sQualifier;
                                if (lastColIndex != index)
                                {
                                    colheader = colheader + Convert.ToString(csvOptions.Delimiter);
                                }
                            }
                            sb.AppendLine(colheader);
                        }

                        foreach (IImportHistoryItem item in items)
                        {
                            if (string.Equals("DUPLICATE", item.ItemType) && !Convert.ToBoolean(item.IsResolved))
                            {
                                sb.AppendFormat("{0}{1}{2}{3}{4}\r\n", sQualifier, item.Id, sQualifier, csvOptions.Delimiter, item.Data);
                            }
                        }

                        ImportCSVReader sourceReader = GetCSVReader(sb.ToString());
                        sourceReader.Options = csvOptions;
                        DataTable dtDups = sourceReader.GetAsDataTable(-1);
                        if (dtDups.Columns[0].ColumnName != "Id")
                        {
                            dtDups.Columns[0].ColumnName = "Id";
                        }
                        grdDuplicates.DataSource = dtDups;
                    }
                }
                grdDuplicates.DataBind();
            }
        }
        catch (Exception ex)
        {
            log.Error("The call to ImportHistoryDuplicates.LoadForm() failed", ex);
        }
    }
Пример #13
0
    private IList<IImportHistoryItem> GetHistoryItems(IImportHistory importHistory, string itemType, string sortField, bool ascending)
    {
        IList<IImportHistoryItem> items = null;
        IRepository<IImportHistoryItem> repItems = EntityFactory.GetRepository<IImportHistoryItem>();
        IQueryable qryItems = (IQueryable)repItems;
        IExpressionFactory expItems = qryItems.GetExpressionFactory();
        Sage.Platform.Repository.ICriteria critItems = qryItems.CreateCriteria();
        critItems.Add(expItems.Eq("ImportHistoryId", importHistory.Id));
        if(!string.IsNullOrEmpty(itemType))
        {
          critItems.Add(expItems.Eq("ItemType", itemType));
        }
        if (!String.IsNullOrEmpty(sortField))
        {
            if (ascending)
            {
                critItems.AddOrder(expItems.Asc(sortField));
            }
            else
            {
                critItems.AddOrder(expItems.Desc(sortField));
            }
        }

        items = critItems.List<IImportHistoryItem>();
        return items;
    }
 /// <summary>
 /// Aborts the import.
 /// </summary>
 /// <param name="importHistory">The import history.</param>
 private void AbortImport(IImportHistory importHistory)
 {
     SetProcessState(importHistory.Id.ToString(), Enum.GetName(typeof(ImportProcessState), ImportProcessState.Abort), "Aborted");
     GoToImportHistory();
 }
Пример #15
0
    /// <summary>
    /// Raises the <see cref="E:System.Web.UI.Control.PreRender"/> event.
    /// </summary>
    /// <param name="e">An <see cref="T:System.EventArgs"/> object that contains the event data.</param>
    protected override void OnPreRender(EventArgs e)
    {
        ImportManager  importManager = Page.Session["importManager"] as ImportManager;
        IImportHistory importHistory = null;
        string         historyId     = Page.Session["importHistoryId"] as string;

        importHistory = Sage.Platform.EntityFactory.GetById <IImportHistory>(historyId);

        if (importHistory == null)
        {
            if (importManager != null)
            {
                //importHistory = importManager.ImportHistory;
            }
        }

        if (importHistory != null)
        {
            try
            {
                lnkImportNumber.Text = string.Format("{0}-{1}", importHistory.Alternatekeyprefix, importHistory.Alternatekeysuffix);

                ImportProcessState processState = (ImportProcessState)Enum.Parse(typeof(ImportProcessState), importHistory.ProcessState);
                if (processState.Equals(ImportProcessState.Abort))
                {
                    //lblHeader.Text = string.Format(GetLocalResourceObject("AbortMsg").ToString());
                    if (importHistory.ErrorCount > 0)
                    {
                        lblHeader2.Text = string.Format("{0}  {1}", GetLocalResourceObject("ViewImportHistoryMsgWithErrors").ToString(), GetLocalResourceObject("ViewImportHistoryMsg").ToString());
                    }
                    else
                    {
                        lblHeader2.Text = string.Format("{0}", GetLocalResourceObject("ViewImportHistoryMsg").ToString());
                    }

                    cmdAbort.Visible = false;
                }
                else
                {
                    if (processState.Equals(ImportProcessState.Completed))
                    {
                        cmdAbort.Visible = false;
                        lblHeader.Text   = string.Format(GetLocalResourceObject("CompletedMsg").ToString());
                        if (importHistory.ErrorCount > 0)
                        {
                            lblHeader2.Text = string.Format("{0}  {1}", GetLocalResourceObject("ViewImportHistoryMsgWithErrors").ToString(), GetLocalResourceObject("ViewImportHistoryMsg").ToString());
                        }
                        else
                        {
                            lblHeader2.Text = string.Format("{0}", GetLocalResourceObject("ViewImportHistoryMsg").ToString());
                        }

                        importManager = null;
                        Page.Session["importManager"] = null;
                        //Page.Session["importHistoryId"] = null;
                        radImportProcessArea.Visible = false;
                    }
                    else
                    {
                        cmdAbort.Visible = true;
                        lblHeader.Text   = string.Format(GetLocalResourceObject("lblPrimary_Progress.Caption").ToString());
                        lblHeader2.Text  = string.Format(GetLocalResourceObject("ProcessingMsg").ToString());
                    }
                }
            }
            catch (Exception)
            {
            }
        }
        else
        {
        }
        base.OnPreRender(e);
    }