Advertisement
Guest User

CFAPPLibrary error code

a guest
Sep 25th, 2013
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.16 KB | None | 0 0
  1. public void FillDataAsnych(ActionControl ac)
  2. {
  3.     m_Logger.Debug("FillDataAsnych");
  4.     ac.Enabled = false;
  5.     BackgroundWorker bw = new BackgroundWorker();
  6.     bw.DoWork += GetDetailsWork;
  7.     bw.RunWorkerCompleted += OnGetDetailsCompleted;
  8.     bw.RunWorkerAsync(ac);
  9. }
  10.  
  11. private void GetDetailsWork(object sender, DoWorkEventArgs e)
  12. {
  13.     m_Logger.Debug("GetDetailsWork");
  14.     ActionControl ac = (ActionControl)e.Argument;
  15.     e.Result = GetDataForDetailedActionUpdate(ac.ActionCode);
  16. }
  17.  
  18. private RawActionDetails GetDataForDetailedActionUpdate(string actionCode)
  19. {
  20.     m_Logger.Debug("GetDataForDetailedActionUpdate");
  21.     RawActionDetails res = new RawActionDetails(actionCode);
  22.     DataTable dt = Globals.bse.GetActionByCode(actionCode); // this is a WCF call to the server returning a DataTable
  23.     if (dt == null || dt.Rows.Count < 1)
  24.     {
  25.         return res;
  26.     }
  27.     res.action = dt.Rows[0];
  28.    
  29.     DataTable dtUsers = Globals.bse.GetAgentsOfAbility(actionCode);
  30.     if (dtUsers == null)
  31.     {
  32.         return res;
  33.     }
  34.     res.users = dtUsers;
  35.  
  36.     DataTable dtMarkDFields = Globals.bse.GetMarkDFields(actionCode);
  37.     if (dtMarkDFields == null)
  38.     {
  39.         return res;
  40.     }
  41.     res.fields = dtMarkDFields;
  42.     res.complete = true;
  43.  
  44.     return res;
  45. }
  46.  
  47. private void OnGetDetailsCompleted(object sender, RunWorkerCompletedEventArgs e) // no other code call this method, only the background worker above
  48. {
  49.     m_Logger.Debug("OnGetDetailsCompleted");
  50.     BackgroundWorker bw = (BackgroundWorker) sender;
  51.     RawActionDetails bwr = (RawActionDetails)e.Result;
  52.     lock (actionToControlMapSynchRoot)
  53.     {
  54.         actionToControlMap[bwr.actionCode].Enabled = true;
  55.     }
  56.     if (bwr.complete)
  57.     {
  58.         OnActionDetailsArrived(bwr);
  59.     }
  60. }
  61.  
  62. // this is not called by OnGetDetailsCompleted exclusively there is one more backgroundworker end event calling this
  63. private void OnActionDetailsArrived(RawActionDetails bwr)
  64.         {
  65.             m_Logger.Debug("OnActionDetailsArrived");
  66.             DataRow dr = bwr.action;
  67.             DataTable dtUsers = bwr.users;
  68.             DataTable dtFields = bwr.fields;
  69.  
  70.             ActionClass acc = new ActionClass(dr, dtFields, false);
  71.             Globals.actions.Change(acc);
  72.             ActionControl ac;
  73.             lock (actionToControlMapSynchRoot)
  74.             {
  75.                 if (!actionToControlMap.ContainsKey(bwr.actionCode))
  76.                 {
  77.                     CFAPControlLibrary.Service<ICFAPService>.Use(srv =>
  78.                     {
  79.                         srv.Log(string.Format("Client: cannot find the action {0} in the control map", bwr.actionCode));
  80.                     });
  81.                     return;
  82.                 }
  83.                 ac = actionToControlMap[bwr.actionCode];
  84.             }
  85.  
  86.             ac.FillData(Globals.actions.GetByCode(ac.ActionCode));
  87.             PropertyBox.Base baseControl = ac.GetBaseControl();
  88.             AgentSelector agntControl = ac.GetAgentControl();
  89.             if (agntControl != null)
  90.             {
  91.                 agntControl.FillSelectedAgents(dtUsers);
  92.             }
  93.             actionSelector1.FillNodes();
  94.         }
  95.  
  96. //The other chain calling OnActionDetailsArrived:
  97.  
  98.  
  99.  
  100. // this is called on application startup and in some button handlers, but the hang occures even when none of these buttons are pressed
  101. private void LoadInitialValues()
  102. {
  103.     m_Logger.Debug("LoadInitialValues");
  104.     if (wic == null)
  105.     {
  106.         wic = new WaitingInfoControl();
  107.     }
  108.     Controls.Add(wic);
  109.  
  110.     int x = (this.Width - wic.Width) / 2;
  111.     int y = (this.Height - wic.Height) / 2;
  112.  
  113.     wic.Left = x < 0 ? 0 : x;
  114.     wic.Top = y < 0 ? 0 : y;
  115.  
  116.     wic.BringToFront();
  117.     wic.Show();
  118.    
  119.     BackgroundWorker bw = new BackgroundWorker();
  120.     bw.RunWorkerCompleted += bw_RunWorkerCompleted; // here is the end event setup
  121.     bw.ProgressChanged += bw_ProgressChanged;
  122.     bw.DoWork += DoGetAllDataWork;
  123.     bw.WorkerReportsProgress = true;
  124.     lock (actionToControlMapSynchRoot)
  125.     {
  126.         foreach (ActionControl ac in actionToControlMap.Values)
  127.         {
  128.             ac.Enabled = false;
  129.         }
  130.         bw.RunWorkerAsync(
  131.             from openedActionCode in actionToControlMap.Keys where Globals.actions.GetByCode(openedActionCode) != null select openedActionCode
  132.         );
  133.     }
  134.     SetEnabledControls(false);
  135. }
  136. private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
  137. {
  138.     m_Logger.Debug("bw_RunWorkerCompleted");
  139.     SetEnabledControls(true);
  140.     Controls.Remove(wic);
  141.     wic.Dispose();
  142.     wic = null;
  143.     actionSelector1.FillNodes();
  144.     lock (actionToControlMapSynchRoot)
  145.     {
  146.         foreach (ActionControl ac in actionToControlMap.Values)
  147.         {
  148.             ac.Enabled = true;
  149.         }
  150.         if (e.Result is IEnumerable<RawActionDetails>)
  151.         {
  152.             IEnumerable<RawActionDetails> results = (IEnumerable<RawActionDetails>)e.Result;
  153.             foreach (RawActionDetails rawData in results)
  154.             {
  155.                 OnActionDetailsArrived(rawData); // the actual call
  156.             }
  157.         }
  158.         foreach (ActionControl ac in actionToControlMap.Values)
  159.         {
  160.             ac.Enabled = true;
  161.         }
  162.     }
  163. }
  164.  
  165.  
  166. // this is probably irrelevant
  167. public class RawActionDetails
  168. {
  169.     public string actionCode;
  170.     public DataRow action;
  171.     public DataTable users;
  172.     public DataTable fields;
  173.     public bool complete;
  174.  
  175.     public RawActionDetails(string pActionCode, DataRow pAction, DataTable pUsers, DataTable pFields)
  176.     {
  177.         actionCode = pActionCode;
  178.         action = pAction;
  179.         users = pUsers;
  180.         fields = pFields;
  181.         complete = true;
  182.     }
  183.  
  184.     public RawActionDetails(string pActionCode)
  185.     {
  186.         actionCode = pActionCode;
  187.         complete = false;
  188.     }
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement