本文整理汇总了C#中zvs.DataModel.ZvsContext类的典型用法代码示例。如果您正苦于以下问题:C# ZvsContext类的具体用法?C# ZvsContext怎么用?C# ZvsContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ZvsContext类属于zvs.DataModel命名空间,在下文中一共展示了ZvsContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ExecuteDeviceCommandAsync
internal async Task<Result> ExecuteDeviceCommandAsync(DeviceCommand command, string argument, string argument2, CancellationToken cancellationToken)
{
using (var context = new ZvsContext(EntityContextConnection))
{
var deviceCommand = await context.DeviceCommands
.Include(o => o.Device)
.Include(o => o.Device.Type)
.Include(o => o.Device.Type.Adapter)
.FirstOrDefaultAsync(o => o.Id == command.Id, cancellationToken);
if (deviceCommand == null)
return Result.ReportErrorFormat("Cannot locate device command with id of {0}", command.Id);
var commandAction = string.Format("{0}{1} ({3}) on {2} ({4})",
deviceCommand.Name,
string.IsNullOrEmpty(argument) ? "" : " " + argument,
deviceCommand.Device.Name, deviceCommand.Id, deviceCommand.Device.Id);
var aGuid = deviceCommand.Device.Type.Adapter.AdapterGuid;
var adapter = AdapterManager.FindZvsAdapter(aGuid);
if (adapter == null)
{
return Result.ReportErrorFormat("{0} failed, device adapter is not loaded!",
commandAction);
}
if (!adapter.IsEnabled)
return Result.ReportErrorFormat("{0} failed because the '{1}' adapter is disabled",
commandAction,
deviceCommand.Device.Type.Adapter.Name);
await adapter.ProcessDeviceCommandAsync(deviceCommand.Device, deviceCommand, argument, argument2);
return Result.ReportSuccessFormat("{0} complete", commandAction);
}
}
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:35,代码来源:CommandProcessor.cs
示例2: SignalExternalCommandLineArgs
public async Task<bool> SignalExternalCommandLineArgs(IList<string> args)
{
if (args == null || args.Count == 0)
return true;
if ((args.Count <= 2)) return true;
//the first index always contains the location of the exe so we need to check the second index
if ((args[1].ToLowerInvariant() != "-startscene")) return true;
var searchQuery = args[2].ToLower();
using (var context = new ZvsContext(EntityContextConnection))
{
Scene scene;
int sceneId;
if (int.TryParse(searchQuery, out sceneId))
scene = await context.Scenes.FirstOrDefaultAsync(s => s.Id == sceneId);
else scene = await context.Scenes.FirstOrDefaultAsync(s => s.Name.ToLower().Equals(searchQuery));
if (scene != null)
{
var cmd = await context.BuiltinCommands.FirstOrDefaultAsync(c => c.UniqueIdentifier == "RUN_SCENE");
if (cmd == null) return true;
await ZvsEngine.RunCommandAsync(cmd.Id, scene.Id.ToString(CultureInfo.InvariantCulture), string.Empty, Cts.Token);
}
else
await Log.ReportInfoFormatAsync(Cts.Token, "Cannot find scene '{0}'", searchQuery);
}
return true;
}
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:29,代码来源:App.xaml.cs
示例3: ExecuteDeviceTypeCommandAsync
internal async Task<Result> ExecuteDeviceTypeCommandAsync(DeviceTypeCommand command, string argument, string argument2, CancellationToken cancellationToken)
{
using (var context = new ZvsContext(EntityContextConnection))
{
int dId = int.TryParse(argument2, out dId) ? dId : 0;
var device = await context.Devices
.Include(o => o.Type)
.Include(o => o.Type.Adapter)
.FirstOrDefaultAsync(o => o.Id == dId, cancellationToken);
if (device == null)
return Result.ReportErrorFormat("Cannot find device with id of {0}", dId);
var commandAction =
$"{command.Name}{(string.IsNullOrEmpty(argument) ? "" : " " + argument)} {device.Name}";
var aGuid = device.Type.Adapter.AdapterGuid;
var adapter = AdapterManager.FindZvsAdapter(aGuid);
if (adapter == null)
{
return Result.ReportErrorFormat("{0} failed, device adapter is not loaded!",
commandAction);
}
if (!adapter.IsEnabled)
return Result.ReportErrorFormat("{0} failed because the {1} adapter is {2}",
commandAction,
device.Type.Adapter.Name,
adapter.IsEnabled ? "not ready" : "disabled");
await adapter.ProcessDeviceTypeCommandAsync(device.Type, device, command, argument);
return Result.ReportSuccessFormat("{0} complete", commandAction);
}
}
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:35,代码来源:CommandProcessor.cs
示例4: TryAddOrEditAsync
public static async Task<Result> TryAddOrEditAsync(ZvsContext context, ProgramOption programOption, CancellationToken cancellationToken)
{
if (programOption == null)
throw new ArgumentNullException("programOption");
var existingOption = await context.ProgramOptions.FirstOrDefaultAsync(o => o.UniqueIdentifier == programOption.UniqueIdentifier, cancellationToken);
var changed = false;
if (existingOption == null)
{
context.ProgramOptions.Add(programOption);
changed = true;
}
else
{
if (existingOption.Value != programOption.Value)
{
changed = true;
existingOption.Value = programOption.Value;
}
}
if (changed)
return await context.TrySaveChangesAsync(cancellationToken);
return Result.ReportSuccess();
}
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:28,代码来源:ProgramOption.cs
示例5: RegisterAsyncNewTest
public async Task RegisterAsyncNewTest()
{
//arrange
var dbConnection = new UnitTestDbConnection();
Database.SetInitializer(new CreateFreshDbInitializer());
var bcb = new BuiltinCommandBuilder(dbConnection);
var builtinCommand = new BuiltinCommand
{
Name = "Unit Test Builtin Command",
UniqueIdentifier = "BUILTIN_COMMAND1"
};
//act
var result = await bcb.RegisterAsync(builtinCommand, CancellationToken.None);
BuiltinCommand setting;
using (var context = new ZvsContext(dbConnection))
{
setting =
await
context.BuiltinCommands.FirstOrDefaultAsync(
o => o.UniqueIdentifier == builtinCommand.UniqueIdentifier);
}
//assert
Console.WriteLine(result.Message);
Assert.IsFalse(result.HasError, result.Message);
Assert.IsNotNull(setting, "Expected new builtin command setting saved to DB");
}
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:31,代码来源:BuiltinCommandBuilderTests.cs
示例6: RegisterAsyncNewDeviceValueTest
public async Task RegisterAsyncNewDeviceValueTest()
{
//arrange
var dbConnection = new StubIEntityContextConnection { NameOrConnectionStringGet = () => "dvb-RegisterAsyncNewDeviceValueTest" };
Database.SetInitializer(new CreateFreshDbInitializer());
var dvb = new DeviceValueBuilder( dbConnection);
var device = UnitTesting.CreateFakeDevice();
using (var context = new ZvsContext(dbConnection))
{
context.Devices.Add(device);
await context.SaveChangesAsync();
var deviceValue = new DeviceValue
{
Description = "Testing Value Description Here",
Name = "Test Value",
ValueType = DataType.BOOL,
Value = true.ToString(),
DeviceId = device.Id
};
//act
var result = await dvb.RegisterAsync(deviceValue, device, CancellationToken.None);
var dv = await context.DeviceValues.FirstOrDefaultAsync(o => o.Name == deviceValue.Name);
//assert
Assert.IsFalse(result.HasError, result.Message);
Assert.IsNotNull(dv, "Registered device value count not be found in database.");
Console.WriteLine(result.Message);
}
}
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:34,代码来源:DeviceValueBuilderTests.cs
示例7: Execute
public async Task<IHttpActionResult> Execute([FromODataUri] int key, ODataActionParameters parameters)
{
if (!ModelState.IsValid)
{
return BadRequest();
}
var arg1 = (string)parameters["Argument"];
var arg2 = (string)parameters["Argument2"];
try
{
using (var context = new ZvsContext(WebApi2Plugin.EntityContextConnection))
{
var command = await context.Commands.FirstOrDefaultAsync(o => o.Id == key);
if (command == null)
return NotFound();
var result = await WebApi2Plugin.RunCommandAsync(command.Id, arg1, arg2, CancellationToken.None);
if (result.HasError)
return BadRequest(result.Message);
return Ok(result.Message);
}
}
catch (Exception e)
{
return BadRequest(e.Message);
}
}
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:32,代码来源:CommandsController.cs
示例8: TriggerEditorWindow
public TriggerEditorWindow(Int64 deviceValueTriggerId, ZvsContext context)
{
Log = new DatabaseFeedback(_app.EntityContextConnection) { Source = "Trigger Editor" };
_context = context;
_deviceValueTriggerId = deviceValueTriggerId;
InitializeComponent();
}
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:7,代码来源:TriggerEditorWindow.xaml.cs
示例9: RegisterAsyncNewTest
public async Task RegisterAsyncNewTest()
{
//arrange
var dbConnection = new StubIEntityContextConnection { NameOrConnectionStringGet = () => "ssb-RegisterAsyncNewTest" };
Database.SetInitializer(new CreateFreshDbInitializer());
var ssb = new SceneSettingBuilder(dbConnection);
var sceneSetting = new SceneSetting
{
Name = "Unit Test Scene Setting",
UniqueIdentifier = "SCENE_SETTING1"
};
//act
var result = await ssb.RegisterAsync(sceneSetting, CancellationToken.None);
SceneSetting setting;
using (var context = new ZvsContext(dbConnection))
{
setting =
await
context.SceneSettings.FirstOrDefaultAsync(
o => o.UniqueIdentifier == sceneSetting.UniqueIdentifier);
}
//assert
Console.WriteLine(result.Message);
Assert.IsFalse(result.HasError, result.Message);
Assert.IsNotNull(setting, "Expected new scene setting saved to DB");
}
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:31,代码来源:SceneSettingBuilderTests.cs
示例10: JavaScriptEditor
public JavaScriptEditor()
{
Context = new ZvsContext(_app.EntityContextConnection);
Log = new DatabaseFeedback(_app.EntityContextConnection) { Source = "Javascript Editor" };
LogEntries = new ObservableCollection<LogEntry>();
InitializeComponent();
}
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:7,代码来源:JavaScriptEditor.xaml.cs
示例11: RegisterAsyncNewTest
public async Task RegisterAsyncNewTest()
{
//arrange
var dbConnection = new UnitTestDbConnection();
Database.SetInitializer(new CreateFreshDbInitializer());
var dsb = new DeviceSettingBuilder(dbConnection);
var deviceSetting = new DeviceSetting
{
Name = "Unit Test Device Setting",
UniqueIdentifier = "DEVICE_SETTING1"
};
//act
var result = await dsb.RegisterAsync(deviceSetting, CancellationToken.None);
DeviceSetting setting;
using (var context = new ZvsContext(dbConnection))
{
setting =
await
context.DeviceSettings.FirstOrDefaultAsync(
o => o.UniqueIdentifier == deviceSetting.UniqueIdentifier);
}
//assert
Console.WriteLine(result.Message);
Assert.IsFalse(result.HasError, result.Message);
Assert.IsNotNull(setting, "Expected new device setting saved to DB");
}
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:31,代码来源:DeviceSettingBuilderTests.cs
示例12: ExportAsync
public async override Task<Result> ExportAsync(string fileName, CancellationToken cancellationToken)
{
using (var context = new ZvsContext(EntityContextConnection))
{
var backupJs = await context.JavaScriptCommands
.Select(o => new JavaScriptBackup
{
Script = o.Script,
Name = o.Name,
UniqueIdentifier = o.UniqueIdentifier,
ArgumentType = (int)o.ArgumentType,
Description = o.Description,
CustomData1 = o.CustomData1,
CustomData2 = o.CustomData2,
Help = o.Help,
SortOrder = o.SortOrder
})
.ToListAsync(cancellationToken);
var saveResult = await SaveAsXmlToDiskAsync(backupJs, fileName);
if (saveResult.HasError)
return Result.ReportError(saveResult.Message);
return Result.ReportSuccessFormat("Exported {0} JavaScript commands to {1}", backupJs.Count,
Path.GetFileName(fileName));
}
}
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:28,代码来源:JavascriptBackupRestore.cs
示例13: LogUserControl_OnInitialized
private async void LogUserControl_OnInitialized(object sender, EventArgs e)
{
// Do not load your data at design time.
if (DesignerProperties.GetIsInDesignMode(this))
return;
await InitialLogEntryLoad();
NotifyEntityChangeContext.ChangeNotifications<LogEntry>.OnEntityAdded += LogUserControl_OnEntityAdded;
using (var context = new ZvsContext(App.EntityContextConnection))
{
//Load your data here and assign the result to the CollectionViewSource.
var myCollectionViewSource = (CollectionViewSource)Resources["LogEntryViewSource"];
myCollectionViewSource.Source = LogEntries;
var dataView = CollectionViewSource.GetDefaultView(LogDataGrid.ItemsSource);
//clear the existing sort order
dataView.SortDescriptions.Clear();
//create a new sort order for the sorting that is done lastly
var dir = ListSortDirection.Ascending;
var option = await context.ProgramOptions.FirstOrDefaultAsync(o => o.UniqueIdentifier == "LOGDIRECTION");
if (option != null && option.Value == "Descending")
dir = ListSortDirection.Descending;
myCollectionViewSource.SortDescriptions.Clear();
myCollectionViewSource.SortDescriptions.Add(new SortDescription("Datetime", dir));
}
}
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:30,代码来源:LogUserControl.xaml.cs
示例14: ExportAsync
public override async Task<Result> ExportAsync(string fileName, CancellationToken cancellationToken)
{
using (var context = new ZvsContext(EntityContextConnection))
{
var existingTriggers = await context.DeviceValueTriggers
.ToListAsync(cancellationToken);
var backupTriggers = new List<TriggerBackup>();
foreach (var o in existingTriggers)
{
var trigger = new TriggerBackup
{
Name = o.Name,
isEnabled = o.IsEnabled,
DeviceValueName = o.DeviceValue.Name,
NodeNumber = o.DeviceValue.Device.NodeNumber,
StoredCommand = await StoredCmdBackup.ConvertToBackupCommand(o),
Operator = (int?) o.Operator,
Value = o.Value
};
backupTriggers.Add(trigger);
}
var saveResult = await SaveAsXmlToDiskAsync(backupTriggers, fileName);
if (saveResult.HasError)
return Result.ReportError(saveResult.Message);
return Result.ReportSuccessFormat("Exported {0} triggers to {1}", backupTriggers.Count,
Path.GetFileName(fileName));
}
}
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:32,代码来源:TriggerBackupRestore.cs
示例15: ExecuteScriptAsync
public async Task<Result> ExecuteScriptAsync(string script, CancellationToken cancellationToken)
{
using (var context = new ZvsContext(EntityContextConnection))
{
JintEngine.SetValue("zvsContext", context);
JintEngine.SetValue("logInfo", new Action<object>(LogInfo));
JintEngine.SetValue("logWarn", new Action<object>(LogWarn));
JintEngine.SetValue("logError", new Action<object>(LogError));
JintEngine.SetValue("setTimeout", new Action<string, double>(SetTimeout));
JintEngine.SetValue("shell", new Func<string, string, System.Diagnostics.Process>(Shell));
JintEngine.SetValue("runDeviceNameCommandName", new Func<string, string, string, Result>(RunDeviceNameCommandName));
JintEngine.SetValue("runCommand", new Func<int, string, string, Result>(RunCommand));
JintEngine.SetValue("require", new Action<string>(Require));
JintEngine.SetValue("mappath", new Func<string, string>(MapPath));
try
{
//pull out import statements
//import them into the JintEngine by running each script
//then run the JintEngine as normal
var result = await Task.Run(() => JintEngine.Execute(script), cancellationToken);
return Result.ReportSuccessFormat("JavaScript execution complete. {0}", result);
}
catch (Exception ex)
{
return Result.ReportErrorFormat("JavaScript execution error. {0}", ex.Message);
}
}
}
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:33,代码来源:JavaScriptRunner.cs
示例16: ImportAsync
public async override Task<Result> ImportAsync(string fileName, CancellationToken cancellationToken)
{
var result = await ReadAsXmlFromDiskAsync<List<DeviceBackup>>(fileName);
if (result.HasError)
return Result.ReportError(result.Message);
var backupDevices = result.Data;
var importedCount = 0;
using (var context = new ZvsContext(EntityContextConnection))
{
foreach (var d in await context.Devices.ToListAsync(cancellationToken))
{
var dev = backupDevices.FirstOrDefault(o => o.NodeNumber == d.NodeNumber);
if (dev == null) continue;
d.Name = dev.Name;
d.Location = dev.Location;
importedCount++;
}
var saveResult = await context.TrySaveChangesAsync(cancellationToken);
if (saveResult.HasError)
return Result.ReportError(saveResult.Message);
}
return Result.ReportSuccess(string.Format("Restored {0} device names. File: '{1}'", importedCount, Path.GetFileName(fileName)));
}
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:30,代码来源:DeviceBackupRestore.cs
示例17: RegisterAsyncNewDeviceTypeTest
public async Task RegisterAsyncNewDeviceTypeTest()
{
//arrange
var dbConnection = new UnitTestDbConnection();
Database.SetInitializer(new CreateFreshDbInitializer());
var dtb = new DeviceTypeBuilder( dbConnection);
var adapter = UnitTesting.CreateFakeAdapter();
using (var context = new ZvsContext(dbConnection))
{
context.Adapters.Add(adapter);
await context.SaveChangesAsync();
}
var dt = new DeviceType
{
AdapterId = adapter.Id,
UniqueIdentifier = "UNIT_TEST_DEVICE_TYPE1",
Name = "Unit Test Device Type"
};
//act
var result = await dtb.RegisterAsync(adapter.AdapterGuid, dt, CancellationToken.None);
//assert
Console.WriteLine(result.Message);
Assert.IsFalse(result.HasError);
Assert.IsTrue(dt.Id > 0, "Expected device type to have a database generated Id");
}
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:29,代码来源:DeviceTypeBuilderTests.cs
示例18: RegisterAsync
public async Task<Result> RegisterAsync(int deviceId, DeviceCommand deviceCommand, CancellationToken cancellationToken)
{
if (deviceCommand == null)
return Result.ReportError("Device command is null");
using (var context = new ZvsContext(EntityContextConnection))
{
var device = await context.Devices.FirstOrDefaultAsync(o => o.Id == deviceId, cancellationToken);
if(device == null )
return Result.ReportError("Invalid device id");
//Does device type exist?
var existingDc = await context.DeviceCommands
.Include(o => o.Options)
.FirstOrDefaultAsync(c => c.UniqueIdentifier == deviceCommand.UniqueIdentifier &&
c.DeviceId == deviceId, cancellationToken);
if (existingDc == null)
{
device.Commands.Add(deviceCommand);
return await context.TrySaveChangesAsync(cancellationToken);
}
var changed = false;
PropertyChangedEventHandler handler = (s, a) => changed = true;
existingDc.PropertyChanged += handler;
existingDc.ArgumentType = deviceCommand.ArgumentType;
existingDc.CustomData1 = deviceCommand.CustomData1;
existingDc.CustomData2 = deviceCommand.CustomData2;
existingDc.Description = deviceCommand.Description;
existingDc.Name = deviceCommand.Name;
existingDc.Help = deviceCommand.Help;
existingDc.SortOrder = deviceCommand.SortOrder;
existingDc.PropertyChanged -= handler;
var addedOptions = deviceCommand.Options.Where(option => existingDc.Options.All(o => o.Name != option.Name)).ToList();
foreach (var option in addedOptions)
{
existingDc.Options.Add(option);
changed = true;
}
var removedOptions = existingDc.Options.Where(option => deviceCommand.Options.All(o => o.Name != option.Name)).ToList();
foreach (var option in removedOptions)
{
context.CommandOptions.Local.Remove(option);
changed = true;
}
if (changed)
return await context.TrySaveChangesAsync(cancellationToken);
return Result.ReportSuccess("Nothing to update");
}
}
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:58,代码来源:DeviceCommandBuilder.cs
示例19: TestMethod1
public void TestMethod1()
{
using (var context = new ZvsContext(new ZvsEntityContextConnection()))
{
var device = UnitTesting.CreateFakeDevice();
context.Devices.Add(device);
context.SaveChanges();
}
}
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:9,代码来源:CreateFakeData.cs
示例20: ScheduledTaskCreator
public ScheduledTaskCreator()
{
_context = new ZvsContext(_app.EntityContextConnection);
Log = new DatabaseFeedback(_app.EntityContextConnection) { Source = "Scheduled Task Editor" };
InitializeComponent();
NotifyEntityChangeContext.ChangeNotifications<ScheduledTask>.OnEntityAdded += ScheduledTaskCreator_onEntityAdded;
NotifyEntityChangeContext.ChangeNotifications<ScheduledTask>.OnEntityDeleted += ScheduledTaskCreator_onEntityDeleted;
NotifyEntityChangeContext.ChangeNotifications<ScheduledTask>.OnEntityUpdated += ScheduledTaskCreator_onEntityUpdated;
}
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:9,代码来源:ScheduledTaskCreator.xaml.cs
注:本文中的zvs.DataModel.ZvsContext类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论