private int CommitTestSource(AutoEvaluation eval, IExternalSource zone) { FileSystem fs = new FileSystem(m_ident); //Make sure toplevel zone directory exists CFile zonedir = fs.GetFile(@"c:\zones"); if (null == zonedir) { zonedir = fs.CreateDirectory(@"c:\zones", true, null); } //Build file perms CFilePermission.FilePermissionList perms = new CFilePermission.FilePermissionList(); CourseRole.CourseRoleList staff = new Courses(m_ident).GetTypedRoles(eval.CourseID, true, null); foreach (CourseRole role in staff) { perms.AddRange(CFilePermission.CreateFullAccess(role.PrincipalID)); } //Create zone directory string zpath = @"c:\zones\" + eval.ID; CFile ezonedir; if (null == (ezonedir = fs.GetFile(zpath))) { ezonedir = fs.CreateDirectory(zpath, false, perms); ezonedir.Alias = eval.Name; ezonedir.SpecType = CFile.SpecialType.TEST; fs.UpdateFileInfo(ezonedir, false); } fs.ImportData(zpath, zone, false, true); //Import the data return(ezonedir.ID); }
public void Save(String fileName) { Stream s = CSerialization.SerializeBinary(m_Traffic); s.Position = 0; CFile.WriteStream(fileName, (MemoryStream)s); }
/// <summary> /// Set permissions for a given file /// </summary> public void SetPermissions(CFile file, CFilePermission perm) { CFilePermission.FilePermissionList perms = new CFilePermission.FilePermissionList(); perms.Add(perm); SetPermissions(file, perms); }
/// <summary> /// Private functionality to override admin security check /// </summary> private void SetPermissionsInt(CFile file, CFilePermission.FilePermissionList perms) { foreach (CFilePermission perm in perms) { m_dp.UpdateFilePermission(file, perm); } }
private string GetExportPath(CFile file) { string path = file.FullPath.Substring(3, file.FullPath.Length - 3); string[] dirs = path.Split(@"\".ToCharArray()); string aggdir = ""; int i; path = ""; for (i = 0; i < dirs.Length - 1; i++) { aggdir = Path.Combine(aggdir, dirs[i]); CFile fdir = GetFile(@"c:\" + aggdir); if (fdir == null) { path += dirs[i] + @"\"; } else { path += fdir.Alias + @"\"; } } path += file.Alias; path = Globals.PurifyString(path); return(path); }
/// <summary> /// Save changes to file data /// </summary> public bool Save(CFile file) { CFileLock flock; //Release the lock if (null == (flock = m_dp.GetLockByFileID(file.ID))) { throw new FileOperationException("File was never locked, cannot save"); } //Authorize if (!Authorize(file, FileAction.WRITE)) { throw new FileOperationException("Permission denied on action: WRITE"); } //Write the data CommitData(file); //Update mod times file.FileModified = DateTime.Now; file.Size = file.RawData.Length; m_dp.SyncFile(file); PercolateModified(file, file.FileModified); m_dp.ReleaseLock(flock); return(true); }
/// <summary> /// Authorize a user on a file for an action /// </summary> protected bool Authorize(int principalID, CFile file, FileAction action, User hint) { //Hack for system path if (file.Path.StartsWith(@"c:\system")) { return(true); } else if (hint != null) { if (hint.Admin) { return(true); } else { return(m_dp.AuthorizeFile(principalID, file, action)); } } else { //Check for a user Principal prin = new Principals(m_ident).GetInfo(principalID); if (prin.Type == Principal.USER) { User user = new Users(m_ident).GetInfo(prin.Name, null); if (user.Admin) { return(true); } } return(m_dp.AuthorizeFile(principalID, file, action)); } }
public void Load(String fileName) { try { List <T_ChsNameWordTraffic> newWords = new List <T_ChsNameWordTraffic>(); if (!File.Exists(fileName)) { //字典文件不存在 return; } MemoryStream s = CFile.ReadFileToStream(fileName); s.Position = 0; object obj; CSerialization.DeserializeBinary(s, out obj); m_Traffic = (T_ChsNameTraffic)obj; m_Traffic.AfterCount = 0; m_Traffic.AfterWordCount = 0; m_Traffic.BeforeCount = 0; m_Traffic.BeforeWordCount = 0; //整理姓名前缀后缀表 foreach (T_ChsNameWordTraffic wordTraffic in m_Traffic.Words) { if (wordTraffic.Word.Length > 1) { if (wordTraffic.Word[0] >= 0x4e00 && wordTraffic.Word[0] <= 0x9fa5) { //是汉字,且长度大于2,才作为有效前后缀 newWords.Add(wordTraffic); if (wordTraffic.After > 0) { m_Traffic.AfterCount += wordTraffic.After; m_Traffic.AfterWordCount++; } if (wordTraffic.Before > 0) { m_Traffic.BeforeCount += wordTraffic.After; m_Traffic.BeforeWordCount++; } } } } m_Traffic.Words = newWords; } catch { m_Traffic = new T_ChsNameTraffic(); } foreach (T_ChsNameWordTraffic wordTraffic in m_Traffic.Words) { m_Table[wordTraffic.Word] = wordTraffic; } }
private void f_BeforeFileCopy(object sender, CBeforeFileCopyEventArgs e) { FileInfo fiSrc = new FileInfo(e.FullPathSrc); FileInfo fiDest = (File.Exists(e.FullPathDest) ? new FileInfo(e.FullPathDest) : null); if (fiDest != null) { //Remove ReadOnly attribute from destination to block error when copying. if ((fiDest.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { FileAttributes AttrRemoved = CFile.RemoveAttribute(fiDest.Attributes, FileAttributes.ReadOnly); fiDest.Attributes = AttrRemoved; } } string FullPathSrcNewIs; if (!IsValidForSync(fiSrc, fiDest, false, out FullPathSrcNewIs)) { e.Cancel = true; } if (!string.IsNullOrEmpty(FullPathSrcNewIs)) { e.FullPathSrcNew = FullPathSrcNewIs; } }
public void LoadIncompletedFiles() { foreach (string folder in CKernel.Preferences.GetStringArray("TempFolders")) { try { string [] files = Directory.GetFiles(folder); foreach (string strfile in files) { if (Path.GetExtension(strfile).Equals(".part")) { CFile file = new CFile(Path.GetDirectoryName(strfile), Path.GetFileName(strfile)); if (file.FileHash != null) { AddFile(file); //file loaded properly } } } } catch (IOException e) { // any temp directory don't exist Debug.Write(e.ToString()); } } }
public string GetFileImage(CFile file) { if (file.IsDirectory()) { return("../../" + GetFolderIcon(file)); } else { ; string imgpath; try { imgpath = FileBrowserImageFactory.GetInstance().GetExtensionImage( Path.GetExtension(file.Name)); } catch (Exception) { imgpath = null; } if (imgpath == null) { return("../../attributes/filebrowser/misc.gif"); } else { return("../../attributes/filebrowser/" + imgpath); } } }
public HttpResponseMessage DeleteFile(Guid fileId) { try { HttpResponseMessage response = new HttpResponseMessage(); CFile file = _fileContext.GetByFileId(fileId); // if file exist - delete it, if not continue to delete DB record cuz user wanted to delete real file anyway if (File.Exists(file.Path + file.Name)) { File.Delete(file.Path + file.Name); } // delete record from DB if (_fileContext.Delete(fileId) > 0) { Request.CreateResponse(HttpStatusCode.OK, $"File {file.Name} has been deleted!"); return(response); } Request.CreateResponse(HttpStatusCode.BadRequest, $"Error: File {file.Name} has not been deleted!"); return(response); } catch (ContextException e) { HttpContext.Current.Response.StatusCode = (Int32)HttpStatusCode.BadRequest; throw new ContextException(e.Message, e); } }
public void LoadFileBrowser() { int i = 0; tvFiles.Nodes.Clear(); FileSystem fs = new FileSystem(Globals.CurrentIdentity); foreach (string droot in m_roots) { CFile dirroot = fs.GetFile(droot); TreeNode root = new TreeNode(); root.Text = dirroot.Alias; root.ImageUrl = GetFolderIcon(dirroot); root.NodeData = dirroot.FullPath; root.Expandable = ExpandableValue.Always; tvFiles.Nodes.Add(root); if (i == 0 && ViewState["gridpath"] == null) { ViewState["gridpath"] = dirroot.FullPath; ExpandTreeNode(root); } ++i; } BindFileGrid(); BindClipBoard(); }
private void BindFileGrid() { FileSystem fs = new FileSystem(Globals.CurrentIdentity); string path = GetCurrentPath(); if (path == null) { return; } CFile file = fs.GetFile(path); CFile.FileList dirlist; try { dirlist = fs.ListDirectory(file); } catch (CustomException er) { dirlist = new CFile.FileList(); DisplayMessage(er.Message); } dirlist.Insert(0, file); m_curdir = file; dgFiles.DataSource = dirlist; dgFiles.DataBind(); }
private void DoDelete(int subID, int locid) { FileSystem fs = new FileSystem(m_ident); //Take results Results resultda = new Results(m_ident); Result.ResultList ress = GetResults(subID); foreach (Result res in ress) { resultda.Delete(res.ID); } //Take any tests queued AutoJobs jobda = new AutoJobs(m_ident); AutoJobTest.AutoJobTestList tests = jobda.GetSubTests(subID); foreach (AutoJobTest test in tests) { jobda.FinishTest(test); } //Take the submission record m_dp.DeleteSubmission(subID); //Take the files CFile subdir = fs.GetFile(locid); if (subdir != null) { fs.DeleteFile(subdir); } }
/// <summary> /// Save Log file /// </summary> /// <param name="arrLine"></param> private void LogErrorFileSave(ArrayList arrLine) { string strYear = DateTime.Now.Year.ToString(); string strMonth = DateTime.Now.Month.ToString(); string strDay = DateTime.Now.Day.ToString(); if (arrLine.Count == 0) { return; } Config cConf = new Config(); CFile cLogFile = new CFile(); string DirPath = cConf.getappSettings(Config.SettingField.DataSyncDir.ToString()); cLogFile.fileName = DirPath + "/errorTerminal.log"; string sLine; foreach (string Line in arrLine) { sLine = "[" + DateTime.Now.ToUniversalTime().ToString() + "]" + Line; cLogFile.AddLine(sLine); } cLogFile.Write(); }
private void SaveToCacheDt(string Key, string FullPathToSave) { CreateCacheFolder(); string FullPathCache = GetFullPathCacheDt(Key); if (!File.Exists(FullPathCache)) { CreateDt(FullPathCache, false); } DataTable dt = new DataTable(); dt.ReadXml(FullPathCache); string Criteria = "Key = '" + Key.Replace("'", "''") + "'"; DataRow[] adr = dt.Select(Criteria); if (adr.Length > 0) { adr[0]["Content"] = CFile.GetByteFromFile(FullPathToSave); } else { DataRow dr = dt.NewRow(); dr["Key"] = Key; dr["Content"] = CFile.GetByteFromFile(FullPathToSave); dt.Rows.Add(dr); } dt.WriteXml(FullPathCache, XmlWriteMode.WriteSchema); dt = null; }
/// <summary> /// Fetch the data for a file object /// </summary> public void FetchData(CFile file) { SqlConnection myConnection = new SqlConnection(Globals.DataConnectionString); SqlCommand myCommand = new SqlCommand("SELECT data FROM FileData WHERE fileID = @FileID", myConnection); SqlParameter parameter = new SqlParameter("@FileID", SqlDbType.Int, 4); parameter.Value = file.ID; myCommand.Parameters.Add(parameter); myConnection.Open(); SqlDataReader reader = myCommand.ExecuteReader(); if (!reader.Read()) { throw new Exception("File Not Found!"); } byte[] data = (byte[])reader["data"]; file.RawData = data; reader.Close(); myConnection.Close(); }
public void CopyFile(CFile dest, CFile src) { string dpath = Path.Combine(m_localpath, dest.ID.ToString()); string spath = Path.Combine(m_localpath, src.ID.ToString()); File.Copy(spath, dpath, true); }
public void SaveDataByProcToCache(string Key, object DataToSave) { string FullPathTemp = CFile.GetTempFileName(); if (this.mUseAdo) { Recordset RsToSave = DataToSave as Recordset; RsToSave.Save(FullPathTemp, PersistFormatEnum.adPersistXML); SaveToCacheRs(Key, FullPathTemp); } else { DataTable DtToSave = DataToSave as DataTable; DtToSave.TableName = "Content"; if (DtToSave.DataSet == null) { DtToSave.WriteXml(FullPathTemp, XmlWriteMode.WriteSchema); } else { DtToSave.DataSet.WriteXml(FullPathTemp, XmlWriteMode.WriteSchema); } SaveToCacheDt(Key, FullPathTemp); } }
public void TestReadInt32s() { using (var cfile = new CFile(BuildStream(new byte[] { 0x12, 0x34, 0x56, 0x78, 0xFE, 0xDC, 0xBA, 0x98 }))) { var vals = cfile.ReadInt32s(4); Assert.Equal(2, vals.Length); Assert.Equal((int)0x78563412, vals[0]); Assert.Equal(0x98BADCFE, (uint)vals[1]); Assert.Equal(null, cfile.ReadInt32s(4)); Assert.Equal(true, cfile.EOF); } using (var cfile = new CFile(BuildStream(new byte[] { 0x12, 0x34, 0x56, 0x78, 0xFE, 0xDC, 0xBA }))) { var vals = cfile.ReadInt32s(4); Assert.Equal(1, vals.Length); Assert.Equal((int)0x78563412, vals[0]); Assert.Equal(null, cfile.ReadInt32s(4)); Assert.Equal(true, cfile.EOF); } using (var cfile = new CFile(BuildStream(new byte[] { 97, 0x12, 0x34, 0x56, 0x78, 0xFE, 0xDC, 0xBA, 0x98 }))) { Assert.Equal('a', cfile.ReadChar()); var vals = cfile.ReadInt32s(4); Assert.Equal(2, vals.Length); Assert.Equal((int)0x78563412, vals[0]); Assert.Equal(0x98BADCFE, (uint)vals[1]); Assert.Equal(null, cfile.ReadInt32s(4)); Assert.Equal(true, cfile.EOF); } }
public void TestCreate() { using (var stream = new System.IO.MemoryStream()) using (var cfile = new CFile(stream)) { #if !NET_STANDARD Assert.Equal("Windows-1252", cfile.Encoding.WebName); #else Assert.Equal("utf-8", cfile.Encoding.WebName); #endif Assert.Equal(0, cfile.Length); Assert.Equal(0, cfile.Position); Assert.Equal(false, cfile.EOF); Assert.Equal(-1, cfile.Read()); Assert.Equal(true, cfile.EOF); } using (var stream = new System.IO.MemoryStream()) using (var cfile = new CFile(stream, Encoding.UTF8)) { Assert.Equal("utf-8", cfile.Encoding.WebName); Assert.Equal(0, cfile.Length); Assert.Equal(0, cfile.Position); Assert.Equal(false, cfile.EOF); Assert.Equal(-1, cfile.Read()); Assert.Equal(true, cfile.EOF); } }
/// <summary> /// 获取SDK目录 /// </summary> /// <returns></returns> /*private static string GetSDKDir() * { * return EditorUtility.OpenFolderPanel("Please select the android sdk directory", SDK_PATH_DEFAULT, ""); * }*/ /// <summary> /// 更改标题画面 /// </summary> /// <param name="titleName"></param> private static bool CopyLogo() { try { string src = Application.dataPath + "/Projects/" + PlayerSettings.companyName + "/Logo"; string desc = Application.dataPath + "/Logo"; Debug.Log("copy file from:" + src + " to:" + desc); if (!Directory.Exists(src)) { Debug.Log(src + " dir is not exists"); return(true); } if (Directory.Exists(desc)) { CFile.DeleteDirectory(desc); } CFile.CopyDirectory(src, desc); AssetDatabase.Refresh(); } catch (Exception ex) { Debug.LogException(ex); return(false); } return(true); }
public void TestReadDoubles() { using (var cfile = new CFile(BuildStream(new byte[] { 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0xFE, 0xDC, 0xBA, 0x98, 0xFE, 0xDC, 0xBA, 0x98 }))) { var vals = cfile.ReadDoubles(4); Assert.Equal(2, vals.Length); Assert.Equal("4.69197536052338E+271", vals[0].ToString(CultureInfo.InvariantCulture)); Assert.Equal(-1.50730608775746E-189, vals[1], 15); Assert.Equal(null, cfile.ReadDoubles(4)); Assert.Equal(true, cfile.EOF); } using (var cfile = new CFile(BuildStream(new byte[] { 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0xFE, 0xDC, 0xBA, 0x98, 0xFE, 0xDC, 0xBA }))) { var vals = cfile.ReadDoubles(4); Assert.Equal(1, vals.Length); Assert.Equal("4.69197536052338E+271", vals[0].ToString(CultureInfo.InvariantCulture)); Assert.Equal(null, cfile.ReadDoubles(4)); Assert.Equal(true, cfile.EOF); } using (var cfile = new CFile(BuildStream(new byte[] { 97, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0xFE, 0xDC, 0xBA, 0x98, 0xFE, 0xDC, 0xBA, 0x98 }))) { Assert.Equal('a', cfile.ReadChar()); var vals = cfile.ReadDoubles(4); Assert.Equal(2, vals.Length); Assert.Equal("4.69197536052338E+271", vals[0].ToString(CultureInfo.InvariantCulture)); Assert.Equal(-1.50730608775746E-189, vals[1], 15); Assert.Equal(null, cfile.ReadDoubles(4)); Assert.Equal(true, cfile.EOF); } }
/// <summary> /// Update a rubric entry /// </summary> public bool Update(Rubric rub) { //check permission Assignment asst = new Assignments(m_ident).GetInfo(rub.AsstID); Authorize(asst.CourseID, "updaterubric", asst.ID, null); //Rename zone on entry rename if (rub.EvalID >= 0) { FileSystem fs = new FileSystem(m_ident); int zoneID = (new Evaluations(m_ident).GetInfo(rub.EvalID) as AutoEvaluation).ZoneID; CFile zdir = fs.GetFile(zoneID); zdir.Alias = rub.Name; fs.UpdateFileInfo(zdir, false); } //Update entry m_dp.UpdateRubricEntry(rub); //Retally points and update root entry Rubric root = new Assignments(m_ident).GetRubric(rub.AsstID); root.Points = RetallyPoints(root); m_dp.UpdateRubricEntry(root); //Log Log("Updated rubric entry: " + rub.Name, rub.AsstID); return(true); }
/// <summary> /// No Path, No Extension /// </summary> /// <param name="NameFull"></param> /// <param name="Name"></param> /// <param name="Error"></param> /// <returns></returns> public static bool GetNameShort(String NameFull, out String Name, out String Error) { int iIndex; String strMsg, strName, strNameFull; Name = ""; if (!CFile.GetName(NameFull, out strName, out Error)) { return(false); } //System.IO.Path.GetFileNameWithoutExtension() strNameFull = NameFull; iIndex = strName.LastIndexOf("."); if (iIndex == -1) { strMsg = String.Format("The name of file doesn't contain the extension.({0})", strNameFull); Error = strMsg; return(false); } Name = strName.Substring(0, iIndex); return(true); }
private void SaveToCacheRs(string Key, string FullPathToSave) { CreateCacheFolder(); string FullPathCache = GetFullPathCacheRs(Key); if (!File.Exists(FullPathCache)) { CreateRs(FullPathCache, false); } Recordset Rs = new Recordset(); Rs.Open(FullPathCache, Missing.Value, CursorTypeEnum.adOpenStatic, LockTypeEnum.adLockPessimistic, -1); string Criteria = "Key = '" + Key.Replace("'", "''") + "'"; Rs.Find(Criteria, 0, SearchDirectionEnum.adSearchForward, Missing.Value); if (!Rs.EOF) { Rs.Fields["Content"].AppendChunk(CFile.GetByteFromFile(FullPathToSave)); } else { Rs.AddNew(Missing.Value, Missing.Value); Rs.Fields["Key"].Value = Key; Rs.Fields["Content"].AppendChunk(CFile.GetByteFromFile(FullPathToSave)); } Rs.Save(FullPathCache, PersistFormatEnum.adPersistXML); Rs.Close(); Rs = null; }
public static void GetFileFromField(ADODB.Field Fld, string FullPath) { byte[] aChunks = new byte[Fld.ActualSize]; aChunks = (byte[])Fld.GetChunk(Fld.ActualSize); CFile.WriteByteToFile(FullPath, aChunks); }
protected IEnumerator UpdateAssetFromUrl(CUpdateList needUpdateLst, string downloadUrl) { updateNum = 0; needUpdateNum = needUpdateLst.Count(); string savePath, downloadPath, saveDir; base.Event.Trigger(CAutoUpdateEvents.ON_UPDATE_FILE_START); foreach (CUpdateListField field in needUpdateLst) { downloadPath = downloadUrl + field.Path; savePath = CEnv.AssetPath + field.Path; saveDir = savePath.Substring(0, savePath.LastIndexOf('/')); updateNum++; base.Event.Trigger(CAutoUpdateEvents.ON_UPDATE_FILE_ACTION); using (UnityWebRequest request = UnityWebRequest.Get(downloadPath)) { yield return(request.Send()); if (request.isError || request.responseCode != 200) { base.Event.Trigger(CAutoUpdateEvents.ON_UPDATE_FILE_FAILD); yield break; } CDirectory.CreateDir(saveDir); CFile.Cover(savePath, request.downloadHandler.data, 0, request.downloadHandler.data.Length); } } base.Event.Trigger(CAutoUpdateEvents.ON_UPDATE_FILE_END); }
static public void SaveToBinFile(String fileName, T_DictFile dictFile) { Stream s = CSerialization.SerializeBinary(dictFile); s.Position = 0; CFile.WriteStream(fileName, (MemoryStream)s); }
public async Task<ActionResult> Receive() { bool thumb = true; int thumb_width = 200; int thumb_height = 200; string name = Request.Headers["UploaderName"]; bool chunk = bool.Parse(Request.Headers["Chunk"]); if (chunk) { var fileName = Request.Headers["FileName"]; var size = int.Parse(Request.Headers["FileSize"]); CFile file = null; //Check it if there is a file with that name and if there is not create one if (!chunkFilesPath.ContainsKey(fileName)) { file = new CFile(Server.MapPath("~/uploads") + "/" + fileName, size); chunkFilesPath.Add(fileName, file); } //Write the partion of the file with the position. if (chunkFilesPath.TryGetValue(fileName, out file)) { var stream = Request.InputStream; var position = int.Parse(Request.Headers["ChunkPosition"]); file.Upload(stream, position); } //If it is %100 then remove it from the dictionary. if (file.Percent == 100) { chunkFilesPath.Remove(fileName); } return Json(true); } else { TFile file = new TFile(Server.MapPath("~/uploads/images"), Server.MapPath("~/uploads/thumbnails"), thumb_width, thumb_height); if (file.UploadAjax(Request.InputStream, name, thumb) == -1) //fail { return Json(false); } else //success { return Json(true); } } }
public Collection( string FileName, object ProgressBar ) { _vectors_name = new List<string>(); _vectors_visibility = new List<bool>(); Vectors = new List<Vector>(); File = new CFile(_vectors_name, _vectors_visibility, Vectors, FileParam); File.Load_TextFile( FileName, ProgressBar ); }
public void TestCreate() { var stream = new System.IO.MemoryStream(); using (var cfile = new CFile(stream)) { Assert.AreEqual(0, cfile.Length); Assert.AreEqual(0, cfile.Position); Assert.AreEqual(false, cfile.EOF); Assert.AreEqual(-1, cfile.Read()); Assert.AreEqual(true, cfile.EOF); } }
public CHashSetResponse(MemoryStream buffer, CFile File) { BinaryWriter writer = new BinaryWriter(buffer); DonkeyHeader header = new DonkeyHeader((byte)Protocol.ClientCommand.HashSetAnswer, writer); writer.Write(File.FileHash); writer.Write((ushort)File.HashSet.Count); foreach (byte[] PartialHash in File.HashSet) { writer.Write(PartialHash); } header.Packetlength = (uint)writer.BaseStream.Length - header.Packetlength + 1; writer.Seek(0, SeekOrigin.Begin); header.Serialize(writer); }
public Collection(int ItemsCount = 1) { _vectors_name = new List<string>(); _vectors_visibility = new List<bool>(); Vectors = new List<Vector>(); File = new CFile(_vectors_name, _vectors_visibility, Vectors, FileParam); FileParam.CanalCount = ItemsCount; FileParam.FileVersion = 1; FileParam.SamplingTime = 1.0f; FileParam.ScaleFactor = 1.0f; for (int i = 0; i < ItemsCount; i++) { _vectors_name.Add("Canal_" + i.ToString()); _vectors_visibility.Add(true); } set_Vectors_Count(ItemsCount); }
public Collection(int ItemsCount) { _names = new List<string>(); _visible = new List<bool>(); _items = new List<List<float>>(); File = new CFile(_names, _visible, _items, FileParam); FileParam.CanalCount = 0; FileParam.FileVersion = 0; FileParam.SamplingTime = 0.0f; FileParam.ScaleFactor = 1.0f; for (int i = 0; i < ItemsCount; i++) { _names.Add("Canal_" + i.ToString()); _visible.Add(true); } SetListsCount(ItemsCount); }
public Collection( Collection inCollection ) { _vectors_name = new List<string>(inCollection._vectors_name); _vectors_visibility = new List<bool>(inCollection._vectors_visibility); Vectors = new List<Vector>(); File = new CFile(_vectors_name, _vectors_visibility, Vectors, FileParam); FileParam.CanalCount = inCollection.FileParam.CanalCount; FileParam.FileVersion = inCollection.FileParam.FileVersion; FileParam.SamplingTime = inCollection.FileParam.SamplingTime; FileParam.ScaleFactor = inCollection.FileParam.ScaleFactor; int ItemsCount = inCollection.Vectors.Count; // Копирование содержимого Vectors.Clear(); for (int i = 0; i < ItemsCount; i++) Vectors.Add(new Vector(inCollection.Vectors[i])); GC.Collect(); }
public CHashSetResponse(MemoryStream buffer, ref CFile File) { BinaryReader reader = new BinaryReader(buffer); byte[] FileHash;//=new byte[16]; FileHash = reader.ReadBytes(16); if (!CKernel.SameHash(ref FileHash, ref File.FileHash)) return; ArrayList NewHashSet = new ArrayList(); ushort nChunks = reader.ReadUInt16(); if (nChunks == 0) { NewHashSet.Add(FileHash); //Fichero.GetHashSet().Clear(); //Fichero.SetHashSet(null); File.HashSet = NewHashSet; } else { byte[] PartialHash;//=new byte[16]; while (nChunks > 0) { PartialHash = reader.ReadBytes(16); NewHashSet.Add(PartialHash); nChunks--; } byte[] HashSetChecked = CHash.DoHashSetHash(NewHashSet); if (CKernel.SameHash(ref HashSetChecked, ref File.FileHash)) { //Fichero.GetHashSet().Clear(); //Fichero.SetHashSet(null); File.HashSet = NewHashSet; } } reader.Close(); buffer.Close(); reader = null; buffer = null; }
public void TestReadChar() { using (var cfile = new CFile(BuildStream("èaà\nüî"))) { Assert.AreEqual(195, cfile.ReadChar()); Assert.AreEqual(168, cfile.ReadChar()); Assert.AreEqual(97, cfile.ReadChar()); Assert.AreEqual(195, cfile.ReadChar()); Assert.AreEqual(160, cfile.ReadChar()); Assert.AreEqual(10, cfile.ReadChar()); Assert.AreEqual(195, cfile.ReadChar()); Assert.AreEqual(188, cfile.ReadChar()); Assert.AreEqual(195, cfile.ReadChar()); Assert.AreEqual(174, cfile.ReadChar()); Assert.AreEqual(0, cfile.ReadChar()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî", Encoding.GetEncoding("windows-1252")))) { Assert.AreEqual(232, cfile.ReadChar()); Assert.AreEqual(97, cfile.ReadChar()); Assert.AreEqual(224, cfile.ReadChar()); Assert.AreEqual(10, cfile.ReadChar()); Assert.AreEqual(252, cfile.ReadChar()); Assert.AreEqual(238, cfile.ReadChar()); Assert.AreEqual(0, cfile.ReadChar()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî"), Encoding.UTF8)) { Assert.AreEqual('è', cfile.ReadChar()); Assert.AreEqual('a', cfile.ReadChar()); Assert.AreEqual('à', cfile.ReadChar()); Assert.AreEqual('\n', cfile.ReadChar()); Assert.AreEqual('ü', cfile.ReadChar()); Assert.AreEqual('î', cfile.ReadChar()); Assert.AreEqual(0, cfile.ReadChar()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî", Encoding.GetEncoding("windows-1252")), Encoding.GetEncoding("windows-1252"))) { Assert.AreEqual(232, cfile.ReadChar()); Assert.AreEqual(97, cfile.ReadChar()); Assert.AreEqual(224, cfile.ReadChar()); Assert.AreEqual(10, cfile.ReadChar()); Assert.AreEqual(252, cfile.ReadChar()); Assert.AreEqual(238, cfile.ReadChar()); Assert.AreEqual(0, cfile.ReadChar()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî", Encoding.UTF8), Encoding.GetEncoding("windows-1252"))) { Assert.AreEqual(195, cfile.ReadChar()); Assert.AreEqual(168, cfile.ReadChar()); Assert.AreEqual(97, cfile.ReadChar()); Assert.AreEqual(195, cfile.ReadChar()); Assert.AreEqual(160, cfile.ReadChar()); Assert.AreEqual(10, cfile.ReadChar()); Assert.AreEqual(195, cfile.ReadChar()); Assert.AreEqual(188, cfile.ReadChar()); Assert.AreEqual(195, cfile.ReadChar()); Assert.AreEqual(174, cfile.ReadChar()); Assert.AreEqual(0, cfile.ReadChar()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream(new byte[] { 195 }), Encoding.UTF8)) { Assert.AreEqual(65533, cfile.ReadChar()); Assert.AreEqual(0, cfile.ReadChar()); Assert.AreEqual(true, cfile.EOF); } }
public void TestReadChars() { using (var cfile = new CFile(BuildStream("èaà\nüî"))) { CollectionAssert.AreEqual(new char[] { 'Ã', '¨', 'a' }, cfile.ReadChars(3)); CollectionAssert.AreEqual(new char[] { 'Ã', ' ', '\n' }, cfile.ReadChars(3)); CollectionAssert.AreEqual(new char[] { 'Ã', '¼', 'Ã', }, cfile.ReadChars(3)); CollectionAssert.AreEqual(new char[] { '®' }, cfile.ReadChars(3)); CollectionAssert.AreEqual(null, cfile.ReadChars(3)); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî", Encoding.GetEncoding("windows-1252")))) { CollectionAssert.AreEqual(new char[] { 'è', 'a', 'à' }, cfile.ReadChars(3)); CollectionAssert.AreEqual(new char[] { '\n', 'ü', 'î' }, cfile.ReadChars(3)); CollectionAssert.AreEqual(null, cfile.ReadChars(3)); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî"), Encoding.UTF8)) { CollectionAssert.AreEqual(new char[] { 'è', 'a', 'à' }, cfile.ReadChars(3)); CollectionAssert.AreEqual(new char[] { '\n', 'ü', 'î' }, cfile.ReadChars(3)); CollectionAssert.AreEqual(null, cfile.ReadChars(3)); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî", Encoding.GetEncoding("windows-1252")), Encoding.GetEncoding("windows-1252"))) { CollectionAssert.AreEqual(new char[] { 'è', 'a', 'à' }, cfile.ReadChars(3)); CollectionAssert.AreEqual(new char[] { '\n', 'ü', 'î' }, cfile.ReadChars(3)); CollectionAssert.AreEqual(null, cfile.ReadChars(3)); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî", Encoding.UTF8), Encoding.GetEncoding("windows-1252"))) { CollectionAssert.AreEqual(new char[] { 'Ã', '¨', 'a' }, cfile.ReadChars(3)); CollectionAssert.AreEqual(new char[] { 'Ã', ' ', '\n' }, cfile.ReadChars(3)); CollectionAssert.AreEqual(new char[] { 'Ã', '¼', 'Ã', }, cfile.ReadChars(3)); CollectionAssert.AreEqual(new char[] { '®' }, cfile.ReadChars(3)); CollectionAssert.AreEqual(null, cfile.ReadChars(3)); Assert.AreEqual(true, cfile.EOF); } }
public void TestRead() { using (var cfile = new CFile(BuildStream("èaà\nüî"))) { Assert.AreEqual(195, cfile.Read()); Assert.AreEqual(168, cfile.Read()); Assert.AreEqual(97, cfile.Read()); Assert.AreEqual(195, cfile.Read()); Assert.AreEqual(160, cfile.Read()); Assert.AreEqual(10, cfile.Read()); Assert.AreEqual(195, cfile.Read()); Assert.AreEqual(188, cfile.Read()); Assert.AreEqual(195, cfile.Read()); Assert.AreEqual(174, cfile.Read()); Assert.AreEqual(-1, cfile.Read()); Assert.AreEqual(-1, cfile.Read()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî", Encoding.GetEncoding("windows-1252")))) { Assert.AreEqual(232, cfile.Read()); Assert.AreEqual(97, cfile.Read()); Assert.AreEqual(224, cfile.Read()); Assert.AreEqual(10, cfile.Read()); Assert.AreEqual(252, cfile.Read()); Assert.AreEqual(238, cfile.Read()); Assert.AreEqual(-1, cfile.Read()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî"), Encoding.UTF8)) { Assert.AreEqual(195, cfile.Read()); Assert.AreEqual(168, cfile.Read()); Assert.AreEqual(97, cfile.Read()); Assert.AreEqual(195, cfile.Read()); Assert.AreEqual(160, cfile.Read()); Assert.AreEqual(10, cfile.Read()); Assert.AreEqual(195, cfile.Read()); Assert.AreEqual(188, cfile.Read()); Assert.AreEqual(195, cfile.Read()); Assert.AreEqual(174, cfile.Read()); Assert.AreEqual(-1, cfile.Read()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî", Encoding.GetEncoding("windows-1252")), Encoding.GetEncoding("windows-1252"))) { Assert.AreEqual(232, cfile.Read()); Assert.AreEqual(97, cfile.Read()); Assert.AreEqual(224, cfile.Read()); Assert.AreEqual(10, cfile.Read()); Assert.AreEqual(252, cfile.Read()); Assert.AreEqual(238, cfile.Read()); Assert.AreEqual(-1, cfile.Read()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî", Encoding.UTF8), Encoding.GetEncoding("windows-1252"))) { Assert.AreEqual(195, cfile.Read()); Assert.AreEqual(168, cfile.Read()); Assert.AreEqual(97, cfile.Read()); Assert.AreEqual(195, cfile.Read()); Assert.AreEqual(160, cfile.Read()); Assert.AreEqual(10, cfile.Read()); Assert.AreEqual(195, cfile.Read()); Assert.AreEqual(188, cfile.Read()); Assert.AreEqual(195, cfile.Read()); Assert.AreEqual(174, cfile.Read()); Assert.AreEqual(-1, cfile.Read()); Assert.AreEqual(true, cfile.EOF); } }
public void TestReadDoubles() { using (var cfile = new CFile(BuildStream(new byte[] { 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0xFE, 0xDC, 0xBA, 0x98, 0xFE, 0xDC, 0xBA, 0x98 }))) { var vals = cfile.ReadDoubles(4); Assert.AreEqual(2, vals.Length); Assert.AreEqual(4.69197536052338E+271, vals[0], 1e+257); Assert.AreEqual(-1.50730608775746E-189, vals[1], 1e-150); Assert.AreEqual(null, cfile.ReadDoubles(4)); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream(new byte[] { 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0xFE, 0xDC, 0xBA, 0x98, 0xFE, 0xDC, 0xBA }))) { var vals = cfile.ReadDoubles(4); Assert.AreEqual(1, vals.Length); Assert.AreEqual(4.69197536052338E+271, vals[0], 1e+257); Assert.AreEqual(null, cfile.ReadDoubles(4)); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream(new byte[] { 97, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0xFE, 0xDC, 0xBA, 0x98, 0xFE, 0xDC, 0xBA, 0x98 }))) { Assert.AreEqual('a', cfile.ReadChar()); var vals = cfile.ReadDoubles(4); Assert.AreEqual(2, vals.Length); Assert.AreEqual(4.69197536052338E+271, vals[0], 1e+257); Assert.AreEqual(-1.50730608775746E-189, vals[1], 1e-150); Assert.AreEqual(null, cfile.ReadDoubles(4)); Assert.AreEqual(true, cfile.EOF); } }
public void TestSeek() { using (var cfile = new CFile(BuildStream(new byte[] { 0x12, 0x34, 0x56, 0x78, 0xFE, 0xDC, 0xBA, 0x98 }))) { Assert.AreEqual(0, cfile.Seek(4, SeekOrigin.Current)); Assert.AreEqual(0x98BADCFE, (uint)cfile.ReadInt32()); Assert.AreEqual(0, cfile.Seek(0, SeekOrigin.Begin)); Assert.AreEqual((int)0x78563412, cfile.ReadInt32()); } using (var cfile = new CFile(null)) { Assert.AreEqual(-1, cfile.Seek(4, SeekOrigin.Current)); } }
public void TestReadLine() { using (var cfile = new CFile(BuildStream(""))) { Assert.AreEqual(null, cfile.ReadLine()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream(" "))) { Assert.AreEqual(" ", cfile.ReadLine()); Assert.AreEqual(null, cfile.ReadLine()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("1\n"))) { Assert.AreEqual("1", cfile.ReadLine()); Assert.AreEqual(null, cfile.ReadLine()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("1\n2"))) { Assert.AreEqual("1", cfile.ReadLine()); Assert.AreEqual("2", cfile.ReadLine()); Assert.AreEqual(null, cfile.ReadLine()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("1\n2\r"))) { Assert.AreEqual("1", cfile.ReadLine()); Assert.AreEqual("2", cfile.ReadLine()); Assert.AreEqual(null, cfile.ReadLine()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("1\n2\r3"))) { Assert.AreEqual("1", cfile.ReadLine()); Assert.AreEqual("2", cfile.ReadLine()); Assert.AreEqual("3", cfile.ReadLine()); Assert.AreEqual(null, cfile.ReadLine()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("1\n2\r3\n\r"))) { Assert.AreEqual("1", cfile.ReadLine()); Assert.AreEqual("2", cfile.ReadLine()); Assert.AreEqual("3", cfile.ReadLine()); Assert.AreEqual("", cfile.ReadLine()); Assert.AreEqual(null, cfile.ReadLine()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("1\n2\r3\n\r4"))) { Assert.AreEqual("1", cfile.ReadLine()); Assert.AreEqual("2", cfile.ReadLine()); Assert.AreEqual("3", cfile.ReadLine()); Assert.AreEqual("", cfile.ReadLine()); Assert.AreEqual("4", cfile.ReadLine()); Assert.AreEqual(null, cfile.ReadLine()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("1\n2\r3\n\r4\r\n"))) { Assert.AreEqual("1", cfile.ReadLine()); Assert.AreEqual("2", cfile.ReadLine()); Assert.AreEqual("3", cfile.ReadLine()); Assert.AreEqual("", cfile.ReadLine()); Assert.AreEqual("4", cfile.ReadLine()); Assert.AreEqual(null, cfile.ReadLine()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("1\n2\r3\n\r4\r\n5"))) { Assert.AreEqual("1", cfile.ReadLine()); Assert.AreEqual("2", cfile.ReadLine()); Assert.AreEqual("3", cfile.ReadLine()); Assert.AreEqual("", cfile.ReadLine()); Assert.AreEqual("4", cfile.ReadLine()); Assert.AreEqual("5", cfile.ReadLine()); Assert.AreEqual(null, cfile.ReadLine()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("1\n\n\n\r\r\r\n5"))) { Assert.AreEqual("1", cfile.ReadLine()); Assert.AreEqual("", cfile.ReadLine()); Assert.AreEqual("", cfile.ReadLine()); Assert.AreEqual("", cfile.ReadLine()); Assert.AreEqual("", cfile.ReadLine()); Assert.AreEqual("", cfile.ReadLine()); Assert.AreEqual("5", cfile.ReadLine()); Assert.AreEqual(null, cfile.ReadLine()); Assert.AreEqual(true, cfile.EOF); } }
public void TestReadSBytes() { using (var cfile = new CFile(BuildStream("èaà\nüî"))) { CollectionAssert.AreEqual(new sbyte[] { -61, -88, 97 }, cfile.ReadSBytes(3)); CollectionAssert.AreEqual(new sbyte[] { -61, -96, 10 }, cfile.ReadSBytes(3)); CollectionAssert.AreEqual(new sbyte[] { -61, -68, -61 }, cfile.ReadSBytes(3)); CollectionAssert.AreEqual(new sbyte[] { -82 }, cfile.ReadSBytes(3)); CollectionAssert.AreEqual(null, cfile.ReadSBytes(3)); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî", Encoding.GetEncoding("windows-1252")))) { CollectionAssert.AreEqual(new sbyte[] { -24, 97, -32 }, cfile.ReadSBytes(3)); CollectionAssert.AreEqual(new sbyte[] { 10, -4, -18 }, cfile.ReadSBytes(3)); CollectionAssert.AreEqual(null, cfile.ReadSBytes(3)); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî"), Encoding.UTF8)) { CollectionAssert.AreEqual(new sbyte[] { -61, -88, 97 }, cfile.ReadSBytes(3)); CollectionAssert.AreEqual(new sbyte[] { -61, -96, 10 }, cfile.ReadSBytes(3)); CollectionAssert.AreEqual(new sbyte[] { -61, -68, -61 }, cfile.ReadSBytes(3)); CollectionAssert.AreEqual(new sbyte[] { -82 }, cfile.ReadSBytes(3)); CollectionAssert.AreEqual(null, cfile.ReadSBytes(3)); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî", Encoding.GetEncoding("windows-1252")), Encoding.GetEncoding("windows-1252"))) { CollectionAssert.AreEqual(new sbyte[] { -24, 97, -32 }, cfile.ReadSBytes(3)); CollectionAssert.AreEqual(new sbyte[] { 10, -4, -18 }, cfile.ReadSBytes(3)); CollectionAssert.AreEqual(null, cfile.ReadSBytes(3)); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî", Encoding.UTF8), Encoding.GetEncoding("windows-1252"))) { CollectionAssert.AreEqual(new sbyte[] { -61, -88, 97 }, cfile.ReadSBytes(3)); CollectionAssert.AreEqual(new sbyte[] { -61, -96, 10 }, cfile.ReadSBytes(3)); CollectionAssert.AreEqual(new sbyte[] { -61, -68, -61 }, cfile.ReadSBytes(3)); CollectionAssert.AreEqual(new sbyte[] { -82 }, cfile.ReadSBytes(3)); CollectionAssert.AreEqual(null, cfile.ReadSBytes(3)); Assert.AreEqual(true, cfile.EOF); } }
public void TestReadString() { String str = null; using (var cfile = new CFile(BuildStream("èaà\nüî"))) { str = "$$$"; Assert.AreEqual(true, cfile.ReadString(ref str, 3)); Assert.AreEqual("èa", str); str = "$$$"; Assert.AreEqual(true, cfile.ReadString(ref str, 3)); Assert.AreEqual("à \n", str); str = "$$$"; Assert.AreEqual(true, cfile.ReadString(ref str, 3)); Assert.AreEqual("üÃ", str); str = "$$$"; Assert.AreEqual(false, cfile.ReadString(ref str, 3)); Assert.AreEqual("®", str); str = "$$$"; Assert.AreEqual(false, cfile.ReadString(ref str, 3)); Assert.AreEqual(null, str); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî", Encoding.GetEncoding("windows-1252")))) { str = "$$$"; Assert.AreEqual(true, cfile.ReadString(ref str, 3)); Assert.AreEqual("èaà", str); str = "$$$"; Assert.AreEqual(true, cfile.ReadString(ref str, 3)); Assert.AreEqual("\nüî", str); str = "$$$"; Assert.AreEqual(false, cfile.ReadString(ref str, 3)); Assert.AreEqual(null, str); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî"), Encoding.UTF8)) { str = "$$$"; Assert.AreEqual(true, cfile.ReadString(ref str, 3)); Assert.AreEqual("èaà", str); str = "$$$"; Assert.AreEqual(true, cfile.ReadString(ref str, 3)); Assert.AreEqual("\nüî", str); str = "$$$"; Assert.AreEqual(false, cfile.ReadString(ref str, 3)); Assert.AreEqual(null, str); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî", Encoding.GetEncoding("windows-1252")), Encoding.GetEncoding("windows-1252"))) { str = "$$$"; Assert.AreEqual(true, cfile.ReadString(ref str, 3)); Assert.AreEqual("èaà", str); str = "$$$"; Assert.AreEqual(true, cfile.ReadString(ref str, 3)); Assert.AreEqual("\nüî", str); str = "$$$"; Assert.AreEqual(false, cfile.ReadString(ref str, 3)); Assert.AreEqual(null, str); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî", Encoding.UTF8), Encoding.GetEncoding("windows-1252"))) { str = "$$$"; Assert.AreEqual(true, cfile.ReadString(ref str, 3)); Assert.AreEqual("èa", str); str = "$$$"; Assert.AreEqual(true, cfile.ReadString(ref str, 3)); Assert.AreEqual("à \n", str); str = "$$$"; Assert.AreEqual(true, cfile.ReadString(ref str, 3)); Assert.AreEqual("üÃ", str); str = "$$$"; Assert.AreEqual(false, cfile.ReadString(ref str, 3)); Assert.AreEqual("®", str); str = "$$$"; Assert.AreEqual(false, cfile.ReadString(ref str, 3)); Assert.AreEqual(null, str); Assert.AreEqual(true, cfile.EOF); } }
public void TestReadByte() { using (var cfile = new CFile(BuildStream("èaà\nüî"))) { Assert.AreEqual(195, cfile.ReadByte()); Assert.AreEqual(168, cfile.ReadByte()); Assert.AreEqual(97, cfile.ReadByte()); Assert.AreEqual(195, cfile.ReadByte()); Assert.AreEqual(160, cfile.ReadByte()); Assert.AreEqual(10, cfile.ReadByte()); Assert.AreEqual(195, cfile.ReadByte()); Assert.AreEqual(188, cfile.ReadByte()); Assert.AreEqual(195, cfile.ReadByte()); Assert.AreEqual(174, cfile.ReadByte()); Assert.AreEqual(0, cfile.ReadByte()); Assert.AreEqual(0, cfile.ReadByte()); Assert.AreEqual(true, cfile.EOF); } }
public void TestReadBytes() { byte[] buff = new byte[3]; using (var cfile = new CFile(BuildStream("èaà\nüî"))) { Assert.AreEqual(3, cfile.Read(buff, 0, 3)); CollectionAssert.AreEqual(new byte[] { 195, 168, 97 }, buff); Assert.AreEqual(3, cfile.Read(buff, 0, 3)); CollectionAssert.AreEqual(new byte[] { 195, 160, 10}, buff); Assert.AreEqual(3, cfile.Read(buff, 0, 3)); CollectionAssert.AreEqual(new byte[] { 195, 188, 195 }, buff); Assert.AreEqual(1, cfile.Read(buff, 0, 3)); CollectionAssert.AreEqual(new byte[] { 174, 188, 195 }, buff); Assert.AreEqual(0, cfile.Read(buff, 0, 3)); Assert.AreEqual(0, cfile.Read(buff, 0, 3)); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî", Encoding.GetEncoding("windows-1252")))) { Assert.AreEqual(3, cfile.Read(buff, 0, 3)); CollectionAssert.AreEqual(new byte[] { 232, 97, 224 }, buff); Assert.AreEqual(3, cfile.Read(buff, 0, 3)); CollectionAssert.AreEqual(new byte[] { 10, 252, 238 }, buff); Assert.AreEqual(0, cfile.Read(buff, 0, 3)); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî"), Encoding.UTF8)) { Assert.AreEqual(3, cfile.Read(buff, 0, 3)); CollectionAssert.AreEqual(new byte[] { 195, 168, 97 }, buff); Assert.AreEqual(3, cfile.Read(buff, 0, 3)); CollectionAssert.AreEqual(new byte[] { 195, 160, 10 }, buff); Assert.AreEqual(3, cfile.Read(buff, 0, 3)); CollectionAssert.AreEqual(new byte[] { 195, 188, 195 }, buff); Assert.AreEqual(1, cfile.Read(buff, 0, 3)); CollectionAssert.AreEqual(new byte[] { 174, 188, 195 }, buff); Assert.AreEqual(0, cfile.Read(buff, 0, 3)); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî", Encoding.GetEncoding("windows-1252")), Encoding.GetEncoding("windows-1252"))) { Assert.AreEqual(3, cfile.Read(buff, 0, 3)); CollectionAssert.AreEqual(new byte[] { 232, 97, 224 }, buff); Assert.AreEqual(3, cfile.Read(buff, 0, 3)); CollectionAssert.AreEqual(new byte[] { 10, 252, 238 }, buff); Assert.AreEqual(0, cfile.Read(buff, 0, 3)); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî", Encoding.UTF8), Encoding.GetEncoding("windows-1252"))) { Assert.AreEqual(3, cfile.Read(buff, 0, 3)); CollectionAssert.AreEqual(new byte[] { 195, 168, 97 }, buff); Assert.AreEqual(3, cfile.Read(buff, 0, 3)); CollectionAssert.AreEqual(new byte[] { 195, 160, 10 }, buff); Assert.AreEqual(3, cfile.Read(buff, 0, 3)); CollectionAssert.AreEqual(new byte[] { 195, 188, 195 }, buff); Assert.AreEqual(1, cfile.Read(buff, 0, 3)); CollectionAssert.AreEqual(new byte[] { 174, 188, 195 }, buff); Assert.AreEqual(0, cfile.Read(buff, 0, 3)); Assert.AreEqual(true, cfile.EOF); } }
public void TestReadInt32s() { using (var cfile = new CFile(BuildStream(new byte[] { 0x12, 0x34, 0x56, 0x78, 0xFE, 0xDC, 0xBA, 0x98 }))) { var vals = cfile.ReadInt32s(4); Assert.AreEqual(2, vals.Length); Assert.AreEqual((int)0x78563412, vals[0]); Assert.AreEqual(0x98BADCFE, (uint)vals[1]); Assert.AreEqual(null, cfile.ReadInt32s(4)); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream(new byte[] { 0x12, 0x34, 0x56, 0x78, 0xFE, 0xDC, 0xBA }))) { var vals = cfile.ReadInt32s(4); Assert.AreEqual(1, vals.Length); Assert.AreEqual((int)0x78563412, vals[0]); Assert.AreEqual(null, cfile.ReadInt32s(4)); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream(new byte[] { 97, 0x12, 0x34, 0x56, 0x78, 0xFE, 0xDC, 0xBA, 0x98 }))) { Assert.AreEqual('a', cfile.ReadChar()); var vals = cfile.ReadInt32s(4); Assert.AreEqual(2, vals.Length); Assert.AreEqual((int)0x78563412, vals[0]); Assert.AreEqual(0x98BADCFE, (uint)vals[1]); Assert.AreEqual(null, cfile.ReadInt32s(4)); Assert.AreEqual(true, cfile.EOF); } }
public void TestReadLineEncoded() { using (var cfile = new CFile(BuildStream("èaà\nüî"))) { Assert.AreEqual("èaà ", cfile.ReadLine()); Assert.AreEqual("üî", cfile.ReadLine()); Assert.AreEqual(null, cfile.ReadLine()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî", Encoding.GetEncoding("windows-1252")))) { Assert.AreEqual("èaà", cfile.ReadLine()); Assert.AreEqual("üî", cfile.ReadLine()); Assert.AreEqual(null, cfile.ReadLine()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî"), Encoding.UTF8)) { Assert.AreEqual("èaà", cfile.ReadLine()); Assert.AreEqual("üî", cfile.ReadLine()); Assert.AreEqual(null, cfile.ReadLine()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî", Encoding.GetEncoding("windows-1252")), Encoding.GetEncoding("windows-1252"))) { Assert.AreEqual("èaà", cfile.ReadLine()); Assert.AreEqual("üî", cfile.ReadLine()); Assert.AreEqual(null, cfile.ReadLine()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî", Encoding.UTF8), Encoding.GetEncoding("windows-1252"))) { Assert.AreEqual("èaà ", cfile.ReadLine()); Assert.AreEqual("üî", cfile.ReadLine()); Assert.AreEqual(null, cfile.ReadLine()); Assert.AreEqual(true, cfile.EOF); } }
public void TestReadUInt32() { using (var cfile = new CFile(BuildStream(new byte[] { 0x12, 0x34, 0x56, 0x78, 0xFE, 0xDC, 0xBA, 0x98 }))) { Assert.AreEqual((uint)0x78563412, cfile.ReadUInt32()); Assert.AreEqual(0x98BADCFE, cfile.ReadUInt32()); Assert.AreEqual((uint)0, cfile.ReadUInt32()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream(new byte[] { 0x12, 0x34, 0x56, 0x78, 0xFE, 0xDC, 0xBA }))) { Assert.AreEqual((uint)0x78563412, cfile.ReadUInt32()); Assert.AreEqual((uint)0, cfile.ReadUInt32()); Assert.AreEqual((uint)0, cfile.ReadUInt32()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream(new byte[] { 97, 0x12, 0x34, 0x56, 0x78, 0xFE, 0xDC, 0xBA, 0x98 }))) { Assert.AreEqual('a', cfile.ReadChar()); Assert.AreEqual((uint)0x78563412, cfile.ReadUInt32()); Assert.AreEqual(0x98BADCFE, cfile.ReadUInt32()); Assert.AreEqual((uint)0, cfile.ReadUInt32()); Assert.AreEqual(true, cfile.EOF); } }
public void TestReadDouble() { using (var cfile = new CFile(BuildStream(new byte[] { 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0xFE, 0xDC, 0xBA, 0x98, 0xFE, 0xDC, 0xBA, 0x98 }))) { Assert.AreEqual(4.69197536052338E+271, cfile.ReadDouble(), 1e+257); Assert.AreEqual(-1.50730608775746E-189, cfile.ReadDouble(), 1e-150); Assert.AreEqual(0, cfile.ReadDouble()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream(new byte[] { 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0xFE, 0xDC, 0xBA, 0x98, 0xFE, 0xDC, 0xBA}))) { Assert.AreEqual(4.69197536052338E+271, cfile.ReadDouble(), 1e+257); Assert.AreEqual(0, cfile.ReadDouble()); Assert.AreEqual(0, cfile.ReadDouble()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream(new byte[] {97, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0xFE, 0xDC, 0xBA, 0x98, 0xFE, 0xDC, 0xBA, 0x98 }))) { Assert.AreEqual('a', cfile.ReadChar()); Assert.AreEqual(4.69197536052338E+271, cfile.ReadDouble(), 1e+257); Assert.AreEqual(-1.50730608775746E-189, cfile.ReadDouble(), 1e-150); Assert.AreEqual(0, cfile.ReadInt32()); Assert.AreEqual(true, cfile.EOF); } }
public void TestReadSByte() { using (var cfile = new CFile(BuildStream("èaà\nüî"))) { Assert.AreEqual(-61, cfile.ReadSByte()); Assert.AreEqual(-88, cfile.ReadSByte()); Assert.AreEqual(97, cfile.ReadSByte()); Assert.AreEqual(-61, cfile.ReadSByte()); Assert.AreEqual(-96, cfile.ReadSByte()); Assert.AreEqual(10, cfile.ReadSByte()); Assert.AreEqual(-61, cfile.ReadSByte()); Assert.AreEqual(-68, cfile.ReadSByte()); Assert.AreEqual(-61, cfile.ReadSByte()); Assert.AreEqual(-82, cfile.ReadSByte()); Assert.AreEqual(0, cfile.ReadSByte()); Assert.AreEqual(0, cfile.ReadSByte()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî", Encoding.GetEncoding("windows-1252")))) { Assert.AreEqual(-24, cfile.ReadSByte()); Assert.AreEqual(97, cfile.ReadSByte()); Assert.AreEqual(-32, cfile.ReadSByte()); Assert.AreEqual(10, cfile.ReadSByte()); Assert.AreEqual(-4, cfile.ReadSByte()); Assert.AreEqual(-18, cfile.ReadSByte()); Assert.AreEqual(0, cfile.ReadSByte()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî"), Encoding.UTF8)) { Assert.AreEqual(-61, cfile.ReadSByte()); Assert.AreEqual(-88, cfile.ReadSByte()); Assert.AreEqual(97, cfile.ReadSByte()); Assert.AreEqual(-61, cfile.ReadSByte()); Assert.AreEqual(-96, cfile.ReadSByte()); Assert.AreEqual(10, cfile.ReadSByte()); Assert.AreEqual(-61, cfile.ReadSByte()); Assert.AreEqual(-68, cfile.ReadSByte()); Assert.AreEqual(-61, cfile.ReadSByte()); Assert.AreEqual(-82, cfile.ReadSByte()); Assert.AreEqual(0, cfile.ReadSByte()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî", Encoding.GetEncoding("windows-1252")), Encoding.GetEncoding("windows-1252"))) { Assert.AreEqual(-24, cfile.ReadSByte()); Assert.AreEqual(97, cfile.ReadSByte()); Assert.AreEqual(-32, cfile.ReadSByte()); Assert.AreEqual(10, cfile.ReadSByte()); Assert.AreEqual(-4, cfile.ReadSByte()); Assert.AreEqual(-18, cfile.ReadSByte()); Assert.AreEqual(0, cfile.ReadSByte()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream("èaà\nüî", Encoding.UTF8), Encoding.GetEncoding("windows-1252"))) { Assert.AreEqual(-61, cfile.ReadSByte()); Assert.AreEqual(-88, cfile.ReadSByte()); Assert.AreEqual(97, cfile.ReadSByte()); Assert.AreEqual(-61, cfile.ReadSByte()); Assert.AreEqual(-96, cfile.ReadSByte()); Assert.AreEqual(10, cfile.ReadSByte()); Assert.AreEqual(-61, cfile.ReadSByte()); Assert.AreEqual(-68, cfile.ReadSByte()); Assert.AreEqual(-61, cfile.ReadSByte()); Assert.AreEqual(-82, cfile.ReadSByte()); Assert.AreEqual(0, cfile.ReadSByte()); Assert.AreEqual(0, cfile.ReadSByte()); Assert.AreEqual(true, cfile.EOF); } using (var cfile = new CFile(BuildStream(new byte[] { 0, 0x01, 0x10, 0x80, 0xF0, 0xFF }))) { Assert.AreEqual(0, cfile.ReadSByte()); Assert.AreEqual(1, cfile.ReadSByte()); Assert.AreEqual(16, cfile.ReadSByte()); Assert.AreEqual(-128, cfile.ReadSByte()); Assert.AreEqual(-16, cfile.ReadSByte()); Assert.AreEqual(-1, cfile.ReadSByte()); Assert.AreEqual(0, cfile.ReadSByte()); Assert.AreEqual(0, cfile.ReadSByte()); Assert.AreEqual(true, cfile.EOF); } }