Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Service need to be started manullay.I have tried all the ways found google search not getting any solution pls suggest any solution
C#
protected override void OnStart(string[] args)
        {
            Logger.WriteInfoLog("Service Started");
            Thread.Sleep(31000);
            ProceesXMlFiles();
        }

        public void ProceesXMlFiles()
        {
            try
            {

                //To check whether zip enabled or not
                string strIsZipEnable = ConfigurationManager.AppSettings["IsZipEnable"].ToString();


                if (!Directory.Exists(strArchiveFolderPath))
                    Directory.CreateDirectory(strArchiveFolderPath);

                //to check whether data from zip Url or folder path
                if (Convert.ToInt32(strIsZipEnable) == 1)
                {
                    Logger.WriteInfoLog("XML files from Zip URL path");

                    System.Net.WebClient client = new System.Net.WebClient();
                    //Folder path of downloaded Zip files
                    string Zippath = ConfigurationManager.AppSettings["ZipDownloadPath"].ToString();
                    if (!File.Exists(Zippath))
                    {
                        File.Delete(Zippath);
                    }
                    //Zip Download Url
                    client.DownloadFile(ConfigurationManager.AppSettings["ZipDownloadUrl"].ToString(), Zippath);

                    Logger.WriteInfoLog("Downloaded XML files from Zip URL path");

                    //Zip Files extracted path
                    string StrExtractPath = ConfigurationManager.AppSettings["ZipExtarctedPath"].ToString();

                    //To crete Extracted File Folder
                    if (!Directory.Exists(StrExtractPath))
                        Directory.CreateDirectory(StrExtractPath);

                    if (Directory.Exists(StrExtractPath + "\\New folder"))
                        Directory.Delete(StrExtractPath + "\\New folder", true);

                    //to extract zip file XMLs
                    ZipFile.ExtractToDirectory(Zippath, StrExtractPath);

                    Logger.WriteInfoLog("Downloaded Zip Files Extracted");

                    strArrayXMLfiles = Directory.GetFiles(StrExtractPath + "\\New folder", "*.xml");
                    StrAllFiles = Directory.GetFiles(StrExtractPath + "\\New folder");
                }
                else
                {
                    if (Directory.Exists(ConfigurationManager.AppSettings["XMLsFolderPath"].ToString()))
                    {
                        //folder path to Xml Files
                        strArrayXMLfiles = Directory.GetFiles(ConfigurationManager.AppSettings["XMLsFolderPath"].ToString(), "*.xml");
                        StrAllFiles = Directory.GetFiles(ConfigurationManager.AppSettings["XMLsFolderPath"].ToString());
                    }
                    else
                        Logger.WriteInfoLog("Xml Folder not found at given path");
                }
                foreach (string strFilepath in StrAllFiles)
                {
                    string StrFileExtension = Path.GetExtension(strFilepath);
                    if (StrFileExtension != "xml")
                    {
                        Logger.WriteInfoLog(Path.GetFileName(strFilepath) + " is not an Xml File");
                    }
                }

                for (int i = 0; i < strArrayXMLfiles.Count(); i++)
                {
                    Logger.WriteInfoLog("Processing XML files one after another");

                    //To get Xml File path to process
                    strXMLFilePath = strArrayXMLfiles[i].ToString();

                    Logger.WriteInfoLog("Getting file name whether it is started with aceds  or acfcs");

                    //to get the file name to check whether aceds or acfcs files
                    strFileName = Path.GetFileName(strXMLFilePath);

                    DataSet dsXMLData = new DataSet();
                    //to read XML file to Dataset 
                    dsXMLData.ReadXml(strXMLFilePath, XmlReadMode.InferSchema);
                    Logger.WriteInfoLog("XML Files converted as Dateset");

                    //To send prospect_id to aother json payloads also
                    string prospect_id = dsXMLData.Tables["prospect"].Rows[0][0].ToString();
                    //to process ParadotProspect JsonPayload
                    ProcessParadotProspect(dsXMLData, strFileName);
                    //to process VistorActivity JsonPayload
                    ProcessVistorActivity(dsXMLData, prospect_id, strFileName);
                    //to process VistorActivity JsonPayload
                    ProcessListSubscription(dsXMLData, prospect_id, strFileName);
                    //To move files from source to Archive Folder
                    MovefilesFromSourceToDestination(strXMLFilePath, strArchiveFolderPath);

                }
                Logger.WriteInfoLog("Service Stoped");
            }
            catch (Exception ex)
            {
                Logger.WriteErrorLog(ex, "", "");
            }
        }

        /// <summary>
        /// Paradot Prospect json Paylod Processed
        /// </summary>
        /// <param name="dsXMLData"></param>
        /// <param name="strFileName"></param>
        public void ProcessParadotProspect(DataSet dsXMLData, string strFileName)
        {
            try
            {
                #region ParadotProspect
                DataTable dtparodot = dsXMLData.Tables["prospect"];

                Logger.WriteInfoLog("If any column in paradot doesnt exist then need to add");
                //if column doesnt exist then add to send to json paylod
                if (dtparodot.Columns.Contains("campaign_id") == false)
                    dtparodot.Columns.Add("campaign_id", typeof(String));

                if (dtparodot.Columns.Contains("salutation") == false)
                    dtparodot.Columns.Add("salutation", typeof(String));

                if (dtparodot.Columns.Contains("first_name") == false)
                    dtparodot.Columns.Add("first_name", typeof(String));

                if (dtparodot.Columns.Contains("last_name") == false)
                    dtparodot.Columns.Add("last_name", typeof(String));

                if (dtparodot.Columns.Contains("email") == false)
                    dtparodot.Columns.Add("email", typeof(String));

                if (dtparodot.Columns.Contains("password") == false)
                    dtparodot.Columns.Add("password", typeof(String));

                if (dtparodot.Columns.Contains("company") == false)
                    dtparodot.Columns.Add("company", typeof(String));

                if (dtparodot.Columns.Contains("website") == false)
                    dtparodot.Columns.Add("website", typeof(String));

                if (dtparodot.Columns.Contains("job_title") == false)
                    dtparodot.Columns.Add("job_title", typeof(String));

                if (dtparodot.Columns.Contains("department") == false)
                    dtparodot.Columns.Add("department", typeof(String));

                if (dtparodot.Columns.Contains("country") == false)
                    dtparodot.Columns.Add("country", typeof(String));

                if (dtparodot.Columns.Contains("address_one") == false)
                    dtparodot.Columns.Add("address_one", typeof(String));

                if (dtparodot.Columns.Contains("address_two") == false)
                    dtparodot.Columns.Add("address_two", typeof(String));

                if (dtparodot.Columns.Contains("city") == false)
                    dtparodot.Columns.Add("city", typeof(String));

                if (dtparodot.Columns.Contains("state") == false)
                    dtparodot.Columns.Add("state", typeof(String));

                if (dtparodot.Columns.Contains("territory") == false)
                    dtparodot.Columns.Add("territory", typeof(String));

                if (dtparodot.Columns.Contains("zip") == false)
                    dtparodot.Columns.Add("zip", typeof(String));

                if (dtparodot.Columns.Contains("phone") == false)
                    dtparodot.Columns.Add("phone", typeof(String));

                if (dtparodot.Columns.Contains("fax") == false)
                    dtparodot.Columns.Add("fax", typeof(String));

                if (dtparodot.Columns.Contains("source") == false)
                    dtparodot.Columns.Add("source", typeof(String));

                if (dtparodot.Columns.Contains("annual_revenue") == false)
                    dtparodot.Columns.Add("annual_revenue", typeof(String));

                if (dtparodot.Columns.Contains("employees") == false)
                    dtparodot.Columns.Add("employees", typeof(String));

                if (dtparodot.Columns.Contains("industry") == false)
                    dtparodot.Columns.Add("industry", typeof(String));

                if (dtparodot.Columns.Contains("years_in_business") == false)
                    dtparodot.Columns.Add("years_in_business", typeof(String));

                if (dtparodot.Columns.Contains("comments") == false)
                    dtparodot.Columns.Add("comments", typeof(String));

                if (dtparodot.Columns.Contains("notes") == false)
                    dtparodot.Columns.Add("notes", typeof(String));

                if (dtparodot.Columns.Contains("score") == false)
                    dtparodot.Columns.Add("score", typeof(String));

                if (dtparodot.Columns.Contains("grade") == false)
                    dtparodot.Columns.Add("grade", typeof(String));

                if (dtparodot.Columns.Contains("last_activity_at") == false)
                    dtparodot.Columns.Add("last_activity_at", typeof(String));

                if (dtparodot.Columns.Contains("recent_interaction") == false)
                    dtparodot.Columns.Add("recent_interaction", typeof(String));

                if (dtparodot.Columns.Contains("crm_lead_fid") == false)
                    dtparodot.Columns.Add("crm_lead_fid", typeof(String));

                if (dtparodot.Columns.Contains("crm_contact_fid") == false)
                    dtparodot.Columns.Add("crm_contact_fid", typeof(String));

                if (dtparodot.Columns.Contains("crm_owner_fid") == false)
                    dtparodot.Columns.Add("crm_owner_fid", typeof(String));

                if (dtparodot.Columns.Contains("crm_account_fid") == false)
                    dtparodot.Columns.Add("crm_account_fid", typeof(String));

                if (dtparodot.Columns.Contains("crm_last_sync") == false)
                    dtparodot.Columns.Add("crm_last_sync", typeof(String));

                if (dtparodot.Columns.Contains("crm_url") == false)
                    dtparodot.Columns.Add("crm_url", typeof(String));

                if (dtparodot.Columns.Contains("is_do_not_email") == false)
                    dtparodot.Columns.Add("is_do_not_email", typeof(String));

                if (dtparodot.Columns.Contains("is_do_not_call") == false)
                    dtparodot.Columns.Add("is_do_not_call", typeof(String));

                if (dtparodot.Columns.Contains("opted_out") == false)
                    dtparodot.Columns.Add("opted_out", typeof(String));

                if (dtparodot.Columns.Contains("is_reviewed") == false)
                    dtparodot.Columns.Add("is_reviewed", typeof(String));

                if (dtparodot.Columns.Contains("is_starred") == false)
                    dtparodot.Columns.Add("is_starred", typeof(String));

                if (dtparodot.Columns.Contains("created_at") == false)
                    dtparodot.Columns.Add("created_at", typeof(String));

                if (dtparodot.Columns.Contains("updated_at") == false)
                    dtparodot.Columns.Add("updated_at", typeof(String));

                if (dtparodot.Columns.Contains("type") == false)
                    dtparodot.Columns.Add("type", typeof(String));


                if (strFileName.StartsWith("acfcs-"))
                {
                    Logger.WriteInfoLog("processing file starts with acfcs");

                    if (dtparodot.Columns.Contains("ACFCS_2015_Conference_request_for_info") == false)
                        dtparodot.Columns.Add("ACFCS_2015_Conference_request_for_info", typeof(String));

                    if (dtparodot.Columns.Contains("ACFCS_2015_Conference_at_a_Glance_Download") == false)
                        dtparodot.Columns.Add("ACFCS_2015_Conference_at_a_Glance_Download", typeof(String));

                    if (dtparodot.Columns.Contains("ACFCS_2015_Conference_Prospectus") == false)
                        dtparodot.Columns.Add("ACFCS_2015_Conference_Prospectus", typeof(String));

                    if (dtparodot.Columns.Contains("ACFCS_2015_Summit_Agenda_Download") == false)
                        dtparodot.Columns.Add("ACFCS_2015_Summit_Agenda_Download", typeof(String));

                    if (dtparodot.Columns.Contains("ACFCS_2015_Summit_Prospectus") == false)
                        dtparodot.Columns.Add("ACFCS_2015_Summit_Prospectus", typeof(String));

                    if (dtparodot.Columns.Contains("ACFCS_Candidate_Handbook_Download") == false)
                        dtparodot.Columns.Add("ACFCS_Candidate_Handbook_Download", typeof(String));

                    if (dtparodot.Columns.Contains("CFCS_Brochure") == false)
                        dtparodot.Columns.Add("CFCS_Brochure", typeof(String));

                }
                else if (strFileName.StartsWith("aceds-"))
                {
                    Logger.WriteInfoLog("processing file starts with aceds");

                    if (dtparodot.Columns.Contains("ACEDS_2015_Conference_request_for_info") == false)
                        dtparodot.Columns.Add("ACEDS_2015_Conference_request_for_info", typeof(String));

                    if (dtparodot.Columns.Contains("ACEDS_2015_Conference_at_a_Glance_Download") == false)
                        dtparodot.Columns.Add("ACEDS_2015_Conference_at_a_Glance_Download", typeof(String));

                    if (dtparodot.Columns.Contains("ACEDS_2015_Conference_Prospectus") == false)
                        dtparodot.Columns.Add("ACEDS_2015_Conference_Prospectus", typeof(String));

                    if (dtparodot.Columns.Contains("ACEDS_2015_Summit_Agenda_Download") == false)
                        dtparodot.Columns.Add("ACEDS_2015_Summit_Agenda_Download", typeof(String));

                    if (dtparodot.Columns.Contains("ACEDS_2015_Summit_Prospectus") == false)
                        dtparodot.Columns.Add("ACEDS_2015_Summit_Prospectus", typeof(String));

                    if (dtparodot.Columns.Contains("ACEDS_Candidate_Handbook_Download") == false)
                        dtparodot.Columns.Add("ACEDS_Candidate_Handbook_Download", typeof(String));

                    if (dtparodot.Columns.Contains("CEDS_Brochure") == false)
                        dtparodot.Columns.Add("CEDS_Brochure", typeof(String));

                }

                if (dtparodot.Columns.Contains("Colombian_Seminar_Program_at_a_Glance") == false)
                    dtparodot.Columns.Add("Colombian_Seminar_Program_at_a_Glance", typeof(String));

                if (dtparodot.Columns.Contains("FinCrime_Jobs") == false)
                    dtparodot.Columns.Add("FinCrime_Jobs", typeof(String));

                if (dtparodot.Columns.Contains("Lat_Am_2014_Conference_at_a_Glance_Download") == false)
                    dtparodot.Columns.Add("Lat_Am_2014_Conference_at_a_Glance_Download", typeof(String));

                if (dtparodot.Columns.Contains("Lat_Am_2015_Conference___request_info") == false)
                    dtparodot.Columns.Add("Lat_Am_2015_Conference___request_info", typeof(String));

                if (dtparodot.Columns.Contains("Lat_Am_2015_Conference_at_a_Glance") == false)
                    dtparodot.Columns.Add("Lat_Am_2015_Conference_at_a_Glance", typeof(String));

                if (dtparodot.Columns.Contains("Lat_Am_2015_Conference_Prospectus") == false)
                    dtparodot.Columns.Add("Lat_Am_2015_Conference_Prospectus", typeof(String));

                if (dtparodot.Columns.Contains("Lat_Am_Candidate_Handbook_Download") == false)
                    dtparodot.Columns.Add("Lat_Am_Candidate_Handbook_Download", typeof(String));

                if (dtparodot.Columns.Contains("Management_Level") == false)
                    dtparodot.Columns.Add("Management_Level", typeof(String));

                if (dtparodot.Columns.Contains("Spanish") == false)
                    dtparodot.Columns.Add("Spanish", typeof(String));


                if (strFileName.StartsWith("acfcs-"))
                {
                    Logger.WriteInfoLog(strFileName + " paradot Datatable process started");

                    var lstACFCSParodotProspect = (from Tableparodot in dtparodot.AsEnumerable()
                                                   select new
                                                   {
                                                       Id = Tableparodot["id"],
                                                       Campaign_id = Tableparodot["campaign_id"],
                                                       Salutation = Tableparodot["salutation"],
                                                       First_name = Tableparodot["first_name"],
                                                       Last_name = Tableparodot["last_name"],
                                                       Email = Tableparodot["email"],
                                                       Password = Tableparodot["password"],
                                                       Company = Tableparodot["company"],
                                                       Website = Tableparodot["website"],
                                                       Job_title = Tableparodot["job_title"],
                                                       Department = Tableparodot["department"],
                                                       Country = Tableparodot["country"],
                                                       Address_one = Tableparodot["address_one"],
                                                       Address_two = Tableparodot["address_two"],
                                                       City = Tableparodot["city"],
                                                       State = Tableparodot["state"],
                                                       Territory = Tableparodot["territory"],
                                                       Zip = Tableparodot["zip"],
                                                       Phone = Tableparodot["phone"],
                                                       Fax = Tableparodot["fax"],
                                                       Source = Tableparodot["source"],
                                                       Annual_revenue = Tableparodot["annual_revenue"],
                                                       Employees = Tableparodot["employees"],
                                                       Industry = Tableparodot["industry"],
                                                       Years_in_business = Tableparodot["years_in_business"],
                                                       Comments = Tableparodot["comments"],
                                                       Notes = Tableparodot["notes"],
                                                       Score = Tableparodot["score"],
                                                       Grade = Tableparodot["grade"],
                                                       Last_activity_at = Tableparodot["last_activity_at"],
                                                       Recent_interaction = Tableparodot["recent_interaction"],
                                                       Crm_lead_fid = Tableparodot["crm_lead_fid"],
                                                       Crm_contact_fid = Tableparodot["crm_contact_fid"],
                                                       Crm_owner_fid = Tableparodot["crm_owner_fid"],
                                                       Crm_account_fid = Tableparodot["crm_account_fid"],
                                                       Crm_last_sync = Tableparodot["crm_last_sync"],
                                                       Crm_url = Tableparodot["crm_url"],
                                                       Is_do_not_email = Tableparodot["is_do_not_email"],
                                                       Is_do_not_call = Tableparodot["is_do_not_call"],
                                                       Opted_out = Tableparodot["opted_out"],
                                                       Is_reviewed = Tableparodot["is_reviewed"],
                                                       Is_starred = Tableparodot["is_starred"],
                                                       Created_at = Tableparodot["created_at"],
                                                       Updated_at = Tableparodot["updated_at"],
                                                       ACFCS_2015_Conference_request_for_info = Tableparodot["ACFCS_2015_Conference_request_for_info"],
                                                       ACFCS_2015_Conference_at_a_Glance_Download = Tableparodot["ACFCS_2015_Conference_at_a_Glance_Download"],
                                                       ACFCS_2015_Conference_Prospectus = Tableparodot["ACFCS_2015_Conference_Prospectus"],
                                                       ACFCS_2015_Summit_Agenda_Download_ = Tableparodot["ACFCS_2015_Summit_Agenda_Download"],
                                                       ACFCS_2015_Summit_Prospectus = Tableparodot["ACFCS_2015_Summit_Prospectus"],
                                                       ACFCS_Candidate_Handbook_Download = Tableparodot["ACFCS_Candidate_Handbook_Download"],
                                                       CFCS_Brochure = Tableparodot["CFCS_Brochure"],
                                                       Colombian_Seminar_Program_at_a_Glance = Tableparodot["Colombian_Seminar_Program_at_a_Glance"],
                                                       FinCrime_Jobs = Tableparodot["FinCrime_Jobs"],
                                                       Lat_Am_2014_Conference_at_a_Glance_Download = Tableparodot["Lat_Am_2014_Conference_at_a_Glance_Download"],
                                                       Lat_Am_2015_Conference___request_info = Tableparodot["Lat_Am_2015_Conference___request_info"],
                                                       Lat_Am_2015_Conference_at_a_Glance = Tableparodot["Lat_Am_2015_Conference_at_a_Glance"],
                                                       Lat_Am_2015_Conference_Prospectus = Tableparodot["Lat_Am_2015_Conference_Prospectus"],
                                                       Lat_Am_Candidate_Handbook_Download = Tableparodot["Lat_Am_Candidate_Handbook_Download"],
                                                       Management_Level = Tableparodot["Management_Level"],
                                                       Spanish = Tableparodot["Spanish"],
                                                   }).ToList();
                    //to make list as datatable
                    DataTable dtLstparodot = ToDataTable(lstACFCSParodotProspect);
                    //to make data as json payload
                    DataTableToJSONWithStringBuilder(dtLstparodot, "pardotprospect", strFileName, "Paradot json Payload");
                }
                else if (strFileName.StartsWith("aceds-"))
                {
                    var lstACEDSParodotProspect = (from Tableparodot in dtparodot.AsEnumerable()
                                                   select new
                                                   {
                                                       Id = Tableparodot["id"],
                                                       Campaign_id = Tableparodot["campaign_id"],
                                                       Salutation = Tableparodot["salutation"],
                                                       First_name = Tableparodot["first_name"],
                                                       Last_name = Tableparodot["last_name"],
                                                       Email = Tableparodot["email"],
                                                       Password = Tableparodot["password"],
                                                       Company = Tableparodot["company"],
                                                       Website = Tableparodot["website"],
                                                       Job_title = Tableparodot["job_title"],
                                                       Department = Tableparodot["department"],
                                                       Country = Tableparodot["country"],
                                                       Address_one = Tableparodot["address_one"],
                                                       Address_two = Tableparodot["address_two"],
                                                       City = Tableparodot["city"],
                                                       State = Tableparodot["state"],
                                                       Territory = Tableparodot["territory"],
                                                       Zip = Tableparodot["zip"],
                                                       Phone = Tableparodot["phone"],
                                                       Fax = Tableparodot["fax"],
                                                       Source = Tableparodot["source"],
                                                       Annual_revenue = Tableparodot["annual_revenue"],
                                                       Employees = Tableparodot["employees"],
                                                       Industry = Tableparodot["industry"],
                                                       Years_in_business = Tableparodot["years_in_business"],
                                                       Comments = Tableparodot["comments"],
                                                       Notes = Tableparodot["notes"],
                                                       Score = Tableparodot["score"],
                                                       Grade = Tableparodot["grade"],
                                                       Last_activity_at = Tableparodot["last_activity_at"],
                                                       Recent_interaction = Tableparodot["recent_interaction"],
                                                       Crm_lead_fid = Tableparodot["crm_lead_fid"],
                                                       Crm_contact_fid = Tableparodot["crm_contact_fid"],
                                                       Crm_owner_fid = Tableparodot["crm_owner_fid"],
                                                       Crm_account_fid = Tableparodot["crm_account_fid"],
                                                       Crm_last_sync = Tableparodot["crm_last_sync"],
                                                       Crm_url = Tableparodot["crm_url"],
                                                       Is_do_not_email = Tableparodot["is_do_not_email"],
                                                       Is_do_not_call = Tableparodot["is_do_not_call"],
                                                       Opted_out = Tableparodot["opted_out"],
                                                       Is_reviewed = Tableparodot["is_reviewed"],
                                                       Is_starred = Tableparodot["is_starred"],
                                                       Created_at = Tableparodot["created_at"],
                                                       Updated_at = Tableparodot["updated_at"],
                                                       ACFCS_2015_Conference_request_for_info = Tableparodot["ACEDS_2015_Conference_request_for_info"],
                                                       ACFCS_2015_Conference_at_a_Glance_Download = Tableparodot["ACEDS_2015_Conference_at_a_Glance_Download"],
                                                       ACFCS_2015_Conference_Prospectus = Tableparodot["ACEDS_2015_Conference_Prospectus"],
                                                       ACFCS_2015_Summit_Agenda_Download_ = Tableparodot["ACEDS_2015_Summit_Agenda_Download"],
                                                       ACFCS_2015_Summit_Prospectus = Tableparodot["ACEDS_2015_Summit_Prospectus"],
                                                       ACFCS_Candidate_Handbook_Download = Tableparodot["ACEDS_Candidate_Handbook_Download"],
                                                       CFCS_Brochure = Tableparodot["CEDS_Brochure"],
                                                       Colombian_Seminar_Program_at_a_Glance = Tableparodot["Colombian_Seminar_Program_at_a_Glance"],
                                                       FinCrime_Jobs = Tableparodot["FinCrime_Jobs"],
                                                       Lat_Am_2014_Conference_at_a_Glance_Download = Tableparodot["Lat_Am_2014_Conference_at_a_Glance_Download"],
                                                       Lat_Am_2015_Conference___request_info = Tableparodot["Lat_Am_2015_Conference___request_info"],
                                                       Lat_Am_2015_Conference_at_a_Glance = Tableparodot["Lat_Am_2015_Conference_at_a_Glance"],
                                                       Lat_Am_2015_Conference_Prospectus = Tableparodot["Lat_Am_2015_Conference_Prospectus"],
                                                       Lat_Am_Candidate_Handbook_Download = Tableparodot["Lat_Am_Candidate_Handbook_Download"],
                                                       Management_Level = Tableparodot["Management_Level"],
                                                       Spanish = Tableparodot["Spanish"],
                                                   }).ToList();
                    DataTable dtLstparodot = ToDataTable(lstACEDSParodotProspect);
                    DataTableToJSONWithStringBuilder(dtLstparodot, "pardotprospect", strFileName, "Paradot json Payload");
                }
            }
            catch (Exception ex)
            {
                Logger.WriteErrorLog(ex, "", "");
            }
                #endregion

        }

C#
/// <summary>
        /// Generic List Converted to Data Table
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="items"></param>
        /// <returns></returns>
        public static DataTable ToDataTable<T>(List<T> items)
        {
            DataTable dataTable = new DataTable(typeof(T).Name);

            //Get all the properties
            PropertyInfo[] Props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
            foreach (PropertyInfo prop in Props)
            {
                //Setting column names as Property names
                dataTable.Columns.Add(prop.Name);
            }
            foreach (T item in items)
            {
                var values = new object[Props.Length];
                for (int i = 0; i < Props.Length; i++)
                {
                    //inserting property values to datatable rows
                    values[i] = Props[i].GetValue(item, null);
                }
                dataTable.Rows.Add(values);
            }
            //put a breakpoint here and check datatable
            return dataTable;
        }

        /// <summary>
        /// Data Table converted to Json payload and sent to http Url
        /// </summary>
        /// <param name="table"></param>
        /// <param name="ExportType"></param>
        /// <param name="FileName"></param>
        public  void DataTableToJSONWithStringBuilder(DataTable table, string ExportType, string FileName, string JsonName)
        {
            try
            {
                Logger.WriteInfoLog("Datatable converted to Json format");

                var JSONString = new StringBuilder();
                if (table.Rows.Count > 0)
                {
                    JSONString.Append("{");
                    JSONString.Append("\"" + "ExportType" + "\":" + "\"" + ExportType + "\"," + "\"" + System.Environment.NewLine + "BodyJson [");
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        JSONString.Append("{");
                        for (int j = 0; j < table.Columns.Count; j++)
                        {
                            if (j < table.Columns.Count - 1)
                            {
                                JSONString.Append("\"" + table.Columns[j].ColumnName.ToString() + "\":" + "\"" + table.Rows[i][j].ToString() + "\",");
                            }
                            else if (j == table.Columns.Count - 1)
                            {
                                JSONString.Append("\"" + table.Columns[j].ColumnName.ToString() + "\":" + "\"" + table.Rows[i][j].ToString() + "\"");
                            }
                            JSONString.Append(System.Environment.NewLine);
                        }
                        if (i == table.Rows.Count - 1)
                        {
                            JSONString.Append("}]");
                        }
                        else
                        {
                            JSONString.Append("},");
                        }
                        JSONString.Append(System.Environment.NewLine);
                    }
                    JSONString.Append("}");
                }
                Logger.WriteInfoLog("sending JSON Payload to URL");
                var stringPayload = JSONString.ToString();

                byte[] byteRequestData;
                byteRequestData = Encoding.UTF8.GetBytes(stringPayload.ToString());


                WebRequest request = WebRequest.Create(ConfigurationManager.AppSettings["JsonPayloadPostUrl"].ToString());
                //set the content type to JSON
                request.Method = "POST";
                request.ContentType = "";
                // "application/json";
                // Set the ContentLength property of the WebRequest.
                request.ContentLength = byteRequestData.Length;
                // Get the request stream.
                Stream dataStream = request.GetRequestStream();
                // Write the data to the request stream.
                dataStream.Write(byteRequestData, 0, byteRequestData.Length);
                // Close the Stream object.
                dataStream.Close();
                // Get the response.
                Logger.WriteInfoLog("Getting Response..");
                //
                WebResponse response = request.GetResponse();
                Logger.WriteInfoLog("Response stream started");
                // Get the stream containing content returned by the server.
                dataStream = response.GetResponseStream();
                //// Open the stream using a StreamReader for easy access.
                Logger.WriteInfoLog("Response stream started");
                StreamReader reader = new StreamReader(dataStream);
               string  strResponseFromServer = reader.ReadToEnd();

                HttpWebResponse httpResponse = (HttpWebResponse)response;
                string strStatusCode = httpResponse.StatusCode.ToString();
                Logger.WriteInfoLog("http Response code for- " + FileName + "----" + JsonName + "-------:" + httpResponse.StatusCode);

                //var httpContent = new StringContent(stringPayload);

                //using (var httpClient = new HttpClient())
                //{
                //    httpClient.DefaultRequestHeaders.ExpectContinue = false; 

                //    // Do the actual request and await the response
                //    var httpResponse = await httpClient.PostAsync(ConfigurationManager.AppSettings["JsonPayloadPostUrl"].ToString(), httpContent);

                //    Logger.WriteInfoLog("http Response code for- " + FileName + "----" + JsonName + "-------:" + httpResponse.StatusCode);

                //    if (httpResponse.IsSuccessStatusCode == false)
                //    {
                //        Logger.WriteInfoLog(httpResponse.Content.ToString());
                //    }
                //}

            }
            catch (Exception ex)
            {
                Logger.WriteErrorLog(ex,FileName,JsonName);
            }
        }

        /// <summary>
        /// After json Payloads Sent to url XML files moved to url
        /// </summary>
        /// <param name="sourceFilePath"></param>
        /// <param name="destinationDirectorypath"></param>
        public void MovefilesFromSourceToDestination(string sourceFilePath, string destinationDirectorypath)
        {
            try
            {
                Logger.WriteInfoLog("To move XML Files to Archive Folder");

                //if file already existed Need to replace
                if (File.Exists(destinationDirectorypath + "\\" + Path.GetFileName(sourceFilePath)))
                {
                 File.Delete(destinationDirectorypath + "\\" + Path.GetFileName(sourceFilePath));
                }
                //To move file from source to destination folder
                File.Move(sourceFilePath, destinationDirectorypath + "\\" + Path.GetFileName(sourceFilePath));
            }
            catch (Exception ex)
            {
                Logger.WriteErrorLog(ex,"","");
            }
        }


What I have tried:

deploying Release folder
Regedit Service pipe timeout
requestdelay TimeOut
Thread Sleep
Posted
Updated 12-Sep-16 21:40pm
v2
Comments
phil.o 12-Sep-16 5:19am    
If you do not take time to describe your problem with actual relevant contextual informations, you may have a hard time finding someone wanting to spend time analyzing your issue.
Please use the green "Improve question" button and give us details about your problem.
F-ES Sitecore 12-Sep-16 5:32am    
Your service is taking too long to start, probably over 30 seconds. You haven't posted any code so it's impossible to say why, but most likely is that you haven't written it in the appropriate manner and are expecting the "work" to all be done in the OnStart event (ie you're doing a loop inside that event waiting for things to do).

C#
Thread.Sleep(31000);
So you have the executing thread sleeping 31 seconds during OnStart, while Windows expectes that method to have returned within 30 seconds (unless stated that it takes longer)? That call is not only useless, it is destructive.
Furthermore, do all that file processing in a different thread/task.
C#
protected override void OnStart(string[] args)
{
    Logger.WriteInfoLog("Service Started");
    System.Threading.Tasks.Task.Run(() => ProceesXMlFiles());
}
 
Share this answer
 
Comments
Jochen Arndt 13-Sep-16 3:46am    
OMG

My five
Maciej Los 13-Sep-16 3:57am    
5ed!
depending on how you've written your service, you may be able to use ServiceBase.RequestAdditionalTime Method (Int32) (System.ServiceProcess)[^]

- you are much better logging and profiling your service to see what/where the 'holdup' is before you do that though, if you cant speed up the Startup then apply RequestAdditionalTime
 
Share this answer
 
Comments
Member 10236682 12-Sep-16 6:30am    
already tried for RequestAdditionalTime even
actualaly iam having 300xML FILES TO PROCESS .AFTER GETTING THIS DAILOGUE BOX EVEN PROCESS WAS DONE THE BACKGROUND .BUT TIMEOUT POPUP IS COMING
Garth J Lancaster 12-Sep-16 6:54am    
you havnt provided any code so we dont know how your service is written - I have this sneaking suspicion from what you've said, that you're trying to do waaaaaay too much in OnStart() - I'd recommend finding a good reference source for services - maybe https://www.syncfusion.com/resources/techportal/details/ebooks/windowsservices and start there
Member 10236682 5-Oct-16 2:52am    
thanks for the suggestion I fallowed it on start taking too long time so I placed thread and all the process moved to background its working fine

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900