public static string get_personal_image_address(Guid?applicationId,
                                                        Guid?userId, bool networkAddress = false, bool highQuality = false)
        {
            if (RaaiVanSettings.SAASBasedMultiTenancy)
            {
                applicationId = null;
            }

            if (!userId.HasValue || userId == Guid.Empty)
            {
                string addr = PublicConsts.DefaultProfileImageURL;

                return(highQuality ? string.Empty :
                       (networkAddress ? addr.Replace("../..", RaaiVanSettings.RaaiVanURL(applicationId)) : addr));
            }

            FolderNames folderName = highQuality ? FolderNames.HighQualityProfileImage : FolderNames.ProfileImages;

            DocFileInfo fi = new DocFileInfo()
            {
                FileID     = userId,
                Extension  = "jpg",
                FolderName = folderName
            };

            string address = !fi.exists(applicationId) ?
                             (highQuality ? string.Empty : PublicConsts.DefaultProfileImageURL) : fi.url(applicationId);

            return(networkAddress ? address.Replace("../..", RaaiVanSettings.RaaiVanURL(applicationId)) : address);
        }
예제 #2
0
        public TextExtractionResult Extract(Guid applicationId, DocFileInfo file, ref bool succeed, ref string errorText)
        {
            try
            {
                AutoDetectParser parser       = new AutoDetectParser();
                Metadata         metadata     = new Metadata();
                ParseContext     parseContext = new ParseContext();
                Class            parserClass  = parser.GetType();
                parseContext.set(parserClass, parser);

                byte[] fileContent = file.toByteArray(applicationId);

                using (InputStream inputStream = TikaInputStream.get(fileContent, metadata))
                {
                    parser.parse(inputStream, getTransformerHandler(), metadata, parseContext);
                    inputStream.close();
                }

                return(assembleExtractionResult(_outputWriter.toString(), metadata));
            }
            catch (Exception ex)
            {
                errorText = ex.StackTrace.ToString();
                succeed   = false;
                return(null);
            }
        }
        public static string get_application_icon_url(Guid?applicationId, bool highQuality = false, bool networkAddress = false)
        {
            FolderNames folderName = highQuality ? FolderNames.HighQualityApplicationIcon : FolderNames.ApplicationIcons;

            if (!applicationId.HasValue || applicationId == Guid.Empty)
            {
                string addr = RaaiVanSettings.LogoMiniURL;

                return(highQuality ? string.Empty :
                       (networkAddress ? addr.Replace("../..", RaaiVanSettings.RaaiVanURL(applicationId)) : addr));
            }

            DocFileInfo fi = new DocFileInfo()
            {
                FileID     = applicationId,
                OwnerID    = applicationId,
                Extension  = "jpg",
                FolderName = folderName
            };

            string retUrl = fi.exists(applicationId) ? fi.url(applicationId) : string.Empty;

            if (string.IsNullOrEmpty(retUrl) && !highQuality)
            {
                retUrl = RaaiVanSettings.LogoMiniURL;
            }

            return(networkAddress ? retUrl.Replace("../..", RaaiVanSettings.RaaiVanURL(applicationId)) : retUrl);
        }
        public static string get_cover_photo_url(Guid?applicationId,
                                                 Guid?ownerId, bool networkAddress = false, bool highQuality = false)
        {
            if (RaaiVanSettings.SAASBasedMultiTenancy)
            {
                applicationId = null;
            }

            if (!ownerId.HasValue || ownerId == Guid.Empty)
            {
                string addr = PublicConsts.DefaultCoverPhotoURL;

                return(highQuality ? string.Empty :
                       (networkAddress ? addr.Replace("../..", RaaiVanSettings.RaaiVanURL(applicationId)) : addr));
            }

            FolderNames folderName = highQuality ? FolderNames.HighQualityCoverPhoto : FolderNames.CoverPhoto;

            DocFileInfo fi = new DocFileInfo()
            {
                FileID     = ownerId,
                OwnerID    = ownerId,
                Extension  = "jpg",
                FolderName = folderName
            };

            string retUrl = fi.exists(applicationId) ? fi.url(applicationId) : string.Empty;

            return(networkAddress ? retUrl.Replace("../..", RaaiVanSettings.RaaiVanURL(applicationId)) : retUrl);
        }
예제 #5
0
        public static bool create_icon(Guid?applicationId, Guid iconId, IconType iconType,
                                       byte[] fileContent, ref string errorMessage, ref IconMeta meta)
        {
            int width = 100, height = 100, highQualityWidth = 600, highQualityHeight = 600;

            FolderNames imageFolder            = FolderNames.ProfileImages,
                        highQualityImageFolder = FolderNames.HighQualityProfileImage;

            bool isValid                       = DocumentUtilities.get_icon_parameters(applicationId, iconType, ref width, ref height,
                                                                                       ref highQualityWidth, ref highQualityHeight, ref imageFolder, ref highQualityImageFolder);

            if (!isValid)
            {
                return(false);
            }

            DocFileInfo highQualityFile = new DocFileInfo()
            {
                FileID = iconId, Extension = "jpg", FolderName = highQualityImageFolder
            };
            DocFileInfo file = new DocFileInfo()
            {
                FileID = iconId, Extension = "jpg", FolderName = imageFolder
            };

            byte[] hqContent = new byte[0];

            bool succeed = RVGraphics.make_thumbnail(applicationId,
                                                     fileContent, highQualityFile, ref hqContent, highQualityWidth, highQualityHeight,
                                                     width, height, ref errorMessage, highQualityFile.Extension, dontStore: false);

            return(succeed && hqContent != null && hqContent.Length > 0 &&
                   RVGraphics.extract_thumbnail(applicationId, highQualityFile, hqContent,
                                                file, -1, -1, -1, -1, width, height, ref errorMessage, ref meta));
        }
        public static string get_icon_url(Guid applicationId, Guid ownerId,
                                          DefaultIconTypes defaultIcon = DefaultIconTypes.Node, Guid?alternateOwnerId = null, bool networkAddress = false)
        {
            if (ownerId == Guid.Empty)
            {
                return(string.Empty);
            }

            DocFileInfo fi = new DocFileInfo()
            {
                FileID     = ownerId,
                OwnerID    = ownerId,
                Extension  = "jpg",
                FolderName = FolderNames.Icons
            };

            string retUrl = fi.exists(applicationId) ? fi.url(applicationId) : string.Empty;

            if (string.IsNullOrEmpty(retUrl) && alternateOwnerId.HasValue)
            {
                fi.FileID = alternateOwnerId;
                retUrl    = fi.exists(applicationId) ? fi.url(applicationId) : string.Empty;
            }

            if (string.IsNullOrEmpty(retUrl) && defaultIcon != DefaultIconTypes.None)
            {
                retUrl = get_icon_url(applicationId, defaultIcon);
            }

            return(networkAddress ? retUrl.Replace("../..", RaaiVanSettings.RaaiVanURL(applicationId)) : retUrl);
        }
예제 #7
0
        public static string ExtractFileContent(Guid applicationId, DocFileInfo file, ref string errorText)
        {
            bool                 succeed       = true;
            TextExtractor        textExtractor = new TextExtractor();
            TextExtractionResult result        = textExtractor.Extract(applicationId, file, ref succeed, ref errorText);

            if (!succeed)
            {
                return(string.Empty);
            }

            if (result.ContentType == "application/pdf")
            {
                string text = result.Text.ToString();
                text = text.Replace(')', ' ');
                text = text.Replace('(', ' ');
                text = text.Replace('.', ' ');
                text = text.Replace(',', ' ');
                text = text.Replace('?', ' ');
                text = text.Replace('\n', ' ');
                text = text.Replace('\r', ' ');
                string[] words = text.ToString().Split(' ');
                text = string.Empty;
                for (int i = 0; i < words.Length; i++)
                {
                    if (words[i].Length > 1)
                    {
                        if ((words[i][0] >= 'A' && words[i][0] <= 'Z') || (words[i][0] >= 'a' && words[i][0] <= 'z') ||
                            (words[i][0] >= '0' && words[i][0] <= '9'))
                        {
                            char[] cArray = words[i].ToCharArray();
                            Array.Reverse(cArray);
                            text += (new string(cArray) + " ");
                        }
                        else
                        {
                            text += (words[i] + " ");
                        }
                    }
                    else
                    {
                        text += (words[i] + " ");
                    }
                }

                return(text.Trim());
            }
            else
            {
                return(result.Text.Trim());
            }
        }
예제 #8
0
        public static bool extract_thumbnail(Guid?applicationId, DocFileInfo sourceFile, byte[] sourceContent,
                                             DocFileInfo destFile, int x, int y, int width, int height, int thumbnailWidth, int thumbnailHeight,
                                             ref string message, ref IconMeta meta)
        {
            try
            {
                if (sourceFile == null || sourceContent == null || sourceContent.Length == 0)
                {
                    return(false);
                }

                destFile.Extension = "jpg";

                if (!string.IsNullOrEmpty(sourceFile.Extension) && sourceFile.Extension != "jpg")
                {
                    using (MemoryStream stream = new MemoryStream(sourceContent))
                        using (MemoryStream newSt = new MemoryStream())
                            using (Image img = Bitmap.FromStream(stream))
                            {
                                img.Save(newSt, ImageFormat.Jpeg);
                                img.Dispose();

                                //sourceFile.delete(applicationId);

                                sourceFile.Extension = "jpg";
                                sourceContent        = newSt.ToArray();

                                //sourceFile.store(applicationId, newSt.ToArray());
                            }
                }

                Image retImage = null;
                if (extract_thumbnail(applicationId, sourceFile, sourceContent, destFile, x, y, width, height,
                                      thumbnailWidth, thumbnailHeight, ref retImage, ref message, ref meta))
                {
                    using (MemoryStream st = new MemoryStream())
                    {
                        retImage.Save(st, ImageFormat.Jpeg);
                        retImage.Dispose();

                        destFile.store(applicationId, st.ToArray());
                    }
                }

                return(true);
            }
            catch
            {
                message = "{\"ErrorText\":\"" + Messages.OperationFailed.ToString() + "\"}";
                return(false);
            }
        }
        public static bool picture_exists(Guid applicationId, Guid pictureId)
        {
            if (pictureId == Guid.Empty)
            {
                return(false);
            }

            DocFileInfo fi = new DocFileInfo()
            {
                FileID     = pictureId,
                Extension  = "jpg",
                FolderName = FolderNames.Pictures
            };

            return(fi.exists(applicationId));
        }
예제 #10
0
        private static string _get_email_template(Guid?applicationId, string templateType)
        {
            if (RaaiVanSettings.SAASBasedMultiTenancy)
            {
                applicationId = null;
            }

            DocFileInfo fi = new DocFileInfo()
            {
                FileName   = templateType,
                Extension  = "txt",
                FolderName = FolderNames.EmailTemplates
            };

            return(fi.exists(applicationId) ? fi.get_text_content(applicationId) :
                   (applicationId.HasValue ? _get_email_template(null, templateType) : string.Empty));
        }
        public static bool icon_exists(Guid applicationId, Guid ownerId)
        {
            if (ownerId == Guid.Empty)
            {
                return(false);
            }

            DocFileInfo fi = new DocFileInfo()
            {
                FileID     = ownerId,
                OwnerID    = ownerId,
                Extension  = "jpg",
                FolderName = FolderNames.Icons
            };

            return(fi.exists(applicationId));
        }
        public static List <DocFileInfo> get_files_info(string strFiles)
        {
            List <DocFileInfo> retList = new List <DocFileInfo>();

            if (string.IsNullOrEmpty(strFiles))
            {
                return(retList);
            }

            Dictionary <string, object> dic = PublicMethods.fromJSON("{\"Items\":" + Base64.decode(strFiles) + "}");

            if (!dic.ContainsKey("Items"))
            {
                return(retList);
            }

            if (dic["Items"].GetType() == typeof(Dictionary <string, object>))
            {
                DocFileInfo fi = _get_file_info((Dictionary <string, object>)dic["Items"]);
                if (fi != null)
                {
                    retList.Add(fi);
                }
            }
            else if (dic["Items"].GetType() == typeof(ArrayList))
            {
                foreach (object obj in (ArrayList)dic["Items"])
                {
                    Dictionary <string, object> f = obj.GetType() == typeof(string) ? PublicMethods.fromJSON((string)obj) :
                                                    (obj.GetType() == typeof(Dictionary <string, object>) ? (Dictionary <string, object>)obj : null);

                    DocFileInfo fi = f == null ? null : _get_file_info(f);
                    if (fi != null)
                    {
                        retList.Add(fi);
                    }
                }
            }

            return(retList);
        }
        protected static DocFileInfo _get_file_info(Dictionary <string, object> dic)
        {
            if (dic == null)
            {
                return(null);
            }

            Guid?  fileId    = !dic.ContainsKey("FileID") ? null : PublicMethods.parse_guid(dic["FileID"].ToString());
            string extension = !dic.ContainsKey("Extension") ? null : PublicMethods.parse_string(dic["Extension"].ToString());
            string fileName  = !dic.ContainsKey("FileName") ? null : PublicMethods.parse_string(dic["FileName"].ToString());
            long?  size      = !dic.ContainsKey("Size") ? null : PublicMethods.parse_long(dic["Size"].ToString());
            Guid?  ownerId   = !dic.ContainsKey("OwnerID") ? null : PublicMethods.parse_guid(dic["OwnerID"].ToString());

            FileOwnerTypes ownerType = FileOwnerTypes.None;

            if (dic.ContainsKey("OwnerType"))
            {
                Enum.TryParse <FileOwnerTypes>(dic["OwnerType"].ToString(), true, out ownerType);
            }

            DocFileInfo fi = new DocFileInfo()
            {
                FileID    = fileId,
                FileName  = fileName,
                Extension = extension,
                Size      = size
            };

            if (ownerId.HasValue && ownerId != Guid.Empty)
            {
                fi.OwnerID = ownerId;
            }
            if (ownerType != FileOwnerTypes.None)
            {
                fi.OwnerType = ownerType;
            }

            return(!fileId.HasValue ? null : fi);
        }
        public static string get_icon_url(Guid applicationId, Guid ownerId, string extension,
                                          bool highQuality = false, bool networkAddress = false)
        {
            if (ownerId == Guid.Empty)
            {
                return(string.Empty);
            }

            FolderNames folderName = highQuality ? FolderNames.HighQualityIcon : FolderNames.Icons;

            DocFileInfo fi = new DocFileInfo()
            {
                FileID     = ownerId,
                OwnerID    = ownerId,
                Extension  = "jpg",
                FolderName = folderName
            };

            string retUrl = fi.exists(applicationId) ? fi.url(applicationId) :
                            (highQuality ? string.Empty : get_icon_url(applicationId, DefaultIconTypes.Extension, extension));

            return(networkAddress ? retUrl.Replace("../..", RaaiVanSettings.RaaiVanURL(applicationId)) : retUrl);
        }
예제 #15
0
        public static bool make_thumbnail(Guid?applicationId, byte[] sourceContent, DocFileInfo destFile, ref byte[] destContent,
                                          int width, int height, int minWidth, int minHeight, ref string errorMessage,
                                          string forceExtension = null, bool stretch = false, bool dontStore = false)
        {
            if (!string.IsNullOrEmpty(forceExtension))
            {
                destFile.Extension = forceExtension;
            }

            if (sourceContent == null || sourceContent.Length == 0)
            {
                return(false);
            }

            Image retImage = null;

            try
            {
                using (MemoryStream stream = new MemoryStream(sourceContent))
                    using (Image img = Bitmap.FromStream(stream))
                    {
                        bool result = make_thumbnail(img, width, height, minWidth, minHeight,
                                                     ref retImage, ref errorMessage, stretch);

                        if (img != null)
                        {
                            img.Dispose();
                        }

                        if (!result)
                        {
                            if (retImage != null)
                            {
                                retImage.Dispose();
                            }
                            if (img != null)
                            {
                                retImage.Dispose();
                            }

                            return(false);
                        }

                        using (MemoryStream ms = new MemoryStream())
                        {
                            retImage.Save(ms, ImageFormat.Jpeg);
                            retImage.Dispose();
                            img.Dispose();

                            destContent = ms.ToArray();
                            if (!dontStore)
                            {
                                destFile.store(applicationId, destContent);
                            }
                        }

                        return(true);
                    }
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        public static DocFileInfo decode_base64_file_content(Guid applicationId, Guid?ownerId,
                                                             string base64FileContent, FileOwnerTypes ownerType)
        {
            if (string.IsNullOrEmpty(base64FileContent))
            {
                return(null);
            }

            byte[] theData = null;

            try { theData = Convert.FromBase64String(base64FileContent); }
            catch { return(null); }

            int FIXED_HEADER = 16;

            DocFileInfo ret = new DocFileInfo()
            {
                FileID     = Guid.NewGuid(),
                OwnerID    = ownerId,
                OwnerType  = ownerType,
                FolderName = FolderNames.TemporaryFiles
            };

            try
            {
                using (MemoryStream ms = new MemoryStream(theData))
                {
                    using (BinaryReader theReader = new BinaryReader(ms))
                    {
                        //Position the reader to get the file size.
                        byte[] headerData = new byte[FIXED_HEADER];
                        headerData = theReader.ReadBytes(headerData.Length);

                        ret.Size = (int)theReader.ReadUInt32();
                        int fileNameLength = (int)theReader.ReadUInt32() * 2;

                        if (fileNameLength <= 0 || fileNameLength > 255)
                        {
                            throw new Exception("what the fuzz!!");
                        }

                        byte[] fileNameBytes = theReader.ReadBytes(fileNameLength);
                        //InfoPath uses UTF8 encoding.
                        Encoding enc          = Encoding.Unicode;
                        string   fullFileName = enc.GetString(fileNameBytes, 0, fileNameLength - 2);

                        int dotIndex = fullFileName.LastIndexOf(".");
                        if (dotIndex > 0 && dotIndex < (fullFileName.Length - 1))
                        {
                            ret.Extension = fullFileName.Substring(dotIndex + 1);
                        }

                        ret.FileName = string.IsNullOrEmpty(ret.Extension) ?
                                       fullFileName : fullFileName.Substring(0, dotIndex);

                        byte[] fileBytes = theReader.ReadBytes((int)ret.Size.Value);

                        if (!ret.store(applicationId, fileBytes))
                        {
                            return(null);
                        }
                    }
                }

                return(ret);
            }
            catch (Exception ex)
            {
                //maybe the file is a base64 image!!
                try
                {
                    Image img = PublicMethods.image_from_byte_array(theData);
                    if (img == null)
                    {
                        return(null);
                    }
                    byte[] imageBytes = PublicMethods.image_to_byte_array(img, System.Drawing.Imaging.ImageFormat.Jpeg);
                    if (imageBytes == null || imageBytes.Length == 0)
                    {
                        return(null);
                    }

                    ret.Size      = imageBytes.Length;
                    ret.FileName  = "img";
                    ret.Extension = "jpg";

                    if (!ret.store(applicationId, imageBytes))
                    {
                        return(null);
                    }

                    return(ret);
                }
                catch { return(null); }
            }
        }
예제 #17
0
        public static bool extract_thumbnail(Guid?applicationId, DocFileInfo sourceFile, byte[] sourceContent,
                                             DocFileInfo destFile, int x, int y, int width, int height, int thumbnailWidth, int thumbnailHeight,
                                             ref Image retImage, ref string message, ref IconMeta meta)
        {
            try
            {
                if (sourceContent == null || sourceContent.Length == 0)
                {
                    return(false);
                }

                bool result = true;

                using (MemoryStream stream = new MemoryStream(sourceContent))
                    using (Bitmap image = Bitmap.FromStream(stream) as Bitmap)
                    {
                        if (image.Width < thumbnailWidth || image.Height < thumbnailHeight)
                        {
                            message = "{\"ErrorText\":\"" + Messages.ImageSizeIsNotValid.ToString() + "\"}";
                            image.Dispose();
                            return(false);
                        }

                        if (x < 0 || y < 0 || width <= 0 || height <= 0)
                        {
                            double aspectRatio = (double)thumbnailWidth / (double)thumbnailHeight;
                            int    min         = ((double)image.Width / (double)thumbnailWidth) < ((double)image.Height / (double)thumbnailHeight) ?
                                                 image.Width : image.Height;

                            if (min == image.Width)
                            {
                                width  = image.Width;
                                height = (int)Math.Floor((double)width / aspectRatio);
                            }
                            else
                            {
                                height = image.Height;
                                width  = (int)Math.Floor((double)height * aspectRatio);
                            }

                            x = (image.Width - width) / 2;
                            y = (image.Height - height) / 2;
                        }

                        meta = new IconMeta()
                        {
                            X               = x,
                            Y               = y,
                            Width           = width,
                            Height          = height,
                            Icon            = destFile,
                            HighQualityIcon = sourceFile
                        };

                        message = meta.toJson(applicationId);

                        Rectangle rect = new Rectangle(x, y, width, height);

                        using (Bitmap target = new Bitmap(rect.Width, rect.Height))
                        {
                            Graphics g = Graphics.FromImage(target);
                            g.DrawImage(image, new Rectangle(0, 0, target.Width, target.Height), rect, GraphicsUnit.Pixel);

                            result = make_thumbnail(target as Image,
                                                    thumbnailWidth, thumbnailHeight, 0, 0, ref retImage, ref message, true);
                        }

                        if (!result)
                        {
                            message = "{\"ErrorText\":\"" + Messages.OperationFailed + "\"}";
                        }
                        return(result);
                    }
            }
            catch { message = "{\"ErrorText\":\"" + Messages.OperationFailed + "\"}"; return(false); }
        }