internal static string SaveConfigurationImpl(string configurationXml) { using (Tracer.GetTracer().StartTrace(configurationXml)) { using (SessionAwareCoreServiceClient client = CoreServiceManager.GetCoreServiceClient()) { try { XmlDocument appDataXml = new XmlDocument(); appDataXml.LoadXml(configurationXml); ApplicationDataAdapter ada = new ApplicationDataAdapter(Constants.DXA_RESOLVER_CONFIGURATION_NAME, appDataXml.DocumentElement); client.SaveApplicationData(null, new[] { ada.ApplicationData }); return(configurationXml); } catch (Exception ex) { throw new Exception( Resources.DXA_CM_Extensions_DXAResolver_Models_Strings.CR_SaveConfigurationFailed, ex); } } } }
private void SetAppData(SessionAwareCoreServiceClient client, string itemUri, string applicationId, string value) { var appData = new ApplicationData(); appData.ApplicationId = applicationId; appData.Data = new ASCIIEncoding().GetBytes(value); client.SaveApplicationData(itemUri, new ApplicationData[] { appData }); }
private void SetAppData(SessionAwareCoreServiceClient client, string itemUri, Dictionary <string, string> keyValues) { var appDataArray = new List <ApplicationData>(); foreach (KeyValuePair <string, string> keyValue in keyValues) { var appData = new ApplicationData(); appData.ApplicationId = keyValue.Key; appData.Data = new ASCIIEncoding().GetBytes(keyValue.Value); appDataArray.Add(appData); } client.SaveApplicationData(itemUri, appDataArray.ToArray()); }
protected void UpdateVocabsClick(object sender, EventArgs e) { var client = new SessionAwareCoreServiceClient(_binding, _coreServiceEndpoint); client.Impersonate(HttpContext.Current.User.Identity.Name); var appData = new ApplicationData { ApplicationId = _vocabulariesAppId, Data = Encoding.Unicode.GetBytes(AppData.Text) }; client.SaveApplicationData(null, new[] { appData }); Close(client); VocabsLabel.Text = "saved..."; }
protected void UpdateSchemaClick(object sender, EventArgs e) { var client = new SessionAwareCoreServiceClient(_binding, _coreServiceEndpoint); client.Impersonate(HttpContext.Current.User.Identity.Name); var appData = new ApplicationData { ApplicationId = _typeOfAppId, Data = Encoding.Unicode.GetBytes(TypeOf.Text) }; client.SaveApplicationData(SchemaList.SelectedItem.Value, new[] { appData }); Close(client); SchemaLabel.Text = SchemaList.SelectedItem.Value + " saved..."; }
private void SetAppDataAddress(string id, string address) { // Create a new, null Core Service Client SessionAwareCoreServiceClient client = null; // TODO: Update to pass internal part of below snippet as a function (to reuse try-catch pattern) try { // Creates a new core service client client = new SessionAwareCoreServiceClient("netTcp_2013"); // Gets the current user so we can impersonate them for our client string username = GetUserName(); client.Impersonate(username); Byte[] byteData = Encoding.Unicode.GetBytes(address); ApplicationData appData = new ApplicationData { ApplicationId = id, Data = byteData }; client.SaveApplicationData(null, new[] { appData }); // Explicitly abort to ensure there are no memory leaks. client.Abort(); } catch (Exception ex) { // Proper way of ensuring that the client gets closed... we close it in our try block above, // then in a catch block if an exception is thrown we abort it. if (client != null) { client.Abort(); } // We are rethrowing the original exception and just letting webapi handle it. throw ex; } }
public void SaveNotificationSettings(BaseSettings settings, string appKey) { try { this.OpenSession(); ApplicationData appData = new ApplicationData(); appData.ApplicationId = appKey; XElement xSettings = new XElement("appKey"); xSettings.Add(new XElement("SavedDate", settings.SavedDate)); xSettings.Add(new XElement("UserId", settings.UserId)); appData.Data = Encoding.UTF8.GetBytes(xSettings.ToString()); session.SaveApplicationData(settings.UserId, new ApplicationData[] { appData }); } catch (Exception ex) { throw ex; } finally { this.CloseSession(); } }
public SocialPageData Execute(string pageUri) { SessionAwareCoreServiceClient client = null; SocialPageData socialPageData = new SocialPageData(); try { client = Client.GetCoreService(); string liveTargetUri = Configuration.GetConfigString("livetargeturi"); string liveUrl = Configuration.GetConfigString("liveurl"); PageData pageData = (PageData)client.Read(pageUri, new ReadOptions()); PublishLocationInfo pubInfo = (PublishLocationInfo)pageData.LocationInfo; socialPageData.Title = pageData.Title; socialPageData.Uri = pageUri; socialPageData.Url = liveUrl + pubInfo.PublishLocationUrl; socialPageData.IsPublished = client.IsPublished(pageUri, liveTargetUri, true); socialPageData.UseShortUrl = bool.Parse(Configuration.GetConfigString("shorturl")); string shortUrl = string.Empty; if (socialPageData.UseShortUrl) { ApplicationData appData = client.ReadApplicationData(pageUri, SHORT_URL_APP_ID); if (appData != null) { Byte[] data = appData.Data; shortUrl = Encoding.Unicode.GetString(data); } if (shortUrl.Equals(string.Empty)) { Bitly service = new Bitly(socialPageData.Url); string shorter = service.ShortenUrl(service.UrlToShorten, service.BitlyLogin, service.BitlyAPIKey); shortUrl = Bitly.ParseXmlResponse(shorter, false); Byte[] byteData = Encoding.Unicode.GetBytes(shortUrl); appData = new ApplicationData { ApplicationId = SHORT_URL_APP_ID, Data = byteData, TypeId = shortUrl.GetType().ToString() }; client.SaveApplicationData(pageUri, new[] { appData }); } } socialPageData.ShortUrl = shortUrl; } catch (Exception ex) { socialPageData.HasError = true; socialPageData.ErrorInfo = ex; } finally { if (client != null) { if (client.State == CommunicationState.Faulted) { client.Abort(); } else { client.Close(); } } } return(socialPageData); }