Beispiel #1
0
        private static Dictionary <string, object> ModelToDictionary(SpeechModel model)
        {
            Dictionary <string, object> postParameters = new Dictionary <string, object>();

            foreach (var propertyInfo in model.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                var param    = propertyInfo.GetValue(model);
                var fileName = string.Empty;
                switch (propertyInfo.Name)
                {
                case "languagedata":
                case "transcriptions":
                    var textFile = (byte[])param;
                    fileName = propertyInfo.Name;
                    var textFileParameter = new FileParameter(textFile, fileName, "text/plain");
                    postParameters.Add(propertyInfo.Name, textFileParameter);
                    break;

                case "audiodata":
                    var zipFile = (byte[])param;
                    fileName = propertyInfo.Name;
                    var zipFileParameter = new FileParameter(zipFile, fileName, "application/x-zip-compressed");
                    postParameters.Add(propertyInfo.Name, zipFileParameter);
                    break;

                case "properties":
                    var jsonProperties = JsonConvert.SerializeObject(param);
                    postParameters.Add(propertyInfo.Name, jsonProperties);
                    break;

                default:     // it's just a string/string key value pair
                    postParameters.Add(propertyInfo.Name, param);
                    break;
                }
            }
            return(postParameters);
        }