public new static UncDocumentLibraryFolder Read(UncSession session, ObjectId folderId)
        {
            if (folderId == null)
            {
                throw new ArgumentNullException("folderId");
            }
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }
            UncObjectId uncObjectId = folderId as UncObjectId;

            if (uncObjectId == null)
            {
                throw new ArgumentException("folderId");
            }
            return(Utils.DoUncTask <UncDocumentLibraryFolder>(session.Identity, uncObjectId, false, Utils.MethodType.Read, delegate
            {
                FileSystemInfo fileSystemInfo = new FileInfo(uncObjectId.Path.LocalPath);
                if (fileSystemInfo.Attributes != (FileAttributes)(-1) && (fileSystemInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    return new UncDocumentLibraryFolder(session, uncObjectId);
                }
                throw new ObjectNotFoundException(uncObjectId, Strings.ExObjectNotFound(uncObjectId.Path.LocalPath));
            }));
        }
Example #2
0
        private UncSession(UncObjectId objectId, IPrincipal authenticatedUser)
        {
            WindowsPrincipal windowsPrincipal = authenticatedUser as WindowsPrincipal;

            if (windowsPrincipal == null)
            {
                throw new ArgumentException("authenticatedUser");
            }
            this.identity = (WindowsIdentity)windowsPrincipal.Identity;
            this.id       = new UncObjectId(new Uri("\\\\" + objectId.Path.Host), UriFlags.Unc);
        }
Example #3
0
        internal static G DoUncTask <G>(WindowsIdentity identity, UncObjectId uncObjectId, bool objectOpened, Utils.MethodType methodType, Utils.DoTask <G> doTask)
        {
            WindowsImpersonationContext windowsImpersonationContext = Utils.ImpersonateUser(identity);
            G result;

            try
            {
                result = doTask();
            }
            catch (IOException ex)
            {
                Utils.UndoContext(ref windowsImpersonationContext);
                throw Utils.TranslateException(ex, uncObjectId, objectOpened);
            }
            catch (UnauthorizedAccessException innerException)
            {
                Utils.UndoContext(ref windowsImpersonationContext);
                if (methodType == Utils.MethodType.GetView)
                {
                    throw new GetViewAccessDeniedException(uncObjectId, Strings.ExAccessDeniedForGetViewUnder((uncObjectId != null) ? uncObjectId.Path.LocalPath : null), innerException);
                }
                if (methodType == Utils.MethodType.GetStream)
                {
                    throw new DocumentStreamAccessDeniedException(uncObjectId, Strings.ExAccessDenied((uncObjectId != null) ? uncObjectId.Path.LocalPath : null), innerException);
                }
                throw new AccessDeniedException(uncObjectId, Strings.ExAccessDenied((uncObjectId != null) ? uncObjectId.Path.LocalPath : null), innerException);
            }
            catch (SecurityException innerException2)
            {
                Utils.UndoContext(ref windowsImpersonationContext);
                if (methodType == Utils.MethodType.GetView)
                {
                    throw new GetViewAccessDeniedException(uncObjectId, Strings.ExAccessDeniedForGetViewUnder((uncObjectId != null) ? uncObjectId.Path.LocalPath : null), innerException2);
                }
                if (methodType == Utils.MethodType.GetStream)
                {
                    throw new DocumentStreamAccessDeniedException(uncObjectId, Strings.ExAccessDeniedForGetViewUnder((uncObjectId != null) ? uncObjectId.Path.LocalPath : null), innerException2);
                }
                throw new AccessDeniedException(uncObjectId, Strings.ExAccessDenied((uncObjectId != null) ? uncObjectId.Path.LocalPath : null), innerException2);
            }
            catch
            {
                Utils.UndoContext(ref windowsImpersonationContext);
                throw;
            }
            finally
            {
                Utils.UndoContext(ref windowsImpersonationContext);
            }
            return(result);
        }
Example #4
0
 private UncDocumentLibrary(UncSession session, UncObjectId id, string description)
 {
     if (id.Path.Segments.Length != 2)
     {
         throw new ArgumentException("id");
     }
     this.shareName     = Uri.UnescapeDataString(id.Path.Segments[1]);
     this.description   = description;
     this.id            = id;
     this.session       = session;
     this.directoryInfo = new DirectoryInfo(this.Uri.LocalPath);
     this.directoryInfo.Refresh();
     FileAttributes attributes = this.directoryInfo.Attributes;
 }
Example #5
0
        public static UncSession Open(ObjectId objectId, IPrincipal authenticatedUser)
        {
            if (objectId == null)
            {
                throw new ArgumentNullException("objectId");
            }
            if (authenticatedUser == null)
            {
                throw new ArgumentNullException("authenticatedUser");
            }
            UncObjectId uncObjectId = objectId as UncObjectId;

            if (uncObjectId == null)
            {
                throw new ArgumentException("objectId");
            }
            return(new UncSession(uncObjectId, authenticatedUser));
        }
Example #6
0
 internal static DocumentLibraryException TranslateException(IOException ex, UncObjectId objectId, bool objectOpened)
 {
     if (ex is FileNotFoundException || ex is DirectoryNotFoundException)
     {
         if (objectOpened)
         {
             return(new ObjectMovedOrDeletedException(objectId, Strings.ExObjectNotFound((objectId != null) ? objectId.Path.LocalPath : null), ex));
         }
         return(new ObjectNotFoundException(objectId, Strings.ExObjectNotFound((objectId != null) ? objectId.Path.LocalPath : null), ex));
     }
     else
     {
         if (ex is PathTooLongException)
         {
             return(new PathTooLongException(objectId, Strings.ExPathTooLong((objectId != null) ? objectId.Path.LocalPath : null), ex));
         }
         return(new UnknownErrorException(objectId, Strings.ExUnknownError, ex));
     }
 }
 internal UncDocumentLibraryItem(UncSession session, UncObjectId uncObjectId, FileSystemInfo fileSystemInfo, Schema schema)
 {
     this.session        = session;
     this.uncId          = uncObjectId;
     this.fileSystemInfo = fileSystemInfo;
     this.schema         = schema;
     try
     {
         this.fileSystemInfo.Refresh();
         if (this.fileSystemInfo.Attributes == (FileAttributes)(-1))
         {
             throw new ObjectNotFoundException(uncObjectId, Strings.ExObjectNotFound(uncObjectId.Path.LocalPath));
         }
     }
     catch (ArgumentException innerException)
     {
         throw new ObjectNotFoundException(uncObjectId, Strings.ExObjectNotFound(uncObjectId.Path.LocalPath), innerException);
     }
 }
        public static UncDocumentLibraryItem Read(UncSession session, ObjectId id)
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            UncObjectId uncObjectId = id as UncObjectId;

            if (uncObjectId == null)
            {
                throw new ArgumentException("id");
            }
            if (uncObjectId.UriFlags != UriFlags.UncDocument && uncObjectId.UriFlags != UriFlags.UncFolder)
            {
                throw new ArgumentException("id");
            }
            if (!session.Uri.IsBaseOf(uncObjectId.Path))
            {
                throw new ArgumentException("objectId");
            }
            return(Utils.DoUncTask <UncDocumentLibraryItem>(session.Identity, uncObjectId, false, Utils.MethodType.Read, delegate
            {
                FileSystemInfo fileSystemInfo = new FileInfo(uncObjectId.Path.LocalPath);
                if (fileSystemInfo.Attributes == (FileAttributes)(-1))
                {
                    throw new ObjectNotFoundException(uncObjectId, Strings.ExObjectNotFound(uncObjectId.Path.LocalPath));
                }
                if (fileSystemInfo.Exists)
                {
                    return new UncDocument(session, uncObjectId);
                }
                if ((fileSystemInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    return new UncDocumentLibraryFolder(session, uncObjectId);
                }
                throw new ObjectNotFoundException(uncObjectId, Strings.ExObjectNotFound(uncObjectId.Path.LocalPath));
            }));
        }
Example #9
0
        public UncDocumentLibraryItem Read(ObjectId objectId, params PropertyDefinition[] propsToReturn)
        {
            if (objectId == null)
            {
                throw new ArgumentNullException("objectId");
            }
            UncObjectId uncObjectId = objectId as UncObjectId;

            if (uncObjectId == null)
            {
                throw new ArgumentException("objectId");
            }
            if (uncObjectId.Path.Segments.Length <= 2)
            {
                throw new ArgumentException("objectId");
            }
            if (!this.id.Path.IsBaseOf(uncObjectId.Path))
            {
                throw new ArgumentException("objectId");
            }
            return(UncDocumentLibraryItem.Read(this.session, uncObjectId));
        }
Example #10
0
        public override bool Equals(object obj)
        {
            UncObjectId uncObjectId = obj as UncObjectId;

            return(uncObjectId != null && uncObjectId.path == this.path);
        }
        internal static ITableView InternalGetView(QueryFilter query, SortBy[] sortBy, DocumentLibraryQueryOptions queryOptions, PropertyDefinition[] propsToReturn, UncSession session, DirectoryInfo directoryInfo, UncObjectId id)
        {
            if (propsToReturn == null)
            {
                throw new ArgumentNullException("propsToReturn");
            }
            if (propsToReturn.Length == 0)
            {
                throw new ArgumentException("propsToReturn");
            }
            DocumentLibraryPropertyDefinition[] propertyDefinitions = new DocumentLibraryPropertyDefinition[propsToReturn.Length];
            for (int i = 0; i < propsToReturn.Length; i++)
            {
                propertyDefinitions[i] = (propsToReturn[i] as DocumentLibraryPropertyDefinition);
                if (propertyDefinitions[i] == null)
                {
                    throw new ArgumentException("propsToReturn");
                }
            }
            return(Utils.DoUncTask <ArrayTableView>(session.Identity, id, true, Utils.MethodType.GetView, delegate
            {
                FileSystemInfo[] array;
                switch (queryOptions)
                {
                case DocumentLibraryQueryOptions.Folders:
                    array = directoryInfo.GetDirectories();
                    break;

                case DocumentLibraryQueryOptions.Files:
                    array = directoryInfo.GetFiles();
                    break;

                case DocumentLibraryQueryOptions.FoldersAndFiles:
                    array = directoryInfo.GetFileSystemInfos();
                    break;

                default:
                    throw new ArgumentOutOfRangeException("queryOptions");
                }
                List <object[]> list = new List <object[]>();
                int num = 0;
                int num2 = Utils.GetViewMaxRows;
                while (num < array.Length && num2 > 0)
                {
                    object[] array2 = new object[propertyDefinitions.Length];
                    for (int j = 0; j < propertyDefinitions.Length; j++)
                    {
                        array2[j] = UncDocumentLibraryItem.GetValueFromFileSystemInfo(propertyDefinitions[j], array[num]);
                    }
                    list.Add(array2);
                    num2--;
                    num++;
                }
                return new ArrayTableView(query, sortBy, propertyDefinitions, list);
            }));
        }
 internal UncDocumentLibraryFolder(UncSession session, UncObjectId objectId) : base(session, objectId, new DirectoryInfo(objectId.Path.LocalPath), UncFolderSchema.Instance)
 {
     this.directoryInfo = (this.fileSystemInfo as DirectoryInfo);
 }
Example #13
0
        private static ClassifyResult ClassifyUncLink(Uri uri, WindowsIdentity authenticatedUser)
        {
            WindowsImpersonationContext windowsImpersonationContext = null;
            ClassifyResult classifyResult = null;
            ClassifyResult result;

            try
            {
                windowsImpersonationContext = Utils.ImpersonateUser(authenticatedUser);
                UriFlags uriFlags = UriFlags.Other;
                if (!Utils.IsValidUncUri(uri))
                {
                    result = new ClassifyResult(uri, ClassificationError.InvalidUri);
                }
                else
                {
                    if (uri.Segments.Length == 1)
                    {
                        try
                        {
                            UncObjectId objectId   = new UncObjectId(uri, UriFlags.Unc);
                            UncSession  uncSession = UncSession.Open(objectId, new WindowsPrincipal(WindowsIdentity.GetCurrent()));
                            uncSession.GetView(null, null, new PropertyDefinition[0]);
                        }
                        catch (AccessDeniedException)
                        {
                            return(new ClassifyResult(uri, ClassificationError.AccessDenied));
                        }
                        catch (ObjectMovedOrDeletedException)
                        {
                            return(new ClassifyResult(uri, ClassificationError.ConnectionFailed));
                        }
                        uriFlags = UriFlags.Unc;
                    }
                    else if (uri.Segments.Length >= 2)
                    {
                        if (uri.Segments.Length >= 3)
                        {
                            try
                            {
                                FileSystemInfo fileSystemInfo = new FileInfo(uri.LocalPath);
                                if (fileSystemInfo.Attributes == (FileAttributes)(-1))
                                {
                                    return(new ClassifyResult(uri, ClassificationError.ObjectNotFound));
                                }
                                if ((fileSystemInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
                                {
                                    uriFlags = UriFlags.UncFolder;
                                }
                                else
                                {
                                    uriFlags = UriFlags.UncDocument;
                                }
                            }
                            catch (UnauthorizedAccessException)
                            {
                                classifyResult = new ClassifyResult(uri, ClassificationError.AccessDenied);
                            }
                            catch (FileNotFoundException)
                            {
                                classifyResult = new ClassifyResult(uri, ClassificationError.ObjectNotFound);
                            }
                            catch (IOException)
                            {
                                classifyResult = new ClassifyResult(uri, ClassificationError.AccessDenied);
                            }
                        }
                        if (classifyResult != null || uri.Segments.Length == 2)
                        {
                            IntPtr intPtr;
                            int    num = UncSession.NetShareGetInfo(uri.Host, Uri.UnescapeDataString(uri.Segments[1].TrimEnd(new char[]
                            {
                                '\\',
                                '/'
                            })), 1, out intPtr);
                            if (intPtr != IntPtr.Zero)
                            {
                                UncSession.NetApiBufferFree(intPtr);
                            }
                            else if (num == 5 || num == 2311)
                            {
                                classifyResult = new ClassifyResult(uri, ClassificationError.AccessDenied);
                            }
                            else if (num == 53 || num == 2250)
                            {
                                classifyResult = new ClassifyResult(uri, ClassificationError.ConnectionFailed);
                            }
                            else if (num == 2310)
                            {
                                classifyResult = new ClassifyResult(uri, ClassificationError.ObjectNotFound);
                            }
                            else if (num != 0)
                            {
                                classifyResult = new ClassifyResult(uri, ClassificationError.UnknownError);
                            }
                            uriFlags = UriFlags.UncDocumentLibrary;
                        }
                        if (classifyResult != null)
                        {
                            return(classifyResult);
                        }
                    }
                    if ((uriFlags & UriFlags.Unc) != (UriFlags)0)
                    {
                        result = new ClassifyResult(new UncObjectId(uri, uriFlags), uri, uriFlags);
                    }
                    else
                    {
                        result = new ClassifyResult(uri, ClassificationError.ObjectNotFound);
                    }
                }
            }
            catch
            {
                Utils.UndoContext(ref windowsImpersonationContext);
                throw;
            }
            finally
            {
                Utils.UndoContext(ref windowsImpersonationContext);
            }
            return(result);
        }
Example #14
0
        public static UncDocumentLibrary Read(UncSession session, ObjectId objectId)
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }
            if (objectId == null)
            {
                throw new ArgumentNullException("objectId");
            }
            UncObjectId uncObjectId = objectId as UncObjectId;

            if (uncObjectId == null || uncObjectId.UriFlags != UriFlags.UncDocumentLibrary)
            {
                throw new ArgumentException("objectId");
            }
            if (!session.Uri.IsBaseOf(uncObjectId.Path))
            {
                throw new ArgumentException("objectId");
            }
            if (uncObjectId.Path.Segments.Length != 2)
            {
                throw new ArgumentException("uncId");
            }
            return(Utils.DoUncTask <UncDocumentLibrary>(session.Identity, uncObjectId, false, Utils.MethodType.Read, delegate
            {
                string netName = Uri.UnescapeDataString(uncObjectId.Path.Segments[1].TrimEnd(new char[]
                {
                    '\\',
                    '/'
                }));
                IntPtr zero = IntPtr.Zero;
                int num = UncSession.NetShareGetInfo(uncObjectId.Path.Host, netName, 1, out zero);
                try
                {
                    if (num == 0)
                    {
                        UncSession.SHARE_INFO_1 share_INFO_ = (UncSession.SHARE_INFO_1)Marshal.PtrToStructure(zero, typeof(UncSession.SHARE_INFO_1));
                        try
                        {
                            return new UncDocumentLibrary(session, uncObjectId, share_INFO_.Remark);
                        }
                        catch (IOException innerException)
                        {
                            throw new AccessDeniedException(uncObjectId, Strings.ExAccessDenied(uncObjectId.Path.LocalPath), innerException);
                        }
                    }
                    if (num == 5 || num == 2311)
                    {
                        throw new AccessDeniedException(uncObjectId, Strings.ExAccessDenied(uncObjectId.Path.LocalPath));
                    }
                    if (num == 53 || num == 2250)
                    {
                        throw new ConnectionException(uncObjectId, Strings.ExCannotConnectToMachine(uncObjectId.Path.Host));
                    }
                    throw new ObjectNotFoundException(uncObjectId, Strings.ExObjectNotFound(uncObjectId.Path.LocalPath));
                }
                finally
                {
                    if (zero != IntPtr.Zero)
                    {
                        UncSession.NetApiBufferFree(zero);
                    }
                }
                UncDocumentLibrary result;
                return result;
            }));
        }
Example #15
0
 internal UncDocument(UncSession session, UncObjectId objectId) : base(session, objectId, new FileInfo(objectId.Path.LocalPath), UncDocumentSchema.Instance)
 {
     this.fileInfo = (this.fileSystemInfo as FileInfo);
 }
Example #16
0
        public ITableView GetView(QueryFilter filter, SortBy[] sortBy, params PropertyDefinition[] propsToReturn)
        {
            WindowsImpersonationContext windowsImpersonationContext = Utils.ImpersonateUser(this.identity);
            ITableView result;

            try
            {
                IntPtr zero = IntPtr.Zero;
                try
                {
                    int num = 0;
                    int num3;
                    int num4;
                    int num2 = UncSession.NetShareEnum(this.id.Path.Host, 1, out zero, -1, out num3, out num4, ref num);
                    if (num2 == 5)
                    {
                        throw new AccessDeniedException(this.Id, Strings.ExAccessDenied(this.id.Path.LocalPath));
                    }
                    if (num2 == 2250 || num2 == 53)
                    {
                        throw new ObjectMovedOrDeletedException(this.Id, Strings.ExObjectMovedOrDeleted(this.id.Path.LocalPath));
                    }
                    List <object[]> list = new List <object[]>();
                    if (num2 == 0 && num3 > 0)
                    {
                        int    num5 = Marshal.SizeOf(typeof(UncSession.SHARE_INFO_1));
                        IntPtr ptr  = zero;
                        int    num6 = 0;
                        int    num7 = Utils.GetViewMaxRows;
                        while (num6 < num3 && num7 > 0)
                        {
                            UncSession.SHARE_INFO_1 share_INFO_ = (UncSession.SHARE_INFO_1)Marshal.PtrToStructure(ptr, typeof(UncSession.SHARE_INFO_1));
                            if (share_INFO_.ShareType == UncSession.ShareType.Disk)
                            {
                                UncObjectId   uncObjectId   = new UncObjectId(new Uri(Path.Combine("\\\\" + this.id.Path.Host, share_INFO_.NetName)), UriFlags.UncDocumentLibrary);
                                object[]      array         = new object[propsToReturn.Length];
                                DirectoryInfo directoryInfo = null;
                                bool          flag          = true;
                                int           i             = 0;
                                while (i < propsToReturn.Length)
                                {
                                    DocumentLibraryPropertyId         documentLibraryPropertyId         = DocumentLibraryPropertyId.None;
                                    DocumentLibraryPropertyDefinition documentLibraryPropertyDefinition = propsToReturn[i] as DocumentLibraryPropertyDefinition;
                                    if (documentLibraryPropertyDefinition != null)
                                    {
                                        documentLibraryPropertyId = documentLibraryPropertyDefinition.PropertyId;
                                    }
                                    DocumentLibraryPropertyId documentLibraryPropertyId2 = documentLibraryPropertyId;
                                    switch (documentLibraryPropertyId2)
                                    {
                                    case DocumentLibraryPropertyId.None:
                                        array[i] = new PropertyError(propsToReturn[i], PropertyErrorCode.NotFound);
                                        break;

                                    case DocumentLibraryPropertyId.Uri:
                                        array[i] = uncObjectId.Path;
                                        break;

                                    case DocumentLibraryPropertyId.ContentLength:
                                    case DocumentLibraryPropertyId.CreationTime:
                                    case DocumentLibraryPropertyId.LastModifiedTime:
                                    case DocumentLibraryPropertyId.IsFolder:
                                        goto IL_1F2;

                                    case DocumentLibraryPropertyId.IsHidden:
                                        array[i] = share_INFO_.NetName.EndsWith("$");
                                        break;

                                    case DocumentLibraryPropertyId.Id:
                                        array[i] = uncObjectId;
                                        break;

                                    case DocumentLibraryPropertyId.Title:
                                        array[i] = share_INFO_.NetName;
                                        break;

                                    default:
                                        if (documentLibraryPropertyId2 != DocumentLibraryPropertyId.Description)
                                        {
                                            goto IL_1F2;
                                        }
                                        array[i] = share_INFO_.Remark;
                                        break;
                                    }
IL_248:
                                    i++;
                                    continue;
IL_1F2:
                                    if (flag)
                                    {
                                        try
                                        {
                                            if (directoryInfo == null && flag)
                                            {
                                                directoryInfo = new DirectoryInfo(uncObjectId.Path.LocalPath);
                                                FileAttributes attributes = directoryInfo.Attributes;
                                            }
                                        }
                                        catch (UnauthorizedAccessException)
                                        {
                                            flag = false;
                                        }
                                        catch (IOException)
                                        {
                                            flag = false;
                                        }
                                    }
                                    if (flag)
                                    {
                                        array[i] = UncDocumentLibraryItem.GetValueFromFileSystemInfo(documentLibraryPropertyDefinition, directoryInfo);
                                        goto IL_248;
                                    }
                                    array[i] = new PropertyError(documentLibraryPropertyDefinition, PropertyErrorCode.NotFound);
                                    goto IL_248;
                                }
                                list.Add(array);
                                num7--;
                            }
                            num6++;
                            ptr = (IntPtr)(ptr.ToInt64() + (long)num5);
                        }
                    }
                    result = new ArrayTableView(filter, sortBy, propsToReturn, list);
                }
                finally
                {
                    if (IntPtr.Zero != zero)
                    {
                        UncSession.NetApiBufferFree(zero);
                    }
                }
            }
            catch
            {
                Utils.UndoContext(ref windowsImpersonationContext);
                throw;
            }
            finally
            {
                Utils.UndoContext(ref windowsImpersonationContext);
            }
            return(result);
        }