Ejemplo n.º 1
0
 public static void CreatePath(String inPath)
 {
     try
     {
         string[] splPath = (inPath.TrimEnd('\\') + "\\").Split('\\');
         String   dirs    = splPath[0] + "\\" + splPath[1];
         for (int i = 2; i < splPath.Length; i++)
         {
             if (!System.IO.Directory.Exists(dirs))
             {
                 System.IO.Directory.CreateDirectory(dirs);
             }
             dirs += "\\" + splPath[i];
         }
     }
     catch (Exception ee)
     {
         var li = new LogItem
         {
             App        = "Apteka.Utils",
             Stacktrace = ee.GetStackTrace(25),
             Message    = ee.GetAllMessages(),
             Method     = "CFile.CreatePath",
             Params     = inPath
         };
         CLogJson.Write(li);
     }
 }
Ejemplo n.º 2
0
        public static string GetRemoteString(string from, string token = "")
        {
            using (var wc = new WebClient())
            {
                try
                {
                    if (token != "")
                    {
                        wc.Headers.Add("Authorization", $"bearer {token}");
                    }

                    return(wc.DownloadString(from));
                }
                catch (Exception ee)
                {
                    var li = new LogItem
                    {
                        App        = "Apteka.Utils",
                        Message    = ee.Message,
                        Stacktrace = ee.GetStackTrace(5),
                        Url        = $"{from}  {token}",
                        Method     = "CInet.GetRemoteString"
                    };
                    CLogJson.Write(li);
                    return("");
                }
            }
        }
Ejemplo n.º 3
0
        public static string LocalIpAddressAll()
        {
            string IP    = string.Empty;
            string allIp = "";

            try
            {
                IPHostEntry host = Dns.GetHostEntry(System.Environment.MachineName);

                foreach (IPAddress ip in host.AddressList)
                {
                    if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                    {
                        allIp += ip.ToStr() + "  ";
                    }
                }
            }
            catch (Exception ee)
            {
                var li = new LogItem
                {
                    App        = "Apteka.Utils",
                    Stacktrace = ee.GetStackTrace(5),
                    Message    = ee.GetAllMessages(),
                    Method     = "CNet.LocalIpAddressAll"
                };
                CLogJson.Write(li);
            }
            return(allIp);
        }
Ejemplo n.º 4
0
        public static async Task <bool> DownloadFileAsync(string from, string to)
        {
            using (var wc = new WebClient())
            {
                try
                {
                    if (File.Exists(to))
                    {
                        File.Delete(to);
                    }
                    await wc.DownloadFileTaskAsync(from, to);

                    return(true);
                }
                catch (Exception ee)
                {
                    var li = new LogItem
                    {
                        App        = "Apteka.Utils",
                        Message    = ee.Message,
                        Stacktrace = ee.GetStackTrace(5),
                        Url        = $"{from} => {to}",
                        Method     = "CInet.DownloadFileAsync"
                    };
                    CLogJson.Write(li);
                    return(false);
                }
            }
        }
Ejemplo n.º 5
0
        public static string LocalIpAddressAll(string ia)
        {
            string IP = string.Empty;

            try
            {
                string[] sa = ia.Split('.');
                ia = $"{sa[0]}.{sa[1]}.{sa[2]}.";
                IPHostEntry host = Dns.GetHostEntry(System.Environment.MachineName);
                foreach (IPAddress ip in host.AddressList)
                {
                    if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                    {
                        string ai = ip.ToStr();
                        if (ia == ai.Substring(0, ia.Length))
                        {
                            return(ai);
                        }
                    }
                }
            }
            catch (Exception ee)
            {
                var li = new LogItem
                {
                    App        = "Apteka.Utils",
                    Stacktrace = ee.GetStackTrace(5),
                    Message    = ee.GetAllMessages(),
                    Method     = "CNet.LocalIpAddressAll"
                };
                CLogJson.Write(li);
            }
            return("");
        }