/// <summary> /// This reads XML from a string and returns a new instance with that information. /// </summary> /// <param name="xml">The xml string containing the customer.</param> /// <returns>An instance of a account class</returns> public static object ReadCustomer(string xml) { StringReader reader = null; try { CustomerProviderCustomerRecord local = new CustomerProviderCustomerRecord(); XmlSerializer serializer = new XmlSerializer(local.GetType()); reader = new StringReader(xml); local = serializer.Deserialize(reader) as CustomerProviderCustomerRecord; reader.Close(); return(local); } catch // ( Exception exp ) // when needed for debugging { if (reader != null) { reader.Close(); } return(null); } }
/// <summary> /// Function to save the sessions state for a customer /// </summary> /// <param name="active">true if this session is active</param> /// <returns>An XML string or null if there are no applications</returns> public override string Save(bool active) { // Check if the application host is null then return if (this.AppHost == null) { return(null); } // Create a string builder object to perform string concatenation StringBuilder sb = new StringBuilder(); // build a header about the session sb.AppendFormat("<Session id=\"{0:d}\" name=\"{1}\" active=\"{2}\" startTime=\"{3}\" presence=\"{4:d}\">", this.SessionID, this.Name, active.ToString(), this.StartTime, this.PresenceState); // get the current customer info in xml string customerXml = String.Empty; if (customer != null) { customerXml = WriteCustomer(customer, customer.GetType()); } // This context wraps the Ccf Conext, hence the "Context" // tag name and not "CcfContext" sb.AppendFormat("<Context>{0}</Context><Customer>{1}</Customer>", (this.AppHost.GetContext()).GetContext(), customerXml); // Save the current workflow if there is any if (this.Workflow != null && this.Workflow != String.Empty) { if (this.Workflow.ToString().Contains("<Session ID=")) { //The line below is to be used with legacy WorkflowControl sb.AppendFormat("<WorkflowData>{0}</WorkflowData>", this.Workflow); } else { // The code below is to be used if you wish to use the refactored WfWorkflowControl XmlDocument doc = new XmlDocument(); doc.LoadXml(this.Workflow); XmlNode root = doc.DocumentElement; sb.AppendFormat("<WorkflowData>{0}</WorkflowData>", "<XML>" + root.InnerXml + "</XML>"); } } // save information about each application foreach (IHostedApplication app in this.AppHost) { try { // Add basic application information sb.AppendFormat("<Application id=\"{0}\"><Name>{1}</Name>", app.ApplicationID.ToString(), app.ApplicationName); // In the future, we may wish to add all the app information or // make appHost self-serializable. // add the application state information sb.AppendFormat("<State>{0}</State>", app.GetStateData()); sb.Append("</Application>"); } catch (Exception exp) { Logging.Error(localize.DESKTOP_MODULE_NAME, localize.DESKTOP_APP_SAVE_ERROR, exp); } } // Indicate the current application if (this.FocusedApplication != null) { sb.AppendFormat("<CurrentApplication>{0}</CurrentApplication>", this.FocusedApplication.ApplicationID); } // close the XML sb.Append("</Session>"); string savedState = sb.ToString(); return(savedState); }