public List <int> SmartConstructCurrentPOV(IStream stream, int slotIndex) { List <int> retVal = new List <int>(); IValue val = stream.Get(occupancyKey); if (val != null) { byte[] bytes = val.GetBytes(); var listofPOVs = Enumerable.Range(0, bytes.Length / 4).Select(i => BitConverter.ToInt32(bytes, i * 4)).ToList(); int width = slotIndex % 96; int ndays = slotIndex / 96; retVal = listofPOVs.Skip(ndays * width).Take(width).ToList(); } return(retVal); }
protected Tuple <Byte[], StrValue> UpdateHelper(IKey key, IValue value, bool IsAppend, long timestamp = -1) { if (!value.GetType().Equals(typeof(ByteValue))) { throw new InvalidDataException("Invalid IValue Type. ByteValue expected."); } if (logger != null) { logger.Log("Start FileDataStream Delete Old DataBlock"); } // check if the entry is present, so that the old file can be deleted IValue valueDataFilePathOld = base.Get(key); // remove old entry/file if present and update has been called if (valueDataFilePathOld != null && !IsAppend) { System.IO.FileInfo fi = new System.IO.FileInfo(valueDataFilePathOld.ToString()); try { fi.Delete(); } catch (System.IO.IOException e) { Console.WriteLine(e.Message); } } if (logger != null) { logger.Log("End FileDataStream Delete Old DataBlock"); } if (logger != null) { logger.Log("Start FileDataStream Construct DataBlock"); } long ts; // timestamp ts = StreamFactory.HighResTick(); string dataFilePath = targetDir + "/" + Convert.ToString(ts) + ".dat"; StrValue strDataFilePathValue = new StrValue(Convert.ToString(ts) + ".dat"); if (streamtype == StreamFactory.StreamSecurityType.Secure) { value = new ByteValue(Crypto.EncryptBytesSimple(value.GetBytes(), Crypto.KeyDer(acl_md.encKey), acl_md.IV)); } else { value = new ByteValue(value.GetBytes()); } // if (logger != null) logger.Log("Start FileDataStream Construct DBI"); Byte[] hash; if (streamtype == StreamFactory.StreamSecurityType.Secure) { hash = hasher.ComputeHash(value.GetBytes()); } else { hash = null; } // if (logger != null) logger.Log("End FileDataStream Construct DBI"); if (logger != null) { logger.Log("End FileDataStream Construct DataBlock"); } if (logger != null) { logger.Log("Start FileDataStream Update FilePathValue"); } base.UpdateHelper(key, strDataFilePathValue, IsAppend, hash, timestamp); if (logger != null) { logger.Log("End FileDataStream Update FilePathValue"); } // write <val> to file if (logger != null) { logger.Log("Start FileDataStream WriteToDisc DataBlock"); } FileStream fout = new FileStream(dataFilePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite); fout.Write(value.GetBytes(), 0, (int)value.Size()); fout.Flush(true); fout.Close(); if (logger != null) { logger.Log("End FileDataStream WriteToDisc DataBlock"); } return(new Tuple <byte[], StrValue>(hash, strDataFilePathValue)); }
public void setValue(IValue v) { this.value = v; this.val_bytes = v.GetBytes(); }