Exemplo n.º 1
0
        //check to make sure no conflicting upload options are set
        public static bool checkMutualExclusionUpload(UploadOptions UploadClassObj)
        {
            //commandline didn't have a good way to define a **required** set of argumants that were mutually exclusive. This function is called
            //when parsing to validate that commands were set correctly

            int sum = 0;

            if (!String.IsNullOrEmpty(UploadClassObj.UploadFile))
            {
                sum++;
            }
            if (!String.IsNullOrEmpty(UploadClassObj.UploadIndicatorFile))
            {
                sum++;
            }
            if (!String.IsNullOrEmpty(UploadClassObj.UploadJson))
            {
                sum++;
            }

            if (sum == 0)
            {
                Console.Error.WriteLine("*** ERROR verb command 'upload' requires one of the parametors [file, json, indicatorfile]");
                System.Environment.Exit(-1);
            }
            if (sum > 1)
            {
                Console.Error.WriteLine("*** ERROR Too many parametors passed to verb command 'upload'. Only one parametor in [file, json, indicatorfile] can be given.");
                System.Environment.Exit(-1);
            }
            return(true);
        }
Exemplo n.º 2
0
        static int ParseUploadOptions(UploadOptions opts)
        {
            checkMutualExclusionUpload(opts);

            //If else tree for flag processing
            //if uploading a generic file
            if (!String.IsNullOrEmpty(opts.UploadFile))
            {
                try
                {
                    int responseCode = interflow.interflow.UploadInterflowGenericFile(opts.apikey, opts.UploadFile);
                    if (responseCode == 202)
                    {
                        Console.WriteLine("File upload sucessful.");
                    }
                    else if (responseCode == 204)
                    {
                        Console.Error.WriteLine("*** ERROR No Content: The request does not contain any file.");                           //this should never be a return code the user encounters.
                    }
                    else if (responseCode == 409)
                    {
                        Console.Error.WriteLine("*** ERROR Conflict: File already exists.");
                    }
                    else if (responseCode == 415)
                    {
                        Console.Error.WriteLine("*** ERROR Unsupported media type.");
                    }
                    else if (responseCode == 500)
                    {
                        Console.Error.WriteLine("*** ERROR Internal server error");
                    }
                    else
                    {
                        Console.Error.WriteLine("*** ERROR File upload failed with status code " + responseCode);
                    }
                }
                catch
                {
                    Console.Error.WriteLine("*** ERROR could not upload file. Please check the file path!");
                }
            }
            //if uploading a json oneIdicator file
            if (!String.IsNullOrEmpty(opts.UploadIndicatorFile))
            {
                try
                {
                    int responseCode = interflow.interflow.UploadInterflowOneIndicator(opts.apikey, File.ReadAllText(opts.UploadIndicatorFile));
                    if (responseCode == 201)
                    {
                        Console.WriteLine("File upload sucessful.");
                    }
                    else if (responseCode == 400)
                    {
                        Console.Error.WriteLine("*** ERROR No data.");
                    }
                    else if (responseCode == 500)
                    {
                        Console.Error.WriteLine("*** ERROR Internal server error");
                    }
                    else
                    {
                        Console.Error.WriteLine("*** ERROR File upload failed with status code " + responseCode);
                    }
                }
                catch
                {
                    Console.Error.WriteLine("*** ERROR could not upload file. Please check the file path!");
                }
            }
            //if uploading a json string oneIndicator deffinition
            if (!String.IsNullOrEmpty(opts.UploadJson))
            {
                int responseCode = interflow.interflow.UploadInterflowOneIndicator(opts.apikey, opts.UploadJson.Replace("\\", ""));

                if (responseCode == 201)
                {
                    Console.WriteLine("Indicator upload sucessful.");
                }
                else if (responseCode == 400)
                {
                    Console.Error.WriteLine("One or more indicators is not valid.");
                }
                else if (responseCode == 409)
                {
                    Console.Error.WriteLine("One or more indicators was not received or accepted by the hub.");
                }
                else
                {
                    Console.Error.WriteLine("*** ERROR Indicator upload failed with status code " + responseCode);
                }
            }

            return(0);
        }