jueves, 30 de noviembre de 2017

Exportar de dwg a shp Autocad Map 2015

Exportar de dwg a shp Autocad Map 2015



En este video muestran como :

Exportar de dwg a shp en Autocad Map 2015 1. Exportar poligonos 2. Exportar textos como puntos con su atributo correspondiente (buscar el campo string o textstring,tambien puedes seleccionar ambos si no estas seguro de donde se encuentra el atributo) Verificar en que se hayan hecho correctamente los procedimientos abriendo los shapes, en este caso se utilizo ArcMap

Convertir Dwg a Shape en ArcGis

Convertir Dwg a Shape de autocad


- http://www.aguaysig.com
En este vídeo muestran como convertir archivos de formato dwg de autocad a formato shape de ArcGis.

miércoles, 22 de noviembre de 2017

Report viewer control authentication

Report viewer control authentication – Forms Authentication


If the reporting services configured to use forms authentication and you need to show the reports in the custom developed applications then the need of processing authentication the report viewer control through the code. 
Report viewer control authentication using windows authentication is described in the part 1 here. Now, we will discuss the authenticating forms authentication through C# code.
If we are are developing windows application and want to use report viewer control, then we need to implement the below logic to authenticate.

reportViewer1.ServerReport.ReportServerCredentials.SetFormsCredentials(null, "userName", "password", "");
this.reportViewer1.RefreshReport();
Where as in forms authentication simply assigning the credentials not enough. The reasons behind are, security, code efficiency, performance, response time etc everything come into the picture. So, we need to write code which supports everything. 

What are the major tasks?
  • Report viewer control excepts the credential of type IReportServerCredentials. So, we need to create an object which inherits from this interface and pass this to the report viewer control to authenticate.
  • Handling cookie. Based on the login and request is successful we will write the cookie to browser and keep that in browser for further requests processing. The advantage is if cookie is available then won’t make any request to report server for authenticating.
  • To create the cookie related information we actually need of hijack the request and response and get the cookie information and save it to browser. So, how to catch the request and response which made to report server? We will discuss this later in this article.
  • To actually communicate to the report server, we need to make the communication with it. The best way to do that is using web services. Everyone knows that reports in SSRS gets with two sites. One is report manager means report web application [/reports] and the report server means a report web service[/reportserver]. So, we will use the web service, write a proxy and implement the existing functions in it.

I think, it is little bit complex to understand the above tasks. But actually they are very simple to implement.


Code needed: We need two classes to get what we need. These are custom classes and add them in single file named ReportServerCredentials.cs somewhere in the project. 
  • Classes needed - ReportServerCredentials and ReportingService.
public class ReportServerCredentials : IReportServerCredentials
{
private Cookie m_authCookie;
public ReportServerCredentials(Cookie authCookie)
{
m_authCookie = authCookie;
}
public WindowsIdentity ImpersonationUser
{
get
{
return null;  // Use default identity.
}
}
public ICredentials NetworkCredentials
{
get
{
return null;  // Not using NetworkCredentials to authenticate.
}
}
public bool GetFormsCredentials(out Cookie authCookie,
out string user, out string password, out string authority)
{
authCookie = null;
user = ConfigurationManager.AppSettings["ReportServerUserName"];
password = ConfigurationManager.AppSettings["ReportServerPassword"];
authority = "";
return true;  // Use forms credentials to authenticate.
}
}
public class MyReportingService : rsExecutionReference.ReportExecutionService
{
private Cookie m_authCookie;
public Cookie AuthCookie
{
get
{
return m_authCookie;
}
}
protected override WebRequest GetWebRequest(Uri uri)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
request.CookieContainer = new CookieContainer();
if (m_authCookie != null)
request.CookieContainer.Add(m_authCookie);
return request;
}
protected override WebResponse GetWebResponse(WebRequest request)
{
WebResponse response = base.GetWebResponse(request);
string cookieName = response.Headers["RSAuthenticationHeader"];
if (cookieName != null)
{
HttpWebResponse webResponse = (HttpWebResponse)response;
m_authCookie = webResponse.Cookies[cookieName];
}
return response;
}
}

A small explanation:
ReportServerCredentials class is the class which is inheriting from the IReportServerCredentialsinterface. 
  • If we are using the impersonation then the first property will be used.
  • If we are passing the custom network credentials then the second property will be used.
  • If we are using forms authentication then the method GetFormsCredentials() will be used.
ReportingService is the class which is inheriting from the ReportExecutionService web service. The question in your mind now is what is the "rsExecutionReference". This is the web reference to the report server web service. To get this, right click on the web application/web site and select the option "Add web reference". Now, in the input box, enter the report server url ending with "ReportExecution2005.asmx". For example, if your report server is at http://localhost/reportserverthen the web service location will be http://localhost/reportserver/ReportExecution2005.asmx. Add the web reference to project or site. Now, we have the web service proxy created in the solution. So, in my code rsExecutionReference is nothing but the web service proxy for the report server web service. 

The web service has two methods already implemented GetWebRequest() and GetWebResponse(). So, we are overriding them in our code to catch the cookie ticket information which is returned by the report server. If you observe the GetWebResponse() code, we are actually checking for the header information from the response and in the response we are catching the cookie we need. If cookie is null means the request authentication failed and means invalid credentials passed. 

I think, till now what I have mentioned is clear for you and we are done with contacting or communicating with the web service. Now, where we are calling the web service or in other words where the authentication request started? It's not yet. Check the below code and notes for it.

I have a Utility class in my application where I place all the util related code in it. For example purpose, I am assuming this method you have placed in Utility class  [If no Utility class in your application then create one and place this below method in it].

public static HttpCookie AuthenticateReportServerAccess()
{
MyReportingService svc = new MyReportingService();
svc.Url = ConfigurationManager.AppSettings["ReportServerWebSeriveUrl"];
HttpCookie hcookie = null;
try
{
svc.LogonUser(ConfigurationManager.AppSettings["ReportServerUserName"],
ConfigurationManager.AppSettings["ReportServerPassword"], null);
Cookie myAuthCookie = svc.AuthCookie;
if (myAuthCookie == null)
{
//Message.Text = "Logon failed";
}
else
{
hcookie = new HttpCookie(myAuthCookie.Name, myAuthCookie.Value);
HttpContext.Current.Response.Cookies.Add(hcookie);
}
}
catch (Exception ex)
{
//Message.Text = "Logon failed: " + ex.Message;
}
return hcookie;
}
What this method is doing? A little explanation is here. We need to make or send a request to report server for authenticating the current request to load a report. So, I am using this method for that. I have a proxy class as described above and based on that I have created my own custom class named ReportingService. So, I am using that to make the call by using the built in function exists in the web service named LogonUser(). 

Which is actually takes three parameters named username, password and authority. Authority is optional, the specific authority to use when authenticating a user. For example, a Windows domain, some name to make distinct the call for that user. Pass a value of null to omit this argument. This will make call to the report server. Because of we override the request and response methods in proxy, it will come to those method and executes all the code in them. So, in the method AuthenticateReportServerAccess() we are making request and getting the cookie. If wrong credentials passed then it means cookie is null. So, you can write your own logic there like throw exception or show some message, If you have any login page implemented for reporting then redirecting the user there etc… If cookie exist then Add that cookie to the response object. 

Now, we are done with making a call and processing it and loading cookie. Now what? What we left with… See below.

In the page where we have placed the report viewer control, there add the below code. The below code you can write may be in onclick event of something or when page loads depends on your requirement.

HttpCookie cookie = Request.Cookies["sqlAuthCookie"];
if (cookie == null)
{
cookie = Util.AuthenticateReportServerAccess();
}
if(cookie != null)            {
//Add logic to pass parameters if needed.

reportViewer1.ServerReport.ReportServerUrl = new Uri("reportserverurl");
reportViewer1.ProcessingMode = ProcessingMode.Remote;
reportViewer1.ServerReport.ReportPath = "reportPath";
Cookie authCookie = new Cookie(cookie.Name, cookie.Value);
authCookie.Domain = Request.Url.Host;
reportViewer1.ServerReport.ReportServerCredentials =
new ReportServerCredentials(authCookie);           
//If any parameters then reportViewer1.ServerReport.SetParameters(reportParams);
}

What is happening in the code? We are checking whether the cookie already exist means user is already authenticated and if it null then we are sending request to report server and loading the cookie to browser. If cookie exists then it will go to second if condition and loads the report in the report viewer control by passing the cookie information to report server.

OHHH… What else? we are done with complete coding. We are left with testing the code. 
Note: If you observe the code, there are some places we are getting the appsettings keys from the web.config. 
Hope you are well understood and not with many questions in mind at this stage. Please feel free to ask me if you have any questions. Love to hear comments.

miércoles, 8 de noviembre de 2017

Using a Parameter in a SQL Server Reporting Services 2016 Mobile Report

SQL Server Reporting Services 2016 Mobile Report

By:  

Problem
We are using SQL Server Reporting Services (SSRS) 2016. I have created a mobile report using Mobile Report Publisher. The dashboard works fine, but loads kind of slow. I'd like to pre-filter my dataset using a parameter. How can I achieve this?
Solution
Reporting Services has a ton of new features and mobile reports is probably one of the most important ones. Microsoft acquired the company DataZen, which specialized in dashboards and KPIs for mobile devices. In the SQL Server 2016 release, this technology is incorporated into the Reporting Services product. An introduction to mobile reports can be found in the tip SQL Server 2016 Reporting Services Mobile Report and an introduction to KPIs in the tip How to create a basic KPI in Reporting Services 2016. The tool used to create mobile reports is called Mobile Report Publisher and can be downloaded here. Luckily this editor has parameter support built-in.

Test Set-up

Let's use a fairly basic query that retrieves Order Quantities for each month from the Wide World Importers data warehouse.
SELECT
     [Month] = DATENAME(MONTH,[Order Date Key])
    ,[MonthOrder] = DATEPART(MONTH,[Order Date Key])
    ,[Quantity] = SUM([Quantity])
FROM [Fact].[Order]
--WHERE YEAR([Order Date Key]) = @Year
GROUP BY DATENAME(MONTH,[Order Date Key]),DATEPART(MONTH,[Order Date Key])
ORDER BY [MonthOrder];
The query will return 12 rows, but each month will contain data for all of the years present in the data. For example, January will contain the aggregated order quantities of January 2013, January 2014, January 2015 and January 2016. In the final query we will use a parameter on year, so we will return data for one single year. Keep in mind that if you try out this query on your system, you probably will have different data returned, as data for Wide World Importers is randomly generated and you can add data any time. You can read more about it in the tip Generate more data for the Wide World Importers sample databases.
sample query
Before we can use this query in the Mobile Report Publisher, we need to turn it into a shared data set. You can either create one using Visual Studio (SQL Server Data Tools) or using Report Builder. Let's create one with Report Builder. On the SSRS portal, you can click on the New menu to create different kinds of objects. Selecting Dataset will open up Report Builder.
create new item using Report Builder
Before we continue, we need to make sure there's a shared data source our dataset can use. In the following screenshot a data source to the Wide World Importers data warehouse is created:
create new data source
When we create the new dataset, you need to pick the data source you just created.
create new data set - select data source
Next we need to write the query for the dataset. The easiest option would be to write the query using Management Studio and to copy paste it into the editor. Make sure you are using the Text Editor by clicking on Edit as Text.
specify query
Before we save the dataset, we need to set some additional options for the parameter. We can do this by clicking on the Set Options button in the ribbon. In the Dataset properties dialog, go to the parameter pane.
specify query
Here we'll configure the following options:
  • The data type is Integer.
  • The default value for the parameter is 2016.
  • It won't allow empty or multiple values.
Now we can save the dataset and give it a name. Now we're going to repeat the process and create a shared dataset that will supply the parameter values to the mobile report. In other words, a simple query that will return the different years. The following SELECT statement is used:
SELECT DISTINCT Years = YEAR([Order Date Key])
FROM [Fact].[Order]
ORDER BY 1;

Using a Parameter in a Mobile Report

Let's start by creating a new Mobile Report. On the portal, click New and then Mobile Report.
create mobile report
This will open up Mobile Report Publisher. If it isn't installed on your system yet, you'll have to download and install it first. In the Data section of the mobile report, we're going to add our two shared datasets. You can do this by clicking on the Add Data button.
add data
Since we have a shared dataset on the server, we need to choose the Report Server option.
report server
After choosing your report server, you can pick the shared dataset you just created.
choose shared data set
The data will now appear in the Mobile Report Publisher editor. The editor has recognized that the dataset contains a parameter. This is indicated with the curly brackets inside the green circle, right next to the dataset name. You can repeat the same process to add the dataset with the distinct years.
imported data set
Before we proceed further, let's add two objects to the dashboard canvas. You can do this in the Layout section of the tool. The first one is a Selection List, which will provide us with a dropdown box for choosing the parameter value. The other object is a Simple data grid, which will display the tabular data.
dashboard design
Now we need to hook these up with the datasets we imported. Back to the Data tab! It's possible that there are some simulated tables there. These are automatically generated by the Mobile Report Publisher to provide the dashboard objects with sample data. These will disappear once you hook them up with the actual datasets. For the Selection List, change the keys value to the dataset that contains the distinct years. In the example, this is Param_Years. Change the column to Years. There are no other options to set. Do not configure the selection list to filter out any other dataset, since this will be done by the parameter itself.
configure selection list
The next step is to configure the parameter for the OrderswithParam dataset. Click on the gear icon next to the dataset to open its context menu.
context menu
In the context menu, click on the curly brackets (with Param.) to open up the parameter menu.
parameter menu
You have three configuration options for the parameter value:
  • Default value. This will take the value configured inside the shared dataset as the default value.
  • A hardcoded value.
  • Source report parameters. These are values provided by objects inside the report. In our case, the selection list.
For the selection list, you can choose between SelectedItem or SelectedItems, depending if you want to have multi-select or not. Here, we want a single selection of a value, so we set the parameter value to SelectedItem of the selection list. Click Apply to close the menu. The next step is hooking up the data grid with the orders dataset. Select the grid in the left pane and set the following properties:
grid properties
When we run the preview, you'll see that the grid is empty.
no data returned
This is caused by the selection list we has as default value the All member. The Orders dataset doesn't know any year that is equal to All, so it will not return any data. You can either avoid this by turning off the All selection in the selection list options.
disable All
Another option is to take this into account in the source query. If the parameter value equals "All", all data should be returned. After disabling the all selection, we get the following result when the mobile report is in preview mode:
preview with data 2013
By changing the selection, we can run the orders dataset for a different year:
preview with data 2016

Remarks

Although the shared dataset for the orders has a configured default value of 2016 for the year parameter, the mobile report just uses the first item of the list instead. In this case, the year 2013. There seems to be no way of influencing this behavior.
There seem to be issues when you add parameters to a dataset at a later point in time. It's possible that the Mobile Report Publisher doesn't detect that there are changes in the dataset, even though you refresh it. Adding the dataset a second time will detect the parameter in the second dataset, but this means you have to relink every report object to the new dataset. This is something you'd like to avoid, so think ahead of which datasets will need parameters.

Conclusion

Adding parameters to a mobile report is straight forward. However, if you need more advanced options, such as using the all member or multi-selections, you need to take care of it in the source query. Some sources will handle this better than others.
Next Steps
  • Try it out yourself! You can follow along with the sample provided in the tip.
  • The tip SQL Server 2016 Reporting Services Mobile Report goes into more detail about how to create mobile reports using the DataZen technology.
  • For more SQL Server 2016 tips, you can use this overview.
https://www.mssqltips.com/sqlservertip/4625/using-a-parameter-in-a-sql-server-reporting-services-2016-mobile-report/

Embedding Power BI Reports with Power BI Report Server

by Kasper

A common question I get is what will we will be able to do around embedding Power BI reports with Power BI report server. To understand this it is important to look at how the Power BI reports are being integrated into SSRS.
The Power BI reports are really a new type of reports supported by Reporting services. In SQL Server 2016 we added support for mobile reports and now with Power BI Report Server we add support for Power BI reports. This means that the reports will be using the traditional reporting services framework and “content management” system which means it’s existing folder structure including all it’s security features but also it’s existing embedding framework. Now SSRS has several ways to do embedding, one is using the reportviewer control and the other is through iframe embedding. The report viewer control only works for RDL files, not for the mobile reports nor for the Power BI reports, that leaves us with the traditional IFrame embedding.  Let’s take a look at this works.
To try this I started by creating a sample report and upload it to Power BI report server:
image
This I can open and see as part of my Report Server:
image
Now let’s say I want to embed this into a regular ASP.NET application. I start by creating a blank ASP.NET web app in Visual Studio and remove all the content from my Default.ASPX  within the asp:Content tags and replace it with an asp.net Iframe, leaving my page to look like this:
1
2
3
4
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<IFRAME id="frame1" scrolling="auto" runat="server" width="1000px;" height="600px">
</IFRAME>
</asp:Content>
Now in my code behind I want to load my report:
1
2
3
4
protected void Page_Load(object sender, EventArgs e)
{
}
Running this will compile and run but will not show anything:
image
The trick here is to add the following parameter to the URL: “?rs:Embed=true” as described here in the SSRS team blog. This will generate an embedding-optimized view of the report.
Now the code looks like this:
1
2
3
4
protected void Page_Load(object sender, EventArgs e)
{
}
Now running this again give us what we want:
image
And that is it, of course this can be used in a customer application or when you want to embed into SharePoint.
A few interesting things to note here are:
  1. There are currently no ways to add parameters to the connection string, I talked to the team and this is definitely on the road map.
  2. The user who is connecting to your custom app also needs to have access to the Power BI report on the report server, this is great for internal applications but harder for extranet scenario’s. A solution to this is also on the road map.
https://www.kasperonbi.com/embedding-power-bi-reports-with-power-bi-report-server/

  Installing Redis-x64-3.2.100 on Windows and Running Redis Server https://medium.com/@kasunprageethdissanayake/installing-redis-x64-3-2-100...