protected override void Execute(CodeActivityContext context) { // Create a Lead class and populate it with the input arguments Lead l = new Lead(); l.ContactName = ContactName.Get(context); l.ContactPhone = ContactPhone.Get(context); l.Interests = Interests.Get(context); l.Comments = Notes.Get(context); l.WorkflowID = context.WorkflowInstanceId; l.Status = "Open"; // Get the connection string DBExtension ext = context.GetExtension <DBExtension>(); if (ext == null) { throw new InvalidProgramException("No connection string available"); } // Insert a record into the Lead table LeadDataDataContext dc = new LeadDataDataContext(ext.ConnectionString); dc.Leads.InsertOnSubmit(l); dc.SubmitChanges(); // Store the request in the OutArgument Lead.Set(context, l); }
private void LoadExistingLeads() { LeadDataDataContext dc = new LeadDataDataContext(_connectionString); dc.Refresh(RefreshMode.OverwriteCurrentValues, dc.Leads); IEnumerable <Lead> q = dc.Leads .Where <Lead>(x => x.Status == "Open" || x.Status == "Assigned"); foreach (Lead l in q) { AddNewLead(l); } }
protected override void Execute(NativeActivityContext context) { // Get the connection string DBExtension ext = context.GetExtension <DBExtension>(); if (ext == null) { throw new InvalidProgramException("No connection string available"); } // Create a data context LeadDataDataContext dc = new LeadDataDataContext(ext.ConnectionString); // Enlist on the current transaction RuntimeTransactionHandle rth = new RuntimeTransactionHandle(); rth = context.Properties.Find(rth.ExecutionPropertyName) as RuntimeTransactionHandle; if (rth != null) { Transaction t = rth.GetCurrentTransaction(context); // Open the connection, if necessary if (dc.Connection.State == System.Data.ConnectionState.Closed) { dc.Connection.Open(); } dc.Connection.EnlistTransaction(t); } // Create an Assignment class and populate its properties Assignment a = new Assignment(); dc.Assignments.InsertOnSubmit(a); a.WorkflowID = context.WorkflowInstanceId; a.LeadID = LeadID.Get(context); a.DateAssigned = DateTime.Now; a.AssignedTo = AssignedTo.Get(context); a.Status = "Assigned"; a.DateDue = DateTime.Now + TimeSpan.FromDays(5); dc.SubmitChanges(); }
protected override void Execute(NativeActivityContext context) { // Get the connection string DBExtension ext = context.GetExtension <DBExtension>(); if (ext == null) { throw new InvalidProgramException("No connection string available"); } // Query the Lead table LeadDataDataContext dc = new LeadDataDataContext(ext.ConnectionString); dc.Refresh(RefreshMode.OverwriteCurrentValues, dc.Leads); Lead l = dc.Leads.SingleOrDefault <Lead> (x => x.WorkflowID == context.WorkflowInstanceId); if (l == null) { throw new InvalidProgramException ("The Lead was not found in the database"); } l.AssignedTo = AssignedTo.Get(context); l.Status = "Assigned"; // Enlist on the current transaction RuntimeTransactionHandle rth = new RuntimeTransactionHandle(); rth = context.Properties.Find(rth.ExecutionPropertyName) as RuntimeTransactionHandle; if (rth != null) { Transaction t = rth.GetCurrentTransaction(context); dc.Connection.EnlistTransaction(t); } dc.SubmitChanges(); // Store the request in the OutArgument Lead.Set(context, l); }
private void btnAssign_Click(object sender, RoutedEventArgs e) { if (lstLeads.SelectedIndex >= 0) { Lead l = (Lead)lstLeads.Items[lstLeads.SelectedIndex]; Guid id = l.WorkflowID; LeadDataDataContext dc = new LeadDataDataContext(_connectionString); dc.Refresh(RefreshMode.OverwriteCurrentValues, dc.Leads); l = dc.Leads.SingleOrDefault <Lead>(x => x.WorkflowID == id); if (l != null) { l.AssignedTo = txtAgent.Text; l.Status = "Assigned"; dc.SubmitChanges(); // Clear the input txtAgent.Text = ""; } // Update the grid lstLeads.Items[lstLeads.SelectedIndex] = l; lstLeads.Items.Refresh(); WorkflowApplication i = new WorkflowApplication(new EnterLead()); SetupInstance(i); i.Load(id); try { i.ResumeBookmark("GetAssignment", l); } catch (Exception e2) { AddEvent(e2.Message); } } }
protected override void Execute(CodeActivityContext context) { // Create a Lead class and populate it with the input arguments Lead l = new Lead(); l.ContactName = ContactName.Get(context); l.ContactPhone = ContactPhone.Get(context); l.Interests = Interests.Get(context); l.Comments = Notes.Get(context); l.WorkflowID = context.WorkflowInstanceId; l.Status = "Open"; // Insert a record into the Lead table LeadDataDataContext dc = new LeadDataDataContext(ConnectionString.Get(context)); dc.Leads.InsertOnSubmit(l); dc.SubmitChanges(); // Store the request in the OutArgument Lead.Set(context, l); }
public void AddAssignment(Assignment a) { LeadDataDataContext dc = new LeadDataDataContext(_connectionString); dc.Refresh(RefreshMode.OverwriteCurrentValues, dc.Leads); Assignment aTmp = dc.Assignments .SingleOrDefault<Assignment> (x => x.AssignmentID == a.AssignmentID); if (aTmp != null) this.lstLeads.Items.Add(aTmp); }
private void LoadExistingLeads() { LeadDataDataContext dc = new LeadDataDataContext(_connectionString); dc.Refresh(RefreshMode.OverwriteCurrentValues, dc.Assignments); IEnumerable<Assignment> q = dc.Assignments .Where<Assignment>(x => x.Status == "Assigned" || x.Status == "Completed"); foreach (Assignment a in q) { AddAssignment(a); } }
protected override void Track(TrackingRecord record, TimeSpan timeout) { WorkflowInstanceRecord instanceTrackingRecord = record as WorkflowInstanceRecord; if (instanceTrackingRecord != null) { TrackInstance t = new TrackInstance(); t.WorkflowID = instanceTrackingRecord.InstanceId; t.Status = instanceTrackingRecord.State; t.EventDate = DateTime.UtcNow; // Insert a record into the TrackInstance table LeadDataDataContext dc = new LeadDataDataContext(_connectionString); dc.TrackInstances.InsertOnSubmit(t); dc.SubmitChanges(); } BookmarkResumptionRecord bookTrackingRecord = record as BookmarkResumptionRecord; if (bookTrackingRecord != null) { TrackBookmark t = new TrackBookmark(); t.WorkflowID = bookTrackingRecord.InstanceId; t.BookmarkName = bookTrackingRecord.BookmarkName; t.EventDate = DateTime.UtcNow; // Insert a record into the TrackBookmark table LeadDataDataContext dc = new LeadDataDataContext(_connectionString); dc.TrackBookmarks.InsertOnSubmit(t); dc.SubmitChanges(); } ActivityStateRecord activityStateRecord = record as ActivityStateRecord; if (activityStateRecord != null) { TrackActivity t = new TrackActivity(); t.ActivityName = activityStateRecord.Activity.Name; t.WorkflowID = activityStateRecord.InstanceId; t.Status = activityStateRecord.State; t.EventDate = DateTime.UtcNow; // Concatenate all the variables into a string IDictionary <String, object> variables = activityStateRecord.Variables; StringBuilder s = new StringBuilder(); if (variables.Count > 0) { foreach (KeyValuePair <string, object> v in variables) { s.AppendLine(String.Format("{0}: Value = [{1}]", v.Key, v.Value)); } } // Store the variables string t.Variables = s.ToString(); // Insert a record into the TrackActivity table LeadDataDataContext dc = new LeadDataDataContext(_connectionString); dc.TrackActivities.InsertOnSubmit(t); dc.SubmitChanges(); } CustomTrackingRecord customTrackingRecord = record as CustomTrackingRecord; if (customTrackingRecord != null) { TrackCustom t = new TrackCustom(); t.WorkflowID = customTrackingRecord.InstanceId; t.CustomEventName = customTrackingRecord.Name; t.EventDate = DateTime.UtcNow; // Concatenate all the user data into a string string s = ""; if ((customTrackingRecord != null) && (customTrackingRecord.Data.Count > 0)) { foreach (string data in customTrackingRecord.Data.Keys) { if (s.Length > 1) { s += "\r\n"; } s += String.Format("{0}: Value = [{1}]", data, customTrackingRecord.Data[data]); } } t.UserData = s; // Insert a record into the TrackUser table LeadDataDataContext dc = new LeadDataDataContext(_connectionString); dc.TrackCustoms.InsertOnSubmit(t); dc.SubmitChanges(); } }
protected override void CollectValues (out IDictionary <XName, object> readWriteValues, out IDictionary <XName, object> writeOnlyValues) { // We're not actually providing data to the caller readWriteValues = null; writeOnlyValues = null; // See if there is any work to do... if (_object.Count > 0) { // Get the current transaction Transaction t = System.Transactions.Transaction.Current; // Setup the DataContext LeadDataDataContext dc = new LeadDataDataContext(_connectionString); // Open the connection, if necessary if (dc.Connection.State == System.Data.ConnectionState.Closed) { dc.Connection.Open(); } if (t != null) { dc.Connection.EnlistTransaction(t); } // Process each object in our work queue foreach (KeyValuePair <Guid, Lead> kvp in _object) { Lead l = kvp.Value as Lead; string action = _action[l.WorkflowID]; // Perform the insert if (action == "Insert") { dc.Leads.InsertOnSubmit(l); } // Perform the update if (action == "Update") { dc.Refresh(RefreshMode.OverwriteCurrentValues, dc.Leads); Lead lTmp = dc.Leads.SingleOrDefault <Lead> (x => x.WorkflowID == l.WorkflowID); if (lTmp != null) { lTmp.AssignedTo = l.AssignedTo; lTmp.Status = l.Status; } } } // Submit all the changes to the database dc.SubmitChanges(); // Remove all objects since the changes have been submitted _object.Clear(); _action.Clear(); } }
protected override void CollectValues (out IDictionary<XName, object> readWriteValues, out IDictionary<XName, object> writeOnlyValues) { // We're not actually providing data to the caller readWriteValues = null; writeOnlyValues = null; // See if there is any work to do... if (_object.Count > 0) { // Get the current transaction Transaction t = System.Transactions.Transaction.Current; // Setup the DataContext LeadDataDataContext dc = new LeadDataDataContext(_connectionString); // Open the connection, if necessary if (dc.Connection.State == System.Data.ConnectionState.Closed) dc.Connection.Open(); if (t != null) dc.Connection.EnlistTransaction(t); // Process each object in our work queue foreach (KeyValuePair<Guid, Assignment> kvp in _object) { Assignment a = kvp.Value as Assignment; string action = _action[kvp.Key]; // Perform the insert if (action == "Insert") { dc.Assignments.InsertOnSubmit(a); } // Perform the update if (action == "Update") { dc.Refresh(RefreshMode.OverwriteCurrentValues, dc.Leads); Assignment aTmp = dc.Assignments .SingleOrDefault<Assignment> (x => x.WorkflowID == kvp.Key); if (aTmp != null) { aTmp.DateCompleted = a.DateCompleted; aTmp.Remarks = a.Remarks; aTmp.Status = a.Status; } } } // Submit all the changes to the database dc.SubmitChanges(); // Remove all objects since the changes have been submitted _object.Clear(); _action.Clear(); } }
private void LoadExistingLeads() { LeadDataDataContext dc = new LeadDataDataContext(_connectionString); dc.Refresh(RefreshMode.OverwriteCurrentValues, dc.Leads); IEnumerable<Lead> q = dc.Leads .Where<Lead>(x => x.Status == "Open" || x.Status == "Assigned"); foreach (Lead l in q) { AddNewLead(l); } }