Ejemplo n.º 1
0
 private void cvTitle_ServerValidate(object source, ServerValidateEventArgs args)
 {
     if (LinkId == 0 && ParentFolderId >= 0)
     {
         if (fs.FileExist(txtTitle.Text, ParentFolderId))
         {
             args.IsValid = false;
         }
         else
         {
             args.IsValid = true;
         }
     }
     else
     {
         Mediachase.IBN.Business.ControlSystem.FileInfo fi = fs.GetFile(FileId);
         if (fs.FileExist(txtTitle.Text, fi.ParentDirectoryId) && fi.Name != txtTitle.Text)
         {
             args.IsValid = false;
         }
         else
         {
             args.IsValid = true;
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the web dav URL by WebDavTicket.
        /// </summary>
        /// <param name="ticket">The ticket.</param>
        /// <returns></returns>
        public static string GetWebDavUrl(string ticket)
        {
            string       retVal       = string.Empty;
            WebDavTicket webDavTicket = WebDavTicket.Parse(ticket);

            //Попытаемся определить имя файла
            if (String.IsNullOrEmpty(webDavTicket.AbsolutePath.FileName))
            {
                if (webDavTicket.AbsolutePath.StorageType == ObjectTypes.File_FileStorage)
                {
                    FileStorageAbsolutePath fsAbsPath = webDavTicket.AbsolutePath as FileStorageAbsolutePath;
                    if (fsAbsPath != null)
                    {
                        FileStorage fs = new FileStorage();
                        Mediachase.IBN.Business.ControlSystem.FileInfo fileInfo = fs.GetFile(fsAbsPath.UniqueId);
                        if (fileInfo != null)
                        {
                            webDavTicket.AbsolutePath.FileName = fileInfo.Name;
                        }
                    }
                }
                else if (webDavTicket.AbsolutePath.StorageType == ObjectTypes.File_MetaData)
                {
                    MetaDataAbsolutePath mdAbsPath = webDavTicket.AbsolutePath as MetaDataAbsolutePath;
                    if (mdAbsPath != null)
                    {
                        Mediachase.Ibn.Data.Meta.FileInfo fileInfo = new Mediachase.Ibn.Data.Meta.FileInfo(mdAbsPath.FileUID);
                        webDavTicket.AbsolutePath.FileName = fileInfo.Name;
                    }
                }
                else if (webDavTicket.AbsolutePath.StorageType == ObjectTypes.File_MetaDataPlus)
                {
                    MetaDataPlusAbsolutePath mdpAbsPath = webDavTicket.AbsolutePath as MetaDataPlusAbsolutePath;
                    if (mdpAbsPath != null)
                    {
                        Mediachase.MetaDataPlus.MetaObject obj = MetaDataWrapper.LoadMetaObject(mdpAbsPath.MetaObjectId, mdpAbsPath.MetaObjectType);
                        MetaFile mf = obj[mdpAbsPath.MetaFieldName] as MetaFile;
                        if (mf != null)
                        {
                            webDavTicket.AbsolutePath.FileName = mf.Name;
                        }
                    }
                }
                else if (webDavTicket.AbsolutePath.StorageType == ObjectTypes.File_Incident)
                {
                    EmailStorageAbsolutePath emlAbsPath = webDavTicket.AbsolutePath as EmailStorageAbsolutePath;
                    if (emlAbsPath != null)
                    {
                        EMailMessageInfo emlInfo    = EMailMessageInfo.Load(emlAbsPath.EmailMsgId);
                        AttachmentInfo   attachInfo = emlInfo.Attachments[emlAbsPath.EmailAttachmentIndex];
                        webDavTicket.AbsolutePath.FileName = attachInfo.FileName;
                    }
                }
            }

            retVal = GetWebDavUrl(webDavTicket.AbsolutePath, true);


            return(retVal);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the web dav URL by FileInfo.
        /// </summary>
        /// <param name="fileInfo">The file info.</param>
        /// <param name="withAuthToken">if set to <c>true</c> [with auth token].</param>
        /// <returns></returns>
        public static string GetFileStorageWebDavUrl(Mediachase.IBN.Business.ControlSystem.FileInfo fileInfo, bool withAuthToken)
        {
            if (fileInfo == null)
            {
                throw new ArgumentNullException("fielInfo");
            }

            return(GetFileStorageWebDavUrl(fileInfo.Id, fileInfo.Name, withAuthToken));
        }
Ejemplo n.º 4
0
 private void BindValues()
 {
     Mediachase.IBN.Business.ControlSystem.FileInfo fi = fs.GetFile(FileId);
     if (fi != null)
     {
         txtTitle.Text         = fi.Name;
         textDescription.Text  = fi.Description;
         cbKeepHistory.Checked = fi.AllowHistory;
     }
 }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        public static int Create(string Extension, string ContentTypeString,
                                 string FriendlyName, string FileName, Stream _inputStream, string BigFileName,
                                 Stream _bigInputStream, bool AllowWebDav, bool AllowNewWindow, bool AllowForceDownload)
        {
            int ContentTypeId = -1;

            using (DbTransaction tran = DbTransaction.Begin())
            {
                int IconFileId    = -1;
                int BigIconFileId = -1;
                if (FileName != null && FileName != "")
                {
                    string ContainerName = "FileLibrary";
                    string ContainerKey  = "ContentType";

                    BaseIbnContainer bic = BaseIbnContainer.Create(ContainerName, ContainerKey);
                    FileStorage      fs  = (FileStorage)bic.LoadControl("FileStorage");
                    Mediachase.IBN.Business.ControlSystem.FileInfo fi = fs.SaveFile(fs.Root.Id, FileName, _inputStream);
                    IconFileId = fi.Id;
                }
                if (BigFileName != null && BigFileName != "")
                {
                    string ContainerName = "FileLibrary";
                    string ContainerKey  = "ContentType";

                    BaseIbnContainer bic1 = BaseIbnContainer.Create(ContainerName, ContainerKey);
                    FileStorage      fs1  = (FileStorage)bic1.LoadControl("FileStorage");
                    Mediachase.IBN.Business.ControlSystem.FileInfo fi1 = fs1.SaveFile(fs1.Root.Id, BigFileName, _bigInputStream);
                    BigIconFileId = fi1.Id;
                }

                object oIconFileId = DBNull.Value;
                if (IconFileId > 0)
                {
                    oIconFileId = IconFileId;
                }
                object oBigIconFileId = DBNull.Value;
                if (BigIconFileId > 0)
                {
                    oBigIconFileId = BigIconFileId;
                }
                ContentTypeId = DBContentType.Create(Extension, ContentTypeString, FriendlyName, oIconFileId, oBigIconFileId, AllowWebDav, AllowNewWindow, AllowForceDownload);

                tran.Commit();
            }
            return(ContentTypeId);
        }
Ejemplo n.º 7
0
            public DummyFileInfoWrapper(Mediachase.IBN.Business.ControlSystem.FileInfo fileInfo, FileHistoryInfo historyInfo)
            {
                _contentType       = fileInfo.FileBinaryContentType;
                _name              = fileInfo.Name;
                _fileBinaryId      = fileInfo.FileBinaryId;
                _legth             = fileInfo.Length;
                _created           = fileInfo.Created;
                _modified          = fileInfo.Modified;
                _containerKey      = fileInfo.ContainerKey;
                _parentDirectoryId = fileInfo.ParentDirectoryId;

                if (historyInfo != null)
                {
                    _contentType  = historyInfo.FileBinaryContentType;
                    _name         = historyInfo.Name;
                    _fileBinaryId = historyInfo.FileBinaryId;
                    _legth        = historyInfo.Length;
                    _modified     = historyInfo.Modified;
                }
            }
Ejemplo n.º 8
0
        public static void Update(int ContentTypeId, string FriendlyName,
                                  string FileName, Stream _inputStream, string BigFileName,
                                  Stream _bigInputStream, bool AllowWebDav, bool AllowNewWindow, bool AllowForceDownload)
        {
            //		int OldIconFileId = DBContentType.GetIconFileId(ContentTypeId);
            //		int OldBigIconFileId = DBContentType.GetBigIconFileId(ContentTypeId);

            using (DbTransaction tran = DbTransaction.Begin())
            {
                DBContentType.Update(ContentTypeId, FriendlyName, AllowWebDav, AllowNewWindow, AllowForceDownload);
                if (FileName != null && FileName != "")
                {
                    string ContainerName = "FileLibrary";
                    string ContainerKey  = "ContentType";

                    BaseIbnContainer bic = BaseIbnContainer.Create(ContainerName, ContainerKey);
                    FileStorage      fs  = (FileStorage)bic.LoadControl("FileStorage");
                    Mediachase.IBN.Business.ControlSystem.FileInfo fi = fs.SaveFile(fs.Root.Id, FileName, _inputStream);

                    DBContentType.UpdateIconFileId(ContentTypeId, fi.Id);
                    //				if(OldIconFileId>0 && OldIconFileId!=fi.Id)
                    //					fs.DeleteFile(OldIconFileId);
                }

                if (BigFileName != null && BigFileName != "")
                {
                    string ContainerName = "FileLibrary";
                    string ContainerKey  = "ContentType";

                    BaseIbnContainer bic = BaseIbnContainer.Create(ContainerName, ContainerKey);
                    FileStorage      fs  = (FileStorage)bic.LoadControl("FileStorage");
                    Mediachase.IBN.Business.ControlSystem.FileInfo fi = fs.SaveFile(fs.Root.Id, BigFileName, _bigInputStream);

                    DBContentType.UpdateBigIconFileId(ContentTypeId, fi.Id);
                    //				if(OldBigIconFileId>0 && OldBigIconFileId!=fi.Id)
                    //					fs.DeleteFile(OldBigIconFileId);
                }

                tran.Commit();
            }
        }
Ejemplo n.º 9
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;
        }
Ejemplo n.º 10
0
 private string GetLinkText(FileInfo fi)
 {
     System.IO.MemoryStream memStream = new System.IO.MemoryStream();
     Mediachase.IBN.Business.ControlSystem.FileStorage.LightLoadFile(fi, memStream);
     memStream.Position = 0;
     System.IO.StreamReader reader = new System.IO.StreamReader(memStream, Encoding.Unicode);
     string data = reader.ReadLine();
     string sLink = "";
     while (data != null)
     {
         if (data.IndexOf("URL=") >= 0)
         {
             sLink = data.Substring(data.IndexOf("URL=") + 4);
             break;
         }
         data = reader.ReadLine();
     }
     if (sLink != "")
     {
         if (!sLink.StartsWith("http://") && !sLink.StartsWith("\\"))
             sLink = "http://" + sLink;
         if (sLink.StartsWith("\\"))
         {
             sLink = sLink.Replace(@"\", "/");
             sLink = "file:" + sLink;
         }
     }
     return sLink;
 }
Ejemplo n.º 11
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            Response.ContentType = "application/octet-stream";

            int FileId = int.Parse(Request.QueryString["Id"]);

            if (Request.QueryString["CName"] != null && Request.QueryString["CKey"] != null)
            {
                string           ContainerName = Request.QueryString["CName"];
                string           ContainerKey  = Request.QueryString["CKey"];
                BaseIbnContainer bic           = BaseIbnContainer.Create(ContainerName, ContainerKey);
                Mediachase.IBN.Business.ControlSystem.FileStorage fs = (Mediachase.IBN.Business.ControlSystem.FileStorage)bic.LoadControl("FileStorage");

                Mediachase.IBN.Business.ControlSystem.FileInfo fi = fs.GetFile(FileId);
                if (fi == null)
                {
                    throw new NotExistingIdException();
                }
                FileHistoryInfo fhiLoad = null;
                if (Request["VId"] != null)
                {
                    FileHistoryInfo[] _fhi = fi.GetHistory();
                    foreach (FileHistoryInfo fhi in _fhi)
                    {
                        if (fhi.Id == int.Parse(Request["VId"]))
                        {
                            fhiLoad = fhi;
                            break;
                        }
                    }
                }
                if (fhiLoad == null)
                {
                    Response.ContentType = fi.FileBinaryContentType;
                    if (fi.FileBinaryContentType.ToLower().IndexOf("url") >= 0)
                    {
                        MemoryStream memStream = new MemoryStream();
                        fs.LoadFile(FileId, memStream);
                        memStream.Position = 0;
                        StreamReader reader = new StreamReader(memStream, Encoding.Unicode);
                        string       data   = reader.ReadLine();
                        string       sLink  = "";
                        while (data != null)
                        {
                            if (data.IndexOf("URL=") >= 0)
                            {
                                sLink = data.Substring(data.IndexOf("URL=") + 4);
                                break;
                            }
                            data = reader.ReadLine();
                        }
                        if (sLink != "")
                        {
                            if (!sLink.StartsWith("http://"))
                            {
                                sLink = "http://" + sLink;
                            }
                            Response.Redirect(sLink);
                            return;
                        }
                    }

                    if (Mediachase.IBN.Business.Common.OpenInNewWindow(fi.FileBinaryContentType))
                    {
                        Response.AddHeader("content-disposition", String.Format("inline; filename=\"{0}\"", GetNameForCurrentBrowser(fi.Name)));
                    }
                    else
                    {
                        Response.AddHeader("content-disposition", String.Format("attachment; filename=\"{0}\"", GetNameForCurrentBrowser(fi.Name)));
                    }
                    fs.LoadFile(FileId, Response.OutputStream);
                }
                else
                {
                    Response.ContentType = fhiLoad.FileBinaryContentType;
                    if (Mediachase.IBN.Business.Common.OpenInNewWindow(fhiLoad.FileBinaryContentType))
                    {
                        Response.AddHeader("content-disposition", String.Format("inline; filename=\"{0}\"", GetNameForCurrentBrowser(fhiLoad.Name)));
                    }
                    else
                    {
                        Response.AddHeader("content-disposition", String.Format("attachment; filename=\"{0}\"", GetNameForCurrentBrowser(fhiLoad.Name)));
                    }
                    fs.LoadFile(fhiLoad, Response.OutputStream);
                }
            }
            else
            {
                Mediachase.IBN.Business.ControlSystem.FileInfo fi = Mediachase.IBN.Business.ControlSystem.FileStorage.GetFile(Mediachase.IBN.Business.Security.CurrentUser.UserID, "Read", FileId);
                if (fi == null)
                {
                    throw new NotExistingIdException();
                }
                Response.ContentType = fi.FileBinaryContentType;
                if (Mediachase.IBN.Business.Common.OpenInNewWindow(fi.FileBinaryContentType))
                {
                    Response.AddHeader("content-disposition", String.Format("inline; filename=\"{0}\"", GetNameForCurrentBrowser(fi.Name)));
                }
                else
                {
                    Response.AddHeader("content-disposition", String.Format("attachment; filename=\"{0}\"", GetNameForCurrentBrowser(fi.Name)));
                }
                Mediachase.IBN.Business.ControlSystem.FileStorage.LightLoadFile(fi, Response.OutputStream);
            }


            Response.End();
        }
Ejemplo n.º 12
0
        private static bool CheckRights(SystemEventTypes eventType, ObjectTypes objectType, ObjectTypes relObjectType, int?objectId, int?relObjectId, Guid?objectUid, int userId)
        {
            // если нужна дополнительная проверка в зависимости от типа события, то её нужно делать здесь
            bool retval = false;

            if (relObjectType == ObjectTypes.File_FileStorage && relObjectId != null)
            {
                FileInfo fileInfo = null;
                //Получаем оригинальный файл
                using (IDataReader reader = Mediachase.IBN.Database.ControlSystem.DBFile.GetById(0, relObjectId.Value))
                {
                    if (reader.Read())
                    {
                        fileInfo = new Mediachase.IBN.Business.ControlSystem.FileInfo(reader);
                    }
                }

                if (fileInfo != null)
                {
                    return(CheckFileStorageRight(fileInfo, "Read", userId));
                }
            }

            switch (objectType)
            {
            case ObjectTypes.ToDo:
                retval = ToDo.CanRead(objectId.Value, userId);
                break;

            case ObjectTypes.CalendarEntry:
                retval = CalendarEntry.CanRead(objectId.Value, userId);
                break;

            case ObjectTypes.Document:
                retval = Document.CanRead(objectId.Value, userId);
                break;

            case ObjectTypes.Issue:
                retval = Incident.CanRead(objectId.Value, userId);
                break;

            case ObjectTypes.List:
                retval = ListInfoBus.CanRead(objectId.Value, userId);
                break;

            case ObjectTypes.Project:
                retval = Project.CanRead(objectId.Value, userId);
                break;

            case ObjectTypes.Task:
                retval = Task.CanRead(objectId.Value, userId);
                break;

            case ObjectTypes.IssueRequest:
                retval = IssueRequest.CanUse(userId);
                break;

            case ObjectTypes.User:
                retval = Security.IsUserInGroup(userId, InternalSecureGroups.Administrator);
                break;

            case ObjectTypes.Assignment:
                AssignmentEntity entity = (AssignmentEntity)BusinessManager.Load(AssignmentEntity.ClassName, (PrimaryKeyId)objectUid);
                if (entity != null && entity.OwnerDocumentId.HasValue)
                {
                    retval = Document.CanRead(entity.OwnerDocumentId.Value, userId);
                }
                break;

            default:
                // Для остальных временно разрешаем любой доступ
                retval = true;
                break;
            }

            return(retval);
        }
Ejemplo n.º 13
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            // Check Security
            if (Security.CurrentUser == null)
            {
                int iObjectTypeId = -1;
                int iObjectId     = -1;

                using (IDataReader reader = Mediachase.IBN.Business.User.GetGateByGuid(ExternalID))
                {
                    if (reader.Read())
                    {
                        iObjectTypeId = (int)reader["ObjectTypeId"];
                        iObjectId     = (int)reader["ObjectId"];
                    }
                }

                if (iObjectTypeId != (int)ObjectTypes.Issue)
                {
                    throw new AccessDeniedException();
                }
            }

            // Download
            Response.ContentType = "application/octet-stream";
            int    FileId        = int.Parse(Request.QueryString["Id"]);
            string ContainerName = Request.QueryString["CName"];
            string ContainerKey  = Request.QueryString["CKey"];

            if (!String.IsNullOrEmpty(ContainerName) && !String.IsNullOrEmpty(ContainerKey))
            {
                BaseIbnContainer bic = BaseIbnContainer.Create(ContainerName, ContainerKey);
                Mediachase.IBN.Business.ControlSystem.FileStorage fs = (Mediachase.IBN.Business.ControlSystem.FileStorage)bic.LoadControl("FileStorage");

                FileInfo fi = fs.GetFile(FileId);
                if (fi == null)
                {
                    throw new NotExistingIdException();
                }

                FileHistoryInfo fhiLoad = null;
                if (Request["VId"] != null)
                {
                    FileHistoryInfo[] _fhi = fi.GetHistory();
                    foreach (FileHistoryInfo fhi in _fhi)
                    {
                        if (fhi.Id == int.Parse(Request["VId"]))
                        {
                            fhiLoad = fhi;
                            break;
                        }
                    }
                }

                if (fhiLoad == null)
                {
                    Response.ContentType = fi.FileBinaryContentType;

                    if (Mediachase.IBN.Business.Common.OpenInNewWindow(fi.FileBinaryContentType))
                    {
                        Response.AddHeader("content-disposition", String.Format("inline; filename=\"{0}\"", GetNameForCurrentBrowser(fi.Name)));
                    }
                    else
                    {
                        Response.AddHeader("content-disposition", String.Format("attachment; filename=\"{0}\"", GetNameForCurrentBrowser(fi.Name)));
                    }
                    fs.LoadFile(FileId, Response.OutputStream);
                }
                else
                {
                    Response.ContentType = fhiLoad.FileBinaryContentType;
                    if (Mediachase.IBN.Business.Common.OpenInNewWindow(fhiLoad.FileBinaryContentType))
                    {
                        Response.AddHeader("content-disposition", String.Format("inline; filename=\"{0}\"", GetNameForCurrentBrowser(fhiLoad.Name)));
                    }
                    else
                    {
                        Response.AddHeader("content-disposition", String.Format("attachment; filename=\"{0}\"", GetNameForCurrentBrowser(fhiLoad.Name)));
                    }
                    fs.LoadFile(fhiLoad, Response.OutputStream);
                }
            }
            else
            {
                Mediachase.IBN.Business.ControlSystem.FileInfo fi = Mediachase.IBN.Business.ControlSystem.FileStorage.GetFile(Mediachase.IBN.Business.Security.CurrentUser.UserID, "Read", FileId);
                if (fi == null)
                {
                    throw new NotExistingIdException();
                }
                Response.ContentType = fi.FileBinaryContentType;
                if (Mediachase.IBN.Business.Common.OpenInNewWindow(fi.FileBinaryContentType))
                {
                    Response.AddHeader("content-disposition", String.Format("inline; filename=\"{0}\"", GetNameForCurrentBrowser(fi.Name)));
                }
                else
                {
                    Response.AddHeader("content-disposition", String.Format("attachment; filename=\"{0}\"", GetNameForCurrentBrowser(fi.Name)));
                }
                Mediachase.IBN.Business.ControlSystem.FileStorage.LightLoadFile(fi, Response.OutputStream);
            }

            Response.End();
        }