Example #1
0
        /// <summary>
        /// Read a file from the storage area.
        /// This function reads the content of a given file from the storage area that is currently used by Orthanc.
        /// </summary>
        /// <param name="context">The Orthanc plugin context, as received by OrthancPluginInitialize().</param>
        /// <param name="target">The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().</param>
        /// <param name="storageArea">The storage area.</param>
        /// <param name="uuid">The identifier of the file to be read.</param>
        /// <param name="type">The type of the file content.</param>
        /// <returns>0 if success, other value if error.</returns>
        public static OrthancPluginErrorCode OrthancPluginStorageAreaRead(ref OrthancPluginContext context, IntPtr target, IntPtr storageArea, IntPtr uuid, OrthancPluginContentType type)
        {
            IntPtr ptr = IntPtr.Zero;

            try
            {
                _OrthancPluginStorageAreaRead pr = new _OrthancPluginStorageAreaRead();
                pr.target      = target;
                pr.storageArea = storageArea;
                pr.uuid        = uuid;
                pr.type        = type;

                int size = Marshal.SizeOf(pr);
                ptr = Marshal.AllocHGlobal(size);
                Marshal.StructureToPtr(pr, ptr, true);

                return(context.InvokeService(ref context, _OrthancPluginService._OrthancPluginService_StorageAreaRead, ptr));
            }
            catch (Exception ex)
            {
                Log.Message(ex.ToString());
                OrthancPluginLogError(ref context, ex.ToString());
                return(OrthancPluginErrorCode.OrthancPluginErrorCode_InternalError);
            }
            finally
            {
                Marshal.FreeHGlobal(ptr);
            }
        }
        /// <summary>
        /// Remove a file from the storage area.
        /// This function removes a given file from the storage area that is currently used by Orthanc.
        /// </summary>
        /// <param name="context">OrthancPluginContext* - The Orthanc plugin context, as received by OrthancPluginInitialize().</param>
        /// <param name="storageArea">OrthancPluginStorageArea* - The storage area.</param>
        /// <param name="uuid">const char* - The identifier of the file to be removed.</param>
        /// <param name="type">OrthancPluginContentType - The type of the file content.</param>
        /// <returns>0 if success, other value if error.</returns>
        public static OrthancPluginErrorCode OrthancPluginStorageAreaRemove(ref OrthancPluginContext context, IntPtr storageArea, IntPtr uuid, OrthancPluginContentType type)
        {
            IntPtr ptr = IntPtr.Zero;
            try
            {
                _OrthancPluginStorageAreaRemove pr = new _OrthancPluginStorageAreaRemove();
                pr.storageArea = storageArea;
                pr.uuid = uuid;
                pr.type = type;

                int size = Marshal.SizeOf(pr);
                ptr = Marshal.AllocHGlobal(size);
                Marshal.StructureToPtr(pr, ptr, true);

                return context.InvokeService(ref context, _OrthancPluginService._OrthancPluginService_StorageAreaRemove, ptr);
            }
            catch (Exception ex)
            {
                Log.Message(ex.ToString());
                OrthancPluginLogError(ref context, ex.ToString());
                return OrthancPluginErrorCode.OrthancPluginErrorCode_InternalError;
            }
            finally
            {
                Marshal.FreeHGlobal(ptr);
            }
        }