Esempio n. 1
0
        public ActionResult InstanceList()
        {
            //var appInstances = CredentialManager.GetAppInstances(GetUserKey());
            var appInstances = SqlCredentialManager.GetAppInstances(GetUserKey());

            return(PartialView(appInstances));
        }
Esempio n. 2
0
        private ClientContext GetClientContext(string location, bool isLibrarySubmit = false)
        {
            var appInstance = SqlCredentialManager.GetMatchingInstanceByUrl(location);

            var isValidInstance = appInstance != null &&
                                  !String.IsNullOrWhiteSpace(appInstance.Username) &&
                                  !String.IsNullOrWhiteSpace(appInstance.Password);

            var webUrl = isLibrarySubmit
                ? GetWebUrl(location)
                : location;

            if (!isValidInstance)
            {
                return(SpManager.GetSharePointContext(HttpContext, webUrl));
            }

            var credentials = GetCredentials(webUrl, appInstance);

            var clientContext = new ClientContext(webUrl);

            clientContext.Credentials = credentials;

            return(clientContext);
        }
Esempio n. 3
0
        public async Task <ActionResult> DeleteInstance(string instanceId)
        {
            if (String.IsNullOrWhiteSpace(instanceId))
            {
                return(new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest));
            }

            var instanceDeleteResult = await SqlCredentialManager.DeleteAppInstance(instanceId, GetUserKey());

            return(Json(new { Result = instanceDeleteResult }, JsonRequestBehavior.AllowGet));
        }
Esempio n. 4
0
        public ActionResult Instance(string instanceId)
        {
            var appInstance = String.IsNullOrWhiteSpace(instanceId)
                ? new AppInstance()
                : SqlCredentialManager.GetAppInstanceById(instanceId, GetUserKey());

            //: CredentialManager.GetAppInstanceById(instanceId, GetUserKey());

            appInstance = appInstance ?? new AppInstance();

            return(PartialView(appInstance));
        }
Esempio n. 5
0
        public async Task <ActionResult> Instance(AppInstance instance)
        {
            var isInstanceExists = await SqlCredentialManager.IsAppInstanceExistAsync(instance, GetUserKey());

            if (isInstanceExists)
            {
                return(Json(new { Result = false, Exists = isInstanceExists }));
            }

            var operationResult = SqlCredentialManager.SaveOrUpdateAppInstance(instance, GetUserKey());

            return(Json(new { Result = operationResult }));
        }
Esempio n. 6
0
        private ICredentials GetCredentials(string spUrl)
        {
            var appInstance = SqlCredentialManager.GetMatchingInstanceByUrl(spUrl);

            var isValidInstance = appInstance != null &&
                                  !String.IsNullOrWhiteSpace(appInstance.Username) &&
                                  !String.IsNullOrWhiteSpace(appInstance.Password);

            if (!isValidInstance)
            {
                return(null);
            }

            return(GetCredentials(spUrl, appInstance));
        }
Esempio n. 7
0
        public ActionResult CallRestService(string url)
        {
            var success    = false;
            var message    = string.Empty;
            var resultBody = string.Empty;

            if (!String.IsNullOrWhiteSpace(url))
            {
                var appInstance = SqlCredentialManager.GetMatchingInstanceByUrl(url);

                var isCredentialsExist = appInstance != null &&
                                         !String.IsNullOrWhiteSpace(appInstance.Username) &&
                                         !String.IsNullOrWhiteSpace(appInstance.Password);

                using (var webClient = new WebClient())
                {
                    try
                    {
                        if (isCredentialsExist)
                        {
                            webClient.Credentials = new NetworkCredential(appInstance.Username, appInstance.Password, appInstance.Domain);
                        }

                        resultBody = webClient.DownloadStringDetectEncoding(url);
                        success    = true;
                    }
                    catch (Exception ex)
                    {
                        message = String.Format("{0} : {1}", ex.GetType().ToString(), ex.Message);
                    }
                }
            }
            else
            {
                message = "Url cannot be blank.";
            }

            var restResult = new RestResult
            {
                Message    = message,
                ResultBody = resultBody,
                Success    = success
            };

            return(Json(restResult, JsonRequestBehavior.AllowGet));
        }