Пример #1
0
        private void RunDelivery()
        {
            tsslblStatus.Text = "Cleaning up Input folder ...";
            clsFunction.CleanupInput();
            tsslblStatus.Text = "Delivery console app is running. Please wait ...";
            Program.ShowWindow(Program.handle, 5);
            if (clsDelivery.TransmittalInitialize())
            {
                try
                {
                    listEnum.ForEach(x =>
                    {
                        try
                        {
                            project = clsFunction.StringToEnum(x);

                            clsDelivery.Delivery(project);

                            if (!string.IsNullOrEmpty(clsVariable.JobnamesPath))
                            {
                                dataGridView1.Rows.Add(new string[]
                                {
                                    x,
                                    clsDelivery.RemoteSFtpPart,
                                    clsVariable.projectPath,
                                    clsVariable.nextPartPath,
                                    clsVariable.JobnamesPath
                                });
                            }
                        }
                        finally
                        {
                            clsDelivery.RemoteSFtpPart                     = string.Empty;
                            clsVariable.projectPath                        = string.Empty;
                            clsVariable.nextPartPath                       = string.Empty;
                            clsVariable.JobnamesPath                       = string.Empty;
                            clsVariable.listPartFolders                    = null;
                            clsVariable.listFileInfosCaselaw               = null;
                            clsVariable.listFileInfosNonVirgo              = null;
                            clsVariable.listFileInfosVirgo                 = null;
                            clsVariable.listFileInfosStateNet              = null;
                            clsVariable.listDirectoryInfosNonVirgo         = null;
                            clsVariable.listDirectoryInfosCaseRelated      = null;
                            clsVariable.listDirectoryInfosStateNet         = null;
                            clsVariable.listDirectoryInfosSecuritiesMosaic = null;
                            clsVariable.TransmittalFileInfos               = null;
                        }
                    });
                }
                finally
                {
                    clsDelivery.SaveAsLNSchedule();
                    clsDelivery.LNScheduleBackup();
                    Program.ShowWindow(Program.handle, 0);
                    clsFunction.ReleaseMemory();

                    if (dataGridView1.Rows.Count > 0)
                    {
                        if (dataGridView1.Rows.Count > 1)
                        {
                            if (dataGridView1.Rows[0].Cells[0].Value != null)
                            {
                                var msg = MessageBox.Show("Upload all files ?", "Infomation", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                                if (msg == DialogResult.Yes)
                                {
                                    RunUpload();
                                }
                                else
                                {
                                    clsFunction.ReleaseMemory();
                                }
                            }
                        }
                    }
                    tsslblStatus.Text = "Done.";
                }
            }
            else
            {
                if (clsVariable.isAutoRun)
                {
                    clsConsole.WriteLine("\r\n LN Schedule in used by another process. Program will restart after 5 minutes.", ConsoleColor.Red);
                    System.Threading.Thread.Sleep(5000);
                    clsFunction.RestartApp(5);
                }
                else
                {
                    var msg = MessageBox.Show("LN Schedule in used by another process. Please close the excel files then press retry, if not please cancel.", "Warning", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning);
                    if (msg == DialogResult.Retry)
                    {
                        RunDelivery();
                    }
                    else
                    {
                        Program.ShowWindow(Program.handle, 0);
                    }
                }
            }
        }
Пример #2
0
        public static void sFtpUploadFiles(clsVariable.ProjectSet projectSet, string strProjectPath, string strNextPart)
        {
            if (Directory.Exists(strNextPart))
            {
                Console.Clear();
                clsConsole.WriteLine(string.Format("\r\n  *****************  Starting upload: {0}", strNextPart), ConsoleColor.Cyan);
                if (sFtpCheckConnection())
                {
                    using (sFtpClient = new SftpClient(connectionInfo))
                    {
                        sFtpClient.Connect();

                        if (sFtpClient.IsConnected)
                        {
                            switch (projectSet)
                            {
                            case clsVariable.ProjectSet.Caselaw:
                                RemoteSFtpPart = strNextPart.Replace(strProjectPath, rmCaselawPath).Replace(@"\", "/");
                                break;

                            case clsVariable.ProjectSet.NonVirgo:
                                RemoteSFtpPart = strNextPart.Replace(strProjectPath, rmNonVirgoPath).Replace(@"\", "/");
                                break;

                            case clsVariable.ProjectSet.Virgo:
                                RemoteSFtpPart = strNextPart.Replace(strProjectPath, rmVirgoPath).Replace(@"\", "/");
                                break;

                            case clsVariable.ProjectSet.CaseRelated:
                                RemoteSFtpPart = strNextPart.Replace(strProjectPath, rmCaseRelatedPath).Replace(@"\", "/");
                                break;

                            case clsVariable.ProjectSet.StateNet:
                                RemoteSFtpPart = strNextPart.Replace(strProjectPath, rmStateNetPath).Replace(@"\", "/");
                                break;

                            case clsVariable.ProjectSet.SecuritiesMosaic:
                                RemoteSFtpPart = strNextPart.Replace(strProjectPath, rmSecuritiesMosaicPath).Replace(@"\", "/");
                                break;
                            }

                            if (!sFtpCheckFolderExists(RemoteSFtpPart))
                            {
                                clsConsole.WriteLine(string.Format("\r\n  ** Create remote sFtp Path: {0}", RemoteSFtpPart), ConsoleColor.Green);

                                sFtpClient.CreateDirectory(RemoteSFtpPart);

                                Match m = Regex.Match(RemoteSFtpPart, "(CASELAW_XML|NON VIRGO|VIRGO_XML|CASE RELATED|STATE_NET|SECURITIES MOSAIC)", RegexOptions.RightToLeft);
                                switch (m.Value)
                                {
                                case "CASELAW_XML":
                                    clsReports.sFtpPathReports.Caselaw = RemoteSFtpPart;
                                    break;

                                case "NON VIRGO":
                                    clsReports.sFtpPathReports.NonVirgo = RemoteSFtpPart;
                                    break;

                                case "VIRGO_XML":
                                    clsReports.sFtpPathReports.Virgo = RemoteSFtpPart;
                                    break;

                                case "CASE RELATED":
                                    clsReports.sFtpPathReports.CaseRelated = RemoteSFtpPart;
                                    break;

                                case "STATE_NET":
                                    clsReports.sFtpPathReports.StateNet = RemoteSFtpPart;
                                    break;

                                case "SECURITIES MOSAIC":
                                    clsReports.sFtpPathReports.SecuritiesMosaic = RemoteSFtpPart;
                                    break;
                                }
                            }

                            string        filePath      = string.Empty;
                            DirectoryInfo directoryInfo = new DirectoryInfo(strNextPart);

                            switch (projectSet)
                            {
                            case clsVariable.ProjectSet.NonVirgo:
                            case clsVariable.ProjectSet.StateNet:
                                foreach (DirectoryInfo dir in directoryInfo.GetDirectories("*", System.IO.SearchOption.AllDirectories))
                                {
                                    RemoteSFtpDir = dir.FullName.Replace(strNextPart, RemoteSFtpPart).Replace(@"\", "/") + "/";

                                    if (!sFtpCheckFolderExists(RemoteSFtpDir))
                                    {
                                        try
                                        {
                                            clsConsole.Write(string.Format("  *** Create remote sFtp Folders & Sub Folders: {0}", RemoteSFtpDir), ConsoleColor.DarkGray);
                                            sFtpClient.CreateDirectory(RemoteSFtpDir);
                                        }
                                        finally
                                        {
                                            clsConsole.WriteLine(" ... ok", ConsoleColor.Green);
                                        }
                                    }
                                }

                                clsConsole.WriteLine("\r\n  ** Starting upload file ...", ConsoleColor.Green);
                                foreach (FileInfo file in directoryInfo.GetFiles("*.*", System.IO.SearchOption.AllDirectories))
                                {
                                    if (!Regex.IsMatch(file.Name, "(D0KDV|D0VJE)", RegexOptions.IgnoreCase))
                                    {
                                        using (var FileStream = File.OpenRead(file.FullName))
                                        {
                                            try
                                            {
                                                RemoteSFtpDir = file.DirectoryName.Replace(strNextPart, RemoteSFtpPart).Replace(@"\", "/") + "/";
                                                if (!sFtpCheckFolderExists(RemoteSFtpDir))
                                                {
                                                    sFtpClient.CreateDirectory(RemoteSFtpDir);
                                                }
                                                RemoteSFtpFilePath = RemoteSFtpDir + file.Name;
                                                clsConsole.Write(string.Format("  *** Uploading file: {0}", RemoteSFtpFilePath), ConsoleColor.DarkGray);
                                                sFtpClient.UploadFile(FileStream, RemoteSFtpFilePath, true);
                                            }
                                            finally
                                            {
                                                clsConsole.WriteLine(" ... ok", ConsoleColor.Green);
                                            }
                                        }
                                    }
                                }
                                break;

                            default:
                                foreach (FileInfo file in directoryInfo.GetFiles("*.zip"))
                                {
                                    using (var FileStream = File.OpenRead(file.FullName))
                                    {
                                        try
                                        {
                                            RemoteSFtpDir = file.DirectoryName.Replace(strNextPart, RemoteSFtpPart).Replace(@"\", "/") + "/";
                                            if (!sFtpCheckFolderExists(RemoteSFtpDir))
                                            {
                                                sFtpClient.CreateDirectory(RemoteSFtpDir);
                                            }
                                            RemoteSFtpFilePath = RemoteSFtpDir + file.Name;
                                            clsConsole.Write(string.Format("  *** Uploading file: {0}", RemoteSFtpFilePath), ConsoleColor.DarkGray);
                                            sFtpClient.UploadFile(FileStream, RemoteSFtpFilePath, true);
                                        }
                                        finally
                                        {
                                            clsConsole.WriteLine(" ... ok", ConsoleColor.Green);
                                        }
                                    }
                                }
                                break;
                            }

                            sFtpClient.Disconnect();
                        }
                    }
                }
            }
        }