We are planning to move our Team Foundation Server server to a new domain, and as such any customized permissions will need to be updated/corrected.
I was wondering if there was a tool, or some sample code I could use to scan through TFS files and folders (as seen in Source Control Explorer) to find permissions that are different from the default.
Note that unfortunately, we are still using TFS 2010.
What I would like is to get or build a summarized list saying at this path, security was changed for User X to a, User Y to b, etc. and if inheritance was turned off. If a path did not have any security changes, then I would prefer it if it is not included in the report. I can build code to strip that out if necessary as long as the report is in an editable format (e.g. csv, xml, html, txt)
I am quite willing to create the tool myself, I am just unsure where to start. It seems like the libraries for this are so large and often these things are not well documented. If I create this, I will share what I can.
Thank you
You may try Team Foundation Sidekicks. Team Foundation Sidekicks includes Permission Sidekick, which provides the following features:
Select user whose effective permissions are to be reviewed
View Team Foundation Server groups user is a member of (Windows
domain groups are not included)
View user's global TFS server permissions
Select Team project to view project specific effective permissions
View user's Team project's permissions
Select project's version control folder/file and view effective
version control permissions for that item (including indication
whether permissions are inherited or explicitly set)
Select project's area and view effective permissions for that area
For every effective permissions display, view a reason for every
effective permission setting - namely, for which groups Allow/Deny
permissions are set and therefore what effective permission is based
on
I ended up writing code to do this. I'm sorry it took so long to post this.
It creates a text file that specifies the security on every item in TFS that has explicit security. It may give more information that needed, but worked well for my needs.
If you make use of this, you should replace "TFSServer" with your actual server name, and "CollectionName" with the actual source code collection name which is typically "DefaultCollection".
Note that this was written in VB, and requires the following references.
Default references of System, System.Core, XML, and XML.Linq are included.
From "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0"
Microsoft.TeamFoundation.Client
Microsoft.TeamFoundation.Common
Microsoft.TeamFoundation.VersionControl.Client
Option Explicit On
Option Strict On
Option Infer Off
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports Microsoft.TeamFoundation.Client
Imports Microsoft.TeamFoundation.VersionControl.Client
Imports Microsoft.TeamFoundation.Framework.Client
Imports System.IO
Namespace EnumerateTFSSecurity
Friend Class Program
Private Shared UpdateConsoleIndex As Integer
Shared Sub Main()
Try
Dim tfs As TfsTeamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(New Uri("http://TFSServer:8080/tfs/CollectionName"))
Dim OutputFileName As String = ".\EnumTFSSec.txt"
If Command().Length <> 0 Then
OutputFileName = Command()
End If
tfs.EnsureAuthenticated()
Dim VersionControl As VersionControlServer = tfs.GetService(Of VersionControlServer)()
Dim OutputFile As StreamWriter = New StreamWriter(OutputFileName)
Dim AllProjs() As TeamProject = VersionControl.GetAllTeamProjects(True)
For Each TeamProj As TeamProject In AllProjs
GetChildItems(VersionControl, TeamProj.ServerItem, OutputFile)
OutputFile.Flush()
Next
Catch e As Exception
Dim ex As String = e.Message
Console.WriteLine("!!EXCEPTION: " & e.Message)
Console.WriteLine("Continuing... ")
End Try
Console.WriteLine("========")
Console.Read()
End Sub
Private Shared Sub GetChildItems(VersionControl As VersionControlServer, ItemPath As String, OutputFile As StreamWriter)
Dim Items() As Item = VersionControl.GetItems(ItemPath & "/*").Items
Dim FolderPaths As Specialized.StringCollection
Dim FilePaths As List(Of String)
FolderPaths = New Specialized.StringCollection
FilePaths = New List(Of String)
GetSecurityInfo(VersionControl, {ItemPath}, OutputFile)
For Each Item As Item In Items
If Item.ItemType = ItemType.Folder Then
FolderPaths.Add(Item.ServerItem)
Else
FilePaths.Add(Item.ServerItem)
End If
Next
For Each Folder As String In FolderPaths
GetChildItems(VersionControl, Folder, OutputFile)
Next
If FilePaths.Count <> 0 Then
GetSecurityInfo(VersionControl, FilePaths.ToArray, OutputFile)
End If
End Sub
' Define other methods and classes here
Private Shared Sub GetSecurityInfo(VersionControl As VersionControlServer, ByVal ItemPaths() As String, OutputFile As StreamWriter)
Dim result As List(Of String) = New List(Of String)
Dim SecurityList() As ItemSecurity
Dim SecurityInfo As StringBuilder = Nothing
Dim Clearstringlength As Integer
Dim ConsoleText As String
Try
SecurityList = VersionControl.GetPermissions(ItemPaths, RecursionType.None)
SecurityInfo = New StringBuilder
If SecurityList IsNot Nothing AndAlso SecurityList.Length <> 0 Then
For Each ItemSecurity As ItemSecurity In SecurityList
With ItemSecurity
If .Inherit = False Then
SecurityInfo.Append(" - Inherit: False")
End If
For Each Entry As AccessEntry In .Entries
If (Entry.Allow.Length <> 0 OrElse Entry.Deny.Length <> 0) Then
SecurityInfo.AppendLine()
SecurityInfo.AppendLine(" Identity: " & Entry.IdentityName)
If Entry.Allow.Length <> 0 Then
SecurityInfo.Append(" Allow: ")
For Each Value As String In Entry.Allow
SecurityInfo.Append(Value & "; ")
Next
SecurityInfo.Remove(SecurityInfo.Length - 2, 2)
If Entry.Deny.Length <> 0 Then
SecurityInfo.AppendLine()
End If
End If
If Entry.Deny.Length <> 0 Then
SecurityInfo.Append(" Deny: ")
For Each Value As String In Entry.Deny
SecurityInfo.Append(Value & "; ")
Next
SecurityInfo.Remove(SecurityInfo.Length - 2, 2)
End If
End If
Next
If SecurityInfo.Length <> 0 Then
SecurityInfo.AppendLine()
End If
End With
If UpdateConsoleIndex Mod 25 = 0 Then
ConsoleText = "Item:" & ItemSecurity.ServerItem
Clearstringlength = If(Console.CursorTop = 0, 0, Console.CursorTop * Console.BufferWidth - 1) - ConsoleText.Length
Console.CursorTop = 0
Console.CursorLeft = 0
If Clearstringlength > 0 Then
ConsoleText &= New String(" "c, Clearstringlength)
End If
Console.WriteLine(ConsoleText)
End If
If SecurityInfo IsNot Nothing AndAlso SecurityInfo.Length > 0 Then
If UpdateConsoleIndex <> 0 Then
OutputFile.WriteLine()
End If
OutputFile.Write("Item:" & ItemSecurity.ServerItem)
OutputFile.Write(SecurityInfo.ToString())
SecurityInfo.Clear()
End If
UpdateConsoleIndex += 1
Next
End If
Catch e As Exception
Dim ex As String = e.Message
Console.WriteLine("!!EXCEPTION: " & e.Message)
Console.WriteLine("Continuing... ")
End Try
End Sub
End Class
End Namespace
Related
It's trying to make a TypeProvider for Xamarin.Forms, but has been plagued by FS2024 error.
Parse own library from the XAML of Xamarin.Forms
Assign x:Name to Propertis
`F#
type MainPage = Moonmile.XamarinFormsTypeProvider.XAML<"MainPage.xaml">
// made btn1 and text1 propertis
type MainPageEx(target:MainPage) =
let mutable count = 0
do
// When set event to btn.Clicked, happen FS2024 error.
// If this event is comment out, it success build.
target.btn1.Clicked.Add( fun e ->
count <- count + 1
target.btn1.Text <- "Clicked " + count.ToString())
// Property is success
member this.CurrentPage
with get() = target.CurrentPage
When you are referring to a property, build & operation you can normally.
But the internal class of Xamarin.Forms like Button.Clicked, If you try to access to, it is the build error.
Sample code for error
https://github.com/moonmile/SimpleEventTypeProvider
Making code for XamarinFormsTypeProvider
github.com/moonmile/XamarinFormsTypeProvider
Maybe, I suspect inconsistencies and is happening in the part of the generation of a Native TypeProvider and Xamrin.Forms.Core a PCL.
F# Compiler for F# 3.1 (Open Source Edition)
Freely distributed under the Apache 2.0 Open Source License my error!!!
isMscorlib: true
name: "System.Runtime"
PrimaryAssembly.DotNetCore.Name: "System.Runtime"
PrimaryAssembly.Mscorlib.Name: "mscorlib"
parameter error FS2024: Static linking may not use assembly that targets different profile.
It's to operate the property they work properly, and to MVVM perhaps.
Butt I am trying to implement a way to be assigned to Button.Clicked events
as shown in the codebehide-like buildings if possible.
Would there workaround or what?
In the case of XAML in WPF, How can such seems to work well.
github.com/fsprojects/FsXaml
This answer isn't guaranteed to be correct, but it should help at least point you in the right direction.
The first thing to do is to make sure that you have installed the latest Visual F# Tools Build, as this adds the FSharp.Core that is compatible with the PCL profiles (You can find it here: (https://visualfsharp.codeplex.com/). Once that is installed, you will want to reference either the Profile78, or Profile259 FSharp.Core.dll (On my machine, these are found at: "C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp.NETPortable\2.3.5.0", and "C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp.NETPortable\2.3.5.1" respectively).
Once you have that installed, the next thing to do is make sure that your PCL projects have the following in their project files (This tells MSBuild / xBuild that the projects are PCL libraries, and that they are F# Projects):
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{F2A71F9B-5D33-465A-A702-920D77279786}</ProjectTypeGuids>
Once that is done, you will need to select either Profile78, or Profile259 (I would recommend 78, as the current Xamarin.Forms nuget package doesn't support 259).
Once that is done, then you should be able to build and run and it should get rid of the error.
Thank you for my question.
Meybe,
When it build TypeProvider, F# compiler use classes in mscorlib.
When it resolve the type of btn1.Clicked event, the F# comiler use type in System.Runtime.
I think for that, and it can not be resolved at build time
Try, if you attach the Clicked Event using reflection, it has moved successfully on Android build through.
I seem, if it I use only shard classes in mscorlib and System.Rutime, I can build no FS2024 error.
type MainPage = Moonmile.XamarinFormsTypeProvider.XAML<"MainPage.xaml">
type MainPageEx() as this =
inherit BindObject<MainPage>(new MainPage())
// Add handlder by reflection
let AddHandler(target:obj, eventName:string, eventMethod: obj*obj -> unit ) =
let hdr = Action<obj,obj>( fun s e -> eventMethod(s,e))
let ei = target.GetType().GetRuntimeEvent(eventName)
let dt = ei.AddMethod.GetParameters().[0].ParameterType
let handler = new Action<obj,obj>(fun s e -> hdr.Invoke( s, new EventArgs() ))
let handlerInvoke = handler.GetType().GetRuntimeMethod("Invoke", [|typeof<obj>; typeof<Type[]>|])
let dele = handlerInvoke.CreateDelegate( dt, handler )
let add = new Func<Delegate, EventRegistrationToken> ( fun t ->
let para = ei.AddMethod.GetParameters()
let ret = ei.AddMethod.Invoke( target, [|t|])
if ret <> null then
ret :?> EventRegistrationToken
else
new EventRegistrationToken()
)
let remove = new Action<EventRegistrationToken>( fun t -> ei.RemoveMethod.Invoke(target, [|t|]) |> ignore )
// WindowsRuntimeMarshal.AddEventHandler<Delegate>(add, remove, dele)
add.Invoke( dele ) |> ignore
()
let mutable count = 0
do
(* // build error
target.btn1.Clicked.Add( fun e ->
count <- count + 1
target.btn1.Text <- "Clicked " + count.ToString())
*)
// add handler by reflection
AddHandler( base.Target.btn1, "Clicked", this.ButtonClick )
()
member this.CurrentPage
with get() = this.Target.CurrentPage
member this.ButtonClick(s,e) =
count <- count + 1
base.Target.text1.Text <- "clicked " + count.ToString()
Is it possible to build a DataTable object from scratch using F#
I have written this code
module DataHelper
open System
open System.Data
open System.Data.SqlClient
let addDataRow (dt : DataTable) kerberos =
let dr = dt.NewRow()
dr["Kerberos"] = kerberos
dt.Rows.Add(dr)
let Func userList : string seq =
let dt : DataTable = new DataTable("UserNameListType")
let dc : DataColumn = new DataColumn("Kerberos")
dt.Columns.Add(dc)
Seq.iter (fun user -> addDataRow dt user) userList
dt
But this has too many errors
VS.NET does not seem to understand DataTable, DataRow classes and only shows me a "Note" as intellisense.
Its hard to use the collection objects Rows, Columns in F# because none of the methods really work (which work easily in C#).
If you're doing this in a new project, you need to add references to System.Data.dll and System.Xml.dll. After that, Visual Studio should recognize the types. You can do that by right clicking on "References" in your project and choosing "Add Reference".
Aside from that, there are two minor mistakes in your code. The assignment should be written as (note that there is a dot before [ and the operator is <- instead of =):
dr.["Kerberos"] <- kerberos
And your Func function should return DataTable:
let Func userList : DataTable =
I am learning how to use nHapi. As many have pointed out, there's not much documentation. Following this doc I've been able to parse a message using the library. But I can't figure out how to access that message using an object model (which is what I really want nHapi to do). Essentially, I want to take an HL7 message as a string and access it using the object model, in the same way that LINQ to SQL takes a database record and lets you access it as an object. I found Parsing an HL7 without a priori messageType knowledge, but it seems to be about something else because the code in the post returns a string instead of an HL7 object (like I need). In the documentation I linked to above they seem to access the parts of a message using a "query"--but I can't find the materials to query IMessages in the library.
Here is the code I'm using, with a line showing what I want to do...
Imports NHapi.Base
Imports NHapi.Base.Parser
Imports NHapi.Base.Model
Module Module1
Sub Main()
Dim msg As String = "MSH|^~\&|SENDING|SENDER|RECV|INST|20060228155525||QRY^R02^QRY_R02|1|P|2.3|QRD|20060228155525|R|I||||10^RD&Records&0126|38923^^^^^^^^&INST|||"
Dim myPipeParser As PipeParser = New PipeParser()
Dim myImsg As IMessage = myPipeParser.Parse(msg)
Dim msgType As String = myImsg.GetStructureName
Dim mySendingFacilityName As String = myImsg.getSendingFacility() //this is what I want
End Sub
Remember with HL7 messages that each segment has to end with a line return.
Also, you'll want to parse the message back to its actual type in order for the object model to be fully populated correctly (notice that when I used myPipeParser.Parse it was cast back to a QRY_R02 message type from the NHapi.Model.V23 Library). So the code should look something like this:
Imports NHapi.Model.V23.Message
Imports NHapi.Base.Parser
Imports NHapi.Base
Module Module1
Sub Main()
Dim msg As String = "MSH|^~\&|SENDING|SENDER|RECV|INST|20060228155525||QRY^R02^QRY_R02|1|P|2.3" & vbNewLine & _
"QRD|20060228155525|R|I||||10^RD&Records&0126|38923^^^^^^^^&INST|||"
Dim myPipeParser As PipeParser = New PipeParser()
Dim myImsg As QRY_R02 = myPipeParser.Parse(msg)
Dim msgType As String = myImsg.GetStructureName
Dim mySendingFacilityName As String = myImsg.MSH.SendingFacility.NamespaceID.Value
Console.WriteLine(mySendingFacilityName)
Console.ReadLine()
End Sub
End Module
I know it was a very long time ago, however I was looking for this resource very recently and found that there is nearly no documentation on how to use this API. And excellent source of examples can be found in the test part of source code in the project NHapi.NUnit.
Sources can be found here
Could you please check my code? Why can't I get any values back when I use Linq to Sql?
BHS_TimeSheet is my database table in which have some records.
Model.TimeSheet is a class I create in the model.
Private db As DataFactoryDataContext
Public Sub New()
db = New DataFactoryDataContext
End Sub
Public Sub New(ByVal repository As DataFactoryDataContext)
db = repository
End Sub
Public Function GetTimeSheetByProject(ByVal wbs1 As String, ByVal wbs2 As String, ByVal wbs3 As String) _
As List(Of Model.TimeSheet) Implements ITimeSheetRepository.GetTimeSheetByProject
Return (From ts In db.BHS_TimeSheets _
Where ts.WBS1.Equals(wbs1) And ts.WBS2.Equals(wbs2) And ts.WBS3.Equals(wbs3) _
Select New Model.TimeSheet(ts.TSBatchNo, ts.Employee, ts.TransDate, ts.WBS1, ts.WBS2, ts.WBS3, ts.LaborCode, _
ts.RegHrs, ts.OvtHrs, ts.SpecialOvtHrs, ts.TransComment, ts.Status, ts.AuthorizedBy, _
ts.RejectReason, ts.ModDate)).ToList
End Function
Your Linq-to-SQL statement
(From ts In db.BHS_TimeSheets
Where ts.WBS1.Equals(wbs1)
And ts.WBS2.Equals(wbs2)
And ts.WBS3.Equals(wbs3) _
basically corresponds to this SQL query:
SELECT * FROM dbo.BHS_TimeSheets
WHERE WBS1 = (value for wbs1)
AND WBS2 = (value for wbs2)
AND WBS3 = (value for wbs3)
Does that SQL query return any values, if you call it with in SQL Server Management Studio using the same parameters for wbs1, wbs2, wbs3 as you do in your Linq-to-SQL code??
Update: okay, so the SQL query does return results - next step: approach the Linq-to-SQL stuff step by step. First, try this - do you get any results??
Dim basicQueryResults = (From ts In db.BHS_TimeSheets
Where ts.WBS1.Equals(wbs1)
And ts.WBS2.Equals(wbs2)
And ts.WBS3.Equals(wbs3)
).ToList();
Does your resulting list of items have a .Count > 0 or not??
If not: there must be something wrong with your Linq-to-SQL model then. Have you changed your database and not updated the DBML file?? Can you drop the DBML file and do it again - does it work now? Or do you still have the same results??
So here is the thing ..
I wrote a c# application to generate monthly Attendance Reports for each employee with his own details
I want to be able to do this once for all employees and view the report grouped by name
so when I select the customer name from the crystal report sub tree I get his monthly Attendance Report
I don't really know how to use the sub tree in crystal report ... is it possible to something like that ?
the goal from all this is to be able to print all reports at once in one click
This is not exactly what you asked for but I am going to post it because it may work for you. I did for me in a similar situation. Also sorry about the VB syntax
This will allow you to create your reports as PDFs using the Crystal Reports engine. Basically it will allow you to create multiple PDF using a loop, which can then be printed automatically.The Export PDF Sub will write the file to disk and then open it with the default pdf reader. The print PDF function will automaticaly print the PDF files that were saved to disk. This is not a perfect solution but I hope that it at least gets you closer to what you are trying to accomplish.
Public Class PDFCR
Private Const SW_SHOWNORMAL As Integer = 2
<DllImport("shell32")> _
Public Shared Function ShellExecute(ByVal hWnd As IntPtr, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Integer) As IntPtr
End Function
Public Shared Sub ExportPDF(ByVal crDOC As ReportDocument, ByVal FilePath As String)
Dim CrExportOptions As ExportOptions
Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions()
Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions()
CrDiskFileDestinationOptions.DiskFileName = FilePath
CrExportOptions = crDOC.ExportOptions
CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions
CrExportOptions.FormatOptions = CrFormatTypeOptions
crDOC.Export()
Process.Start(FilePath)
End Sub
Public Shared Function PrintPDF(ByVal FilePath As String) As Boolean
If IO.File.Exists(FilePath) Then
If ShellExecute(CType(1, IntPtr), "Print", FilePath, "", _
Directory.GetDirectoryRoot(FilePath), SW_SHOWNORMAL).ToInt32 <= 32 Then
Return False
Else
Return True
End If
Else
Return False
End If
End Function
End Class
I was having trouble getting the Imports to show in this code block so here they are in plain text.
Imports System.IO
Imports System.Management
Imports CrystalDecisions.Shared
Imports System.Runtime.InteropServices
Imports CrystalDecisions.CrystalReports.Engine
If you add a GROUP to your report on your Employee Name field, this will (by default) create the group tree you are looking for.
From there, code-wise, it can be turned off, but you should see the group tree by default if your report has any groups in it.
The problem seems to be with the report not being grouped on Employee Name.