Ejemplo n.º 1
0
        /// <summary>
        /// Downloads the specified file to a given folder.
        /// </summary>
        /// <param name="file">The file on the bisque server.</param>
        /// <param name="destinationFolder">The folder to download it to.</param>
        /// <returns> The path to the file downloaded.</returns>
        public string DownloadFile(BisqueImageResource file, string destinationFolder)
        {
            var request = new RestRequest("image_service/" + file.Id, Method.GET);
            var response = client.Execute(request);
            RestSharpHelpers.CheckResponse(response);
            var content = response.Content; // raw content as string

            byte[] fileData = response.RawBytes;
            string fileName = destinationFolder.TrimEnd('\\') + "\\" + file.ImageName;

            using (var fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write))
            {
                try
                {
                    fileStream.Write(fileData, 0, fileData.Length);
                    fileStream.Close();
                }
                catch (Exception e)
                {
                    Debug.WriteLine("Download failed : " + e);
                }
            }

            return fileName;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets the bisque metadata / tags of a file.
        /// </summary>
        /// <param name="client">The client used for the request.</param>
        /// <param name="file">The image file.</param>
        /// <param name="metaDataXml">The meta data XML.</param>
        /// <returns>The respones of the request.</returns>
        internal static IRestResponse SetMetaData(RestClient client, BisqueImageResource file, string metaDataXml)
        {
            var request = new RestRequest(DataServicePrefix + file.Id, Method.PUT);
            request.AddHeader(ContentType, MediaTypeNames.Text.Xml);
            request.AddParameter(MediaTypeNames.Text.Xml, metaDataXml, ParameterType.RequestBody);

            var response = client.Execute(request);
            RestSharpHelpers.CheckResponse(response);
            var content = response.Content; // raw content as string

            RestSharpHelpers.CheckResponse(response);
            return response;
        }
Ejemplo n.º 3
0
 public BisqueImage(BisqueImageResource imageResource, BisqueSession session)
 {
     this.resource = imageResource;
     this.usedSession = session;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Extract the imageses from a given XML reply from the bisuqe server.
        /// </summary>
        /// <param name="xml">The XML string.</param>
        /// <returns>The images.</returns>
        internal static IEnumerable<BisqueImageResource> ImagesFromXml(string xml)
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(xml);

            string xpath = "resource/image";
            var nodes = xmlDoc.SelectNodes(xpath);

            foreach (XmlNode node in nodes)
            {
                var name = node.Attributes["name"];
                var uri = node.Attributes["uri"];
                var id = node.Attributes["resource_uniq"];

                if (name == null || uri == null || id == null)
                {
                    continue;
                }

                var image = new BisqueImageResource
                {
                    ImageName = name.Value,
                    URI = uri.Value,
                    Id = id.Value,
                };

                yield return image;
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Gets the metadata that is embedded in the file and could be extracted by bisque (bioformats).
 /// </summary>
 /// <param name="file">The file.</param>
 /// <returns>The Metadata as an xml string. </returns>
 public string GetEmbeddedMetaData(BisqueImageResource file)
 {
     var response = ImageServiceHelper.QueryWithParameter(this.client, file.Id, ImageServiceParameters.MetaData);
     return response.Content;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Get all tags that are currently on the file and add it to the xml document.
 /// </summary>
 /// <param name="file">The file.</param>
 /// <param name="xmlDoc">The XML document.</param>
 private void AddExitingTagsToXml(BisqueImageResource file, XmlDocument xmlDoc)
 {
     var metaData = this.GetMetaData(file);
     var tags = BisqueXmlHelper.TagsFromXml(metaData);
     BisqueXmlHelper.WriteTagsToXml(xmlDoc, tags);
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets an XML document containing the current tags of an image. 
        /// This XML document can be used for tag manupulation.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <returns>The xml document.</returns>
        public XmlDocument GetXmlDocumentForTagManupulation(BisqueImageResource file)
        {
            var xml = this.GetImageStandardData(file);
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(xml);

            // Add allready exitiong Tags
            AddExitingTagsToXml(file, xmlDoc);

            return xmlDoc;
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Gets the bisque - metadata / tags that belonge to the file.
 /// </summary>
 /// <param name="file">The file.</param>
 /// <returns>The Metadata as an xml string. </returns>
 public string GetMetaData(BisqueImageResource file)
 {
     var request = new RestRequest("data_service/" + file.Id +"/tag", Method.GET);
     var response = client.Execute(request);
     RestSharpHelpers.CheckResponse(response);
     return response.Content;
 }
Ejemplo n.º 9
0
 public string GetFileInfo(BisqueImageResource file)
 {
     var response = ImageServiceHelper.QueryWithParameter(this.client, file.Id, ImageServiceParameters.Info);
     return response.Content;
 }