Tuesday, March 8, 2011

ListView ObservableCollection Selection

I have ListView with GridView inside (in order to divide ListView for some columns). I bind ObservableCollection of some objects with that ListView.DataContext when main UserControl is loaded. Items show up but when i create two objects which fields have same values (and put them to observable collection), that new items show up in ListView. Problem is that, when user clicks and select one of the new item - both select.

When value of one of mentioned objects changes (and is different) problem doesn't exist, ListView treat them as it should.

Friday, March 4, 2011

The filter

head t.txt; echo ... tail t.txt

%sort -r +1-2 t1_data.txt
%sort -r -n -k2 t1_data.txt
%grep ' [6-9]' t1_data.txt

Wednesday, February 23, 2011

C# Write Access Check

        /// <summary> Checks for write access for the given file.
        /// </summary>
        /// <param name="fileName">The filename.</param>
        /// <returns>true, if write access is allowed, otherwise false</returns>
        public static bool WriteAccess(string dire)
        {

            // Get the access rules of the specified files (user groups and user names that have access to the file)
            var rules = Directory.GetAccessControl(dire).GetAccessRules(true, true, typeof(System.Security.Principal.SecurityIdentifier));

            // Get the identity of the current user and the groups that the user is in.
            var groups = WindowsIdentity.GetCurrent().Groups;
            string sidCurrentUser = WindowsIdentity.GetCurrent().User.Value;

            // Check if writing to the file is explicitly denied for this user or a group the user is in.
            if (rules.OfType<FileSystemAccessRule>().Any(r => (groups.Contains(r.IdentityReference) || r.IdentityReference.Value == sidCurrentUser) && r.AccessControlType == AccessControlType.Deny && (r.FileSystemRights & FileSystemRights.WriteData) == FileSystemRights.WriteData))
                return false;

            // Check if writing is allowed
            return rules.OfType<FileSystemAccessRule>().Any(r => (groups.Contains(r.IdentityReference) || r.IdentityReference.Value == sidCurrentUser) && r.AccessControlType == AccessControlType.Allow && (r.FileSystemRights & FileSystemRights.WriteData) == FileSystemRights.WriteData);
        }

WPF Mouse Cursors busy

Mouse.OverrideCursor = Cursors.Wait;
Mouse.OverrideCursor = null;

Wednesday, February 9, 2011

Articles to read about Threads

http://msdn.microsoft.com/en-us/magazine/cc163328.aspx

http://msdn.microsoft.com/en-us/library/ms741870.aspx

c# thread

ThreadPool.QueueUserWorkItem(new WaitCallback(delegate
    {
        ChangeCMFolderLocationEventHandler(sender, oea);
    }));



Dispatcher.Invoke(new Action(() => mainDockingPane.mainDockingManager.ExecuteClose(mainDockingPane.Detail)));