RemoteDataCenterClientClass.php 2.19 KB
<?php
/**
 * @class RemoteDataCenterClientClass
 * @brief  
 * @details
 */
class RemoteDataCenterClientClass
{		
	public $baseDom = null, $dataCenter = null;  
	public $baseDomName;
	public $baseID = null;
   public $ViId = null, $ParamId = null, $defaultFillValue;
   protected $client;
	public $infoFile = null;
	
	/*
	 * @brief Constructor
	*/
	function __construct()
	{		
		$this->baseID = get_class($this);
		$this->baseDom = new DomDocument("1.0");
		$this->baseDomName = RemoteData.$this->baseID."/base.xml";
		
	//	if (!file_exists($this->baseDomName))
	//			return -1;
	//	if (!$this->baseDom->load($this->baseDomName))
	//			return -2;
		if (!@$this->baseDom->load($this->baseDomName))
				echo 'Cannot Load base.xml for '.$this->baseID.PHP_EOL;
		
		date_default_timezone_set('UTC');

		try {
				$this->client = new SoapClient(DD_WSDL);
		}
		catch  (SoapFault $exception) {
				$msg = $exception->faultstring.PHP_EOL;                           
				exit($msg);
		}
	
	//	return 0;
	}		
	
	public function param2dd($paramID) 
	{
		$pairs = array(" " => "_","-" => "_","/" => "_","%" => "_","\\" => "_","$" => "_",":" => "_","+" =>"_",
							"#" => "_","@" => "_","." => "_", ">" => "_", "<" => "_", "," => "_", ")" => "", "(" => "_"); 
							
		return strtr($paramID,$pairs); 
	}
	
	
	public function setViId($id)
	{
		$this->ViId = $id;
	}
	
	public function setParamId($id)
	{
		$this->ParamId = $id;
	}
	
	public function addViToDD()
	{
		if (!$this->ViId) return false;	
		
		$this->setInfoFile();
		//check if VI already added		
		try {
			$res = $this->client->isRemoteViAdded($this->baseID, strtolower($this->ViId));			
			if (!$res) 
			{
			// call to DD Server to create new VI			
				$command = 'AddVI '.$this->dataset2dd($this->ViId).' '.$this->ViId.' '.$this->baseID;  								
				system($command, $err);

				return ($err == 0);	
			}
		 
			return true;
		}
		catch  (SoapFault $exception) {	
// 		echo $this->client->__getLastRequest();
// 		echo $this->client->__getLastResponse();
				$msg = $exception->faultstring.PHP_EOL;				
				return false;
		}
	}
	
	
	protected function dataset2dd($id){}
	public function setInfoFile(){}
	public function getParamSize(){}
	public function getParamComponents(){}
}
?>