E_ElecCompetition/Electrical_inspectionCompet.../Assets/Adam/Net/KepUrlBuild.cs

99 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Text;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//============================================================
//支持中文文件使用UTF-8编码
//@author Zhaozibo
//@create 20230213
//@company WT
//
//@description:
//============================================================
public class KepUrlBuild
{
private string _baseUrl;
private StringBuilder _strBuild;
private KepUrlBuildType _urlType;
// public KepUrlBuild(KepUrlBuildType urlType)
// {
// _baseUrl = "http://127.0.0.1:39320/iotgateway/";
// _urlType = urlType;
// _strBuild = new StringBuilder(_baseUrl);
// SetType();
// }
public KepUrlBuild(string baseUrl, KepUrlBuildType urlType)
{
this._baseUrl = baseUrl;
_urlType = urlType;
_strBuild = new StringBuilder(_baseUrl);
SetType();
}
private void SetType()
{
void SetBrowse()
{
_strBuild.Append("browse");
}
void SetRead()
{
_strBuild.Append("read?ids=");
}
void SetWrite()
{
_strBuild.Append("write?ids=");
}
switch (_urlType)
{
case KepUrlBuildType.browse:
SetBrowse();
break;
case KepUrlBuildType.read:
SetRead();
break;
case KepUrlBuildType.write:
SetWrite();
break;
}
}
public KepUrlBuild SetTags(params string[] parameters)
{
// if (_urlType == KepUrlBuildType.browse)
// {
// return _strBuild.ToString();
// }
for (int i = 0; i < parameters.Length; i++)
{
_strBuild.Append($"{parameters[i]}{(i < parameters.Length - 1 ? "&" : "")}");
}
return this;
}
public string Build()
{
return _strBuild.ToString();
}
/// <summary>
/// 网页构造类型
/// </summary>
public enum KepUrlBuildType
{
browse,
read,
write
}
}