I am reading values for dropdown using selector + request parameters.
/bin/services/myservlet.GET_DROPDOWN_VALUES.json?locale=$PATH
the $PATH gives me currentPath.path. I can I get the current locale using the path.
for example:
/bin/services/myservlet.GET_DROPDOWN_VALUES.json?locale=en-us
How can I return only the locale from the $PATH and pass it to locale. That will resolve the issue.
Resource resource = resourceResolver.getResource(path);
if (resource != null) {
Page targetPage = resource.adaptTo(Page.class);
if (targetPage != null) {
Locale pageLocale = targetPage.getLanguage(true);
String countryLocale = pageLocale.getCountry();
}
}
To retrieve locale using $PATH
/bin/services/myservlet.GET_DROPDOWN_VALUES.json?locale=$PATH
String compNodePath = (String) request.getParameter("locale");
String pagePath = StringUtils.substringBefore(compNodePath, "jcr:content");
PageManager pageMgr = request.getResourceResolver().adaptTo(PageManager.class);
Page page = pageMgr.getContainingPage(pagePath);
Locale pageLocale = page.getLanguage(false);
For this to work, Language field in page properties should be set to a suitable value.
Related
The culture of windows form application doesn't change, despite using the correct code (I think of course).
In the Program.cs file in the win form application I try to change the current culture from en-US to fa-IR and I use these codes:
CultureInfo culture = CultureInfo.CreateSpecificCulture("Fa-IR");
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
Thread.CurrentThread.CurrentCulture = culture;
But after running the program, nothing happened. The current culture is still en-US!. Let me also say this, I don't change the culture program anywhere else.
I thought that after changing the culture of the system, the language of the system should change as well. While I was wrong. By adding the following code I was able to change the Windows language to Farsi.
InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(culture);
public static void InitializePersianCulture() {
var culture = new CultureInfo("fa-ir");
var info = culture.DateTimeFormat;
var calendar = new PersianCalendar();
info.Calendar = calendar;
var field = typeof(CultureInfo).GetField("Calendar", System.Reflection.BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
if (field != null)
field.SetValue(culture, "fa-ir");
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
CultureInfo.CurrentCulture.DateTimeFormat = info;
CultureInfo.CurrentUICulture.DateTimeFormat = info;
}
I am doing pagination in REST api developed over slim.
Using below API to get current uri
(string) $request->getUri();
RESULT ::http://localhost/slim/test_app/test/public/api/actions/?page=2
But now for next request i need to replace the page number in current url to (+1) ie 3 here and pass in data returned to user like below
{
"data":[
//data
]
"next": http://localhost/slim/test_app/test/public/api/actions/?page=3
}
What could be the best way to replace the page number ? Do we have any direct api for this,to just replace the attributes ?
I added a function to merge attributes and than bind the query to url as below function
private function merge_querystring($url = null,$query = null,$recursive = false)
{
if($url == null)
return false;
if($query == null)
return $url;
// split the url into it's components
$url_components = parse_url($url);
// if we have the query string but no query on the original url
// just return the URL + query string
if(empty($url_components['query']))
return $url.'?'.ltrim($query,'?');
// turn the url's query string into an array
parse_str($url_components['query'],$original_query_string);
// turn the query string into an array
parse_str(parse_url($query,PHP_URL_QUERY),$merged_query_string);
// merge the query string
if($recursive == true)
$merged_result = array_merge_recursive($original_query_string,$merged_query_string);
else
$merged_result = array_merge($original_query_string,$merged_query_string);
// Find the original query string in the URL and replace it with the new one
return str_replace($url_components['query'],http_build_query($merged_result),$url);
}
and i use below to add query to url
$postQuery["page"]=$currentpage+1;
//print_r($postQuery);
//echo http_build_query($postQuery);
$data["next"]= $this->merge_querystring($request->getUri(),"?".http_build_query($postQuery));
You can replace pagination value by string manipulation. But you can also using what Slim provide.
Slim\Http\Uri class, which implements Psr\Http\Message\UriInterface, has withQuery() method that will replace current query string.
It will return cloned Slim\Http\Uri instance with its query string replaced.
$query = $request->getQueryParams();
$query['page'] = $query['page'] + 1;
$url = $request->getUri();
$nextUrl = $url->withQuery(http_build_query($query));
$data['next'] = (string) $nexUrl;
I need help getting the landingpage for a session using google analytics ga:landingPagePath.
When i use the query below I get the correct result with my first visit using IE. However, when I close IE and open Firefox and visit a different landing page, I still get the landing page of the previous session. I should get the landing page of the current firefox session unless since this is a new browser session. Thanks in advance for any help.
// query google analytics
var query1 = new Google.GData.Analytics.DataQuery(dataFeedUrl);
query1.Ids = string.Format("ga:{0}", profileId);
query1.Metrics = "ga:entrances";
query1.Dimensions = "ga:landingPagePath";
//query1.Filters = "ga:entrances==1";
//query.Filters = string.Format("ga:pagePath=={0}", url);
// set from and to date (google does not accept datetime min/max value)
string fromDate = DateTime.Today.ToString("yyyy-MM-dd");
query1.GAStartDate = fromDate;
query1.GAEndDate = DateTime.Today.AddDays(1).ToString("yyyy-MM-dd");
var dataFeed = service.Query(query1);
if (dataFeed != null && dataFeed.Entries != null && dataFeed.Entries.Count > 0)
{
var dataEntries = dataFeed.Entries.Last() as Google.GData.Analytics.DataEntry;
var landingPage = dataEntries;
result = landingPage.Dimensions.Last().Value.ToString();
HttpContext.Current.Session["landing"] = result.ToString();
}
return result;
}
Here is my problem.
I use a dynamic connection string for my Entity Framework context.
//In Web Config
add key="DataSource" value="WIN-QBRH0MJL8IT\ISS" />
//In my EntityFactory.cs
public static DBEntities GetEntity()
{
var scsb = new SqlConnectionStringBuilder();
scsb.DataSource = ConfigurationManager.AppSettings["DataSource"];
scsb.InitialCatalog = "db1";
scsb.MultipleActiveResultSets = true;
scsb.IntegratedSecurity = true;
if (HttpContext.Current.Session["DBName"] == null)
{
HttpContext.Current.Response.Redirect("/Account/Step1");
}
else
{
scsb.InitialCatalog = HttpContext.Current.Session["DBName"].ToString();
}
var builder = new EntityConnectionStringBuilder();
builder.Metadata = "metadata=~/bin/Models/DBModel.csdl|~/bin/Models/DBModel.ssdl|~/bin/Models/DBModel.msl";
builder.Provider = "System.Data.SqlClient";
builder.ProviderConnectionString = scsb.ConnectionString;
DBEntities db = new DBEntities(builder.ConnectionString);
return db;
}
I Know the problem is for this line :
builder.Metadata =
"metadata=~/bin/Models/DBModel.csdl|~/bin/Models/DBModel.ssdl|~/bin/Models/DBModel.msl";
I check and the csdl, ssdl, msl are in /mvcinfosite/bin/Models/.csdl,.ssdl,.msl
The configuration for my edmx is:
Metadata Artifact Processing : Copy to Output Directory
Here is the full error
The specified metadata path is not valid. A valid path must be either
an existing directory, an existing file with extension '.csdl',
'.ssdl', or '.msl', or a URI that identifies an embedded resources
Thanks
Try to remove ~ character and use valid relative path to your app root. I think it is not able to work with this special character used on in ASP.NET application.
I have a c# class which was written to read the lotus emails for any attachments and save it to the local drive. It was working fine when I pass "" as first parameter to GetDataBase method and full path of .nsf file of my local system as second argument. But, if I remove "" and I specify my local system full name as first argument it is returning null value.
Is it problem with any permissions? If so, it should not work even when I pass "" as first parameter. Otherwise, should I have any other permissions at system/server level?
Please help me in this issue.
Finally, I could do it in the following way. And I thought of posting it to some one can atleast not to suffer again.
Following code is to read the attachment from the lotus emails and save it to the physical location.
string lotusServerName = ConfigurationSettings.AppSettings["Lotus_Server"].ToString();
string lotusDBFilePath = ConfigurationSettings.AppSettings["Lotus_DB_File_Path"].ToString();
string password = ConfigurationSettings.AppSettings["Password"].ToString();
string sourceFolder = ConfigurationSettings.AppSettings["Source_Folder"].ToString();
string targetFolder = ConfigurationSettings.AppSettings["Target_Folder"].ToString();
string documentsFolder = ConfigurationSettings.AppSettings["Documents_Folder"].ToString();
//Creating the notes session and passing password
NotesSession session = new NotesSession();
session.Initialize(password);
//Getting the DB instance by passing the servername and path of the mail file.
//third param "false" will try to check the DB availability by opening the connection
//if it cannot open, then it returns null.
NotesDatabase NotesDb = session.GetDatabase(lotusServerName, lotusDBFilePath, false);
//Get the view of the source folder
NotesView inbox = NotesDb.GetView(sourceFolder);
//looping through each email/document and looking for the attachments
//if any attachments found, saving them to the given specified location
//moving the read mails to the target folder
NotesDocument docInbox = null;
int docCnt = inbox.EntryCount;
for (int currDoc = 0; currDoc < docCnt; currDoc++) {
docInbox = inbox.GetFirstDocument();
object[] items = (object[])docInbox.Items;
foreach (NotesItem nItem in items) {
if (nItem.Name == "$FILE") {
NotesItem file = docInbox.GetFirstItem("$File");
string fileName = ((object[])nItem.Values)[0].ToString();
NotesEmbeddedObject attachfile = (NotesEmbeddedObject)docInbox.GetAttachment(fileName);
if (attachfile != null) {
attachfile.ExtractFile(documentsFolder + fileName);
}
}
}
docInbox.PutInFolder(targetFolder, true);//"true" creates the folder if it doesn't exists
docInbox.RemoveFromFolder(sourceFolder);
}
//releasing resources
if (session != null)
session = null;
if (NotesDb != null)
NotesDb = null;
if (inbox != null)
inbox = null;
if (docInbox != null)
docInbox = null;
Following is values read from .config file.
The above code will work properly if you alredy have lotus mail client in your system and you are able to access mails from your mail server. You don't require any other previliges.