public static DescriptionFile ParseFile(string path) { var res = new DescriptionFile(); res.relativePath = path; using (FileStream headFileStream = new FileStream(path, FileMode.Open)) { if (!headFileStream.CanRead) { throw new UnityException("Not existed file!"); } var LineReader = new StreamReader(headFileStream); string line; List <string> volumeFile = new List <string>(); bool headOver = false; int lineNo = 0; while ((line = LineReader.ReadLine()) != null) { lineNo++; if (!headOver) { if (parseHeadline(res, line, lineNo)) { headOver = true; } } else { volumeFile.Add(line); } } res.volumeData = volumeFile.ToArray(); } return(res); }
protected override ThreadedReadTexture readTexture() { try { desc = DescriptionFile.ParseFile(_headFilePath); return(new AsyncReader(desc, this)); } catch (Exception e) { throw new UnityException(e.Message); } }
public override bool Execute() { if (null == DescriptionFile) { Log.LogError("DescriptionFile argument must be specified"); return(false); } if (String.IsNullOrEmpty(PackageId)) { Log.LogError("PackageId argument must be specified"); return(false); } string descriptionPath = DescriptionFile.GetMetadata("FullPath"); if (!File.Exists(descriptionPath)) { Log.LogError("DescriptionFile '{0}' does not exist", descriptionPath); return(false); } Dictionary <string, string> descriptionTable = null; if (!s_descriptionCache.TryGetValue(descriptionPath, out descriptionTable)) { // no cache, load it now. descriptionTable = LoadDescriptions(descriptionPath); s_descriptionCache[descriptionPath] = descriptionTable; } string description = null; if (descriptionTable != null) { descriptionTable.TryGetValue(PackageId, out description); } if (String.IsNullOrEmpty(description)) { Log.LogError("Unable to find description for package {0}", PackageId); } Description = description; return(!Log.HasLoggedErrors); }
/// <summary> /// /// </summary> /// <param name="filename"></param> public void LoadDescriptionSettings(string filename) { colName.Items.Clear(); if (File.Exists(filename)) { descriptionfile = Functions.DeserializeDescriptionFile(filename); if (descriptionfile != null) { foreach (DescriptionItem item in descriptionfile.Items) { colName.Sorted = true; colName.Items.Add(item.Name); } } } }
public List <DescriptionFile> GetFiles(string sort) { using (var db = ApplicationDbContext.Create()) { IQueryable <File> dataIP = db.Files; switch (sort) { case "Name": dataIP = dataIP.OrderBy(l => l.Name); break; case "NameDesc": dataIP = dataIP.OrderByDescending(l => l.Name); break; case "Page": dataIP = dataIP.OrderBy(l => l.NominationPage); break; case "PageDesc": dataIP = dataIP.OrderByDescending(l => l.NominationPage); break; default: dataIP = dataIP.OrderBy(l => l.Id); break; } var listIP = dataIP.ToList(); if (listIP != null) { var files = new List <DescriptionFile>(); foreach (var item in listIP) { var file = new DescriptionFile(); file.Name = item.Name; file.PathToFile = item.Path; file.NominationPage = item.NominationPage; files.Add(file); } return(files); } return(null); } }
/// <summary> /// Fold these in a generic /// </summary> /// <param name="filename"></param> /// <returns></returns> public static DescriptionFile DeserializeDescriptionFile(string filename) { DescriptionFile desc = null; if (File.Exists(filename)) { XmlSerializer nser = new XmlSerializer(typeof(DescriptionFile)); TextReader ntext = new StreamReader(filename); try { desc = (DescriptionFile)nser.Deserialize(ntext); } finally { ntext.Close(); ntext.Dispose(); } } return(desc); }
/// <summary> /// Fold these in a generic... /// </summary> /// <param name="filename"></param> /// <param name="descriptionfile"></param> /// <returns></returns> public static bool SerializeDescriptionFile(string filename, DescriptionFile descriptionfile) { bool b = false; XmlSerializer nser = new XmlSerializer(typeof(DescriptionFile)); TextWriter ntext = new StreamWriter(filename); try { nser.Serialize(ntext, descriptionfile); ntext.Flush(); b = true; } catch { b = false; } finally { ntext.Dispose(); } return(b); }
private static bool parseHeadline(DescriptionFile desc, string line, int lineNo) { var splitted = line.Split(new char[] { ':' }, 2); if (splitted.Length == 0) { return(false); //nothing this line. } if (splitted[0][0] == '=') //divide line, means the following lines are all volume data. { return(true); } if (splitted[0][1] == '#') //commment line { return(false); } var key = splitted[0].Trim().ToLower(); //key switch (key) { case "width": if (!int.TryParse(splitted[1].Trim(), out desc.width)) { throw new UnityException("Problem while parsing line " + lineNo); } break; case "height": if (!int.TryParse(splitted[1].Trim(), out desc.height)) { throw new UnityException("Problem while parsing line " + lineNo); } break; case "depth": if (!int.TryParse(splitted[1].Trim(), out desc.depth)) { throw new UnityException("Problem while parsing line " + lineNo); } break; case "bytecount": if (!int.TryParse(splitted[1].Trim(), out desc.byteCount)) { throw new UnityException("Problem while parsing line " + lineNo); } break; case "gradientscale": if (!float.TryParse(splitted[1].Trim(), out desc.gradientScale)) { throw new UnityException("Problem while parsing line " + lineNo); } break; case "albedo": desc.albedoTex = splitted[1].Trim(); break; case "metallic": desc.metallicTex = splitted[1].Trim(); break; default: break; } return(false); }
public static VolumeDataInfo ReadFromFile(DescriptionFile desc, IAsyncReaderProgressNotifier notifier) { var twidth = CeilToBinary(desc.width); var theight = CeilToBinary(desc.height); var tdepth = CeilToBinary(desc.depth); var fileData = new int[twidth * theight * tdepth]; FileStream currentFile = null; bool flag = false; int?minData = null; int?maxData = null; int volumeFileIndex = 0; for (int z = 0; z < desc.depth; z++) { if (flag) { break; } for (int y = 0; y < desc.height; y++) { if (flag) { break; } for (int x = 0; x < desc.width; x++) { if (currentFile == null) { if (volumeFileIndex < desc.volumeData.Length) //we have next file { var nextFilePath = desc.volumeData[volumeFileIndex++]; currentFile = new FileStream(desc.relativePath + "/../" + nextFilePath, FileMode.Open); if (notifier != null) { notifier.Notify("Reading file.. : " + nextFilePath); } } else //all input finished. { flag = true; break; } } //read it. byte[] byData = new byte[desc.byteCount]; if (currentFile.Read(byData, 0, desc.byteCount) == 0) { x--; currentFile.Close(); currentFile = null; continue; } int data = 0; for (int i = 0; i < desc.byteCount; i++) { data <<= 8; data += byData[i]; } fileData[x + y * twidth + z * twidth * theight] = data; if (minData == null) { minData = data; } else { minData = Mathf.Min(minData.Value, data); } if (maxData == null) { maxData = data; } else { maxData = Mathf.Max(maxData.Value, data); } } } } var result = new VolumeDataInfo(twidth, theight, tdepth); for (int i = 0; i < twidth; i++) { notifier.Notify("Filling texture...(" + (int)((float)i / twidth * 100) + "%)"); for (int j = 0; j < theight; j++) { for (int k = 0; k < tdepth; k++) { var data = (float)fileData[i + j * twidth + k * theight * twidth] / (maxData.Value - minData.Value); result[i, j, k] = new Color(data, data, data, data); } } } return(result); }
public AsyncReader(DescriptionFile descFile, IAsyncReaderProgressNotifier notifier) { this.descFile = descFile; this.notifier = notifier; }
public LogsViewModel() { ip = new ListIP(); descriptionFile = new DescriptionFile(); }