Pudge 24 Posted September 20, 2022 Share Posted September 20, 2022 Hi all, i using class robotManager methods.Helpful.Settings for for communication wrobot windows on same PC. Very often in log i see the error like "Serialize(String path, object @object)#3: Cannot write file." when calling a method robotManager methods.Helpful.Settings .Save(). How can I avoid this? Link to comment https://wrobot.eu/forums/topic/14775-settings-question/ Share on other sites More sharing options...
Droidz 2738 Posted September 21, 2022 Share Posted September 21, 2022 Hi, in relogger I use Mutex class : https://stackoverflow.com/questions/30205648/how-to-have-processes-not-threads-in-c-sharp-synchronize-file-system-access Link to comment https://wrobot.eu/forums/topic/14775-settings-question/#findComment-66689 Share on other sites More sharing options...
Pudge 24 Posted September 21, 2022 Author Share Posted September 21, 2022 3 hours ago, Droidz said: Hi, in relogger I use Mutex class : https://stackoverflow.com/questions/30205648/how-to-have-processes-not-threads-in-c-sharp-synchronize-file-system-access I cant understand why file not owerwriting. Whot i need to change to unlock file. File with settings using at same time by 10+ wrobot windows, but error does not always appear. is there an option to 100% unlock the file before saving? Link to comment https://wrobot.eu/forums/topic/14775-settings-question/#findComment-66691 Share on other sites More sharing options...
Pudge 24 Posted September 21, 2022 Author Share Posted September 21, 2022 Mutex is only used in relogger? The fact is that this error happens both in the relogger and in the wrobot Link to comment https://wrobot.eu/forums/topic/14775-settings-question/#findComment-66692 Share on other sites More sharing options...
Pudge 24 Posted September 27, 2022 Author Share Posted September 27, 2022 I still couldn't find a solution. I use settings class to communicate relogger and wrobot windows Link to comment https://wrobot.eu/forums/topic/14775-settings-question/#findComment-66738 Share on other sites More sharing options...
TechMecca 7 Posted September 27, 2022 Share Posted September 27, 2022 Unless you are going to reread all the commands between two clients, its bad practice to write to file to read then just to reread, You should use something like a server to talk together. Link to comment https://wrobot.eu/forums/topic/14775-settings-question/#findComment-66740 Share on other sites More sharing options...
Droidz 2738 Posted September 28, 2022 Share Posted September 28, 2022 You can try to host http server in relogger (with relogger plugin) (you can get/return values (or xml) from it. It's sample of http server, but for wrobot plugin : using System.Net; using System.Text; using System.Threading.Tasks; using robotManager.Helpful; using wManager.Wow.Helpers; using wManager.Wow.ObjectManager; public class Main : wManager.Plugin.IPlugin { /* Samples: http://localhost:8000/name http://localhost:8000/jump http://localhost:8000/pos http://localhost:8000/runlua?code=print(%22test%20from%20web%22) */ private readonly bool _debugLog = true; private HttpListener _listener; private readonly string _url = "http://localhost:8000/"; private int _requestCount; private bool _runServer; public void Initialize() { // Create a Http server and start listening for incoming connections _listener = new HttpListener(); _listener.Prefixes.Add(_url); _listener.Start(); if (_debugLog) Logging.WriteDebug("Listening for connections on " + _url); // Handle requests var listenTask = HandleIncomingConnections(); listenTask.GetAwaiter().GetResult(); } public void Dispose() { if (_listener != null) { _runServer = false; _listener.Close(); _listener = null; } } public void Settings() { } private async Task HandleIncomingConnections() { _runServer = true; // While a user hasn't visited the `shutdown` url, keep on handling requests while (_runServer) { // Will wait here until we hear from a connection var ctx = await _listener.GetContextAsync(); // Peel out the requests and response objects var req = ctx.Request; var resp = ctx.Response; // Print out some info about the request if (_debugLog) { Logging.WriteDebug("Request #: " + ++_requestCount); Logging.WriteDebug(req.Url.ToString()); Logging.WriteDebug(req.HttpMethod); Logging.WriteDebug(req.UserHostName); Logging.WriteDebug(req.UserAgent); Logging.WriteDebug(req.Url.AbsolutePath); } var content = string.Empty; // Parse if (req.Url.AbsolutePath == "/name") { content = ObjectManager.Me.Name; } else if (req.Url.AbsolutePath == "/jump") { Move.JumpOrAscend(); content = "done"; } else if (req.Url.AbsolutePath == "/pos") { content = ObjectManager.Me.Position.ToStringXml(); } else if (req.Url.AbsolutePath.StartsWith("/runlua")) { //var r = System.Web.HttpUtility.ParseQueryString(req.Url.Query).Get("code"); var r = req.QueryString["code"]; if (!string.IsNullOrWhiteSpace(r)) { Lua.LuaDoString(r); content = "ok"; } else content = "failed"; } // Write the response info byte[] data = Encoding.UTF8.GetBytes(content); resp.ContentType = "text/html"; resp.ContentEncoding = Encoding.UTF8; resp.ContentLength64 = data.LongLength; // Write out to the response stream (asynchronously), then close it await resp.OutputStream.WriteAsync(data, 0, data.Length); resp.Close(); } } } happiness7 and Pudge 2 Link to comment https://wrobot.eu/forums/topic/14775-settings-question/#findComment-66742 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now