private Entity GetEntityForDomainByLinkAndUsernameAndPassword(int link, string username, string password) { using (ExecutorClient client = new ExecutorClient()) { string domain = ((Entity)client.Execute("Link", "GetEntityByField", new object[] { "Unique", link, "=" })).GetValue("Value").ToString(); try { if ((new PrincipalContext(ContextType.Domain, domain)).ValidateCredentials(username, password) == true) { Entity filter = Helper.Deserialize("{\"Value\": \"" + username + "\", \"Link\": " + link.ToString() + "}"); Entity connector = Helper.Deserialize("{\"Value\": \"=\", \"Link\": \"=\"}"); EntityCollection verificates = (EntityCollection)client.Execute("Verificate", "GetEntitiesByFilter", new object[] { filter, connector }); if (verificates.Count == 0) { return(Helper.GetEntity(false, "该用户未在本系统授权!", "Link")); } else { return(Helper.GetEntity(true, "登录成功!", this.GetTokenByLinkAndUsernameAndPassword(link, username, password))); } } else { return(Helper.GetEntity(false, "用户名/密码错误,请重新登录!", "Id")); } } catch (Exception exception) { return(Helper.GetEntity(false, exception.Message)); } } }
private Entity GetTokenByLinkAndUsernameAndPassword(int link, string username, string password) { using (ExecutorClient client = new ExecutorClient()) { return((Entity)client.Execute("Token", "GetTokenByLinkAndUsernameAndPassword", new object[] { link, username, password })); } }
private Entity GetTokenForDomainByLinkAndUsernameAndPassword(int link, string username, string password) { using (ExecutorClient client = new ExecutorClient()) { string domain = ((Entity)client.Execute("Link", "GetEntityByField", new object[] { "Unique", link, "=" })).GetValue("Value").ToString(); if ((new PrincipalContext(ContextType.Domain, domain)).ValidateCredentials(username, password) == true) { Entity filter = Helper.Deserialize("{\"Value\": \"" + username + "\", \"Link\": " + link.ToString() + "}"); Entity connector = Helper.Deserialize("{\"Value\": \"=\", \"Link\": \"=\"}"); EntityCollection verificates = (EntityCollection)client.Execute("Verificate", "GetEntitiesByFilter", new object[] { filter, connector }); if (verificates.Count == 0) { return(Helper.GetEntity(false, "该用户未在本系统授权!", "Link")); } Entity account = (Entity)client.Execute("Account", "GetEntityByField", new object[] { "Unique", verificates[0].GetValue("Account").ToString(), "=" }); EntityCollection functions = (EntityCollection)client.Execute("Act", "GetEntitiesWithFunctionByAccount", new object[] { account.GetValue("Unique").ToInt32() }); return(this.GetToken(account, verificates[0], functions)); } else { return(Helper.GetEntity(false, "用户名/密码错误!", "Id")); } } }
private Entity GetTokenByLinkAndIdAndPassword(int link, string id, string password) { using (ExecutorClient client = new ExecutorClient()) { Entity account = (Entity)client.Execute("Account", "GetEntityByField", new object[] { "Id", id, "=" }); if (account.IsEmpty == true) { return(Helper.GetEntity(false, "该用户名不存在!", "Id")); } Entity filter = Helper.Deserialize("{\"Account\": " + account.GetValue("Unique").ToString() + ", \"Link\": " + link.ToString() + "}"); Entity connector = Helper.Deserialize("{\"Account\": \"=\", \"Link\": \"=\"}"); EntityCollection verificates = (EntityCollection)client.Execute("Verificate", "GetEntitiesByFilter", new object[] { filter, connector }); if (verificates.Count == 0) { return(Helper.GetEntity(false, "该用户不支持该登录方式!", "Link")); } if (verificates[0].GetValue("Value").ToString() != password) { return(Helper.GetEntity(false, "密码错误!", "Password")); } EntityCollection functions = (EntityCollection)client.Execute("Act", "GetEntitiesWithFunctionByAccount", new object[] { account.GetValue("Unique").ToInt32() }); return(this.GetToken(account, verificates[0], functions)); } }
public void Update(string unique, Entity entity) { ExecutorClient client = new ExecutorClient(); client.Endpoint.Behaviors.Add(new WebHttpBehavior()); client.Execute("Exchange.Single", "Update", new object[] { unique, entity }); client.Close(); }
public bool Load() { if (this.Request.QueryString["Token"] == null) { return(this.Redirect()); } Entity entity; if (this.Request.QueryString["Token"] != null) { string token = this.Request.QueryString["Token"].ToString(); try { string oldEntity = this.Request.Cookies[token].ToString(); entity = Helper.Deserialize(oldEntity); this.Session["Token"] = entity; } catch { using (ExecutorClient client = new ExecutorClient()) { entity = (Entity)client.Execute("Token", "CheckToken", new object[] { token }); if (entity.PropertyCollection.IndexOf("Success") != -1) { return(this.Redirect()); } if (this._No != "Index") { if (((EntityCollection)entity.GetValue("Functions")).GetEntityCollection("No", this._No).Count == 0) { return(this.Redirect()); } } AddCookie("Token", entity.Serialize(entity), 60 * 8, this._No); this.Session["Token"] = entity; } } } Entity account = (Entity)((Entity)this.Session["Token"]).GetValue("Account"); this.SetAccount(account); return(true); }
private void Zhhwy_DataReceived(object sender, EventArgs e) { Entity result = (Entity)sender; string date = result.GetValue("Date").ToDateTime().ToString("yyyy-MM-dd HH:mm:ss"); string mobile = result.GetValue("Mobile").ToString(); string text = result.GetValue("Text").ToString(); Entity entity = new Entity(this._PropertyCollection); entity.SetValue("Unique", string.Empty); entity.SetValue("Parent", string.Empty); entity.SetValue("Mobile", mobile); entity.SetValue("Text", text); entity.SetValue("Date", date); entity.SetValue("Remark", string.Empty); entity.SetValue("Status", 0); entity.SetValue("Operator", Program.Account); ExecutorClient client = new ExecutorClient(); client.Endpoint.Behaviors.Add(new WebHttpBehavior()); int length = text.Length; for (int i = 0; i < length - 1; i++) { try { client.Execute("GsmMessage", "SaveEntity", new object[] { entity }); break; } catch { if (i == length - 1) { entity.SetValue("Text", "(全部是乱码)"); } else { entity.SetValue("Text", text.Substring(0, length - i - 1)); } } } client.Close(); if (this.DataReceived != null) { this.DataReceived(sender, e); } }
private void Logon_Load(object sender, EventArgs e) { ExecutorClient client = new ExecutorClient(); client.Endpoint.Behaviors.Add(new WebHttpBehavior()); EntityCollection collection = (EntityCollection)client.Execute("Link", "GetEntities", new object[] { }); client.Close(); for (int i = 0; i < collection.Count; i++) { this.ddlLink.Items.Add(new ListItem(collection[i].GetValue("Name").ToString(), collection[i].GetValue("Unique").ToString())); } this.ddlLink.SelectedIndex = 0; }
private void btnLogon_Click(object sender, EventArgs e) { if (this.txtUsername.Text.Trim() == string.Empty) { MessageBox.Show("用户名不能为空!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.txtUsername.Focus(); return; } if (this.txtPassword.Text.Trim() == string.Empty) { MessageBox.Show("密码不能为空!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.txtPassword.Focus(); return; } ExecutorClient client = new ExecutorClient(); client.Endpoint.Behaviors.Add(new WebHttpBehavior()); Entity entity = (Entity)client.Execute("Verificate", "GetEntityByLinkAndUsernameAndPassword", new object[] { ((ListItem)this.ddlLink.SelectedItem).Value.ToInt32(), this.txtUsername.Text, this.txtPassword.Text }); client.Close(); if (entity.GetValue("Success").ToBoolean() == false) { MessageBox.Show(entity.GetValue("Message").ToString(), "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); if (entity.GetValue("Value").ToString() == "Id" || entity.GetValue("Value").ToString() == "Link") { this.txtUsername.Text = string.Empty; this.txtPassword.Text = string.Empty; this.txtUsername.Focus(); } else { this.txtPassword.Text = string.Empty; this.txtPassword.Focus(); } return; } Entity account = (Entity)((Entity)entity.GetValue("Value")).GetValue("Account"); Program.Account = account.GetValue("Unique").ToInt32(); this.DialogResult = DialogResult.OK; }
public Entity GetEntityByLinkAndUsernameAndPassword(int link, string username, string password) { using (ExecutorClient client = new ExecutorClient()) { int type = ((Entity)client.Execute("Link", "GetEntityByField", new object[] { "Unique", link, "=" })).GetValue("Type").ToInt32(); if (type == 0) { return(this.GetEntityByLinkAndIdAndPassword(link, username, password)); } else if (type == 1) { return(this.GetEntityForUrlByLinkAndUsernameAndPassword(link, username, password)); } else { return(this.GetEntityForDomainByLinkAndUsernameAndPassword(link, username, password)); } } }
public MessageHelper() { this._PropertyCollection.Add(new SimpleProperty("Supplier", typeof(string))); this._PropertyCollection.Add(new SimpleProperty("Tree", typeof(string))); this._PropertyCollection.Add(new SimpleProperty("Make", typeof(Nullable <DateTime>))); this._PropertyCollection.Add(new SimpleProperty("Area", typeof(string))); this._PropertyCollection.Add(new SimpleProperty("Origin", typeof(string))); this._PropertyCollection.Add(new SimpleProperty("License", typeof(string))); this._PropertyCollection.Add(new SimpleProperty("Driver", typeof(string))); this._PropertyCollection.Add(new SimpleProperty("Ship", typeof(Nullable <DateTime>))); this._PropertyCollection.Add(new SimpleProperty("Line", typeof(string))); using (ExecutorClient client = new ExecutorClient()) { this._GsmOrigins = client.Execute("GsmOrigin", "GetEntitiesWithAreaNameByStartAndLength", new object[] { 1, int.MaxValue }) as EntityCollection; this._GsmLines = client.Execute("GsmLine", "GetEntities", new object[0]) as EntityCollection; this._GsmSuppliers = client.Execute("GsmSupplier", "GetEntities", new object[0]) as EntityCollection; this._GsmTrees = client.Execute("GsmTree", "GetEntities", new object[0]) as EntityCollection; } }
public static int Execute(params string[] args) { // Trigger plugin manager before anything else. if (ExecutorClient.IsRunningIsolated) { // TODO: This is not needed right now, but might be again when we fix the TODO in tap.exe //PluginManager.DirectoriesToSearch.Clear(); //PluginManager.DirectoriesToSearch.Add(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)); using (var tpmClient = new ExecutorClient()) { tpmClient.MessageServer("delete " + Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)); } } // Set TapMutex to ensure any installers know about running OpenTAP processes. ReflectionHelper.SetTapMutex(); try { // Turn off the default system behavior when CTRL+C is pressed. // When Console.TreatControlCAsInput is false, CTRL+C is treated as an interrupt instead of as input. Console.TreatControlCAsInput = false; } catch { } try { var execThread = TapThread.Current; Console.CancelKeyPress += (s, e) => { e.Cancel = true; execThread.Abort(); }; } catch { } CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; // Find the called action if (!TypeData.GetDerivedTypes <ICliAction>().Any()) { Console.WriteLine("No commands found. Please try reinstalling OpenTAP."); return(1); } try { // setup logging to be relative to the executing assembly. // at this point SessionLogs.Initialize has already been called (PluginManager.Load). // so the log is already being saved at a different location. var logpath = EngineSettings.Current.SessionLogPath.Expand(date: Process.GetCurrentProcess().StartTime); bool isPathRooted = Path.IsPathRooted(logpath); if (isPathRooted == false) { var dir = Path.GetDirectoryName(typeof(SessionLogs).Assembly.Location); if (ExecutorClient.IsRunningIsolated) { // redirect the isolated log path to the non-isolated path. dir = ExecutorClient.ExeDir; } logpath = Path.Combine(dir, logpath); } SessionLogs.Rename(logpath); } catch (Exception e) { log.Error("Path defined in Engine settings contains invalid characters: {0}", EngineSettings.Current.SessionLogPath); log.Debug(e); } ITypeData selectedCommand = null; // Find selected command var actionTree = new CliActionTree(); var selectedcmd = actionTree.GetSubCommand(args); if (selectedcmd?.Type != null && selectedcmd?.SubCommands.Any() != true) { selectedCommand = selectedcmd.Type; } void print_command(CliActionTree cmd, int level, int descriptionStart) { if (cmd.IsBrowsable) { int relativePadding = descriptionStart - (level * LevelPadding); // Calculate amount of characters to pad right before description start to ensure description alignments. Console.Write($"{"".PadRight(level * LevelPadding)}{cmd.Name.PadRight(relativePadding)}"); if (cmd.Type?.IsBrowsable() ?? false) { Console.WriteLine($"{cmd.Type.GetDisplayAttribute().Description}"); } else { Console.WriteLine(); } if (cmd.IsGroup) { foreach (var subCmd in cmd.SubCommands) { print_command(subCmd, level + 1, descriptionStart); } } } } // Print default info if (selectedCommand == null) { Console.WriteLine("OpenTAP Command Line Interface ({0})", Assembly.GetExecutingAssembly().GetSemanticVersion().ToString(4)); Console.WriteLine("Usage: tap <command> [<subcommand(s)>] [<args>]\n"); if (selectedcmd == null) { Console.WriteLine("Valid commands are:"); foreach (var cmd in actionTree.SubCommands) { print_command(cmd, 0, actionTree.GetMaxCommandTreeLength(LevelPadding) + LevelPadding); } } else { Console.Write("Valid subcommands of "); print_command(selectedcmd, 0, actionTree.GetMaxCommandTreeLength(LevelPadding) + LevelPadding); } Console.WriteLine($"\nRun \"{(OperatingSystem.Current == OperatingSystem.Windows ? "tap.exe" : "tap")} " + "<command> [<subcommand>] -h\" to get additional help for a specific command.\n"); if (args.Length == 0 || args.Any(s => s.ToLower() == "--help" || s.ToLower() == "-h")) { return(0); } else { return(-1); } } if (selectedCommand != TypeData.FromType(typeof(RunCliAction)) && UserInput.Interface == null) // RunCliAction has --non-interactive flag and custom platform interaction handling. { CliUserInputInterface.Load(); } ICliAction packageAction = null; try{ packageAction = (ICliAction)selectedCommand.CreateInstance(); }catch (TargetInvocationException e1) when(e1.InnerException is System.ComponentModel.LicenseException e) { Console.Error.WriteLine("Unable to load CLI Action '{0}'", selectedCommand.GetDisplayAttribute().GetFullName()); Console.Error.WriteLine(e.Message); return(-4); } if (packageAction == null) { Console.WriteLine("Error instantiating command {0}", selectedCommand.Name); return(-3); } try { int skip = selectedCommand.GetDisplayAttribute().Group.Length + 1; // If the selected command has a group, it takes two arguments to use the command. E.g. "package create". If not, it only takes 1 argument, E.g. "restapi". return(packageAction.Execute(args.Skip(skip).ToArray())); } catch (ExitCodeException ec) { log.Error(ec.Message); return(ec.ExitCode); } catch (ArgumentException ae) { // ArgumentException usually contains several lines. // Only print the first line as an error message. // Example message: // "Directory is not a git repository. // Parameter name: repositoryDir" var lines = ae.Message.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); log.Error(lines.First()); for (int i = 1; i < lines.Length; i++) { log.Debug(lines[i]); } return(-1); } catch (OperationCanceledException ex) { log.Error(ex.Message); return(1); } catch (Exception ex) { log.Error(ex.Message); log.Debug(ex); return(-1); } finally { Log.Flush(); } }
internal static void RunIsolated(string application = null, string target = null, IsolatedPackageAction isolatedAction = null) { using (var tpmClient = new ExecutorClient()) { var packages = new Installation(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)).GetPackages(); PackageDef findPackageWithFile(string file) { foreach (var package in packages) { foreach (var pkgfile in package.Files) { var filePath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), pkgfile.FileName); if (string.Equals(NormalizePath(filePath), NormalizePath(file), StringComparison.OrdinalIgnoreCase)) { return(package); } } } return(null); } var exec = application ?? Assembly.GetEntryAssembly().Location; PackageDef pkg = findPackageWithFile(Path.GetFullPath(exec)); if (pkg == null) { throw new InvalidOperationException($"{Path.GetFileName(exec)} was not installed through a package."); } var dependencies = pkg.Dependencies.ToList(); if (isolatedAction != null) { // If the executing IsolatedPackageAction does not origin from OpenTAP package, we need to include it when we copy and run isolated var actionAsm = isolatedAction.GetType().Assembly.Location; PackageDef isolatedActionPackage = findPackageWithFile(Path.GetFullPath(actionAsm)); if (isolatedActionPackage == null) { throw new InvalidOperationException($"{Path.GetFileName(actionAsm)} was not installed through a package."); } if (pkg.Name != isolatedActionPackage.Name) { if (!dependencies.Any(p => p.Name == isolatedActionPackage.Name)) { dependencies.Add(new PackageDependency(isolatedActionPackage.Name, new VersionSpecifier(isolatedActionPackage.Version, VersionMatchBehavior.Compatible))); } } } // when installing/uninstalling packages we might need to use custom package actions as well. var extraDependencies = PluginManager.GetPlugins <ICustomPackageAction>().Select(t => t.Assembly.Location).Distinct().ToList(); foreach (var exDep in extraDependencies) { var package = findPackageWithFile(exDep); if (package != null && !dependencies.Any(p => p.Name == package.Name)) { dependencies.Add(new PackageDependency(package.Name, new VersionSpecifier(package.Version, VersionMatchBehavior.Compatible))); } } var deps = OpenTap.Utils.FlattenHeirarchy(dependencies, dep => (IEnumerable <PackageDependency>)packages.FirstOrDefault(x => x.Name == dep.Name)?.Dependencies ?? Array.Empty <PackageDependency>(), distinct: true); if (false == deps.Any(x => x.Name == pkg.Name)) { deps.Add(new PackageDependency(pkg.Name, new VersionSpecifier(pkg.Version, VersionMatchBehavior.Compatible))); } bool force = isolatedAction?.Force ?? false; List <string> allFiles = new List <string>(); foreach (var d in deps) { var availPackages = packages.Where(p => p.Name == d.Name); var package = availPackages.FirstOrDefault(p => d.Version.IsCompatible(p.Version)); if (package == null) { package = availPackages.FirstOrDefault(); if (!force) { if (package != null) { throw new Exception($"Cannot find compatible dependency '{d.Name}' {d.Version}. Version {package.Version} is installed."); } throw new Exception($"Cannot find needed dependency '{d.Name}'."); } log.Warning("Unable to find compatible package, using {0} v{1} instead.", package.Name, package.Version); } var defPath = String.Join("/", PackageDef.PackageDefDirectory, package.Name, PackageDef.PackageDefFileName); if (File.Exists(defPath)) { allFiles.Add(defPath); } var fs = package.Files; var brokenPackages = new HashSet <string>(); foreach (var file in fs) { string loc = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), file.FileName); if (!File.Exists(loc)) { brokenPackages.Add(package.Name); log.Debug($"Could not find file '{loc}' part of package '{package.Name}'."); continue; } allFiles.Add(file.FileName); } foreach (var name in brokenPackages) { log.Warning($"Package '{name}' has missing files and is broken."); } } string tempFolder = Path.GetFullPath(FileSystemHelper.CreateTempDirectory()); foreach (var _loc in allFiles.Distinct()) { string loc = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), _loc); var newloc = Path.Combine(tempFolder, _loc); OpenTap.FileSystemHelper.EnsureDirectory(newloc); if (File.Exists(newloc)) { continue; } File.Copy(loc, newloc); } { // tell TPM Server to start new app. var loc = application ?? Assembly.GetEntryAssembly().Location; if (string.Equals(".dll", Path.GetExtension(loc), StringComparison.OrdinalIgnoreCase)) { //.netcore wierdness. loc = Path.ChangeExtension(loc, "exe"); if (File.Exists(loc) == false) { loc = loc.Substring(0, loc.Length - ".exe".Length); } } var newname = Path.Combine(tempFolder, Path.GetFileName(loc)); newname = $"\"{newname}\""; // there could be whitespace in the name. // now that we start from a different dir, we need to supply a --target argument if (target != null) { newname = $"{newname} --target \"{target}\""; } tpmClient.MessageServer("run " + newname); tpmClient.Dispose(); } } }