Awesomium WebControl Clicking/Writing - awesomium

I am trying to let click/write on the Awesomium WebControl, but it doesn't work.
This is the code that I use:
WebControl1.Source = New Uri("website") 'i dont put the website
xpath=link.xpath
Dim nlink As JSObject = WebControl1.ExecuteJavascriptWithResult([String].Format("document.evaluate(""{0}"", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue", xpath))
nlink.InvokeAsync("click")
end if
next

If you want to just trigger 'click' on your website content, that should work (using jQuery):
WebControl1.ExecuteJavascript(#"$(document.body).trigger('click');");
or (I've found it here, not tested):
dynamic document = (JSObject)webView.ExecuteJavascriptWithResult("document");
if (document == null)
return;
using (document)
{
dynamic signin = document.getElementById("signin");
if (signin == null)
return;
using (signin)
signin.click();
}
Remember to wait till DocumentReady is Loaded state:
private void BaseWebControl_DocumentReady(object sender, DocumentReadyEventArgs e)
{
if (e.ReadyState != DocumentReadyState.Loaded) return;
// Now!
}
EDIT:
<a id="foo" href="http://...." target="_blank">Test link</a>
in jQuery:
jQuery('#foo')[0].click();

Related

Acumatica - FieldDefaulting update ImageUrl from DAC extension

I am trying to update the Inventory Item ImageUrl if it is found to be null with some conditions. I have added a Usr field called UsrStyleImg to the Item Class screen. This field is for a basic image of an item and it is stored in the database. The functionality I want is if the Inventory Item does not have an image in the ImageUrl then it will default to the UsrStyleImg that is connected with the ItemClassID. ItemClassID is also found on the Stock Item Screen. Here is the code I have in the InventoryItemMaint graph:
protected void InventoryItem_ImageUrl_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
{
var row = (InventoryItem)e.Row;
if (row == null) return;
var item = (INItemClass)PXSelect<INItemClass, Where<INItemClass.itemClassID, Equal<Current<InventoryItem.itemClassID>>>>.Select(Base, row.ItemClassID);
var image = PXSelect<InventoryItem, Where<InventoryItem.imageUrl, Equal<Current<InventoryItem.imageUrl>>>>.Select(Base, row.ImageUrl);
if (image != null)
return;
else {
e.NewValue = item.GetExtension<INItemClassExt>().UsrStyleImg;
}
}
The code compiles fine but when I test with an Item that has an Item Class attached to it with an image in the INItemClass table called UsrStyleImg it does not populate to the imageUrl found in the Inventory Item table or the Stock Item screen. I have also tried this with FieldSelecting and using the e.ReturnValue with still the same results.
If I need more clarification please let me know.
Try using a RowSelecting Event
protected virtual void InventoryItem_RowSelecting(PXCache sender, PXRowSelectingEventArgs e)
{
InventoryItem row = e.Row as InventoryItem;
//Extra checks to prevent infinite loops
if (row != null && !string.IsNullOrWhiteSpace(row.InventoryCD) && Base.Item.Cache.GetStatus(row) == PXEntryStatus.Notchanged)
{
if (!string.IsNullOrWhiteSpace(row.ItemClassID))
{
//You must always use a PXConnectionScope if Selecting during RowSelecting
using (new PXConnectionScope())
{
//If you're going to pass in a value in .Select, use Required instead of Current.
INItemClass itemClass = PXSelectReadonly<INItemClass, Where<INItemClass.itemClassID, Equal<Required<INItemClass.itemClassID>>>>.Select(Base, row.ItemClassID);
if (itemClass != null && string.IsNullOrWhiteSpace(row.ImageUrl))
{
INItemClassExt itemClassExt = itemClass.GetExtension<INItemClassExt>();
//To prevent unneeded update if it's blank
if (!string.IsNullOrWhiteSpace(itemClassExt.UsrStyleImg))
{
row.ImageUrl = itemClassExt .UsrStyleImg;
//Force set the status in the Cache, otherwise it infinite loops
Base.Item.Cache.SetStatus(row, PXEntryStatus.Updated);
Base.Item.Update(row);
}
}
}
}
}
}

lotus.domino.local.Item cannot be cast to lotus.domino.RichTextItem

I try to put a file into a richtext but it crashes !
In my first code, I try to use directly "getFirstItem", in first time it was ok but now i try to use it again and it crashed.
In second time i pass with an object and it find my obj doesn't an richtextItem (instanceof) ???
I don't understand.
I have the message : "lotus.domino.local.Item cannot be cast to lotus.domino.RichTextItem" ?
Could you help me ?
public void copieFichierDansRichText(String idDocument, String nomRti, File file,
String nameFichier, String chemin) throws NotesException {
lotus.domino.Session session = Utils.getSession();
lotus.domino.Database db = session.getCurrentDatabase();
lotus.domino.Document monDoc = db.getDocumentByUNID(idDocument);
lotus.domino.RichTextItem rtiNew = null;
try {
try {
if (monDoc != null) {
// if (monDoc.getFirstItem(nomRti) != null) {
// rtiNew = (lotus.domino.RichTextItem)
// monDoc.getFirstItem(nomRti);
// } else {
// rtiNew = (lotus.domino.RichTextItem)
// monDoc.createRichTextItem(nomRti);
// }
Object obj = null;
if (monDoc.getFirstItem(nomRti) != null) {
obj = monDoc.getFirstItem(nomRti);
if (obj instanceof lotus.domino.RichTextItem) {
rtiNew = (lotus.domino.RichTextItem) obj;
}
} else {
obj = monDoc.createRichTextItem(nomRti);
if (obj instanceof lotus.domino.RichTextItem) {
rtiNew = (lotus.domino.RichTextItem) obj;
}
}
PieceJointe pieceJointe = new PieceJointe();
pieceJointe = buildPieceJointe(file, nameFichier, chemin);
rtiNew.embedObject(EmbeddedObject.EMBED_ATTACHMENT, "", pieceJointe.getChemin()
+ pieceJointe.getNomPiece(), pieceJointe.getNomPiece());
monDoc.computeWithForm(true, false);
monDoc.save(true);
}
} finally {
rtiNew.recycle();
monDoc.recycle();
db.recycle();
session.recycle();
}
} catch (Exception e) {
e.printStackTrace();
}
}
EDIT : I try to modify my code with yours advices but the items never considerate as richtextitem. It is my problem. I don't understand why, because in my field it is a richtext ! For it, the item can't do :
rtiNew = (lotus.domino.RichTextItem) item1;
because item1 not be a richtext !!!
I was trying to take all the fields and pass in the item one by one, and it never go to the obj instance of lotus.domini.RichTextItem....
Vector items = doc.getItems();
for (int i=0; i<items.size(); i++) {
// get next element from the Vector (returns java.lang.Object)
Object obj = items.elementAt(i);
// is the item a RichTextItem?
if (obj instanceof RichTextItem) {
// yes it is - cast it as such // it never go here !!
rt = (RichTextItem)obj;
} else {
// nope - cast it as an Item
item = (Item)obj;
}
}
A couple of things. First of all I would set up a util class method to handle the object recycling in a neater way:
public enum DominoUtil {
;
public static void recycle(Base... bases) {
for (Base base : bases) {
if (base != null) {
try {
base.recycle();
} catch (Exception e) {
// Do nothing
}
}
}
}
}
Secondly I would remove the reduntants try/catch blocks and simplify it like this:
private void copieFichierDansRichText(String idDocument, String nomRti, File file,
String nameFichier, String chemin) {
Session session = DominoUtils.getCurrentSession();
Database db = session.getCurrentDatabase();
Document monDoc = null;
try {
monDoc = db.getDocumentByUNID(idDocument);
Item item = monDoc.getFirstItem(nomRti);
if (item == null) {
item = monDoc.createRichTextItem(nomRti);
} else if (item.getType() != Item.RICHTEXT) {
// The item is not a rich text item
// What are you going to do now?
}
RichTextItem rtItem = (RichTextItem) item;
PieceJointe pieceJointe = new PieceJointe();
pieceJointe = buildPieceJointe(file, nameFichier, chemin);
rtItem.embedObject(EmbeddedObject.EMBED_ATTACHMENT, "", pieceJointe.getChemin()
+ pieceJointe.getNomPiece(), pieceJointe.getNomPiece());
monDoc.computeWithForm(true, false);
monDoc.save(true);
} catch (NotesException e) {
throw new FacesException(e);
} finally {
DominoUtil.recycle(monDoc);
}
}
Finally, apart from the monDoc, you need not recycle anything else. Actually Session would be automatically recycled and anything beneath with it (so no need to recycle db, let alone the session!, good rule is don't recycle what you didn't instantiate), but it's not bad to keep the habit of keeping an eye on what you instantiate. If it were a loop with many documents you definitively want to do that. If you also worked with many items you would want to recycle them as early as possible. Anyway, considered the scope of the code it's sufficient like this. Obviously you would call DominoUtil.recycle directly from the try block. If you have multiple objects you can recycle them at once possibly by listing them in the reverse order you set them (eg. DominoUtil.recycle(item, doc, view)).
Also, what I think you miss is the check on the item in case it's not a RichTextItem - and therefore can't be cast. I put a comment where I think you should decide what to do before proceeding. If you let it like that and let the code proceed you will have the code throw an error. Always better to catch the lower level exception and re-throw a higher one (you don't want the end user to know more than it is necessary to know). In this case I went for the simplest thing: wrapped NotesException in a FacesException.

Xamarin.Forms Warning: Attempt to present * on * whose view is not in the window hierarchy with iOS image/gesture recogniser

I have a modal Navigation page with an image which acts like a button;
<Image Source ="share.png" HeightRequest="32" WidthRequest="32">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="On_Share" />
</Image.GestureRecognizers>
</Image>
And the method behind;
async void On_Share(object sender, EventArgs e)
{
if (CrossConnectivity.Current.IsConnected)
{
var message = "Share this";
var title = "Share";
await CrossShare.Current.Share(new ShareMessage { Text = message, Title = title}, new ShareOptions { ExcludedUIActivityTypes = new[] { ShareUIActivityType.PostToFacebook } });
}
else
{
NoInternetLabel.IsVisible = true;
}
}
I'm getting the error when I try to click on the share image/button. I've put breakpoints into the first line of the On_Share method & they're not being hit.
Warning: Attempt to present <UIActivityViewController: 0x141b60f70> on <Xamarin_Forms_Platform_iOS_ModalWrapper: 0x1419a0920> whose view is not in the window hierarchy!
Please note this works fine in Android, I'm only seeing issues in iOS. I'm not sure what is going on - I'm not trying to present any other windows or anything when I click the image. Regardless, the error appears before the process reaches the beginning of the On_Share method. What am I missing here?
EDIT: The method does get hit now, and I'm still getting the error. It must be trying to send up the share sheet and failing...
There was a problem with the Share plugin in the end - we resolved it by making part of the code recursive.
the GetVisibleViewController used to look like this;
UIViewController GetVisibleViewController()
{
var rootController = UIApplication.SharedApplication.KeyWindow.RootViewController;
if (rootController.PresentedViewController == null)
return rootController;
if (rootController.PresentedViewController is UINavigationController)
{
return ((UINavigationController)rootController.PresentedViewController).VisibleViewController;
}
if (rootController.PresentedViewController is UITabBarController)
{
return ((UITabBarController)rootController.PresentedViewController).SelectedViewController;
}
return rootController.PresentedViewController;
}
whereas it needed to cycle through to find the top UIViewController;
UIViewController GetVisibleViewController(UIViewController controller = null)
{
controller = controller ?? UIApplication.SharedApplication.KeyWindow.RootViewController;
if (controller.PresentedViewController == null)
return controller;
if (controller.PresentedViewController is UINavigationController)
{
return ((UINavigationController)controller.PresentedViewController).VisibleViewController;
}
if (controller.PresentedViewController is UITabBarController)
{
return ((UITabBarController)controller.PresentedViewController).SelectedViewController;
}
return GetVisibleViewController(controller.PresentedViewController);
}
I've raised the issue and submitted a pull request on the github

WinRT Selectively hide a child of a ListViewItem based on the ListViewItem's sibling

I am using a ListView and set the ItemsSources to an ObservableCollection of Message objects. The DataTemplate for the ListViewItem contains a custom control. I have defined a Message property on the custom control and am binding the Message property on this custom control to the dataContext of the ListViewItem. When the loaded event gets fired on the custom control, I want to compare the ReceivedDate set on its Message to the ReceivedDate set on the sibling of this ListViewItem. This is not working consistently since the Message property is set on some of the ListViewItems by the time the Loaded event is fired and not set on some.
Example:
<local:ListView x:Name="MyMessagesView"
Visibility="Collapsed"
ItemsSource="{Binding Messages}"
ItemContainerStyle="{StaticResource AppListViewItemStyle}">
<ListView.ItemTemplate>
<DataTemplate>
<dm:MyScreenRow Message="{Binding}"/>
</DataTemplate>
</ListView.ItemTemplate>
</local:ListView>
In the code behind of my CustomControl, I handle the Loaded event. I want to compare the ReceivedTime property set on the current ListViewItem to its previous sibling and show a child element in the ListViewItem. Is Loaded event not the correct place to handle this? If not, any recommendations on how to handle this?
public MyScreenRow()
{
this.InitializeComponent();
this.Loaded += MyScreenRow_Loaded;
}
private static void MyScreenRow_Loaded(object sender, RoutedEventArgs e)
{
MyScreenRow screenRow = sender as MyScreenRow;
if (screenRow.Message == null)
{
return;
}
ListViewItemPresenter presenter = (ListViewItemPresenter)VisualTreeHelper.GetParent(screenRow);
if (presenter != null)
{
ListViewItem currentViewItem = (ListViewItem)VisualTreeHelper.GetParent(presenter);
if (currentViewItem != null)
{
ListView listView = (ListView)ItemsControl.ItemsControlFromItemContainer(currentViewItem);
if (listView != null)
{
int indexOfCurrentContainer = listView.IndexFromContainer(currentViewItem);
if (indexOfCurrentContainer == 0)
{
screenRow.GroupHeader.Visibility = Visibility.Visible;
}
else
{
// Get the previous container info
ListViewItem previousViewItem = (ListViewItem)listView.ContainerFromIndex(indexOfCurrentContainer - 1);
if (previousViewItem != null)
{
MyScreenRow previousScreenRow = (MyScreenRow)previousViewItem.ContentTemplateRoot;
if (previousScreenRow != null
&& previousScreenRow.Message != null
&& previousScreenRow.Message.ReceivedTimeUtc != null)
{
if (screenRow.Message != null
&& screenRow.Message.ReceivedTimeUtc != null)
{
if (previousScreenRow.Message.ReceivedTimeUtc.Date.CompareTo(screenRow.Message.ReceivedTimeUtc.Date) != 0)
{
screenRow.GroupHeader.Visibility = Visibility.Visible;
}
}
}
}
}
}
}
}
}
Yes.. as you guessed doing it in the loaded event will not work becuase the loaded event is fired only Once when the listview is first instantiated and loaded with some elements after that it isn't fired.
I strongly suggest you use the LayoutUpdated Event .
This is a part of UIElement so every control in the windows universe must have it.
it is triggered when there is a layout change .. in case of lists when new items are added or deleted ..
Now to some more fun part .. if you don't want to do it all your controls at once then you can use ContainerContentChanging this will allow you to apply changes on the items in view only.
<ListView LayoutUpdated="ListView_LayoutUpdated" ContainerContentChanging="ListView_ContainerContentChanging"/>
Quick tutorial link : http://blogs.msdn.com/b/hanxia/archive/2013/11/04/incremental-update-item-data-for-listviewbased-controls-in-windows-8-1.aspx

Add Facebook Open Graph Protocol Meta Tags to sharepoint

When I like an article on our website (www.potatopro.com) with a Facebook like and a facebook sharebutton the wrong website data is being fetched.
Either you are not able to change the picture or in the other case facebook fetches the navigation instead of the content.
To my understanding I have to implement facebook's open graph protocol meta-tags on our site. But how do I do that for a sharepoint based website?! Please advice!
You can add a webpart to the pagelayout that your page is using. In the webpart you add a function that finds the title, content and image on the page and writes metatags to the masterpage that the page is using. Here is an example of the function...
protected override void Render(HtmlTextWriter writer)
{
if (SPContext.Current != null && SPContext.Current.ListItem != null)
{
SPListItem item = SPContext.Current.ListItem;
var title = item["Title"];
if (title != null)
{
writer.WriteBeginTag("meta");
writer.WriteAttribute("property", "og:title");
writer.WriteAttribute("content", title.ToString());
writer.WriteEndTag("meta");
}
var pageContent = item["PublishingPageContent"];
if (pageContent != null)
{
string strippedPageContent = Regex.Replace(pageContent.ToString(), #"<(.|\n)*?>", string.Empty);
writer.WriteBeginTag("meta");
writer.WriteAttribute("property", "og:description");
writer.WriteAttribute("content", strippedPageContent);
writer.WriteEndTag("meta");
}
var pageImage = item["PublishingPageImage"];
if (pageImage != null)
{
ImageFieldValue pageImageValue = pageImage as ImageFieldValue;
if (pageImageValue != null)
{
var url = pageImageValue.ImageUrl;
writer.WriteBeginTag("meta");
writer.WriteAttribute("property", "og:image");
writer.WriteAttribute("content", url);
writer.WriteEndTag("meta");
}
}
}
}

Resources