public void Execute_Click(object sender, EventArgs e)
        {
            if (pluginView.GetModel().Plugin == "")
            {
                MessageBox.Show("Please select a plugin in the list above first.", "PhotoTagStudio", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (currentPicture == null)
            {
                return;
            }

            mainForm.WaitCursor(true);

            PluginWorker worker  = new PluginWorker();
            bool         changes = worker.ProcessFile(currentPicture, pluginView.GetModel());

            if (changes)
            {
                if (!currentPicture.SaveChanges())
                {
                    this.ShowFileVanishedMsg(currentPicture.Filename);
                    mainForm.WaitCursor(false);
                    return;
                }

                FireDataChanged();
            }

            mainForm.WaitCursor(false);
        }
예제 #2
0
        /// <summary>
        /// Implements the plugin business logic.
        /// </summary>
        /// <param name="worker">PluginWorker with the plugin instance properties.</param>
        public override void Execute(PluginWorker worker)
        {
            worker.Prefix = "CacheWorkerPlugin";
            worker.TraceMessage("Test trace nessage");

            var cache = MemoryCache.Default;

            cache.Set("Worker", worker, DateTime.Now.AddMinutes(1));
        }
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker backgroundWorker = (BackgroundWorker)sender;

            PluginWorker worker = new PluginWorker();

            backgroundWorker.ReportProgress(0);

            List <string> filenames = this.GetAllFileList(this.processFilesInSubdirectories);
            int           i         = 0;

            foreach (string filename in filenames)
            {
                i++;
                PictureMetaData pmd;
                if (this.currentPicture != null &&
                    this.currentPicture.Filename == filename)
                {
                    pmd = currentPicture;
                }
                else
                {
                    if (File.Exists(filename))
                    {
                        pmd = new PictureMetaData(filename);
                    }
                    else
                    {
                        backgroundWorker.ReportProgress(i * 100 / filenames.Count);
                        continue;
                    }
                }

                bool breakForeach = false;
                if (worker.ProcessFile(pmd, pluginView.GetModel()))
                {
                    if (!pmd.SaveChanges())
                    {
                        breakForeach = !this.ShowFileVanishedMsg(pmd.Filename);
                    }
                }

                if (pmd != currentPicture)
                {
                    pmd.Close();
                }

                if (breakForeach)
                {
                    break;
                }

                backgroundWorker.ReportProgress(i * 100 / filenames.Count);
            }
        }
예제 #4
0
 public void Init()
 {
     if (_helper.isSecureConnection)
     {
         auth = _helper.GetPlugin("auth");
         if (_helper.Request.HttpMethod == "GET" && _helper.Request.Url.AbsolutePath != "/auth/logout" && _helper.Auth.Status)
         {
             _helper.AnswerRedirect("/chat");
         }
     }
     else
     {
         _helper.AnswerRedirect($"https://{_helper.domainName}{_helper.Request.Url.PathAndQuery}");
     }
 }
예제 #5
0
 public void GetStaticPlugins(PluginWorker controller, ref HelperClass helper)
 {
     string[] staticInclude = controller._GetStaticInclude();
     if (staticInclude != null)
     {
         if (helper.staticPlugins == null)
         {
             helper.staticPlugins = new Hashtable();
         }
         for (int i = 0; i < staticInclude.Length; i++)
         {
             if (!helper.staticPlugins.ContainsKey(staticInclude[i]))
             {
                 helper.staticPlugins.Add(staticInclude[i], ((PluginLoader)staticPlugins[staticInclude[i]]).plugin.GetPluginRefObject());
             }
         }
     }
 }
예제 #6
0
        public void WorkWS(HelperClass _helper)
        {
            _helper.ContextWs.WebSocket.OnMessage += (sender, args) => {
                HelperClass helper = (HelperClass)WSclients[sender];
                var         json   = Newtonsoft.Json.Linq.JObject.Parse(args.Data);
                if (!json.ContainsKey("path") || !json.ContainsKey("type") || !json.ContainsKey("body"))
                {
                    helper.ContextWs.WebSocket.Close(WebSocketSharp.CloseStatusCode.InvalidData, "Invalid message content");
                    return;
                }
                string         path      = (string)json["path"];
                Queue <string> pathSplit = new Queue <string>(path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries));
                if (pathSplit.Count == 0)
                {
                    return;
                }
                ControllerTreeElement tree = controllerTree.SearchWS(ref pathSplit, out string action);
                if (tree != null)
                {
                    ControllerWorker controller = (ControllerWorker)tree.plugin.GetPluginRefObject();
                    try {
                        GetStaticPlugins(controller, ref helper);
                        controller._WorkWS(helper, action, new object[] { (string)json["type"], (string)json["body"] });
                        helper.GetData(controller._GetHelper());

                        if (helper.returnType == ReturnType.DefaultContent)
                        {
                            string bufS = "";
                            ResentContent(ref helper, ref controller, ref bufS);
                            helper.ContextWs.WebSocket.Send(bufS);
                            bufS = null;
                        }
                    }
                    catch (Exception e) {
                        if (helper.ContextWs.WebSocket.IsAlive)
                        {
                            Log.Error("Ошибка обработки сообщения WebSocket", e);
                        }
                    }
                }
            };
            _helper.ContextWs.WebSocket.OnClose += (sender, args) => {
                HelperClass helper = (HelperClass)WSclients[sender];
                WSclients.Remove(sender);
            };

            if (WebSocketInit)
            {
                PluginWorker httpInitPlugin = GetPlugin(WebSocketinitName);
                GetStaticPlugins(httpInitPlugin, ref _helper);
                httpInitPlugin._Work(_helper);
                _helper.GetData(httpInitPlugin._GetHelper());
                if (_helper.Auth.Status)
                {
                    WSclients.Add(_helper.ContextWs.WebSocket, _helper);
                    _helper.ContextWs.WebSocket.Accept();
                    return;
                }
            }
            _helper.ContextWs.WebSocket.Close(WebSocketSharp.CloseStatusCode.Normal, "Unathorized");
        }
예제 #7
0
        public void Work(HelperClass _helper)
        {
            string         path      = $"{_helper.Context.Request.Url.GetComponents(UriComponents.Path, UriFormat.SafeUnescaped)}";
            Queue <string> pathSplit = new Queue <string>(path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries));

            if (pathSplit.Count == 0)
            {
                pathSplit.Enqueue("index");
            }
            ControllerTreeElement tree = controllerTree.Search(ref pathSplit, out string action);

            if (tree != null)
            {
                ControllerWorker controller = (ControllerWorker)tree.plugin.GetPluginRefObject();
                try {
                    if (HTTPinit)
                    {
                        PluginWorker httpInitPlugin = GetPlugin(HTTPinitName);
                        GetStaticPlugins(httpInitPlugin, ref _helper);
                        httpInitPlugin._Work(_helper);
                        _helper.GetData(httpInitPlugin._GetHelper());
                    }
                    GetStaticPlugins(controller, ref _helper);

                    controller._Work(_helper, action);
                    _helper.GetData(controller._GetHelper());

                    _helper.Context.Response.Headers.Add(_helper.Responce.Headers);
                    _helper.Context.Response.StatusCode        = _helper.Responce.StatusCode;
                    _helper.Context.Response.StatusDescription = _helper.Responce.StatusDescription;
                }
                catch (Exception e) {
                    Log.Error("Внутренняя ошибка подключения", e);
                    _helper.Answer500(e);
                }

                if (_helper.returnType == ReturnType.DefaultContent)
                {
                    _helper.Context.Response.ContentType = _helper.Responce.ContentType;

                    string bufS = "";
                    if (_helper.Render.isEnabled)
                    {
                        ResentLayout(ref _helper, ref controller, ref bufS, _helper.Render.layout, true);
                    }
                    else
                    {
                        ResentContent(ref _helper, ref controller, ref bufS);
                    }
                    //byte[] buf; // не работает в данной реализации HttpListenerContext
                    //while (bufS.Length > 0) {
                    //	buf = Encoding.UTF8.GetBytes(bufS.Substring(0, bufS.Length > 16000 ? 16000 : bufS.Length));
                    //	bufS = bufS.Remove(0, bufS.Length > 16000 ? 16000 : bufS.Length);
                    //	helper.Context.Response.OutputStream.Write(buf, 0, buf.Length);
                    //}
                    byte[] buf = Encoding.UTF8.GetBytes(bufS);
                    _helper.Context.Response.ContentLength64 = buf.Length;
                    _helper.Context.Response.OutputStream.Write(buf, 0, buf.Length);
                }
                else if (_helper.returnType == ReturnType.Info)
                {
                    if (_helper.Responce.StatusCode / 100 == 3)
                    {
                        _helper.Context.Response.Redirect(_helper.Responce.RedirectLocation);
                    }
                }
                if (_helper.WShelper.Acts.Count > 0)
                {
                    if (_helper.WShelper.ActsForAll)
                    {
                        foreach (HelperClass WSclient in WSclients.Values)
                        {
                            foreach (WebSocketAct act in _helper.WShelper.Acts)
                            {
                                WSclient.ContextWs.WebSocket.Send(act.Body);
                            }
                        }
                    }
                    else
                    {
                        foreach (HelperClass WSclient in WSclients.Values)
                        {
                            foreach (WebSocketAct act in _helper.WShelper.Acts)
                            {
                                if (act.Recepients.Contains(WSclient.Auth.Login))
                                {
                                    WSclient.ContextWs.WebSocket.Send(act.Body);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                bool resFile = false;
                try {
                    FileInfo fi = new FileInfo($"{baseDirectory.FullName}public{Path.DirectorySeparatorChar}{path.Replace('/', Path.DirectorySeparatorChar)}");
                    if (fi.Exists)
                    {
                        using (FileStream reader = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read)) {
                            resFile = true;
                            int    pos    = fi.Name.LastIndexOf('.') + 1;
                            string format = fi.Name.Substring(pos, fi.Name.Length - pos);
                            if (format == "css")
                            {
                                _helper.Context.Response.ContentType = "text/css";
                            }
                            else if (format == "js")
                            {
                                _helper.Context.Response.ContentType = "text/javascript";
                            }
                            _helper.Context.Response.ContentLength64 = reader.Length;
                            _helper.Context.Response.Headers.Add(HttpResponseHeader.CacheControl, "max-age=86400");
                            reader.CopyTo(_helper.Context.Response.OutputStream, 16384);
                        }
                    }
                    else
                    {
                        resFile = false;
                    }
                }
                catch {
                    resFile = false;
                }
                if (!resFile)
                {
                    _helper.Context.Response.StatusCode        = 404;
                    _helper.Context.Response.StatusDescription = "Not found";
                }
            }
        }