Dynamically added Raddocks Optimization? - telerik

We have a optimization problem regarding rad dock controls. The requirement of project is such that we are creating dynamic raddocks on the fly and adding it to a raddockzone, then we are saving the raddock "type" etc in a mssql db. We also have a collector window/raddockzone in which we have build a functionality where we can drag a dock and save it in collector. As with the first raddockzone we are adding the dock in collector on the fly. Now while adding a dock or moving it to another raddockzones it takes sometime. Our client is comparing it with the example of the demo link : http://demos.telerik.com/aspnet-ajax/dock/examples/content/defaultcs.aspx
Following is our code snippet to add dock on the fly:
private RadDockNew CreateRadDock()
{
//string[] allowedZones = { "RDZCollector", "RadDockZone2" };
int width = Convert.ToInt32((hdnWidth.Value == "") ? "520" : hdnWidth.Value);
RadDockNew dock = new RadDockNew();
dock.DockMode = DockMode.Docked;
dock.UniqueName = Guid.NewGuid().ToString().Replace("-", "a");
dock.ID = string.Format("RadDock{0}", dock.UniqueName);
//dock.Title = dock.UniqueName.Substring(dock.UniqueName.Length - 3);
dock.Width = Unit.Pixel(width);
dock.CssClass = "RadDockZoneMain";
//dock.AllowedZones = allowedZones;
dock.Style.Add("min-height", "290px");
dock.OnClientDockPositionChanged = "DropInCollector";
//dock.EnableViewState = false;
DockCommand cmd = new DockCommand();
cmd.Name = "Setting";
cmd.Text = "Setting";
cmd.OnClientCommand = "showSettings";
dock.Commands.Add(cmd);
DockCommand dc = new DockCommand();
dc.Text = "Trash";
dc.Name = "Trash";
dc.OnClientCommand = "CloseDock";
dc.CssClass = "rdClose";
dc.AutoPostBack = true;
dock.Commands.Add(dc);
DockToggleCommand cmd2 = new DockToggleCommand();
cmd2.CssClass = "rdCollapse";
cmd2.AlternateCssClass = "rdexpand";
cmd2.OnClientCommand = "ChangeImage";
//DockCommand collapse = new DockCommand();
//collapse.Text = "Collapse/Expand";
//collapse.Name = "Collapse/Expand";
//collapse.OnClientCommand = "CollapseDock";
//collapse.CssClass = "rdCollapse";
dock.Commands.Add(cmd2);
return dock;
}
Please tell if there is any way to optimize / make it faster.
Thanks.

I examined the attached code sample and I think that it is correct. My suggestions are to check if the problem persists if you use other storage medium, instead of a database or if there are client script errors on the page, containing the RadDocks.
As the setup of your project seems to be similar to the one, implemented in the My Portal demo, I would recommend using the example in the Code Library article Saving State of Dynamically Created RadDocks in DataBase using Hidden UpdatePanel as a reference.

Related

Xamarin.Mac - How to highlight the selected text in a PDF file

I'm actualy trying to add a markup annotation in a PDF with PDFKit, in Xamarin.Mac, so for OS X.
So my goal is to highlight permanently, as an annotation, a selected text in the PDF File, and save it to retrieve it when I open the file later.
The thing is, I can get the current selection and store it into a variable :
PdfSelection currentSelection = m_aPdfView.CurrentSelection;
And I can create an object PdfAnnotationMarkup :
//Create the markup annotation
var annot = new PdfAnnotationMarkup();
//add characteristics to the annotation
annot.Contents = currentSelectionText;
annot.MarkupType = PdfMarkupType.Highlight;
annot.Color = NSColor.Yellow;
annot.ShouldDisplay = true;
But I can't find, even though I checked a lot of different documentations, how to link the two of them.
There is no method giving the location of the currentSelection, or any hint to go in that direction.
Would anyone know of a way to make this possible ?
PS: I found that the subclasses of PDFAnnotation are deprecated on the Apple Developer Website , but not on the Xamarin Website, is there any way of knowing if both of them are related of entirely different ?
Thanks in advance for your help
EDIT : Here is the code I got and works perfectly. Thanks to svn's answers
//Get the current selection on the PDF file opened in the PdfView
PdfSelection currentSelection = m_aPdfView.CurrentSelection;
//Check if there is an actual selection right now
if (currentSelection != null)
{
currentSelection.GetBoundsForPage(currentSelection.Pages[0]);
//Create the markup annotation
var annot = new PdfAnnotationMarkup();
//add characteristics to the annotation
annot.Contents = "Test";
annot.MarkupType = PdfMarkupType.Highlight;
annot.Color = NSColor.Yellow;
annot.ShouldDisplay = true;
annot.ShouldPrint = true;
annot.UserName = "MyName";
//getting the current page
PdfPage currentPage = currentSelection.Pages[0];
//getting the bounds from the current selection and adding it to the annotation
var locationRect = currentSelection.GetBoundsForPage(currentPage);
getValuLabel.StringValue = locationRect.ToString();
//converting the CGRect object into CGPoints
CoreGraphics.CGPoint upperLeft = locationRect.Location;
CoreGraphics.CGPoint lowerLeft = new CoreGraphics.CGPoint(locationRect.X, (locationRect.Y + locationRect.Height));
CoreGraphics.CGPoint upperRight = new CoreGraphics.CGPoint((locationRect.X + locationRect.Width), locationRect.Y);
CoreGraphics.CGPoint lowerRight = new CoreGraphics.CGPoint((locationRect.X + locationRect.Width), (locationRect.Y + locationRect.Height));
//adding the CGPoints to a NSMutableArray
NSMutableArray pointsArray = new NSMutableArray();
pointsArray.Add(NSValue.FromCGPoint(lowerLeft));
pointsArray.Add(NSValue.FromCGPoint(lowerRight));
pointsArray.Add(NSValue.FromCGPoint(upperLeft));
pointsArray.Add(NSValue.FromCGPoint(upperRight));
//setting the quadrilateralPoints
annot.WeakQuadrilateralPoints = pointsArray;
//add the annotation to the PDF file current page
currentPage.AddAnnotation(annot);
//Tell the PdfView to update the display
m_aPdfView.NeedsDisplay = true;
A selection can span multiple pages. To get the location of a selection use:
var locationRect = currentSelection.GetBoundsForPage(currentSelection.Pages[0]);
You should be able to instantiate PdfAnnotationMarkup with bounds but the xamarin implementation does not expose that constuctor. But is does expose a bounds property
var annot = new PdfAnnotationMarkup();
annot.bounds = locationRect;
I have not tested this.

How to automate Package Manager Console in Visual Studio 2013

My specific problem is how can I automate "add-migration" in a build process for the Entity Framework. In researching this, it seems the mostly likely approach is something along the lines of automating these steps
Open a solution in Visual Studio 2013
Execute "Add-Migration blahblah" in the Package Manager Console (most likely via an add-in vsextention)
Close the solution
This initial approach is based on my own research and this question, the powershell script ultimately behind Add-Migration requires quite a bit of set-up to run. Visual Studio performs that setup automatically when creating the Package Manager Console and making the DTE object available. I would prefer not to attempt to duplicate that setup outside of Visual Studio.
One possible path to a solution is this unanswered stack overflow question
In researching the NuGet API, it does not appear to have a "send this text and it will be run like it was typed in the console". I am not clear on the lines between Visual Studio vs NuGet so I am not sure this is something that would be there.
I am able to find the "Pacakage Manager Console" ironically enough via "$dte.Windows" command in the Package Manager Console but in a VS 2013 window, that collection gives me objects which are "Microsoft.VisualStudio.Platform.WindowManagement.DTE.WindowBase". If there is a way stuff text into it, I think I need to get it to be a NuGetConsole.Implementation.PowerConsoleToolWindow" through reviewing the source code I am not clear how the text would stuffed but I am not at all familiar with what I am seeing.
Worst case, I will fall back to trying to stuff keys to it along the lines of this question but would prefer not to since that will substantially complicate the automation surrounding the build process.
All of that being said,
Is it possible to stream commands via code to the Package Manager Console in Visual Studio which is fully initialized and able to support an Entity Framework "add-migration" command?
Thanks for any suggestions, advice, help, non-abuse in advance,
John
The approach that worked for me was to trace into the entity framework code starting in with the AddMigrationCommand.cs in the EntityFramework.Powershell project and find the hooks into the EntityFramework project and then make those hooks work so there is no Powershell dependency.
You can get something like...
public static void RunIt(EnvDTE.Project project, Type dbContext, Assembly migrationAssembly, string migrationDirectory,
string migrationsNamespace, string contextKey, string migrationName)
{
DbMigrationsConfiguration migrationsConfiguration = new DbMigrationsConfiguration();
migrationsConfiguration.AutomaticMigrationDataLossAllowed = false;
migrationsConfiguration.AutomaticMigrationsEnabled = false;
migrationsConfiguration.CodeGenerator = new CSharpMigrationCodeGenerator(); //same as default
migrationsConfiguration.ContextType = dbContext; //data
migrationsConfiguration.ContextKey = contextKey;
migrationsConfiguration.MigrationsAssembly = migrationAssembly;
migrationsConfiguration.MigrationsDirectory = migrationDirectory;
migrationsConfiguration.MigrationsNamespace = migrationsNamespace;
System.Data.Entity.Infrastructure.DbConnectionInfo dbi = new System.Data.Entity.Infrastructure.DbConnectionInfo("DataContext");
migrationsConfiguration.TargetDatabase = dbi;
MigrationScaffolder ms = new MigrationScaffolder(migrationsConfiguration);
ScaffoldedMigration sf = ms.Scaffold(migrationName, false);
}
You can use this question to get to the dte object and from there to find the project object to pass into the call.
This is an update to John's answer whom I have to thank for the "hard part", but here is a complete example which creates a migration and adds that migration to the supplied project (project must be built before) the same way as Add-Migration InitialBase -IgnoreChanges would:
public void ScaffoldedMigration(EnvDTE.Project project)
{
var migrationsNamespace = project.Properties.Cast<Property>()
.First(p => p.Name == "RootNamespace").Value.ToString() + ".Migrations";
var assemblyName = project.Properties.Cast<Property>()
.First(p => p.Name == "AssemblyName").Value.ToString();
var rootPath = Path.GetDirectoryName(project.FullName);
var assemblyPath = Path.Combine(rootPath, "bin", assemblyName + ".dll");
var migrationAssembly = Assembly.Load(File.ReadAllBytes(assemblyPath));
Type dbContext = null;
foreach(var type in migrationAssembly.GetTypes())
{
if(type.IsSubclassOf(typeof(DbContext)))
{
dbContext = type;
break;
}
}
var migrationsConfiguration = new DbMigrationsConfiguration()
{
AutomaticMigrationDataLossAllowed = false,
AutomaticMigrationsEnabled = false,
CodeGenerator = new CSharpMigrationCodeGenerator(),
ContextType = dbContext,
ContextKey = migrationsNamespace + ".Configuration",
MigrationsAssembly = migrationAssembly,
MigrationsDirectory = "Migrations",
MigrationsNamespace = migrationsNamespace
};
var dbi = new System.Data.Entity.Infrastructure
.DbConnectionInfo("ConnectionString", "System.Data.SqlClient");
migrationsConfiguration.TargetDatabase = dbi;
var scaffolder = new MigrationScaffolder(migrationsConfiguration);
ScaffoldedMigration migration = scaffolder.Scaffold("InitialBase", true);
var migrationFile = Path.Combine(rootPath, migration.Directory,
migration.MigrationId + ".cs");
File.WriteAllText(migrationFile, migration.UserCode);
var migrationItem = project.ProjectItems.AddFromFile(migrationFile);
var designerFile = Path.Combine(rootPath, migration.Directory,
migration.MigrationId + ".Designer.cs");
File.WriteAllText(designerFile, migration.DesignerCode);
var designerItem = project.ProjectItems.AddFromFile(migrationFile);
foreach(Property prop in designerItem.Properties)
{
if (prop.Name == "DependentUpon")
prop.Value = Path.GetFileName(migrationFile);
}
var resxFile = Path.Combine(rootPath, migration.Directory,
migration.MigrationId + ".resx");
using (ResXResourceWriter resx = new ResXResourceWriter(resxFile))
{
foreach (var kvp in migration.Resources)
resx.AddResource(kvp.Key, kvp.Value);
}
var resxItem = project.ProjectItems.AddFromFile(resxFile);
foreach (Property prop in resxItem.Properties)
{
if (prop.Name == "DependentUpon")
prop.Value = Path.GetFileName(migrationFile);
}
}
I execute this in my project template's IWizard implementation where I run a migration with IgnoreChanges, because of shared entites with the base project. Change scaffolder.Scaffold("InitialBase", true) to scaffolder.Scaffold("InitialBase", false) if you want to include the changes.

Windows Phone, set image source on async callback doesn't work?

I am getting images from Bing to display in my app. I followed Bing's instructions, I successfully retrieve the image's URLs, but for some reason, the emulator won't display them! Here's what I have
var bingContainer = new Bing.BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/Search/"));
var accountKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
bingContainer.Credentials = new NetworkCredential(accountKey, accountKey);
var imageQuery = bingContainer.Image("porsche", null, null, null, null, null, "Size:Medium");
imageQuery.BeginExecute(new AsyncCallback(this.ImageResultLoadedCallback), imageQuery);
Then, I get my images and try to set them here:
var imageQuery = (DataServiceQuery<Bing.ImageResult>)ar.AsyncState;
var enumerableImages = imageQuery.EndExecute(ar);
var imagesList = enumerableImages.ToList();
List<String> imList = new List<String>();
while (imList.Count != 3)
{
Bing.ImageResult tr = imagesList.First<Bing.ImageResult>();
if (tr.ContentType == "image/jpeg")
{
imList.Add(tr.MediaUrl);
}
imagesList.RemoveAt(0);
}
image1.Source = new BitmapImage(new Uri(#imList[0]));
image2.Source = new BitmapImage(new Uri(#imList[1]));
image3.Source = new BitmapImage(new Uri(#imList[2]));
When I debug, the process seems to just stop on those three last lines where I set the source.
Alright, after two days of frustration, I found out you cannot access the UI thread from an async callback. VS wasn't giving any errors, yet the images were not showing. An async callback runs alongside the main UI thread, so it can't access or change the elements in the UI. The easy workaround just involves wrapping the lines of code that access the UI like this:
Dispatcher.BeginInvoke(() =>
{
image1.Source = new BitmapImage(new Uri(#imList[0]));
image2.Source = new BitmapImage(new Uri(#imList[1]));
image3.Source = new BitmapImage(new Uri(#imList[2]));
});
It works now!
Are you sure MediaUrl is returning proper urls to images? What if you would use some hardcoded urls to images in the imList list, would the images load properly in image1, image2 and image3? The point i am getting to is that perhaps the quality of the data is incorrect. That is, though your query executes well, MediaURL is not containing a properly formatted URL.
Also, what is the exception you get when the debugger stops?

Unable to set firefox bookmark description for in Add-On Kit API

I found the nsINavBookmarksService, however since Firefox 3, it does not seem to have any API methods for getting/setting the Bookmark description. (API doc)
I've seen other Add-Ons modify the description as a method of synchronized data storage (which is exactly what I'm trying to do). I'm guessing perhaps the description is a non-gecko standard, and that's why it is not directly supported, but then there must be a completely different interface for manipulating Bookmarks that I haven't discovered.
Can anyone help with this newbie problem?
Starting with Firefox 3 the bookmarks have been merged into the Places database containing all of your browsing history. So to get the bookmarks you do a history query, like this (first line is specific to the Add-on SDK which you appear to be using):
var {Cc, Ci} = require("chrome");
var historyService = Cc["#mozilla.org/browser/nav-history-service;1"]
.getService(Ci.nsINavHistoryService);
var options = historyService.getNewQueryOptions();
var query = historyService.getNewQuery();
query.onlyBookmarked = true;
var result = historyService.executeQuery(query, options);
result.root.containerOpen = true;
for (var i = 0; i < result.root.childCount; i++)
{
var node = result.root.getChild(i);
console.log(node.title);
}
That's mostly identical to the code example here. Your problem is of course that nsINavHistoryResultNode has no way of storing data like a description. You can set annotations however, see Using the Places annotation service. So if you already have a node variable for your bookmark:
var annotationName = "my.extension.example.com/bookmarkDescription";
var ioService = Cc["#mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService);
var uri = ioService.newURI(node.uri, null, null);
var annotationService = Cc["#mozilla.org/browser/annotation-service;1"]
.getService(Ci.nsIAnnotationService);
annotationService.setPageAnnotation(uri, annotationName,
"Some description", 0, Ci.nsIAnnotationService.EXPIRE_NEVER);
For reference: nsIAnnotationService.setPageAnnotation()

No valid report source is available. in asp.net sap crystal report

I am using Sap Crystal Report in asp.net 2010
It will shows the error no valid report source id available, when i refreshing the report or moving to next page at run time using report viewer tools
and this is my coding,
Dim crdoc5 As New ReportDocument()
Dim crtablogoninfo5 As New TableLogOnInfo
Dim crtabs5 As Tables
If Not IsPostBack Then
crdoc5.Load(Server.MapPath("CrStaffrecruit.rpt"))
Session.Add("CrStaffrecruit", crdoc5)
CrystalReportViewer5.ReportSource = crdoc5
Else
CrystalReportViewer5.ReportSource = Session("CrStaffrecruit")
End If
crdoc5.Load(Server.MapPath("CrStaffrecruit.rpt"))
Dim crconninfo5 As New ConnectionInfo()
rconninfo5.ServerName = "servername"
crconninfo5.DatabaseName = "databasename"
crconninfo5.UserID = "sa"
crconninfo5.Password = ""
crtabs5 = crdoc5.Database.Tables()
For Each crtab5 As CrystalDecisions.CrystalReports.Engine.Table In crtabs5
crtablogoninfo5 = crtab5.LogOnInfo
crtablogoninfo5.ConnectionInfo = crconninfo5
crtab5.ApplyLogOnInfo(crtablogoninfo5)
Next
CrystalReportViewer5.ReportSource = crdoc5
CrystalReportViewer5.RefreshReport()
If any one know pls help me...
Thanks in advance
For this please go through the following link
http://forums.sdn.sap.com/thread.jspa?messageID=10951477&#10951477
Although the following code is in C#, it shouldn't be too difficult to translate it to VB and it should solve your issue:
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
//whatever you do when the page is loaded for the first time
//this could even be bindReport();
}
else
{
bindReport();
}
}
public void bindReport()
{
ReportDocument rptDoc = new ReportDocument();
dsSample ds = new dsSample(); // .xsd file name
DataTable dt = new DataTable();
// Just set the name of data table
dt.TableName = "Crystal Report Example";
dt = getMostDialledNumbers(); //This function populates the DataTable
ds.Tables[0].Merge(dt, true, MissingSchemaAction.Ignore);
// Your .rpt file path will be below
rptDoc.Load(Server.MapPath("yourReportFilePath.rpt"));
//set dataset to the report viewer.
rptDoc.SetDataSource(ds);
CrystalReportViewer1.ReportSource = rptDoc;
CrystalReportViewer1.RefreshReport();
//in case you have an UpdatePanel in your page, it needs to be updated
UpdatePanel1.Update();
}
I was experiencing the same problem. In what event are you executing the code you posted? I ask because after much debugging, I discovered that you need to place the code in Page_Load (as opposed to PreRender like I was doing previously...)
Hope this helps.
I have got this problem several times, and the solution is to save the Report Document variable in a session then in the Page_load put the below code:
if (IsPostBack)
{
if (Session["reportDocument"] != null)
{
ReportDocument cr = new ReportDocument();
cr = (ReportDocument)Session["reportDocument"];
CrystalReportViewer1.ReportSource = cr;
CrystalReportViewer1.DataBind();
}
}
NB:
Don't forget to fill the (Session["reportDocument"]) with the Display button.
Go through following link. I resolved same issue with that solution.
http://www.aspsnippets.com/Articles/ASPNet-Crystal-Reports-13-Visual-Studio-2010-CrystalReportViewer-Search-Button-Issue---No-valid-report-source-is-available.aspx

Resources