private IHierarchyViewerServiceContract CreateServiceClient()
 {
     try
     {
         return(TransportManagerProxyFactory <IHierarchyViewerServiceContract> .GetReusableInstance("HierarchyViewerServiceContract"));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        //private void backgroundWorker_DoWork()
        {
            int errorCount   = 0;
            int warningCount = 0;

            ProposedOrderList proposedOrderList = new ProposedOrderList();

            proposedOrderList.AddRange(from ProposedOrdersDataSet.ProposedOrdersPasteRow row in borders.Rows
                                       select new ProposedOrder
            {
                PromptSymbol     = row.PromptSymbol,
                ProposedValue    = row.ProposedValue,
                SideMnemonic     = row.SideMnemonic,
                AccountShortName = row.AccountShortName,
                //Broker = "",//row.Broker,
                //UserField1 = "",// row.UserField1,
                //UserField2 = "",// row.UserField2,
                //UserField8 = "",// row.UserField8,
                id = row.id
            });

            try
            {
                ApplicationMessageList    messageList;
                ApplicationMessageList    messageListWarn = new ApplicationMessageList();
                SalesToolsServiceContract contract        = TransportManagerProxyFactory <SalesToolsServiceContract> .GetReusableInstance("SalesTools");

                ProposedOrderErrorList errorList = contract.AddProposed(proposedOrderList, localPropAllorNone, out messageList);
                // addInBase.MessageService.LogMessagesFromBackgroundThread(messageList);
                foreach (ProposedOrderError proposedOrderError in errorList)
                {
                    DataView view = borders.AsDataView();
                    view.Sort = "id";
                    int j = view.Find(proposedOrderError.id);
                    view[j]["ErrorString"] = proposedOrderError.error;
                    if (!string.IsNullOrEmpty(proposedOrderError.error))
                    {
                        CompareInfo compareInfo = CultureInfo.CurrentCulture.CompareInfo;
                        if (compareInfo.IsPrefix(proposedOrderError.error, "WARNING", CompareOptions.IgnoreCase))
                        {
                            warningCount++;
                            messageListWarn.Add(new ApplicationMessage(proposedOrderError.error, ApplicationMessageType.Warning));
                        }
                        else
                        {
                            errorCount++;
                        }
                    }
                }

                // remove successfully imported rows
                if (errorCount == 0 || (errorCount > 0 && !localPropAllorNone))
                {
                    foreach (ProposedOrderError proposedOrderError in from proposedOrderError in errorList
                             where proposedOrderError.proposed_order_id != 0
                             select proposedOrderError)
                    {
                        DataView view = borders.AsDataView();
                        view.Sort = "id";
                        int j = view.Find(proposedOrderError.id);
                        statusWindow.Dispatcher.Invoke(new Action(() => view.Delete(j)));
                    }
                }
                //    addInBase.MessageService.LogMessagesFromBackgroundThread(messageListWarn);
            }
            catch (Exception ex)
            {
                ApplicationMessageList list = new ApplicationMessageList {
                    new ApplicationMessage(ex, ApplicationMessageType.ErrorNoPopup)
                };
                // addInBase.MessageService.LogMessagesFromBackgroundThread(list);
                throw ex;
            }
            statusWindow.Dispatcher.BeginInvoke(new Action(() => statusWindow.StatusText =
                                                               string.Format(
                                                                   "Order Import Complete\r\n\r\nTotal attempted {0}\r\nErrors {1}\r\nWarnings {2}\r\n\r\nTotal Imported {3}",
                                                                   proposedOrderList.Count,
                                                                   errorCount,
                                                                   warningCount,
                                                                   !localPropAllorNone
                                                                         ? proposedOrderList.Count - errorCount
                                                                         : ((errorCount == 0) ? proposedOrderList.Count : 0))));
        }