コード例 #1
0
 public AsynchronousSocketListener(ILogWriter writerParam, IDMSHandler handler) : base(writerParam, handler)
 {
 }
コード例 #2
0
        protected AbstractDMSListener(ILogWriter writerParam, IDMSHandler handler)
        {
            this.Handler = handler;
            this.Writer  = writerParam ?? new ConsoleLogWriter()
            {
            };
            this.trWorker = new Thread(() =>
            {
                while (running)
                {
                    SessionDesc nextSessionDesc = sessions.RetrieveNextUnworkedSession();
                    if (nextSessionDesc != null)
                    {
                        IDictionary <string, dynamic> input_payload = nextSessionDesc.Payload;
                        IDictionary <string, object> ret            = nextSessionDesc.ReturnMap;
                        IDictionary <string, object> payload        = new Dictionary <string, object>();
                        ret[KEY_PAYLOAD] = payload;
                        try
                        {
                            switch (nextSessionDesc.Command)
                            {
                            case "insert":
                                {
                                    string filepath  = input_payload[KEY_FILEPATH];
                                    string originKey = input_payload[KEY_ORIGINKEY];
                                    IDictionary <String, String> metadata = ReadMetadata(input_payload);

                                    Writer.WriteMessage(String.Format("inserting; file '{0}', originkey: '{1}'", filepath, originKey));
                                    DMSDocument selDocument = Handler.InsertDocument(originKey, filepath, metadata);
                                    if (selDocument != null)
                                    {
                                        Writer.WriteMessage(String.Format("returned document '{0}'", selDocument));
                                        payload[KEY_DMSID]        = selDocument.Id;
                                        payload[KEY_DOCUMENTNAME] = selDocument.Name;
                                        payload[KEY_ORIGINKEY]    = originKey;
                                        ret[KEY_STATUS]           = KEY_STATUS_OK;
                                    }
                                    else
                                    {
                                        ret[KEY_STATUS] = KEY_STATUS_CANCEL;
                                    }
                                    nextSessionDesc.Status = SessionDesc.SessionStatus.DONE;
                                }
                                break;

                            case "attach":
                                {
                                    string originKey = input_payload[KEY_ORIGINKEY];
                                    IDictionary <String, String> metadata = ReadMetadata(input_payload);

                                    Writer.WriteMessage(String.Format("attaching; originkey: '{0}'", originKey));
                                    DMSDocument selDocument = Handler.AttachDocument(originKey, metadata);
                                    if (selDocument != null)
                                    {
                                        Writer.WriteMessage(String.Format("returned document '{0}'", selDocument));
                                        payload[KEY_DMSID]        = selDocument.Id;
                                        payload[KEY_DOCUMENTNAME] = selDocument.Name;
                                        payload[KEY_ORIGINKEY]    = originKey;
                                        ret[KEY_STATUS]           = KEY_STATUS_OK;
                                    }
                                    else
                                    {
                                        ret[KEY_STATUS] = KEY_STATUS_CANCEL;
                                    }
                                    nextSessionDesc.Status = SessionDesc.SessionStatus.DONE;
                                }
                                break;

                            case "show":
                                {
                                    string idOfFileInDMS_show  = input_payload[KEY_DMSID];
                                    string nameOfDMSDocument   = input_payload[KEY_DOCUMENTNAME];
                                    string originKey           = input_payload[KEY_ORIGINKEY];
                                    DMSDocument documentToShow = new DMSDocument(idOfFileInDMS_show, nameOfDMSDocument);
                                    Writer.WriteMessage(String.Format("show document '{0}'", documentToShow));
                                    Handler.ShowDocument(documentToShow);
                                    ret[KEY_STATUS]        = KEY_STATUS_OK;
                                    nextSessionDesc.Status = SessionDesc.SessionStatus.DONE;
                                }
                                break;

                            default:
                                {
                                }
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            LOG.Error("processing error on session " + nextSessionDesc.Key + ": " + ex.Message, ex);
                            Writer.WriteMessage("processing error on session " + nextSessionDesc.Key + ": " + ex.Message);
                            ret[KEY_STATUS]    = "FAIL";
                            ret[KEY_ERRORTEXT] = ex.Message;
                        }
                    }
                }
            }
                                       )
            {
                IsBackground = true
            };
            trWorker.Start();
        }