141 lines
		
	
	
		
			4.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			141 lines
		
	
	
		
			4.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| //180917    chi makefilepath,MakeFTPPath 입력
 | |
| //180705    chi GetHexStringNoSpace 다시 추가 ,UrlPathEncode 추가
 | |
| //              getDateValue 추가                
 | |
| //180625    chi GetHexStringNoSpace 삭제(이것은 util.cs로 이동)
 | |
| //180614    chi Map 명령추가
 | |
| 
 | |
| 
 | |
| using System;
 | |
| using System.Collections.Generic;
 | |
| using System.Linq;
 | |
| using System.Runtime.InteropServices;
 | |
| using System.Text;
 | |
| using System.Text.RegularExpressions;
 | |
| using System.Threading.Tasks;
 | |
| 
 | |
| namespace WebServer
 | |
| {
 | |
|     /// <summary>
 | |
|     /// generic method Extension
 | |
|     /// </summary>
 | |
|     public static class MethodExtensions
 | |
|     {
 | |
|         public static string MakeFilePath(this string value,params string[] param)
 | |
|         {
 | |
|             System.Text.StringBuilder sb = new System.Text.StringBuilder();
 | |
|             sb.Append(value.Replace("/", "\\"));
 | |
|             foreach (var item in param)
 | |
|             {
 | |
|                 if (sb.Length > 0 && sb.ToString().EndsWith("\\") == false) sb.Append("\\");
 | |
|                 sb.Append(item.Replace("/", "\\"));
 | |
|             }
 | |
|             var retval = sb.ToString().Replace("/", "\\").Replace("\\\\", "\\");
 | |
|             return retval.ToString();
 | |
|         }
 | |
| 
 | |
| 
 | |
|         public static string MakeFTPPath(this string value, params string[] param)
 | |
|         {
 | |
|             System.Text.StringBuilder sb = new System.Text.StringBuilder();
 | |
|             sb.Append(value.Replace("\\", "/")); 
 | |
|             foreach (var item in param)
 | |
|             {
 | |
|                 if (sb.Length > 0 && sb.ToString().EndsWith("/") == false) sb.Append("/");
 | |
|                 sb.Append(item.Replace("\\", "/"));
 | |
|             }
 | |
|             var retval = sb.ToString().Replace("//", "/");
 | |
|             return retval.ToString();
 | |
|         }
 | |
| 
 | |
| 
 | |
|         public static double map(this double x, int in_min, int in_max, int out_min, int out_max)
 | |
|         {
 | |
|             return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
 | |
|         }
 | |
| 
 | |
|         public static string Base64Encode(this string src)
 | |
|         {
 | |
|             string base64enc = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(src));
 | |
|             return base64enc;
 | |
|         }
 | |
|         public static string Base64Decode(this string src)
 | |
|         {
 | |
|             var base64dec = Convert.FromBase64String(src);
 | |
|             return System.Text.Encoding.UTF8.GetString(base64dec);
 | |
|         }
 | |
|        
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 0101이 반복되는 문자열 형태로 전환합니다.
 | |
|         /// </summary>
 | |
|         /// <param name="arr"></param>
 | |
|         /// <returns></returns>
 | |
|         public static string BitString(this System.Collections.BitArray arr)
 | |
|         {
 | |
|             System.Text.StringBuilder sb = new System.Text.StringBuilder();
 | |
|             for (int i = arr.Length; i > 0; i--)
 | |
|                 sb.Append(arr[i - 1] ? "1" : "0");
 | |
|             return sb.ToString();
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// int 값으로 변환합니다.
 | |
|         /// </summary>
 | |
|         /// <param name="arr"></param>
 | |
|         /// <returns></returns>
 | |
|         public static int ValueI(this System.Collections.BitArray arr)
 | |
|         {
 | |
|             byte[] buf = new byte[4];
 | |
|             arr.CopyTo(buf, 0);
 | |
|             return BitConverter.ToInt32(buf, 0);
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 숫자인지 검사합니다.
 | |
|         /// </summary>
 | |
|         /// <param name="input"></param>
 | |
|         /// <returns></returns>
 | |
|         public static bool IsNumeric(this string input)
 | |
|         {
 | |
|             double data;
 | |
|             return double.TryParse(input, out data);
 | |
|             //return Regex.IsMatch(input, @"^\d+$");
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// isnullorempty 를 수행합니다.
 | |
|         /// </summary>
 | |
|         /// <param name="input"></param>
 | |
|         /// <returns></returns>
 | |
|         public static Boolean isEmpty(this string input)
 | |
|         {
 | |
|             return string.IsNullOrEmpty(input);
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// default 인코딩을 사용하여 문자열로 반환합니다.
 | |
|         /// </summary>
 | |
|         /// <param name="input"></param>
 | |
|         /// <returns></returns>
 | |
|         public static string GetString(this Byte[] input)
 | |
|         {
 | |
|             return System.Text.Encoding.Default.GetString(input);
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 16진수 문자열 형태로 반환합니다.
 | |
|         /// </summary>
 | |
|         /// <param name="input"></param>
 | |
|         /// <returns></returns>
 | |
|         public static string GetHexString(this Byte[] input)
 | |
|         {
 | |
|             System.Text.StringBuilder sb = new System.Text.StringBuilder();
 | |
|             foreach (byte b in input)
 | |
|                 sb.Append(" " + b.ToString("X2"));
 | |
|             return sb.ToString();
 | |
|         }
 | |
|     }
 | |
| 
 | |
| 
 | |
| }
 | 
