My Project
OSFileUpload.cpp
Go to the documentation of this file.
1
28//#include "OSResult.h"
29//#include "OSiLReader.h"
30//#include "OSiLWriter.h"
31//#include "OSrLReader.h"
32//#include "OSrLWriter.h"
33//#include "OSInstance.h"
34//#include "OSnLNode.h"
35
36#include "OSConfig.h"
37#include "OSParameters.h"
38#include "OSFileUtil.h"
39#include "OSErrorClass.h"
40#include "OSWSUtil.h"
41#include "OSSolverAgent.h"
42#include "CoinHelperFunctions.hpp"
43//
44
45#ifdef HAVE_CTIME
46# include <ctime>
47#else
48# ifdef HAVE_TIME_H
49# include <time.h>
50# else
51# error "don't have header file for time"
52# endif
53#endif
54
55
56#include <sstream>
57#include <vector>
58//#include <asl.h>
59
60int main(int argC, char* argV[])
61{
62 WindowsErrorPopupBlocker();
63 FileUtil *fileUtil = NULL;
64 const char dirsep = CoinFindDirSeparator();
65 std::string osilFileNameWithPath;
66 std::string osilFileName;
67 std::string osil;
68 std::string uploadResult;
69 std::string actualServer;
70
71 /* Replace this URL as needed */
72 std::string defaultServer = "http://128.135.130.17:8080/os/servlet/OSFileUpload";
73
74 try{
75 if( argC == 1 || argC > 3 || argV[1] == "-?")
76 throw ErrorClass( "usage: OSFileUpload <filename> [<serverURL>]");
77 fileUtil = new FileUtil();
78 time_t start, finish, tmp;
79 osilFileNameWithPath = argV[ 1];
80 std::cout << "FILE NAME = " << argV[1] << std::endl;
81 std::cout << "Read the file into a string" << std::endl;
82 osil = fileUtil->getFileAsString( osilFileNameWithPath.c_str() );
83 OSSolverAgent* osagent = NULL;
84 if (argC == 2)
85 actualServer = defaultServer;
86 else
87 actualServer = argV[2];
88 osagent = new OSSolverAgent(actualServer);
89
90 // strip off just the file name
91 // modify to into a file C:filename
92 int index = osilFileNameWithPath.find_last_of( dirsep);
93 int slength = osilFileNameWithPath.size();
94 osilFileName = osilFileNameWithPath.substr( index + 1, slength) ;
95 std::cout << std::endl << std::endl;
96 std::cout << "Place remote synchronous call" << std::endl;
97
98 start = time( &tmp);
99 uploadResult = osagent->fileUpload(osilFileName, osil);
100 finish = time( &tmp);
101 std::cout << "File Upload took (seconds): "<< difftime(finish, start) << std::endl;
102 std::cout << uploadResult << std::endl;
103
104 if(fileUtil != NULL) delete fileUtil;
105 return 0;
106 }
107 catch( const ErrorClass& eclass){
108 std::cout << eclass.errormsg << std::endl;
109 if(fileUtil != NULL) delete fileUtil;
110 return 0;
111 }
112}
113
int main(int argC, char *argV[])
used for throwing exceptions.
std::string errormsg
errormsg is the error that is causing the exception to be thrown
class used to make it easy to read and write files.
Definition OSFileUtil.h:38
std::string getFileAsString(const char *fname)
read a file and return contents as a string.
Used by a client to invoke a remote solver.
std::string fileUpload(std::string osilFileName, std::string osil)
implement the fileUpload() method which is a virtual function in OShL