I want to capture query component mode(Basic | Advanced) in processQuery event listener method for QueryEvent as below:
public void processQuery(QueryEvent queryEvent)
{
// Add event code here...
QueryDescriptor qdesc = queryEvent.getDescriptor();
String searchName = qdesc.getName();
String queryMode =?
I tried to get this value from getUIHints() map using UIHINT_MODE key. but getUIHints() returns empty map.
Try this :
ViewCriteria vc = null;
try
{
Method m =
pQueryDescriptor.getClass().getDeclaredMethod("getViewCriteria",
null);
m.setAccessible(true);
vc = (ViewCriteria) m.invoke(pQueryDescriptor, null);
}
catch (Exception ite)
{
_logger.logp(Level.SEVERE, CLAZZ_NAME, methodName,
"Exception getting ViewCriteria from QueryDescriptor.",
ite);
}
String searchType =
(String) vc .getProperty(ViewCriteriaHints.CRITERIA_MODE);
The idea is to get the ViewCriteria from the QueryDescriptor and to get the mode from the VC. This is becasue the mode is set on the criteria object itself, the VC knows how to display and what to display in each mode, and so it makes the MODE an inherent property of the VC and not just a UI thing....
QueryDescriptor qdesc = queryEvent.getDescriptor();
QueryDescriptor.QueryMode mode = (QueryDescriptor.QueryMode) qdesc.getUIHints().get(qdesc.UIHINT_MODE);
if("BASIC".equals(mode.toString())){
}
Related
Suppose I have 3 entities generated from EF, say tab1, tab2 and tab3. In SL app, I call SubmitChanges to save data to DB, all changes will be process by WCF and EF automatically.
Question is: how can I know the order of Update operation in Database?
I need to know this because I have triggers on those tables and need to know the order of the updating.
One thing you can do is to override the PeristChangeSet() in your DomainService and manually control the order of saves. Just do nothing in your regular update/insert statements. Here's some pseudocode for a saving a document exmmple to explain my answer:
[Insert]
public void InsertDocument(MyDocument objDocument) { }
[Update]
public void UpdateDocument(MyDocument objDocument) { }
protected override bool PersistChangeSet()
{
try {
// have to save document first to get its id....
MyDocument objDocumentBeingSaved = null;
foreach (ChangeSetEntry CSE in ChangeSet.ChangeSetEntries.Where(i => i.Entity is MyDocument)) {
var changedEntity = (MyDocument)CSE.Entity;
objDocumentBeingSaved = documentRepository.SaveDocument(changedEntity);
break; // only one doc
}
if (objDocumentBeingSaved == null)
throw new NullReferenceException("CreateDocumentDomainService.PersistChangeSet(): Error saving document information. Document is null in entity set.");
// save document assignments after saving document object
foreach (ChangeSetEntry CSE in ChangeSet.ChangeSetEntries.Where(i => i.Entity is DocumentAssignment)) {
var changedEntity = (DocumentAssignment)CSE.Entity;
changedEntity.DocumentId = objDocumentBeingSaved.Id;
changedEntity.Id = documentRepository.SaveDocumentAssignment(objDocumentBeingSaved, changedEntity);
}
// save line items after saving document assignments
foreach (ChangeSetEntry CSE in ChangeSet.ChangeSetEntries.Where(i => i.Entity is LineItem)) {
var changedEntity = (LineItem)CSE.Entity;
changedEntity.DocumentId = objDocumentBeingSaved.Id;
changedEntity.Id = documentRepository.SaveLineItem(objDocumentBeingSaved, changedEntity);
}
documentRepository.GenerateDocumentNumber(objDocumentBeingSaved.Id);
}
catch {
// ....
throw;
}
return false;
}
If I record actions to enter in login credentials into a dialog and call this Submit() in say UImap1.uitests. The autogenerated code will look something like this:
public void Launch()
{
#region Variable Declarations
WpfEdit uIUsernameBoxEdit = this.UIOCC600OILoginWindow.UIUsernameBoxEdit;
WpfEdit uIPasswordBoxEdit = this.UIOCC600OILoginWindow.UIPasswordBoxEdit;
WpfButton uIOKButton = this.UIOCC600OILoginWindow.UIOKButton;
#endregion
// Type 'username' in 'usernameBox' text box
uIUsernameBoxEdit.Text = this.LaunchParams.UIUsernameBoxEditText;
// Click 'passwordBox' text box
Mouse.Click(uIPasswordBoxEdit, new Point(63, 13));
// Type '********' in 'passwordBox' text box
Keyboard.SendKeys(uIPasswordBoxEdit, this.LaunchParams.UIPasswordBoxEditSendKeys, true);
// Click 'OK' button
Mouse.Click(uIOKButton, new Point(33, 14));
}
Now, if I manually launch the application under a method decorded with ClassInitialize in my in my CodedUI test class as follows:
[ClassInitialize()]
public static void MyTestInitialize(TestContext context)
{
Process.Start(#"C:\Program Files (x86)\MyCompany\MyApp.exe");
Playback.Wait(2000);
var uimap = new LaunchApplicationMap();
var loginParams = uimap.EnterLoginCredentialsParams;
loginParams.UIUsernameBoxEditText = "username";
loginParams.UIPasswordBoxEditSendKeys = Playback.EncryptText("password
");
uimap.Launch();
Playback.Wait(5000);
}
why do I get the following a null exception as shown below?
This is also the stack trace:
System.NullReferenceException was unhandled by user code
Message=Object reference not set to an instance of an object.
Source=Microsoft.VisualStudio.TestTools.UITest.Framework
StackTrace:
at Microsoft.VisualStudio.TestTools.UITest.Framework.UITestService.TechnologyManagerByName(String technologyName)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.ValidateSearchProperties()
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindInternal()
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindControlIfNecessary()
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.SetProperty(String propertyName, Object value)
at Microsoft.VisualStudio.TestTools.UITesting.WpfControls.WpfEdit.set_Text(String value)
at UITests.UIMaps.LaunchApplicationMapClasses.LaunchApplicationMap.Launch() in C:\dev\OCC600\Source - Copy\Tests\UITests\UIMaps\LaunchApplicationMap.Designer.cs:line 44
at UITests.LogsViewTests.MyTestInitialize(TestContext context) in C:\dev\OCC600\Source - Copy\Tests\UITests\LogsViewTests.cs:line 70
InnerException:
TIA.
You need to initialize the playback engine to use CodedUI outside of a test method. The framework automatically initializes playback/cleanup in the testinitalize/cleanup methods so you don't see it in there.
ClassInitialize/AssemblyInitialize happen before any tests begin so you have to call Playback.Initialize().
question 1. I have this issue of "Object reference not set to an instance of an object" when my Majorlabel is empty and this occurs after i try to do a save button click on xml serialization. How can i fix this?
private void SaveButton_Click(object sender, RoutedEventArgs e)
{
string savepath;
SaveFileDialog DialogSave = new SaveFileDialog();
// Default file extension
DialogSave.DefaultExt = "txt";
// Available file extensions
DialogSave.Filter = "XML file (*.xml)|*.xml|All files (*.*)|*.*";
// Adds a extension if the user does not
DialogSave.AddExtension = true;
// Restores the selected directory, next time
DialogSave.RestoreDirectory = true;
// Dialog title
DialogSave.Title = "Where do you want to save the file?";
// Startup directory
DialogSave.InitialDirectory = #"C:/";
DialogSave.ShowDialog();
savepath = DialogSave.FileName;
DialogSave.Dispose();
DialogSave = null;
FormSaving abc = new FormSaving();
if (!string.IsNullOrEmpty(MajorversionresultLabel.Content.ToString()))
{
abc.Majorversion = MajorversionresultLabel.Content.ToString();
}
abc.Startzbuildfrom = StartzbuildcomboBox.SelectedItem.ToString();
using (Stream savestream = new FileStream(savepath, FileMode.Create))
{
XmlSerializer serializer = new XmlSerializer(typeof(FormSaving));
serializer.Serialize(savestream, abc);
}
}
As recommended,
here is the line of error:
if (!string.IsNullOrEmpty(MajorversionresultLabel.Content.ToString()))
{
abc.Majorversion = MajorversionresultLabel.Content.ToString();
}
Question 2. I used this line to save my combo box selection:
abc.Startzbuildfrom = StartzbuildcomboBox.SelectedItem.ToString();
and in my load i have this line:
StartzbuildcomboBox.SelectedItem = abc.Startzbuildfrom
why wont it select the combobox selection previously?
As a first note, I'd recommend only putting one question into a single query here. Makes it easier.
For your second question, my guess is that you're running into a reference variable problem. I think that calling the ToString() method on the SelectedItem actually creates an entirely new string variable. Then, when you try to set the selected item later, it can't find the new string as a possible item to select because, even though the two strings have the same value, they are different objects. I would maybe recommend that you either:
1) Set the selected item by searching through your combo box contents to find a string whose value matches the one you've saved
or
2) Save the actual reference by saying abc.Startzbuildfrom = StartzbuildcomboBox.SelectedItem. Then set the selected item from that reference.
I suspect that MajorversionresultLabel is null, or MajorversionresultLabel.Content is null. Thus your statement
if (!string.IsNullOrEmpty(MajorversionresultLabel.Content.ToString()))
will throw a NullReferenceException. Try this instead:
if (MajorversionresultLabel != null && MajorversionresultLabel.Content != null && MajorversionLabel.Content.ToString() != string.Empty)
I bet your NullReferenceException will go away.
Im using Linq...more specifically, PLINQO. anyway the following is an example of a query I have bound to a datagridview (winforms):
public static List<Task> GetUserTasks( Guid userID ) {
using (myDataContext ctx = new myDataContext()) {
try {
return ctx.Manager.Task.GetByUserID( userID ).ToList();
} catch (Exception) {
throw;
}
}
}
In my UI, I have the following setup to bind:
BindingSource bs = new BindingSource();
bs.DataSource = DUtasks.GetUserTasks( User.Current.UserID );
dgvTasks.DataSource = bs;
It works, but no sorting is possible. I tried "AsEnumerable()" instead of "ToList()" but that for some reason, throws an "objection reference" error. Any ideas as to how I can proceed on this front?
Many thanks!
OK, problem sorted!!! :)
found the following link: SortableBindingList... (my comment is at the bottom with converted C# working code).
Now all my query methods that return List<(ENTITY)> simply get used like this:
SortableBindingList<Task> sortedTasks = new SortableBindingList<Task>( DUtasks.GetUserTasks( User.Current.UserID ) );
dgvTasks.DataSource = sortedTasks;
dgvTasks.Sort( colTaskDue, ListSortDirection.Ascending );
Hope this helps someone!
Have you tried returning an IOrderedEnumerable? Not sure if it will help but that is designed to handle ordered LINQ results.
use only MySortableBindingList class in this page Implementing-a-Sortable-BindingList-
then
var yourLinqList = ...;
MySortableBindingList sortList = new MySortableBindingList(yourLinqList);
dataGridView1.DataSource = sortList;
then your dataGridView must be sort when cell header click.
I'm trying to get the Int64 value of a Directory Services object's "uSNChanged" value. Unfortunately, it is always coming back as a COM object of some kind. I've tried using casting to Int64, calling Int64.Parse(), and calling Convert.ToInt64(). None of these work.
For a given DirectoryEntry object, this code will display the properties:
private static void DisplaySelectedProperties(DirectoryEntry objADObject)
{
try
{
string[] properties = new string[] {
"displayName",
"whenCreated",
"whenChanged",
"uSNCreated",
"uSNChanged",
};
Console.WriteLine(String.Format("Displaying selected properties of {0}", objADObject.Path));
foreach (string strAttrName in properties)
{
foreach (var objAttrValue in objADObject.Properties[strAttrName])
{
string strAttrValue = objAttrValue.ToString();
Console.WriteLine(String.Format(" {0, -22} : {1}", strAttrName, strAttrValue));
}
}
Console.WriteLine();
}
catch (Exception ex)
{
throw new ApplicationException(string.Format("Fatal error accessing: {0} - {1}", objADObject.Path, ex.Message), ex);
}
}
This is the output:
Displaying selected properties of LDAP://server/o=org/cn=obj
displayName : Display Name
whenCreated : 7/8/2009 7:29:02 PM
whenChanged : 7/8/2009 10:42:23 PM
uSNCreated : System.__ComObject
uSNChanged : System.__ComObject
How do I convert that System.__ComObject into a Int64?
Solution Used:
This is the solution I used based on marc_s's solution below:
public static Int64 ConvertADSLargeIntegerToInt64(object adsLargeInteger)
{
var highPart = (Int32)adsLargeInteger.GetType().InvokeMember("HighPart", System.Reflection.BindingFlags.GetProperty, null, adsLargeInteger, null);
var lowPart = (Int32)adsLargeInteger.GetType().InvokeMember("LowPart", System.Reflection.BindingFlags.GetProperty, null, adsLargeInteger, null);
return highPart * ((Int64)UInt32.MaxValue + 1) + lowPart;
}
I'm using this snippet of code in my ADSI Browser BeaverTail which is written in C#:
Int64 iLargeInt = 0;
IADsLargeInteger int64Val = (IADsLargeInteger)oPropValue.LargeInteger;
iLargeInt = int64Val.HighPart * 4294967296 + int64Val.LowPart;
As far as I can tell, this should work just fine.
Marc
It looks like it's an IADsLargeInteger type, so a little interop magic will be required to extract the values. This Thread contains a sample VB implementation -- and mentions problems similar to your own -- however I'm nowhere near able to verify the usefulness of it right now. Hope this helps.