Exemple #1
0
		static void SensorList (String filename)
		{
			// try to open it for reading...
			Console.Write("Opening "+filename+" data-store for reading...");
			TinyOnDiskStorage data_store = new TinyOnDiskStorage(filename, false,100);
			Console.WriteLine("done");

			Dictionary<String,XS1_DataObject> Sensors = new Dictionary<string, XS1_DataObject>();

			foreach (OnDiscAdress ondisc in data_store.InMemoryIndex)
			{
				XS1_DataObject dataobject = new XS1_DataObject();
                try
                {
                    dataobject.Deserialize(data_store.Read(ondisc));
                    //Console.WriteLine(dataobject.Timecode.ToLongTimeString() + ";" + dataobject.Timecode.ToShortDateString() + ";" + dataobject.Name + ";" + dataobject.Type + ";" + dataobject.TypeName + ";" + dataobject.Value + ";" + dataobject.OriginalXS1Statement);
                    if (!Sensors.ContainsKey(dataobject.Name))
                        Sensors.Add(dataobject.Name, dataobject);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error: "+ondisc.CreationTime+" - "+ ondisc.Start +" - " + e.Message);
                }
			}

			foreach(XS1_DataObject dataobject in Sensors.Values)
			{
				Console.WriteLine(dataobject.Name+";"+dataobject.Type+";"+dataobject.TypeName+";"+dataobject.Value+";"+dataobject.OriginalXS1Statement);
			}

		}
Exemple #2
0
        public void SerializeDeserializeTest()
        {
            XS1_DataObject start = new XS1_DataObject("server","Keller", ObjectTypes.Sensor, "temperature", new DateTime(2010, 12, 18, 17, 37, 31, 0, System.Globalization.Calendar.CurrentEra), 1, 14.8);
            byte[] Serialized;
            XS1_DataObject deserialized;

            Serialized = start.Serialize();

            deserialized = new XS1_DataObject();
            deserialized.Deserialize(Serialized);

            Assert.AreEqual(start.ServerName, deserialized.ServerName);
            Assert.AreEqual(start.Name,             deserialized.Name);
            Assert.AreEqual(start.Timecode.Ticks,   deserialized.Timecode.Ticks);
            Assert.AreEqual(start.Type,             deserialized.Type);
            Assert.AreEqual(start.TypeName,         deserialized.TypeName);
            Assert.AreEqual(start.Value,            deserialized.Value);
            Assert.AreEqual(start.XS1ObjectID,      deserialized.XS1ObjectID);

            start = new XS1_DataObject("server","Keller", ObjectTypes.Actor, "temperature", new DateTime(2010, 12, 18, 17, 37, 31, 0, System.Globalization.Calendar.CurrentEra), 1, 14.8);

            Serialized = start.Serialize();

            deserialized = new XS1_DataObject();
            deserialized.Deserialize(Serialized);

            Assert.AreEqual(start.ServerName, deserialized.ServerName);
            Assert.AreEqual(start.Name, deserialized.Name);
            Assert.AreEqual(start.Timecode.Ticks, deserialized.Timecode.Ticks);
            Assert.AreEqual(start.Type, deserialized.Type);
            Assert.AreEqual(start.TypeName, deserialized.TypeName);
            Assert.AreEqual(start.Value, deserialized.Value);
            Assert.AreEqual(start.XS1ObjectID, deserialized.XS1ObjectID);
        }
Exemple #3
0
		private XS1_DataObject ReadFromCache(OnDiscAdress adress)
		{
			XS1_DataObject dataobject = new XS1_DataObject();

			object cacheditem = sensor_data.Cache.ReadFromCache(adress);
			if (cacheditem == null)
			{
				// not found in cache, read from disk and add to cache
				dataobject.Deserialize(sensor_data.Read(adress));
				sensor_data.Cache.AddToCache(adress,dataobject);
			}
			else
			{
				// found in cache, take it...
				dataobject = (XS1_DataObject)cacheditem;
			}

			return dataobject;
		}
Exemple #4
0
		static void Main(string[] args)
		{
			Console.WriteLine("hacs storage performance tuning project: benchmark");
			Console.WriteLine("(C) 2013 Daniel Kirstenpfad - http://technology-ninja.com");
			Console.WriteLine();

			int number = 100000;
			int cachefactor = 1;
			Stopwatch sw = new Stopwatch();

			#region Generating benchmark data set
			if (Directory.Exists("benchmark-data"))
			{
				Directory.Delete("benchmark-data",true);
				Directory.CreateDirectory("benchmark-data");
			}
			else
				Directory.CreateDirectory("benchmark-data");
			sw.Start();
			TinyOnDiskStorage benchmark_storage = new TinyOnDiskStorage("benchmark-data" + Path.DirectorySeparatorChar + "benchmark-data", false, number/cachefactor);
			sw.Stop();
			Console.WriteLine("Initialized benchmark-data storage in "+sw.ElapsedMilliseconds+" ms");

			sw.Reset();

			Console.Write("Generating data ("+number+") - ");

			int CursorLeft = Console.CursorLeft;
			int CursorTop = Console.CursorTop;

			sw.Start ();
			for (int i=0;i<=number;i++)
			{
				//Console.SetCursorPosition(CursorLeft,CursorTop);
				//Console.Write(i+"/"+number);

				// now generating the file...
				XS1_DataObject data = new XS1_DataObject("ServerName","Name",ObjectTypes.Actor,"TypeName",DateTime.Now,i,i);

				benchmark_storage.Write(data.Serialize());
			}
			sw.Stop();
			Console.WriteLine("done in "+sw.ElapsedMilliseconds+" ms");

			sw.Reset();
			Console.WriteLine("Resetting...");

			benchmark_storage.Shutdown();

			sw.Start();
			benchmark_storage = new TinyOnDiskStorage("benchmark-data" + Path.DirectorySeparatorChar + "benchmark-data", false, number/2);
			sw.Stop();
			Console.WriteLine("Initialized benchmark-data storage in "+sw.ElapsedMilliseconds+" ms");
			sw.Reset();

			Console.Write("Reading ("+number+") - ");
			int o = 0;
			sw.Start();
			foreach(OnDiscAdress addr in benchmark_storage.InMemoryIndex)
			{
				XS1_DataObject data = new XS1_DataObject();
				data.Deserialize(benchmark_storage.Read(addr));
				if (data.XS1ObjectID != o)
					Console.WriteLine(data.Timecode.ToString());
				o++;
			}
			o--;
			sw.Stop();
			Console.WriteLine("done ("+o+") in "+sw.ElapsedMilliseconds+" ms");
			sw.Reset();
			#endregion
		}