Hello,
I am completely new to c# and need to convert below code fo php to c#.Any help will be much appreciated .
define('LOGIN_URL', 'http://signin.ebay.com/aw-cgi/eBayISAPI.dll');
define('FILE_EXCHANGE_URL', 'http://bulksell.ebay.com/ws/eBayISAPI.dll');
define('DOWNLOAD_URL', 'http://k2b-bulk.ebay.com/ws/eBayISAPI.dll');
class eFileExchange {
var $emailAddr=null;
var $cookiePath ="YOUR COOKIES PATH";
var $rawxml=null;
var $records=array();
var $Logging = false;
var $Debug = false;
var $retries=0;
function eFileExchange($emailAddress, $ebayUser, $ebayPass) {
$this->emailAddr=$emailAddress;
$return=$this->eBayPost(LOGIN_URL."?SignIn");
$POSTFIELDS = 'MfcISAPICommand=SignInWelcome&siteid=0&co_partnerId=2&UsingSSL=0&ru=&pp=&pa1=&pa2=&pa3=&i1=-1&pageType=-1&userid='. $ebayUser .'&pass='. $ebayPass;
$reffer = FILE_EXCHANGE_URL."?FileExchangeUploadForm";
$return=$this->eBayPost(LOGIN_URL, $reffer, null, $POSTFIELDS);
}
function DownloadFile($url) {
$this->records=explode(chr(13), $this->records[0]);
$url=str_replace ("&", "&", $url);
$handle=fopen("EbayReport.tmp", "w+");
fwrite($handle, $this->eBayPost($url));
rewind($handle);
$row=0;
while (($this->records[] = fgetcsv($handle, 200000, ",")) !== FALSE) {
if ($row==0) { $this->records = array(); }
$row++;
}
fclose($handle);
return $this->records;
}
function ViewDownloads() {
$this->rawxml= $this->eBayPost(DOWNLOAD_URL."?SMDownloadPickup&ssPageName=STRK:ME:LNLK");
$this->rawxml=substr($this->rawxml, strpos(strtolower($this->rawxml), ">90 days<"), 3000000);
$this->rawxml=substr($this->rawxml, strpos(strtolower($this->rawxml), "<table")+1, 3000000);
$this->rawxml=substr($this->rawxml, strpos(strtolower($this->rawxml), "<table")-1, 3000000);
$this->rawxml=substr($this->rawxml, 1, strpos(strtolower($this->rawxml), "</table>")+8 );
$this->rawxml=str_replace('">Download', '', str_replace('"."[[:space:]]+"."<", "><", $this->rawxml);
//get rid of superfluous line terminators
$this->rawxml=str_replace ("\n", " ", $this->rawxml);
$this->rawxml=str_replace ("\r\n", " ", $this->rawxml);
//trim anything hanging on the beginning or end
$this->rawxml=addslashes(trim($this->rawxml));
$rarr=array();
//removes all tags and leaves data in array elements
$rarr=preg_split('/<[^>]+>/ix',$this->rawxml, -1, PREG_SPLIT_NO_EMPTY );
//Interpretation
if (isset($rarr[0])) {
$this->records=$rarr;
} else {
$this->records[0]='Amazon returned XML tags with no data between them which may mean that there is nothing to return.';
}
if ($this->Debug) {
echo "
"; print_r($this->records); echo "
";
}
return;
}
function eBayPost($url, $Referrer=null, $Headers=null, $Data=null) {
/* added this as a dying curl wrapper for eBayPost1 */
$rc=$this->eBayPost1($url, $Referrer, $Headers, $Data);
if ($rc == 'FATAL ERROR: Curl failed.') {
echo $rc." RETRY 1
\n";
sleep(10);
$rc=$this->eBayPost1($url, $Referrer, $Headers, $Data);
if ($rc == 'FATAL ERROR: Curl failed.') {
echo $rc." RETRY 2
\n";
sleep(10);
$rc=$this->eBayPost1($url, $Referrer, $Headers, $Data);
}
}
return $rc;
}
function eBayPost1($url, $Referrer=null, $Headers=null, $Data=null) {
// $agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7";
// Use built-in curl libraries
if (function_exists("curl_init"))
{
if ($this->Debug) {
echo "
HTTP HEADERS
";
echo "
"; print_r($Headers); echo "
";
if (!is_null($Data)) {
echo "
INVENTORY DATA
";
echo "
"; echo $Data; echo "
";
}
}
// Set Locale
if ($this->Locale != US) {
$url = str_replace(US, $this->Locale, $url);
}
// Curl is available. If curl_init succeeds, then SSL is
// Available
if (!$ch = curl_init())
{
return false;
}
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookiePath);
curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookiePath);
if (!is_null($Headers))
{
curl_setopt($ch, CURLOPT_HTTPHEADER, $Headers);
}
if (!is_null($Data))
{
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $Data);
}
if (!is_null($Referrer))
{
if ($this->Locale != US) {
$url = str_replace(US, $this->Locale, $Referrer);
}
curl_setopt($ch, CURLOPT_REFERER, $Referrer);
}
if ($this->Logging)
{
// Record all headers in the file DEBUG_FILE
curl_setopt($ch, CURLOPT_VERBOSE, true);
$fh = fopen(LOGGING_FILE, 'a');
curl_setopt($ch, CURLOPT_STDERR, $fh);
}
if (!($data_out = curl_exec($ch)))
{
if ($this->Debug)
{
echo "
CURL SESSION
";
print_r(curl_getinfo($ch));
}
curl_close($ch);
if ($this->Logging)
{
$datestr = date("F j Y h:i:s A");
$errstr = "$datestr: Curl_exec failed - curl_error($ch)\n";
error_log($errstr, 3, ERROR_LOG);
}
return 'FATAL ERROR: Curl failed.';
}
else
{
$this->retries=0;
if ($this->Debug)
{
echo "
CURL SESSION
";
print_r(curl_getinfo($ch));
echo "
RAW OUTPUT
";
echo htmlspecialchars($data_out, ENT_QUOTES);
}
curl_close($ch);
return $data_out;
}
}
else
{
die('Curl not available.');
}
}
}