src/Classificationbox.Net/ServiceWrapper.cs
/// <summary>
/// Saves the current model to the specified file
/// </summary>
/// <param name="modelId">id of the model to save</param>
/// <param name="filename">filename where to save the model</param>
/// <returns>OK for success or error message</returns>
Saves the current model to the specified file
Saves the current model to the specified file
public string SaveModel(string modelId, string filename)
        {
            using (HttpClient client = new HttpClient())
            {
                var request = new HttpRequestMessage
                {
                    Method = HttpMethod.Get,
                    RequestUri = new Uri(string.Format("{0}/classificationbox/state/{1}", _baseUrl, modelId))
                };
                HttpResponseMessage rsp;
                try
                {
                    rsp = client.SendAsync(request).GetAwaiter().GetResult();
                }
                catch (Exception ex)
                {
                    return ex.Message;
                }
                if (rsp.IsSuccessStatusCode)
                {
                    if (File.Exists(filename)) File.Delete(filename);
                    using (Stream output = File.OpenWrite(filename))
                    using (Stream input = rsp.Content.ReadAsStreamAsync().Result)
                    {
                        input.CopyTo(output);
                    }
                    return "OK";
                }
                else
                {
                    var s = rsp.Content.ReadAsStringAsync().Result;
                    return s;
                }
            }
        }
public string SaveModel ( string modelId , string filename ) { using ( HttpClient client = new HttpClient ( ) ) { var request = new HttpRequestMessage { Method = HttpMethod . Get , RequestUri = new Uri ( string . Format ( " " , _baseUrl , modelId ) ) } ; HttpResponseMessage rsp ; try { rsp = client . SendAsync ( request ) . GetAwaiter ( ) . GetResult ( ) ; } catch ( Exception ex ) { return ex . Message ; } if ( rsp . IsSuccessStatusCode ) { if ( File . Exists ( filename ) ) File . Delete ( filename ) ; using ( Stream output = File . OpenWrite ( filename ) ) using ( Stream input = rsp . Content . ReadAsStreamAsync ( ) . Result ) { input . CopyTo ( output ) ; } return " " ; } else { var s = rsp . Content . ReadAsStringAsync ( ) . Result ; return s ; } } }
Saves the current model to the specified file
Saves the current model to the specified file
OK for success or error message
OK for success or error message
modelId
string
id of the model to save
id of the model to save
filename
string
filename where to save the model
filename where to save the model