示例#1
0
 private void bttnOK_Click(object sender, EventArgs e)
 {
     try
     {
         if (listViewFileItems.Items.Count > 0)
         {
             foreach (string filePath in dbInfoDictionary.Keys)
             {
                 DBFileInfo dbFileInfo = dbInfoDictionary[filePath];
                 if (dbFileInfo.isDefault)
                 {
                     settings.DefaultDBFile = dbFileInfo.FilePath;
                     break;
                 }
             }
             settings.DBInfoDictionary = dbInfoDictionary;
             settings.WriteINI();
             this.DialogResult = DialogResult.OK;
             this.Close();
         }
         else
         {
             MessageBox.Show("Please select at least a file.", "Missing Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Failed to save the file information.\n" + ex.Message, "Error: Alternative Data Source", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
示例#2
0
        private void propertiesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (listViewFileItems.SelectedItems.Count > 0)
                {
                    DBFileInfo selectedFile = listViewFileItems.SelectedItems[0].Tag as DBFileInfo;

                    if (null != selectedFile)
                    {
                        form_FileProperties propertyForm = new form_FileProperties(selectedFile);
                        if (DialogResult.OK == propertyForm.ShowDialog())
                        {
                            listViewFileItems.SelectedItems[0].Tag = propertyForm.DataBaseFileInfo;
                            listViewFileItems.SelectedItems[0].SubItems[4].Text = propertyForm.DataBaseFileInfo.Comments;
                            selectedFile.Comments = propertyForm.DataBaseFileInfo.Comments;
                            if (dbInfoDictionary.ContainsKey(selectedFile.FilePath))
                            {
                                dbInfoDictionary.Remove(selectedFile.FilePath);
                            }
                            dbInfoDictionary.Add(selectedFile.FilePath, selectedFile);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Please seleca at least a file item in the list view to add comments.", "Missing Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to activate an item: \n" + listViewFileItems.SelectedItems[0].Name + "\n" + ex.Message, "Error: Alternative Data Source", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
示例#3
0
        public IList <DBTagInfo> GetContainTags(DBFileInfo monitoredFile)
        {
            IList <DBTagInfo> tagInfos = new List <DBTagInfo>();

            if (monitoredFile.IsNull())
            {
                return(tagInfos);
            }

            string[] array = monitoredFile.Tag.Split(';');
            for (int i = 0; i < array.Length; i++)
            {
                int tagId = -1;
                if (!Int32.TryParse(array[i], out tagId))
                {
                    continue;
                }
                DBTagInfo tagInfo = TagInfos.FirstOrDefault(tag => tag.ID == tagId);
                if (tagInfo.IsNull())
                {
                    continue;
                }
                tagInfos.Add(tagInfo);
            }
            return(tagInfos);
        }
        /// <summary>
        /// 添加文件
        /// </summary>
        /// <param name="fileInfo"></param>
        /// <param name="fileContent"></param>
        public void AddFile(string nodePath, DBFileInfo fileInfo, byte[] fileContent)
        {
            DiskFile file = DBFileInfo.toDiskFile(fileInfo, fileContent);

            repository.AddFileOfFolderDB(nodePath, file);
            //将ID传回
            fileInfo.ID = file.ID;
        }
示例#5
0
        /// <summary>
        /// 创建地理数据库
        /// </summary>
        /// <param name="databasePath">存储路径</param>
        /// <param name="gdbName">数据库名</param>
        /// <param name="gdbUser">账号</param>
        /// <param name="gdbPassword">密码</param>
        /// <returns></returns>
        public static bool CreateDataBase(string databasePath, string gdbName, string gdbUser, string gdbPassword)
        {
            Server svr = new Server();  //地理数据库服务器
            bool   rtn = svr.Connect("Mapgislocal", "", "");

            if (rtn == true)
            {
                //日志事件触发器
                LogEventReceiver LogER = new LogEventReceiver();

                //地理数据库创建信息对象
                GDBCreateParam createParam = new GDBCreateParam();
                //数据库文件信息对象
                DBFileInfo fileInfo = new DBFileInfo();
                //数据库文件信息列表对象
                List <DBFileInfo> ListDB = new List <DBFileInfo>();
                //数据库文件扩展信息对象
                FileExtendInfo extendInfo = new FileExtendInfo
                {
                    //设置数据库文件扩展信息
                    ExtendMode   = FileExtendMode.Size,  //数据增长类型
                    ExtendSize   = 1,                    //数据文件增长大小
                    ExtendUnit   = FileExtendUnit.Mbyte, //文件增长单位
                    IsExtendable = true,                 //是否实现自增长
                    MaxFileSize  = 0                     //数据库最大容量
                };

                //设置数据库文件信息
                fileInfo.ExtendInfo = extendInfo;   //数据库文件扩展信息
                fileInfo.FilePath   = databasePath; //数据库路径  @"C:\Users\姚一鸣\Desktop\test.HDF"
                fileInfo.InitSize   = 20;           //数据库初始大小

                //数据库文件信息列表
                ListDB.Add(fileInfo);

                createParam.GDBName       = gdbName;     //地理数据库的名称  "test"
                createParam.GDBOwner      = gdbUser;     //用户名称  ""
                createParam.OwnerPsw      = gdbPassword; //用户密码  ""
                createParam.DataFileInfos = ListDB;      //数据库文件信息列表
                createParam.IndexFileInfo = fileInfo;    //数据库文件信息

                //创建数据库
                int i = svr.CreateGDB(createParam, LogER);
                svr.DisConnect();
                if (i > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// 添加文件
        /// </summary>
        private void AddFiles()
        {
            WinForm.OpenFileDialog openFileDialog = new WinForm.OpenFileDialog();
            openFileDialog.Multiselect = true;
            String info = "";

            if (openFileDialog.ShowDialog() == WinForm.DialogResult.OK)
            {
                foreach (var FileName in openFileDialog.FileNames)
                {
                    FileInfo fi = new FileInfo(FileName);
                    if (fi.Length > 5 * 1024 * 1024)
                    {
                        MessageBoxResult result = MessageBox.Show("要加入的文件:“" + System.IO.Path.GetFileName(FileName) + "”大小为:" + FileUtils.FileSizeFormater(fi.Length) + ",将大文件加入数据库会导致程序性能下降,点击“是”添加此文件,点击“否”跳过此文件", "加入大文件", MessageBoxButton.YesNo, MessageBoxImage.Exclamation);
                        if (result == MessageBoxResult.No)
                        {
                            continue;
                        }
                    }


                    DBFileInfo fileInfo = new DBFileInfo()
                    {
                        AddTime  = DateTime.Now,
                        FilePath = FileName,
                        FileSize = fi.Length
                    };
                    //不加入重复的文件
                    if (_dataObject.AttachFiles.IndexOf(fileInfo) != -1)
                    {
                        continue;
                    }
                    //当加入文件时,有可能因为另一进程也使用此文件而导致加载失败
                    try
                    {
                        accessObj.AddFile(_dataObject.Path, fileInfo, System.IO.File.ReadAllBytes(FileName));
                        _dataObject.AttachFiles.Add(fileInfo);
                        info = string.Format("正在加入文件{0}", System.IO.Path.GetFileName(FileName));

                        if (_dataObject.MainWindow != null)
                        {
                            _dataObject.MainWindow.ShowInfo(info);
                        }
                    }

                    catch (IOException ex)
                    {
                        MessageBox.ShowInformation(ex.Message);
                    }
                    if (_dataObject.MainWindow != null)
                    {
                        _dataObject.MainWindow.ShowInfo("文件添加完毕");
                    }
                }
            }

            RaiseFileCountChangedEvent();
        }
        public async Task <bool> Move(string newPath)
        {
            var newDBPath = new DBPath(newPath);
            var r         = await fileSystem.MovePathAsync(fileInfo.Path, newDBPath);

            if (r)
            {
                fileInfo = await fileSystem.FileInfoForPathAsync(newDBPath);
            }
            return(r);
        }
 public DropboxFile(DBFileInfo fileInfo, DBFilesystem fileSystem)
 {
     if (fileInfo == null)
     {
         throw new ArgumentNullException("fileInfo");
     }
     if (fileSystem == null)
     {
         throw new ArgumentNullException("fileSystem");
     }
     this.fileInfo   = fileInfo;
     this.fileSystem = fileSystem;
 }
        public async Task WriteString(string contents)
        {
            await fileLock.WaitAsync();

            try {
                var file = await fileSystem.OpenFileAsync(fileInfo.Path);

                await file.WriteStringAsync(contents);

                file.Close();
                fileInfo = await fileSystem.FileInfoForPathAsync(fileInfo.Path);
            }
            finally {
                fileLock.Release();
            }
        }
示例#10
0
        private void ReqSyncBlock(bool bCheckemptyDB = true)
        {
            LogHelper.WriteMethodLog(true);
            if (bCheckemptyDB)
            {
                if (LeveldbOperator.OpenDB(AppSettings.XXPDBFolder) != ConstHelper.BC_OK)
                {
                    DBFileInfo df  = this.commHandler.RequestHightestDBInfo();
                    string     str = string.Format("Ip:{0}, highest:{1} size:{2}", df.IP, df.LastBlockHeight, df.DBFileSize);
                    MessageBox.Show(str);
                    Task.Run(() => {
                        string SavePath = Path.Combine(AppSettings.XXPTempFolder, ConstHelper.BC_DBZipName);
                        long lRet       = this.commHandler.StartReceiveFile(df.IP, df.DBFileSize, SavePath);
                        if (lRet == -1)
                        {
                            MessageBox.Show("try later, there is a file transfering now");
                        }
                        else
                        {
                            MessageBox.Show("Received: " + lRet.ToString());
                            FileIOHelper.DeleteDir(AppSettings.XXPDBFolder);
                            Directory.CreateDirectory(AppSettings.XXPDBFolder);
                            ZipHelper.UnZip(SavePath, AppSettings.XXPDBFolder);
                            this.InitFromDB();
                        }
                        this.commHandler.DisposeTransFileHelper();
                    });

                    if (this.commHandler.RequestStartTransDB(df.IP) != ConstHelper.BC_OK)
                    {
                    }
                }
                LeveldbOperator.CloseDB();
            }


            ResponseBlock BkInfo = this.commHandler.RequestNewBlockInfo(this.bkHandler.GetLastBlock());

            if (BkInfo.BlockResult == BlockResultType.Lower)
            {
                string sRet = this.commHandler.GetNewBlocks(BkInfo.IP, this.bkHandler.GetLastBlock());
            }
            LogHelper.WriteMethodLog(false);
        }
        /// <summary>
        /// 删除用户选择的文件
        /// </summary>
        private void RemoveFiles()
        {
            List <int>        fileIDs = new List <int>();
            List <DBFileInfo> files   = new List <DBFileInfo>();

            foreach (var item in dgFiles.SelectedItems)
            {
                DBFileInfo fileInfo = item as DBFileInfo;
                files.Add(fileInfo);
                fileIDs.Add(fileInfo.ID);
            }
            if (fileIDs.Count > 0)
            {
                accessObj.DeleteFilesOfFolderDB(_dataObject.Path, fileIDs);
            }
            foreach (var fileInfo in files)
            {
                _dataObject.AttachFiles.Remove(fileInfo);
            }
        }
示例#12
0
        public async Task <bool> GetFileName(string UserName, string AppID, string OS)
        {
            var param       = new GetFileNameRM(UserName, AppID, OS);
            var responseDto = await _sgService
                              .GetFileName(Priority.UserInitiated, param)
                              .ConfigureAwait(false);

            if (responseDto != null)
            {
                if (responseDto.dbFileNames != null && responseDto.dbFileNames.Count() != 0)
                {
                    foreach (var fileNameInfo in responseDto.dbFileNames)
                    {
                        if (fileNameInfo.file_Type == "Audit_DB")
                        {
                            var auditFileInfo = new DBFileInfo();
                            auditFileInfo.ConvertFromFileInfoDto(fileNameInfo);
                            Globals.AuditDBInfo = auditFileInfo;
                        }
                        else if (fileNameInfo.file_Type == "Master_DB")
                        {
                            var masterFileInfo = new DBFileInfo();
                            masterFileInfo.ConvertFromFileInfoDto(fileNameInfo);
                            Globals.MasterDBInfo = masterFileInfo;
                        }
                    }

                    Globals.GetFileNameResult = GetFileNameResultType.Success;
                    return(true);
                }
                else
                {
                    Globals.GetFileNameResult = GetFileNameResultType.Error;
                    return(false);
                }
            }

            Globals.GetFileNameResult = GetFileNameResultType.Error;
            return(false);
        }
        void WriteDropboxFile(IEnumerable <Tuple <string, string> > locations, IDictionary <Tuple <string, string, int>, ISequenceItem> sequenceDictionary)
        {
            // todo = unless you're a super user, only write the file for the location where you currently are
            foreach (var tuple in locations)
            {
                var items = sequenceDictionary
                            .Where(kvp => kvp.Key.Item1 == tuple.Item1 && kvp.Key.Item2 == tuple.Item2)
                            .Select(kvp => new JsonSequenceItem
                {
                    RaceCode      = _race.Code,
                    LocationName  = kvp.Key.Item1,
                    LocationToken = kvp.Key.Item2,
                    StartNumber   = kvp.Value.Boat.Number,
                    TimeStamp     = kvp.Value.TimeStamp,
                    Notes         = kvp.Value.Notes
                }).ToList();

                string     json = JsonConvert.SerializeObject(items.OrderBy(cr => cr.TimeStamp));
                DBError    error;
                string     filename = string.Format("{0}-{1}-{2}.json", _race.Code, tuple.Item1, tuple.Item2);
                var        path     = DBPath.Root.ChildPath(_race.Code).ChildPath(filename);
                DBFileInfo fi       = DBFilesystem.SharedFilesystem.FileInfoForPath(path, out error);
                DBFile     file;
                if (fi == null || (error != null && error.Code == (int)DBErrorCode.NotFound))
                {
                    file = DBFilesystem.SharedFilesystem.CreateFile(path, out error);
                }
                else
                {
                    file = DBFilesystem.SharedFilesystem.OpenFile(path, out error);
                }

                if (file != null)
                {
                    file.WriteString(json.ToString(), out error);
                    file.Close();
                }
            }
        }
示例#14
0
        private void form_FileSelection_Load(object sender, EventArgs e)
        {
            try
            {
                foreach (string filePath in dbInfoDictionary.Keys)
                {
                    if (File.Exists(filePath))
                    {
                        DBFileInfo   dbFileInfo = dbInfoDictionary[filePath];
                        ListViewItem item       = new ListViewItem(dbFileInfo.FileName);
                        item.Name = dbFileInfo.FilePath;
                        item.Tag  = dbFileInfo;

                        if (dbFileInfo.isDefault)
                        {
                            item.ImageIndex = 1;
                        }
                        else
                        {
                            item.ImageIndex = 0;
                        }

                        item.SubItems.Add(dbFileInfo.DateModified);
                        item.SubItems.Add(dbFileInfo.ModifiedBy);
                        item.SubItems.Add(dbFileInfo.FilePath);
                        item.SubItems.Add(dbFileInfo.Comments);

                        listViewFileItems.Items.Add(item);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to load the form.\n" + ex.Message, "Error: Alternative Data Source", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#15
0
		public DropboxFile (DBFileInfo fileInfo, DBFilesystem fileSystem)
		{
			if (fileInfo == null)
				throw new ArgumentNullException ("fileInfo");
			if (fileSystem == null)
				throw new ArgumentNullException ("fileSystem");
			this.fileInfo = fileInfo;
			this.fileSystem = fileSystem;
		}
示例#16
0
        private void ExecuteWhenDirectoryScanned(FileScannerProcessEventArgs e)
        {
            //DBFolderInfo monitoredFolderInfo = null;
            //IList<DBFolderInfo> monitoredFolderInfos;
            //DBFolderInfo existFolder = DBCache.Folders.FirstOrDefault(folder => 0 == string.Compare(folder.Path, e.CurrentDir.FullName, true));
            //if (null == existFolder)
            //{
            //    monitoredFolderInfo = DBFolderInfo.Convert(e.CurrentDir);
            //    monitoredFolderInfos = new List<DBFolderInfo>() {
            //        monitoredFolderInfo
            //    };
            //    DBHelper.InsertFolders(monitoredFolderInfos);
            //}
            //else
            //{
            //    monitoredFolderInfo = existFolder;
            //    monitoredFolderInfos = new List<DBFolderInfo>() {
            //        monitoredFolderInfo
            //    };
            //    DBHelper.UpdateFolders(monitoredFolderInfos);
            //}

            //monitoredFolderInfo.IsScanned = true;
            //newMonitoredFolderInfos.Add(monitoredFolderInfo);

            DBFolderInfo existFolder = DBCache.Folders.FirstOrDefault(folder => 0 == string.Compare(folder.Path, e.CurrentDir.FullName, true));

            if (!existFolder.IsNull())
            {
                existFolder.IsScanned = true;
                DBHelper.UpdateFolders(new List <DBFolderInfo>()
                {
                    existFolder
                });
            }

            IList <DBFileInfo> filesToAdd     = new List <DBFileInfo>();
            IList <DBFileInfo> filesToUpgrade = new List <DBFileInfo>();

            foreach (ScannedFileInfo fileInfo in e.Files)
            {
                if (null == fileInfo || null == fileInfo.File)
                {
                    continue;
                }
                DBFileInfo newfile = DBFileInfo.Convert(fileInfo);
                //newfile.ParentID = monitoredFolderInfo.ID;
                DBFileInfo findFile = DBCache.Files.FirstOrDefault(file => 0 == string.Compare(fileInfo.File.FullName, file.Path));
                if (findFile.IsNull())
                {
                    filesToAdd.Add(newfile);
                }
                else
                {
                    filesToUpgrade.Add(findFile);
                }
            }
            //if (monitoredFolderInfo.ID == -1)
            //{
            //    int i = 0;
            //    ;
            //}
            DBHelper.InsertFiles(filesToAdd);
            DBHelper.UpdateFiles(filesToUpgrade);
        }
示例#17
0
		public async Task<bool> Move (string newPath)
		{
			var newDBPath = new DBPath (newPath);
			var r = await fileSystem.MovePathAsync (fileInfo.Path, newDBPath);
			if (r) {
				fileInfo = await fileSystem.FileInfoForPathAsync (newDBPath);
			}
			return r;
		}
示例#18
0
 public form_FileProperties(DBFileInfo fileInfo)
 {
     dbFileInfo = fileInfo;
     InitializeComponent();
 }
示例#19
0
        private void ResearchNodes_Click(object sender, EventArgs e)
        {
            LogHelper.WriteMethodLog(true);
            string Ip = this.textBoxSeedIP.Text;
            //step1 handshake
            bool bRet = this.commHandler.RequestHandshake(Ip);

            if (!bRet)
            {
                MessageBox.Show("Invalid seed IP");
                return;
            }
            //step2 get more Nodes IP
            List <string> lstAddress = this.commHandler.RequestMoreNodes(Ip);
            List <string> lstNew     = new List <string>();

            // step3 handshake lstAddress
            foreach (var item in lstAddress)
            {
                if (item == OSHelper.GetLocalIP())
                {
                    continue;
                }
                if (this.commHandler.RequestHandshake(item))
                {
                    lstNew.Add(item);
                }
            }
            // step4 send new addresses to all I know
            this.commHandler.SendNewAddress2Others(lstNew);
            this.textBoxConnectedNodes.Text = this.commHandler.GetAddressCount().ToString();

            if (LeveldbOperator.OpenDB(AppSettings.XXPDBFolder) != ConstHelper.BC_OK)
            {
                DBFileInfo df  = this.commHandler.RequestHightestDBInfo();
                string     str = string.Format("Ip:{0}, highest:{1} size:{2}", df.IP, df.LastBlockHeight, df.DBFileSize);

                Task.Run(() => {
                    string SavePath = Path.Combine(AppSettings.XXPTempFolder, ConstHelper.BC_DBZipName);
                    long lRet       = this.commHandler.StartReceiveFile(df.IP, df.DBFileSize, SavePath);
                    if (lRet == -1)
                    {
                        MessageBox.Show("try later, there is a file transfering now");
                    }
                    else
                    {
                        MessageBox.Show("Received: " + lRet.ToString());
                        FileIOHelper.DeleteDir(AppSettings.XXPDBFolder);
                        Directory.CreateDirectory(AppSettings.XXPDBFolder);
                        ZipHelper.UnZip(SavePath, AppSettings.XXPDBFolder);
                        this.InitFromDB();
                    }
                    this.commHandler.DisposeTransFileHelper();
                });
                MessageBox.Show(str);
                if (this.commHandler.RequestStartTransDB(df.IP) != ConstHelper.BC_OK)
                {
                }
            }
            LeveldbOperator.CloseDB();

            ResponseBlock BkInfo = this.commHandler.RequestNewBlockInfo(this.bkHandler.GetLastBlock());

            if (BkInfo.BlockResult == BlockResultType.Lower)
            {
                string sRet = this.commHandler.GetNewBlocks(BkInfo.IP, this.bkHandler.GetLastBlock());
            }

            LogHelper.WriteMethodLog(false);
        }
示例#20
0
 public UIFile(DBFileInfo monitoredFile)
 {
     this.MonitoredFile = monitoredFile;
 }
示例#21
0
		public async Task WriteString (string contents)
		{
			await fileLock.WaitAsync ();
			try {
				var file = await fileSystem.OpenFileAsync (fileInfo.Path);
				await file.WriteStringAsync (contents);
				file.Close ();
				fileInfo = await fileSystem.FileInfoForPathAsync (fileInfo.Path);
			}
			finally {
				fileLock.Release ();
			}
		}