public IEnumerable <Label> GetLabels(Topic topic, ImageLabel image)
        {
            #region validation

            if (topic == null)
            {
                throw new ArgumentNullException(nameof(topic));
            }

            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }

            #endregion

            IEnumerable <Label> labels = FileSession.Execute((fileName, filePath) =>
            {
                if (!FileContainer.ExistsFile(fileName, filePath))
                {
                    return(new List <Label>());
                }

                using (Stream labelFileStream = FileContainer.GetFileStream(fileName, filePath))
                {
                    return(LabelStoreUtil.GetLabelsFromStream(labelFileStream));
                }
            }, image.GetLabelFileName(), GetLabelsPath(topic));

            image.SetLabels(labels);
            return(labels);
        }
        public IEnumerable <Label> GetLabels(Topic topic, ImageLabel imageLabel)
        {
            #region validation

            if (topic == null)
            {
                throw new ArgumentNullException(nameof(topic));
            }

            if (imageLabel == null)
            {
                throw new ArgumentNullException(nameof(imageLabel));
            }

            #endregion

            IEnumerable <Label> labels = FileSession.Execute((fileName, filePath) =>
            {
                if (!FileContainer.ExistsFile(fileName, filePath))
                {
                    return(new List <Label>());
                }

                using (StreamReader streamReader = EncodingUtil.GetStreamReader(FileContainer.GetFileStream(fileName, filePath), Encoding.UTF8))
                {
                    string labelContentJson = streamReader.ReadToEnd();
                    return(JsonConvert.DeserializeObject <IEnumerable <Label> >(labelContentJson));
                }
            }, GetLabelFileName(imageLabel.Url), GetLabelsPath(topic));

            imageLabel.SetLabels(labels);
            return(labels);
        }
예제 #3
0
        /// <summary>
        /// Save list of objectclasses in json-file.
        /// </summary>
        /// <param name="topic">Topic of objectclasses</param>
        /// <param name="objectClasses">List of objectclasses to save</param>
        private void SaveObjectClasses(Topic topic, IEnumerable <ObjectClass> objectClasses)
        {
            FileSession.Execute((fileName, filePath) =>
            {
                string objectclassesAsJson = JsonSerializer.Serialize(objectClasses);
                byte[] newFileContent      = EncodingUtil.GetBytes(objectclassesAsJson);
                FileContainer.CreateFile(fileName, newFileContent, filePath);

                return(true);
            }, "objectclasses.json", GetTopicPath(topic));
        }
예제 #4
0
        public IEnumerable <Topic> GetTopics()
        {
            return(FileSession.Execute((fileName, filePath) =>
            {
                using (StreamReader streamReader = EncodingUtil.GetStreamReader(FileContainer.GetFileStream(fileName, filePath)))
                {
                    string fileContent = streamReader.ReadToEnd();

                    return JsonConvert.DeserializeObject <IEnumerable <Topic> >(fileContent);
                }
            }, TOPICS_FILE_NAME));
        }
예제 #5
0
        /// <summary>
        /// Loads objectclasses from objectclasses.json-file.
        /// If file doesn't exsists, emtpy list will be returned.
        /// </summary>
        /// <param name="topic">Topic of objectclasses</param>
        /// <returns>List of objectclasses</returns>
        private IEnumerable <ObjectClass> LoadObjectClasses(Topic topic)
        {
            if (!FileContainer.ExistsFile("objectclasses.json", GetTopicPath(topic)))
            {
                return(new List <ObjectClass>());
            }

            return(FileSession.Execute((fileName, filePath) =>
            {
                using (StreamReader streamReader = EncodingUtil.GetStreamReader(FileContainer.GetFileStream(fileName, filePath)))
                {
                    string objectclassesContent = streamReader.ReadToEnd();
                    return JsonConvert.DeserializeObject <IEnumerable <ObjectClass> >(objectclassesContent);
                }
            }, "objectclasses.json", GetTopicPath(topic)));
        }
        public IEnumerable <Label> AddLabels(Topic topic, ImageLabel image, IEnumerable <Label> labels)
        {
            #region validation

            if (topic == null)
            {
                throw new ArgumentNullException(nameof(topic));
            }

            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }

            if (labels == null)
            {
                throw new ArgumentNullException(nameof(labels));
            }

            #endregion

            // set id for labels
            foreach (Label label in labels)
            {
                label.Id = labels.GetNext(o => o.Id) + 1;
            }

            FileSession.Execute((fileName, filePath) =>
            {
                image.Labels            = labels.ToList();
                byte[] labelFileContent = image.GetLabelsAsByte();
                FileContainer.CreateFile(fileName, labelFileContent, filePath);

                return(true);
            }, image.GetLabelFileName(), GetLabelsPath(topic));

            return(labels);
        }
        public IEnumerable <Label> CreateLabels(Topic topic, ImageLabel imageLabel)
        {
            #region validation

            if (topic == null)
            {
                throw new ArgumentNullException(nameof(topic));
            }

            if (imageLabel == null)
            {
                throw new ArgumentNullException(nameof(imageLabel));
            }

            #endregion

            // set id for undefined label-ids
            // undefined label id will be lower than 0
            foreach (Label label in imageLabel.Labels)
            {
                if (label.Id < 0)
                {
                    label.Id = imageLabel.Labels.GetNext(o => o.Id);
                }
            }

            FileSession.Execute((fileName, filePath) =>
            {
                string labelssAsJson  = JsonConvert.SerializeObject(imageLabel.Labels);
                byte[] newFileContent = EncodingUtil.GetBytes(labelssAsJson, Encoding.UTF8);
                FileContainer.CreateFile(fileName, newFileContent, filePath);

                return(true);
            }, GetLabelFileName(imageLabel.Url), GetLabelsPath(topic));

            return(imageLabel.Labels);
        }
예제 #8
0
        /// <summary>
        /// Loads objectclasses from objectclasses.json-file.
        /// If file doesn't exsists, emtpy list will be returned.
        /// </summary>
        /// <param name="topic">Topic of objectclasses</param>
        /// <returns>List of objectclasses</returns>
        private IEnumerable <ObjectClass> LoadObjectClasses(Topic topic)
        {
            if (!FileContainer.ExistsFile("objectclasses.json", GetTopicPath(topic)))
            {
                return(new List <ObjectClass>());
            }

            var objectClasses = FileSession.Execute((fileName, filePath) =>
            {
                using (StreamReader streamReader = EncodingUtil.GetStreamReader(FileContainer.GetFileStream(fileName, filePath)))
                {
                    string objectclassesContent = streamReader.ReadToEnd();
                    return(JsonSerializer.Deserialize <IEnumerable <ObjectClass> >(objectclassesContent));
                }
            }, "objectclasses.json", GetTopicPath(topic));

            // set topic reference id
            foreach (ObjectClass objectClass in objectClasses)
            {
                objectClass.TopicId = topic.Id;
            }

            return(objectClasses);
        }