/// <remarks/>
 public void CreateAddressListAsync(string client_app_id, string client_app_pwd, int data_template_id, name_value[][] data) {
     this.CreateAddressListAsync(client_app_id, client_app_pwd, data_template_id, data, null);
 }
 /// <remarks/>
 public void CreateAddressListAsync(string client_app_id, string client_app_pwd, int data_template_id, name_value[][] data, object userState) {
     if ((this.CreateAddressListOperationCompleted == null)) {
         this.CreateAddressListOperationCompleted = new System.Threading.SendOrPostCallback(this.OnCreateAddressListOperationCompleted);
     }
     this.InvokeAsync("CreateAddressList", new object[] {
                 client_app_id,
                 client_app_pwd,
                 data_template_id,
                 data}, this.CreateAddressListOperationCompleted, userState);
 }
        static void Main(string[] args)
        {
            string[] filePaths = Directory.GetFiles(pathtopdf);
            ArrayList fileID = new ArrayList();
            //molapiv2.Service molapiv2connect = new molapiv2.Service();
            devmolpro.name_value[] nmvalues = new devmolpro.name_value[] { };

            string[] columns;
            List<string[]> data_values = new List<string[]>();
            Console.Out.WriteLine("Reading csv data...");
            using (StreamReader reader = new StreamReader(list_file_name))
            {
                string header = reader.ReadLine();
                columns = header.Split(',');
                while (!reader.EndOfStream)
                {
                    string line_data = reader.ReadLine();
                    string[] values = line_data.Split(',');
                    data_values.Add(values);
                }
                reader.Close();
            }

            Console.Out.WriteLine("Building List data...");
            devmolpro.name_value[][] name_values = new devmolpro.name_value[data_values.Count][];
            for (int a = 0; a < data_values.Count; a++)
            {
                Console.WriteLine("Done" + a.ToString());
                name_values[a] = new devmolpro.name_value[columns.Length];
                for (int b = 0; b < columns.Length; b++)
                {

                    name_values[a][b] = new devmolpro.name_value();
                    name_values[a][b].name = columns[b];
                    if (data_values[a].Length >= b)
                    {
                        name_values[a][b].value = data_values[a][b];
                    }
                    else
                    {
                        name_values[a][b].value = "";
                    }
                }
            }

            Console.Out.WriteLine("List data built...");

            string tokenList =devmolpros.CreateAddressList(user_name, pass_word, mapping_id,name_values);
               Console.WriteLine("Token Code Received after creating datalist: {0}", tokenList.ToString());
            devmolpro.return_status stat = new devmolpro.return_status();
            Thread.Sleep(300);
            while (stat.status_id != 3)
            {

                stat = devmolpros.CheckListStatus(user_name, pass_word, tokenList);
                if (stat.status_id == 9)
                {
                    throw new Exception("Error while Creating List.Please Try Again");
                }
            }
               Console.WriteLine("Status Received after creating datalist: {0}", stat.description);

            foreach (string ff in filePaths)
            {
                try
                {

                    Console.WriteLine("Uploading File");
                    fileID = UploadFileToServer(ff);
                    Console.WriteLine("File Uploaded.....");
                    string[] stringArray = (string[])fileID.ToArray(typeof(string));
                    //Can Upload Document Ends here

                    //list processing ends here

                    string docname = string.Empty;

                    //create document from template starts here
                    for (int doc = 0; doc < stringArray.Length; doc++)
                    {
                        int docid = -1;
                        Random random = new Random();
                        int rand = random.Next();
                        docname = rand + "moltesting1";
                        string token1 = String.Empty;
                        devmolpro.return_status dst = new devmolpro.return_status();
                        dst = devmolpros.CreateDocument(user_name, pass_word, docname, "Letter 8.5 x 11", 1, stringArray[doc]);

                        Console.WriteLine(dst.description);

                        if (dst.status_id == 0)
                        {

                            Console.WriteLine("Document Creation Completed ID:{0}", dst.id);

                            //what forms of payment do you want to use
                            //here is the one for credit card
                            devmolpro.billing_details billingdet = new devmolpro.billing_details();
                            billingdet.bill_name = "Test Account";
                            billingdet.bill_type = "Credit Card";
                            billingdet.bill_address1 = "94-g Industrial Dr";
                            billingdet.bill_company = "Click2Mail";
                            billingdet.bill_city = "Troy";
                            billingdet.bill_state = "Virginia";
                            billingdet.bill_zip = "22974";
                            billingdet.bill_number = "4111111111111111";
                            billingdet.bill_exp_month = "04";
                            billingdet.bill_exp_year = "2012";

                            //here is how you can do for invoice
                            devmolpro.billing_details billingdetinvoice = new devmolpro.billing_details();
                            billingdetinvoice.bill_type = "Invoice";
                            billingdetinvoice.bill_address1 = "92g Industrial Dr";
                            billingdetinvoice.bill_company = "Click2Mail";
                            billingdetinvoice.bill_city = "Troy";
                            billingdetinvoice.bill_state = "Virginia";
                            billingdetinvoice.bill_zip = "22974";

                            //here is the setup for ACH
                            devmolpro.billing_details billingdetach = new devmolpro.billing_details();
                            billingdetach.bill_type = "ACH";
                            billingdetach.bill_address1 = "94-g Industrial Dr";
                            billingdetach.bill_company = "Click2Mail";
                            billingdetach.bill_city = "Troy";
                            billingdetach.bill_state = "Virginia";
                            billingdetach.bill_zip = "22974";

                            //here is one using your credits
                            devmolpro.billing_details billingdetprepaid = new devmolpro.billing_details();
                            billingdetprepaid.bill_type = "prepaid";
                            billingdetprepaid.bill_address1 = "92-g industrial dr";
                            billingdetprepaid.bill_company = "Click2Mail";
                            billingdetprepaid.bill_city = "Troy";
                            billingdetprepaid.bill_state = "Virginia";
                            billingdetprepaid.bill_zip = "22974";

                            //lets setup a return address
                            devmolpro.return_address_details retaddress = new devmolpro.return_address_details();
                            retaddress.name = "test";
                            retaddress.business = "Click2Mail";
                            retaddress.address = "92-g Industrial Dr";
                            retaddress.city = "Troy";
                            retaddress.state = "VA";
                            retaddress.zip = "22974";
                            retaddress.ancillary_endorsement = "";

                            devmolpro.address_details[] ad=new devmolpro.address_details[2]{new devmolpro.address_details(),new devmolpro.address_details()};

                            ad[0].name="test test";
                            ad[0].address1="92-g industrial dr";
                            ad[0].address2="";
                            ad[0].organization="Click2Mail";
                            ad[0].city="Troy";
                            ad[0].state="VA";
                            ad[0].zip="22974";

                            ad[1].name = "Sudeep Ghimire";
                            ad[1].address1 = "92-g industrial dr";
                            ad[1].address2 = "";
                            ad[1].organization = "Troy";
                            ad[1].city = "Troy";
                            ad[1].state = "VA";
                            ad[1].zip = "22974";

                            molprodevtest.devmolpro.molpro m = new devmolpro.molpro();

                            object[] obj = new object[ad.Length];

                           obj=devmolpros.CorrectAddress(user_name,pass_word,ad);
                           long[] docids = new long[] { new long(), new long() };
                           docids[0] = 1027;
                           docids[1] = 1014;
                           rand = random.Next();
                           docname = rand + "molmerged1";
                          long mergeresult = devmolpros.MergeDocuments(user_name, pass_word, docids, docname,"Letter 8.5 x 11");
                           molprodevtest.devmolpro.return_status jobcreationstatus = devmolpros.CreateJob(user_name, pass_word, stat.id, dst.id, job_template_id, retaddress);
                            Console.WriteLine("Job Created Sucessfully...What is my Job ID:" + jobcreationstatus.id);
                            Console.WriteLine("Job Creation Status...What is my Job ID:" + jobcreationstatus.description);
                            Console.WriteLine("Job Creation Status...What is my Job status code:" + jobcreationstatus.status_id);

                         molprodevtest.devmolpro.status_code ret  = devmolpros.SubmitJob(user_name, pass_word, jobcreationstatus.id, billingdetinvoice);

                             devmolpro.status_code statJob = devmolpros.CheckJobStatus(user_name, pass_word, jobcreationstatus.id);

                           Console.WriteLine("Job Status: {0}", statJob.description);

                           string proofurl = devmolpros.CreateProof(user_name, pass_word, jobcreationstatus.id);
                           Console.WriteLine("Proof URL : {0}", proofurl);
                           Console.WriteLine("Merged Document ID:" + jobcreationstatus.id);

                        }

                    }
                    //molapiv2.status_type status1 = molapiv2connect.CheckDocumentCreateStatus(user_name, pass_word, token);

                }

                catch (Exception ex)
                {
                    throw new Exception(ex.Message);

                }
            }

            Console.ReadLine();
        }