Beispiel #1
0
 private void comboBoxProfiles_SelectedIndexChanged(object sender, EventArgs e)
 {
     comboBoxConnectionSource.SelectedItem = null;
     if (comboBoxProfiles.SelectedItem != null)
     {
         currentProfile          = man.Profiles[comboBoxProfiles.SelectedIndex];
         textBoxProfileName.Text = currentProfile.ProfileName;
         comboBoxConnectionSource.SelectedItem = currentProfile.SourceConnectionName;
         comboBoxWorkflows.SelectedItem        = currentProfile.WorkflowName;
         xmlEditor1.Text = currentProfile.FetchXMLQuery;
         deleteProfileToolStripMenuItem.Enabled = true;
         newToolStripMenuItem.Enabled           = true;
         saveToolStripMenuItem.Enabled          = true;
         textBoxProfileName.Enabled             = false;
         runProfileToolStripMenuItem.Enabled    = true;
     }
     else
     {
         currentProfile                         = null;
         textBoxProfileName.Text                = "";
         comboBoxWorkflows.SelectedItem         = null;
         deleteProfileToolStripMenuItem.Enabled = false;
         newToolStripMenuItem.Enabled           = false;
         saveToolStripMenuItem.Enabled          = false;
         textBoxProfileName.Enabled             = true;
         runProfileToolStripMenuItem.Enabled    = false;
     }
 }
Beispiel #2
0
        /// <summary>
        /// Deletes the Workflow Execution profile.
        /// </summary>
        /// <param name="profile">The Workflow Execution profile.</param>
        /// <exception cref="System.Exception">Workflow Execution Profile deletion failed. The Workflow Execution Profile  + profile.ProfileName +  was not found in the configuration file.</exception>
        public void DeleteProfile(MSCRMWorkflowExecutionProfile profile)
        {
            int index = Profiles.FindIndex(d => d.ProfileName == profile.ProfileName);

            if (index > -1)
            {
                Profiles.RemoveAt(index);
            }
            else
            {
                LogManager.WriteLog("Workflow Execution Profile deletion failed. The Workflow Execution Profile " + profile.ProfileName + " was not found in the configuration file.");
                throw new Exception("Workflow Execution Profile deletion failed. The Workflow Execution Profile " + profile.ProfileName + " was not found in the configuration file.");
            }

            //Delete Profile folder
            try
            {
                if (Directory.Exists(Folder + "\\" + profile.ProfileName))
                {
                    Directory.Delete(Folder + "\\" + profile.ProfileName, true);
                }
            }
            catch (Exception)
            {
                throw;
            }

            //Save Profiles
            WriteProfiles();
        }
        /// <summary>
        /// Creates the Workflow Execution profile.
        /// </summary>
        /// <param name="profile">The profile.</param>
        public void CreateProfile(MSCRMWorkflowExecutionProfile profile)
        {
            if (!Directory.Exists(Folder + "\\" + profile.ProfileName))
                Directory.CreateDirectory(Folder + "\\" + profile.ProfileName);

            //Creating new Profile
            Profiles.Add(profile);
            WriteProfiles();
        }
Beispiel #4
0
        /// <summary>
        /// Creates the Workflow Execution profile.
        /// </summary>
        /// <param name="profile">The profile.</param>
        public void CreateProfile(MSCRMWorkflowExecutionProfile profile)
        {
            if (!Directory.Exists(Folder + "\\" + profile.ProfileName))
            {
                Directory.CreateDirectory(Folder + "\\" + profile.ProfileName);
            }

            //Creating new Profile
            Profiles.Add(profile);
            WriteProfiles();
        }
Beispiel #5
0
        /// <summary>
        /// Runs the Workflow Execution profile.
        /// </summary>
        /// <param name="profile">The profile.</param>
        public void RunProfile(MSCRMWorkflowExecutionProfile profile)
        {
            LogManager.WriteLog("Running Workflow Execution Profile: " + profile.ProfileName);

            try
            {
                MSCRMConnection connection = profile.getSourceConneciton();
                _serviceProxy = cm.connect(connection);

                EntityCollection result = _serviceProxy.RetrieveMultiple(new FetchExpression(profile.FetchXMLQuery));

                foreach (Entity record in result.Entities)
                {
                    ExecuteWorkflowRequest request = new ExecuteWorkflowRequest()
                    {
                        WorkflowId = profile.WorkflowId,
                        EntityId   = record.Id
                    };

                    // Execute the workflow.
                    ExecuteWorkflowResponse response = (ExecuteWorkflowResponse)_serviceProxy.Execute(request);
                }
            }
            catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> ex)
            {
                LogManager.WriteLog("Error:" + ex.Detail.Message + "\n" + ex.Detail.TraceText);
                throw;
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    LogManager.WriteLog("Error:" + ex.Message + "\n" + ex.InnerException.Message);
                }
                else
                {
                    LogManager.WriteLog("Error:" + ex.Message);
                }
                throw;
            }
            LogManager.WriteLog("All workflows were launched.");
        }
Beispiel #6
0
        /// <summary>
        /// Updates the Workflow Execution profile.
        /// </summary>
        /// <param name="profile">The Workflow Execution profile.</param>
        /// <exception cref="System.Exception">Data Export Profile Update failed. The Data Export Profile  + profile.ProfileName +  was not found in the configuration file.</exception>
        public void UpdateProfile(MSCRMWorkflowExecutionProfile profile)
        {
            if (!Directory.Exists(Folder + "\\" + profile.ProfileName))
            {
                Directory.CreateDirectory(Folder + "\\" + profile.ProfileName);
            }

            int index = Profiles.FindIndex(d => d.ProfileName == profile.ProfileName);

            if (index > -1)
            {
                Profiles[index] = profile;
            }
            else
            {
                LogManager.WriteLog("Data Export Profile Update failed. The Data Export Profile " + profile.ProfileName + " was not found in the configuration file.");
                throw new Exception("Data Export Profile Update failed. The Data Export Profile " + profile.ProfileName + " was not found in the configuration file.");
            }

            WriteProfiles();
        }
Beispiel #7
0
        private void deleteProfileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string       currentProfileName = currentProfile.ProfileName;
            DialogResult dResTest;

            dResTest = MessageBox.Show("Are you sure you want to delete this Profile ?", "Confirm Profile Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (dResTest == DialogResult.No)
            {
                return;
            }
            else
            {
                comboBoxProfiles.Items.Remove(currentProfile.ProfileName);
                comboBoxProfiles.SelectedItem = null;
                man.DeleteProfile(currentProfile);
                currentProfile                        = null;
                textBoxProfileName.Text               = "";
                xmlEditor1.Text                       = "";
                textBoxProfileName.Enabled            = true;
                comboBoxConnectionSource.SelectedItem = null;
                toolStripStatusLabel1.Text            = "Profile " + currentProfileName + " deleted";
            }
        }
        private bool SaveProfile()
        {
            bool result = true;
            //Check that all fields are provided
            if (string.IsNullOrEmpty(textBoxProfileName.Text))
            {
                MessageBox.Show("Profile Name is mandatory!");
                return false;
            }

            //Check that the name of the connection is valid
            if (textBoxProfileName.Text.Contains(" ") ||
                    textBoxProfileName.Text.Contains("\\") ||
                    textBoxProfileName.Text.Contains("/") ||
                    textBoxProfileName.Text.Contains(">") ||
                    textBoxProfileName.Text.Contains("<") ||
                    textBoxProfileName.Text.Contains("?") ||
                    textBoxProfileName.Text.Contains("*") ||
                    textBoxProfileName.Text.Contains(":") ||
                    textBoxProfileName.Text.Contains("|") ||
                    textBoxProfileName.Text.Contains("\"") ||
                    textBoxProfileName.Text.Contains("'")
                    )
            {
                MessageBox.Show("You shouldn't use spaces nor the following characters (\\/<>?*:|\"') in the Profile Name as it will be used to create folders and files.");
                return false;
            }

            if (comboBoxConnectionSource.SelectedItem == null)
            {
                MessageBox.Show("You must select a Source for the Profile");
                return false;
            }

            if (comboBoxWorkflows.SelectedItem == null)
            {
                MessageBox.Show("You must select a Workflow for the Profile");
                return false;
            }

            //Vérify that the query was provided
            if (xmlEditor1.Text == "")
            {
                MessageBox.Show("You must provide a Query for the records!");
                return false;
            }

            //Check if this is a creation
            if (currentProfile == null)
            {
                //Check if a Data Export Profile having the same name exist already
                MSCRMWorkflowExecutionProfile existingProfile = man.Profiles.Find(d => d.ProfileName.ToLower() == textBoxProfileName.Text.ToLower());
                if (existingProfile != null)
                {
                    MessageBox.Show("Profile with the name " + textBoxProfileName.Text + " exist already. Please select another name");
                    return false;
                }

                MSCRMWorkflowExecutionProfile newProfile = new MSCRMWorkflowExecutionProfile();
                newProfile.ProfileName = textBoxProfileName.Text;
                newProfile.SourceConnectionName = comboBoxConnectionSource.SelectedItem.ToString();
                newProfile.setSourceConneciton();
                newProfile.WorkflowId = this.Workflows.Find(w => w.Name == comboBoxWorkflows.SelectedItem.ToString()).Id;
                newProfile.WorkflowName = comboBoxWorkflows.SelectedItem.ToString();
                newProfile.FetchXMLQuery = xmlEditor1.Text;
                man.CreateProfile(newProfile);
                comboBoxProfiles.Items.AddRange(new object[] { newProfile.ProfileName });
                comboBoxProfiles.SelectedItem = newProfile.ProfileName;
                currentProfile = newProfile;
            }
            else
            {
                currentProfile.ProfileName = textBoxProfileName.Text;
                currentProfile.SourceConnectionName = comboBoxConnectionSource.SelectedItem.ToString();
                currentProfile.WorkflowId = this.Workflows.Find(w => w.Name == comboBoxWorkflows.SelectedItem.ToString()).Id;
                currentProfile.WorkflowName = comboBoxWorkflows.SelectedItem.ToString();
                currentProfile.FetchXMLQuery = xmlEditor1.Text;
                currentProfile.setSourceConneciton();
                MSCRMWorkflowExecutionProfile oldDEP = man.GetProfile(currentProfile.ProfileName);
                man.UpdateProfile(currentProfile);
            }

            runProfileToolStripMenuItem.Enabled = true;
            toolStripStatusLabel1.Text = "Profile " + currentProfile.ProfileName + " saved.";
            LogManager.WriteLog("Profile " + currentProfile.ProfileName + " saved.");
            return result;
        }
 private void deleteProfileToolStripMenuItem_Click(object sender, EventArgs e)
 {
     string currentProfileName = currentProfile.ProfileName;
     DialogResult dResTest;
     dResTest = MessageBox.Show("Are you sure you want to delete this Profile ?", "Confirm Profile Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
     if (dResTest == DialogResult.No)
     {
         return;
     }
     else
     {
         comboBoxProfiles.Items.Remove(currentProfile.ProfileName);
         comboBoxProfiles.SelectedItem = null;
         man.DeleteProfile(currentProfile);
         currentProfile = null;
         textBoxProfileName.Text = "";
         xmlEditor1.Text = "";
         textBoxProfileName.Enabled = true;
         comboBoxConnectionSource.SelectedItem = null;
         toolStripStatusLabel1.Text = "Profile " + currentProfileName + " deleted";
     }
 }
 private void comboBoxProfiles_SelectedIndexChanged(object sender, EventArgs e)
 {
     comboBoxConnectionSource.SelectedItem = null;
     if (comboBoxProfiles.SelectedItem != null)
     {
         currentProfile = man.Profiles[comboBoxProfiles.SelectedIndex];
         textBoxProfileName.Text = currentProfile.ProfileName;
         comboBoxConnectionSource.SelectedItem = currentProfile.SourceConnectionName;
         comboBoxWorkflows.SelectedItem = currentProfile.WorkflowName;
         xmlEditor1.Text = currentProfile.FetchXMLQuery;
         deleteProfileToolStripMenuItem.Enabled = true;
         newToolStripMenuItem.Enabled = true;
         saveToolStripMenuItem.Enabled = true;
         textBoxProfileName.Enabled = false;
         runProfileToolStripMenuItem.Enabled = true;
     }
     else
     {
         currentProfile = null;
         textBoxProfileName.Text = "";
         comboBoxWorkflows.SelectedItem = null;
         deleteProfileToolStripMenuItem.Enabled = false;
         newToolStripMenuItem.Enabled = false;
         saveToolStripMenuItem.Enabled = false;
         textBoxProfileName.Enabled = true;
         runProfileToolStripMenuItem.Enabled = false;
     }
 }
Beispiel #11
0
        private bool SaveProfile()
        {
            bool result = true;

            //Check that all fields are provided
            if (string.IsNullOrEmpty(textBoxProfileName.Text))
            {
                MessageBox.Show("Profile Name is mandatory!");
                return(false);
            }

            //Check that the name of the connection is valid
            if (textBoxProfileName.Text.Contains(" ") ||
                textBoxProfileName.Text.Contains("\\") ||
                textBoxProfileName.Text.Contains("/") ||
                textBoxProfileName.Text.Contains(">") ||
                textBoxProfileName.Text.Contains("<") ||
                textBoxProfileName.Text.Contains("?") ||
                textBoxProfileName.Text.Contains("*") ||
                textBoxProfileName.Text.Contains(":") ||
                textBoxProfileName.Text.Contains("|") ||
                textBoxProfileName.Text.Contains("\"") ||
                textBoxProfileName.Text.Contains("'")
                )
            {
                MessageBox.Show("You shouldn't use spaces nor the following characters (\\/<>?*:|\"') in the Profile Name as it will be used to create folders and files.");
                return(false);
            }

            if (comboBoxConnectionSource.SelectedItem == null)
            {
                MessageBox.Show("You must select a Source for the Profile");
                return(false);
            }

            if (comboBoxWorkflows.SelectedItem == null)
            {
                MessageBox.Show("You must select a Workflow for the Profile");
                return(false);
            }

            //Vérify that the query was provided
            if (xmlEditor1.Text == "")
            {
                MessageBox.Show("You must provide a Query for the records!");
                return(false);
            }

            //Check if this is a creation
            if (currentProfile == null)
            {
                //Check if a Data Export Profile having the same name exist already
                MSCRMWorkflowExecutionProfile existingProfile = man.Profiles.Find(d => d.ProfileName.ToLower() == textBoxProfileName.Text.ToLower());
                if (existingProfile != null)
                {
                    MessageBox.Show("Profile with the name " + textBoxProfileName.Text + " exist already. Please select another name");
                    return(false);
                }

                MSCRMWorkflowExecutionProfile newProfile = new MSCRMWorkflowExecutionProfile();
                newProfile.ProfileName          = textBoxProfileName.Text;
                newProfile.SourceConnectionName = comboBoxConnectionSource.SelectedItem.ToString();
                newProfile.setSourceConneciton();
                newProfile.WorkflowId    = this.Workflows.Find(w => w.Name == comboBoxWorkflows.SelectedItem.ToString()).Id;
                newProfile.WorkflowName  = comboBoxWorkflows.SelectedItem.ToString();
                newProfile.FetchXMLQuery = xmlEditor1.Text;
                man.CreateProfile(newProfile);
                comboBoxProfiles.Items.AddRange(new object[] { newProfile.ProfileName });
                comboBoxProfiles.SelectedItem = newProfile.ProfileName;
                currentProfile = newProfile;
            }
            else
            {
                currentProfile.ProfileName          = textBoxProfileName.Text;
                currentProfile.SourceConnectionName = comboBoxConnectionSource.SelectedItem.ToString();
                currentProfile.WorkflowId           = this.Workflows.Find(w => w.Name == comboBoxWorkflows.SelectedItem.ToString()).Id;
                currentProfile.WorkflowName         = comboBoxWorkflows.SelectedItem.ToString();
                currentProfile.FetchXMLQuery        = xmlEditor1.Text;
                currentProfile.setSourceConneciton();
                MSCRMWorkflowExecutionProfile oldDEP = man.GetProfile(currentProfile.ProfileName);
                man.UpdateProfile(currentProfile);
            }

            runProfileToolStripMenuItem.Enabled = true;
            toolStripStatusLabel1.Text          = "Profile " + currentProfile.ProfileName + " saved.";
            LogManager.WriteLog("Profile " + currentProfile.ProfileName + " saved.");
            return(result);
        }
Beispiel #12
0
        private static void Main(string[] args)
        {
            //Set the application directory as the current directory
            string appPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);

            appPath = appPath.Replace("file:\\", "");
            Directory.SetCurrentDirectory(appPath);

            MSCRMWorkflowExecutionManager man = new MSCRMWorkflowExecutionManager();
            string selectedProfileName        = "";

            if (args.Length == 0)
            {
                if (man.Profiles.Count == 0)
                {
                    Console.WriteLine("\nNo profiles found.");
                    return;
                }

                //Display all profiles for selection
                Console.WriteLine("\nSpecify the Profile to run (1-{0}) [1] : ", man.Profiles.Count);
                int tpCpt = 1;
                foreach (MSCRMWorkflowExecutionProfile profile in man.Profiles)
                {
                    Console.WriteLine(tpCpt + ". " + profile.ProfileName);
                    tpCpt++;
                }

                String input = Console.ReadLine();
                if (input == String.Empty)
                {
                    input = "1";
                }
                int depNumber;
                Int32.TryParse(input, out depNumber);
                if (depNumber > 0 && depNumber <= man.Profiles.Count)
                {
                    selectedProfileName = man.Profiles[depNumber - 1].ProfileName;
                }
                else
                {
                    Console.WriteLine("The specified Profile does not exist.");
                    return;
                }
            }
            else
            {
                //Check that the Profile name is provided
                if (string.IsNullOrEmpty(args[0]))
                {
                    return;
                }
                selectedProfileName = args[0];
            }

            MSCRMWorkflowExecutionProfile p = man.GetProfile(selectedProfileName);

            if (p == null)
            {
                Console.WriteLine("The specified Profile does not exist.");
                return;
            }

            man.RunProfile(p);
        }
        /// <summary>
        /// Deletes the Workflow Execution profile.
        /// </summary>
        /// <param name="profile">The Workflow Execution profile.</param>
        /// <exception cref="System.Exception">Workflow Execution Profile deletion failed. The Workflow Execution Profile  + profile.ProfileName +  was not found in the configuration file.</exception>
        public void DeleteProfile(MSCRMWorkflowExecutionProfile profile)
        {
            int index = Profiles.FindIndex(d => d.ProfileName == profile.ProfileName);
            if (index > -1)
            {
                Profiles.RemoveAt(index);
            }
            else
            {
                LogManager.WriteLog("Workflow Execution Profile deletion failed. The Workflow Execution Profile " + profile.ProfileName + " was not found in the configuration file.");
                throw new Exception("Workflow Execution Profile deletion failed. The Workflow Execution Profile " + profile.ProfileName + " was not found in the configuration file.");
            }

            //Delete Profile folder
            try
            {
                if (Directory.Exists(Folder + "\\" + profile.ProfileName))
                    Directory.Delete(Folder + "\\" + profile.ProfileName, true);
            }
            catch (Exception)
            {
                throw;
            }

            //Save Profiles
            WriteProfiles();
        }
        /// <summary>
        /// Updates the Workflow Execution profile.
        /// </summary>
        /// <param name="profile">The Workflow Execution profile.</param>
        /// <exception cref="System.Exception">Data Export Profile Update failed. The Data Export Profile  + profile.ProfileName +  was not found in the configuration file.</exception>
        public void UpdateProfile(MSCRMWorkflowExecutionProfile profile)
        {
            if (!Directory.Exists(Folder + "\\" + profile.ProfileName))
                Directory.CreateDirectory(Folder + "\\" + profile.ProfileName);

            int index = Profiles.FindIndex(d => d.ProfileName == profile.ProfileName);
            if (index > -1)
            {
                Profiles[index] = profile;
            }
            else
            {
                LogManager.WriteLog("Data Export Profile Update failed. The Data Export Profile " + profile.ProfileName + " was not found in the configuration file.");
                throw new Exception("Data Export Profile Update failed. The Data Export Profile " + profile.ProfileName + " was not found in the configuration file.");
            }

            WriteProfiles();
        }
        /// <summary>
        /// Runs the Workflow Execution profile.
        /// </summary>
        /// <param name="profile">The profile.</param>
        public void RunProfile(MSCRMWorkflowExecutionProfile profile)
        {
            LogManager.WriteLog("Running Workflow Execution Profile: " + profile.ProfileName);

            try
            {
                MSCRMConnection connection = profile.getSourceConneciton();
                _serviceProxy = cm.connect(connection);

                EntityCollection result = _serviceProxy.RetrieveMultiple(new FetchExpression(profile.FetchXMLQuery));

                foreach (Entity record in result.Entities)
                {
                    ExecuteWorkflowRequest request = new ExecuteWorkflowRequest()
                    {
                        WorkflowId = profile.WorkflowId,
                        EntityId = record.Id
                    };

                    // Execute the workflow.
                    ExecuteWorkflowResponse response = (ExecuteWorkflowResponse)_serviceProxy.Execute(request);
                }
            }
            catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> ex)
            {
                LogManager.WriteLog("Error:" + ex.Detail.Message + "\n" + ex.Detail.TraceText);
                throw;
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                    LogManager.WriteLog("Error:" + ex.Message + "\n" + ex.InnerException.Message);
                else
                    LogManager.WriteLog("Error:" + ex.Message);
                throw;
            }
            LogManager.WriteLog("All workflows were launched.");
        }