private void TaskExecuted(DocumentImportTask task)
        {
            if (task.DeleteAfterImport)
            {
                var fname = task.Uri.LocalPath;
                try
                {
                    File.Delete(fname);
                }
                catch (Exception ex)
                {
                    Logger.ErrorFormat(ex, "Delete source failed: {0}", fname);
                }
            }

            if (DeleteTaskFileAfterImport)
            {
                try
                {
                    File.Delete(task.PathToTaskFile);
                }
                catch (Exception ex)
                {
                    Logger.ErrorFormat(ex, "Delete task failed: {0}", task.PathToTaskFile);
                    throw;
                }
            }
        }
Example #2
0
        protected async override Task <ProcessResult> OnPolling(PollerJobParameters parameters, string workingFolder)
        {
            String      format = parameters.All.GetOrDefault(JobKeys.ThumbnailFormat)?.ToLower() ?? "png";
            ImageFormat imageFormat;

            switch (format)
            {
            case "png":
                imageFormat = ImageFormat.Png;
                break;

            case "bmp":
                imageFormat = ImageFormat.Bmp;
                break;

            default:
                imageFormat = ImageFormat.Png;
                break;
            }
            Logger.DebugFormat("Conversion for jobId {0} in format {1} starting", parameters.JobId, format);
            string pathToFile = await DownloadBlob(parameters.TenantId, parameters.JobId, parameters.FileName, workingFolder).ConfigureAwait(false);

            using (SolidEdgeDocument document = SolidEdgeDocument.Open(pathToFile))
            {
                Logger.Debug(String.Format("ClassId: '{0}'", document.ClassId));
                Logger.Debug(String.Format("CreatedVersion: '{0}'", document.CreatedVersion));
                Logger.Debug(String.Format("LastSavedVersion: '{0}'", document.LastSavedVersion));
                Logger.Debug(String.Format("Created: '{0}'", document.Created));
                Logger.Debug(String.Format("LastModified: '{0}'", document.LastModified));
                Logger.Debug(String.Format("Status: '{0}'", document.Status));

                String thumbFileName = Path.ChangeExtension(pathToFile, "." + format);
                using (Bitmap bitmap = document.GetThumbnail())
                {
                    bitmap.Save(thumbFileName, imageFormat);
                }
                if (File.Exists(thumbFileName))
                {
                    await AddFormatToDocumentFromFile(
                        parameters.TenantId,
                        parameters.JobId,
                        new DocumentFormat(DocumentFormats.RasterImage),
                        thumbFileName,
                        new Dictionary <string, object>());

                    Logger.DebugFormat("Conversion of {0} in format {1} done", parameters.JobId, format);
                    return(ProcessResult.Ok);
                }
            }

            return(ProcessResult.Fail("Unable to extract thumbnail"));
        }
Example #3
0
        public static FileStream OpenWrite(string path)
        {
            if (!DsFile.Exists(path))
            {
                using (DsFile.Create(path));
            }
            if (path != null && path.Length < 240)
            {
                return(System.IO.File.OpenWrite(path));
            }

            return(MyFile.OpenWrite(path));
        }
Example #4
0
        public static void WriteAllText(string fileName, string textFile)
        {
            if (DsFile.Exists(fileName))
            {
                DsFile.Delete(fileName);
            }

            if (fileName != null && fileName.Length < 240)
            {
                System.IO.File.WriteAllText(fileName, textFile);
            }
            else
            {
                MyFile.WriteAllText(fileName, textFile);
            }
        }
Example #5
0
        public static int Main(string[] args)
        {
            try
            {
                Native.DisableWindowsErrorReporting();
                Int32 exitCode;
                if (args.Length > 0)
                {
                    var autoExecution = FindArgument(args, "/autoRestart:");
                    if ("true".Equals(autoExecution, StringComparison.OrdinalIgnoreCase))
                    {
                        SetupAutoRestart();
                    }

                    String dsBaseAddress = FindArgument(args, "/dsuris:");
                    String queueName     = FindArgument(args, "/queue:");
                    String handle        = FindArgument(args, "/handle:", "Default");
                    if (String.IsNullOrEmpty(dsBaseAddress) || String.IsNullOrEmpty(queueName))
                    {
                        Console.WriteLine("Error in parameters: dsuris={0} queue={1}", dsBaseAddress, queueName);
                        Console.ReadKey();
                        return(-1);
                    }

                    exitCode = SingleJobStart(dsBaseAddress, queueName, handle);
                    if (exitCode > 0)
                    {
                        ReStart();
                    }
                    return(exitCode);
                }

                Console.WriteLine("Wrong command line. This utilities expetcs following parameters:");
                Console.WriteLine("/dsuris:http://localhost:5123 - List of addresses (comma separated) of document store uris.");
                Console.WriteLine("/queue:tika - Name of the queue");
                Console.WriteLine("/handle:xxxxx - Optional, a string that identify this worker");

                Console.ReadKey();
                return(0);
            }
            catch (Exception ex)
            {
                var fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "_lastError.txt");
                File.WriteAllText(fileName, ex.ToString());
                throw;
            }
        }
        internal DocumentImportTask LoadTask(string pathToFile)
        {
            try
            {
                var asJson = File.ReadAllText(pathToFile)
                             .Replace("%CURRENT_DIR%", Path.GetDirectoryName(pathToFile).Replace("\\", "/"));

                var task = JsonConvert.DeserializeObject <DocumentImportTask>(asJson, PocoSerializationSettings.Default);
                task.PathToTaskFile = pathToFile;
                task.FileTimestamp  = File.GetLastWriteTimeUtc(pathToFile);
                return(task);
            }
            catch (Exception ex)
            {
                Logger.ErrorFormat(ex, "failed to deserialize {0}", pathToFile);
                return(null);
            }
        }
Example #7
0
        protected async override Task <ProcessResult> OnPolling(PollerJobParameters parameters, string workingFolder)
        {
            String format        = parameters.All.GetOrDefault(JobKeys.ThumbnailFormat) ?? "png";
            Int32  secondsOffset = Int32.Parse(parameters.All.GetOrDefault("thumb_seconds_offset") ?? "10");

            Logger.DebugFormat("Conversion for jobId {0} in format {1} starting", parameters.JobId, format);

            String vlcExecutable = Helper.GetExecutableLocation();

            if (!File.Exists(vlcExecutable))
            {
                String error = String.Format("Unable to find VLC.exe executable in standard folders. You can specify VLC directory with 'vlc_location' job parameter or with 'vlc_location' app config configuration");
                Logger.ErrorFormat(error);
                Console.WriteLine("Unable to start converter, press a key to close.");
                Console.ReadKey();
                throw new ApplicationException(error);
            }

            var worker = new VlcCommandLineThumbnailCreator(vlcExecutable, format, Logger);

            String networkStream = base.GetBlobUriForJobBlob(parameters.TenantId, parameters.JobId);
            String thumbNail     = worker.CreateThumbnail(networkStream, workingFolder, secondsOffset);

            if (String.IsNullOrEmpty(thumbNail))
            {
                Logger.WarnFormat("Conversion returned no thumbnail for file {0} - job {1}", parameters.FileName, parameters.JobId);
            }
            else
            {
                await AddFormatToDocumentFromFile(
                    parameters.TenantId,
                    parameters.JobId,
                    new DocumentFormat(DocumentFormats.RasterImage),
                    thumbNail,
                    new Dictionary <string, object>());

                Logger.DebugFormat("Conversion of {0} in format {1} done", parameters.JobId, format);
            }
            return(ProcessResult.Ok);
        }
        private static int Main(string[] args)
        {
            var lastErrorFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "_lastError.txt");

            if (File.Exists(lastErrorFileName))
            {
                File.Delete(lastErrorFileName);
            }
            try
            {
                MongoRegistration.RegisterMongoConversions(
                    "NEventStore.Persistence.MongoDB"
                    );

                MongoFlatMapper.EnableFlatMapping(true);

                CommandsExtensions.EnableDiagnostics = true;
                Native.DisableWindowsErrorReporting();
                MongoFlatMapper.EnableFlatMapping(true); //before any chanche that the driver scan any type.
                Int32 executionExitCode;
                if (args.Length == 1 && (args[0] == "install" || args[0] == "uninstall"))
                {
                    executionExitCode = (Int32)StartForInstallOrUninstall();
                }
                else
                {
                    executionExitCode = (Int32)StandardDocumentStoreStart();
                }
                return(executionExitCode);
            }
            catch (Exception ex)
            {
                File.WriteAllText(lastErrorFileName, ex.ToString());
                throw;
            }
        }
        internal void UploadFile(String jobFile, DocumentImportTask task)
        {
            String fname = "";

            try
            {
                TenantContext.Enter(task.Tenant);

                if (!task.Uri.IsFile)
                {
                    LogAndThrow("Error importing task file {0}: Uri is not a file: {1}", jobFile, task.Uri);
                }

                fname = task.Uri.LocalPath;

                if (FileHasImportFailureMarker(fname, task.FileTimestamp))
                {
                    return;
                }

                if (!File.Exists(fname))
                {
                    LogAndThrow("Error importing task file {0}: File missing: {1}", jobFile, fname);
                }

                var blobStore         = GetBlobStoreForTenant();
                var identityGenerator = GetIdentityGeneratorForTenant();
                if (blobStore == null || identityGenerator == null)
                {
                    Logger.ErrorFormat("Tenant {1} not found or not configured for file: {1}", task.Tenant, fname);
                    return;
                }

                BlobId blobId;
                if (!String.IsNullOrEmpty(task.FileName))
                {
                    //use the real file name from the task not the name of the file
                    using (FileStream fs = File.Open(fname, FileMode.Open, FileAccess.Read))
                    {
                        blobId = blobStore.Upload(task.Format, new FileNameWithExtension(task.FileName), fs);
                    }
                }
                else
                {
                    //No filename given in task, use name of the blob
                    blobId = blobStore.Upload(task.Format, fname);
                }

                if (task.Format == OriginalFormat)
                {
                    var descriptor = blobStore.GetDescriptor(blobId);
                    var fileName   = new FileNameWithExtension(task.FileName);
                    var handleInfo = new DocumentHandleInfo(task.Handle, fileName, task.CustomData);
                    var documentId = identityGenerator.New <DocumentDescriptorId>();

                    var createDocument = new InitializeDocumentDescriptor(
                        documentId,
                        blobId,
                        handleInfo,
                        descriptor.Hash,
                        fileName
                        );
                    _commandBus.Send(createDocument, "import-from-file");
                }
                else
                {
                    var reader     = _tenantAccessor.Current.Container.Resolve <IDocumentWriter>();
                    var handle     = reader.FindOneById(task.Handle);
                    var documentId = handle.DocumentDescriptorId;

                    var command = new AddFormatToDocumentDescriptor(
                        documentId,
                        task.Format,
                        blobId,
                        new PipelineId("user-content")
                        );
                    _commandBus.Send(command, "import-from-file");
                }

                TaskExecuted(task);
                DeleteImportFailure(fname);
            }
            catch (Exception ex)
            {
                Logger.ErrorFormat(ex, "Job Import Queue - Error importing {0} - {1}", jobFile, ex.Message);
                ImportFailure failure = new ImportFailure()
                {
                    Error     = ex.ToString(),
                    FileName  = fname,
                    Timestamp = DateTime.Now,
                    ImportFileTimestampTicks = task.FileTimestamp.Ticks,
                };
                MarkImportFailure(failure);
            }
            finally
            {
                TenantContext.Exit();
            }
        }