Chrome_AutocompleteEditView gone in July 2013 from Chrome Browser - google-chrome

From 2011 to the July of 2013 i have been using FindWindowEx to get data from the Chrome Browser about current url. Today 25.09.2013 ,I've noticed that the class Chrome_AutocompleteEditView is gone... My currrent Chrome Version is 29.0.1547.76
Does anyone of you have idea how can i read this url right now ?
Below my code
Thanks
IntPtr handle = getforegroundWindow();IntPtr urlHandle = FindWindowEx(handle, IntPtr.Zero, "Chrome_AutocompleteEditView", null);

My problem have been solved
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Windows.Automation;
namespace ui_automation
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
foreach (Process process in Process.GetProcessesByName("chrome"))
{
string url = GetChromeUrl(process);
if (url == null)
continue;
MessageBox.Show(url);
}
}
public static string GetChromeUrl(Process process)
{
string out_url = null;
if (process == null) {
out_url = null;
} else if (process.MainWindowHandle == IntPtr.Zero) {
out_url = null;
} else {
AutomationElement element = AutomationElement.FromHandle(process.MainWindowHandle);
if (element == null)
return null;
Condition conditions = new AndCondition(
new PropertyCondition(AutomationElement.ProcessIdProperty, process.Id),
new PropertyCondition(AutomationElement.IsControlElementProperty, true),
new PropertyCondition(AutomationElement.IsContentElementProperty, true),
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit)
);
AutomationElement elementx = element.FindFirst(TreeScope.Descendants, conditions);
out_url = ((ValuePattern)elementx.GetCurrentPattern(ValuePattern.Pattern)).Current.Value as string;
}
return out_url;
}
}
}
But this is not what I want exaclty.
This code works but it still getting the URL from chrome to slow... 2 seconds or even 3 sometimes.I noticed that, when I change TreeScope.Descendant to TreeScope.Children this code is started to run lika a flash :) but return null - nothing found.
Any ideas ?

Related

How to get error line number when using IExceptionHandlerPathFeature

I am testing a custom error page with IExceptionHandlerPathFeature (see test code in "CODE SEGMENT" section). In the stack trace, I can see the code line number where the exception was triggered.
I would like to know how to extract the line number from the stack trace without having to parse the large block of text. What methods I could use to get the line number?
TEST ENVIRONMENT
App Type: ASP .NET 6 with Razor pages
IDE: VS 2022
Dev Machine: Windows 11
CODE SEGMENT
public class ErrorHandlerModel : PageModel
{
private string _envName;
public ExceptionDetailsModel ExceptionInfo { get; set; }
public ErrorHandlerModel(IWebHostEnvironment webEnv)
{
_envName = webEnv.EnvironmentName;
}
public IActionResult OnGet()
{
var exceptionFeature = HttpContext.Features.Get<IExceptionHandlerPathFeature>();
if (exceptionFeature != null)
{
string reqId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
ExceptionInfo = new ExceptionDetailsModel(reqId);
if (HttpContext.Response.StatusCode != 0)
ExceptionInfo.HttpStatus = HttpContext.Response.StatusCode.ToString();
ExceptionInfo.ErrorMessage = exceptionFeature.Error.Message;
ExceptionInfo.StackTrace = exceptionFeature.Error.StackTrace.ToString();
ExceptionInfo.Route = exceptionFeature.Path;
}
if (_envName.ToLower().IndexOf("develop") >= 0)
{
TempData["show_error_details"] = "yes";
}
else
{
TempData["show_error_details"] = "no";
}
return Page();
}
}

Send Row from one DataFlow Task to Another

In response to my deleted post
I am suspecting (I could be wrong) a way to transfer limited number of rows from 1 Dataflow Task to another is by using DataReader in the
first one and ScriptTask as Source in the second one.
I need to know how to derive Connection String to connect to that
DataReader if this is all done in one package.
I was looking for a way to send processed rows from one DataFlow Task to another to simplify my design and have better control.
Here is my remarkable solution to this problem!
Code For RecordSet Source with used example
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using System.Data.SqlClient;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Linq;
using System.Data.DataSetExtensions;
[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
private OleDbDataAdapter oleDA = new OleDbDataAdapter();
private DataTable table = new DataTable();
private DataRow[] result;
public override void PreExecute()
{
base.PreExecute();
oleDA.Fill(table, Variables.DatabaseObjects);
var query = from table_address in table.AsEnumerable()
select table_address;
result = query.ToArray<DataRow>();
}
public override void PostExecute()
{
base.PostExecute();
}
public override void CreateNewOutputRows()
{
if (result != null)
{
foreach (DataRow ro in result)
{
Output0Buffer.AddRow();
//----------------------------------------[CHANGE BELOW]-------------------------------------------------
// EXAMPLE:
if (ro["File"] != null && ro["Sequence_ID"] != null && ro["Execution_ID"] != null && ro["Object"] != null)
{
Output0Buffer.File = ro["File"].ToString();
Output0Buffer.SequenceID = Convert.ToInt64(ro["Sequence_ID"]);
Output0Buffer.Object = ro["Object"].ToString();
Output0Buffer.ExecutionID = Convert.ToInt64(ro["Execution_ID"]);
}
//--------------------------------------- [CHANGE ABOVE]------------------------------------------------
}
}
}
}

Asp.net Razor Web Pages Binding Values To Object

I am just wondering is there a way to bind coming request values to an object like we do in MVC in Web Pages.
Web pages has a simpler way to develop smaller websites than mvc. So I want to use razor web pages to develop websites now.
I used MVC for long time and there was automatic model binding based on conventions. And in any Action you can use TryUpdateModel() method to bind request values on complex object for extra cool job.
There is a ModelBinders.Binders.DefaultBinder.BindModel() method I can see in page but it needs two long parameters.
I am wondering is there a simple fast way for bind Request Parameters to C# object :)
Thx for help.
There is no Model Binding in the Web Pages framework. The framework was developed with novice developers primarily in mind and from the comments I saw from members of the project team at the time, they didn't think their target audience would understand or use strongly typed containers for data (business objects).
I needed something like this for a project I worked on, so I built my own very simple model binder. It's rough code that only handles simple types and hasn't been put through any kind of wringer, but it serves my purpose. You can use it for the basis of something more robust:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
public static class RequestBinder
{
/// <summary>
/// Generates entity instances from Request values
/// </summary>
/// <typeparam name="TEntity">The Type to be generated</typeparam>
/// <param name="request"></param>
/// <returns>TEntity</returns>
public static TEntity Bind<TEntity>(this HttpRequestBase request) where TEntity : class, new()
{
var entity = (TEntity)Activator.CreateInstance(typeof(TEntity));
var properties = typeof(TEntity).GetProperties();
foreach (var property in properties)
{
object safeValue;
Type t = Nullable.GetUnderlyingType(property.PropertyType) ?? property.PropertyType;
try
{
if (t == typeof(String))
{
safeValue = string.IsNullOrEmpty(request[property.Name]) ? null : request[property.Name];
}
else if (t.IsEnum)
{
safeValue = (request[property.Name] == null) ? null : Enum.Parse(t, request[property.Name]);
}
else
{
Type tColl = typeof(ICollection<>);
if (t.IsGenericType && tColl.IsAssignableFrom(t.GetGenericTypeDefinition()) || t.GetInterfaces().Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == tColl))
{
continue;
}
safeValue = (request[property.Name] == null) ? null : Convert.ChangeType(request[property.Name], t);
}
property.SetValue(entity, safeValue, null);
}
catch (Exception)
{
}
}
return entity;
}
/// <summary>
/// Populates an existing entity's properties from the Request.Form collection
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="request"></param>
/// <param name="entity"></param>
/// <returns></returns>
public static TEntity Bind<TEntity>(this HttpRequestBase request, TEntity entity) where TEntity : class, new()
{
foreach (string item in request.Form)
{
var property = entity.GetType().GetProperty(item);
if (property != null)
{
object safeValue;
Type t = Nullable.GetUnderlyingType(property.PropertyType) ?? property.PropertyType;
try
{
if (t == typeof(String))
{
safeValue = string.IsNullOrEmpty(request[property.Name]) ? null : request[property.Name];
}
else if (t.IsEnum)
{
safeValue = (request[property.Name] == null) ? null : Enum.Parse(t, request[property.Name]);
}
else
{
Type tColl = typeof(ICollection<>);
if (t.IsGenericType && tColl.IsAssignableFrom(t.GetGenericTypeDefinition()) || t.GetInterfaces().Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == tColl))
{
continue;
}
safeValue = (request[property.Name] == null) ? null : Convert.ChangeType(request[property.Name], t);
}
property.SetValue(entity, safeValue, null);
}
catch (Exception)
{
}
}
}
return entity;
}
}
You would use it like this:
var person = Request.Bind<Person>();
It's unclear at the moment how Web Pages will be incorporated into ASP.NET vNext. The ASP.NET team have talked about eliminating duplication across Web Pages, MVC and Web API, so hopefully that will result in Web Pages including Model Binding.

Storing and getting data in windows phone app and using NavigationService.GoBack()

I have created a Windows phone app based on a quiz game. I want that when the user give the correct answer for some question then a small tick mark will be permanently on in the tab of the question.
I want to store score for every question so that i can display that in a place name as 'your score'. And that score will not be reset even if the app is closed.I have used IsolatedStorageFile to store the data for each page separately. In each page i have provided a back button which will navigate to category page using "NavigationService.GoBack()".
//mainpage
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using logic.Resources;
using System.IO;
using System.IO.IsolatedStorage;
namespace logic
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/logo.xaml", UriKind.Relative));
//Obtain a virtual store for application
IsolatedStorageFile fileStorage = IsolatedStorageFile.GetUserStoreForApplication();
int y = 0;
if (!fileStorage.FileExists("amazon.txt"))
{
//Create a new StreamWriter, to write the file to the specified location.
StreamWriter fileWriter = new StreamWriter(new IsolatedStorageFileStream("amazon.txt", FileMode.OpenOrCreate, fileStorage));
//Write the contents of our TextBox to the file.
fileWriter.WriteLine(y);
//Close the StreamWriter.
fileWriter.Close();
}
}
}
}
//category page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.IO;
using System.IO.IsolatedStorage;
namespace logic
{
public partial class logo : PhoneApplicationPage
{
public logo()
{
InitializeComponent();
int x = 0;
//Obtain a virtual store for application
IsolatedStorageFile fileStorage = IsolatedStorageFile.GetUserStoreForApplication();
//Create a new StreamReader
StreamReader fileReader = null;
if (fileStorage.FileExists("amazon.txt"))
{
//Read the file from the specified location.
fileReader = new StreamReader(new IsolatedStorageFileStream("amazon.txt", FileMode.Open, fileStorage));
//Read the contents of the file (the only line we created).
string textFile = fileReader.ReadLine();
x = Convert.ToInt32(textFile);
//Write the contents of the file to the TextBlock on the page.
fileReader.Close();
if (x == 1)
{
ama.Visibility = System.Windows.Visibility.Visible;
}
}
}
private void Image_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
NavigationService.Navigate(new Uri("/amazon.xaml", UriKind.Relative));
}
}}
//question page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.IO;
using System.IO.IsolatedStorage;
namespace logic
{
public partial class amazon : PhoneApplicationPage
{
public amazon()
{
InitializeComponent();
}
//check the answer is correct or not
int count = 0;
int x;
private void b1_Click(object sender, RoutedEventArgs e)
{
if (tb1.Text.Length == 0 || tb2.Text.Length == 0 || tb3.Text.Length == 0 || tb4.Text.Length == 0 || tb5.Text.Length == 0 || tb6.Text.Length == 0)
{
}
else
{
Char s1, s2, s3, s4, s5, s6;
s1 = Char.ToUpper(tb1.Text[0]);
s2 = Char.ToUpper(tb2.Text[0]);
s3 = Char.ToUpper(tb3.Text[0]);
s4 = Char.ToUpper(tb4.Text[0]);
s5 = Char.ToUpper(tb5.Text[0]);
s6 = Char.ToUpper(tb6.Text[0]);
if (s1 == 'A' && s2 == 'M' && s3 == 'A' && s4 == 'Z' && s5 == 'O' && s6 == 'N')
{
//Obtain a virtual store for application
IsolatedStorageFile fileStorage = IsolatedStorageFile.GetUserStoreForApplication();
//Create a new StreamReader
StreamReader fileReader = null;
//Read the file from the specified location.
fileReader = new StreamReader(new IsolatedStorageFileStream("amazon.txt", FileMode.Open, fileStorage));
//Read the contents of the file (the only line we created).
string textFile = fileReader.ReadLine();
x = Convert.ToInt32(textFile);
//Write the contents of the file to the TextBlock on the page.
fileReader.Close();
if (x == 0)
{
fileStorage.DeleteFile("amazon.txt");
//Create a new StreamWriter, to write the file to the specified location.
StreamWriter fileWriter = new StreamWriter(new IsolatedStorageFileStream("amazon.txt", FileMode.OpenOrCreate, fileStorage));
fileWriter.WriteLine("1");
//Close the StreamWriter.
fileWriter.Close();
}
ans.Text = "Correct!!!";
}
else
{
ans.Text = "\n\nINCORRECT";
}
}
}
//reset the value
private void reset_Click(object sender, RoutedEventArgs e)
{
tb1.Text = "";
tb2.Text = ""; tb3.Text = ""; tb4.Text = ""; tb5.Text = ""; tb6.Text = "";
}
private void Image_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
NavigationService.GoBack();
}
}
}
The problem is that when ever i gave the correct answer and press the back button which navigate to logo page the trick(named as "ama" in category code) do not show. But when again i navigate to mainpage then come back to category page the trick is shown. I want that when ever i give the correct answer and navigate back to category page using the back button provided in the app or back button of mobile the trick should be shown at that time only.
According to your code.
Your logic is in constructor of that class. Which is called once you navigate to it from main page and is not called again when you navigate back from question page.
So, you are logically not executing any code when it navigates back, hence displaying the same view as it was.
To make it update, write your logic code in Page_Loaded event.

SSIS/C#: Script Task, C# script to look at directory and store the name of 1 file in a variable

Basically I've written a C# script for a Script task in SSIS that looks in a User::Directory for 1 csv, if & only if there is one file, it stores that in the instance variable which then maps to the package variables of SSIS.
When I exicute, it gives me the red filled in box of the Script task. I think it's related to how I'm looking at the directory, but I'm not sure.
Please help!
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.IO;
namespace ST_e8b4bbbddb4b4806b79f30644240db19.csproj
{
[System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
private String fileName = "";
private String RootDirictory;
private String FilePath;
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
public ScriptMain()
{
RootDirictory = Dts.Variables["RootDir"].Value.ToString();
FilePath = RootDirictory + "\\" + "SourceData" + "\\";
}
public void setFileName()
{
DirectoryInfo YDGetDir = new DirectoryInfo(FilePath);
FileInfo[] numberOfFiles = YDGetDir.GetFiles(".csv");
if (numberOfFiles.Length < 2)
{
fileName = numberOfFiles[0].ToString();
}
int fileNameLen = fileName.Length;
String temp = fileName.Substring(0, fileNameLen - 5);
fileName = temp;
}
public void mapStateToPackage()
{
if((fileName!=null)||(fileName!=""))
{
Dts.Variables["ExDFileName"].Value = fileName;
}
}
public void Main()
{
setFileName();
mapStateToPackage();
Dts.TaskResult = (int)ScriptResults.Success;
}
}
}
This could simply be done using Foreach loop container as explained in this Stack Overflow question, which was asked by you. :-)
Anyway, to answer your question with respect to Script Task code that you have provided. Below mentioned reasons could be cause of the issues:
You are looking for .csv. This won't return any results because you are looking for a file with no name but extension .csv. The criteria should be *.csv
If you are looking for exactly one file, then the condition if (numberOfFiles.Length < 2) should be changed to if (numberOfFiles.Length == 1)
The section of code after the if section which extracts the file name should be within the above mentioned if condition and not out side of it. This has to be done to prevent applying substring functionality on an empty string.
Modified code can be found under the Script Task Code section.
Sorry, I took the liberty to simplify the code a little. I am not suggesting this is the best way to do this functionality but this is merely an answer to the question.
Hope that helps.
Script Task Code:
C# code that can be used only in SSIS 2008 and above.
/*
Microsoft SQL Server Integration Services Script Task
Write scripts using Microsoft Visual C# 2008.
The ScriptMain is the entry point class of the script.
*/
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.IO;
namespace ST_3effcc4e812041c7a0fea69251bedc25.csproj
{
[System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
Variables varCollection = null;
String fileName = string.Empty;
String fileNameNoExtension = string.Empty;
String rootDirectory = string.Empty;
String filePath = string.Empty;
#region VSTA generated code
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion
public void Main()
{
Dts.VariableDispenser.LockForRead("User::RootDir");
Dts.VariableDispenser.LockForWrite("User::ExDFileName");
Dts.VariableDispenser.GetVariables(ref varCollection);
rootDirectory = varCollection["User::RootDir"].Value.ToString();
filePath = rootDirectory + #"\SourceData\";
DirectoryInfo YDGetDir = new DirectoryInfo(filePath);
FileInfo[] numberOfFiles = YDGetDir.GetFiles("*.csv");
if (numberOfFiles.Length == 1)
{
fileName = numberOfFiles[0].ToString();
fileNameNoExtension = fileName.Substring(0, fileName.LastIndexOf("."));
}
if (!String.IsNullOrEmpty(fileNameNoExtension))
{
varCollection["User::ExDFileName"].Value = fileNameNoExtension;
}
Dts.TaskResult = (int)ScriptResults.Success;
}
}
}