我已经安装了这个应用程序,但问题是这个应用程序不读取 config.ini 文件我得到了 config.ini 不存在的错误?确定我错了我不知道如何在安装项目中添加 config.ini 文件?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Timers;
using System.Net.NetworkInformation;
using System.IO;
namespace MovimentoServic
{
public partial class Service1 : ServiceBase
{
Dictionary<string, string> vpN = new Dictionary<string, string>();
cancelaments cancel = new cancelaments();
vendas vendas = new vendas();
Vendaecf ecf = new Vendaecf();
Sangrias sangria = new Sangrias();
Devolucao devolucao = new Devolucao();
CancelamentECF cancelecf = new CancelamentECF();
EnviarItemparalojas enivar = new EnviarItemparalojas();
RecheckVendas recheck = new RecheckVendas();
String vpn = null;
String host = null;
string user = null;
string pass = null;
string mysql_db = null;
string vpn_db = null;
String permissao = null;
int count = 0;
public void conect()
{
if ( System.IO.File.Exists("config.ini") )
{
String[] INI = System.IO.File.ReadAllLines("config.ini");
for ( int i = 0; i < INI.Length; i++ )
{
if ( INI[i].StartsWith("HOST") )
{
host = INI[i].Substring(INI[i].IndexOf("=") + 1);
}
if ( INI[i].StartsWith("USER") )
{
user = INI[i].Substring(INI[i].IndexOf("=") + 1);
}
if ( INI[i].StartsWith("PASS") )
{
pass = INI[i].Substring(INI[i].IndexOf("=") + 1);
}
if ( INI[i].StartsWith("DBPATH") )
{
mysql_db = INI[i].Substring(INI[i].IndexOf("=") + 1);
}
if ( INI[i].StartsWith("VPN") )
{
vpn = (INI[i].Substring(INI[i].IndexOf("=") + 1));
Char[] cs = { ';' };
String[] VPN = vpn.Split(cs);
vpN.Add(VPN[0], VPN[1]);
}
if ( INI[i].StartsWith("DBPATH_VPN") )
{
vpn_db = (INI[i].Substring(INI[i].IndexOf("=") + 1));
}
if ( INI[i].StartsWith("Permissao") )
{
permissao = (INI[i].Substring(INI[i].IndexOf("=") + 1));
}
}
}
}
public static bool IsAlive( string aIP, String shop )
{
bool result = false;
Ping pingSender = new Ping();
PingOptions options = new PingOptions();
options.DontFragment = true;
string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
byte[] buffer = Encoding.ASCII.GetBytes(data);
int timeout = 10;
PingReply reply = pingSender.Send(aIP, timeout, buffer, options);
if ( reply.Status == IPStatus.Success )
{
result = true;
}
return result;
}
long Validtime = 50;
int tk = 0;
private void timer1_Elapsed( object sender, EventArgs e )
{
tk++;
if ( tk == Validtime )
{
// Workout();
tk = 0;
}
}
public Service1()
{
InitializeComponent();
}
protected override void OnStart( string[] args )
{
conect();
Timer timer1 = new Timer();
timer1.Interval = 100;
timer1.Start();
timer1.Elapsed += new ElapsedEventHandler(timer1_Elapsed);
}
protected override void OnStop()
{
}
}
}