private int ProcessFile(string filePath)
        {
            int importedSopCount = 0;
            bool isDicomFile = false;
            bool skipped = false;
            FileInfo fileInfo = new FileInfo(filePath);
            if (fileInfo.Exists)
            {
                DicomFile file;
                try
                {
                    file = new DicomFile(filePath);
                    file.Load();
                    isDicomFile = true;

                    string studyInstanceUid;
                    if (file.DataSet[DicomTags.StudyInstanceUid].TryGetString(0, out studyInstanceUid))
                    {
                        skipped = _skippedStudies.Contains(studyInstanceUid);
                        if (!skipped)
                        {
                            InitializeImporter();

                            try
                            {
                                DicomProcessingResult result = _importer.Import(file);
                                if (result.Successful)
                                {
                                    if (result.Duplicate)
                                    {
                                        // was imported but is duplicate
                                    }
                                    else
                                    {
                                        importedSopCount = 1;
                                        Platform.Log(LogLevel.Info, "Imported SOP {0} to {1}", result.SopInstanceUid, _parms.PartitionAE);
                                        ProgressChangedEventArgs progress = new ProgressChangedEventArgs(100, result.SopInstanceUid);

                                        // Fire the imported event.
                                        SopImportedEventArgs args = new SopImportedEventArgs
                                                                    	{
                                                                    		StudyInstanceUid = result.StudyInstanceUid,
                                                                    		SeriesInstanceUid = result.SeriesInstanceUid,
                                                                    		SopInstanceUid = result.SopInstanceUid
                                                                    	};
                                    	EventsHelper.Fire(_sopImportedHandlers, this, args);

                                        OnProgressChanged(progress);
                                    }
                                }
                                else
                                {
                                    if (result.DicomStatus == DicomStatuses.StorageStorageOutOfResources)
                                    {
                                        if (result.RestoreRequested)
                                            EventsHelper.Fire(_restoreTriggerHandlers, this, null);

                                        Platform.Log(LogLevel.Info, "Images for study {0} cannot be imported at this time because: {1}", result.StudyInstanceUid, result.ErrorMessage);
                                        _skippedStudies.Add(result.StudyInstanceUid);
                                        skipped = true;
                                    }
                                    else
                                    {
										Platform.Log(LogLevel.Warn, "Failed to import {0} to {1} : {2}", filePath, _parms.PartitionAE, result.ErrorMessage);
                                    }
                                }
                            }
                            catch (DicomDataException ex)
                            {
                                // skip to next file, this file will be deleted
                                Platform.Log(LogLevel.Warn, ex, "Failed to import {0} to {1}: {2}", filePath, _parms.PartitionAE, ex.Message);
                                skipped = true;
                            }
                        }
                    }
                    else
                    {
                        throw new ApplicationException("Sop does not contains Study Instance Uid tag");
                    }
                }
                catch(Exception ex)
                {
                    Platform.Log(LogLevel.Error, ex);
                    
                }
                finally
                {
                    try
                    {
                        if (importedSopCount > 0)
                        {
                            DeleteFile(fileInfo);
                        }
                        else if (!isDicomFile)
                        {
                            DeleteFile(fileInfo);
                        }
                        else
                        {
                            //is dicom file but could not be imported.
                            if (!skipped)
                                DeleteFile(fileInfo);
                        }
                    }
                    catch(IOException ex)
                    {
                        Platform.Log(LogLevel.Error, ex, "Unable to delete file after it has been imported: {0}", fileInfo.FullName);
                        // Raise alert because this file is stuck in the incoming folder and becomes a duplicate when it is imported again later on.
                        // Depending on the duplicate policy, SIQ may be filled with many duplicate entries.
                        ServerPlatform.Alert(AlertCategory.Application, AlertLevel.Critical, "File Importer", -1, null, TimeSpan.Zero,
                                             "The following file has been imported but could not be removed : {0}.\nError: {1}",
                                             fileInfo.FullName, ex.Message);
                    }

                }
            }

            return importedSopCount;
        }
        private int ProcessFile(string filePath)
        {
            int      importedSopCount = 0;
            bool     isDicomFile      = false;
            bool     skipped          = false;
            FileInfo fileInfo         = new FileInfo(filePath);

            if (fileInfo.Exists)
            {
                DicomFile file;
                try
                {
                    file = new DicomFile(filePath);
                    file.Load();
                    isDicomFile = true;

                    string studyInstanceUid;
                    if (file.DataSet[DicomTags.StudyInstanceUid].TryGetString(0, out studyInstanceUid))
                    {
                        skipped = _skippedStudies.Contains(studyInstanceUid);
                        if (!skipped)
                        {
                            InitializeImporter();

                            try
                            {
                                DicomProcessingResult result = _importer.Import(file);
                                if (result.Successful)
                                {
                                    if (result.Duplicate)
                                    {
                                        // was imported but is duplicate
                                    }
                                    else
                                    {
                                        importedSopCount = 1;
                                        Platform.Log(LogLevel.Info, "Imported SOP {0} to {1}", result.SopInstanceUid, _parms.PartitionAE);
                                        ProgressChangedEventArgs progress = new ProgressChangedEventArgs(100, result.SopInstanceUid);

                                        // Fire the imported event.
                                        SopImportedEventArgs args = new SopImportedEventArgs
                                        {
                                            StudyInstanceUid  = result.StudyInstanceUid,
                                            SeriesInstanceUid = result.SeriesInstanceUid,
                                            SopInstanceUid    = result.SopInstanceUid
                                        };
                                        EventsHelper.Fire(_sopImportedHandlers, this, args);

                                        OnProgressChanged(progress);
                                    }
                                }
                                else
                                {
                                    if (result.DicomStatus == DicomStatuses.StorageStorageOutOfResources)
                                    {
                                        if (result.RestoreRequested)
                                        {
                                            EventsHelper.Fire(_restoreTriggerHandlers, this, null);
                                        }

                                        Platform.Log(LogLevel.Info, "Images for study {0} cannot be imported at this time because: {1}", result.StudyInstanceUid, result.ErrorMessage);
                                        _skippedStudies.Add(result.StudyInstanceUid);
                                        skipped = true;
                                    }
                                    else
                                    {
                                        Platform.Log(LogLevel.Warn, "Failed to import {0} to {1} : {2}", filePath, _parms.PartitionAE, result.ErrorMessage);
                                    }
                                }
                            }
                            catch (DicomDataException ex)
                            {
                                // skip to next file, this file will be deleted
                                Platform.Log(LogLevel.Warn, ex, "Failed to import {0} to {1}: {2}", filePath, _parms.PartitionAE, ex.Message);
                                skipped = true;
                            }
                        }
                    }
                    else
                    {
                        throw new ApplicationException("Sop does not contains Study Instance Uid tag");
                    }
                }
                catch (Exception ex)
                {
                    Platform.Log(LogLevel.Error, ex);
                }
                finally
                {
                    try
                    {
                        if (importedSopCount > 0)
                        {
                            DeleteFile(fileInfo);
                        }
                        else if (!isDicomFile)
                        {
                            DeleteFile(fileInfo);
                        }
                        else
                        {
                            //is dicom file but could not be imported.
                            if (!skipped)
                            {
                                DeleteFile(fileInfo);
                            }
                        }
                    }
                    catch (IOException ex)
                    {
                        Platform.Log(LogLevel.Error, ex, "Unable to delete file after it has been imported: {0}", fileInfo.FullName);
                        // Raise alert because this file is stuck in the incoming folder and becomes a duplicate when it is imported again later on.
                        // Depending on the duplicate policy, SIQ may be filled with many duplicate entries.
                        ServerPlatform.Alert(AlertCategory.Application, AlertLevel.Critical, "File Importer", -1, null, TimeSpan.Zero,
                                             "The following file has been imported but could not be removed : {0}.\nError: {1}",
                                             fileInfo.FullName, ex.Message);
                    }
                }
            }

            return(importedSopCount);
        }