public ActionResult <AddReaderResponse> Post(AddReader request) { GXSelectArgs arg = GXSelectArgs.SelectAll <GXReaderInfo>(); arg.Where.And <GXReaderInfo>(q => q.Guid == request.Reader.Guid); GXReaderInfo i = host.Connection.SingleOrDefault <GXReaderInfo>(arg); if (i == null) { request.Reader.Detected = request.Reader.Generation = DateTime.Now; host.Connection.Insert(GXInsertArgs.Insert(request.Reader)); } else if (i.Name != request.Reader.Name && !string.IsNullOrEmpty(request.Reader.Name)) { //Update reader name. i.Detected = DateTime.Now; host.Connection.Update(GXUpdateArgs.Update(i, u => new { u.Detected, u.Name })); } else { i.Detected = DateTime.Now; host.Connection.Update(GXUpdateArgs.Update(i, u => u.Detected)); } host.SetChange(TargetType.Readers, DateTime.Now); return(new AddReaderResponse()); }
public void ExcludeSelectTest() { GXSelectArgs args = GXSelectArgs.SelectAll <TestClass>(); args.Columns.Exclude <TestClass>(x => new { x.Id, x.Time, x.Text, x.Text2, x.Text3, x.Text4, x.BooleanTest, x.IntTest, x.DoubleTest, x.FloatTest, x.Span, x.Object, x.Status }); Assert.AreEqual("SELECT `Guid` FROM TestClass", args.ToString()); }
public void LeftJoinTest() { GXSelectArgs arg = GXSelectArgs.SelectAll <TestClass>(); arg.Columns.Add <TestClass2>(); arg.Joins.AddLeftJoin <TestClass2, TestClass>(x => x.Parent, x => x.Id); Assert.AreEqual("SELECT TestClass.`ID`, TestClass.`Guid`, TestClass.`Time`, TestClass.`Text`, TestClass.`SimpleText`, TestClass.`Text3`, TestClass.`Text4`, TestClass.`BooleanTest`, TestClass.`IntTest`, TestClass.`DoubleTest`, TestClass.`FloatTest`, TestClass.`Span`, TestClass.`Object`, TestClass.`Status`, TestClass2.`Id`, TestClass2.`ParentID`, TestClass2.`Name` FROM TestClass2 LEFT OUTER JOIN TestClass ON TestClass2.`ParentID`=TestClass.`ID`", arg.ToString()); }
public ActionResult <ListSystemErrorsResponse> Post(ListSystemErrors request) { ListSystemErrorsResponse ret = new ListSystemErrorsResponse(); GXSelectArgs arg = GXSelectArgs.SelectAll <GXSystemError>(); ret.Errors = host.Connection.Select <GXSystemError>(arg).ToArray(); return(ret); }
public ActionResult <ListDeviceTemplatesResponse> Post(ListDeviceTemplates request) { ListDeviceTemplatesResponse ret = new ListDeviceTemplatesResponse(); GXSelectArgs arg = GXSelectArgs.SelectAll <GXDeviceTemplate>(); arg.Where.And <GXDeviceTemplate>(q => q.Removed == DateTime.MinValue); if (!string.IsNullOrEmpty(request.Name)) { string name = request.Name; arg.Where.And <GXDeviceTemplate>(q => q.Name.Contains(name)); } else if (request.Ids != null) { arg.Where.And <GXDeviceTemplate>(q => request.Ids.Contains(q.Id)); } /* * if ((request.Targets & TargetType.AttributeTemplate) != 0) * { * arg.Columns.Add<GXObjectTemplate>(); * arg.Columns.Add<GXAttributeTemplate>(); * * arg.Joins.AddLeftJoin<GXDeviceTemplate, GXObjectTemplate>(d => d.Id, o => o.DeviceTemplateId); * arg.Joins.AddLeftJoin<GXObjectTemplate, GXAttributeTemplate>(o => o.Id, a => a.ObjectTemplateId); * arg.Where.And<GXObjectTemplate>(q => q.Removed == DateTime.MinValue); * arg.Where.And<GXAttributeTemplate>(q => q.Removed == DateTime.MinValue); * } * else if ((request.Targets & TargetType.ObjectTemplate) != 0) * { * arg.Columns.Add<GXObjectTemplate>(); * arg.Joins.AddLeftJoin<GXDeviceTemplate, GXObjectTemplate>(d => d.Id, o => o.DeviceTemplateId); * arg.Where.And<GXObjectTemplate>(q => q.Removed == DateTime.MinValue); * } */ ret.Devices = host.Connection.Select <GXDeviceTemplate>(arg).ToArray(); if ((request.Targets & TargetType.AttributeTemplate) != 0) { foreach (GXDeviceTemplate it in ret.Devices) { arg = GXSelectArgs.SelectAll <GXObjectTemplate>(); arg.Where.And <GXObjectTemplate>(q => q.DeviceTemplateId == it.Id); arg.Where.And <GXObjectTemplate>(q => q.Removed == DateTime.MinValue); it.Objects = host.Connection.Select <GXObjectTemplate>(arg); if (it.Objects != null && (request.Targets & TargetType.ObjectTemplate) != 0) { foreach (GXObjectTemplate o in it.Objects) { arg = GXSelectArgs.SelectAll <GXAttributeTemplate>(); arg.Where.And <GXAttributeTemplate>(q => q.ObjectTemplateId == o.Id); arg.Where.And <GXAttributeTemplate>(q => q.Removed == DateTime.MinValue); o.Attributes = host.Connection.Select <GXAttributeTemplate>(arg); } } } } return(ret); }
public ActionResult <GetNextTaskResponse> Post(GetNextTask request) { GetNextTaskResponse ret = new GetNextTaskResponse(); lock (host) { GXSelectArgs arg = GXSelectArgs.Select <GXTask>(c => c.Id, q => q.Start == DateTime.MinValue); arg.Joins.AddInnerJoin <GXTask, GXObject>(a => a.Object, b => b.Id); arg.Joins.AddInnerJoin <GXObject, GXDevice>(a => a.DeviceId, b => b.Id); //Don't get meters that are mapped to other readers. arg.Joins.AddLeftJoin <GXDevice, GXDeviceToReader>(a => a.Id, b => b.DeviceId); if (request.DeviceId != 0) { arg.Where.And <GXDevice>(q => q.Id == request.DeviceId); } if (!request.Listener) { arg.Where.And <GXDevice>(q => q.Dynamic == false); } arg.OrderBy.Add <GXTask>(q => q.Id); GXSelectArgs onProgress = GXSelectArgs.Select <GXObject>(c => c.DeviceId, q => q.Removed == DateTime.MinValue); onProgress.Joins.AddInnerJoin <GXTask, GXObject>(a => a.Object, b => b.Id); onProgress.Where.And <GXTask>(q => q.Start != DateTime.MinValue && q.End == DateTime.MinValue); arg.Where.And <GXObject>(q => !GXSql.Exists <GXObject, GXDevice>(a => a.DeviceId, b => b.Id, onProgress)); GXTask task = host.Connection.SingleOrDefault <GXTask>(arg); if (task != null) { //Get task device ID and creation time. arg = GXSelectArgs.SelectAll <GXTask>(q => q.Id == task.Id); arg.Columns.Add <GXObject>(); arg.Joins.AddInnerJoin <GXTask, GXObject>(a => a.Object, b => b.Id); arg.Joins.AddInnerJoin <GXObject, GXDevice>(a => a.DeviceId, b => b.Id); task = host.Connection.SingleOrDefault <GXTask>(arg); //Get all tasks that are created at the same time for same meter. arg = GXSelectArgs.SelectAll <GXTask>(q => q.Generation == task.Generation); arg.Where.And <GXDevice>(q => q.Id == task.Object.DeviceId); arg.Where.And <GXObject>(q => q.Removed == DateTime.MinValue); arg.Columns.Add <GXObject>(); arg.Columns.Add <GXDevice>(); arg.Columns.Add <GXAttribute>(); arg.Joins.AddInnerJoin <GXTask, GXObject>(a => a.Object, b => b.Id); arg.Joins.AddInnerJoin <GXObject, GXDevice>(a => a.DeviceId, b => b.Id); arg.Joins.AddInnerJoin <GXObject, GXAttribute>(a => a.Id, b => b.ObjectId); ret.Tasks = host.Connection.Select <GXTask>(arg).ToArray(); DateTime now = DateTime.Now; foreach (GXTask it in ret.Tasks) { it.Start = now; host.Connection.Update(GXUpdateArgs.Update(it, q => q.Start)); } host.SetChange(TargetType.Tasks, DateTime.Now); } } return(ret); }
public ActionResult <ReaderDeviceResponse> GetMeters(ReaderDevices request) { GXSelectArgs arg = GXSelectArgs.SelectAll <GXDevice>(); arg.Joins.AddInnerJoin <GXDevice, GXDeviceToReader>(d => d.Id, i => i.DeviceId); arg.Where.And <GXDeviceToReader>(q => request.Ids.Contains(q.ReaderId)); ReaderDeviceResponse ret = new ReaderDeviceResponse(); ret.Devices = host.Connection.Select <GXDevice>(arg).ToArray(); return(ret); }
public ActionResult <ListReadersResponse> Post(ListReaders request) { ListReadersResponse ret = new ListReadersResponse(); GXSelectArgs arg = GXSelectArgs.SelectAll <GXReaderInfo>(); if (request.Ids != null && request.Ids.Length != 0) { arg.Where.And <GXReaderInfo>(q => request.Ids.Contains(q.Id)); } ret.Readers = host.Connection.Select <GXReaderInfo>(arg).ToArray(); return(ret); }
public void MikkoTest() { GXWorkflow workflow = new GXWorkflow(); workflow.Id = Guid.Parse("17f9f275-7dba-44a8-b9c5-5c404283cf7e"); GXSelectArgs arg = GXSelectArgs.SelectAll <GXJob>(q => q.Workflow == workflow && q.Removed == null); arg.Columns.Add <GXModule>(); arg.Columns.Exclude <GXModule>(e => e.Jobs); arg.Joins.AddLeftJoin <GXModule, GXJob>(j => j.Id, j => j.Module); Assert.AreEqual("Mikko", arg.ToString()); }
public ActionResult <ListValuesResponse> Post(ListValues request) { ListValuesResponse ret = new ListValuesResponse(); GXSelectArgs arg = GXSelectArgs.SelectAll <GXValue>(); if (request.Ids != null && request.Ids.Length != 0) { arg.Where.And <GXValue>(q => request.Ids.Contains(q.AttributeId)); } ret.Items = host.Connection.Select <GXValue>(arg).ToArray(); return(ret); }
public ActionResult <ListDeviceLogResponse> Post(ListDeviceLog request) { ListDeviceLogResponse ret = new ListDeviceLogResponse(); GXSelectArgs arg = GXSelectArgs.SelectAll <GXDeviceLog>(); arg.Count = (UInt32)request.Count; arg.Descending = true; arg.Where.And <GXDeviceLog>(q => request.Ids.Contains(q.Id)); arg.OrderBy.Add <GXDeviceLog>(q => q.Id); arg.OrderBy.Add <GXDeviceLog>(q => q.Generation); ret.Logs = host.Connection.Select <GXDeviceLog>(arg).ToArray(); return(ret); }
public void NotExistsTest() { GXSelectArgs arg2 = GXSelectArgs.Select <Company>(q => q.Id); arg2.Where.And <Company>(q => q.Name.Equals("Gurux")); GXSelectArgs arg = GXSelectArgs.SelectAll <Country>(); arg.Where.And <Country>(q => !GXSql.Exists <Company, Country>(a => a.Country, b => b.Id, arg2)); string expected = "SELECT `ID`, `CountryName` FROM Country WHERE NOT EXISTS (SELECT `Id` FROM Company WHERE UPPER(Company.`Name`) LIKE('GURUX') AND Country.`ID` = Company.`CountryID`)"; string actual = arg.ToString(); Assert.AreEqual(expected, actual); }
public ActionResult <ListSchedulesResponse> Post(ListSchedules request) { ListSchedulesResponse ret = new ListSchedulesResponse(); GXSelectArgs arg = GXSelectArgs.SelectAll <GXSchedule>(); arg.Distinct = true; arg.Where.And <GXSchedule>(q => q.Removed == DateTime.MinValue); if (request.ObjectId != 0) { arg.Joins.AddInnerJoin <GXSchedule, GXScheduleToAttribute>(s => s.Id, o => o.ScheduleId); arg.Joins.AddInnerJoin <GXScheduleToAttribute, GXAttribute>(s => s.AttributeId, o => o.Id); arg.Where.And <GXAttribute>(q => q.ObjectId == request.ObjectId); } else if (request.DeviceId != 0) { arg.Joins.AddInnerJoin <GXSchedule, GXScheduleToAttribute>(s => s.Id, o => o.ScheduleId); arg.Joins.AddInnerJoin <GXScheduleToAttribute, GXAttribute>(s => s.AttributeId, o => o.Id); arg.Joins.AddInnerJoin <GXAttribute, GXObject>(s => s.ObjectId, o => o.Id); arg.Where.And <GXObject>(q => q.DeviceId == request.DeviceId); } /* * if ((request.Targets & TargetType.Attribute) != 0) * { * arg.Columns.Add<GXObject>(); * arg.Columns.Add<GXScheduleToAttribute>(); * arg.Joins.AddLeftJoin<GXSchedule, GXScheduleToAttribute>(s => s.Id, o => o.ScheduleId); * arg.Joins.AddLeftJoin<GXScheduleToAttribute, GXAttribute>(s => s.AttributeId, o => o.Id); * arg.Joins.AddInnerJoin<GXAttribute, GXObject>(s => s.ObjectId, o => o.Id); * arg.Where.And<GXObject>(q => q.Removed == DateTime.MinValue); * arg.Where.And<GXAttribute>(q => q.Removed == DateTime.MinValue); * } */ ret.Schedules = host.Connection.Select <GXSchedule>(arg).ToArray(); foreach (GXSchedule it in ret.Schedules) { arg = GXSelectArgs.SelectAll <GXObject>(); arg.Columns.Add <GXAttribute>(); arg.Distinct = true; arg.Joins.AddInnerJoin <GXSchedule, GXScheduleToAttribute>(s => s.Id, o => o.ScheduleId); arg.Joins.AddInnerJoin <GXScheduleToAttribute, GXAttribute>(s => s.AttributeId, o => o.Id); arg.Joins.AddInnerJoin <GXAttribute, GXObject>(s => s.ObjectId, o => o.Id); arg.Where.And <GXObject>(q => q.Removed == DateTime.MinValue); arg.Where.And <GXAttribute>(q => q.Removed == DateTime.MinValue); arg.Where.And <GXSchedule>(q => q.Id == it.Id); it.Objects = host.Connection.Select <GXObject>(arg); } return(ret); }
public void WhereStringIsNullTest() { string expected = "WHERE TestClass.`Text` IS NULL"; string text = null; GXSelectArgs args = GXSelectArgs.SelectAll <TestClass>(q => q.Text == text); string actual = args.Where.ToString(); Assert.AreEqual(expected, actual); args = GXSelectArgs.SelectAll <TestClass>(q => q.Text.Equals(text)); actual = args.Where.ToString(); Assert.AreEqual(expected, actual); expected = "WHERE (TestClass.`Text` IS NULL OR TestClass.`Text` = '')"; args = GXSelectArgs.SelectAll <TestClass>(q => string.IsNullOrEmpty(q.Text)); actual = args.Where.ToString(); Assert.AreEqual(expected, actual); }
public ActionResult <ListDevicesResponse> Post(ListDevices request) { ListDevicesResponse ret = new ListDevicesResponse(); GXSelectArgs arg = GXSelectArgs.SelectAll <GXDevice>(); arg.Where.And <GXDevice>(q => q.Removed == DateTime.MinValue); if ((request.Targets & TargetType.Attribute) != 0) { arg.Columns.Add <GXObject>(); arg.Columns.Add <GXAttribute>(); arg.Joins.AddLeftJoin <GXDevice, GXObject>(d => d.Id, o => o.DeviceId); arg.Joins.AddLeftJoin <GXObject, GXAttribute>(o => o.Id, a => a.ObjectId); arg.Where.And <GXObject>(q => q.Removed == DateTime.MinValue); arg.Where.And <GXAttribute>(q => q.Removed == DateTime.MinValue); } else if ((request.Targets & TargetType.Object) != 0) { arg.Columns.Add <GXObject>(); arg.Joins.AddLeftJoin <GXDevice, GXObject>(d => d.Id, o => o.DeviceId); arg.Where.And <GXObject>(q => q.Removed == DateTime.MinValue); } byte[] st = GXCommon.HexToBytes(request.SystemTitle); if (st.Length == 8) { string str = GXCommon.ToHex(st, false); arg.Where.And <GXDevice>(q => q.DeviceSystemTitle.Equals(str)); } else if (!string.IsNullOrEmpty(request.Name)) { string name = request.Name; arg.Where.And <GXDevice>(q => q.Name.Contains(name)); } else if (request.Ids != null) { arg.Where.And <GXDevice>(q => request.Ids.Contains(q.Id)); } ret.Devices = host.Connection.Select <GXDevice>(arg).ToArray(); return(ret); }
public ActionResult <ListTasksResponse> Post(ListTasks request) { ListTasksResponse ret = new ListTasksResponse(); GXSelectArgs arg = GXSelectArgs.SelectAll <GXTask>(); arg.Count = (UInt32)request.Count; arg.Descending = true; if (request.AttributeId != 0) { arg.Columns.Add <GXDevice>(); arg.Columns.Add <GXObject>(); arg.Columns.Add <GXAttribute>(); arg.Joins.AddInnerJoin <GXTask, GXObject>(a => a.Object, b => b.Id); arg.Joins.AddInnerJoin <GXObject, GXDevice>(a => a.DeviceId, b => b.Id); arg.Joins.AddInnerJoin <GXObject, GXAttribute>(a => a.Id, b => b.ObjectId); arg.Where.And <GXAttribute>(q => q.Id == request.AttributeId); } else if (request.ObjectId != 0) { arg.Columns.Add <GXDevice>(); arg.Columns.Add <GXObject>(); arg.Columns.Add <GXAttribute>(); arg.Joins.AddInnerJoin <GXTask, GXObject>(a => a.Object, b => b.Id); arg.Joins.AddInnerJoin <GXObject, GXDevice>(a => a.DeviceId, b => b.Id); arg.Where.And <GXObject>(q => q.Id == request.ObjectId); } else if (request.DeviceId != 0) { arg.Columns.Add <GXDevice>(); arg.Columns.Add <GXObject>(); arg.Columns.Add <GXAttribute>(); arg.Joins.AddInnerJoin <GXTask, GXObject>(a => a.Object, b => b.Id); arg.Joins.AddInnerJoin <GXObject, GXDevice>(a => a.DeviceId, b => b.Id); arg.Joins.AddInnerJoin <GXObject, GXAttribute>(a => a.Id, b => b.ObjectId); arg.Where.And <GXObject>(q => q.DeviceId == request.DeviceId); } else if ((request.Targets & TargetType.Attribute) != 0) { arg.Columns.Add <GXDevice>(); arg.Columns.Add <GXObject>(); arg.Columns.Add <GXAttribute>(); arg.Joins.AddInnerJoin <GXTask, GXObject>(a => a.Object, b => b.Id); arg.Joins.AddInnerJoin <GXObject, GXDevice>(a => a.DeviceId, b => b.Id); arg.Joins.AddInnerJoin <GXObject, GXAttribute>(a => a.Id, b => b.ObjectId); } else if ((request.Targets & TargetType.Object) != 0) { arg.Columns.Add <GXDevice>(); arg.Columns.Add <GXObject>(); arg.Joins.AddInnerJoin <GXTask, GXObject>(a => a.Object.Id, b => b.Id); arg.Joins.AddInnerJoin <GXObject, GXDevice>(a => a.DeviceId, b => b.Id); } else if ((request.Targets & TargetType.Device) != 0) { arg.Columns.Add <GXDevice>(); arg.Joins.AddInnerJoin <GXTask, GXObject>(a => a.Object.Id, b => b.Id); arg.Joins.AddInnerJoin <GXObject, GXDevice>(a => a.DeviceId, b => b.Id); } arg.OrderBy.Add <GXTask>(q => q.Id); ret.Tasks = host.Connection.Select <GXTask>(arg).ToArray(); return(ret); }
public void WhereExactString() { GXSelectArgs arg = GXSelectArgs.SelectAll <TestIDClass>(q => q.Text == "Gurux"); Assert.AreEqual("SELECT `ID`, `Text` FROM TestIDClass WHERE TestIDClass.`Text` = 'Gurux'", arg.ToString()); }
public void Mikko2Test() { GXSelectArgs arg = GXSelectArgs.SelectAll <GXScript>(q => q.Removed == null); Assert.AreEqual("Mikko", arg.ToString()); }
public void SelectTest() { GXSelectArgs arg = GXSelectArgs.SelectAll <TestClass>(); Assert.AreEqual("SELECT `ID`, `Guid`, `Time`, `Text`, `SimpleText`, `Text3`, `Text4`, `BooleanTest`, `IntTest`, `DoubleTest`, `FloatTest`, `Span`, `Object`, `Status` FROM TestClass", arg.ToString()); }
public ActionResult <AddTestDeviceResponse> Post(AddTestDevice request) { if (request.Device.TemplateId == 0) { return(BadRequest("Device template ID is unknown.")); } if (request.Device.DeviceSystemTitle != null) { request.Device.DeviceSystemTitle = request.Device.DeviceSystemTitle.Replace(" ", ""); } if (request.Device.AuthenticationKey != null) { request.Device.AuthenticationKey = request.Device.AuthenticationKey.Replace(" ", ""); } if (request.Device.BlockCipherKey != null) { request.Device.BlockCipherKey = request.Device.BlockCipherKey.Replace(" ", ""); } DateTime now = DateTime.Now; //Add new DC. request.Device.Generation = now; //We are accessing meters using serial number when test mode is used. request.Device.HDLCAddressing = ManufacturerSettings.HDLCAddressType.SerialNumber; request.Device.LogicalAddress = request.Index; for (UInt16 pos = 0; pos != request.Count; ++pos) { request.Device.Objects = null; request.Device.Name = "Test_" + request.Device.LogicalAddress; ++request.Device.LogicalAddress; request.Device.Id = 0; host.Connection.Insert(GXInsertArgs.Insert(request.Device)); //Add default objects. GXSelectArgs arg = GXSelectArgs.SelectAll <GXObjectTemplate>(q => q.DeviceTemplateId == request.Device.TemplateId); arg.Columns.Add <GXAttributeTemplate>(); arg.Joins.AddLeftJoin <GXObjectTemplate, GXAttributeTemplate>(o => o.Id, a => a.ObjectTemplateId); List <GXObjectTemplate> l = host.Connection.Select <GXObjectTemplate>(arg); foreach (GXObjectTemplate it in l) { GXObject obj = new GXObject() { TemplateId = it.Id, Generation = now, DeviceId = request.Device.Id, ObjectType = it.ObjectType, Name = it.Name, LogicalName = it.LogicalName, ShortName = it.ShortName, }; host.Connection.Insert(GXInsertArgs.Insert(obj)); foreach (GXAttributeTemplate ait in it.Attributes) { GXAttribute a = new GXAttribute(); a.ObjectId = obj.Id; a.Index = ait.Index; a.TemplateId = ait.Id; a.AccessLevel = ait.AccessLevel; a.DataType = ait.DataType; a.UIDataType = ait.UIDataType; a.Generation = now; a.ExpirationTime = ait.ExpirationTime; obj.Attributes.Add(a); } ; host.Connection.Insert(GXInsertArgs.InsertRange(obj.Attributes)); } } host.SetChange(TargetType.Device, DateTime.Now); return(new AddTestDeviceResponse()); }
public ActionResult <UpdateDeviceResponse> Post(UpdateDevice request) { if (request.Device.TemplateId == 0) { return(BadRequest("Device template ID is unknown.")); } bool newDevice = request.Device.Id == 0; if (request.Device.DeviceSystemTitle != null) { request.Device.DeviceSystemTitle = request.Device.DeviceSystemTitle.Replace(" ", ""); } if (request.Device.AuthenticationKey != null) { request.Device.AuthenticationKey = request.Device.AuthenticationKey.Replace(" ", ""); } if (request.Device.BlockCipherKey != null) { request.Device.BlockCipherKey = request.Device.BlockCipherKey.Replace(" ", ""); } if (newDevice) { DateTime now = DateTime.Now; request.Device.Generation = now; //Add new DC. List <GXObject> tmp = request.Device.Objects; request.Device.Objects = null; request.Device.Generation = now; host.Connection.Insert(GXInsertArgs.Insert(request.Device)); //Add default objects. GXSelectArgs arg = GXSelectArgs.SelectAll <GXObjectTemplate>(q => q.DeviceTemplateId == request.Device.TemplateId && q.Removed == DateTime.MinValue); arg.Columns.Add <GXAttributeTemplate>(); arg.Joins.AddLeftJoin <GXObjectTemplate, GXAttributeTemplate>(o => o.Id, a => a.ObjectTemplateId); arg.Where.And <GXAttributeTemplate>(q => q.Removed == DateTime.MinValue); List <GXObjectTemplate> l = host.Connection.Select <GXObjectTemplate>(arg); foreach (GXObjectTemplate it in l) { GXObject obj = new GXObject() { TemplateId = it.Id, Generation = now, DeviceId = request.Device.Id, ObjectType = it.ObjectType, Name = it.Name, LogicalName = it.LogicalName, ShortName = it.ShortName, }; host.Connection.Insert(GXInsertArgs.Insert(obj)); foreach (GXAttributeTemplate ait in it.Attributes) { GXAttribute a = new GXAttribute(); a.ObjectId = obj.Id; a.Index = ait.Index; a.TemplateId = ait.Id; a.AccessLevel = ait.AccessLevel; a.DataType = ait.DataType; a.UIDataType = ait.UIDataType; a.Generation = now; a.ExpirationTime = ait.ExpirationTime; obj.Attributes.Add(a); } ; host.Connection.Insert(GXInsertArgs.InsertRange(obj.Attributes)); } host.SetChange(TargetType.ObjectTemplate, DateTime.Now); } else { request.Device.Updated = DateTime.Now; host.Connection.Update(GXUpdateArgs.Update(request.Device)); host.SetChange(TargetType.DeviceTemplate, DateTime.Now); } return(new UpdateDeviceResponse() { DeviceId = request.Device.Id }); }
public ActionResult <ListObjectsResponse> Post(ListObjects request) { ListObjectsResponse ret = new ListObjectsResponse(); GXSelectArgs arg = GXSelectArgs.Select <GXObject>(null); arg.Columns.Add <GXAttribute>(); arg.Joins.AddInnerJoin <GXObject, GXAttribute>(a => a.Id, b => b.ObjectId); if (request.Objects != null) { List <int> indexes = new List <int>(); foreach (GXObject it in request.Objects) { if (it.Id != 0) { arg.Where.And <GXObject>(q => q.Id == it.Id); } else if (it.ObjectType != 0 && !string.IsNullOrEmpty(it.LogicalName)) { if (it.Attributes != null) { foreach (GXAttribute a in it.Attributes) { if (a.Index != 0) { indexes.Add(a.Index); } } } arg.Where.Or <GXObject>(q => q.Removed == DateTime.MinValue && q.ObjectType == it.ObjectType && q.LogicalName.Equals(it.LogicalName)); } } arg.Where.And <GXAttribute>(q => q.Removed == DateTime.MinValue); GXSelectArgs devices = GXSelectArgs.Select <GXObject>(q => q.DeviceId); if (request.DeviceId != 0) { devices.Where.And <GXObject>(q => q.DeviceId == request.DeviceId); } arg.Where.And <GXObject>(q => GXSql.In(q.DeviceId, devices)); ret.Items = host.Connection.Select <GXObject>(arg).ToArray(); //Delete Removed attributes. foreach (GXObject o in ret.Items) { List <GXAttribute> list = new List <GXAttribute>(); for (int pos = 0; pos < o.Attributes.Count; ++pos) { if (o.Attributes[pos].Removed != DateTime.MinValue || (indexes.Count != 0 && !indexes.Contains(o.Attributes[pos].Index))) { o.Attributes.RemoveAt(pos); --pos; } } } } else if (request.DeviceId != 0) { arg.Where.And <GXObject>(q => q.DeviceId == request.DeviceId); arg.Where.And <GXAttribute>(q => q.Removed == DateTime.MinValue); if ((request.Targets & TargetType.Attribute) != 0) { if (request.Index == 0 && request.Count == 0 && request.Start == DateTime.MinValue && request.End == DateTime.MinValue) { arg.Columns.Add <GXValue>(); arg.Joins.AddLeftJoin <GXAttribute, GXValue>(a => a.Id, v => v.AttributeId); } } ret.Items = host.Connection.Select <GXObject>(arg).ToArray(); } foreach (GXObject obj in ret.Items) { if (obj.ObjectType == (int)ObjectType.ProfileGeneric) { foreach (GXAttribute a in obj.Attributes) { if (a.Index == 2) { arg = GXSelectArgs.SelectAll <GXValue>(); arg.Where.And <GXValue>(q => q.AttributeId == a.Id); if (request.Index != 0) { arg.Index = (UInt32)(request.Index - 1); } arg.Count = (UInt32)request.Count; if (request.Start != DateTime.MinValue) { arg.Where.And <GXValue>(q => q.Read >= request.Start); } if (request.End != DateTime.MinValue) { arg.Where.And <GXValue>(q => q.Read <= request.End); } arg.OrderBy.Add <GXValue>(o => o.Read); List <GXValue> values = host.Connection.Select <GXValue>(arg); StringBuilder sb = new StringBuilder(); sb.Append("<Array>"); foreach (GXValue v in values) { sb.Append(v.Value); } sb.Append("</Array>"); a.Value = sb.ToString(); } } } } return(ret); }