Пример #1
0
        /// <summary>
        /// Open a form to save a ModuleManager
        /// </summary>
        /// <param name="moduleManager"></param>
        public static void saveDialog(ModuleManager moduleManager)
        {
            SaveFileForm saveFileForm = new SaveFileForm(PATH, SUFFIX);

            saveFileForm.TopMost = true;
            saveFileForm.ShowDialog();

            if (saveFileForm.save)
            {
                Console.WriteLine("File changed to " + saveFileForm.file);
                Properties.Settings.Default["modulemanager"] = saveFileForm.file + SUFFIX;

                FileSaver.save(moduleManager);
            }
        }
Пример #2
0
        private string UploadFile(string ticket, string fullName)
        {
            //Step 1: Create a copy of the file and build the path to there.
            var uploadPath = string.Empty;
            var uploadDir  = DFEnvironment.GetSpecialFolder(DFEnvironment.SpecialFolder.UploadDirectory);
            var fileName   = string.Empty;

            try
            {
                if (!Directory.Exists(uploadDir))
                {
                    Directory.CreateDirectory(uploadDir);
                }

                var fileInfo = new FileInfo(fullName);

                uploadPath = string.Format("{0}\\{1}", uploadDir, fileInfo.Name);
                fileName   = fileInfo.Name;

                fileInfo.CopyTo(uploadPath, true);
            }
            catch (Exception ex)
            {
                LogFactory.CreateLog().LogError(ex);
                MessageBox.Show(ex.Message, this.Application.Name, MessageBoxButtons.YesNo,
                                MessageBoxIcon.Error);

                return(String.Empty);
            }

            //Step 3: Upload the file

            TrackingListManager.Reload();

            var trackingItem = TrackingListManager.GetByPath(fullName);

            if (trackingItem != null)
            {
                using (var form = new TransferProgressForm())
                {
                    if (form.UploadFile(ticket, trackingItem.GroupId, trackingItem.FolderId,
                                        trackingItem.FileId, uploadPath, true))
                    {
                        trackingItem.FileId       = form.FileId;
                        trackingItem.ModifiedTime = form.ModifiedTime;

                        TrackingListManager.Save();
                    }
                }
            }
            else
            {
                var community        = (UserGroup)null;
                var folder           = (FileFolder)null;
                var saveAsNewVersion = false;

                using (var saveFileView = new SaveFileForm(ticket))
                {
                    if (saveFileView.ShowSaveFileDialog())
                    {
                        community        = saveFileView.Group;
                        folder           = saveFileView.Folder;
                        saveAsNewVersion = saveFileView.SaveAsNewVersion;
                    }
                    else
                    {
                        return(String.Empty);
                    }
                }

                //Upload file to the server.
                using (var form = new TransferProgressForm())
                {
                    if (form.UploadFile(ticket, community.id,
                                        folder.id, string.Empty, uploadPath, saveAsNewVersion))
                    {
                        trackingItem = new TrackingItem()
                        {
                            Name          = Path.GetFileName(fullName),
                            LastWriteTime = DateTime.Now.ToFileTimeUtc(),
                            Path          = fullName,
                            Type          = "F",
                            GroupId       = community.id,
                            FolderId      = folder.id,
                            FileId        = form.FileId,
                            ModifiedTime  = form.ModifiedTime
                        };

                        TrackingListManager.Add(trackingItem);
                        TrackingListManager.Save();
                    }
                }
            }

            try
            {
                File.Delete(uploadPath);
            }
            catch (Exception e)
            {
                LogFactory.CreateLog().LogError(e);
            }

            return(trackingItem.FileId);
        }