private async void ConnPane_OnConnected(object sender, ConnectEventArgs e)
        {
            await GetCrmData();

            if (!ConfigFile.ConfigFileExists(_dte.Solution.FullName))
            {
                ConfigFile.CreateConfigFile(ConnPane.OrganizationId, ConnPane.SelectedProject.UniqueName, _dte.Solution.FullName);
            }
        }
예제 #2
0
        private void ConnPane_OnConnected(object sender, ConnectEventArgs e)
        {
            SetButtonState(true);
            LoadData();

            //TODO: better place for this?
            if (!ConfigFile.ConfigFileExists(_dte.Solution.FullName))
            {
                ConfigFile.CreateConfigFile(ConnPane.OrganizationId, ConnPane.SelectedProject.UniqueName, _dte.Solution.FullName);
            }
        }
예제 #3
0
        private void frmMain_v2_Load(object sender, EventArgs e)
        {
            // Dump out
            return;

            // Go through and copy the files
            //List<string> listF = Directory.GetFiles(@"D:\tmpTransfer\2017-03-19-iMaintTest\", "*.mdb").ToList();
            //string lPath = @"D:\tmpTransfer\2017-03-19-iMaintTest\";
            //int counter = listF.Count - 1;
            //string name1 = new FileInfo(listF[counter]).Name.Replace("IAR_", "").Replace(".mdb", "");
            //int index = int.Parse(name1);
            //name1 = "IAR_" + int.Parse(name1).ToString().PadLeft(7, '0') + ".mdb";
            //string origFileName = string.Empty;
            //while (index > 0)
            //{
            //	if (File.Exists(Path.Combine(lPath, name1)))
            //	{
            //		// The file exists - don't do anything
            //	}
            //	else
            //	{
            //		// Copy the file
            //		origFileName = listF[counter];
            //		File.Copy(origFileName, Path.Combine(lPath, name1));
            //	}
            //	index--;
            //	counter--;
            //	if (counter < 0) { counter = listF.Count - 1; }
            //	name1 = "IAR_" + index.ToString().PadLeft(7, '0') + ".mdb";
            //}
            //Application.Exit();


            // When the form loads, start the process
            // Present the form
            this.Show();
            //lst.Items.Clear();
            //prgMain.Value = 0;
            Application.DoEvents();

            // Build out the grid with the events/status
            BuildGrid();

            // Check to see if the shift key is down
            bool showConfigForm = false;

            //if ((ModifierKeys & Keys.Shift) != 0)
            //{
            //	// Show the configuration form
            //	showConfigForm = true;
            //}

            // Run some checks
            // Check for the config file in the same running directory
            // If it doesn't exist,
            if (!ConfigFile.ConfigFileExists())
            {
                showConfigForm = true;
            }

            //if (showConfigForm)
            //{
            //	layoutMain.Enabled = false;
            //	frmDialogConfig frm = new frmDialogConfig();
            //	frm.ParentForm = this;
            //	if (frm.ShowDialog() == DialogResult.OK)
            //	{
            //		_sourceDirectory = ConfigFile.GetSourcePath();
            //		_targetDirectory = ConfigFile.GetTargetPath();
            //		_ACCDB = ConfigFile.GetType().ToLower().StartsWith("a");
            //	}
            //	else
            //	{
            //		// Shut down the application
            //		PostError("Configuration not valid.");
            //		_buildItemCollection["CheckConfig"].ItemIcon = BuildItemIcon.Error;
            //		gridViewStatus.RefreshData();
            //		layoutMain.Enabled = true;
            //		return;
            //	}
            //	layoutMain.Enabled = true;
            //}
            //else
            //{
            //	// Just get the values
            //	_sourceDirectory = ConfigFile.GetSourcePath();
            //	_targetDirectory = ConfigFile.GetTargetPath();
            //	_ACCDB = ConfigFile.GetType().ToLower().StartsWith("a");
            //}

            // Update the messages for config
            _buildItemCollection["CheckConfig"].UpdateMessage("Configuration Good.", 100);
            RefreshGrid();

            // Check to make sure we can read from the remote path
            string fileNamePrefix = string.Empty;

            try
            {
                List <string> listFiles = Directory.GetFiles(_sourceDirectory, "*.accdb").ToList <string>();
                if (!_ACCDB)
                {
                    listFiles = Directory.GetFiles(_sourceDirectory, "*.mdb").ToList <string>();
                }

                // Go through and get the file name prefix from the file (everything up until the first number)
                if (listFiles.Count > 0)
                {
                    string tmpFileName = listFiles[0];
                    for (int i = 0; i < tmpFileName.Length - 1; i++)
                    {
                        if (tmpFileName.Substring(i, 1).IndexOfAny("0123456789".ToCharArray()) > -1)
                        {
                            break;
                        }
                        else
                        {
                            fileNamePrefix += tmpFileName.Substring(i, 1);
                        }
                    }
                }
                _buildItemCollection["ReadRemote"].UpdateMessage("Remote Files Read.", 100);
                RefreshGrid();

                // Check to see how many files we have in the remote directory
                if (showConfigForm &&
                    listFiles.Count > 250)
                {
                    if (MessageBox.Show("There are more than 250 files on the remote server.  Large amounts " +
                                        "of files can cause the program to run longer.\r\n\r\nDid you want this program to attempt " +
                                        "deleting these files down to the most recent 50?\r\n\r\n(Please make sure you have a " +
                                        "recent backup before continuing.)", "Large File Count",
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                                        MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                    {
                        try
                        {
                            List <string> localList = Directory.GetFiles(_sourceDirectory, "*.accdb").ToList <string>();
                            if (!_ACCDB)
                            {
                                localList = Directory.GetFiles(_sourceDirectory, "*.mdb").ToList <string>();
                            }
                            localList.Sort();
                            int loopCount = 0;
                            for (int itemCount = localList.Count - 1; itemCount >= 0; itemCount--)
                            {
                                if (itemCount < 0)
                                {
                                    break;
                                }
                                localList.RemoveAt(itemCount);
                                loopCount++;
                                if (loopCount > 50)
                                {
                                    break;
                                }

                                // Show a message to say that the delete worked
                                MessageBox.Show("The system deleted the files.", "Successful Delete",
                                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }
                        catch (Exception ex)
                        {
                            // We weren't unable to delete the files - let the user know
                            MessageBox.Show("The system was unable to delete these files.\r\n\r\n" +
                                            "Please use another method to delete these files from the server.\r\n\r\n" +
                                            "(Error: " + ex.Message + ")", "Unable to Delete", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Shut down the application
                PostError("Could not read from remote directory: \r\n" + _sourceDirectory);
                _buildItemCollection["ReadRemote"].ItemIcon = BuildItemIcon.Error;
                //gridViewStatus.RefreshData();
                return;
            }

            // Check to make sure we can write to the local target directory
            try
            {
                // Create a local file on the target directory and delete it
                string     tempFile = Path.Combine(_targetDirectory, "tst.txt");
                TextWriter wt       = File.AppendText(tempFile);
                TextWriter.Synchronized(wt);
                wt.WriteLine("Testing Write.");
                wt.Close();

                // Delete the file
                if (File.Exists(tempFile))
                {
                    File.Delete(tempFile);
                }

                _buildItemCollection["WriteLocal"].UpdateMessage("Local Write Complete.", 100);
                RefreshGrid();
            }
            catch (Exception ex)
            {
                // Shut down the application
                PostError("Could not write to local directory: " + _targetDirectory + "\r\n" + ex.Message);
                _buildItemCollection["WriteLocal"].ItemIcon = BuildItemIcon.Error;
                //gridViewStatus.RefreshData();
                return;
            }

            // Write the source and target directories
            _buildItemCollection["SourceDir"].UpdateMessage(_sourceDirectory, 100);
            _buildItemCollection["TargetDir"].UpdateMessage(_targetDirectory, 100);
            RefreshGrid();

            // Turn off the code for VBA Warnings so we can start the program without incident
            //if (System.Environment.MachineName.ToLower() != "programmer-ntbk" &&
            //	System.Environment.MachineName.ToLower() != "isspprog-12")
            //{
            try
            {
                bool vbaWarningsKeyExists = false;
                using (RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Office"))
                {
                    foreach (string v in key.GetSubKeyNames())
                    {
                        if (v == "11.0" ||
                            v == "12.0" ||
                            v == "14.0")
                        {
                            // Try to open the access key
                            using (RegistryKey verKey = key.OpenSubKey(v))
                            {
                                foreach (string accessKey in verKey.GetSubKeyNames())
                                {
                                    if (accessKey.ToLower() == "access")
                                    {
                                        using (RegistryKey securityKey = verKey.OpenSubKey("Access\\Security", true))
                                        {
                                            vbaWarningsKeyExists = false;
                                            foreach (string val in securityKey.GetValueNames())
                                            {
                                                if (val == "VBAWarnings")
                                                {
                                                    vbaWarningsKeyExists = true;
                                                    break;
                                                }
                                            }
                                            if (!vbaWarningsKeyExists)
                                            {
                                                // Create the key
                                                securityKey.SetValue("VBAWarnings", 1, RegistryValueKind.DWord);
                                                //AddStatus("Adding VBAWarnings registry value.");
                                            }
                                            else
                                            {
                                                // Check to make sure the value of the key is "1"
                                                if (securityKey.GetValue("VBAWarnings").ToString() != "1")
                                                {
                                                    securityKey.SetValue("VBAWarnings", 1, RegistryValueKind.DWord);
                                                    //AddStatus("Modifying VBAWarnings registry value.");
                                                }
                                            }
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                _buildItemCollection["CheckVBA"].UpdateMessage("VBA Warning Set.", 100);
                RefreshGrid();
            }
            catch (Exception ex)
            {
                //AddStatus("Could not set registry value.");
            }
            //}

            // Find the target file name
            string remoteFileName = string.Empty, localFileName = string.Empty;

            try
            {
                _buildItemCollection["FindFileName"].UpdateMessage("Copying File...", 50);
                RefreshGrid();
                int           maxNum       = 0;
                string        lastFileName = string.Empty;
                List <string> list         = Directory.GetFiles(_sourceDirectory, "*.accdb").ToList <string>();
                if (!_ACCDB)
                {
                    list = Directory.GetFiles(_sourceDirectory, "*.mdb").ToList <string>();
                }
                StringBuilder sb = new StringBuilder();
                foreach (string s in list)
                {
                    try
                    {
                        FileInfo info = new FileInfo(s);
                        //string name = info.Name;
                        string name = info.Name.Substring(info.Name.IndexOf("_") + 1);
                        name = name.Substring(0, name.IndexOf("."));

                        int num = int.Parse(name);
                        if (num > maxNum)
                        {
                            maxNum       = num;
                            lastFileName = info.Name;
                        }
                    }
                    catch
                    {
                        // Do nothing
                    }
                }
                if (maxNum == 0)
                {
                    MessageBox.Show("No file could be found to copy...",
                                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    Application.Exit();
                    return;
                }
                string fileName = lastFileName;                 //"IAR_" + maxNum.ToString().PadLeft(6, '0') + ".mdb";
                remoteFileName = Path.Combine(_sourceDirectory, fileName);
                localFileName  = Path.Combine(_targetDirectory, fileName);
            }
            catch (Exception ex)
            {
                PostError("Could not copy file: " + remoteFileName + "\r\n" + ex.Message);
                _buildItemCollection["FindFileName"].ItemIcon = BuildItemIcon.Error;
                //gridViewStatus.RefreshData();
                return;
            }
            _buildItemCollection["FindFileName"].UpdateMessage("Copy File Complete.", 100);

            // If the local file is the same as the remote file, and it already exists, just load it
            if (!String.IsNullOrEmpty(localFileName) &&
                File.Exists(localFileName))
            {
                System.Diagnostics.Process.Start(localFileName);
                Application.Exit();
                return;
            }

            // Delete any files that might exist in the local directory
            try
            {
                List <string> list = Directory.GetFiles(_targetDirectory, "*.accdb").ToList <string>();
                if (!_ACCDB)
                {
                    list = Directory.GetFiles(_targetDirectory, "*.mdb").ToList <string>();
                }
                list.Sort();
                foreach (string s in list)
                {
                    FileInfo info = new FileInfo(s);
                    File.Delete(s);                         // Delete the local file
                }
                _buildItemCollection["DeleteLocal"].UpdateMessage("Local Files Deleted.", 100);
                RefreshGrid();
            }
            catch (Exception ex)
            {
                PostError("Could not delete local files: " + _targetDirectory + "\r\n" + ex.Message);
                _buildItemCollection["DeleteLocal"].ItemIcon = BuildItemIcon.Error;
                //gridViewStatus.RefreshData();
                return;
            }

            // Find the most recent file name
            remoteFileName = localFileName = string.Empty;
            try
            {
                _buildItemCollection["CopyFromRemote"].UpdateMessage("Copying File...", 1);
                RefreshGrid();
                int           maxNum       = 0;
                string        lastFileName = string.Empty;
                List <string> list         = Directory.GetFiles(_sourceDirectory, "*.accdb").ToList <string>();
                if (!_ACCDB)
                {
                    list = Directory.GetFiles(_sourceDirectory, "*.mdb").ToList <string>();
                }
                StringBuilder sb = new StringBuilder();
                foreach (string s in list)
                {
                    try
                    {
                        FileInfo info = new FileInfo(s);
                        //string name = info.Name;
                        string name = info.Name.Substring(info.Name.IndexOf("_") + 1);
                        name = name.Substring(0, name.IndexOf("."));

                        int num = int.Parse(name);
                        if (num > maxNum)
                        {
                            maxNum       = num;
                            lastFileName = info.Name;
                        }
                    }
                    catch
                    {
                        // Do nothing
                    }
                }
                if (maxNum == 0)
                {
                    MessageBox.Show("No file could be found to copy...",
                                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    Application.Exit();
                    return;
                }
                string fileName = lastFileName;                 //"IAR_" + maxNum.ToString().PadLeft(6, '0') + ".mdb";
                remoteFileName = Path.Combine(_sourceDirectory, fileName);
                localFileName  = Path.Combine(_targetDirectory, fileName);

                // Copy the files over from the server
                Callback myCallback = new Callback(Report);

                bool cancel = false;
                bool ret    = CopyFileEx(
                    remoteFileName,
                    localFileName,
                    myCallback,
                    System.IntPtr.Zero,
                    ref cancel,
                    CopyFileFlags.COPY_FILE_FAIL_IF_EXISTS);
            }
            catch (Exception ex)
            {
                PostError("Could not copy file: " + remoteFileName + "\r\n" + ex.Message);
                _buildItemCollection["CopyFromRemote"].ItemIcon = BuildItemIcon.Error;
                //gridViewStatus.RefreshData();
                return;
            }
            _buildItemCollection["CopyFromRemote"].UpdateMessage("Copy File Complete.", 100);

            _buildItemCollection["StartApp"].UpdateMessage("Starting Application.", 50);
            RefreshGrid();
            this.BringToFront();
            Application.DoEvents();
            //System.Threading.Thread.Sleep(5000);

            // Start the file and terminate this application
            System.Diagnostics.Process.Start(localFileName);

            Application.Exit();
        }
예제 #4
0
 public void ConfigFileExists_True()
 {
     Assert.IsTrue(ConfigFile.ConfigFileExists(_testFilepath));
 }
예제 #5
0
 public void ConfigFileExists_False()
 {
     Assert.IsFalse(ConfigFile.ConfigFileExists(Environment.CurrentDirectory));
 }
 private static CrmDexExConfig GetConfigFile(string solutionPath, string projectUniqueName, Guid organizationId)
 {
     return(!ConfigFile.ConfigFileExists(solutionPath) ?
            ConfigFile.CreateConfigFile(organizationId, projectUniqueName, solutionPath) :
            ConfigFile.GetConfigFile(solutionPath));
 }