CultureInfo: Haitian Creole and .NET 3.5 on ASP.NET/MVC? - asp.net-mvc

It's been easy to get French and Spanish translations added to our site, but we want to add Haitian Creole now and there is no Culture support for it. What's the best way to get this done?

You can create the culture through .Net using the CultureAndRegionInfoBuilder class. As this code needs to run with administrative privileges, it's generally advised that you do it as a separate program or script that runs as part of the installation stage of the software. Once it's set up, you can use it like any other Culture.
This example is based on the example in the MS .Net Application Development Foundation book (2nd ed. p697):
var builder = new CultureAndRegionInfoBuilder("en-PL", CultureAndRegionModifiers.None);
builder.LoadDataFromCultureInfo(new CultureInfo("en-US"));
builder.LoadDataFromRegionInfo(new RegionInfo("US"));
builder.CultureEnglishName = "Pig Latin";
builder.CultureNativeName = "Igpay Atinlay";
builder.IsMetric = true;
builder.ISOCurrencySymbol = "PLD";
builder.RegionEnglishName = "Pig Latin Region";
builder.RegionNativeName = "Igpay Atinlay Egionray";
builder.Register();
Once that's done, you can retrieve your culture in the program.
var culture = new CultureInfo("en-PL");

Related

Hyperlinking a folder stored on iManage

I'm looking for a way to create a hyperlink to a particular folder in Worksite.
So far, I've only come up with a macro linking files on the basis of their database numbers but folders do not have database numbers (I think).
Another thing is that I wanted the folders to be opened in Outlook (Worksite is connected with Outlook and we access folders through it)
What I try to accomplish is creating hyperlinks in Excel for easy folder access (just like hyperlinks to files).
Does anybody have a clue if it's even possible? If yes, I'd appreciate an example of a code for this.
Thanks in advance.
Yes it's possible.
You don't mention which version of the iManage client you're working with however I'm going to assume FileSite 9.x. Installed with that client is a custom protocol handler which supports a custom URI scheme.
In effect this allows you to compose a hyperlink with plain text which you can then embed in your web page, or just start a new process in Windows to let the default browser load it up.
The custom protocol handler will parse it and then start up whatever iManage client it can (FileSite in your case) and then navigate to the correct folder.
Format is iwl:dms=[ServerName]&&lib=[DatabaseName]&&page=[FolderID]
Here's some C# that builds out such a string
var serverName = "MYSERVERNAME";
var databaseName = "MYDBNAME";
var serverName = "1234"; // internal numeric ID of folder (MHGROUP.PROJECTS.PRJ_ID in database, or IManFolder.FolderID via iManage COM API object model
var sb = new StringBuilder("iwl:");
sb.Append($"dms={serverName}");
sb.Append("&&");
sb.Append($"lib={databaseName}");
sb.Append("&&");
sb.Append($"page={serverName}");
// sb.ToString() will now output the hyperlink reference to your folder which you can pass to your web browser..
Sub Folder_link
Dim dmsIM As IManDMS
Dim dmsS As IManSession
Dim dmsD As IManDatabase
Dim FdR As IManFolder
Dim FdrLoc As String
Dim FdrID As Long
Const ServerName As String = <DMS name>
Const DatabaseName As String = <DatabaseName>
FdrLoc = "\\{DMS name}\{DatabaseName}\Main Folder\SubFolder\SubSubFolder\TargetFolderName"
Set dmsIM = New ManDMS
Set dmsS = dmsIM.Sessions.Add(ServerName)
dmsS.TrustedLogin
Set dmsD = dmsS.Databases.ItemByName(DatabaseName)
Set Fdr = Imanage.ImanFolder.Location (FdrLoc)
FdrID = Fdr.FolderID
With ThisWorkBook.WorkSheets(1).Range("A1")
.Hyperlinks.Add _
Anchor:=Selection, _
Address:="iwl:dms={serverName}&&lib={databaseName}&&page=" & FdrID, _
TextToDisplay:="link"
End With
End Sub

Unit Test Formatting of Word/Phrase in View

I'd like to write a test in my project that specifically looks at the HTML and tells me if every instance of a word is always formatted a certain way. Let's say our company has a product named "WidgetFactory". I want to make sure that this "WidgetFactory" is always capitalized the same way, and is always within a <strong> tag.
I'm not sure what the best practice in Unit Testing is. I've glanced at precompiled views, but it never looked quite right. It might be the best solution. I might could open each .cshtml file and try to parse it so that I only look at HTML text, but that could be potentially problematic and I don't really want to write a Razor parser.
Is this possible, or is this a completely wrong way of using a unit test?
This kind of tests should be done in Integration Tests, not unit tests. You don't want to run it everytime you run your other tests, only before you push to prod, and idealy in a continuous integration system like Jenkins or appveyor. You could use a tool like Selenium Webdriver that open a browser (like Chrome) and verify that the end result contains the text the way you want it to be.
I suggest you take a look at the page pattern it really helped us.
Here's what one sample test could look like, note that we have a lot of helper to make the tests clean and easy to read/maintain :
[Test]
public void CreateViewAndEditShouldWork()
{
S.OpenWithCI();
var loginPage = new LoginPage(S);
var centerListPage = loginPage
.LoginValidUser("username", "password")
.MenuClickCenterAndRoomLink();
var centerPage = centerListPage.ClickCreateLink();
//Create
centerPage.Submit();
Assert.That(centerPage.Error("Name"), Is.StringContaining(Strings.Error_Required));
Assert.That(centerPage.Error("EnglishName"), Is.StringContaining(Strings.Error_Required));
centerPage.Name = "Saguenay";
centerPage.EnglishName = "Sag";
centerPage.Address = "2089 blv Talbot";
centerPage.DivisionAfiSelected = true;
centerPage.Submit();
centerListPage.ExpectSuccessNotice(Strings.CenterCreatedSuccessfully);
//View
var centerDetailsPage = centerListPage.ClickDetailsLink("Saguenay");
Assert.That(centerDetailsPage.Title, Is.StringContaining("SAGUENAY"));
Assert.That(centerDetailsPage.Details, Is.StringContaining("Inactive"));
Assert.That(centerDetailsPage.Details, Is.StringContaining("2089 blv Talbot"));
//Edit
centerPage = centerDetailsPage.ClickEdit();
centerPage.Name = "Chicoutimi";
centerPage.Submit();
centerListPage.ExpectSuccessNotice(Strings.CenterUpdatedSuccessfully);
}
Hope it helps!

How to programmatically access the built-in/core properties of an Excel file using OpenXML sdk 2.0.?

I would like to access some of the built-in/core properties(like Revision Number, Version Number, etc.) of an Excel 2010 file using OpenXML SDK 2.0. So I wonder if there is any class or any way I could programmatically get and set the core properties.
I just found a solution for my requirement, I used the below code to do so,
using (SpreadsheetDocument myWorkbook = SpreadsheetDocument.Open(filePath,true))
{
var props = myWorkbook.PackageProperties;
string revision = props.Revision;
props.Revision = "2.5";
myWorkbook.Close();
}

Unit Price Attribute Not Visible in Quickbooks Desktop API

I don't see the Unit Price attribute available in the Item Class when it comes to QBD. Its available in QBO. I am trying to download and fill a database using the items entered via Quickbooks desktop version. Can someone help please?
How can I get the Unit Price for an item in Intuit.Ipp.Data.Qbd.Item?
Extra Information Added after comment by Shivan Raptor (7-Nov-2013)
I am having a Quickbooks Pro Trial 2014 UK version installed in my computer. I have created a company file and items for the company. When I create an item I can enter a Price to that item. Quickbooks must be saving it somewhere. I need to access it using the Quickbooks API from my .Net application.
I am interested on the stock items here. I am using Intuit.Ipp.Data.Qbd.Item class to access it. Am I using the right class? If you go to the API documentation the Item class has a field called Unit Price but its not listed when you actually check from the .Net application.
Shivan Raptor wanted the code (8-Nov-2013)
Given below is the code snippet. If you understand the question properly you would realize it cannot give a run time error because you cannot compile a code if you write it with object attributes that are not exposed. And the compiler error is kind of obvious too:
ATTRIBUTE_NAME not present in CLASS_NAME
In this case, ATTRIBUTE_NAME = UnitPrice and CLASS_NAME = Intuit.Ipp.Data.Qbd.Item (this is already there in the first post itself)
The relevant code sample is given below. Its the code behind of an ASP.Net page.
Try
Dim varItemBL As New BL.ItemManagement
'Preparing Query
Dim qbdItemQuery As New Intuit.Ipp.Data.Qbd.ItemQuery
qbdItemQuery.ItemElementName = Intuit.Ipp.Data.Qbd.ItemChoiceType4.StartPage
qbdItemQuery.Item = "1"
qbdItemQuery.ChunkSize = "10"
'Quering Quickbooks Desktop
Dim qbdItems = qbdItemQuery.ExecuteQuery(Of Intuit.Ipp.Data.Qbd.Item)(context).ToList
'Synchronising Items from Quickbooks to MyDigiRep
For i As Integer = 0 To qbdItems.Count - 1
Dim varUnitPrice As Decimal
'Checking whether Unit Price is entered
If qbdItems(i).UnitPrice Is Nothing Then
varUnitPrice = 0
Else
varUnitPrice = qbdItems(i).UnitPrice.Amount
End If
'Synchronising Item with the MyDigiRep database
varItemBL.fnAddItemsAPI(qbdItems(i).Name, "NS", varUnitPrice, _
qbdItems(i).UOMAbbrv, HttpContext.Current.Session("companyID"), _
qbdItems(i).Id.Value)
Next
'Updating UI to display synchronisation results
lblItemSycnStatus.Text = qbdItems.Count & " Item Records Synchronised."
Catch ex As Exception
lblItemSycnStatus.Text = "Item Records Synchronisation Failed."
End Try
The version of the Intuit.Ipp.Data.dll is 2.1.12.0

Liferay: Default Language by Site

I have one portal and several communities (LR 6.1 - sites). The communities allocate several regions with different languages, hence I would like set different default languages for each community.
Is it possible to set default language by site?
I need it for CMS requirements: every site has a own default language for content. For example site in Germany must have germany as default language, and site in Spain have a spanish as default language and so on.
I'm not aware that configuration setting for default language per site (if you mean community/organization...) exists.
For entire portal you have "Default Language" option under
Control panel -> Portal settings -> Display settings
But if you don't have your language there, or you want to remove/add some languages you can configure that in portal-ext.properties. For example
locales=hr_HR,en_US
EDIT (more info about bug mentioned in comment)
If you take a look at com.liferay.portal.service.impl.CompanyLocalServiceImpl
public void updatePreferences(long companyId, UnicodeProperties properties)
throws PortalException, SystemException {
PortletPreferences preferences = PrefsPropsUtil.getPreferences(
companyId);
try {
String newLocales = properties.getProperty(PropsKeys.LOCALES);
if (newLocales != null) {
String oldLocales = preferences.getValue(
PropsKeys.LOCALES, StringPool.BLANK);
if (!Validator.equals(oldLocales, newLocales)) {
validateLocales(newLocales);
LanguageUtil.resetAvailableLocales(companyId);
}
}
...
}
protected void validateLocales(String locales) throws PortalException {
String[] localesArray = StringUtil.split(locales, StringPool.COMMA);
for (String locale : localesArray) {
if (!ArrayUtil.contains(PropsValues.LOCALES, locale)) {
throw new LocaleException();
}
}
}
you will see that "newLocales" are validate against
if (!ArrayUtil.contains(PropsValues.LOCALES, locale)) {
throw new LocaleException();
}
so if you add new locale key, in Display page of Portal settings, which is not in portal-ext.properties or portal.properties you'll get LocaleException.
Pay attention that oldLocales are read from preferences (database) String oldLocales = preferences.getValue(PropsKeys.LOCALES, StringPool.BLANK);
and validated against portal.properties/portal-ext.properties if (!ArrayUtil.contains(PropsValues.LOCALES, locale)) { ...
PropsValues.LOCALES => public static String[] LOCALES = PropsUtil.getArray(PropsKeys.LOCALES);
As stated in comment this behavior will happen if (and only if) you add new locale (in GUI) that is not in portal.properties
locales=ar_SA,eu_ES,bg_BG,ca_AD,ca_ES,zh_CN,zh_TW,hr_HR,cs_CZ,da_DK,nl_NL,nl_BE,en_US,en_GB,et_EE,fi_FI,fr_FR,gl_ES,de_DE,el_GR,iw_IL,hi_IN,hu_HU,in_ID,it_IT,ja_JP,ko_KR,lo_LA,nb_NO,fa_IR,pl_PL,pt_BR,pt_PT,ro_RO,ru_RU,sr_RS,sr_RS_latin,sl_SI,sk_SK,es_ES,sv_SE,tr_TR,uk_UA,vi_VN
or if you modified locales in portal-ext.properties than if not in portal-ext.properties.
For example if you have in portal-ext.properties
locales=en_GB
you will not be able to add any other locale from GUI unles you first add new locale to portal-ext.properties AND then go to Display page of Portal settings and add it there again.
there might be a way based on how you organize your editors: The default language for web content is based on the current language (e.g. the default language) of the user. Typically german users might have their language set to german, in order to read the german content version, no?
Alternatively you'd have to customize Liferay (e.g. the webcontent editor) and manually set the default language based on some property in the current site - this might be stored as custom field aka expando. This way it will truly be based on the site that content is being created in, but this might conflict with the current user's expectation: What do they set their default language for when the editor doesn't honor this?
Still - in your case the expectation might even be what you describe, so it's a valid option.
Is this level of detail enough?

Resources