using System;
using System.Web;
using Telerik.Windows.Controls;
using System.Collections.Generic;

namespace SLApp1.Web
{
	public class MyUploadHandler : Telerik.Windows.RadUploadHandler
	{
		private string newFileName = string.Empty;

		public override Dictionary<string, object> GetAssociatedData()
		{
			Dictionary<string, object> dict = base.GetAssociatedData();
			if (!string.IsNullOrEmpty(newFileName))
			{
				dict.Add("NewFileName", this.newFileName);
			}
			return dict;
		}

		public override string GetFilePath(string fileName)
		{
			fileName = base.GetFilePath(this.GetFileName(fileName));
			return fileName;
		}

		private string GetFileName(string fileName)
		{
			if (this.IsNewFileRequest())
			{
				this.ResultChunkTag = string.Format(" [{0:yyyymmdd_hhmmss}]", DateTime.Now);
			}

			else if (this.FormChunkTag != null)
			{
				this.ResultChunkTag = this.FormChunkTag;
			}

			if (this.ResultChunkTag != null)
			{
				int i = fileName.LastIndexOf('.');
				if (i >= 0)
				{
					fileName = fileName.Insert(i, this.ResultChunkTag);
				}
			}
			return this.newFileName = fileName;
		}
	}
}
