private void InitVariableList() { _variableList = new AsyncObservableCollection <string>(); _variableList.Add("camera"); var processor = new CommandLineProcessor(); var resp = processor.Pharse(new[] { "list", "camera" }); var list = resp as IEnumerable <string>; if (list != null) { foreach (string s in list) { _variableList.Add(s.Split('=')[0]); } } resp = processor.Pharse(new[] { "list", "property" }); list = resp as IEnumerable <string>; if (list != null) { foreach (string s in list) { _variableList.Add(s.Split('=')[0]); } } resp = processor.Pharse(new[] { "list", "session" }); list = resp as IEnumerable <string>; if (list != null) { foreach (string s in list) { _variableList.Add(s.Split('=')[0]); } } }
private void Button_Click(object sender, RoutedEventArgs e) { try { var processor = new CommandLineProcessor(); var resp = processor.Pharse(TextBoxCmd.Text.Split(' ')); var list = resp as IEnumerable <string>; if (list != null) { TextBlockError.Text = ""; foreach (var o in list) { TextBlockError.Text += o + "\n"; } } else { if (resp != null) { TextBlockError.Text = resp.ToString(); } } lst_cmd.Items.Add(TextBoxCmd.Text); } catch (Exception ex) { TextBlockError.Text = ex.Message; } }
public override ReturnCode Execute( Interpreter interpreter, IClientData clientData, ArgumentList arguments, ref Result result ) { if ((arguments == null) || (arguments.Count < 2)) { result = Utility.WrongNumberOfArguments( this, 1, arguments, "command"); return(ReturnCode.Error); } try { var processor = new CommandLineProcessor(); var o = processor.Pharse(arguments.Select(argument => (string)argument).Skip(1).ToArray()); if (!(o is string) && o is IEnumerable) { result = new StringList(o); } else { result = o == null ? "" : new Variant(o).ToString(); } } catch (Exception exception) { Log.Error("Script error ", exception); result = "Error on command execution " + exception.Message; } return(ReturnCode.Ok); }
private void InitValueList() { _valueList = new AsyncObservableCollection <string>(); try { if (string.IsNullOrEmpty(Variable)) { return; } var processor = new CommandLineProcessor(); if (Variable == "camera") { _valueList = new AsyncObservableCollection <string>(processor.Pharse(new[] { "list", "cameras" }) as IEnumerable <string>); return; } _valueList = new AsyncObservableCollection <string>(processor.Pharse(new[] { "list", Variable }) as IEnumerable <string>); } catch (Exception) { } }
private void GetValue(PluginCondition obj) { try { var processor = new CommandLineProcessor(); var resp = processor.Pharse(new[] { "get", obj.Variable }); obj.Value = resp.ToString(); } catch (Exception ex) { Log.Error("GetValue", ex); } }
public ModuleResult HandleRequest(IHttpContext context) { try { if (string.IsNullOrEmpty(context.Request.Uri.AbsolutePath) || context.Request.Uri.AbsolutePath == "/") { string str = context.Request.Uri.Scheme + "://" + context.Request.Uri.Host; if (context.Request.Uri.Port != 80) { str = str + (object)":" + context.Request.Uri.Port; } string uriString = str + context.Request.Uri.AbsolutePath + "index.html"; if (!string.IsNullOrEmpty(context.Request.Uri.Query)) { uriString = uriString + "?" + context.Request.Uri.Query; } context.Request.Uri = new Uri(uriString); } if (context.Request.Uri.AbsolutePath.StartsWith("/thumb/large")) { string requestFile = Path.GetFileName(context.Request.Uri.AbsolutePath.Replace("/", "\\")); foreach (FileItem item in ServiceProvider.Settings.DefaultSession.Files) { if (Path.GetFileName(item.LargeThumb) == requestFile || item.Name == requestFile) { SendFile(context, !File.Exists(item.LargeThumb) ? Path.Combine(Settings.WebServerFolder, "logo.png") : item.LargeThumb); SendFile(context, item.LargeThumb); return(ModuleResult.Continue); } } } if (context.Request.Uri.AbsolutePath.StartsWith("/thumb/small")) { string requestFile = Path.GetFileName(context.Request.Uri.AbsolutePath.Replace("/", "\\")); foreach (FileItem item in ServiceProvider.Settings.DefaultSession.Files) { if (Path.GetFileName(item.SmallThumb) == requestFile || item.Name == requestFile) { SendFile(context, !File.Exists(item.SmallThumb) ? Path.Combine(Settings.WebServerFolder, "logo.png") : item.SmallThumb); return(ModuleResult.Continue); } } } if (context.Request.Uri.AbsolutePath.StartsWith("/preview.jpg")) { SendFile(context, ServiceProvider.Settings.SelectedBitmap.FileItem.LargeThumb); } if (context.Request.Uri.AbsolutePath.StartsWith("/session.json")) { var s = JsonConvert.SerializeObject(ServiceProvider.Settings.DefaultSession, Formatting.Indented); SendData(context, Encoding.ASCII.GetBytes(s)); } if (context.Request.Uri.AbsolutePath.StartsWith("/settings.json")) { var s = JsonConvert.SerializeObject(ServiceProvider.Settings, Formatting.Indented); SendData(context, Encoding.ASCII.GetBytes(s)); } if (context.Request.Uri.AbsolutePath.StartsWith("/liveview.jpg") && ServiceProvider.DeviceManager.SelectedCameraDevice != null && ServiceProvider.DeviceManager.LiveViewImage.ContainsKey( ServiceProvider.DeviceManager.SelectedCameraDevice)) { SendData(context, ServiceProvider.DeviceManager.LiveViewImage[ServiceProvider.DeviceManager.SelectedCameraDevice]); } if (context.Request.Uri.AbsolutePath.StartsWith("/image/")) { foreach (FileItem item in ServiceProvider.Settings.DefaultSession.Files) { if (Path.GetFileName(item.FileName) == Path.GetFileName(context.Request.Uri.AbsolutePath.Replace("/", "\\"))) { SendFile(context, item.FileName); return(ModuleResult.Continue); } } } var slc = context.Request.QueryString["slc"]; if (!string.IsNullOrEmpty(slc)) { string response = ""; try { var processor = new CommandLineProcessor(); var resp = processor.Pharse(new[] { context.Request.QueryString["slc"], context.Request.QueryString["param1"], context.Request.QueryString["param2"] }); var list = resp as IEnumerable <string>; if (list != null) { foreach (var o in list) { response += o + "\n"; } } else { if (resp != null) { response = resp.ToString(); } } } catch (Exception ex) { response = ex.Message; } byte[] buffer = Encoding.UTF8.GetBytes(response); //response.ContentLength64 = buffer.Length; context.Response.AddHeader("Content-Length", buffer.Length.ToString()); context.Response.Body = new MemoryStream(); context.Response.Body.Write(buffer, 0, buffer.Length); context.Response.Body.Position = 0; return(ModuleResult.Continue); } string fullpath = GetFullPath(context.Request.Uri); if (!string.IsNullOrEmpty(fullpath) && File.Exists(fullpath)) { if (Path.GetFileName(fullpath) == "slide.html") { string file = File.ReadAllText(fullpath); StringBuilder builder = new StringBuilder(); foreach (FileItem item in ServiceProvider.Settings.DefaultSession.Files) { string tempStr = _lineFormat.Replace("@image@", "/thumb/large/" + Path.GetFileName(item.LargeThumb)); tempStr = tempStr.Replace("@image_thumb@", "/thumb/small/" + Path.GetFileName(item.SmallThumb)); tempStr = tempStr.Replace("@image_url@", "/image/" + Path.GetFileName(item.FileName)); tempStr = tempStr.Replace("@title@", item.Name); tempStr = tempStr.Replace("@desc@", item.FileInfo != null ? (item.FileInfo.InfoLabel ?? "") : ""); builder.AppendLine(tempStr); } file = file.Replace("@@image_list@@", builder.ToString()); byte[] buffer = Encoding.UTF8.GetBytes(file); //response.ContentLength64 = buffer.Length; context.Response.AddHeader("Content-Length", buffer.Length.ToString()); context.Response.Body = new MemoryStream(); context.Response.Body.Write(buffer, 0, buffer.Length); context.Response.Body.Position = 0; } else { SendFile(context, fullpath); } } string cmd = context.Request.QueryString["CMD"]; string param = context.Request.QueryString["PARAM"]; if (!string.IsNullOrEmpty(cmd)) { ServiceProvider.WindowsManager.ExecuteCommand(cmd, param); } } catch (Exception ex) { Log.Error("Web server error", ex); } return(ModuleResult.Continue); }
private string ProccesQueries(string query) { string res = ":;response:error;message:wrong query"; try { var lines = Pharse(query); if (lines.ContainsKey("request")) { switch (lines["request"]) { case "session": { return(lines.ContainsKey("format") && lines["format"] == "json" ? JsonConvert.SerializeObject(ServiceProvider.Settings.DefaultSession, Formatting.Indented, new JsonSerializerSettings() { }) : GetSessionData()); } case "cameras": { if (ServiceProvider.DeviceManager.ConnectedDevices.Count == 0) { return(":;response:error;message:no camera is connected"); } return(lines.ContainsKey("format") && lines["format"] == "json" ? JsonConvert.SerializeObject(ServiceProvider.DeviceManager.ConnectedDevices, Formatting.Indented, new JsonSerializerSettings() { }) : GetCamerasData()); } default: return(":;response:error;message:unknown request"); } } if (lines.ContainsKey("command")) { ICameraDevice device = null; if (ServiceProvider.DeviceManager.ConnectedDevices.Count == 0) { return(":;response:error;message:no camera is connected"); } if (lines.ContainsKey("serial")) { device = GetDevice(lines["serial"]); } if (device == null) { if (ServiceProvider.DeviceManager.SelectedCameraDevice == null) { return(":;response:error;message:No camera was found"); } device = ServiceProvider.DeviceManager.SelectedCameraDevice; } switch (lines["command"]) { case "capture": { var thread = new Thread(StartCapture); thread.Start(device); return(":;response:ok;"); } break; case "starliveview": { ServiceProvider.WindowsManager.ExecuteCommand( WindowsCmdConsts.LiveViewWnd_Show, device); return(":;response:ok;"); } break; case "captureliveview": { ServiceProvider.WindowsManager.ExecuteCommand( CmdConsts.LiveView_Capture, device); return(":;response:ok;"); } break; case "manualfocus": { var time = DateTime.Now; ServiceProvider.WindowsManager.ExecuteCommand( CmdConsts.LiveView_ManualFocus + lines["step"], device); return(":;response:ok;executiontime:" + (DateTime.Now - time)); } break; case "stopliveview": { ServiceProvider.WindowsManager.ExecuteCommand( WindowsCmdConsts.LiveViewWnd_Hide, device); return(":;response:ok;"); } break; case "dcc": { try { if (!lines.ContainsKey("param")) { return(":;response:error;No parameters are specified"); } var processor = new CommandLineProcessor(); var resp = processor.Pharse(lines["param"].Split(' ')); return(string.Format(":;response:{0};", JsonConvert.SerializeObject(resp))); } catch (Exception ex) { return(":;response:error;message:" + ex.Message); } } break; } } } catch (Exception exception) { res = ":;response:error;message:" + exception.Message; } return(res); }
public ModuleResult HandleRequest(IHttpContext context) { try { if (string.IsNullOrEmpty(context.Request.Uri.AbsolutePath) || context.Request.Uri.AbsolutePath == "/") { string str = context.Request.Uri.Scheme + "://" + context.Request.Uri.Host; if (context.Request.Uri.Port != 80) { str = str + (object)":" + context.Request.Uri.Port; } string uriString = str + context.Request.Uri.AbsolutePath + "index.html"; if (!string.IsNullOrEmpty(context.Request.Uri.Query)) { uriString = uriString + "?" + context.Request.Uri.Query; } context.Request.Uri = new Uri(uriString); } if (context.Request.Uri.AbsolutePath.StartsWith("/thumb/large")) { string requestFile = Path.GetFileName(context.Request.Uri.AbsolutePath.Replace("/", "\\")); foreach (FileItem item in ServiceProvider.Settings.DefaultSession.Files) { if (Path.GetFileName(item.LargeThumb) == requestFile || item.Name == requestFile) { SendFile(context, !File.Exists(item.LargeThumb) ? Path.Combine(Settings.WebServerFolder, "logo.png") : item.LargeThumb); SendFile(context, item.LargeThumb); return(ModuleResult.Continue); } } } if (context.Request.Uri.AbsolutePath.StartsWith("/thumb/small")) { string requestFile = Path.GetFileName(context.Request.Uri.AbsolutePath.Replace("/", "\\")); foreach (FileItem item in ServiceProvider.Settings.DefaultSession.Files) { if (Path.GetFileName(item.SmallThumb) == requestFile || item.Name == requestFile) { SendFile(context, !File.Exists(item.SmallThumb) ? Path.Combine(Settings.WebServerFolder, "logo.png") : item.SmallThumb); return(ModuleResult.Continue); } } } if (context.Request.Uri.AbsolutePath.StartsWith("/preview.jpg")) { SendFile(context, ServiceProvider.Settings.SelectedBitmap.FileItem.LargeThumb); } if (context.Request.Uri.AbsolutePath.StartsWith("/session.json")) { var s = JsonConvert.SerializeObject(ServiceProvider.Settings.DefaultSession, Formatting.Indented); SendData(context, Encoding.ASCII.GetBytes(s)); } if (context.Request.Uri.AbsolutePath.StartsWith("/settings.json")) { var s = JsonConvert.SerializeObject(ServiceProvider.Settings, Formatting.Indented); SendData(context, Encoding.ASCII.GetBytes(s)); } if (context.Request.Uri.AbsolutePath.StartsWith("/filelist.json")) { List <FileListItem> items = ServiceProvider.Settings.DefaultSession.Files.Select(item => new FileListItem() { FileName = item.FileName, LargeThumb = "/thumb/large/" + Path.GetFileName(item.LargeThumb), SmallThumb = "/thumb/small/" + Path.GetFileName(item.SmallThumb), Original = "/image/" + Path.GetFileName(item.FileName), Name = item.Name, Width = item.FileInfo.Width > 0 ? item.FileInfo.Width : 3000, Height = item.FileInfo.Height > 0 ? item.FileInfo.Height : 2000, }).ToList(); var s = JsonConvert.SerializeObject(items, Formatting.Indented); SendData(context, Encoding.ASCII.GetBytes(s)); } if (context.Request.Uri.AbsolutePath.StartsWith("/liveview.jpg") && ServiceProvider.DeviceManager.SelectedCameraDevice != null && ServiceProvider.DeviceManager.LiveViewImage.ContainsKey( ServiceProvider.DeviceManager.SelectedCameraDevice)) { SendDataFile(context, ServiceProvider.DeviceManager.LiveViewImage[ServiceProvider.DeviceManager.SelectedCameraDevice], MimeTypeProvider.Instance.Get("liveview.jpg")); } if (context.Request.Uri.AbsolutePath.StartsWith("/liveviewwebcam.jpg") && ServiceProvider.DeviceManager.SelectedCameraDevice != null) { if (_liveViewFirstRun) { ServiceProvider.WindowsManager.ExecuteCommand(WindowsCmdConsts.LiveViewWnd_Show); Thread.Sleep(500); ServiceProvider.WindowsManager.ExecuteCommand(CmdConsts.All_Minimize); ServiceProvider.WindowsManager.ExecuteCommand(CmdConsts.LiveView_NoProcess); _liveViewFirstRun = false; } if (ServiceProvider.DeviceManager.LiveViewImage.ContainsKey( ServiceProvider.DeviceManager.SelectedCameraDevice)) { SendDataFile(context, ServiceProvider.DeviceManager.LiveViewImage[ ServiceProvider.DeviceManager.SelectedCameraDevice], MimeTypeProvider.Instance.Get("liveview.jpg")); } } if (context.Request.Uri.AbsolutePath.StartsWith("/image/")) { foreach (FileItem item in ServiceProvider.Settings.DefaultSession.Files) { if (Path.GetFileName(item.FileName) == Path.GetFileName(context.Request.Uri.AbsolutePath.Replace("/", "\\"))) { SendFile(context, item.FileName); return(ModuleResult.Continue); } } } var slc = context.Request.QueryString["slc"]; if (ServiceProvider.Settings.AllowWebserverActions && !string.IsNullOrEmpty(slc)) { string response = ""; try { var processor = new CommandLineProcessor(); processor.SetCamera(context.Request.QueryString["camera"]); var resp = processor.Pharse(new[] { context.Request.QueryString["slc"], context.Request.QueryString["param1"], context.Request.QueryString["param2"] }); var list = resp as IEnumerable <string>; if (list != null) { foreach (var o in list) { response += o + "\n"; } } else { if (resp != null) { response = resp.ToString(); } } } catch (Exception ex) { response = ex.Message; } if (string.IsNullOrEmpty(response)) { response = "OK"; } byte[] buffer = Encoding.UTF8.GetBytes(response); //response.ContentLength64 = buffer.Length; context.Response.AddHeader("Content-Length", buffer.Length.ToString()); context.Response.ContentType = "text/html"; context.Response.Body = new MemoryStream(); context.Response.Body.Write(buffer, 0, buffer.Length); context.Response.Body.Position = 0; return(ModuleResult.Continue); } string fullpath = GetFullPath(context.Request.Uri); if (!string.IsNullOrEmpty(fullpath) && File.Exists(fullpath)) { if (Path.GetFileName(fullpath) == "slide.html") { string file = File.ReadAllText(fullpath); string template = Path.Combine(Settings.WebServerFolder, "template.txt"); string jsontemplate = Path.Combine(Settings.WebServerFolder, "template.json"); bool json = false; if (File.Exists(template)) { _lineFormat = File.ReadAllText(template); } if (File.Exists(jsontemplate)) { _lineFormat = File.ReadAllText(jsontemplate); json = true; } StringBuilder builder = new StringBuilder(); foreach (FileItem item in ServiceProvider.Settings.DefaultSession.Files) { if (json && builder.Length > 0) { builder.AppendLine(","); } string tempStr = _lineFormat.Replace("@image@", "/thumb/large/" + Path.GetFileName(item.LargeThumb)); tempStr = tempStr.Replace("@image_thumb@", "/thumb/small/" + Path.GetFileName(item.SmallThumb)); tempStr = tempStr.Replace("@image_url@", "/image/" + Path.GetFileName(item.FileName)); tempStr = tempStr.Replace("@title@", item.Name); tempStr = tempStr.Replace("@width@", item.FileInfo.Width > 0 ? item.FileInfo.Width.ToString() : "3000"); tempStr = tempStr.Replace("@height@", item.FileInfo.Height > 0 ? item.FileInfo.Height.ToString() : "2000"); tempStr = tempStr.Replace("@desc@", item.FileInfo != null ? (item.FileInfo.InfoLabel ?? "") : ""); builder.AppendLine(json?CleanForJson(tempStr):tempStr); } file = file.Replace("@@image_list@@", builder.ToString()); byte[] buffer = Encoding.UTF8.GetBytes(file); //response.ContentLength64 = buffer.Length; context.Response.AddHeader("Content-Length", buffer.Length.ToString()); context.Response.Body = new MemoryStream(); context.Response.Body.Write(buffer, 0, buffer.Length); context.Response.Body.Position = 0; } else { SendFile(context, fullpath); } } string cmd = context.Request.QueryString["CMD"]; string param = context.Request.QueryString["PARAM"]; if (ServiceProvider.Settings.AllowWebserverActions && !string.IsNullOrEmpty(cmd)) { ServiceProvider.WindowsManager.ExecuteCommand(cmd, param); } } catch (Exception ex) { Log.Error("Web server error", ex); } return(ModuleResult.Continue); }
public bool Evaluate(ICameraDevice device) { bool cond = true; if (string.IsNullOrWhiteSpace(Value) || string.IsNullOrWhiteSpace(Variable) || string.IsNullOrWhiteSpace(Condition)) { return(true); } string op = Condition; var processor = new CommandLineProcessor() { TargetDevice = device }; var resp = processor.Pharse(new[] { "get", Variable }); string left = resp.ToString(); string right = Value; if (string.IsNullOrEmpty(left)) { return(true); } float leftNum = 0; float rightNum = 0; bool numeric = float.TryParse(left, out leftNum); numeric = numeric && float.TryParse(right, out rightNum); // try to process our test if (op == ">=") { if (numeric) { cond = leftNum >= rightNum; } else { cond = String.Compare(left, right, StringComparison.Ordinal) >= 0; } } else if (op == "<=") { if (numeric) { cond = leftNum <= rightNum; } else { cond = String.Compare(left, right, StringComparison.Ordinal) <= 0; } } else if (op == "!=") { if (numeric) { cond = leftNum != rightNum; } else { cond = String.Compare(left, right, StringComparison.Ordinal) != 0; } } else if (op == "=") { if (numeric) { cond = leftNum == rightNum; } else { cond = String.Compare(left, right, StringComparison.Ordinal) == 0; } } else if (op == "<") { if (numeric) { cond = leftNum < rightNum; } else { cond = String.Compare(left, right, StringComparison.Ordinal) < 0; } } else if (op == ">") { if (numeric) { cond = leftNum > rightNum; } else { cond = String.Compare(left, right, StringComparison.Ordinal) > 0; } } else if (op == "%") { if (numeric) { cond = (int)leftNum % (int)rightNum == 0; } else { cond = false; } } else { Log.Error("Wrong operator :" + op); return(true); } return(cond); }