public static IEnumerable <T> ToIEnumerable <T>(this java.util.List list)
    {
        if (list != null)
        {
            java.util.Iterator itr = list.iterator();

            while (itr.hasNext())
            {
                yield return((T)itr.next());
            }
        }
    }
        public ConsumeConcurrentlyStatus consumeMessage(java.util.List list, ConsumeConcurrentlyContext ccc)
        {
            Iterator iterator = list.iterator();

            while (iterator.hasNext())
            {
                try
                {
                    var messageClientExt = iterator.next() as org.apache.rocketmq.common.message.MessageClientExt;

                    var content = Encoding.UTF8.GetString(messageClientExt.getBody());

                    UploadFileObj uploadFileObj = content.ToObj <UploadFileObj>();

                    string objName = null;
                    string mchId   = RedisCache.CreateInstance().Get(ConstCacheKey.GetMchIdKey(uploadFileObj.WxId));
                    if (string.IsNullOrEmpty(mchId))
                    {
                        throw new Exception("未初始化商户Ip");
                    }
                    WechatHelper wechatHelper = new WechatHelper();
                    //图片
                    if (uploadFileObj.MsgType == 3)
                    {
                        byte[] buffer = wechatHelper.GetMsgBigImg(uploadFileObj.LongDataLength, uploadFileObj.MsgId, uploadFileObj.WxId, uploadFileObj.ToWxId, 0, (int)uploadFileObj.LongDataLength);
                        if (buffer != null)
                        {
                            objName = FileStorageHelper.GetObjectName(mchId);
                            FileStorageHelper.Upload(buffer, $"{objName}{uploadFileObj.MsgId}.png");
                        }
                    }
                    //语音
                    else if (uploadFileObj.MsgType == 34)
                    {
                        if (uploadFileObj.Buffer != null)
                        {
                            objName = FileStorageHelper.GetObjectName(mchId);
                            FileStorageHelper.Upload(uploadFileObj.Buffer, $"{objName}{uploadFileObj.MsgId}.silk");
                        }
                    }
                    //视频
                    else if (uploadFileObj.MsgType == 43)
                    {
                        byte[] buffer = wechatHelper.GetVideo(uploadFileObj.WxId, uploadFileObj.ToWxId, uploadFileObj.MsgId, uploadFileObj.LongDataLength, 0, (int)uploadFileObj.LongDataLength);

                        if (buffer != null)
                        {
                            objName = FileStorageHelper.GetObjectName(mchId);
                            FileStorageHelper.Upload(buffer, $"{objName}{uploadFileObj.MsgId}.mp4");
                        }
                    }
                    //Util.Log.Logger.GetLog<UploadOssMessageListener>().Info($"消费Id:{messageClientExt.getMsgId()}--数据:{content}");
                }
                catch (Exception ex)
                {
                    Util.Log.Logger.GetLog <UploadOssMessageListener>().Error(ex);
                    return(ConsumeConcurrentlyStatus.RECONSUME_LATER);
                }
            }



            return(ConsumeConcurrentlyStatus.CONSUME_SUCCESS);
        }
Example #3
0
    // note Awake, Start, Update, etc. made public virtual so can override in extensions

    public virtual void Awake()      // do non-primitive initializations for MonoBehavior's here
    {
        taskHandle    = new EventWaitHandle(false, EventResetMode.ManualReset);
        menuHandle    = new EventWaitHandle(false, EventResetMode.ManualReset);
        sensingHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
        w32Classes    = new W32ClassBatchUnregisterer();
        program       = new Program();
        player        = new Player("Player");
        npc           = new NPC(this, "NPC");
        interaction   = new Interaction(npc, player);
        interaction.setOk(false);          // suppress default Ok's
        // support calling Debug.Log from scripts
        getDisco().eval(
            "Debug = { Log : function (obj) { TextWindow.Program.Log(obj); }}", "DiscoUnity");

        discoThread = new Thread((ThreadStart) delegate {
            try {
                while (discoRunning)
                {
                    // start console if requested
                    if (Console && !formStarted)
                    {
                        formStarted = true;
                        //second parameter is called when the console Form is loaded
                        program.StartWindow(formThread, (sender, evt) => {
                            if (onWindows)
                            {
                                w32Classes.AddWindowClassesRecursively((Control)sender);
                            }
                            formLoaded = true;
                            form.Writer.WriteLine("    DiscoUnity " + VERSION);
                            console = new edu.wpi.disco.Console(null, interaction);
                            interaction.setConsole(console);
                            console.init(getDisco());
                            console.setReader(new Program.ConsoleReader(form));
                            form.shell.shellTextBox.GotFocus += (s, e) => {                             // improve window readability
                                if (!firstPrompt && form.shell.shellTextBox.IsCaretJustBeforePrompt())
                                {
                                    firstPrompt = false;
                                    form.Writer.Write(console.getPrompt());
                                }
                            };
                            interaction.start(true);                             // start console thread
                        });
                    }
                    // do Sensing on Unity thread
                    sensing = true;
                    sensingHandle.WaitOne();
                    sensingHandle.Reset();
                    UpdateDisco(getDisco());               // manage toplevel goals
                    getDisco().tick();                     // update conditions
                    // process player menu choice, if any
                    if (chosen != null)
                    {
                        getDisco().doneUtterance(chosen.task, formatted);
                        done(true, chosen.task, chosen.contributes);
                        chosen    = null;
                        formatted = null;
                    }
                    // process NPC response, if any
                    Agenda.Plugin.Item item = npc.respondIf(interaction, true);
                    if (item != null && !item.task.Equals(npc.getLastUtterance()))
                    {
                        npc.done(interaction, item);
                    }
                    if (Menu)
                    {
                        // update player menu options (including empty)
                        java.util.List newItems = player.generate(interaction);
                        if (!newItems.equals(items))
                        {
                            String [] choices = null;
                            if (!newItems.isEmpty())
                            {
                                choices = new String[newItems.size()];
                                int i   = 0;
                                java.util.Iterator l = newItems.iterator();
                                while (l.hasNext())
                                {
                                    choices[i++] = translate(((Agenda.Plugin.Item)l.next()).task);
                                }
                            }
                            lastMenu = null;                             // block choosing from old menu
                            menu     = choices;
                            items    = newItems;
                            newMenu  = true;
                            menuHandle.WaitOne();                             // execute on Unity thread
                            menuHandle.Reset();
                            lastMenu = choices;
                        }
                    }
                    // sleep for a while
                    Thread.Sleep(Sleep);
                }
            } catch (Exception e) {
                Debug.Log("Disco thread terminating: " + e);
                if (Tracing)
                {
                    Debug.Log(e.ToString());
                }
            }
        });
        discoThread.IsBackground = true;
        discoThread.Priority     = Priority;

        formThread = new Thread((ThreadStart) delegate {
            try {
                /*
                 *      while (true) { // for testing
                 *              program.WriteLine("Echo: " + program.ReadLine());
                 *      }
                 */
                form = program.GetForm();
                java.lang.System.setOut(new java.io.PrintStream(new Program.ConsoleOut(form.Writer), true));
                java.lang.System.setErr(java.lang.System.@out);
            } catch (Exception e) { Debug.Log("Console form thread terminating: " + e); }
        });
        formThread.IsBackground = true;
    }