| | 1 | | using System.Web; |
| | 2 | |
|
| | 3 | | namespace ReportingServices.Shared.HelperClasses |
| | 4 | | { |
| | 5 | | public static class APIHelperFunctions |
| | 6 | | { |
| 0 | 7 | | private readonly static string fabTimeServer = "http://messa004.infineon.com/fabtime717service/GetChartData.aspx |
| | 8 | |
|
| | 9 | | public static string GetBeginningOfWeekAsAPIString() |
| 1 | 10 | | { |
| 1 | 11 | | DateTime date = DateTime.Now; |
| | 12 | |
|
| 1 | 13 | | int dayOfWeek = (int)date.DayOfWeek; |
| | 14 | |
|
| 1 | 15 | | date = dayOfWeek switch |
| 1 | 16 | | { |
| 0 | 17 | | 0 => date.AddDays(-6), |
| 0 | 18 | | 1 => date, |
| 1 | 19 | | _ => date.AddDays(1 - dayOfWeek) |
| 1 | 20 | | }; |
| | 21 | |
|
| 1 | 22 | | return GetDateTimeAsAPIString(date.ToString(), false); |
| 1 | 23 | | } |
| | 24 | |
|
| | 25 | | public static string GetDateWithOffsetAsAPIString(string dateString, float offset) |
| 1 | 26 | | { |
| 1 | 27 | | DateTime date = DateTime.Parse(dateString); |
| | 28 | |
|
| 1 | 29 | | date = date.AddHours(offset); |
| | 30 | |
|
| 1 | 31 | | return GetDateTimeAsAPIString(date.ToString(), true); |
| 1 | 32 | | } |
| | 33 | |
|
| | 34 | | public static string GetDateTimeAsAPIString(string dateString, bool fullDateTime) |
| 4 | 35 | | { |
| 4 | 36 | | DateTime date = DateTime.Parse(dateString); |
| | 37 | |
|
| 4 | 38 | | if (fullDateTime) |
| 2 | 39 | | dateString = date.ToString("yyyy-M-d HH:mm:ss"); |
| | 40 | | else |
| 2 | 41 | | dateString = date.Year + "-" + date.Month + "-" + date.Day + " 0:0:0"; |
| | 42 | |
|
| 4 | 43 | | return dateString; |
| 4 | 44 | | } |
| | 45 | |
|
| | 46 | | public static Dictionary<string, string> SetParameters(string startDate = "", string endDate = "", string chart |
| | 47 | | string areasLike = "", string toolsLike = "", string operationsLike = "", string capacityTypesLike = "") |
| 0 | 48 | | { |
| 0 | 49 | | Dictionary<string, string> parameters = new(); |
| | 50 | |
|
| 0 | 51 | | startDate = startDate == "" ? HttpUtility.UrlEncode(GetBeginningOfWeekAsAPIString()) : startDate; |
| 0 | 52 | | endDate = endDate == "" ? HttpUtility.UrlEncode(GetDateTimeAsAPIString(DateTime.Now.ToString(), true)) : end |
| | 53 | |
|
| 0 | 54 | | parameters.Add("chart", chart); |
| 0 | 55 | | parameters.Add("starttime", startDate); |
| 0 | 56 | | parameters.Add("endtime", endDate); |
| 0 | 57 | | parameters.Add("periodlen", periodLen); |
| 0 | 58 | | parameters.Add("areaslike", areasLike); |
| 0 | 59 | | parameters.Add("toolslike", toolsLike); |
| 0 | 60 | | parameters.Add("operationslike", operationsLike); |
| 0 | 61 | | parameters.Add("capacitytypeslike", capacityTypesLike); |
| 0 | 62 | | parameters.Add("login", "administrator"); |
| 0 | 63 | | parameters.Add("password", "admin"); |
| 0 | 64 | | parameters.Add("fabtimeauthentication", "1"); |
| | 65 | |
|
| 0 | 66 | | return parameters; |
| 0 | 67 | | } |
| | 68 | |
|
| | 69 | | public static string GenerateURL(Dictionary<string, string> parameters) |
| 0 | 70 | | { |
| 0 | 71 | | int count = 0; |
| 0 | 72 | | string url = fabTimeServer; |
| | 73 | |
|
| 0 | 74 | | foreach (KeyValuePair<string, string> pair in parameters) |
| 0 | 75 | | { |
| 0 | 76 | | if (pair.Value != "") |
| 0 | 77 | | url = url + pair.Key + "=" + pair.Value; |
| | 78 | |
|
| 0 | 79 | | if (count != parameters.Count - 1 && !string.IsNullOrEmpty(pair.Value)) |
| 0 | 80 | | url += "&"; |
| | 81 | |
|
| 0 | 82 | | count++; |
| 0 | 83 | | } |
| | 84 | |
|
| 0 | 85 | | return url; |
| 0 | 86 | | } |
| | 87 | |
|
| | 88 | | public static string GenerateURLWithParameters(string startDate = "", string endDate = "", string chart = "", st |
| | 89 | | string areasLike = "", string toolsLike = "", string operationsLike = "", string capacityTypesLike = "") |
| 0 | 90 | | { |
| 0 | 91 | | Dictionary<string, string> parameters = SetParameters(startDate, endDate, chart, |
| 0 | 92 | | periodLen, areasLike, toolsLike, operationsLike, capacityTypesLike); |
| | 93 | |
|
| 0 | 94 | | return GenerateURL(parameters); |
| 0 | 95 | | } |
| | 96 | |
|
| | 97 | | public static List<T> ReverseList<T>(List<T> inputList) |
| 0 | 98 | | { |
| 0 | 99 | | List<T> temp = new(); |
| | 100 | |
|
| 0 | 101 | | for (int i = inputList.Count - 1; i >= 0; i--) |
| 0 | 102 | | { |
| 0 | 103 | | temp.Add(inputList[i]); |
| 0 | 104 | | } |
| | 105 | |
|
| 0 | 106 | | return temp; |
| 0 | 107 | | } |
| | 108 | | } |
| | 109 | | } |