public static WebexTeamsClient getInstance(string token)
 {
     if (instance == null)
     {
         instance = new WebexTeamsClient(token);
     }
     return(instance);
 }
Exemple #2
0
        // 작업 결과 값을 반환할 경우 CodeActivity<TResult>에서 파생되고
        // Execute 메서드에서 값을 반환합니다.
        protected override void Execute(CodeActivityContext context)
        {
            // 텍스트 입력 인수의 런타임 값을 가져옵니다.
            string accessToken = context.GetValue(this.AccessToken);
            List <WebexTeamsRoom> rooms;
            Int32  errorCode;
            string errorMessage;

            WebexTeamsClient client = WebexTeamsClient.getInstance(accessToken);

            bool success = client.ListRooms(out rooms, out errorCode, out errorMessage);

            context.SetValue(this.ErrorCode, errorCode);
            context.SetValue(this.ErrorMessage, errorMessage);
            context.SetValue(this.Rooms, rooms);
        }
        // 작업 결과 값을 반환할 경우 CodeActivity<TResult>에서 파생되고
        // Execute 메서드에서 값을 반환합니다.
        protected override void Execute(CodeActivityContext context)
        {
            string accessToken = context.GetValue(this.AccessToken);
            string roomId      = context.GetValue(this.RoomId);
            string personEmail = context.GetValue(this.PersonEmail);

            WebexTeamsMemberships membership;
            Int32  errorCode;
            string errorMessage;

            WebexTeamsClient client  = WebexTeamsClient.getInstance(accessToken);
            bool             success = client.AddMemberships(roomId, personEmail, out membership, out errorCode, out errorMessage);

            context.SetValue(this.ErrorCode, errorCode);
            context.SetValue(this.ErrorMessage, errorMessage);
            //context.SetValue(this.Message, message);
        }
Exemple #4
0
        // 작업 결과 값을 반환할 경우 CodeActivity<TResult>에서 파생되고
        // Execute 메서드에서 값을 반환합니다.
        protected override void Execute(CodeActivityContext context)
        {
            string accessToken = context.GetValue(this.AccessToken);
            string title       = context.GetValue(this.RoomTitle);
            string teamId      = context.GetValue(this.TeamId);

            WebexTeamsRoom room;
            Int32          errorCode;
            string         errorMessage;

            WebexTeamsClient client  = WebexTeamsClient.getInstance(accessToken);
            bool             success = client.CreateRoom(teamId, title, out room, out errorCode, out errorMessage);

            context.SetValue(this.ErrorCode, errorCode);
            context.SetValue(this.ErrorMessage, errorMessage);
            context.SetValue(this.Room, room);
        }
Exemple #5
0
        // 작업 결과 값을 반환할 경우 CodeActivity<TResult>에서 파생되고
        // Execute 메서드에서 값을 반환합니다.
        protected override void Execute(CodeActivityContext context)
        {
            string accessToken = context.GetValue(this.AccessToken);
            string roomId      = context.GetValue(this.RoomId);
            string text        = context.GetValue(this.Text);
            string filePath    = context.GetValue(this.FilePath);

            WebexTeamsMessage message;
            Int32             errorCode;
            string            errorMessage;

            WebexTeamsClient client  = WebexTeamsClient.getInstance(accessToken);
            bool             success = client.SendMessage(roomId, text, filePath, out message, out errorCode, out errorMessage);

            context.SetValue(this.ErrorCode, errorCode);
            context.SetValue(this.ErrorMessage, errorMessage);
            context.SetValue(this.Message, message);
        }
        /**
         * 메세지를 전송한다. Text 메시지 및 로컬 파일을 포함한 이미지 전송이 가능하다.
         */
        public bool SendMessage(string roomId, string text, string filePath, out WebexTeamsMessage message, out Int32 errorCode, out string errorMessage)
        {
            bool status = true;

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(MESSAGE_ENDPOINT);

            request.Headers.Add("Authorization", string.Format("Bearer {0}", WebexTeamsClient.accessToken));
            request.Method = "POST";

            try
            {
                Dictionary <string, object> postParameters = new Dictionary <string, object>();
                postParameters.Add("roomId", roomId);
                if (!string.IsNullOrEmpty(text))
                {
                    postParameters.Add("text", text);
                }
                string formDataBoundary = String.Format("----------{0:N}", Guid.NewGuid());
                string contentType      = "multipart/form-data; boundary=" + formDataBoundary;
                request.ContentType = contentType;

                if (!string.IsNullOrEmpty(filePath))
                {
                    try
                    {
                        FileInfo imgFile = new FileInfo(filePath);
                        if (imgFile.Exists && imgFile.Length > 0)
                        {
                            byte[] imgData = new byte[imgFile.Length];
                            imgData = File.ReadAllBytes(imgFile.FullName);
                            if (imgData.Length > 0)
                            {
                                postParameters.Add("files", new FileParameter(imgData, imgFile.Name, WebexTeamsClient.getMediaType(imgFile.Name)));
                            }
                        }
                    }
                    catch (IOException ioe)
                    {
                        System.Console.WriteLine(ioe.Message);
                    }
                }

                byte[] formData    = GetMultipartFormData(postParameters, formDataBoundary);
                Stream inputStream = request.GetRequestStream();
                inputStream.Write(formData, 0, formData.Length);
                inputStream.Close();

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    Stream            stream = response.GetResponseStream();
                    StreamReader      reader = new StreamReader(stream, Encoding.UTF8);
                    WebexTeamsMessage result = JsonConvert.DeserializeObject <WebexTeamsMessage>(reader.ReadToEnd());
                    errorCode    = (int)HttpStatusCode.OK;
                    errorMessage = "OK";
                    message      = result;
                }
                else
                {
                    Stream       stream = response.GetResponseStream();
                    StreamReader reader = new StreamReader(stream, Encoding.UTF8);
                    JObject      resp   = JObject.Parse(reader.ReadToEnd());
                    errorCode    = (int)response.StatusCode;
                    errorMessage = resp["message"].ToString();
                    message      = null;
                    status       = false;
                }
            }
            catch (System.Exception e)
            {
                System.Console.WriteLine("Error Message : " + e.Message);
                errorCode    = -1;
                errorMessage = e.Message;
                message      = null;
                status       = false;
            }

            return(status);
        }