public ActionResult InstanceList() { //var appInstances = CredentialManager.GetAppInstances(GetUserKey()); var appInstances = SqlCredentialManager.GetAppInstances(GetUserKey()); return(PartialView(appInstances)); }
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); }
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)); }
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)); }
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 })); }
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)); }
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)); }