Beispiel #1
0
		public FtpSmilFixer(string host, NetworkCredential credential)
		{
			_host = host;
			_credential = credential;
			Console.Write("Connecting to: " + host + "...");
			_ftpClient = new FtpsClientWrapper();
			_ftpClient.Connect(host, credential, ESSLSupportMode.ClearText);
			Console.WriteLine(" succesfully connected");
		}
Beispiel #2
0
        public void FtpTest()
        {
            var ftpClient = new FtpsClientWrapper();
            ftpClient.Connect("", new NetworkCredential("", ""),
                              ESSLSupportMode.ClearText);
            //var lst = ftpClient.GetDirectoryNames("/187855/dev/v3/smil");
            var lst = ftpClient.GetFileNames("/187855/dev/v3/smil/AG1245678900",".smil");

            var fs = ftpClient._client.GetFile(lst.FirstOrDefault());
            var xmlDocument = new XmlDocument{XmlResolver = null};
            var ss = new StreamReader(fs).ReadToEnd();
            xmlDocument.LoadXml(ss);
            var videos = xmlDocument.DocumentElement.ChildNodes.Cast<XmlNode>()
                .FirstOrDefault(x => x.Name == "body").ChildNodes.Cast<XmlNode>()
                .FirstOrDefault(x=> x.Name == "switch").ChildNodes.Cast<XmlNode>().Select(x=> x as XmlElement);
        }
Beispiel #3
0
		public async Task<bool> FixTheSmilFileAsync(string remotePath, string remoteSmilPath)
		{
			var xmlDocument = new XmlDocument { XmlResolver = null };
			var ftpCl = new FtpsClientWrapper();
			Console.WriteLine("Fixing smil {0}", remoteSmilPath);
			ftpCl.Connect(_host, _credential, ESSLSupportMode.ClearText);
			var noSmilFiles = ftpCl.GetFileNames(remotePath, "").Where(x => !x.Contains(".smil"));

			using (var fs = ftpCl._client.GetFile(remoteSmilPath))
			{
				using (var sr = new StreamReader(fs))
				{
					xmlDocument.LoadXml(sr.ReadToEnd());
					var vids = xmlDocument.DocumentElement.ChildNodes.Cast<XmlNode>()
										  .FirstOrDefault(x => x.Name == "body").ChildNodes.Cast<XmlNode>()
										  .FirstOrDefault(x => x.Name == "switch")
										  .ChildNodes.Cast<XmlNode>()
										  .Select(x => x as XmlElement);
					foreach (var xmlElement in vids)
					{
						var isrc = remotePath.Split('/').Last().ToLower();
						var bit = (int.Parse(xmlElement.GetAttribute("system-bitrate")) / 1000) + "k";
						var newfileName = noSmilFiles.FirstOrDefault(x => x.Contains(isrc + "_" + bit)).Split('/').Last();
						var previousValue = xmlElement.GetAttribute("src").Split('/').Last();
						if (newfileName != previousValue)
						{
							xmlElement.SetAttribute("src", xmlElement.GetAttribute("src").Replace(previousValue, newfileName));
						}
					}
					
				}
			}

			var lclFileName = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\smils\\" +
									  remoteSmilPath.Split('/').Last();
			xmlDocument.Save(lclFileName);

			await Task.Run(() =>
				{
					ftpCl._client.PutFile(lclFileName, remoteSmilPath);
					Console.WriteLine("Fixed {0}", remoteSmilPath);
				});
			return true;
		}