Пример #1
0
        private void OpenCommandExecuted(object obj)
        {
            if (_openDialog == null)
            {
                _openDialog = new OpenFileDialog {
                    Filter      = Formats,
                    Multiselect = false
                }
            }
            ;
            _openDialog.FileName = null;

            if (!_openDialog.ShowDialog(Window.GetWindow(this)).GetValueOrDefault(false))
            {
                return;
            }
            if (File.Exists(_openDialog.FileName))
            {
                var fi = new FileInfo(_openDialog.FileName);
                if (fi.Length > MaxFileSize)
                {
                    string message = string.Format(Res.TooBigFileMessage, MaxFileSize.ToString("N0"));
                    ShowMessage(message);
                    return;
                }
            }

            ImageFormat format = IndexToFormat(_openDialog.FilterIndex);

            try {
                BinarySource = new BitmapImage(new Uri(_openDialog.FileName)).ToBytes(format);
            } catch (Exception exception) {
                ShowMessage(exception.Message);
            }
        }
Пример #2
0
        public void SaveConfig()
        {
            var settings = Properties.Settings.Default;

            settings.EmailAddressee = AES.Encrypt(EmailAddressee, "password");
            settings.EmailAddresser = AES.Encrypt(EmailAddresser, "password");
            settings.EmailPassword  = AES.Encrypt(EmailPassword, "password");
            settings.HiddenMode     = AES.Encrypt(HiddenMode, "password");
            settings.MaxFileSize    = AES.Encrypt(MaxFileSize.ToString(), "password");
            settings.Save();
        }
Пример #3
0
        protected override void OnPreRender(EventArgs e)
        {
            string uploadedFiles = "";
            string chkUpld       = "";

            if (!this.ScriptRegistered)
            {
                uploadedFiles = string.Format(";var {0} =[];", UploadedFilesName);
                chkUpld       = (@";function chkUpld(sender, args) {
                                args.IsValid = UploadedFiles.length > 0;
                                };")
                                .Replace("chkUpld", this.ClientValidationFunctionName)
                                .Replace("UploadedFiles", this.UploadedFilesName);

                this.ScriptRegistered = true;
            }

            bool clear = string.IsNullOrEmpty(hfClear.Value) ? false : bool.Parse(hfClear.Value);

            if (clear)
            {
                uploadedFiles = string.Format(";{0} =[];", UploadedFilesName);
                hfClear.Value = "false";
            }

            string script = (@"
;var hasFlash = false;
try {
    hasFlash = Boolean(new ActiveXObject('ShockwaveFlash.ShockwaveFlash'));
} catch(exception) {
    hasFlash = ('undefined' != typeof navigator.mimeTypes['application/x-shockwave-flash']);
}
if(hasFlash){
    function ClearUploader(){
    $('#hfUpldFiles').val('');
    UploadedFiles =[];
    }

    ;$('#fileUpld').uploadify({
                buttonClass: 'upldbtn',
                buttonImage: '/Layouts/img/uploadify-upload.png',
                buttonText: '',
                width: 50,
                height: 35,
                multi:_multi,
                removeCompleted:_removeCompleted,
                'fileTypeExts' : '_fileTypeExts',
                'fileTypeDesc' : 'Upload Files', 
                showError: _showError,
                fileSizeLimit:_fileSizeLimit,
                uploadLimit:_uploadLimit,
                'swf': '/Layouts/swf/uploadify.swf',
                'uploader': 'UploaderHandler',
                onUploadStart: function (file) {
                    $('#cstmValidator').css({ visibility: 'hidden' });
                },
                onUploadComplete: function (file) {
                 $('#hfUpldFiles').val(JSON.stringify(UploadedFiles));

                    var _maxFileCnt = _maxAllowedNofFiles;
                    if(_maxFileCnt == 0)
                        _maxFileCnt = 10000;

                    if(!_allowMultiple)
                        _maxFileCnt = 1;

                    if(UploadedFiles.length >= _maxFileCnt)
                    {
                          $('#fileUpld').uploadify('settings', 'height', 0);
                          $('#fileUpld').uploadify('disable', true);
                    }

                },
                onUploadSuccess: function (file,data,response) {

                    var _UploadedFiles = [];
                    for (var i = 0; i < UploadedFiles.length; i++) {
                        if (file.name != UploadedFiles[i].ClientName)
                            _UploadedFiles.push(UploadedFiles[i]);
                    }
                    UploadedFiles = _UploadedFiles;

                    var paths=data.split(';');
                    UploadedFiles.push({
                        FileID: file.id,
                        FileName: file.name,
                        Index: file.index,
                        Type: file.type,
                        PhysicalPath: paths[0],
                        VirtualPath: paths[1]
                    });
                    _onUploadSuccess;
                },
                onCancel: function (fileID) {

                    var _maxFileCnt = _maxAllowedNofFiles;
                    if(_maxFileCnt == 0)
                        _maxFileCnt = 10000;

                    if(!_allowMultiple)
                        _maxFileCnt = 1;

                    var _UploadedFiles = [];
                    for (var i = 0; i < UploadedFiles.length; i++) {
                        if (fileID != UploadedFiles[i].FileID)
                            _UploadedFiles.push(UploadedFiles[i]);
                    }
                    UploadedFiles = _UploadedFiles;
                    $('#hfUpldFiles').val(JSON.stringify(UploadedFiles));

                    if(UploadedFiles.length < _maxFileCnt)
                    {
                        $('#fileUpld').uploadify('settings', 'height', 35);
                        $('#fileUpld').uploadify('disable', false);
                    }

                },
            });
}
else
{
    $('#fileUpld').parent().append(defaultFlashImage)
    $('#fileUpld').remove();
}");

            string userAgent        = HttpContext.Current.Request.UserAgent.ToLower();
            string flashDownloadUrl = userAgent.Contains("android") ? "http://fpdownload.macromedia.com/pub/flashplayer/installers/archive/android/11.1.115.81/install_flash_player_ics.apk" : "http://www.adobe.com/go/getflashplayer";

            script = script.Replace("_onUploadSuccess", OnUploadSuccessClientFunction)
                     .Replace("_allowMultiple", AllowMultiple.ToString().ToLower())
                     .Replace("fileUpld", fileUpld.ClientID)
                     .Replace("hfUpldFiles", hfUpldFiles.ClientID)
                     .Replace("hfClear", hfClear.ClientID)
                     .Replace("cstmValidator", cstmValidator.ClientID)
                     .Replace("UploadedFiles", UploadedFilesName)
                     .Replace("UploaderHandler", UploaderHandlerUrl)
                     .Replace("_multi", AllowMultiple.ToString().ToLower())
                     .Replace("_showError", ShowErrorFunction)
                     .Replace("_fileSizeLimit", MaxFileSize.ToString())
                     .Replace("_fileTypeExts", GetFilesTypes(FilesType))
                     .Replace("_maxAllowedNofFiles", MaxFilesCount.ToString())
                     .Replace("_uploadLimit", "0")
                     .Replace("_removeCompleted", (!ShowCompletedUIAfterComplete).ToString().ToLower())
                     .Replace("defaultFlashImage", string.Concat("\"<a href='", flashDownloadUrl, "' target='_blank'><img src='http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif'  /></a>\""));

            ScriptManager.RegisterStartupScript(up, up.GetType(), this.ClientID + "_script", uploadedFiles + chkUpld + script, true);
        }
Пример #4
0
        public void AddValidation(ClientModelValidationContext context)
        {
            CustomAttributes.MergeAttribute(context.Attributes, "data-val", "true");
            var errorMessage = FormatErrorMessage(context.ModelMetadata.GetDisplayName());

            CustomAttributes.MergeAttribute(context.Attributes, "data-val-minsize", MinSize.ToString());
            CustomAttributes.MergeAttribute(context.Attributes, "data-val-maxsize", MaxSize.ToString());
            CustomAttributes.MergeAttribute(context.Attributes, "data-val-maxfilesize", MaxFileSize.ToString());
            CustomAttributes.MergeAttribute(context.Attributes, "data-val-canbenull", CanBeNull.ToString());
            CustomAttributes.MergeAttribute(context.Attributes, "data-val-photovalidation", errorMessage);
            //todo: client side part not implemented
        }
Пример #5
0
        protected override void OnPreRender(EventArgs e)
        {
            string uploadedFiles = "";
            string chkUpld       = "";

            if (!this.ScriptRegistered)
            {
                uploadedFiles = string.Format(";var {0} =[];", UploadedFilesName);
                chkUpld       = (@";function chkUpld(sender, args) {
                                args.IsValid = UploadedFiles.length > 0;
                                };")
                                .Replace("chkUpld", this.ClientValidationFunctionName)
                                .Replace("UploadedFiles", this.UploadedFilesName);

                this.ScriptRegistered = true;
            }

            bool clear = string.IsNullOrEmpty(hfClear.Value) ? false : bool.Parse(hfClear.Value);

            if (clear)
            {
                uploadedFiles = string.Format(";{0} =[];", UploadedFilesName);
                hfClear.Value = "false";
            }

            string script = (@"
var UploadedFiles = [];
// Initialize the widget when the DOM is ready
$(function() {
    // Setup html5 version
    var uploader = new plupload.Uploader({
        // General settings
        runtimes : 'html5,flash,silverlight,html4',
        browse_button : '_pickfiles', // you can pass in id...
        container: document.getElementById('_container'), // ... or DOM Element itself
        url : 'UploaderHandler',
        file_data_name : 'Filedata',
        chunk_size : '1mb',
        rename : true,
        dragdrop: true,
        max_file_size : '_fileSizeLimit',

        filters : {
            // Maximum file size
            max_file_size : '10mb',
            // Specify what files to browse for
            mime_types: [
                {title : ""Image files"", extensions : ""_fileTypeExts""}
            ]
        },
          
        // Flash settings
        flash_swf_url : '/Layouts/js/plupload/js/Moxie.swf',
     
        // Silverlight settings
        silverlight_xap_url : '/Layouts/js/plupload/js/Moxie.xap',
        init: {
            PostInit: function() {
                UploadedFiles = [];
            },
 
            FilesAdded: function(up, files) {
                plupload.each(files, function(file) {
                    var table = document.getElementById(""_fileUpld"");
                    var row = table.insertRow(table.rows.length);
                    row.id = 'upload_'+file.id;
                    var cell1 = row.insertCell(0);
                    var cell2 = row.insertCell(1);
                    row.insertCell(2);
                    // Add some text to the new cells:
                    cell1.innerHTML =file.name+ ' (' + plupload.formatSize(file.size)+')';
                    $(""#_fileUpld"").show();
                });
                uploader.start();
            },
 
            UploadProgress: function(up, file) {
                var row = document.getElementById('upload_'+file.id);
                row.cells[1].innerHTML =file.percent+'%';
                if(file.percent == 100){
                    row.cells[2].innerHTML = '<img class=""removeBtn"" style=""display:none"" src=""_cancelImg"" onclick=""removeFile(&#39;'+file.id+'&#39;)""/> ';
                }
            },
          
			FileUploaded:function(up,file,response){
				if(response.response.indexOf(""error"") == 0){
					console.log(response.response.split(""|"")[1]);
					file.status=plupload.FAILED;
					up.trigger('UploadProgress',file);
				}else{
					var _UploadedFiles = [];
					for (var i = 0; i < UploadedFiles.length; i++) {
						if (file.name != UploadedFiles[i].ClientName)
							_UploadedFiles.push(UploadedFiles[i]);
					}
					UploadedFiles = _UploadedFiles;

					var paths=response.response.split(';');
					UploadedFiles.push({
						FileID: file.id,
						FileName: file.name,
						Index: file.index,
						Type: file.type,
						PhysicalPath: paths[0],
						VirtualPath: paths[1]
					});
					_onUploadSuccess;
				}
			}, 
            UploadComplete : function(up,files){
                $('#hfUpldFiles').val(JSON.stringify(UploadedFiles));
                var _maxFileCnt = _maxAllowedNofFiles;
                if(_maxFileCnt == 0)
                    _maxFileCnt = 10000;

                if(!_allowMultiple)
                    _maxFileCnt = 1;

                //if(UploadedFiles.length >= _maxFileCnt)
                //{
                 //       $('#fileUpld').uploadify('settings', 'height', 0);
                 //       $('#fileUpld').uploadify('disable', true);
                //}
                var _removeBtn = document.getElementsByClassName('removeBtn');
                for (var i = 0; i < _removeBtn.length; ++i) {
                    var item = _removeBtn[i];  
                    item.style.display = '';
                }
				$('#_btnUploadFinished').click();
            },
 
            Error: function(up, err) {
                console.log('error: ' + err.response);
            }
        }
     });
    uploader.init();
});
    function ClearUploader(){
        $('#hfUpldFiles').val('');
        UploadedFiles =[];
    }

    function removeFile(id){
            var _UploadedFiles = [];
            for (var i = 0; i < UploadedFiles.length; i++) {
                if (id != UploadedFiles[i].FileID)
                    _UploadedFiles.push(UploadedFiles[i]);
            }
            UploadedFiles = _UploadedFiles;
        removeRow(id);
        $('#hfUpldFiles').val(JSON.stringify(UploadedFiles)); 
    }
    function removeRow(id){
        var row = document.getElementById('upload_'+id);
        if(row != null)
            row.parentNode.removeChild(row);


        var table = document.getElementById(""_fileUpld"");
        if(table.rows.length == 1){
            $(""#_fileUpld"").hide();
        }
        
    }
    ;");

            string userAgent        = HttpContext.Current.Request.UserAgent.ToLower();
            string flashDownloadUrl = userAgent.Contains("android") ? "http://fpdownload.macromedia.com/pub/flashplayer/installers/archive/android/11.1.115.81/install_flash_player_ics.apk" : "http://www.adobe.com/go/getflashplayer";

            script = script.Replace("_onUploadSuccess", OnUploadSuccessClientFunction)
                     .Replace("_allowMultiple", AllowMultiple.ToString().ToLower())
                     .Replace("_fileUpld", fileUpld.ClientID)
                     .Replace("_container", container.ClientID)
                     .Replace("_pickfiles", pickFile.ClientID)
                     .Replace("_fileSizeLimit", MaxFileSize.ToString() + "mb")
                     .Replace("_fileTypeExts", GetFilesTypes(FilesType))
                     .Replace("UploaderHandler", UploaderHandlerUrl)
                     .Replace("UploadedFiles", UploadedFilesName)
                     .Replace("_maxAllowedNofFiles", MaxFilesCount.ToString())
                     .Replace("hfUpldFiles", hfUpldFiles.ClientID)
                     .Replace("hfClear", hfClear.ClientID)
                     .Replace("_cancelImg", "/Layouts/img/uploadify-cancel.png")
                     .Replace("_btnUploadFinished", btnUploadFinished.ClientID);
            //.Replace("_uploadLimit", "0");
            //.Replace("cstmValidator", cstmValidator.ClientID)
            //.Replace("_multi", AllowMultiple.ToString().ToLower())
            //.Replace("_showError", ShowErrorFunction)
            //.Replace("_removeCompleted", (!ShowCompletedUIAfterComplete).ToString().ToLower())
            //.Replace("defaultFlashImage", string.Concat("\"<a href='", flashDownloadUrl, "' target='_blank'><img src='http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif'  /></a>\""));

            ScriptManager.RegisterStartupScript(up, up.GetType(), this.ClientID + "_script", uploadedFiles + chkUpld + script, true);
        }