示例#1
0
    public override bool Save()
    {
        try
        {
            string path = TeamSupport.Data.Quarantine.WebAppQ.GetAttachmentPath8(UserSession.LoginUser);
            RemoveCachedImages(UserSession.LoginUser.OrganizationID, _userID);

            if (img1.Value != "")
            {
                img1.Value = img1.Value.Replace(".ashx", "");
                string source = TeamSupport.Data.Quarantine.WebAppQ.GetAttachmentPath9(UserSession.LoginUser, Session["WorkingImage"].ToString());
                string dest   = path + '\\' + _userID + "avatar.jpg";
                try
                {
                    ImageBuilder.Current.Build(source, dest, new ResizeSettings(img1.Value));
                }
                catch (Exception ex2)
                {
                    ExceptionLogs.LogException(UserSession.LoginUser, ex2, "ImageBuilder", string.Format("source:{0},  dest:{1}", source, dest));
                    throw;
                }

                File.Delete(source);

                AttachmentProxy proxy = TeamSupport.ModelAPI.Model_API.ReadRefTypeProxyByRefID <UserPhotoAttachmentProxy>(_userID);
                if (proxy != null)
                {
                    proxy.FileName   = _userID + "avatar.jpg";
                    proxy.Path       = path + '\\' + _userID + "avatar.jpg";
                    proxy.FilePathID = 3;
                    TeamSupport.ModelAPI.Model_API.Update(proxy);
                }
                else
                {
                    proxy                = AttachmentProxy.ClassFactory(AttachmentProxy.References.UserPhoto);
                    proxy.RefID          = _userID;
                    proxy.OrganizationID = _organizationID;
                    proxy.FileName       = _userID + "avatar.jpg";
                    proxy.Path           = path + '\\' + _userID + "avatar.jpg";
                    proxy.FilePathID     = 3;
                    proxy.FileType       = "image/jpeg";
                    proxy.FileSize       = -1;
                    TeamSupport.ModelAPI.Model_API.Create(proxy);
                }
            }
        }
        catch (Exception ex)
        {
            ExceptionLogs.LogException(UserSession.LoginUser, ex, "Save Avatar");
            throw;
        }
        return(true);
    }
示例#2
0
        public static AttachmentProxy CreateAttachment(int organizationID, AttachmentProxy.References refType, int refID, string path)
        {
            ActionAttachmentProxy attachmentProxy = (ActionAttachmentProxy)AttachmentProxy.ClassFactory(AttachmentProxy.References.Actions);

            attachmentProxy.OrganizationID = organizationID;
            attachmentProxy.ActionID       = refID;
            attachmentProxy.FileName       = "stuff";
            attachmentProxy.FilePathID     = 3;
            attachmentProxy.FileSize       = 256;
            attachmentProxy.FileType       = "text something...";
            attachmentProxy.Path           = path; // IAttachmentDestination
            return(attachmentProxy);
        }
示例#3
0
        /// <summary> Create attachment files </summary>
        public static List <AttachmentProxy> CreateAttachments(HttpContext context, out string _ratingImage)
        {
            List <AttachmentProxy> result = null;

            try
            {
                GetPathMap(context, out PathMap pathMap, out int refID, out _ratingImage);

                using (ConnectionContext connection = new ConnectionContext())
                {
                    // valid ID to add attachment
                    IAttachmentDestination model = ClassFactory(connection, pathMap._refType, refID);
                    HttpFileCollection     files = context.Request.Files;
                    result = new List <AttachmentProxy>();
                    for (int i = 0; i < files.Count; i++)
                    {
                        if (files[i].ContentLength <= 0)
                        {
                            continue;
                        }

                        AttachmentFile  attachmentFile = new AttachmentFile(model, files[i]);            // create the file
                        AttachmentProxy proxy          = AttachmentProxy.ClassFactory(pathMap._refType); // construct the proxy
                        proxy.RefID = refID;
                        InitializeProxy(context, connection, attachmentFile, proxy);
                        Data_API.Create(model as IDNode, proxy);  // save proxy to DB
                        result.Add(proxy);
                    }
                }
            }
            catch (Exception ex)
            {
                _ratingImage = null;
                // TODO - tell user we failed
                Data_API.LogMessage(ActionLogType.Insert, ReferenceType.None, 0, "choke", ex);
            }
            return(result);
        }
示例#4
0
        public static void CreateAttachment(string savePath, int organizationId, AttachmentProxy.References refType, int userID, System.Net.HttpWebResponse httpWebResponse)
        {
            try
            {
                using (ConnectionContext connection = new ConnectionContext())
                {
                    AttachmentProxy attachment = AttachmentProxy.ClassFactory(refType);
                    attachment.RefID          = userID;
                    attachment.OrganizationID = organizationId;
                    attachment.FileName       = Path.GetFileName(savePath);
                    attachment.Path           = savePath;
                    attachment.FileType       = string.IsNullOrEmpty(httpWebResponse.ContentType) ? "application/octet-stream" : httpWebResponse.ContentType;
                    attachment.FileSize       = httpWebResponse.ContentLength;

                    IAttachmentDestination model = ClassFactory(connection, attachment);
                    Data_API.Create(model as IDNode, attachment);
                }
            }
            catch (Exception ex)
            {
                // TODO - tell user we failed
                Data_API.LogMessage(ActionLogType.Insert, (ReferenceType)refType, 0, "choke", ex);
            }
        }