private string PostToSyncServer(string subUrl, string sentXml)
        {
            string result = "";

            try
            {
                string str     = SocketTool.GetUrl();
                string url_Imp = SocketTool.GetUrl_Imp();
                if (MeetingID.ToLower().StartsWith("i"))
                {
                    str = url_Imp;
                }
                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(str + subUrl);
                byte[]         bytes          = Encoding.UTF8.GetBytes(sentXml);
                httpWebRequest.Method        = "POST";
                httpWebRequest.ContentType   = "text/xml; encoding='utf-8'";
                httpWebRequest.ContentLength = bytes.Length;
                Stream requestStream = httpWebRequest.GetRequestStream();
                requestStream.Write(bytes, 0, bytes.Length);
                requestStream.Close();
                WebResponse response = httpWebRequest.GetResponse();
                requestStream = response.GetResponseStream();
                StreamReader streamReader = new StreamReader(requestStream);
                result = streamReader.ReadToEnd();
                streamReader.Close();
                requestStream.Close();
                response.Close();
                return(result);
            }
            catch (Exception ex)
            {
                LogTool.Debug(ex);
                return(result);
            }
        }
Exemple #2
0
        private static void Init_Instance(string _MeetingID, string _UserID, string _UserName, bool InitToSync)
        {
            UserName  = _UserName;
            MeetingID = _MeetingID;
            _UserID   = Socket_FixEmailUserID.ToSocket(_UserID);
            UserID    = _UserID;
            ClearInstance();
            string str     = SocketTool.GetUrl();
            string url_Imp = SocketTool.GetUrl_Imp();

            if (_MeetingID.ToLower().StartsWith("i"))
            {
                str = url_Imp;
            }
            instance = new SocketClient(str + "/JoinSyncServer", _MeetingID, 100, _UserID, _UserName, InitToSync, 2, "12");
            if (ReaderEvent != null)
            {
                instance.AddEventManager(ReaderEvent);
            }
            instance.AddEventManager(OpenEventList);
            instance.AddCloseEventManager(CloseEventList);
            if (CS_0024_003C_003E9__CachedAnonymousMethodDelegate3 == null)
            {
                CS_0024_003C_003E9__CachedAnonymousMethodDelegate3 = new ThreadStart(_003CInit_Instance_003Eb__2);
            }
            thread = new Thread(CS_0024_003C_003E9__CachedAnonymousMethodDelegate3);
            thread.IsBackground = false;
            thread.Start();
            for (int i = 0; i < 10; i++)
            {
                if (instance != null && instance.GetIsConnected())
                {
                    return;
                }
                Thread.Sleep(10);
            }
            if (instance == null || !instance.GetIsConnected())
            {
                instance = null;
            }
        }
Exemple #3
0
        private string PostToSyncServer(string subUrl, string sentXml)
        {
            string getXml = "";

            try
            {
                string SyncServerUrl     = SocketTool.GetUrl();
                string SyncServerUrl_Imp = SocketTool.GetUrl_Imp();
                if (MeetingID.ToLower().StartsWith("i") == true)
                {
                    SyncServerUrl = SyncServerUrl_Imp;
                }

                HttpWebRequest request  = (HttpWebRequest)WebRequest.Create(SyncServerUrl + subUrl);
                string         data     = sentXml;
                byte[]         postData = Encoding.UTF8.GetBytes(data);

                request.Method        = "POST";
                request.ContentType   = "text/xml; encoding='utf-8'";
                request.ContentLength = postData.Length;

                Stream dataStream = request.GetRequestStream();
                dataStream.Write(postData, 0, postData.Length);
                dataStream.Close();

                WebResponse response = request.GetResponse();
                dataStream = response.GetResponseStream();
                StreamReader reader = new StreamReader(dataStream);
                getXml = reader.ReadToEnd();
                reader.Close();
                dataStream.Close();
                response.Close();
            }
            catch (Exception ex)
            {
                LogTool.Debug(ex);
            }

            return(getXml);
        }
Exemple #4
0
        private static void Init_Instance(string _MeetingID, string _UserID, string _UserName, bool InitToSync)
        {
            UserName  = _UserName;
            MeetingID = _MeetingID;
            _UserID   = Socket_FixEmailUserID.ToSocket(_UserID);
            UserID    = _UserID;
            ClearInstance();
            //if (thread != null)
            //{
            //    thread.Abort();
            //}
            //if (instance != null)
            //{
            //    instance = null;
            //}

            // new SocketClient(syncServerUrl, meetingId, maxClient, clientId, clientName, isSync, clientType, func, true);
            // clientType 2是PC
            string SyncServerUrl     = SocketTool.GetUrl();
            string SyncServerUrl_Imp = SocketTool.GetUrl_Imp();

            if (_MeetingID.ToLower().StartsWith("i") == true)
            {
                SyncServerUrl = SyncServerUrl_Imp;
            }
            instance = new SocketClient(SyncServerUrl + "/JoinSyncServer", _MeetingID, 100, _UserID, _UserName, InitToSync, 2, "12");
            if (ReaderEvent != null)
            {
                instance.AddEventManager(ReaderEvent);
            }
            instance.AddEventManager(OpenEventList);
            instance.AddCloseEventManager(CloseEventList);


            thread = new Thread(delegate()
            {
                try
                {
                    //run()方法是無窮迴圈,所以要開Thread去跑
                    if (instance != null)
                    {
                        instance.run();
                    }
                }
                catch (Exception ex)
                {
                    LogTool.Debug(ex);
                }
            });
            thread.IsBackground = true;
            thread.Start();

            // 延遲一下,等待IEventManager.run 開始跑。
            //Thread.Sleep(100);

            int i = 0;

            while (i < 10)
            {
                if (instance != null && instance.GetIsConnected() == true)
                {
                    return;
                }

                Thread.Sleep(10);

                i++;
            }

            if (instance == null || instance.GetIsConnected() == false)
            {
                instance = null;
            }
        }