예제 #1
0
        private void AddAttachment(string path)
        {
            if (string.IsNullOrEmpty(path) || !File.Exists(path))
            {
                return;
            }

            int lastRight = attachmentsPanel.Controls.OfType <FileBox>().OrderByDescending(x => x.Left).FirstOrDefault()?.Right ?? 2;

            attachmentsLabel.Visible            = false;
            attachmentsPanel.AutoScrollPosition = new Point(0, 0);
            FileBox fileBox = new FileBox
            {
                Path             = path,
                Font             = attachmentsLabel.Font,
                AutoSize         = true,
                IconSize         = new Size(32, 32),
                Location         = new Point(lastRight + 3, 5),
                ContextMenuStrip = attachmentContextMenu
            };

            fileBox.MouseClick += Attachments_MouseClick;
            attachmentsPanel.Controls.Add(fileBox);
        }
예제 #2
0
 void CreateTextBox()
 {
     txtFile = new FileBox(this);
     SetControl(txtFile);
 }
예제 #3
0
        public async Task <HttpResponseMessage> PostFile()
        {
            // Check if the request contains multipart/form-data.
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            string temp_root = FileBox.GetWebAppRoot() + "temp\\" + SessionData.client_id + "\\";
            string temp_url  = "//temp//" + SessionData.client_id + "//";

            if (!System.IO.Directory.Exists(temp_root))
            {
                System.IO.Directory.CreateDirectory(temp_root);
            }

            MultipartFormDataStreamProvider provider = new MultipartFormDataStreamProvider(temp_root);
            DynamicDictionary data = new DynamicDictionary();
            ResponseModel     resp = new ResponseModel(false, data);

            try
            {
                StringBuilder sb = new StringBuilder(); // Holds the response body
                // Read the form data and return an async task.
                var bodyparts = await Request.Content.ReadAsMultipartAsync(provider);

                //rename the file to proper-name

                // This illustrates how to get the form data.
                foreach (var key in provider.FormData.AllKeys)
                {
                    foreach (var val in provider.FormData.GetValues(key))
                    {
                        data.Add(key, val);
                    }
                }

                //for logo upload
                string logo_name = data.GetValueAsString("logo_name");
                string extension = string.Empty;

                if (logo_name != "")
                {
                    #region for logo upload
                    string basePath = FileBox.GetWebAppRoot() + "filebox\\CommonInput\\logo\\" + SessionData.client_id + "\\";
                    if (!System.IO.Directory.Exists(basePath))
                    {
                        System.IO.Directory.CreateDirectory(basePath);
                    }

                    //check if file already exist and delete if exist
                    string[] Logo_path = Directory.GetFiles(basePath, logo_name + ".*");
                    string[] filepath  = Directory.GetFiles(basePath, "*.*");
                    if (Logo_path.Length > 0)
                    {
                        System.IO.File.Delete(Logo_path[0]);
                    }
                    //check if file already exist and delete if exist

                    foreach (var file in provider.FileData)
                    {
                        string[] arr = file.Headers.ContentDisposition.FileName.Trim('"').Split('.');
                        if (arr.Length >= 1)
                        {
                            extension = "." + arr[arr.Length - 1];
                        }

                        System.IO.File.Move(file.LocalFileName, basePath + logo_name + extension);
                        data.Add("temp_file_url", basePath + logo_name + extension);
                    }
                    #endregion
                }
                else
                {
                    string url = HttpContext.Current.Request.Url.ToString().Substring(0, HttpContext.Current.Request.Url.ToString().IndexOf("/api/"));
                    // This illustrates how to get the file names for uploaded files.
                    string new_file_name = "";  // System.DateTime.Today.ToString("yyyymmddhhmmss") + "_" + getRandomID() + "_" + SessionData.user_id;
                    foreach (var file in provider.FileData)
                    {
                        FileInfo fileInfo = new FileInfo(file.LocalFileName);
                        string[] arr      = file.Headers.ContentDisposition.FileName.Trim('"').Split('.');

                        if (arr.Length >= 1)
                        {
                            extension = "." + arr[arr.Length - 1];
                        }

                        new_file_name = fileInfo.Name;

                        if (data.ContainsKey("temp_file_path"))
                        {
                            data.SetValue("temp_file_path", temp_root + new_file_name + extension);
                        }
                        else
                        {
                            data.Add("temp_file_path", temp_root + new_file_name + extension);
                        }

                        if (data.ContainsKey("file_name"))
                        {
                            data.SetValue("file_name", new_file_name + extension);
                        }
                        else
                        {
                            data.Add("file_name", new_file_name + extension);
                        }

                        //mime_type_id
                        if (data.ContainsKey("mime_type_id"))
                        {
                            data.SetValue("mime_type_id", extension);
                        }
                        else
                        {
                            data.Add("mime_type_id", extension);
                        }

                        if (data.ContainsKey("file_size_bytes"))
                        {
                            data.SetValue("file_size_bytes", fileInfo.Length);
                        }
                        else
                        {
                            data.Add("file_size_bytes", fileInfo.Length);
                        }

                        data.Add("temp_file_url", url + temp_url + new_file_name + extension);
                        data.Add("temp_file_url", temp_url + new_file_name + extension);

                        System.IO.File.Move(file.LocalFileName, temp_root + new_file_name + extension);
                    }
                }
                resp.success = true;
                resp.message = "File uploaded successfully";
                return(new HttpResponseMessage()
                {
                    Content = new StringContent(JsonConvert.SerializeObject(resp))
                });
            }
            catch (System.Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e));
            }
        }
예제 #4
0
        public override ResponseModel Update(int?id, DynamicDictionary item)
        {
            string        message = string.Empty;
            bool          success = false;
            object        data    = item;
            ResponseModel resp    = new ResponseModel();
            UserModel     Model   = new UserModel();

            LoadItemAfterSave = true;
            using (DbConnect con = new DbConnect())
            {
                con.DB.BeginTransaction();
                try
                {
                    string new_file_name  = item.GetValueAsString("new_file_name");
                    string user_file_name = item.GetValueAsString("userfilename");
                    string relative_path  = "temp/";
                    if (user_file_name == null)
                    {
                        if (new_file_name != null)
                        {
                            item.SetValue("photo_path", relative_path + new_file_name);
                        }
                    }
                    else
                    {
                        if (new_file_name != "")
                        {
                            item.SetValue("photo_path", relative_path + new_file_name);
                        }
                        else
                        {
                            item.SetValue("photo_path", "");
                            string filePath = FileBox.GetWebAppRoot();
                            if (System.IO.File.Exists(filePath + user_file_name)) //if file exists than delete.
                            {
                                System.IO.File.Delete(filePath + user_file_name);
                            }
                        }
                    }
                    if (SessionData.client_id == 1)
                    {
                        CheckClientID = false;
                    }

                    resp = base.Update(id, item);

                    #region User Profile Window
                    if (resp.success && item.GetValueAsString("userProfile") == "true")
                    {
                        string file_name = item.GetValueAsString("new_file_name");
                        string filePath  = FileBox.GetWebAppRoot() + "temp/";
                        int?   photo_id  = item.GetValueAsInt("photo_id");
                        if (file_name == "")
                        {
                            var photoPath = item.GetValueAsString("user_file_name");
                            if (photoPath == "")
                            {
                                return(null);
                            }
                            if (System.IO.File.Exists(filePath + new_file_name)) //if file exists than delete.
                            {
                                System.IO.File.Delete(filePath + new_file_name);
                            }

                            int?tax_photo_id = item.GetValueAsInt("photo_id");
                            item.SetValue("photo_path", "");
                            resp = base.Update(id, item);
                        }
                        else
                        {
                            if (photo_id == 0)
                            {
                                item.SetValue("photo_path", relative_path + new_file_name);
                            }
                            else
                            {
                                item.SetValue("photo_path", relative_path + new_file_name);
                            }
                            resp = base.Update(id, item);
                        }
                    }
                    #endregion
                    else
                    {
                    }
                    if (resp.success)
                    {
                        con.DB.CommitTransaction();
                        message = "Data added successfully.";
                        success = true;
                        if (resp.success)
                        {
                            DynamicDictionary respdata        = (DynamicDictionary)resp.data;
                            string            confirmpassword = respdata.GetValueAsString("confirmpassword");
                            if (item.GetValueAsString("userProfile") == "" || item.GetValueAsString("userProfile") == null)
                            {
                                if (confirmpassword == "" || confirmpassword == null)
                                {
                                    int user_id = (int)((DynamicDictionary)resp.data).GetValueAsInt("id");
                                    resp.data = user_id;
                                    return(resp);
                                }
                            }
                        }
                        return(resp);
                    }
                    else
                    {
                        con.DB.RollbackTransaction();

                        if (resp.validation_errors.GetCount() > 0)
                        {
                            message = string.Join(",", resp.error_code);
                        }
                        else
                        {
                            message = "Data add failed, please try again later.";
                        }
                    }
                }
                catch (Exception)
                {
                    con.DB.RollbackTransaction();
                    message = "Data add failed, Rollback Transaction.";
                }
            }
            return(new ResponseModel(success, item.GetValue("photo_id"), message));
        }
예제 #5
0
 public abstract Task <string?> MessageSendFile(string conversationId, FileBox file);
예제 #6
0
 public abstract Task ContactAvatar(string contactId, FileBox file);
예제 #7
0
 public async Task<IMessageAppService> Say(FileBox file)
 {
     var msgId = await _puppetService.MessageSendFile(RoomId, file);
     return await TryLoad(msgId);
 }
예제 #8
0
        public AddLayerWindow()
        {
            InitializeComponent();
            _vm = new AddLayerViewModel();

            _vm.SelectFileCommand = new RelayCommand(o =>
            {
                var dialog = new Microsoft.Win32.OpenFileDialog()
                {
                    Title       = "Choose file",
                    Filter      = "Supported Images|*.svg;*.jpg;*.jpeg;*.gif;*.png;*.bmp;*.tif",
                    Multiselect = false
                };

                var result = dialog.ShowDialog();

                if (result != null && result.Value)
                {
                    _vm.File = dialog.FileName;
                }
            });

            _vm.SelectMaskCommand = new RelayCommand(o =>
            {
                var dialog = new Microsoft.Win32.OpenFileDialog()
                {
                    Title       = "Choose mask",
                    Filter      = "Supported Images|*.svg;*.jpg;*.jpeg;*.gif;*.png;*.bmp;*.tif",
                    Multiselect = false
                };

                var result = dialog.ShowDialog();

                if (result != null && result.Value)
                {
                    _vm.Mask = dialog.FileName;
                }
            });

            _vm.MaskRadioButtonCommand = new RelayCommand(o =>
            {
                var param = o.ToString();
                switch (param)
                {
                case "None":
                    MaskBox.IsEnabled    = false;
                    MaskButton.IsEnabled = false;
                    _vm.MaskType         = AddLayerViewModel.MaskTypes.None;
                    if (LayerType.SelectedItem != null)
                    {
                        _vm.UpdatePreview((Layer.LayerType)LayerType.SelectedItem);
                    }
                    break;

                case "User":
                    MaskBox.IsEnabled    = true;
                    MaskButton.IsEnabled = true;
                    _vm.MaskType         = AddLayerViewModel.MaskTypes.User;
                    if (LayerType.SelectedItem != null)
                    {
                        _vm.UpdatePreview((Layer.LayerType)LayerType.SelectedItem);
                    }
                    break;

                case "Auto":
                    MaskBox.IsEnabled    = false;
                    MaskButton.IsEnabled = false;
                    _vm.MaskType         = AddLayerViewModel.MaskTypes.Autogenerated;
                    if (LayerType.SelectedItem != null)
                    {
                        _vm.UpdatePreview((Layer.LayerType)LayerType.SelectedItem);
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            });

            DataContext = _vm;
            _vm.MaskRadioButtonCommand.Execute("None");

            // Need to add these handlers manually since the TextBox already has handlers for some kinds of drag-and-drop data types.
            // https://msdn.microsoft.com/en-us/library/hh144798(v=vs.110).aspx
            FileBox.AddHandler(TextBox.DropEvent, new DragEventHandler(LayerFileBox_OnDrop), true);
            MaskBox.AddHandler(TextBox.DropEvent, new DragEventHandler(LayerMaskBox_OnDrop), true);
        }
예제 #9
0
 void CreateTextBox()
 {
     txtFile = new FileBox(this);
     SetControl(txtFile);
 }
예제 #10
0
        public Task <FileBox> Avatar(FileBox file)
        {
            var filebox = _puppetService.ContactAvatar(LoginWeiXinId, file);

            return(filebox);
        }
예제 #11
0
        public LangLoader()
        {
            var fb = new FileBox();

            DefaultFile = fb.WebAppRoot + @"lang\";
        }