package com.aspose.tasks.cloud.resources;

import java.nio.file.Path;

import com.aspose.storage.api.StorageApi;
import com.aspose.tasks.api.TasksApi;
import com.aspose.tasks.cloud.Configuration;
import com.aspose.tasks.cloud.Utils;
import com.aspose.tasks.cloud.working.RetrieveTaskInformationExample;
import com.aspose.tasks.model.ResourceItemResponse;

public class AddResourceToProjectExample {

	public static void main(String[] args) {
		//ExStart: AddResourceToProjectExample
		// Set input file name
		String name = "sample-project.mpp";
		String resourceName = "Resource6";
		int beforeResourceId = 1;
		String fileName = "";
		String storage = "";
		String folder = "";
		Path inputFile = Utils.getPath(RetrieveTaskInformationExample.class, name);

		try
		{
			StorageApi storageApi = new StorageApi(Configuration.apiKey, Configuration.appSID, true);
			// Instantiate Aspose Words API SDK
			TasksApi tasksApi = new TasksApi(Configuration.apiKey, Configuration.appSID, true);
		    // Upload source file to aspose cloud storage
		    storageApi.PutCreate(name, "", "", inputFile.toFile());

		    // Invoke Aspose.Tasks Cloud SDK API to add resource informations
		    ResourceItemResponse apiResponse = tasksApi.PostProjectResource(name, resourceName, beforeResourceId, fileName, storage, folder);

		    if (apiResponse != null)
		    {
		    	System.out.println("Add a Resource To Project, Done!");
		    }
		}
		catch (Exception ex)
		{
		    ex.printStackTrace();
		}
		//ExEnd: AddResourceToProjectExample
	}

}
