public Contract_ImportFolder ToContract()
        {
            Contract_ImportFolder contract = new Contract_ImportFolder();
            contract.ImportFolderID = this.ImportFolderID;
            contract.ImportFolderType = this.ImportFolderType;

            // Make sure to format folder with trailing slash first
            contract.ImportFolderLocation = FormatImportFolderLocation(this.ImportFolderLocation);
            contract.ImportFolderName = this.ImportFolderName;
            contract.IsDropSource = this.IsDropSource;
            contract.IsDropDestination = this.IsDropDestination;
            contract.IsWatched = this.IsWatched;
            contract.CloudID = this.CloudID;
            return contract;
        }
Example #2
0
        public Contract_ImportFolder_SaveResponse SaveImportFolder(Contract_ImportFolder contract)
        {
            Contract_ImportFolder_SaveResponse response = new Contract_ImportFolder_SaveResponse();
            response.ErrorMessage = "";
            response.ImportFolder = null;

            try
            {

                ImportFolderRepository repNS = new ImportFolderRepository();
                ImportFolder ns = null;
                if (contract.ImportFolderID.HasValue)
                {
                    // update
                    ns = repNS.GetByID(contract.ImportFolderID.Value);
                    if (ns == null)
                    {
                        response.ErrorMessage = "Could not find Import Folder ID: " + contract.ImportFolderID.Value.ToString();
                        return response;
                    }
                }
                else
                {
                    // create
                    ns = new ImportFolder();
                }

                if (string.IsNullOrEmpty(contract.ImportFolderName))
                {
                    response.ErrorMessage = "Must specify an Import Folder name";
                    return response;
                }

                if (string.IsNullOrEmpty(contract.ImportFolderLocation))
                {
                    response.ErrorMessage = "Must specify an Import Folder location";
                    return response;
                }

                if (!Directory.Exists(contract.ImportFolderLocation))
                {
                    response.ErrorMessage = "Cannot find Import Folder location";
                    return response;
                }

                if (!contract.ImportFolderID.HasValue)
                {
                    ImportFolder nsTemp = repNS.GetByImportLocation(contract.ImportFolderLocation);
                    if (nsTemp != null)
                    {
                        response.ErrorMessage = "An entry already exists for the specified Import Folder location";
                        return response;
                    }
                }

                if (contract.IsDropDestination == 1 && contract.IsDropSource == 1)
                {
                    response.ErrorMessage = "A folder cannot be a drop source and a drop destination at the same time";
                    return response;
                }

                // check to make sure we don't have multiple drop folders
                List<ImportFolder> allFolders = repNS.GetAll();

                if (contract.IsDropDestination == 1)
                {
                    foreach (ImportFolder imf in allFolders)
                    {
                        if (imf.IsDropDestination == 1 && (!contract.ImportFolderID.HasValue || (contract.ImportFolderID.Value != imf.ImportFolderID)))
                        {
                            imf.IsDropDestination = 0;
                            repNS.Save(imf);
                        }
                    }
                }

                ns.ImportFolderName = contract.ImportFolderName;
                ns.ImportFolderLocation = contract.ImportFolderLocation;
                ns.IsDropDestination = contract.IsDropDestination;
                ns.IsDropSource = contract.IsDropSource;
                ns.IsWatched = contract.IsWatched;
                repNS.Save(ns);

                response.ImportFolder = ns.ToContract();

                MainWindow.StopWatchingFiles();
                MainWindow.StartWatchingFiles();

                return response;
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                response.ErrorMessage = ex.Message;
                return response;
            }
        }
Example #3
0
        void btnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // An import folder cannot be both the drop source and the drop destination
                if (chkDropDestination.IsChecked.HasValue && chkDropSource.IsChecked.HasValue && chkDropDestination.IsChecked.Value && chkDropSource.IsChecked.Value)
                {
                    MessageBox.Show(JMMServer.Properties.Resources.ImportFolders_SameFolder, JMMServer.Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                // The import folder location cannot be blank. Enter a valid path on OMM Server
                if (string.IsNullOrEmpty(txtImportFolderLocation.Text))
                {
                    MessageBox.Show(JMMServer.Properties.Resources.ImportFolders_BlankImport, JMMServer.Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                    txtImportFolderLocation.Focus();
                    return;
                }

                Contract_ImportFolder contract = new Contract_ImportFolder();
                if (importFldr.ImportFolderID == 0)
                    contract.ImportFolderID = null;
                else
                    contract.ImportFolderID = importFldr.ImportFolderID;
                contract.ImportFolderName = "NA";
                contract.ImportFolderLocation = txtImportFolderLocation.Text.Trim();
                contract.IsDropDestination = chkDropDestination.IsChecked.Value ? 1 : 0;
                contract.IsDropSource = chkDropSource.IsChecked.Value ? 1 : 0;
                contract.IsWatched = chkIsWatched.IsChecked.Value ? 1 : 0;

                JMMServiceImplementation imp = new JMMServiceImplementation();
                Contract_ImportFolder_SaveResponse response = imp.SaveImportFolder(contract);
                if (!string.IsNullOrEmpty(response.ErrorMessage))
                    MessageBox.Show(response.ErrorMessage, JMMServer.Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);

                ServerInfo.Instance.RefreshImportFolders();
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }

            this.DialogResult = true;
            this.Close();
        }
Example #4
0
		public Contract_ImportFolder ToContract()
		{
			Contract_ImportFolder contract = new Contract_ImportFolder();
			contract.ImportFolderID = this.ImportFolderID;
			contract.ImportFolderType = this.ImportFolderType;
			contract.ImportFolderLocation = this.ImportFolderLocation;
			contract.ImportFolderName = this.ImportFolderName;
			contract.IsDropSource = this.IsDropSource;
			contract.IsDropDestination = this.IsDropDestination;
			contract.IsWatched = this.IsWatched;

			return contract;
		}
        public Contract_ImportFolder_SaveResponse SaveImportFolder(Contract_ImportFolder contract)
        {
            Contract_ImportFolder_SaveResponse response = new Contract_ImportFolder_SaveResponse();
            response.ErrorMessage = "";
            response.ImportFolder = null;

            try
            {
                ImportFolder ns = null;
                if (contract.ImportFolderID.HasValue && contract.ImportFolderID != 0)
                {
                    // update
                    ns = RepoFactory.ImportFolder.GetByID(contract.ImportFolderID.Value);
                    if (ns == null)
                    {
                        response.ErrorMessage = "Could not find Import Folder ID: " +
                                                contract.ImportFolderID.Value.ToString();
                        return response;
                    }
                }
                else
                {
                    // create
                    ns = new ImportFolder();
                }

                if (string.IsNullOrEmpty(contract.ImportFolderName))
                {
                    response.ErrorMessage = "Must specify an Import Folder name";
                    return response;
                }

                if (string.IsNullOrEmpty(contract.ImportFolderLocation))
                {
                    response.ErrorMessage = "Must specify an Import Folder location";
                    return response;
                }

                if (contract.CloudID==null && !Directory.Exists(contract.ImportFolderLocation))
                {
                    response.ErrorMessage = "Cannot find Import Folder location";
                    return response;
                }

                if (!contract.ImportFolderID.HasValue)
                {
                    ImportFolder nsTemp = RepoFactory.ImportFolder.GetByImportLocation(contract.ImportFolderLocation);
                    if (nsTemp != null)
                    {
                        response.ErrorMessage = "An entry already exists for the specified Import Folder location";
                        return response;
                    }
                }

                if (contract.IsDropDestination == 1 && contract.IsDropSource == 1)
                {
                    response.ErrorMessage = "A folder cannot be a drop source and a drop destination at the same time";
                    return response;
                }

                // check to make sure we don't have multiple drop folders
                IReadOnlyList<ImportFolder> allFolders = RepoFactory.ImportFolder.GetAll();

                if (contract.IsDropDestination == 1)
                {
                    foreach (ImportFolder imf in allFolders)
                    {
                        if (contract.CloudID==imf.CloudID && imf.IsDropDestination == 1 && (!contract.ImportFolderID.HasValue || (contract.ImportFolderID.Value != imf.ImportFolderID)))
                        {
                            imf.IsDropDestination = 0;
                            RepoFactory.ImportFolder.Save(imf);
                        }
                    }
                }

                ns.ImportFolderName = contract.ImportFolderName;
                ns.ImportFolderLocation = contract.ImportFolderLocation;
                ns.IsDropDestination = contract.IsDropDestination;
                ns.IsDropSource = contract.IsDropSource;
                ns.IsWatched = contract.IsWatched;
                ns.ImportFolderType = contract.ImportFolderType;
                ns.CloudID = contract.CloudID.HasValue && contract.CloudID == 0 ? null : contract.CloudID; ;
                RepoFactory.ImportFolder.Save(ns);

                response.ImportFolder = ns.ToContract();
                System.Windows.Application.Current.Dispatcher.Invoke(() =>
                {
                    ServerInfo.Instance.RefreshImportFolders();
                });
                MainWindow.StopWatchingFiles();
                MainWindow.StartWatchingFiles();

                return response;
            }
            catch (Exception ex)
            {
                logger.Error(ex, ex.ToString());
                response.ErrorMessage = ex.Message;
                return response;
            }
        }