本文整理汇总了C#中zvs.DataModel.ZvsContext类的典型用法代码示例。如果您正苦于以下问题:C# ZvsContext类的具体用法?C# ZvsContext怎么用?C# ZvsContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ZvsContext类属于zvs.DataModel命名空间,在下文中一共展示了ZvsContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
示例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;
}
示例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);
}
}
示例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();
}
示例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");
}
示例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);
}
}
示例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);
}
}
示例8: TriggerEditorWindow
public TriggerEditorWindow(Int64 deviceValueTriggerId, ZvsContext context)
{
Log = new DatabaseFeedback(_app.EntityContextConnection) { Source = "Trigger Editor" };
_context = context;
_deviceValueTriggerId = deviceValueTriggerId;
InitializeComponent();
}
示例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");
}
示例10: JavaScriptEditor
public JavaScriptEditor()
{
Context = new ZvsContext(_app.EntityContextConnection);
Log = new DatabaseFeedback(_app.EntityContextConnection) { Source = "Javascript Editor" };
LogEntries = new ObservableCollection<LogEntry>();
InitializeComponent();
}
示例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");
}
示例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));
}
}
示例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));
}
}
示例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));
}
}
示例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);
}
}
}