Can any one tell me what is equivalent of NSMutableDictionary(), NSMutableArray() ,NSArray And NSDictionary in C#
First, there is no difference from mutable and immutable on Array and Dictionary in C#.
We can both change the value after it is initialized. It means they are all Mutable.
For NSMutableDictionary and NSDictionary
Dictionary<string, object> dict = new Dictionary<string, object>();
dict["a"] = new NSString(); // set
var Object = dict["a"]; //get
For NSMutableArray and NSArray
List<object> list = new List<object>();
list.Add(new NSString()); //set
NSString str = list[0] as NSString; //get
Related
In the B Viewcontroller, I store data into NSUserDefaults and retrieve them in AViewController.
During the execution, it performs as it expected. However, once I close and re-run the app, I figure out that these information (dictionary) does not being stored.
Here is the BViewController where I store the data in NSUserDefaults
partial class BViewController : UIViewController
{
const string server = "server";
const string port = "port";
const string password = "password";
const string username = "username";
const string inboxuserid = "inboxuserid";
.............
.............
public override void ViewWillDisappear (bool animated)
{
var appDefaults = new NSDictionary (server, serverTF.Text, port, portTF.Text, password, passwordTF.Text,username,usernameTF.Text, inboxuserid,inboxuserTF.Text);
NSUserDefaults.StandardUserDefaults.RegisterDefaults (appDefaults);
NSUserDefaults.StandardUserDefaults.Synchronize ();
}
}
and retrieve them in the A ViewController as follows:
partial class AViewController : UIViewController
{
public override void ViewWillAppear(bool animated)
{
var username = NSUserDefaults.StandardUserDefaults.StringForKey ("username");
Console.WriteLine (username);
}
}
Based on the following article: https://moovendan.wordpress.com/2012/12/26/monotouch-nsuserdefaults-store-values-in-settings/
I would propose the following code, I have tested with a small example and it worked.
BViewController, store the dictionary in the NSUserDefaults:
NSDictionary appDefaults= new NSDictionary(server, serverTF.Text, port, portTF.Text, password, passwordTF.Text, username, usernameTF.Text, inboxuserid, inboxuserTF.Text);
NSString key = new NSString ("dict");
NSUserDefaults.StandardUserDefaults.SetValueForKey (appDefaults, key);
AViewController, retrive the dictionary from NSUserDefaults:
NSString key = new NSString ("dict");
NSDictionary d2 = NSUserDefaults.StandardUserDefaults.DictionaryForKey (key);
Console.WriteLine (d2["username"]);
This is a bit of a two part question.
I am using Tim Tripcony's Fancy XPage Typeahead script in a number of applications to return a typeahead list based on a number of different views in a specific database.
Can the server side javascript listed in that blog be transformed into a java class to return the same results that can be picked up by the native typeahead functions in XPages.
Can that class be part of an extension library that is deployed to all servers so it is available to all applications for immediate use and if so how would it be called from the XPage.
Yes, I can't think of an example of any SSJS that cannot be converted to Java, Here is Tim Tripcony's SSJS ported to Java.
import java.util.HashMap;
import java.util.Map;
import lotus.domino.*;
import com.ibm.domino.xsp.module.nsf.NotesContext;
public class TypeAhead {
public static String directoryTypeAhead(String searchValue) {
String returnList = "";
try {
Database directory = NotesContext.getCurrent().getCurrentSession().getDatabase("", "names.nsf");
View allUsers = directory.getView("($Users)");
Map<String, HashMap<String, String>> matches = new HashMap<String, HashMap<String, String>>();
Map<String, String> individualMatches = new HashMap<String, String>();
Map<String, Boolean> includeForm = new HashMap<String, Boolean>();
includeForm.put("Person", Boolean.TRUE);
includeForm.put("Group", Boolean.TRUE);
ViewEntryCollection matchingEntries = allUsers.getAllEntriesByKey(searchValue, false);
ViewEntry entry = matchingEntries.getFirstEntry();
int resultCount = 0;
while (entry != null) {
Document matchDoc = entry.getDocument();
String matchType = matchDoc.getItemValueString("Form");
if ((Boolean)includeForm.get(matchType)) {
String fullName = matchDoc.getItemValue("FullName").elementAt(0).toString();
if (matches.get(fullName) == null) {
resultCount++;
Name matchName = NotesContext.getCurrent().getCurrentSession().createName(fullName);
individualMatches = new HashMap<String, String>();
individualMatches.put("cn", matchName.getCommon());
individualMatches.put("photo", matchDoc.getItemValueString("photoUrl"));
individualMatches.put("job", matchDoc.getItemValueString("jobTitle"));
individualMatches.put("email", matchDoc.getItemValueString("internetAddress"));
matches.put(fullName, (HashMap<String, String>) individualMatches);
}
}
if (resultCount > 9) {
entry = null;
}
else {
entry = matchingEntries.getNextEntry(entry);
}
}
returnList = "<ul>";
for (Map<String, String> match : matches.values()) {
String matchDetails = "<li><table><tr><td><img class=\"avatar\" src=\"" + match.get("photo") + "\"/></td><td valign=\"top\"><p><strong>" + match.get("cn") + "</strong></p><p><span class=\"informal\">" + match.get("job") + "<br/>" + match.get("email") + "</span></p></td></tr></table></li>";
returnList += matchDetails;
}
returnList += "</ul>";
} catch(Exception e) {
System.out.println(e);
}
return returnList;
}
}
As far as creating it in an extension library all you really have to do to get what I think you want is put it in a plugin Jar and create a feature and update site then you can use the new 8.5.3 functionality to replicate it out to all of your servers.
You might use this code by doing the following inside of your xpage:
<xp:inputText id="inputText1" value="#{viewScope.someVar}">
<xp:typeAhead mode="partial" minChars="1" valueMarkup="true"
var="searchValue"
valueList="#{javascript:return com.tobysamples.demo.TypeAhead.directoryTypeAhead(searchValue);}">
</xp:typeAhead></xp:inputText>
I think it is not that hard to convert the SSJS to Java. With a managed bean you can immediately access the java method by the field.
And should be a nice enhancement to the Extension Library, so everyone can benefit this cool typeahead
I used the code below to get the list of culture type, is there a way on how to get just the country name?
Thank you
static void Main(string[] args)
{
StringBuilder sb = new StringBuilder();
foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
sb.Append(ci.DisplayName);
sb.AppendLine();
}
Console.WriteLine(sb.ToString());
Console.ReadLine();
}
Sample Output:
Spanish (Puerto Rico)
Spanish (United States)
You can use the Name property of the CultureInfo to construct a RegionInfo. You can then use the DisplayName property.
Try:
foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
var ri = new RegionInfo(ci.Name);
Console.WriteLine(ri.DisplayName);
}
Well, this regular expression seems to do the job in most cases:
var regex = new System.Text.RegularExpressions.Regex(#"([\w+\s*\.*]+\))");
foreach (var item in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
var match = regex.Match(item.DisplayName);
string countryName = match.Value.Length == 0 ? "NA" : match.Value.Substring(0, match.Value.Length - 1);
Console.WriteLine(countryName);
}
// Build your normal dictionary as container
Dictionary<string, string> countryNames = new Dictionary<string, string>();
foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
RegionInfo ri = new RegionInfo(ci.Name);
// Check if the ISO language code is already in your collection
// Because you don't want double entries in a country box because we had to use the culture info
if (!countryNames.ContainsKey(ri.TwoLetterISORegionName))
{
countryNames.Add(ri.TwoLetterISORegionName.ToUpper(), ri.EnglishName);
}
}
// Code for dictionary to dropdownlist transform can be written with your personal preference for symantics
SelectList countryDropdown = new SelectList(countryNames.OrderBy(o => o.Value), "Key", "Value");
Or ready for use without comments:
Dictionary<string, string> countryNames = new Dictionary<string, string>();
foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
RegionInfo ri = new RegionInfo(ci.Name);
if (!countryNames.ContainsKey(ri.TwoLetterISORegionName)) countryNames.Add(ri.TwoLetterISORegionName.ToUpper(), ri.EnglishName);
}
SelectList countryDropdown = new SelectList(countryNames.OrderBy(o => o.Value), "Key", "Value");
this would be what you are looking for:
foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
sb.Append(ci.EnglishName);
sb.AppendLine();
}
You will need to use following namespaces
using System.Configuration;
using System.Globalization;
/// <summary>
/// populate country name
/// </summary>
/// <param name="dropDown"></param>
public static void GetCountryNames(DropDownList dropDown)
{
Hashtable h = new Hashtable();
Dictionary<string, string> objDic = new Dictionary<string, string>();
foreach (CultureInfo ObjCultureInfo in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
RegionInfo objRegionInfo = new RegionInfo(ObjCultureInfo.Name);
if (!objDic.ContainsKey(objRegionInfo.EnglishName))
{
objDic.Add(objRegionInfo.EnglishName, objRegionInfo.TwoLetterISORegionName.ToLower());
}
}
SortedList<string, string> sortedList = new SortedList<string, string>(objDic);
foreach (KeyValuePair<string, string> val in sortedList)
{
dropDown.Items.Add(new ListItem(val.Key, val.Key));
}
dropDown.Items.Insert(0, new ListItem("Select", "Select"));
dropDown.Items.Insert(1, new ListItem("Other Country", "Other"));
}
You can use my nuget package Nager.Country. There is a lot of additional information available for each country. For more information please visit the Github project
PM> install-package Nager.Country
ICountryProvider countryProvider = new CountryProvider();
foreach (var countryCode in (Alpha2Code[])Enum.GetValues(typeof(Alpha2Code)))
{
var countryInfo = countryProvider.GetCountry(countryCode);
Console.WriteLine(countryInfo.CommonName);
}
I was successfully able to update one of the fields (which was of type boolean) from infopath for library item using sharepoint object Model as if it was a list item.
But for another field which is of type text, the same code just gets executed but does not change the field value !!!!
I am using following code, which works for that boolean field but for another field of type string , not sure why it is not working. Any idea ?
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPWeb web;
SPSite site = new SPSite("http://sharepointsite");
web = site.OpenWeb();
SPList formLibList = web.Lists["FormLibraryName"];
SPQuery query = new SPQuery(); query.Query = "<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" + titleName + "</Value></Eq></Where>";
web.Site.WebApplication.FormDigestSettings.Enabled = false;
web.AllowUnsafeUpdates = true;
SPListItemCollection col = formLibList.GetItems(query);
if (col.Count > 0)
{
col[0]["CustomerName"] = "test customer name";
col[0].Update();
}
web.Site.WebApplication.FormDigestSettings.Enabled = true; web.AllowUnsafeUpdates = false;
});
Thanks,
Nikhil
I had to declare SPListItem and set it instead of directly modifying list item collection.
It's not an answer to your question (you already found the solution yourself), but you may want to put your SPSite and SPWeb objects in a using block. In your example code you are not disposing them, which results in a memory leak. The correct way would be like this:
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite("http://sharepointsite"))
{
using (SPWeb web = site.OpenWeb())
{
// the rest of your code
}
}
});
Using the SharePoint SDK, I'm attempting to retrieve a list and display the contents in a composite control. The list is audience aware and I'd like to maintain that in my control. How can I go about getting this list, filtered by audience, using the SharePoint SDK? Here's some of the code I'm working with:
SPWeb currentWeb = SPContext.Current.Site.RootWeb;
SPList shortcuts = currentWeb.Lists["Shortcuts"];
Here's some of the code I'm using now, and it's not quite working for me. According to how the audiences are set up, I should be getting results:
protected override void CreateChildControls()
{
dropdown = new DropDownList();
dropdown.Items.Add(new ListItem("Select...", ""));
SPWeb currentWeb = SPContext.Current.Site.RootWeb;
SPList shortcuts = currentWeb.Lists["Shortcuts"];
ServerContext context = ServerContext.GetContext(currentWeb.Site);
AudienceManager audManager = new AudienceManager(context);
AudienceCollection audiences = audManager.Audiences;
AudienceLoader audienceLoader = AudienceLoader.GetAudienceLoader();
foreach (SPListItem listItem in shortcuts.Items)
{
string audienceFieldValue = (string)listItem["Target Audiences"];
if (AudienceManager.IsCurrentUserInAudienceOf(audienceLoader, audienceFieldValue, false))
{
dropdown.Items.Add(new ListItem(listItem.Title, listItem.Url));
}
}
Controls.Add(dropdown);
base.CreateChildControls();
}
On:
if (AudienceManager.IsCurrentUserInAudienceOf(audienceLoader, audienceFieldValue, false))
It's never returning true, even when it should be.
Here's a more succinct code snippet. Main changes are removal of unused objects, and a more efficient version of the foreach loop.
protected override void CreateChildControls()
{
dropdown = new DropDownList();
dropdown.Items.Add(new ListItem("Select...", ""));
SPWeb currentWeb = SPContext.Current.Site.RootWeb;
SPListItemCollection scItems = currentWeb.Lists["Shortcuts"].Items;
AudienceLoader audienceLoader = AudienceLoader.GetAudienceLoader();
// Iterate over a copy of the collection to prevent multiple queries to the list
foreach (SPListItem listItem in scItems)
{
string audienceFieldValue = (string)listItem["Target Audiences"];
if (AudienceManager.IsCurrentUserInAudienceOf(audienceLoader, audienceFieldValue, false))
{
dropdown.Items.Add(new ListItem(listItem.Title, listItem.Url));
}
}
Controls.Add(dropdown);
base.CreateChildControls();
}
Here's a code snippet that maybe could be of use, to determine each items audience:
SPList shortcuts = currentWeb.Lists["Shortcuts"];
SPListItemCollection items = list.Items;
Audience siteAudience;
ServerContext context = ServerContext.GetContext(site);
AudienceManager audManager = new AudienceManager(context);
foreach (SPListItem item in items)
{
string ID = item["Target Audiences"].ToString();
string NewID = ID.Remove(36);
Guid guid = new Guid(NewID);
siteAudience = audManager.GetAudience(guid);
}