public string[] GetExportEndpointAndStreamDownloadAddresses() { // Export endpoint and stream download endpoint are returned as a two element string array, // where the export endpoint is the first entry and the stream download endpoint is the second. string[] exportEndpointAndStreamDownloadAddresses = { string.Empty, string.Empty }; // Create a new, null Core Service Client SessionAwareCoreServiceClient client = null; // TODO: Use Client, not client (then you don't have to worry about handling abort/dispose/etc.). <- Alchemy version 7.0 or higher // With Client, no need to call client.Abort(); can we also remove catch block below if using Client? Fix in other parts of code as well... 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); // App data is set up with the following parameters. string exportEndpointId = "exportEndpointAddr"; string streamDownloadId = "streamDownloadAddr"; // Pass null for the item ID, since this app data does not correspond to any items in Tridion. ApplicationData appData = client.ReadApplicationData(null, exportEndpointId); if (appData != null) { Byte[] data = appData.Data; // exportEndpointId corresponds to the first element of the array return value. exportEndpointAndStreamDownloadAddresses[0] = Encoding.Unicode.GetString(data); } appData = client.ReadApplicationData(null, streamDownloadId); if (appData != null) { Byte[] data = appData.Data; // streamDownloadId corresponds to the second element of the array return value. exportEndpointAndStreamDownloadAddresses[1] = Encoding.Unicode.GetString(data); } // Explicitly abort to ensure there are no memory leaks. client.Abort(); } catch (Exception ex) { // Proper way of ensuring that the client gets closed. if (client != null) { client.Abort(); } // We are rethrowing the original exception and just letting webapi handle it. throw ex; } return(exportEndpointAndStreamDownloadAddresses); }
internal static string LoadConfigurationImpl() { using (Tracer.GetTracer().StartTrace()) { using (SessionAwareCoreServiceClient client = CoreServiceManager.GetCoreServiceClient()) { try { ApplicationData appData = client.ReadApplicationData(null, Constants.DXA_RESOLVER_CONFIGURATION_NAME); if (appData != null) { ApplicationDataAdapter ada = new ApplicationDataAdapter(appData); XmlElement appDataXml = ada.GetAs <XmlElement>(); return(appDataXml.OuterXml); } return(String.Format( "<Configuration xmlns:{0}=\"{1}\"></Configuration>", Constants.DXA_RESOLVER_CONFIGURATION_PREFIX, Constants.DXA_RESOLVER_CONFIGURATION_NAMESPACE )); } catch (Exception ex) { throw new Exception( Resources.DXA_CM_Extensions_DXAResolver_Models_Strings.CR_LoadConfigurationFailed, ex); } } } }
protected void Page_Load(object sender, EventArgs e) { _coreServiceEndpoint = new EndpointAddress(WebConfigurationManager.AppSettings["EndpointAddress"]); _vocabulariesAppId = WebConfigurationManager.AppSettings["VocabulariesAppId"]; _typeOfAppId = WebConfigurationManager.AppSettings["TypeOfAppId"]; _schemaPublicationUri = WebConfigurationManager.AppSettings["SchemaPublicationUri"]; if (!IsPostBack) { var client = new SessionAwareCoreServiceClient(_binding, _coreServiceEndpoint); client.Impersonate(HttpContext.Current.User.Identity.Name); // load vocabularies appdata ApplicationData appData = client.ReadApplicationData(null, _vocabulariesAppId); if (appData != null) { AppData.Text = Encoding.Unicode.GetString(appData.Data); } else { // load default xml AppData.Text = "<vocabularies>\n <vocabulary prefix=\"s\" name=\"http://schema.org\"/>\n</vocabularies>"; } // load schemas var filter = new RepositoryItemsFilterData { ItemTypes = new[] { ItemType.Schema }, Recursive = true }; var schemas = client.GetList(_schemaPublicationUri, filter); foreach (var schema in schemas) { SchemaList.Items.Add(new ListItem(schema.Title, schema.Id)); } // load appdata for first schema in the list appData = client.ReadApplicationData(schemas[0].Id, _typeOfAppId); if (appData != null) { TypeOf.Text = Encoding.Unicode.GetString(appData.Data); } Close(client); } }
private string GetAppData(SessionAwareCoreServiceClient client, string itemUri, string applicationId) { var appData = client.ReadApplicationData(itemUri, applicationId); //bool isAscii = appData.Data.All(c => c >= 32 && c < 127); //var value = isAscii ? new ASCIIEncoding().GetString(appData.Data) : "<The value is not an ASCII string.>"; //return value; if (appData == null) { return("N/A"); } return(new ASCIIEncoding().GetString(appData.Data)); }
protected void SchemaListChanged(object sender, EventArgs e) { var client = new SessionAwareCoreServiceClient(_binding, _coreServiceEndpoint); client.Impersonate(HttpContext.Current.User.Identity.Name); ApplicationData appData = client.ReadApplicationData(SchemaList.SelectedItem.Value, _typeOfAppId); if (appData != null) { TypeOf.Text = Encoding.Unicode.GetString(appData.Data); } else { // reset textbox TypeOf.Text = String.Empty; } Close(client); SchemaLabel.Text = SchemaList.SelectedItem.Value; }
public BaseSettings GetNotificationSettings(string userId, string appKey) { try { this.OpenSession(userName); ApplicationData appData = session.ReadApplicationData(userId, appKey); XElement xSettings = XElement.Parse(Encoding.UTF8.GetString(appData.Data)); BaseSettings settings = new BaseSettings(); settings.SavedDate = xSettings.Element("SavedDate").Value; settings.UserId = xSettings.Element("UserId").Value; return(settings); } 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); }