Службы Windows, заканчивающиеся рядом с JsonConvert.DeserializeObject - PullRequest
1 голос
/ 22 мая 2019

Ниже приведен код, написанный для оконных сервисов для копирования файлов.Он заканчивается строкой «JsonConvert.DeserializeObject> (jsonStirng);»

public static void copyfiles()
{
    getLog("Before querying");
    SqlDataReader reader = select();
    if (reader.HasRows)
    {
        reader.Read();               
        string jsonStirng = reader["parameter"].ToString();
        getLog("Found rows" + jsonStirng); // this will get log with values
        try
        {

            var result = JsonConvert.DeserializeObject<List<RootObject>>(jsonStirng);
            getLog("result =>" + result[0].FOLDER_NAME); // this ignore, if remove above line, this log will work.
            // continue logic for copying files..
            }

        }
        catch (Exception e)
        {
            getLog("Fail to copy files"+e);
        }

    }
    else
    {
        getLog("No rows found.");
    }
    reader.Close();
}

Ниже приведен журнал, который я получаю

ID  DATE    THREAD  LEVEL   LOGGER  MESSAGE
141 2019-05-22 17:09:02.273 Windows Services-Copy files INFO    OS  Found rows[{"FOLDER_TYPE":"UPLOAD_FOLDER","FOLDER_NAME":"UPLOAD_FOLDER\\"},{"FOLDER_TYPE":"DATA_FOLDER","FOLDER_NAME":"E:\\Suresh\\Projects\\TribandBISE\\BISE_C\\BISE_C\\DATA_FOLDER\\"},{"FOLDER_TYPE":"SOURCE_FOLDER","FOLDER_NAME":"SOURCE_FOLDER\\"},{"FOLDER_TYPE":"DB_BACKUP_FOLDER","FOLDER_NAME":"DATA_FOLDER\\DB_BACKUP_FOLDER"}]
140 2019-05-22 17:09:02.250 Windows Services-Copy files INFO    OS  inside select 
139 2019-05-22 17:09:02.240 Windows Services-Copy files INFO    OS  Before querying
138 2019-05-22 17:09:02.230 Windows Services-Copy files INFO    OS  Code initiated
137 2019-05-22 17:09:02.220 Windows Services-Copy files INFO    OS  windows service Copy_Data_Files initiated
136 2019-05-22 17:05:40.353 Windows Services-Copy files INFO    OS  error in init windows service
135 2019-05-22 17:05:40.050 Windows Services-Copy files INFO    OS  Code initiated

1 Ответ

0 голосов
/ 22 мая 2019

Вы можете пройти через свой сервис как обычное приложение в vs, изменив основную точку входа в сервис.

static void Main()
{
/////IF DEBUG The service will create all resource and allow code stepthrough
#if (!DEBUG)
    //NO DEBUG - Production code ran here
    System.ServiceProcess.ServiceBase[] ServicesToRun;
    ServicesToRun = new System.ServiceProcess.ServiceBase[] { new MyService() };
    System.ServiceProcess.ServiceBase.Run(ServicesToRun);
#else
    // Debug code: this allows the process to run as a non-service.
    // It will kick off the service start point, but never kill it.
    // Shut down the debugger to exit
    MyService service = new MyService();
    service.OnStart(null);    
    System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
#endif 
}
...