package cdac.medinfo.sdk.dcm30_04.services.colorpalette.testcases.scu;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetSocketAddress;

import cdac.medinfo.sdk.dcm30_04.commoninterface.IDataSet;
import cdac.medinfo.sdk.dcm30_04.dicommodel.colorpalette.ColorPaletteIOD;
import cdac.medinfo.sdk.dcm30_04.enums.EnumLoggingLevel;
import cdac.medinfo.sdk.dcm30_04.services.colorpalette.scu.ColorPaletteSCU;
import cdac.medinfo.sdk.dcm30_04.services.dimsecommons.DicomMessage;
import cdac.medinfo.sdk.dcm30_04.utils.DicomConfig;
import cdac.medinfo.sdk.dcm30_04.utils.ISingleCollection;
import cdac.medinfo.sdk.dcm30_04.utils.SingleCollection;

public class ColorPalette_CStoreSCU_Standalone {
	/**
	 * The main method.
	 * @param args the arguments
	 * @throws IOException Signals if IO Exception occurs.
	 */
	public static void main(String[] args)
	{
		try
		{
			DicomConfig objDicomConfig = DicomConfig.createInstance();

			//enable logging,specify the path of the directory where log files are created.
			//User can specify any directory in place of 'c:\DCM_Logs'.]
			//If no directory is defined by user to create logs then it is created in User Temp DIR.
			objDicomConfig.enableLogging(EnumLoggingLevel.INFO, "C:\\DCM_Logs");	

			/*
			 * Creates CStore_SCU_Standalone.
			 */
			ColorPalette_CStoreSCU_Standalone objColorPalette_CStoreSCU_Standalone = new ColorPalette_CStoreSCU_Standalone();
			objColorPalette_CStoreSCU_Standalone.doColorPalette();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}

	private void doColorPalette() {

		try
		{
			String strFilePath = null;
			System.out.println("Enter the Color Palette Dicom File with complete path");
			BufferedReader b_reader =new BufferedReader( new InputStreamReader( System.in ) );
			strFilePath = b_reader.readLine();

			// Creates the object of corresponding IOD by calling its constructor which takes File Name as a parameter and give its DataSet.
	
			ColorPaletteIOD objColorPaletteIOD = new ColorPaletteIOD(strFilePath);
			IDataSet objIDataSet = objColorPaletteIOD.getDataSet();

			InetSocketAddress addr = new InetSocketAddress("192.168.8.94",9000);

			/* 
			 * Creates SCU with specified destination .
			 */
			ColorPaletteSCU objColorPaletteSCU = new ColorPaletteSCU(addr);

			/*
			 * Create Data Set collection.
			 */
			ISingleCollection<IDataSet> objIDataSetCollection = new SingleCollection<IDataSet>();

			/*
			 * sends the available datasets to the destination SCP for storage.
			 */
			objIDataSetCollection.add(objIDataSet);

			String strSOPClassUID=objIDataSet.getSOPClassUID();
			/*
			 * Send the C-Find DataSet with Affected SOP class UID of ORMS
			 */
			objColorPaletteSCU.send("SDK","SDK",strSOPClassUID,objIDataSetCollection);

			/*
			 * After the request is send user can get the response collection.
			 */

			ISingleCollection<DicomMessage> objSingleCollection = objColorPaletteSCU.getDIMSEResponse();
			System.out.println("Color Palette store operation response collection Size :: " + objSingleCollection.size());
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	
		
	}
}
