private void UploadFile(LocalFile localFile, SftpClient ftp, string path)
        {
            //Console.WriteLine($"Checking: {localFile.RelativeName}");
            //Console.Write($"(local) {localFile.LastWriteTime.ToLocalTime()}");

            var filePath = localFile.RelativeName.Replace(Path.DirectorySeparatorChar, DirectorySeparator);
            var fullPath = path + filePath;

            // Check if the file exists
            var fileExists = ftp.Exists(fullPath);

            if (!fileExists)
            {
                EnsureDirExists(ftp, fullPath);
            }

            if (fileExists)
            {
                var lastUpdate = ftp.GetLastWriteTimeUtc(fullPath);
                //Console.Write($"| {lastUpdate.ToLocalTime()} (online)\n");

                if (!localFile.IsNewer(lastUpdate))
                {
                    Console.WriteLine($"Not uploading because file {localFile.RelativeName} is already updated!");
                    return;
                }
            }

            using (var stream = File.OpenRead(localFile.FileName))
            {
                //Console.WriteLine($"Uploading: {localFile.RelativeName}");
                ftp.UploadFile(stream, fullPath, true);
                Console.WriteLine($"Uploaded: {localFile.RelativeName}");
            }
        }
Beispiel #2
0
        internal async Task SyncConfig(SftpClient client, GameConfig config, GameServerConfiguration currentConfig)
        {
            var wasUpdated = false;

            foreach (var file in config.ConfigFiles)
            {
                string fullPath     = GetFileFullPath(config, file);
                var    content      = string.Empty;
                var    lastWriteUTC = DateTime.MinValue;
                if (client.Exists(fullPath))
                {
                    content      = client.ReadAllText(fullPath);
                    lastWriteUTC = client.GetLastWriteTimeUtc(fullPath);
                }
                var dbFile = currentConfig.Files.FirstOrDefault(f => f.Path == file);
                if (dbFile == null)
                {
                    dbFile = new GameConfigurationFile()
                    {
                        Configuration = currentConfig,
                        Content       = content,
                        LastChangeUTC = lastWriteUTC,
                        Path          = file
                    };
                    currentConfig.Files.Add(dbFile);
                    _context.Add(dbFile);
                    wasUpdated = true;
                }
                else if (dbFile.Content != content)
                {
                    dbFile.Content       = content;
                    dbFile.LastChangeUTC = lastWriteUTC;
                    _context.Update(dbFile);
                    wasUpdated = true;
                }
            }

            if (wasUpdated)
            {
                await UpdateComputedProperties(currentConfig);

                _context.GameServerConfigurations.Update(currentConfig);
                await _context.SaveChangesAsync();
            }
            else if (currentConfig.Modset == null)
            {
                if (currentConfig.GameServer.Type == GameServerType.Arma3)
                {
                    await UpdateModset(currentConfig);

                    if (currentConfig.Modset != null)
                    {
                        _context.GameServerConfigurations.Update(currentConfig);
                        await _context.SaveChangesAsync();
                    }
                }
            }
        }
Beispiel #3
0
 public Task <DateTime> GetFileChangeTime(string filePath)
 {
     return(HandleCommonExceptions(() => {
         return _client.GetLastWriteTimeUtc(filePath);
     }));
 }
Beispiel #4
0
 public void GetLastWriteTimeUtcTest()
 {
     ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value
     SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value
     string path = string.Empty; // TODO: Initialize to an appropriate value
     DateTime expected = new DateTime(); // TODO: Initialize to an appropriate value
     DateTime actual;
     actual = target.GetLastWriteTimeUtc(path);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }