static void Main(string[] args)
        {
            var api = new DefaultApi("http://petstore.swagger.io/v2/");
            api.Configuration.ApiKey.Add("api-key","special-key");

            var pet = api.FindPetById(1);

            Console.WriteLine("Found {0} pet.", pet == null ? "no" : pet.Name);
            Console.ReadLine();
        }
示例#2
0
 internal static bool SetChatTitle(int chatId, string chatTitle)
 {
     DefaultApi api = new DefaultApi("http://localhost:8080/api/");
     AccountManager lm = AccountManager.GetInstance();
     return api.UpdateChat(lm.Token, chatId, chatTitle).Value;
 }
示例#3
0
 public static bool UpdateUser(string token, string username, string password, string email, string displayName)
 {
     DefaultApi api = new DefaultApi("http://localhost:8080/api/");
     AccountManager lm = AccountManager.GetInstance();
     var ret = api.UpdateUser(lm.Token, username, password, email, displayName).Value;
     UpdateProfile();
     return ret;
 }
示例#4
0
        public static IO.Swagger.Model.UserProfile UpdateProfile()
        {
            AccountManager lm = AccountManager.GetInstance();
            DefaultApi api = new DefaultApi("http://localhost:8080/api/");

            IO.Swagger.Model.UserProfile profile = new IO.Swagger.Model.UserProfile();
            profile = api.GetMyProfile(lm.Token);
            lm.UserId = profile.UserId.Value;
            lm.Username = profile.Username;
            lm.DisplayName = profile.DisplayName;
            lm.Email = profile.Email;

            return profile;
        }
示例#5
0
 public static IO.Swagger.Model.Message SendChatMessage(int chatId, string message)
 {
     AccountManager lm = AccountManager.GetInstance();
     DefaultApi api = new DefaultApi("http://localhost:8080/api/");
     return api.SendChatMessage(chatId, message, lm.Token);
 }
示例#6
0
 public static bool RegisterUser(string username, string password, string email = null, string displayName = null)
 {
     DefaultApi api = new DefaultApi("http://localhost:8080/api/");
     var result = api.RegisterUserWithHttpInfo(username, password, email, displayName);
     return result.Data == "true";
 }
示例#7
0
        public static bool LoginUser(string username, string password)
        {
            DefaultApi api = new DefaultApi("http://localhost:8080/api/");

            AccountManager lm = AccountManager.GetInstance();
            lm.Token = api.LoginUser(username, password);
            lm.Password = password;

            UpdateProfile();

            return true;
        }
示例#8
0
 public static IO.Swagger.Model.Friend AddFriend(string username)
 {
     AccountManager lm = AccountManager.GetInstance();
     DefaultApi api = new DefaultApi("http://localhost:8080/api/");
     return api.AddFriend(username, lm.Token);
 }
示例#9
0
 public static IO.Swagger.Model.UserProfile GetProfileById(int userId)
 {
     AccountManager lm = AccountManager.GetInstance();
     DefaultApi api = new DefaultApi("http://localhost:8080/api/");
     return api.GetProfileById(userId, lm.Token);
 }
示例#10
0
        public static List<IO.Swagger.Model.Friend> GetFriendList()
        {
            List<IO.Swagger.Model.Friend> friends = new List<IO.Swagger.Model.Friend>();

            try
            {
                AccountManager lm = AccountManager.GetInstance();
                DefaultApi api = new DefaultApi("http://localhost:8080/api/");
                friends = api.GetMyFriends(lm.Token);
            }
            catch (ApiException e)
            {

            }

            return friends;
        }
示例#11
0
 public static List<IO.Swagger.Model.Message> GetChatMessages(int chatId)
 {
     AccountManager lm = AccountManager.GetInstance();
     DefaultApi api = new DefaultApi("http://localhost:8080/api/");
     return api.GetChatMessages(chatId, lm.Token);
 }
示例#12
0
 public static List<IO.Swagger.Model.Chat> GetChatList()
 {
     AccountManager lm = AccountManager.GetInstance();
     DefaultApi api = new DefaultApi("http://localhost:8080/api/");
     return api.GetChats(lm.Token);
 }
示例#13
0
        public static bool DeleteFriend(int id)
        {
            try
            {
                AccountManager lm = AccountManager.GetInstance();
                DefaultApi api = new DefaultApi("http://localhost:8080/api/");
                return api.DeleteFriend(id, lm.Token).Value;
            }
            catch (ApiException e)
            {
            }

            return false;
        }
示例#14
0
 public static int CreateChatGroup(string chatName)
 {
     AccountManager lm = AccountManager.GetInstance();
     DefaultApi api = new DefaultApi("http://localhost:8080/api/");
     return api.CreateChatGroup(new List<int?>() { lm.UserId }, chatName, lm.Token).Value;
 }
示例#15
0
        private void PerformSave()
        {
            ErrorMessage = "";

            var am = AccountManager.GetInstance();

            bool usernameChanged = Username != am.Username;
            bool passwordChanged = Password != "" && Password == PasswordConfirm && Password == am.Password;
            bool emailChanged = Email != am.Email;
            bool displayNameChanged = DisplayName != am.DisplayName;

            try
            {
                // Continue with registration process
                DefaultApi api = new DefaultApi("http://localhost:8080/api/");

                bool ret = false;
                ret = AccountManager.UpdateUser(AccountManager.GetInstance().Token,
                    usernameChanged ? Username : null,
                    passwordChanged ? Password : null,
                    emailChanged ? Email : null,
                    displayNameChanged ? DisplayName : null);

                if (ret)
                {
                    // Get out of registration screen now that we're registered
                    ViewPresenter.PopView();
                }
            }
            catch (ApiException e)
            {
                var error = ErrorCodes.TranslateError(e.ErrorContent);
                ErrorMessage = error.Message;
            }
        }
示例#16
0
 public static bool InviteUserToChat(int chatId, string username)
 {
     AccountManager lm = AccountManager.GetInstance();
     DefaultApi api = new DefaultApi("http://localhost:8080/api/");
     return api.InviteUserToChat(chatId, username, lm.Token).Value;
 }
示例#17
0
        private void UpdateChat()
        {
            DefaultApi api = new DefaultApi("http://localhost:8080/api/");
            AccountManager lm = AccountManager.GetInstance();

            var chatInfo = AccountManager.GetChatInfo(ChatId);
            var chatMessages = AccountManager.GetChatMessages(ChatId);

            ChatTitle = chatInfo.ChatTitle;
            ChatId = chatInfo.Id.Value;

            string chatLog = "";
            foreach(var message in chatMessages)
            {
                var profile = AccountManager.GetProfileById(message.UserId.Value);
                var displayName = profile.DisplayName;
                chatLog += String.Format("[{0}] {1}: {2}", message.Timestamp, displayName, message._Message) + Environment.NewLine;
            }
            ChatLog = chatLog;

            if(_chatScrollViewer != null)
            {
                _chatScrollViewer.ScrollToBottom();
            }

            if (_chatlist != null)
            {
                _chatlist.Items.Clear();
                foreach (var userId in chatInfo.Users)
                {
                    var profile = AccountManager.GetProfileById(userId.Value);
                    Views.FriendListEntry entry = new Views.FriendListEntry(userId.Value, profile.DisplayName, profile.Username);
                    _chatlist.Items.Add(entry);
                }
            }
        }