Beispiel #1
0
        public Model Update(int ModelId, string ModelName, string FilePath, Hash MetaJson)
        {
            RestRequest request = new RestRequest(String.Format("{0}/folders/{1}", ApiPath, Convert.ToString(ModelId), Method.PUT));

            request.AddParameter("api_token", ApiToken);

            if (String.IsNullOrEmpty(ModelName) && !String.IsNullOrEmpty(FilePath))
            {
                request.AddParameter("name", Path.GetFileName(FilePath));
            }
            else
            {
                request.AddParameter("name", ModelName);
            }

            if (!String.IsNullOrEmpty(FilePath))
            {
                request.AddFile("file", FilePath);
            }

            if (MetaJson != null)
            {
                string strMeta = JsonConvert.SerializeObject(MetaJson, TSCloud.serializer_settings());
                request.AddParameter("meta", strMeta);
            }

            try
            {
                IRestResponse httpResponse = RestClient.Execute(request);

                if (httpResponse.StatusCode == HttpStatusCode.OK)
                {
                    Model model = JsonConvert.DeserializeObject <Model>(httpResponse.Content, TSCloud.serializer_settings());
                    model.StatusCode = httpResponse.StatusCode;
                    model.Message    = httpResponse.ErrorMessage;
                    model.SysInfo    = GetSysInfo();

                    return(model);
                }
                else
                {
                    return(new Model(httpResponse.StatusCode, httpResponse.Content));
                }
            }
            catch (Exception ee)
            {
                return(new Model(ee.ToString()));
            }
        }
Beispiel #2
0
        public Newtonsoft.Json.Linq.JObject AuthenticateCenterCode(string UserID, string Password)
        {
            var request = new RestRequest(ApiPath + "/authenticates", Method.POST);

            request.AddParameter("email", UserID);
            request.AddParameter("password", Password);
            request.AddParameter("external", "centercode");
            request.RequestFormat = DataFormat.Json;

            Newtonsoft.Json.Linq.JObject response = new Newtonsoft.Json.Linq.JObject();
            try
            {
                IRestResponse httpResponse = RestClient.Execute(request);

                if (httpResponse.StatusCode == HttpStatusCode.OK)
                {
                    return(JsonConvert.DeserializeObject <Newtonsoft.Json.Linq.JObject>(httpResponse.Content, TSCloud.serializer_settings()));
                }
                else
                {
                    response.Add("error", (int)httpResponse.StatusCode);
                }
            }
            catch (Exception ee)
            {
                response.Add("error", ee.ToString());
            }

            return(response);
        }
Beispiel #3
0
        public Hash UpdateDesktopSettings(Hash settings)
        {
            if (!CheckExpiration())
            {
                throw new Exception("token refresh fails");
            }

            RestRequest request = new RestRequest(String.Format("{0}/profiles/desktop_settings", ApiPath), Method.PUT);

            request.AddParameter("api_token", ApiToken);
            request.AddParameter("desktop_settings", settings.Stringify());

            try
            {
                IRestResponse httpResponse = RestClient.Execute(request);
                Hash          responseHash = JsonConvert.DeserializeObject <Hash>(httpResponse.Content, TSCloud.serializer_settings());

                return(responseHash);
            }
            catch
            {
                return(null);
            }
        }
Beispiel #4
0
        private User Authenticate(string api_token, string refresh_token, long token_expiration)
        {
            RestRequest request = new RestRequest(String.Format("{0}/profiles", ApiPath), Method.GET);

            request.AddParameter("api_token", api_token);

            try
            {
                IRestResponse httpResponse = RestClient.Execute(request);
                if (httpResponse.StatusCode == HttpStatusCode.Unauthorized)
                {
                    return(new User("Unauthorized"));
                }
                User CurrentUser = JsonConvert.DeserializeObject <Datas.User>(httpResponse.Content, TSCloud.serializer_settings());
                RefreshToken           = refresh_token;
                Expiration             = token_expiration;
                ApiToken               = api_token;
                CurrentUser.SysInfo    = GetSysInfo();
                CurrentUser.StatusCode = httpResponse.StatusCode;
                CurrentUser.ApiToken   = api_token;
                this.CurrentUser       = CurrentUser;

                //UserClient UserClient = new UserClient(this);
                //m_users = UserClient.All();

                RefreshThread = new Thread(new RefreshTokenWorker(this).Start);
                RefreshThread.Start();
                return(CurrentUser);
            }
            catch (Exception ee)
            {
                return(new User(ee.ToString()));
            }
        }
Beispiel #5
0
        public List <User> FindAllByEmail(params String[] emails)
        {
            if (emails.Length < 1)
            {
                throw new Exception("emails Required");
            }
            if (!CheckExpiration())
            {
                throw new Exception("token refresh fails");
            }

            RestRequest request = new RestRequest(String.Format("{0}/users", ApiPath), Method.GET);

            request.AddParameter("api_token", ApiToken);
            request.AddParameter("emails", TSUtil.ConvertToStrings(emails));

            try
            {
                IRestResponse httpResponse = RestClient.Execute(request);
                if (httpResponse.StatusCode == HttpStatusCode.OK)
                {
                    Users user_list = JsonConvert.DeserializeObject <Users>(httpResponse.Content, TSCloud.serializer_settings());
                    user_list.All.ForEach(x => x.SysInfo = GetSysInfo());
                    return(user_list.All);
                }
                else
                {
                    return(new List <User>());
                }
            }
            catch (Exception ee)
            {
                throw new Exception(ee.ToString());
            }
        }
Beispiel #6
0
        public Models GetModels(int Page, Ftype ftype, int FolderId, params GetModelsOption[] GetModelsOptions)
        {
            if (!CheckExpiration())
            {
                throw new Exception("token refresh fails");
            }

            RestRequest request = new RestRequest(String.Format("{0}/folders", ApiPath), Method.GET);

            if (ftype == Ftype.Folder)
            {
                request.AddParameter("folder", "true");
            }
            else if (ftype == Ftype.File)
            {
                request.AddParameter("ftype", "file");
            }

            request.AddParameter("api_token", ApiToken);
            if (Page != 0)
            {
                request.AddParameter("page", Page);
            }
            if (FolderId != 0)
            {
                request.AddParameter("parent_id", FolderId);
            }
            if (Configuration["PerPage"] != null)
            {
                request.AddParameter("per_page", Configuration["PerPage"]);
            }

            if (GetModelsOptions.Length > 0)
            {
                foreach (GetModelsOption Option in GetModelsOptions)
                {
                    switch (Option)
                    {
                    case GetModelsOption.OnlyChildren:
                        if (FolderId == 0)
                        {
                            request.AddParameter("root", "true");
                        }
                        request.AddParameter("descendants", "false");
                        break;

                    case GetModelsOption.AllDescendants:
                        request.AddParameter("descendants", "true");
                        break;
                    }
                }
            }

            try
            {
                IRestResponse httpResponse = RestClient.Execute(request);
                Models        models       = JsonConvert.DeserializeObject <Models>(httpResponse.Content, TSCloud.serializer_settings());
                models.Contents.ForEach(x => x.SysInfo = GetSysInfo());

                return(models);
            }
            catch (Exception ee)
            {
                throw ee;
            }
        }
Beispiel #7
0
        public Model Update(Model model)
        {
            if (model.Id == 0)
            {
                throw new Exception("Model ID Required");
            }
            if (!CheckExpiration())
            {
                throw new Exception("token refresh fails");
            }

            RestRequest request = new RestRequest(String.Format("{0}/folders/{1}", ApiPath, Convert.ToString(model.Id)), Method.PUT);

            request.AddParameter("api_token", ApiToken);
            request.AddParameter("name", !String.IsNullOrEmpty(model.Name) || String.IsNullOrEmpty(model.Filepath) ? model.Name : Path.GetFileName(model.Filepath));
            if (!String.IsNullOrEmpty(model.Filepath))
            {
                request.AddFile("file", model.Filepath);
            }
            if (model.Meta != null)
            {
                request.AddParameter("meta", model.Meta.Stringify());
            }
            if (model.Acl != null)
            {
                request.AddParameter("acl", model.Acl.Stringify());
            }
            if (model.Ftype == Ftype.Page)
            {
                request.AddParameter("page", model.Content);
            }
            request.AddParameter("description", model.Description);

            try
            {
                IRestResponse httpResponse = RestClient.Execute(request);
                if (httpResponse.StatusCode == HttpStatusCode.OK)
                {
                    Model model_response = JsonConvert.DeserializeObject <Model>(httpResponse.Content, TSCloud.serializer_settings());
                    model_response.StatusCode = httpResponse.StatusCode;
                    model_response.Message    = httpResponse.ErrorMessage;
                    model_response.SysInfo    = GetSysInfo();

                    return(model_response);
                }
                else
                {
                    return(new Model(httpResponse.Content));
                }
            }
            catch (Exception ee)
            {
                return(new Model(ee.ToString()));
            }
        }
Beispiel #8
0
        public Model Get(int ModelId)
        {
            if (!CheckExpiration())
            {
                throw new Exception("token refresh fails");
            }

            RestRequest request = new RestRequest(String.Format("{0}/folders/{1}", ApiPath, ModelId.ToString()), Method.GET);

            request.AddParameter("api_token", ApiToken);

            try
            {
                IRestResponse httpResponse = RestClient.Execute(request);
                Model         model        = JsonConvert.DeserializeObject <Model>(httpResponse.Content, TSCloud.serializer_settings());

                int owner_id = 0;
                owner_id      = Convert.ToInt32(model.Acl["owner"]);
                model.SysInfo = GetSysInfo();

                return(model);
            }
            catch (Exception ee)
            {
                return(new Model(ee.ToString()));
            }
        }
        public Queue GetQueue(int QueueId)
        {
            if (!CheckExpiration())
            {
                throw new Exception("token refresh fails");
            }

            RestRequest request = new RestRequest(String.Format("{0}/queues/{1}", ApiPath, QueueId), Method.GET);

            request.AddParameter("api_token", ApiToken);

            try
            {
                IRestResponse httpResponse = RestClient.Execute(request);

                if (httpResponse.StatusCode == HttpStatusCode.OK)
                {
                    Queue queue = JsonConvert.DeserializeObject <Queue>(httpResponse.Content, TSCloud.serializer_settings());

                    return(queue);
                }
                else
                {
                    return(new Queue(httpResponse.Content));
                }
            }
            catch (Exception ee)
            {
                throw ee;
            }
        }
Beispiel #10
0
        public Group Create(Group group)
        {
            if (!CheckExpiration())
            {
                throw new Exception("token refresh fails");
            }

            RestRequest request = new RestRequest(String.Format("{0}/groups", ApiPath), Method.POST);

            request.AddParameter("api_token", ApiToken);

            if (!String.IsNullOrEmpty(group.Name))
            {
                request.AddParameter("name", group.Name);
            }
            if (!String.IsNullOrEmpty(group.Description))
            {
                request.AddParameter("description", group.Description);
            }
            if (group.Acl != null)
            {
                request.AddParameter("acl", group.Acl.Stringify());
            }
            if (group.Users != null && group.Users.Count > 0)
            {
                request.AddParameter("user_ids", TSUtil.ConvertToIds(group.Users));
            }
            if (group.ParentId != 0)
            {
                request.AddParameter("parent_id", Convert.ToString(group.ParentId));
            }

            Group created_group = new Group();

            try
            {
                IRestResponse httpResponse = RestClient.Execute(request);
                if (httpResponse.StatusCode == HttpStatusCode.OK)
                {
                    created_group            = JsonConvert.DeserializeObject <Group>(httpResponse.Content, TSCloud.serializer_settings());
                    created_group.StatusCode = httpResponse.StatusCode;

                    return(created_group);
                }
                else
                {
                    created_group.StatusCode = httpResponse.StatusCode;
                    created_group.Message    = httpResponse.ErrorMessage;

                    return(created_group);
                }
            }
            catch (Exception ee)
            {
                return(new Group(Convert.ToString(ee)));
            }
        }
Beispiel #11
0
        public Groups GetGroups(int Page)
        {
            if (!CheckExpiration())
            {
                throw new Exception("token refresh fails");
            }

            RestRequest request = new RestRequest(String.Format("{0}/groups", ApiPath), Method.GET);

            request.AddParameter("api_token", ApiToken);
            if (Page != 0)
            {
                request.AddParameter("page", Page);
            }

            Groups groups = new Groups();

            try
            {
                IRestResponse httpResponse = RestClient.Execute(request);
                if (httpResponse.StatusCode == HttpStatusCode.OK)
                {
                    groups            = JsonConvert.DeserializeObject <Groups>(httpResponse.Content, TSCloud.serializer_settings());
                    groups.StatusCode = httpResponse.StatusCode;

                    return(groups);
                }
                else
                {
                    groups.StatusCode = httpResponse.StatusCode;
                    groups.Message    = httpResponse.ErrorMessage;

                    return(groups);
                }
            }
            catch (Exception ee)
            {
                throw ee;
            }
        }
Beispiel #12
0
        public Group Get(int GroupID)
        {
            if (!CheckExpiration())
            {
                throw new Exception("token refresh fails");
            }

            RestRequest request = new RestRequest(String.Format("{0}/groups/{1}", ApiPath, Convert.ToString(GroupID)), Method.GET);

            request.AddParameter("api_token", ApiToken);

            Group group = new Group();

            try
            {
                IRestResponse httpResponse = RestClient.Execute(request);
                if (httpResponse.StatusCode == HttpStatusCode.OK)
                {
                    group            = JsonConvert.DeserializeObject <Group>(httpResponse.Content, TSCloud.serializer_settings());
                    group.StatusCode = httpResponse.StatusCode;

                    return(group);
                }
                else
                {
                    group.StatusCode = httpResponse.StatusCode;
                    group.Message    = httpResponse.ErrorMessage;

                    return(group);
                }
            }
            catch (Exception ee)
            {
                return(new Group(Convert.ToString(ee)));
            }
        }
Beispiel #13
0
        public User Register(string Email, string Name, string TeamName, string Password, string Phone, string Address, string Company)
        {
            RestRequest request = new RestRequest(String.Format("{0}/users/register", ApiPath), Method.POST);

            if (!String.IsNullOrEmpty(Name))
            {
                request.AddParameter("name", Name);
            }
            if (!String.IsNullOrEmpty(Email))
            {
                request.AddParameter("email", Email);
            }
            if (!String.IsNullOrEmpty(TeamName))
            {
                request.AddParameter("team_name", TeamName);
            }
            if (!String.IsNullOrEmpty(Password))
            {
                request.AddParameter("password", Password);
            }
            if (!String.IsNullOrEmpty(Phone))
            {
                request.AddParameter("phone", Phone);
            }
            if (!String.IsNullOrEmpty(Address))
            {
                request.AddParameter("address", Address);
            }
            if (!String.IsNullOrEmpty(Company))
            {
                request.AddParameter("company", Company);
            }

            try
            {
                IRestResponse httpResponse = RestClient.Execute(request);
                if (httpResponse.StatusCode == HttpStatusCode.OK)
                {
                    User user_response = JsonConvert.DeserializeObject <User>(httpResponse.Content, TSCloud.serializer_settings());
                    user_response.StatusCode = httpResponse.StatusCode;
                    user_response.SysInfo    = GetSysInfo();

                    return(user_response);
                }
                else
                {
                    User user_response = new User();
                    user_response.StatusCode = httpResponse.StatusCode;
                    user_response.Message    = httpResponse.ErrorMessage;

                    return(user_response);
                }
            }
            catch (Exception ee)
            {
                return(new User(Convert.ToString(ee)));
            }
        }
Beispiel #14
0
        //public Users All()
        //{
        //    RestRequest request = new RestRequest(String.Format("{0}/users", ApiPath), Method.GET);
        //    request.AddParameter("api_token", ApiToken);

        //    try
        //    {
        //        IRestResponse httpResponse = RestClient.Execute(request);
        //        List<User> user_list = JsonConvert.DeserializeObject<List<User>>(httpResponse.Content, TSCloud.serializer_settings());
        //        user_list.ForEach(x => x.SysInfo = GetSysInfo());

        //        return new Users(user_list);
        //    }
        //    catch
        //    {
        //        return new Users();
        //    }
        //}
        public User Create(User user)
        {
            if (String.IsNullOrEmpty(user.Email))
            {
                throw new Exception("Email required");
            }
            if (!CheckExpiration())
            {
                throw new Exception("token refresh fails");
            }

            RestRequest request = new RestRequest(String.Format("{0}/users", ApiPath), Method.POST);

            request.AddParameter("api_token", ApiToken);
            request.AddParameter("email", user.Email);
            request.AddParameter("password", user.Password);
            request.AddParameter("name", user.Name);
            request.AddParameter("phone", user.Phone);
            request.AddParameter("address", user.Address);
            request.AddParameter("company", user.Company);
            request.AddParameter("role", user.Role);
            request.AddParameter("meta", user.Meta.Stringify());

            try
            {
                IRestResponse httpResponse = RestClient.Execute(request);
                User          created_user = JsonConvert.DeserializeObject <User>(httpResponse.Content, TSCloud.serializer_settings());
                created_user.SysInfo = GetSysInfo();

                return(created_user);
            }
            catch (Exception ee)
            {
                return(new User(Convert.ToString(ee)));
            }
        }
Beispiel #15
0
        public User Get(int UserID)
        {
            if (!CheckExpiration())
            {
                throw new Exception("token refresh fails");
            }
            RestRequest request = new RestRequest(String.Format("{0}/users/{1}", ApiPath, Convert.ToString(UserID)), Method.GET);

            request.AddParameter("api_token", ApiToken);

            try
            {
                IRestResponse httpResponse = RestClient.Execute(request);
                if (httpResponse.StatusCode == HttpStatusCode.OK)
                {
                    User user = JsonConvert.DeserializeObject <User>(httpResponse.Content, TSCloud.serializer_settings());
                    user.SysInfo    = GetSysInfo();
                    user.StatusCode = httpResponse.StatusCode;

                    return(user);
                }
                else
                {
                    User user = new User();
                    user.StatusCode = httpResponse.StatusCode;
                    user.Message    = httpResponse.ErrorMessage;

                    return(user);
                }
            }
            catch (Exception ee)
            {
                return(new User(Convert.ToString(ee)));
            }
        }
Beispiel #16
0
        public RefreshResponse CheckExpiration(DateTime expiration, string refresh_token)
        {
            if (expiration <= DateTime.Now && !string.IsNullOrEmpty(refresh_token))
            {
                try
                {
                    RestRequest request = new RestRequest(String.Format("{0}/authenticate/refresh", ApiPath), Method.PUT);
                    request.AddParameter("refresh_token", refresh_token);

                    IRestResponse httpResponse = RestClient.Execute(request);
                    if (httpResponse.StatusCode == HttpStatusCode.OK)
                    {
                        return(JsonConvert.DeserializeObject <RefreshResponse>(httpResponse.Content, TSCloud.serializer_settings()));
                    }
                }
                catch (Exception e)
                {
                    return(new RefreshResponse("token refresh fails - " + e.Message));
                }
                return(new RefreshResponse("token refresh fails"));
            }
            return(null);
        }
Beispiel #17
0
        string GetApiHost()
        {
            RestClient = new RestClient(AppHost);
            RestRequest request = new RestRequest(String.Format("/api_host"), Method.GET);

            try
            {
                IRestResponse httpResponse = RestClient.Execute(request);
                if (httpResponse.StatusCode != HttpStatusCode.OK)
                {
                    return(AppHost);
                }

                Hash response = JsonConvert.DeserializeObject <Hash>(httpResponse.Content, TSCloud.serializer_settings());

                return(Convert.ToString(response["api_host"]));
            }
            catch
            {
                return(null);
            }
        }
        private List <Printer> index(int Page)
        {
            RestRequest request = new RestRequest(String.Format("{0}/printers", ApiPath), Method.GET);

            request.AddParameter("api_token", ApiToken);
            request.AddParameter("root", "true");
            if (Page != 0)
            {
                request.AddParameter("page", Page);
            }

            try
            {
                IRestResponse httpResponse = RestClient.Execute(request);
                Printers      printers     = JsonConvert.DeserializeObject <Printers>(httpResponse.Content, TSCloud.serializer_settings());

                int num_pages = printers.Pagination.NumPages;
                if (Page == 0)
                {
                    List <Printer> printer_list = new List <Printer>();

                    for (int i = 1; i <= num_pages; i++)
                    {
                        printer_list.AddRange(index(i));
                    }

                    return(printer_list);
                }
                else
                {
                    return(printers.Contents);
                }
            }
            catch
            {
                return(new List <Printer>());
            }
        }
Beispiel #19
0
        public Model Create(string ModelName, int ParentId, string FilePath, Hash Meta, Hash Acl)
        {
            if (!CheckExpiration())
            {
                throw new Exception("token refresh fails");
            }

            RestRequest request = new RestRequest(String.Format("{0}/folders", ApiPath), Method.POST);
            string      strModelName;

            if (Acl != null)
            {
                request.AddParameter("acl", Acl.Stringify());
            }

            if (ParentId != 0)
            {
                request.AddParameter("parent_id", ParentId.ToString());
            }

            if (!String.IsNullOrEmpty(ModelName))
            {
                strModelName = ModelName;
            }
            else
            {
                strModelName = Path.GetFileName(FilePath);
            }

            request.AddParameter("name", strModelName);
            request.AddParameter("api_token", ApiToken);

            if (Meta != null)
            {
                request.AddParameter("meta", Meta.Stringify());
            }

            if (!String.IsNullOrEmpty(FilePath))
            {
                request.AddFile("file", FilePath);
            }

            try
            {
                IRestResponse httpResponse = RestClient.Execute(request);
                if (httpResponse.StatusCode == HttpStatusCode.OK)
                {
                    Model model = JsonConvert.DeserializeObject <Model>(httpResponse.Content, TSCloud.serializer_settings());
                    model.StatusCode = httpResponse.StatusCode;
                    model.Message    = httpResponse.ErrorMessage;
                    model.SysInfo    = GetSysInfo();

                    return(model);
                }
                else
                {
                    return(new Model(httpResponse.Content));
                }
            }
            catch (Exception ee)
            {
                return(new Model(ee.ToString()));
            }
        }
        public Printer Create(string PrinterName, object MetaJson)
        {
            if (!CheckExpiration())
            {
                throw new Exception("token refresh fails");
            }

            RestRequest request = CreateRequest(PrinterName, MetaJson);

            if (request == null)
            {
                return(new Printer("printer cannot be created without acl or printer name"));
            }

            try
            {
                IRestResponse httpResponse = RestClient.Execute(request);
                Printer       printer      = JsonConvert.DeserializeObject <Printer>(httpResponse.Content, TSCloud.serializer_settings());
                printer.StatusCode = httpResponse.StatusCode;
                printer.Message    = httpResponse.ErrorMessage;

                return(printer);
            }
            catch (Exception ee)
            {
                return(new Printer(ee.ToString()));
            }
        }
        public Queues GetQueues(int PrinterId, int Page)
        {
            if (!CheckExpiration())
            {
                throw new Exception("token refresh fails");
            }

            RestRequest request = new RestRequest(String.Format("{0}/queues", ApiPath), Method.GET);

            request.AddParameter("api_token", ApiToken);
            request.AddParameter("parent_id", PrinterId);
            if (Page != 0)
            {
                request.AddParameter("page", Page);
            }

            try
            {
                IRestResponse httpResponse = RestClient.Execute(request);

                if (httpResponse.StatusCode == HttpStatusCode.OK)
                {
                    Queues queues = JsonConvert.DeserializeObject <Queues>(httpResponse.Content, TSCloud.serializer_settings());

                    return(queues);
                }
                else
                {
                    return(new Queues(httpResponse.Content));
                }
            }
            catch (Exception ee)
            {
                throw ee;
            }
        }
Beispiel #22
0
        public User Authenticate(string Email, string Password, string External)
        {
            var request = new RestRequest(ApiPath + "/authenticates", Method.POST);

            request.AddParameter("email", Email.ToLower());
            request.AddParameter("password", Password);
            if (!string.IsNullOrEmpty(External))
            {
                request.AddParameter("external", External);
            }
            request.RequestFormat = DataFormat.Json;

            try
            {
                IRestResponse httpResponse = RestClient.Execute(request);

                if (httpResponse.StatusCode == HttpStatusCode.OK)
                {
                    User CurrentUser = JsonConvert.DeserializeObject <Datas.User>(httpResponse.Content, TSCloud.serializer_settings());
                    ApiToken            = CurrentUser.ApiToken;
                    RefreshToken        = CurrentUser.RefreshToken;
                    Expiration          = CurrentUser.TokenExpiration;
                    CurrentUser.SysInfo = GetSysInfo();
                    this.CurrentUser    = CurrentUser;


                    //UserClient UserClient = new UserClient(this);
                    //m_users = UserClient.All();

                    if (ApiToken != null)
                    {
                        RefreshThread = new Thread(new RefreshTokenWorker(this).Start);
                        RefreshThread.Start();
                        return(CurrentUser);
                    }
                    else
                    {
                        return(new User("api_token is null"));
                    }
                }
                else
                {
                    return(new User(httpResponse.Content));
                }
            }
            catch (Exception ee)
            {
                return(new User(ee.ToString()));
            }
        }
Beispiel #23
0
        private List <Model> index(int ModelId, int Page, Ftype ftype)
        {
            if (!CheckExpiration())
            {
                throw new Exception("token refresh fails");
            }

            RestRequest request = new RestRequest(String.Format("{0}/folders", ApiPath), Method.GET);

            if (ftype != Ftype.All)
            {
                request.AddParameter("ftype", ftype.ToString());
            }
            request.AddParameter("api_token", ApiToken);
            if (Page != 0)
            {
                request.AddParameter("page", Page);
            }
            if (Configuration["PerPage"] != null)
            {
                request.AddParameter("per_page", Configuration["PerPage"]);
            }

            try
            {
                IRestResponse httpResponse = RestClient.Execute(request);
                Models        models       = JsonConvert.DeserializeObject <Models>(httpResponse.Content, TSCloud.serializer_settings());

                int num_pages = models.Pagination.NumPages;
                if (Page == 0)
                {
                    List <Model> model_list = new List <Model>();

                    for (int i = 1; i <= num_pages; i++)
                    {
                        model_list.AddRange(index(ModelId, i, ftype));
                    }

                    return(model_list);
                }

                List <Model> filtered_model_list = new List <Model>();

                if (ftype != Ftype.All)
                {
                    foreach (Model model in models.Contents)
                    {
                        if (Convert.ToString(model.Ftype) == ftype.ToString())
                        {
                            filtered_model_list.Add(model);
                        }
                    }

                    filtered_model_list.ForEach(x => x.SysInfo = GetSysInfo());
                    return(filtered_model_list);
                }
                else
                {
                    models.Contents.ForEach(x => x.SysInfo = GetSysInfo());
                    return(models.Contents);
                }
            }
            catch
            {
                return(new List <Model>());
            }
        }
Beispiel #24
0
        public User Update(User user)
        {
            if (user.Id == 0)
            {
                throw new Exception("User ID Required");
            }
            if (!CheckExpiration())
            {
                throw new Exception("token refresh fails");
            }

            RestRequest request = new RestRequest(String.Format("{0}/users/{1}", ApiPath, Convert.ToString(user.Id)), Method.PUT);

            request.AddParameter("api_token", ApiToken);

            if (user.Name != null)
            {
                request.AddParameter("name", user.Name);
            }
            if (user.Password != null)
            {
                request.AddParameter("password", user.Password);
            }
            if (user.Role != null)
            {
                request.AddParameter("role", user.Role);
            }
            if (user.Phone != null)
            {
                request.AddParameter("phone", user.Phone);
            }
            if (user.Address != null)
            {
                request.AddParameter("address", user.Address);
            }
            if (user.Company != null)
            {
                request.AddParameter("company", user.Company);
            }
            if (user.Meta != null)
            {
                request.AddParameter("meta", user.Meta.Stringify());
            }

            try
            {
                IRestResponse httpResponse = RestClient.Execute(request);
                if (httpResponse.StatusCode == HttpStatusCode.OK)
                {
                    User user_response = JsonConvert.DeserializeObject <User>(httpResponse.Content, TSCloud.serializer_settings());
                    user_response.StatusCode = httpResponse.StatusCode;
                    user_response.SysInfo    = GetSysInfo();

                    return(user_response);
                }
                else
                {
                    User user_response = new User();
                    user_response.StatusCode = httpResponse.StatusCode;
                    user_response.Message    = httpResponse.ErrorMessage;

                    return(user_response);
                }
            }
            catch (Exception ee)
            {
                return(new User(ee.ToString()));
            }
        }