Ejemplo n.º 1
0
        public static void DeleteDocument(string documentId, bool preventIfPreCached, bool throwIfNull)
        {
            var cache = ServiceHelper.Cache;

            using (var document = DocumentFactory.LoadFromCache(cache, documentId))
            {
                if (throwIfNull)
                {
                    DocumentHelper.CheckLoadFromCache(document);
                }

                if (document != null)
                {
                    // Check if it's one of our pre-cached documents.
                    // If it is, don't remove it from the cache.
                    if (PreCacheHelper.PreCacheExists && document.Uri != null)
                    {
                        if (preventIfPreCached && PreCacheHelper.CheckDocument(document.Uri, document.Images.MaximumImagePixelSize) != null)
                        {
                            return;
                        }
                        else
                        {
                            PreCacheHelper.RemoveDocument(document.Uri, new int[] { document.Images.MaximumImagePixelSize });
                        }
                    }

                    document.AutoDeleteFromCache = true;
                    // But not the children documents (if any)
                    foreach (var child in document.Documents)
                    {
                        child.AutoDeleteFromCache = false;
                    }
                    document.AutoDisposeDocuments = true;
                }
            }
        }
        public static void InitializeService()
        {
            /* This method is called by Application_Start of the web service
             * We will initialize the global and static objects used through out the demos and
             * Each controller will be able to use these same objects.
             * Controller-specific initialization is performed in InitializeController
             */

            // Set the license, initialize the cache and various objects

            // For the license, the TestController.Ping method is used to check the status of this
            // So save the values here to get them later
            try
            {
                SetLicense();
                IsKernelExpired = RasterSupport.KernelExpired;
            }
            catch
            {
                IsKernelExpired = true;
            }

            if (!IsKernelExpired)
            {
                // The license is OK, continue
                try
                {
                    // This setting disables disk access when creating temp files
                    if (!GetSettingBoolean(Key_Application_AllowTempFilesFromDisk))
                    {
                        RasterDefaults.TempFileMode = LeadTempFileMode.Memory;
                    }

                    string tempDirectory = GetSettingValue(ServiceHelper.Key_Application_TempDirectory);
                    if (!string.IsNullOrEmpty(tempDirectory))
                    {
                        tempDirectory = ServiceHelper.GetAbsolutePath(tempDirectory);
                        RasterDefaults.TemporaryDirectory = tempDirectory;
                    }

                    SetMultiplatformSupport();

                    CreateCache();
                    PreCacheHelper.CreatePreCache();
                    SetRasterCodecsOptions(DocumentFactory.RasterCodecsTemplate, 0);

                    LoadMimeTypesWhitelist();

                    if (GetSettingBoolean(Key_Document_OnlyAllowedMimeTypes))
                    {
                        /*
                         * If true, all unspecified mimeTypes are automatically considered "denied".
                         * This effectively means that only mimeTypes in the "allowed" list are accepted.
                         */
                        DocumentFactory.MimeTypes.DefaultStatus = DocumentMimeTypeStatus.Denied;
                    }

                    _autoUpdateHistory     = GetSettingBoolean(Key_Document_AutoUpdateHistory);
                    _returnRequestUserData = GetSettingBoolean(Key_Application_ReturnRequestUserData);
                }
                catch
                {
                    // Let this pass, it is checked again in TestController.Ping
                }

                CreateOCREngine();
                CreateAnnRenderingEngine();
            }
        }