private static void parseVariablesAndDescriptions(ref string content,ModelMeta mm) { string searchText = "initialName\\(([0-9]+),[0-9]+\\)"; Match names = Regex.Match(content, searchText); // number of variables is in $1 var numberofnames = Int32.Parse(names.Groups[1].Value); //go through all string namesstr = content.Substring(names.Index); string[] namesarr = namesstr.Split(new char[]{'\r','\n'},numberofnames+2,StringSplitOptions.RemoveEmptyEntries); //+1 first row contains searchtext, +1 last row contains rest searchText = "initialValue\\("; names = Regex.Match(content, searchText); string valuesstr = content.Substring(names.Index); string[] valuesarr = valuesstr.Split(new char[] { '\r', '\n' }, (numberofnames*2)+2, StringSplitOptions.RemoveEmptyEntries); //each value is in 2 rows searchText = "initialDescription\\("; names = Regex.Match(content, searchText); string descrstr = content.Substring(names.Index); string[] descrarr = descrstr.Split(new char[] { '\n' }, numberofnames+2, StringSplitOptions.None); //there may be empty descriptions - each 2 row is empty because of \r\n //for i=0 the array contains also the searchtext row if (mm.VariableMetas==null) mm.VariableMetas = new Dictionary<string, List<string>>(); bool extraline = !(valuesarr[1].Contains('#')); //some of dsin contains extra line ending if some of the variable name is too long for (int i=1;i<=numberofnames;i++) { //VariableMeta vm = new VariableMeta(); List<string> vm = new List<string>();// VariableMeta(); //vm.InitialValue = Double.Parse(valuesarr[i*2-1].Substring(3,24)); // the value is on each 2nd row from 3rd character 24 chars if (extraline) vm.Add(valuesarr[i*2 - 1].Substring(3, 24).Trim()); else vm.Add(valuesarr[i].Substring(3,24).Trim()); //vm.Description=((descrarr[i].Length >0) && (descrarr[i][descrarr[i].Length-1]=='\r'))?descrarr[i].Substring(0,descrarr[i].Length-1):descrarr[i]; //removes ending \r if there is vm.Add(((descrarr[i].Length > 0) && (descrarr[i][descrarr[i].Length - 1] == '\r')) ? descrarr[i].Substring(0, descrarr[i].Length - 1) : descrarr[i]); //removes ending \r if there is //vm.Units = Regex.Match(descrarr[i], "\\[[^\\]]+\\]").Value; vm.Add(Regex.Match(descrarr[i], "\\[[^\\]]+\\]").Value); if (extraline) vm.Add(valuesarr[i * 2 - 1].Substring(0, 3).Trim()); //type else vm.Add(valuesarr[i].Substring(0,3).Trim()); mm.VariableMetas.Add(namesarr[i],vm); } }
public static void RegisterModelMeta(string path,string id) { ModelId = id; var request = new RestRequest(Method.POST) {Resource = MetaResource + ModelId, RequestFormat = DataFormat.Json}; var mm = new ModelMeta {ModelInstancePath = path}; DymosimFile.ParseMetaSimulationFile("dsin.txt",mm); request.AddBody(mm); //request.JsonSerializer.Serialize() //request.JsonSerializer.Serialize(mm); InitRestClient(); client.Execute(request); }
internal static void ParseMetaSimulationFile(string filename, ModelMeta mm) { var reader = new StreamReader(filename); string content = reader.ReadToEnd(); reader.Close(); parseVariablesAndDescriptions(ref content, mm); }