コード例 #1
0
 internal UncDocument(UncSession session, UncObjectId objectId) : base(session, objectId, new FileInfo(objectId.Path.LocalPath), UncDocumentSchema.Instance)
 {
     this.fileInfo = (this.fileSystemInfo as FileInfo);
 }
コード例 #2
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;
            }));
        }
コード例 #3
0
ファイル: UncSession.cs プロジェクト: YHZX2013/exchange_diff
        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);
        }