Esempio n. 1
0
        public static void ProcessAvatar(HttpContext context, string[] segments, int organizationID, string path, int filePathID)
        {
            string fileName = "";

            if (Path.GetExtension(path) == "")
            {
                path = Path.ChangeExtension(path, ".jpg");
                string imageFile = Path.GetFileName(path);
                path = Path.GetDirectoryName(path);
                string imagePath = Path.Combine(AttachmentPath.GetPath(LoginUser.Anonymous, organizationID, AttachmentPath.Folder.ProfileImages, filePathID), path);
                fileName = AttachmentPath.GetImageFileName(imagePath, imageFile);
                if (!File.Exists(fileName))
                {
                    imagePath = Path.Combine(AttachmentPath.GetDefaultPath(LoginUser.Anonymous, AttachmentPath.Folder.ProfileImages, filePathID), path);
                    fileName  = AttachmentPath.GetImageFileName(imagePath, imageFile);
                }
            }
            else
            {
                fileName = Path.Combine(AttachmentPath.GetPath(LoginUser.Anonymous, organizationID, AttachmentPath.Folder.ProfileImages, filePathID), path);
            }
            if (File.Exists(fileName))
            {
                WriteImage(context, fileName);
            }
        }
Esempio n. 2
0
        public static void ProcessRequest(LoginUser loginUser, int organizationID, HttpContext context, int?_id, string _ratingImage, List <string> segments)
        {
            int id;

            if (int.TryParse(segments[segments.Count - 1], out id))
            {
                _id = id;
                segments.RemoveAt(segments.Count - 1);
            }

            if (segments[segments.Count - 1] == "ratingpositive" || segments[segments.Count - 1] == "ratingneutral" || segments[segments.Count - 1] == "ratingnegative")
            {
                _ratingImage = segments[segments.Count - 1];
                segments.RemoveAt(segments.Count - 1);
            }


            AttachmentPath.Folder folder = GetFolder(context, segments.ToArray());
            if (folder == AttachmentPath.Folder.None)
            {
                throw new Exception("Invalid path.");
            }

            AttachmentProxy.References refType = AttachmentPath.GetFolderReferenceType(folder);
            if (refType == AttachmentProxy.References.None)
            {
                SaveFilesOld(loginUser, organizationID, _id, _ratingImage, context, folder);
            }
            else
            {
                SaveFiles(loginUser, context, folder, organizationID, _id);
            }
        }
Esempio n. 3
0
        public static string GetAttachmentPath3(int organizationID, int chatID, AttachmentProxy attachment)
        {
            string attachmentPath = AttachmentPath.GetPath(LoginUser.Anonymous, organizationID, AttachmentPath.Folder.ChatUploads, (int)attachment.FilePathID);

            attachmentPath += "\\" + chatID;

            attachmentPath = Path.Combine(attachmentPath, attachment.FileName);
            return(attachmentPath);
        }
Esempio n. 4
0
        private static AttachmentPath.Folder GetFolder(HttpContext context, string[] segments)
        {
            StringBuilder path = new StringBuilder();

            for (int i = 0; i < segments.Length; i++)
            {
                path.Append("\\");
                path.Append(segments[i]);
            }
            return(AttachmentPath.GetFolderByName(path.ToString()));
        }
Esempio n. 5
0
        public static string GetCacheFileName2(int organizationID, int userID, int size)
        {
            string cachePath = Path.Combine(AttachmentPath.GetImageCachePath(LoginUser.Anonymous), "HubLogo\\" + organizationID.ToString());

            if (!Directory.Exists(cachePath))
            {
                Directory.CreateDirectory(cachePath);
            }
            string cacheFileName = Path.Combine(cachePath, userID.ToString() + "-" + size.ToString() + ".jpg");

            return(cacheFileName);
        }
Esempio n. 6
0
        public static string GetCacheFileName1(string initial, int size)
        {
            string cachePath = Path.Combine(AttachmentPath.GetImageCachePath(LoginUser.Anonymous), "Initials");

            if (!Directory.Exists(cachePath))
            {
                Directory.CreateDirectory(cachePath);
            }
            string cacheFileName = Path.Combine(cachePath, initial + "-" + size.ToString() + ".jpg");

            return(cacheFileName);
        }
Esempio n. 7
0
        public static void ProcessImages(HttpContext context, string[] segments, int organizationID)
        {
            StringBuilder builder = new StringBuilder();

            for (int i = 2; i < segments.Length; i++)
            {
                if (i != 2)
                {
                    builder.Append("\\");
                }
                builder.Append(segments[i]);
            }
            string path     = builder.ToString();
            string fileName = "";

            if (Path.GetExtension(path) == "")
            {
                path = Path.ChangeExtension(path, ".jpg");
                string imageFile = Path.GetFileName(path);
                path = Path.GetDirectoryName(path);
                string imagePath = Path.Combine(AttachmentPath.GetPath(LoginUser.Anonymous, organizationID, AttachmentPath.Folder.Images), path);
                if (!Directory.Exists(imagePath))
                {
                    Directory.CreateDirectory(imagePath);
                }
                fileName = AttachmentPath.GetImageFileName(imagePath, imageFile);
                if (!File.Exists(fileName))
                {
                    imagePath = Path.Combine(AttachmentPath.GetDefaultPath(LoginUser.Anonymous, AttachmentPath.Folder.Images), path);
                    fileName  = AttachmentPath.GetImageFileName(imagePath, imageFile);
                }
            }
            else
            {
                fileName = Path.Combine(AttachmentPath.GetPath(LoginUser.Anonymous, organizationID, AttachmentPath.Folder.Images), path);
            }

            if (File.Exists(fileName))
            {
                WriteImage(context, fileName);
            }
            else
            {
                fileName = Path.Combine(AttachmentPath.GetPath(LoginUser.Anonymous, organizationID, AttachmentPath.Folder.Images, 3), path);
                if (File.Exists(fileName))
                {
                    WriteImage(context, fileName);
                }
            }
        }
Esempio n. 8
0
        public static string GetCacheFileName4(int organizationParentId, int userId, int size, string type, out bool isIndexPage)
        {
            string cachePath = Path.Combine(AttachmentPath.GetImageCachePath(LoginUser.Anonymous), "Avatars\\" + organizationParentId.ToString() + "\\Contacts\\");

            isIndexPage = !string.IsNullOrEmpty(type) && type.ToLower() == "index";

            if (!Directory.Exists(cachePath))
            {
                Directory.CreateDirectory(cachePath);
            }

            string cacheFileName = Path.Combine(cachePath, string.Format("{0}-{1}{2}.jpg", userId.ToString(), size.ToString(), string.IsNullOrEmpty(type) ? "" : "-" + type));

            return(cacheFileName);
        }
Esempio n. 9
0
        public static string GetChacheFileName3(int organizationID, int logoOrganizationId, int size, string type, out bool isIndexPage)
        {
            string cachePath = Path.Combine(AttachmentPath.GetImageCachePath(LoginUser.Anonymous), "CompanyLogo\\" + organizationID.ToString());

            isIndexPage = !string.IsNullOrEmpty(type) && type.ToLower() == "index";

            if (!Directory.Exists(cachePath))
            {
                Directory.CreateDirectory(cachePath);
            }

            string cacheFileName = Path.Combine(cachePath, string.Format("{0}-{1}{2}.jpg", logoOrganizationId.ToString(), size.ToString(), string.IsNullOrEmpty(type) ? "" : "-" + type));

            return(cacheFileName);
        }
        public static string CreateAttachment(RestCommand command, int ticketIDOrNumber, int actionID)
        {
            TicketsViewItem ticket = TicketsView.GetTicketsViewItemByIdOrNumber(command.LoginUser, ticketIDOrNumber);

            if (ticket.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }

            string path = AttachmentPath.GetPath(command.LoginUser, command.Organization.OrganizationID, AttachmentPath.Folder.Actions, 3);

            path = Path.Combine(path, actionID.ToString());
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            HttpFileCollection files = command.Context.Request.Files;

            if (files.Count > 0)
            {
                if (files[0].ContentLength > 0)
                {
                    string fileName = RemoveSpecialCharacters(DataUtils.VerifyUniqueUrlFileName(path, Path.GetFileName(files[0].FileName)));

                    files[0].SaveAs(Path.Combine(path, fileName));

                    Attachment attachment = (new Attachments(command.LoginUser)).AddNewAttachment();
                    attachment.RefType        = AttachmentProxy.References.Actions;
                    attachment.RefID          = (int)actionID;
                    attachment.OrganizationID = command.Organization.OrganizationID;
                    attachment.FileName       = fileName;
                    attachment.Path           = Path.Combine(path, fileName);
                    attachment.FileType       = files[0].ContentType;
                    attachment.FileSize       = files[0].ContentLength;
                    attachment.FilePathID     = 3;
                    attachment.Collection.Save();
                    return(attachment.Collection.GetXml("Attachments", "Attachment", true, command.Filters));
                }
                else
                {
                    throw new RestException(HttpStatusCode.BadRequest, "The file to attach is empty.");
                }
            }
            else
            {
                throw new RestException(HttpStatusCode.BadRequest, "No file to attach.");
            }
        }
        public static string CreateAttachmentDirectory(LoginUser loginUser, int parentOrganizationID, AttachmentProxy.References refType, int refID)
        {
            // hub save only saves two types of attachments on this code path
            AttachmentPath.Folder folder = AttachmentPath.Folder.CustomerHubLogo;
            if (refType == AttachmentProxy.References.Actions)
            {
                folder = AttachmentPath.Folder.Actions;
            }

            string path = AttachmentPath.GetPath(loginUser, parentOrganizationID, folder);

            path = Path.Combine(path, refID.ToString());
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            return(path);
        }
Esempio n. 12
0
        private void StartUpload(FileInfo file)
        {
            _uploadedFile = file;
            _fileStream   = _uploadedFile.OpenRead();
            _dataLength   = _fileStream.Length;
            var pathofAttachment      = AttachmentPath.Split('/').LastOrDefault();
            var dataToSend            = _dataLength - _dataSent;
            var isLastChunk           = dataToSend <= ChunkSize;
            var isFirstChunk          = _dataSent == 0;
            var httpHandlerUrlBuilder = new UriBuilder(string.Format("{0}/FileUpload.ashx", _baseUri));

            httpHandlerUrlBuilder.Query = string.Format("{4}file={0}&offset={1}&last={2}&first={3}&Folder={5}",
                                                        pathofAttachment, _dataSent, isLastChunk, isFirstChunk,
                                                        string.IsNullOrEmpty(httpHandlerUrlBuilder.Query) ? "" : httpHandlerUrlBuilder.Query.Remove(0, 1) + "&", FolderPath);

            var webRequest = (HttpWebRequest)WebRequest.Create(httpHandlerUrlBuilder.Uri);

            webRequest.Method = "POST";
            webRequest.BeginGetRequestStream(WriteToStreamCallback, webRequest);
        }
Esempio n. 13
0
        public static string OrignalFileName(int organizationID, int userID)
        {
            string originalFileName;

            {
                Attachments attachments = new Attachments(LoginUser.Anonymous);
                attachments.LoadByReference(ReferenceType.UserPhoto, userID);
                StringBuilder path = new StringBuilder();
                if (attachments.Count > 0)
                {
                    path.Append(AttachmentPath.GetPath(LoginUser.Anonymous, organizationID, AttachmentPath.Folder.ProfileImages, (int)attachments[0].FilePathID));
                }
                else
                {
                    path.Append(AttachmentPath.GetPath(LoginUser.Anonymous, organizationID, AttachmentPath.Folder.ProfileImages));
                }
                originalFileName = AttachmentPath.GetImageFileName(path.ToString(), userID.ToString() + "avatar");
            }

            return(originalFileName);
        }
Esempio n. 14
0
        public static void ProcessChat(HttpContext context, string command, int organizationID)
        {
            System.Web.HttpBrowserCapabilities browser = context.Request.Browser;
            if (browser.Browser != "IE")
            {
                context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            }

            if (command == "image")
            {
                bool   isAvailable = ChatRequests.IsOperatorAvailable(LoginUser.Anonymous, organizationID);
                string fileName    = isAvailable ? "chat_available" : "chat_unavailable";
                fileName = AttachmentPath.FindImageFileName(LoginUser.Anonymous, organizationID, AttachmentPath.Folder.ChatImages, fileName);
                WriteImage(context, fileName);
            }
            else if (command == "logo")
            {
                string fileName = AttachmentPath.FindImageFileName(LoginUser.Anonymous, organizationID, AttachmentPath.Folder.ChatImages, "chat_logo");
                WriteImage(context, fileName);
            }
        }