/// <summary>
        /// Returns the SyncIndexDTO from File or created new
        /// </summary>
        /// <returns></returns>
        private SyncIndexDTO GetIndexBuffer()
        {
            string filePath = GetIndexFilePath();

            if (!File.Exists(filePath))
            {
                //Create new and Serialize
                SyncIndexDTO dto = new SyncIndexDTO();
                _logger.Debug("Creating new sync index file: " + filePath);
                if (_serilizer.Serialize(filePath, dto))
                {
                    //Change File Access to hidding
                    HideFile(filePath);
                    _logger.Debug("Creating new index file succeed");
                }
                else
                {
                    _logger.Error("Creating file failed tough to serialization failure");
                }
                return(dto);
            }
            else
            {
                _logger.Debug("Deserializing existing index file");
                SyncIndexDTO result = _serilizer.Deserialize(filePath);
                if (result == null)
                {
                    _logger.Error("Deserialization of the index File failed!");
                }
                return(result);
            }
        }
 /// <summary>
 /// Returns a deserialized DTO instance when file allready exists
 /// or creates empty File if not
 /// </summary>
 /// <returns>Index file content as SyncIndexDTO or null if something went wrong</returns>
 public IEnumerable <SyncIndexElementDTO> GetOrCreateIndexFile()
 {
     if (_indexBuffer == null)
     {
         _indexBuffer = GetIndexBuffer();
     }
     return(_indexBuffer?.elements);
 }
 public SyncIndexManager(ILogger logger, Configuration config)
 {
     _config        = config;
     _indexFileName = "syncindex";
     _logger        = logger;
     _serilizer     = new JsonSerializer <SyncIndexDTO>();
     _indexBuffer   = null;
 }
 /// <summary>
 /// Updates the SyncIndex file with the content of the
 /// given DTO
 /// </summary>
 /// <param name="dto"></param>
 /// <returns></returns>
 private bool UpdateFile(SyncIndexDTO dto)
 {
     return(_serilizer.Serialize(GetIndexFilePath(), dto));
 }