private bool SaveData(string relativeUri, IncomingData data) { Logger.Write("Entered SaveData"); if (impersonateValidUser(ConfigurationManager.AppSettings["UserName"].ToString(), ConfigurationManager.AppSettings["DomainName"].ToString(), ConfigurationManager.AppSettings["UserPass"].ToString())) { //Insert your code that runs under the security context of a specific user here. Logger.Write("Impersonation Successful Save Data"); string uploadPath = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["UploadPath"].ToString() + relativeUri); Logger.Write("Solved upload path? - " + uploadPath); if (!Directory.Exists(uploadPath)) { System.IO.Directory.CreateDirectory(uploadPath); } if (data.DataType == "base64string") { WriteFile(uploadPath, Convert.FromBase64String(data.Data)); } else if (data.DataType == "URL") { //downloadfile from location WebClient cl = new WebClient(); WriteFile(uploadPath, cl.DownloadData(new Uri(data.Data))); cl.Dispose(); } else { //incorect data type } UnzipFile(uploadPath); undoImpersonation(); return true; } else { Logger.Write("Impersonation Failed Save Data"); return false; //Your impersonation failed. Therefore, include a fail-safe mechanism here. } }
public bool UpdateGadgetData(string owner, string gadgetName, string version, IncomingData request) { Logger.Write("Entered Update Gadget Data"); Gadget gadgetObj = DAGadget.Instance.GetGadgetById(string.Format(uriFormat, owner, gadgetName, version)); if (gadgetObj != null) { DAGadget.Instance.UpdateGadgetContent(gadgetObj, false); return SaveData(gadgetObj.GadgetUri, request); } else { WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NotFound; WebOperationContext.Current.OutgoingResponse.StatusDescription = string.Format("GadgetMetadata for Gadget with Owner:{0} Name:{1} Version:{2} does not exist", owner, gadgetName, version); //WebOperationContext.Current.OutgoingResponse.SuppressEntityBody = true; Logger.Write("Exit Store Gadget with fail"); return false; } }