/// <summary> /// First loads the extractTable needed. Goes throught all the Partners in the extract, If the partner already has the subscription, returns all those partners back to client. If the partner doesn't have the subscription, saves this /// subscription to those partners. /// </summary> /// <returns>void</returns> private void SubmitChangesInternal() { TDBTransaction SubmitChangesTransaction; TSubmitChangesResult SubmissionResult = TSubmitChangesResult.scrOK; MExtractTable ExtractDT; PSubscriptionTable SubscriptionTable; PPartnerTable PartnerTable; Int32 RowCounter; Int32 PartnersInExtract; StringCollection RequiredColumns; StringCollection RequiredColumns2; if (FInspectDT != null) { // Initialisations FVerificationResult = new TVerificationResultCollection(); ExtractDT = new MExtractTable(); SubscriptionTable = new PSubscriptionTable(); FSubmissionDT = SubscriptionTable.Clone(); ((TTypedDataTable)FSubmissionDT).InitVars(); PartnerTable = new PPartnerTable(); RequiredColumns = new StringCollection(); RequiredColumns.Add(MExtractTable.GetPartnerKeyDBName()); RequiredColumns2 = new StringCollection(); RequiredColumns2.Add(PPartnerTable.GetPartnerKeyDBName()); RequiredColumns2.Add(PPartnerTable.GetPartnerShortNameDBName()); RowCounter = 0; // Set up asynchronous execution FAsyncExecProgress.ProgressState = TAsyncExecProgressState.Aeps_Executing; FAsyncExecProgress.ProgressInformation = "Checking Partners' Subscriptions..."; try { SubmitChangesTransaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.Serializable); // TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: loading Subscriptions for ExtractID " + FExtractID.ToString() + "..."); ExtractDT = MExtractAccess.LoadViaMExtractMaster(FExtractID, RequiredColumns, SubmitChangesTransaction); PartnersInExtract = ExtractDT.Rows.Count; // TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: ExtractID has " + PartnersInExtract.ToString() + " Partners."); // Go throught all the Partners in the extract foreach (MExtractRow ExtractRow in ExtractDT.Rows) { RowCounter = RowCounter + 1; // Calculate how much Partners we have checked. Let all Partners be a maximum of 70%. FAsyncExecProgress.ProgressPercentage = Convert.ToInt16((((double)RowCounter / (double)PartnersInExtract) * 100) * (MAX_PERCENTAGE_CHECKS / 100.0)); TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: loadbyPrimaryKey"); SubscriptionTable = PSubscriptionAccess.LoadByPrimaryKey( FInspectDT[0].PublicationCode, ExtractRow.PartnerKey, SubmitChangesTransaction); // if the Partner does not yet have the subscription, add the subscription to this partner. if (SubscriptionTable.Rows.Count == 0) { TLogging.LogAtLevel( 7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: will add Subscription to Partner with PartnerKey " + ExtractRow.PartnerKey.ToString()); FInspectDT[0].PartnerKey = ExtractRow.PartnerKey; TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: importing Row into FSubmissionDT..."); FSubmissionDT.ImportRow(FInspectDT[0]); } else { // The partner already has this Subscription: add the partner to the ResponseTable // TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: won't add Subscription to Partner with PartnerKey " + ExtractRow.PartnerKey.ToString()); PartnerTable = PPartnerAccess.LoadByPrimaryKey(ExtractRow.PartnerKey, RequiredColumns2, SubmitChangesTransaction); if (FResponseDT == null) { FResponseDT = PartnerTable.Clone(); } FResponseDT.ImportRow(PartnerTable[0]); } } TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: Finished checking Partner's Subscriptions."); if (FSubmissionDT.Rows.Count > 0) { // Submit the Partners with new Subscriptions to the PSubscription Table. FAsyncExecProgress.ProgressInformation = "Adding Subscriptions to " + FSubmissionDT.Rows.Count.ToString() + " Partners..."; FAsyncExecProgress.ProgressPercentage = MAX_PERCENTAGE_CHECKS; // TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: " + FAsyncExecProgress.ProgressInformation); PSubscriptionAccess.SubmitChanges((PSubscriptionTable)FSubmissionDT, SubmitChangesTransaction); } else { TLogging.LogAtLevel( 7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: no Subscriptions were added to Partners because all the Partners in the Extract already had this Subscription."); } DBAccess.GDBAccessObj.CommitTransaction(); } catch (Exception Exp) { DBAccess.GDBAccessObj.RollbackTransaction(); TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: Exception occured, Transaction ROLLED BACK. Exception: " + Exp.ToString()); FSubmitResult = TSubmitChangesResult.scrError; FSubmitException = Exp; FAsyncExecProgress.ProgressState = TAsyncExecProgressState.Aeps_Stopped; return; } } else { SubmissionResult = TSubmitChangesResult.scrNothingToBeSaved; } // if no values at response table, it needs to be created. If not creates, will raise exeption at client side. if (FResponseDT == null) { FResponseDT = new DataTable(); } FAsyncExecProgress.ProgressPercentage = 100; FAsyncExecProgress.ProgressState = TAsyncExecProgressState.Aeps_Finished; FSubmitResult = SubmissionResult; }
/// <summary> /// First loads the extractTable needed. Goes throught all the Partners in the extract, If the partner already has the subscription, returns all those partners back to client. If the partner doesn't have the subscription, saves this /// subscription to those partners. /// </summary> /// <returns>void</returns> private void SubmitChangesInternal() { TDBTransaction SubmitChangesTransaction = null; TSubmitChangesResult SubmissionResult = TSubmitChangesResult.scrNothingToBeSaved; MExtractTable ExtractDT; PSubscriptionTable SubscriptionTable; PPartnerTable PartnerTable; Int32 RowCounter; Int32 PartnersInExtract; StringCollection RequiredColumns; StringCollection RequiredColumns2; if (FInspectDT != null) { // Initialisations FVerificationResult = new TVerificationResultCollection(); ExtractDT = new MExtractTable(); SubscriptionTable = new PSubscriptionTable(); FSubmissionDT = SubscriptionTable.Clone(); ((TTypedDataTable)FSubmissionDT).InitVars(); PartnerTable = new PPartnerTable(); RequiredColumns = new StringCollection(); RequiredColumns.Add(MExtractTable.GetPartnerKeyDBName()); RequiredColumns2 = new StringCollection(); RequiredColumns2.Add(PPartnerTable.GetPartnerKeyDBName()); RequiredColumns2.Add(PPartnerTable.GetPartnerShortNameDBName()); RowCounter = 0; // Set up asynchronous execution TProgressTracker.SetCurrentState(FProgressID, "Checking Partners' Subscriptions...", 0.0m); DBAccess.GDBAccessObj.BeginAutoTransaction(IsolationLevel.Serializable, ref SubmitChangesTransaction, ref SubmissionResult, delegate { try { // TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: loading Subscriptions for ExtractID " + FExtractID.ToString() + "..."); ExtractDT = MExtractAccess.LoadViaMExtractMaster(FExtractID, RequiredColumns, SubmitChangesTransaction); PartnersInExtract = ExtractDT.Rows.Count; // TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: ExtractID has " + PartnersInExtract.ToString() + " Partners."); // Go throught all the Partners in the extract foreach (MExtractRow ExtractRow in ExtractDT.Rows) { RowCounter = RowCounter + 1; // Calculate how much Partners we have checked. Let all Partners be a maximum of 70%. TProgressTracker.SetCurrentState( FProgressID, string.Empty, Convert.ToInt16((((double)RowCounter / (double)PartnersInExtract) * 100) * (MAX_PERCENTAGE_CHECKS / 100.0))); TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: loadbyPrimaryKey"); SubscriptionTable = PSubscriptionAccess.LoadByPrimaryKey( FInspectDT[0].PublicationCode, ExtractRow.PartnerKey, SubmitChangesTransaction); // if the Partner does not yet have the subscription, add the subscription to this partner. if (SubscriptionTable.Rows.Count == 0) { TLogging.LogAtLevel( 7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: will add Subscription to Partner with PartnerKey " + ExtractRow.PartnerKey.ToString()); FInspectDT[0].PartnerKey = ExtractRow.PartnerKey; TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: importing Row into FSubmissionDT..."); FSubmissionDT.ImportRow(FInspectDT[0]); } else { // The partner already has this Subscription: add the partner to the ResponseTable // TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: won't add Subscription to Partner with PartnerKey " + ExtractRow.PartnerKey.ToString()); PartnerTable = PPartnerAccess.LoadByPrimaryKey(ExtractRow.PartnerKey, RequiredColumns2, SubmitChangesTransaction); if (FResponseDT == null) { FResponseDT = PartnerTable.Clone(); } FResponseDT.ImportRow(PartnerTable[0]); } } TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: Finished checking Partner's Subscriptions."); if (FSubmissionDT.Rows.Count > 0) { // Submit the Partners with new Subscriptions to the PSubscription Table. TProgressTracker.SetCurrentState( FProgressID, "Adding Subscriptions to " + FSubmissionDT.Rows.Count.ToString() + " Partners...", MAX_PERCENTAGE_CHECKS); // TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: " + FAsyncExecProgress.ProgressInformation); PSubscriptionAccess.SubmitChanges((PSubscriptionTable)FSubmissionDT, SubmitChangesTransaction); } else { TLogging.LogAtLevel( 7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: no Subscriptions were added to Partners because all the Partners in the Extract already had this Subscription."); } SubmissionResult = TSubmitChangesResult.scrOK; } catch (Exception Exp) { TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: Exception occured, Transaction will get ROLLED BACK. Exception: " + Exp.ToString()); SubmissionResult = TSubmitChangesResult.scrError; FSubmitResult = SubmissionResult; FSubmitException = Exp; TProgressTracker.CancelJob(FProgressID); return; } }); } // if no values at response table, it needs to be created. If not creates, will raise exeption at client side. if (FResponseDT == null) { FResponseDT = new DataTable(); } TProgressTracker.FinishJob(FProgressID); FSubmitResult = SubmissionResult; }