/// <summary>
        /// Opens the write.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns></returns>
        public override System.IO.Stream OpenWrite(Mediachase.Net.Wdom.WebDavElementInfo element, long contentLength)
        {
            FileStorageAutoCommitedTransactedStream result = null;

            if (element != null && !(element is CollectionInfo))
            {
                DummyFileInfoWrapper fileInfo = element.Tag as DummyFileInfoWrapper;
                if (fileInfo != null)
                {
                    CheckRight(fileInfo, "Write");

                    try
                    {
                        //Auto committed transaction stream wrapper
                        result = new FileStorageAutoCommitedTransactedStream(DataContext.Current.BeginTransaction(), fileInfo.ContainerKey,
                                                                             fileInfo.ParrentDirectoryId, fileInfo.Name, contentLength);
                        result.InnerStream = new MemoryStream();
                    }
                    catch (Exception)
                    {
                        throw new HttpException(404, "Not Found");
                    }
                }
            }

            return(result);
        }
        /// <summary>
        /// Opens the read.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns></returns>
        public override System.IO.Stream OpenRead(Mediachase.Net.Wdom.WebDavElementInfo element)
        {
            FileStorageAutoCommitedTransactedStream result = null;

            if (element != null && !(element is CollectionInfo))
            {
                DummyFileInfoWrapper fileInfo = element.Tag as DummyFileInfoWrapper;
                if (fileInfo != null)
                {
                    CheckRight(fileInfo, "Read");

                    //update download counter
                    Mediachase.IBN.Database.ControlSystem.DBFile.FileBinaryModifyCounter(fileInfo.FileBinaryId);
                    try
                    {
                        result             = new FileStorageAutoCommitedTransactedStream(DataContext.Current.BeginTransaction(), 0);
                        result.InnerStream = Mediachase.IBN.Database.ControlSystem.DBFile.OpenRead(fileInfo.FileBinaryId);
                    }
                    catch (Exception)
                    {
                        throw new HttpException(404, "Not Found");
                    }
                }
            }

            return(result);
        }
        private static void CheckRight(DummyFileInfoWrapper fileInfo, string action)
        {
            bool isActionAllowed = false;

            int userId = Security.CurrentUser.UserID;

            if (fileInfo.ContainerKey.StartsWith("ForumNodeId_"))
            {
                // Extract forumNodeId
                int forumNodeId = int.Parse(fileInfo.ContainerKey.Split('_')[1]);

                // Find incidentId by ForumNodeId
                string forumContainerKey = ForumThreadNodeInfo.GetOwnerContainerKey(forumNodeId);
                int    incidentId        = int.Parse(forumContainerKey.Split('_')[1]);

                // Check Security
                switch (action)
                {
                case "Read":
                    isActionAllowed = Incident.CanRead(incidentId);
                    break;

                case "Write":
                    isActionAllowed = Incident.CanUpdate(incidentId);
                    break;
                }
            }
            else if (fileInfo.ContainerKey.StartsWith("DocumentVers_"))
            {
                // Extract documentVersionId
                int documentId = int.Parse(fileInfo.ContainerKey.Split('_')[1]);

                // Check Security
                switch (action)
                {
                case "Read":
                    isActionAllowed = Document.CanRead(documentId);
                    break;

                case "Write":
                    isActionAllowed = Document.CanAddVersion(documentId);
                    break;
                }
            }
            else
            {
                isActionAllowed = FileStorage.CanUserRunAction(userId, fileInfo.ContainerKey, fileInfo.ParrentDirectoryId, action);
                //retVal = FileStorage.CanUserRead(Security.CurrentUser.UserID, fileInfo.ContainerKey, fileInfo.ParrentDirectoryId);
            }

            if (!isActionAllowed)
            {
                throw new HttpException(403, "Operation '" + action + "' is forbidden.");
            }
        }
        protected ResourceInfo GetResourceInfo(WebDavTicket ticket)
        {
            FileStorageAbsolutePath absPath = ticket.AbsolutePath as FileStorageAbsolutePath;

            if (absPath == null)
            {
                throw new ArgumentException("ticket.AbsolutePath is null.");
            }

            ResourceInfo result = new ResourceInfo();

            Mediachase.IBN.Business.ControlSystem.FileInfo fileInfo = null;

            //Получаем оригинальный файл
            using (IDataReader reader = Mediachase.IBN.Database.ControlSystem.DBFile.GetById(Security.CurrentUser.TimeZoneId, absPath.UniqueId))
            {
                if (reader.Read())
                {
                    fileInfo = new Mediachase.IBN.Business.ControlSystem.FileInfo(reader);
                }
            }

            if (fileInfo == null)
            {
                throw new HttpException(404, "Not found");
            }

            FileHistoryInfo historyInfo = null;

            //Поддержка версий
            if (absPath.IsHistory)
            {
                foreach (FileHistoryInfo history in fileInfo.GetHistory())
                {
                    if (history.Id == absPath.HistoryId)
                    {
                        historyInfo = history;
                        break;
                    }
                }
            }

            DummyFileInfoWrapper dummyInfo = new DummyFileInfoWrapper(fileInfo, historyInfo);

            result.AbsolutePath  = ticket.ToString();
            result.Tag           = dummyInfo;
            result.Name          = dummyInfo.Name;
            result.ContentType   = dummyInfo.ContentType;
            result.ContentLength = dummyInfo.Length;
            result.ParentName    = "root";
            result.Modified      = dummyInfo.Modified;
            result.Created       = dummyInfo.Created;

            return(result);
        }
Exemple #5
0
        internal static void FileListCtrlAddListPrefix(MonoBehaviour __instance, int index, ref string name,
                                                       string club, string personality, string fullpath)
        {
            try
            {
                if (!TranslationHelper.Instance.CurrentCardLoadTranslationEnabled || __instance == null)
                {
                    return;
                }
                var wrapper = new DummyFileInfoWrapper(index, name, club, personality, fullpath);
                Translation.Hooks.FileListCtrlAddListPrefix(__instance, wrapper);
                name = wrapper.Name;
            }

            catch (Exception err)
            {
                Logger.LogException(err, __instance, nameof(FileListCtrlAddListPrefix));
            }
        }
Exemple #6
0
        private static void CheckRight(DummyFileInfoWrapper fileInfo, string action)
        {
            bool isActionAllowed = false;

            int userId = Security.CurrentUser.UserID;

            if (fileInfo.ContainerKey.StartsWith("ForumNodeId_"))
            {
                // Extract forumNodeId
                int forumNodeId = int.Parse(fileInfo.ContainerKey.Split('_')[1]);

                // Find incidentId by ForumNodeId
                string forumContainerKey = ForumThreadNodeInfo.GetOwnerContainerKey(forumNodeId);
                int incidentId = int.Parse(forumContainerKey.Split('_')[1]);

                // Check Security
                switch (action)
                {
                    case "Read":
                        isActionAllowed = Incident.CanRead(incidentId);
                        break;
                    case "Write":
                        isActionAllowed = Incident.CanUpdate(incidentId);
                        break;
                }
            }
            else if (fileInfo.ContainerKey.StartsWith("DocumentVers_"))
            {
                // Extract documentVersionId
                int documentId = int.Parse(fileInfo.ContainerKey.Split('_')[1]);

                // Check Security
                switch (action)
                {
                    case "Read":
                        isActionAllowed = Document.CanRead(documentId);
                        break;
                    case "Write":
                        isActionAllowed = Document.CanAddVersion(documentId);
                        break;
                }
            }
            else
            {
                isActionAllowed = FileStorage.CanUserRunAction(userId, fileInfo.ContainerKey, fileInfo.ParrentDirectoryId, action);
                //retVal = FileStorage.CanUserRead(Security.CurrentUser.UserID, fileInfo.ContainerKey, fileInfo.ParrentDirectoryId);
            }

            if (!isActionAllowed)
                throw new HttpException(403, "Operation '" + action + "' is forbidden.");
        }
Exemple #7
0
        protected ResourceInfo GetResourceInfo(WebDavTicket ticket)
        {
            FileStorageAbsolutePath absPath = ticket.AbsolutePath as FileStorageAbsolutePath;
            if (absPath == null)
                throw new ArgumentException("ticket.AbsolutePath is null.");

            ResourceInfo result = new ResourceInfo();

            Mediachase.IBN.Business.ControlSystem.FileInfo fileInfo = null;

            //Получаем оригинальный файл
            using (IDataReader reader = Mediachase.IBN.Database.ControlSystem.DBFile.GetById(Security.CurrentUser.TimeZoneId, absPath.UniqueId))
            {
                if (reader.Read())
                    fileInfo = new Mediachase.IBN.Business.ControlSystem.FileInfo(reader);
            }

            if (fileInfo == null)
                throw new HttpException(404, "Not found");

            FileHistoryInfo historyInfo = null;

            //Поддержка версий
            if (absPath.IsHistory)
            {
                foreach (FileHistoryInfo history in fileInfo.GetHistory())
                {
                    if (history.Id == absPath.HistoryId)
                    {
                        historyInfo = history;
                        break;
                    }
                }
            }

            DummyFileInfoWrapper dummyInfo = new DummyFileInfoWrapper(fileInfo, historyInfo);
            result.AbsolutePath = ticket.ToString();
            result.Tag = dummyInfo;
            result.Name = dummyInfo.Name;
            result.ContentType = dummyInfo.ContentType;
            result.ContentLength = dummyInfo.Length;
            result.ParentName = "root";
            result.Modified = dummyInfo.Modified;
            result.Created = dummyInfo.Created;

            return result;
        }