Esempio n. 1
0
        public void Dispatcher_Send_Factory()
        {
            var container = Container.Create();

            container.Register <DummyInvoker>(Scope.Singleton);
            container.RegisterFactory <CustomHandlerFactory>();
            container.RegisterEvent <ICustomHandler, CustomArgs>((handler, args) => handler.OnCustomEvent(args));

            var invoker = container.Resolve <DummyInvoker>();
            var factory = container.Resolve <CustomHandlerFactory>();

            var eventHandler = factory.Create <CustomHandler>();

            var expectedValue = new CustomArgs
            {
                flag = true,
                id   = 9,
                name = "shine"
            };

            invoker.RaiseEvent(expectedValue);

            var actualValue = eventHandler.ReceivedArgs;

            Assert.AreEqual(expectedValue, actualValue);
        }
Esempio n. 2
0
    private void register_account(HttpListenerRequest request, HttpListenerResponse response)
    {
        string respone_str = String.Empty;
        string account     = request.QueryString["account"];
        string password    = request.QueryString["password"];

        if (account == null || password == null)
        {
            Dictionary <string, object> body = new Dictionary <string, object>();
            body.Add("err_str", "account or password is null");
            RES_Common res = new RES_Common();
            res.errcode = 1;
            res.errmsg  = "account or password is null";
            respone_str = JsonConvert.SerializeObject(respone_str);
            send(respone_str, response);
            return;
        }

        CustomArgs args = new CustomArgs();

        args.AddParam("response", response);
        args.AddParam("account", account);
        args.AddParam("password", password);
        _DBHandler.addTask(db_register_account, args);
    }
Esempio n. 3
0
    /// <summary>
    /// 注册
    /// </summary>
    /// <param name="conn"></param>
    /// <param name="args"></param>
    public void db_register_account(MySqlConnection conn, CustomArgs args)
    {
        HttpListenerResponse response = args.GetParam("response") as HttpListenerResponse;
        string            account     = args.GetParam("account") as string;
        string            password    = args.GetParam("password") as string;
        DBStoredProcedCmd cmd         = new DBStoredProcedCmd("PRO_REGISTER_ACCOUNT", conn);

        cmd.AddParamVChar("account", account, account.Length);
        cmd.AddParamVChar("password", password, password.Length);
        string md5 = LibServer.Utility.Security.MD5(account + password + DateTime.Now.ToString());

        cmd.AddParamVChar("token", md5, md5.Length);
        cmd.AddOutParamInt("errcode");
        cmd.AddOutParamText("errmsg", LOGIN_DEFINE.VAR_CHAR_LENGHT_255);
        int bsuc = cmd.Execute();

        if (bsuc == 0)
        {
            RES_Common res = new RES_Common();
            res.errcode = (int)cmd.GetParam("errcode").Value;

            res.errmsg = cmd.GetParam("errmsg").Value as string;

            send(JsonConvert.SerializeObject(res), response);
            return;
            // 注册成功;
        }
        else
        {
            throw new Exception("执行存储过程 PRO_REGISTER_ACCOUNT 失败!");
        }
    }
Esempio n. 4
0
        public void Dispatcher_Handle_YieldInstruction()
        {
            var container = Container.Create();

            container.RegisterEvent <CustomArgs>();

            var dispatcher  = container.Resolve <Dispatcher>();
            var instruction = dispatcher.CreateYieldInstruction <CustomArgs>();

            var expectedValue = new CustomArgs
            {
                flag = true,
                id   = 9,
                name = "shine"
            };

            Assert.IsNull(instruction.Current);

            instruction.MoveNext();

            Assert.IsNull(instruction.Current);

            dispatcher.Send(expectedValue);

            Assert.IsNull(instruction.Current);

            instruction.MoveNext();

            var actualValue = instruction.Current;

            Assert.AreEqual(expectedValue, actualValue);
        }
Esempio n. 5
0
        public void Dispatcher_Handle_Callback()
        {
            var container = Container.Create();

            container.RegisterEvent <CustomArgs>();

            var dispatcher = container.Resolve <Dispatcher>();

            var expectedValue = new CustomArgs
            {
                flag = true,
                id   = 9,
                name = "shine"
            };

            CustomArgs actualValue = null;

            dispatcher.Subscribe <CustomArgs>(eventArgs =>
            {
                actualValue = eventArgs;
            });

            dispatcher.Send(expectedValue);

            Assert.AreEqual(expectedValue, actualValue);
        }
Esempio n. 6
0
 public void AddCustomArgs(string key, string value)
 {
     if (CustomArgs == null)
     {
         CustomArgs = new Dictionary <string, string>();
     }
     CustomArgs.Add(key, value);
 }
Esempio n. 7
0
        /// <summary>
        /// 二进制消息
        /// </summary>
        void OnBinaryMessage(ClientSession session, ByteBuffer buffer)
        {
            string token = buffer.ReadString();

            CustomArgs args = new CustomArgs();

            args.AddParam("token", token);
            args.AddParam("session", session);
            DBUtil.Instance.RequestDB(this, args);
        }
 public void AddCustomArg(string customArgKey, string customArgValue)
 {
     if (CustomArgs.ContainsKey(customArgKey))
     {
         CustomArgs[customArgKey] = customArgValue;
     }
     else
     {
         CustomArgs.Add(customArgKey, customArgValue);
     }
 }
Esempio n. 9
0
        protected virtual void ReadyCustomArgs()
        {
            if (CustomArgs == null)
            {
                CustomArgs = "";
            }

            if (CustomArgs != "" && !CustomArgs.EndsWith(" "))
            {
                CustomArgs = CustomArgs + " ";
            }
        }
Esempio n. 10
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="conn"></param>
    /// <param name="args"></param>
    public void db_login_account(MySqlConnection conn, CustomArgs args)
    {
        HttpListenerResponse response = args.GetParam("response") as HttpListenerResponse;
        string account  = args.GetParam("account") as string;
        string password = args.GetParam("password") as string;

        if (response == null)
        {
            return;
        }
        DBStoredProcedCmd cmd = new DBStoredProcedCmd("PRO_LOGIN_ACCOUNT", conn);

        cmd.AddParamVChar("account", account, account.Length);
        cmd.AddParamVChar("password", password, password.Length);
        string md5 = LibServer.Utility.Security.MD5(account + password + DateTime.Now.ToString());

        cmd.AddParamVChar("token", md5, md5.Length);
        cmd.AddOutParamInt("errcode");
        cmd.AddOutParamText("errmsg", LOGIN_DEFINE.VAR_CHAR_LENGHT_255);
        int bsuc = cmd.Execute();

        if (bsuc == 0)
        {
            int    nErrCode   = (int)cmd.GetParam("errcode").Value;
            string err_string = cmd.GetParam("errmsg").Value as string;
            if (nErrCode != 0)
            {
                RES_Common res = new RES_Common();
                res.errcode = nErrCode;
                res.errmsg  = err_string;
                send(JsonConvert.SerializeObject(res), response);
            }
            else
            {
                // 账号密码校验成功, 返回登录token
                RES_LoginSuc res = new RES_LoginSuc();
                res.errcode    = 0;
                res.errmsg     = "";
                res.token      = cmd.GetValue(0, "token") as string;;
                res.tokenstamp = (System.DateTime)cmd.GetValue(0, "tokenstamp");
                send(JsonConvert.SerializeObject(res), response);
            }
        }
        else
        {
            throw new Exception("执行存储过程 PRO_LOGIN_ACCOUNT 失败!");
        }
    }
Esempio n. 11
0
    private void login_account(HttpListenerRequest request, HttpListenerResponse response)
    {
        string account  = request.QueryString["account"];
        string password = request.QueryString["password"];

        if (account == null || password == null)
        {
            RES_Common res = new RES_Common();
            res.errcode = 1;
            res.errmsg  = "账号或密码不存在";
            send(JsonConvert.SerializeObject(res), response);
            return;
        }

        CustomArgs args = new CustomArgs();

        args.AddParam("response", response);
        args.AddParam("account", account);
        args.AddParam("password", password);
        _DBHandler.addTask(db_login_account, args);
    }
Esempio n. 12
0
        public void OnDBTask(MySqlConnection conn, CustomArgs args)
        {
            string        token   = args.GetParam("token") as string;
            ClientSession session = args.GetParam("session") as ClientSession;

            DBBase.DBStoredProcedCmd cmd = new DBBase.DBStoredProcedCmd("PRO_CHECK_LOGIN", conn);
            cmd.AddParamVChar("token", token, token.Length);
            int bSuc = cmd.Execute();

            if (bSuc == 0)
            {
                string     account = cmd.GetValue(0, "account") as string;
                int        nGold   = (int)cmd.GetValue(0, "gold");
                ByteBuffer buffer  = new ByteBuffer();
                buffer.WriteString(account);
                buffer.WriteInt(nGold);
                UserUtil.Add(session.uid, session);
                SocketUtil.SendMessage(session, Protocal.Login, buffer);
                return;
            }
        }
Esempio n. 13
0
        public void Dispatcher_Send_Singleton_Shortcut()
        {
            var container = Container.Create();

            container.Register <ICustomHandler, CustomHandler>(Scope.Singleton);
            container.Register <DummyInvoker>(Scope.Singleton);
            container.RegisterEvent <ICustomHandler, CustomArgs>();

            var invoker      = container.Resolve <DummyInvoker>();
            var eventHandler = container.Resolve <ICustomHandler>();

            var expectedValue = new CustomArgs
            {
                flag = true,
                id   = 9,
                name = "shine"
            };

            invoker.RaiseEvent(expectedValue);

            var actualValue = eventHandler.ReceivedArgs;

            Assert.AreEqual(expectedValue, actualValue);
        }
Esempio n. 14
0
        public void Dispatcher_Handle_Callback_Once()
        {
            var container = Container.Create();

            container.RegisterEvent <CustomArgs>();

            var dispatcher = container.Resolve <Dispatcher>();

            var expectedValue = new CustomArgs
            {
                flag = true,
                id   = 9,
                name = "shine"
            };

            CustomArgs actualValue = null;
            int        invokeCount = 0;

            dispatcher.SubscribeOnce <CustomArgs>(eventArgs =>
            {
                actualValue = eventArgs;
                invokeCount++;
            });

            dispatcher.Send(expectedValue);

            dispatcher.Send(new CustomArgs
            {
                flag = false,
                id   = 10,
                name = "shutdown"
            });

            Assert.AreEqual(expectedValue, actualValue);
            Assert.AreEqual(1, invokeCount);
        }
Esempio n. 15
0
 /// <summary>
 /// Adds a custom argument to the item
 /// </summary>
 /// <param name="argument"></param>
 public void AddArgument(string argument)
 {
     CustomArgs.Add(argument);
 }
Esempio n. 16
0
 public void OnCustomEvent(CustomArgs eventArgs)
 {
     ReceivedArgs = eventArgs;
 }
        public async void Convert()
        {
            ConvertEnabled = false;
            await Task.Run(() =>
            {
                Log += "===================================\n";
                Log += "Starting new Process\n";
                Log += "===================================\n";


                var currentDirectory   = Path.GetDirectoryName(typeof(MainWindowViewModel).Assembly.Location);
                var resourcesDirectory = $"{currentDirectory}\\Resources";
                var medialnfoFileName  = $"{resourcesDirectory}\\Medialnfo.exe";
                var ffmpegFileName     = $"{resourcesDirectory}\\ffmpeg.exe";
                string videosPath      = Environment.GetFolderPath(Environment.SpecialFolder.MyVideos);

                var item = TsFilesCollection.FirstOrDefault(x => !x.Processed);
                while (item != null)
                {
                    item.Status            = ConvertStatus.InProgress;
                    var medialnfoArguments = $"\"{item.FileName}\"";
                    var infoProcess        = StartProcess(medialnfoFileName, medialnfoArguments);
                    JObject mediaInfo      = JObject.Parse(JsonConvert.SerializeObject(new MediaInfo()));
                    var s = infoProcess.ExitCode.ToString(); //-532459699
                    if (infoProcess.ExitCode == 0)
                    {
                        var res   = infoProcess.StandardOutput.ReadToEnd();
                        var err   = infoProcess.StandardError.ReadToEnd();
                        mediaInfo = JObject.Parse(res);
                    }
                    Log += $"converting file {item.FileName}\n";
                    try
                    {
                        var outputPath = $"{OutputDirectory}\\{Path.ChangeExtension(Path.GetFileName(item.FileName), "mp4")}".Replace("$Videos", videosPath);
                        if (!Directory.Exists(Path.GetDirectoryName(outputPath)))
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
                        }

                        string ffmpegArguments;
                        if (IsDefault)
                        {
                            ffmpegArguments = $"-i \"{item.FileName}\" -y -c:v libx264 -c:a copy  \"{outputPath}\"";
                        }
                        else
                        {
                            ffmpegArguments = CustomArgs.Replace("$InputFile", $"\"{item.FileName}\"");
                            ffmpegArguments = ffmpegArguments.Replace("$VideoBitrate", (mediaInfo["VideoInfo"]["Bitrate"].Value <int>() / 1000).ToString("0k"));
                            ffmpegArguments = ffmpegArguments.Replace("$AudioSamplingRateHz", "44100");
                            ffmpegArguments = ffmpegArguments.Replace("$OutputFile", outputPath);
                            ffmpegArguments = ffmpegArguments.Replace("$Videos", videosPath);
                        }

                        currentProcess = StartProcess(ffmpegFileName, ffmpegArguments, false, false, false);
                        currentProcess.WaitForExit();
                        if (IsDelete)
                        {
                            System.IO.File.Delete(item.FileName);
                        }
                        item.Status = ConvertStatus.Success;
                        Log        += $"converting file {item.FileName} DONE!\n";
                    }
                    catch (Exception ex)
                    {
                        Log        += $"converting file {item.FileName} ERROR!\n";
                        Log        += $"Exception\n{ex.ToString()}\n";
                        item.Status = ConvertStatus.Failed;
                    }
                    item.Processed = true;
                    item           = TsFilesCollection.FirstOrDefault(x => !x.Processed);
                }
                Log           += "===================================\n";
                Log           += "Process Completed\n\n\n";
                ConvertEnabled = true;
            });
        }
 public void RaiseEvent(CustomArgs eventArgs)
 {
     dispatcher.Send(eventArgs);
 }