Exemplo n.º 1
0
        /**********************************************************************************************//**
        * Replace value.
        *
        * \author  Ilan Hindy
        * \date    29/09/2016
        *
        * \return  An IndexCreatingOperation.
        *  .
        **************************************************************************************************/

        private IndexCreatingOperation replaceValue()
        {
            bool   converted;
            object value = TypesUtility.Parse(list.GetType().GenericTypeArguments[0], TextBox_Replace_AddValue.Text, out converted);

            if (converted)
            {
                if (ListBox_Elements.SelectedIndex >= 0)
                {
                    TypesUtility.InvokeMethodOfList(list, "RemoveAt", new object[] { ListBox_Elements.SelectedIndex }, false);
                    TypesUtility.InvokeMethodOfList(list, "Insert", new object[] { ListBox_Elements.SelectedIndex, value }, false);
                    return(IndexCreatingOperation.Current);
                }
                else
                {
                    TypesUtility.InvokeMethodOfList(list, "Add", new object[] { value }, false);
                    return(IndexCreatingOperation.Start);
                }
            }
            else
            {
                CustomizedMessageBox.Show("Cannot convert value " + TextBox_AddValue.Text + " to type " + list.GetType().GenericTypeArguments[0].ToString(), "List Input Message", Icons.Error);
                return(IndexCreatingOperation.Start);
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public static bool SelectOutputFile(string fileType, ref string fileName, ref string path)
        ///
        /// \brief Select output file.
        ///
        /// \par Description.
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 10/12/2017
        ///
        /// \param          fileType  (string) - Type of the file.
        /// \param [in,out] fileName (ref string) - Filename of the file.
        /// \param [in,out] path     (ref string) - Full pathname of the file.
        ///
        /// \return True if it succeeds, false if it fails.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static bool SelectOutputFile(string fileType,
                                            ref string fileName,
                                            ref string path)
        {
            //Get the data file name and path
            Microsoft.Win32.SaveFileDialog fileDialog = new Microsoft.Win32.SaveFileDialog();
            fileDialog.CheckFileExists  = false;
            fileDialog.CheckPathExists  = true;
            fileDialog.Filter           = fileType + " Files (." + fileType + ")|*." + fileType;
            fileDialog.FileName         = fileName;
            fileDialog.InitialDirectory = System.IO.Path.GetFullPath(path);
            fileDialog.RestoreDirectory = true;
            fileDialog.Title            = "Select " + fileType + " file";
            if (fileDialog.ShowDialog() == true)
            {
                fileName = System.IO.Path.GetFileName(fileDialog.FileName);
                path     = RelativePath(Directory.GetCurrentDirectory(), Path.GetDirectoryName(fileDialog.FileName));
                return(true);
            }
            else
            {
                CustomizedMessageBox.Show("File Selection canceled", "Select File Dialog", null, Icons.Error);
                return(false);
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public static bool SelectInputFile(string fileType, ref string fileName, ref string path, bool checkFileExist = true)
        ///
        /// \brief Select input file.
        ///
        /// \par Description.
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 10/12/2017
        ///
        /// \param          fileType        (string) - Type of the file.
        /// \param [in,out] fileName       (ref string) - Filename of the file.
        /// \param [in,out] path           (ref string) - Full pathname of the file.
        /// \param          checkFileExist (Optional)  (bool) - true to check file exist.
        ///
        /// \return True if it succeeds, false if it fails.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static bool SelectInputFile(string fileType, ref string fileName, ref string path, bool checkFileExist = true, string title = null)
        {
            Microsoft.Win32.OpenFileDialog fileDialog = new Microsoft.Win32.OpenFileDialog();
            fileDialog.CheckFileExists = checkFileExist;
            fileDialog.CheckPathExists = true;
            //fileDialog.RestoreDirectory = true;
            fileDialog.FileName         = fileName;
            fileDialog.InitialDirectory = System.IO.Path.GetFullPath(path);
            if (title is null)
            {
                fileDialog.Title = "Select " + fileType + " source file";
            }
            else
            {
                fileDialog.Title = title;
            }
            fileDialog.Filter = fileType + " Files (." + fileType + "|*." + fileType;
            if (fileDialog.ShowDialog() == true)
            {
                fileName = fileDialog.SafeFileName;
                path     = RelativePath(Directory.GetCurrentDirectory(), Path.GetDirectoryName(fileDialog.FileName));
                return(true);
            }
            else
            {
                CustomizedMessageBox.Show("File Selection canceled", "Select File Dialog", null, Icons.Error);
                return(false);
            }
        }
Exemplo n.º 4
0
        /**********************************************************************************************//**
        * Creates an attribute.
        *
        * \author  Ilan Hindy
        * \date    29/09/2016
        *
        * \param [out] newValue    The new value.
        *
        * \return  true if it succeeds, false if it fails.
        *  .
        **************************************************************************************************/

        private bool CreateAttribute(out object newValue)
        {
            string    valueString;
            Attribute attribute;

            if (!ComboBox_SelectValue.IsVisible)
            {
                valueString = TextBox_AddValue.Text;
            }
            else
            {
                valueString = (string)ComboBox_SelectValue.SelectedItem;
            }
            if (TypesUtility.CreateAttribute((string)ComboBox_SelectCategory.SelectedItem,
                                             (string)ComboBox_SelectType.SelectedItem,
                                             valueString, out attribute))
            {
                newValue = attribute;
                return(true);
            }
            else
            {
                CustomizedMessageBox.Show("Cannot convert value " + valueString + " to type " + (string)ComboBox_SelectType.SelectedItem, "List Input Message", Icons.Error);
                newValue = null;
                return(false);
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public static void RemoveEmpty(bool confirmNeeded, string subject, string algorithm )
        ///
        /// \brief Removes the empty.
        ///
        /// \par Description.
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 13/12/2017
        ///
        /// \param confirmNeeded  (bool) - true if confirm needed.
        /// \param subject        (string) - The subject.
        /// \param algorithm      (string) - The algorithm.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static void RemoveDataDir(bool confirmNeeded, string subject, string algorithm)
        {
            // If the subject is empty - remove the subject
            string subjectPath = Config.Instance.GenerateSubjectPath(subject);

            if (!HasFiles(subjectPath))
            {
                if (CustomizedMessageBox.Show(new List <string> {
                    "The subject DATA directories are empty. Do you want to delete them?"
                },
                                              "FileUtils Message", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    Directory.Delete(subjectPath, true);
                    return;
                }
            }

            string algorithmPath = Config.Instance.GenerateAlgorithmPath(subject, algorithm);

            if (!HasFiles(algorithmPath))
            {
                if (CustomizedMessageBox.Show(new List <string> {
                    "The algorithm DATA directories are empty. Do you want to delete them?"
                },
                                              "FileUtils Message", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    Directory.Delete(algorithmPath);
                    return;
                }
            }
        }
        public static void RemoveCodeAndDataDirs(bool confirmNeeded, string subject, string algorithm)
        {
            string subjectCodePath = ClassFactory.GenerateSubjectPath(subject);
            string subjectDataPath = Config.Instance.GenerateSubjectPath(subject);

            if (!(HasFiles(subjectCodePath) || HasFiles(subjectDataPath)))
            {
                if (CustomizedMessageBox.Show(new List <string> {
                    "The subject CODE and DATA directories are empty. Do you want to delete them?"
                },
                                              "FileUtils Message", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    Directory.Delete(subjectCodePath, true);
                    Directory.Delete(subjectDataPath, true);
                    return;
                }
            }

            string algorithmCodePath = ClassFactory.GenerateAlgorithmPath(subject, algorithm);
            string algorithmDataPath = Config.Instance.GenerateAlgorithmPath(subject, algorithm);

            if (!(HasFiles(algorithmCodePath) || HasFiles(algorithmDataPath)))
            {
                if (CustomizedMessageBox.Show(new List <string> {
                    "The algorithm CODE and DATA directories are empty. Do you want to delete them?"
                },
                                              "FileUtils Message", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    Directory.Delete(algorithmCodePath, true);
                    Directory.Delete(algorithmDataPath, true);
                    return;
                }
            }
        }
Exemplo n.º 7
0
        /**********************************************************************************************//**
        * Event handler. Called by Button_Save for click events.
        *
        * \author  Ilan Hindy
        * \date    29/09/2016
        *
        * \param   sender  Source of the event.
        * \param   e       Routed event information.
        *
        **************************************************************************************************/

        private void Button_Save_Click(object sender, RoutedEventArgs e)
        {
            if (!EditableCheck())
            {
                return;
            }
            TypesUtility.CopyList(list, listForResetToSaved);
            ListBox_Elements.UpdateLayout();
            CustomizedMessageBox.Show("Finished Saving", "List Input Message", Icons.Success);
        }
Exemplo n.º 8
0
        /**********************************************************************************************//**
        * Event handler. Called by Button_ResetToSaved for click events.
        *
        * \author  Ilan Hindy
        * \date    29/09/2016
        *
        * \param   sender  Source of the event.
        * \param   e       Routed event information.
        *
        **************************************************************************************************/

        private void Button_ResetToSaved_Click(object sender, RoutedEventArgs e)
        {
            if (!EditableCheck())
            {
                return;
            }
            TypesUtility.CopyList(listForResetToSaved, list);
            FillListBox(list, IndexCreatingOperation.Start);
            ListBox_Elements.UpdateLayout();
            CustomizedMessageBox.Show("Finished Reset to Saved", "List Input Message", Icons.Success);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public void InitializeRunning()
        ///
        /// \brief Initializes the running.
        ///
        /// \brief #### Algorithm.
        ///
        /// \brief #### Usage Notes.
        ///
        /// \author Main
        /// \date 24/01/2017
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public void InitializeRunning()
        {
            if (inDebugMode)
            {
                CustomizedMessageBox.Show("The algorithem is running already press one processor to continue", "Running Window Message", null, Icons.Error);
            }
            else
            {
                Run(false, false);
                CustomizedMessageBox.Show("Press the processes to activate them \n Note that all the processes has to be activated", "Running window Message", null, Icons.Info);
            }
        }
Exemplo n.º 10
0
        /**********************************************************************************************//**
        * Exit operations.
        *
        * \author  Ilan Hindy
        * \date    29/09/2016
        *
        **************************************************************************************************/

        private void ExitOperations()
        {
            if (Updated)
            {
                MessageBoxResult dialogResult = CustomizedMessageBox.Show("There is unsaved data do you want to exit or to save first?", "Data not saved dialog", MessageBoxButton.YesNo);
                if (dialogResult == MessageBoxResult.No)
                {
                    Button_ResetToInit_Click(null, null);
                    Updated = false;
                }
            }
        }
Exemplo n.º 11
0
        /**********************************************************************************************//**
        * Determines if we can editable check.
        *
        * \author  Ilan Hindy
        * \date    29/09/2016
        *
        * \return  true if it succeeds, false if it fails.
        *  .
        **************************************************************************************************/

        private bool EditableCheck()
        {
            if (!editable)
            {
                CustomizedMessageBox.Show("The list cannot be updated because it is not editable", "List Input Message", Icons.Error);
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 12
0
        /**********************************************************************************************//**
        * Creates a value.
        *
        * \author  Ilan Hindy
        * \date    29/09/2016
        *
        * \param [out] newValue    The new value.
        *
        * \return  true if it succeeds, false if it fails.
        *  .
        **************************************************************************************************/

        private bool CreateValue(out object newValue)
        {
            bool converted;

            newValue = TypesUtility.Parse(list.GetType().GenericTypeArguments[0], TextBox_AddValue.Text, out converted);
            if (converted)
            {
                return(true);
            }
            else
            {
                CustomizedMessageBox.Show("Cannot convert value " + TextBox_AddValue.Text + " to type " + list.GetType().GenericTypeArguments[0].ToString(), "List Input Message", Icons.Error);
                return(false);
            }
        }
Exemplo n.º 13
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn protected void Button_Scan_Click(object sender, RoutedEventArgs e)
        ///
        /// \brief Event handler. Called by Button_Scan for click events.
        ///
        /// \par Description.
        ///      Scan the current Algorithm Data directory
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 29/11/2017
        ///
        /// \param sender  (object) - Source of the event.
        /// \param e       (RoutedEventArgs) - Routed event information.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        protected void Button_Scan_Click(object sender, RoutedEventArgs e)
        {
            if (CustomizedMessageBox.Show(new List <string> {
                "The current Algorithms Data will be scanned and the config file will be saved",
                "Do you want to continue ?"
            },
                                          "Select Algorithms Path Message",
                                          MessageBoxButton.YesNo,
                                          Icons.Question) == MessageBoxResult.Yes)
            {
                ((Config)networkElements[0]).AddAlgorithmsData(false);
                ResetToExisting();
                InitialExpand();
                forceSave        = false;
                selectionChanged = true;
            }
        }
Exemplo n.º 14
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn protected void Button_Correlate_Click(object sender, RoutedEventArgs e)
        ///
        /// \brief Event handler. Called by Button_Correlate for click events.
        ///
        /// \par Description.
        ///      Correlate between the algorithm programed and the Algorithm Data directory:
        ///      -  Remove folders of algorithms that do not exist
        ///      -  Add folders to new algorithms
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 29/11/2017
        ///
        /// \param sender  (object) - Source of the event.
        /// \param e       (RoutedEventArgs) - Routed event information.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        protected void Button_Correlate_Click(object sender, RoutedEventArgs e)
        {
            if (CustomizedMessageBox.Show(new List <string> {
                "The Algorithms Data directory structure will correlate with the existing algorithms",
                "Do you want to continue ?"
            },
                                          "Select Algorithms Path Message",
                                          MessageBoxButton.YesNo,
                                          Icons.Question) == MessageBoxResult.Yes)
            {
                ((Config)networkElements[0]).UpdateAlgorithmsDataDirectory(null, false);
                ResetToExisting();
                InitialExpand();
                forceSave        = false;
                selectionChanged = true;
            }
        }
Exemplo n.º 15
0
        /**********************************************************************************************//**
        * Event handler. Called by Button_Remove for click events.
        *
        * \author  Ilan Hindy
        * \date    29/09/2016
        *
        * \param   sender  Source of the event.
        * \param   e       Routed event information.
        *
        **************************************************************************************************/

        private void Button_Remove_Click(object sender, RoutedEventArgs e)
        {
            if (!EditableCheck())
            {
                return;
            }
            if (((IList)list).Count > 0)
            {
                TypesUtility.InvokeMethodOfList(list, "RemoveAt", new object[] { ListBox_Elements.SelectedIndex }, false);
                FillListBox(list, IndexCreatingOperation.Previouse);
                Updated = true;
            }
            else
            {
                CustomizedMessageBox.Show("The list is already empty", "List Input Message", Icons.Error);
                return;
            }
        }
Exemplo n.º 16
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn protected void Button_SelectAlgorithmsPath_Click(object sender, RoutedEventArgs e)
        ///
        /// \brief Event handler. Called by Button_SelectAlgorithmsPath for click events.
        ///
        /// \par Description.
        ///      -  Change the selected Algorithm Data path.
        ///      -  This method is activated when the Algorithm Data Path attribute's button is clicked
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 01/11/2017
        ///
        /// \param sender (object) - Source of the event.
        /// \param e      (RoutedEventArgs) - Routed event information.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static void Button_SelectAlgorithmsPath_Click(object sender, RoutedEventArgs e)
        {
            ConfigWindow configWindow = (ConfigWindow)GetWindow((Button)sender);
            Config       config       = (Config)configWindow.networkElements[0];

            if (CustomizedMessageBox.Show("The selecting of an algorithms pass will cause save to the config \n Do you want to continue ?",
                                          "Select Algorithms Path Message",
                                          MessageBoxButton.YesNo,
                                          Icons.Question) == MessageBoxResult.Yes)
            {
                if (config.AddAlgorithmsData())
                {
                    config.CheckAndSetSelected();
                    configWindow.selectionChanged = true;
                    configWindow.ResetToExisting();
                    configWindow.InitialExpand();
                }
            }
        }
Exemplo n.º 17
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn protected void Button_NewDataFolder_Click(object sender, RoutedEventArgs e)
        ///
        /// \brief Event handler. Called by Button_NewDataFolder for click events.
        ///
        /// \par Description.
        ///      Creates a new Algorithm Data folder
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 29/11/2017
        ///
        /// \param sender  (object) - Source of the event.
        /// \param e       (RoutedEventArgs) - Routed event information.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        protected void Button_NewDataFolder_Click(object sender, RoutedEventArgs e)
        {
            if (CustomizedMessageBox.Show(new List <string> {
                "The creation of an algorithms pass will cause save to the config",
                "Do you want to continue ?"
            },
                                          "Select Algorithms Path Message",
                                          MessageBoxButton.YesNo,
                                          Icons.Question) == MessageBoxResult.No)
            {
                return;
            }

            ((Config)networkElements[0]).NewDataFolder();
            ResetToExisting();
            InitialExpand();
            forceSave        = false;
            selectionChanged = true;
        }
Exemplo n.º 18
0
 public void Button_EnumType_Click(object sender, RoutedEventArgs e)
 {
     CustomizedMessageBox.Show(System.Drawing.KnownColor.Aqua.GetType().ToString(), "", null, Icons.Info);
     if (Type.GetType(System.Drawing.KnownColor.Aqua.GetType().ToString()) == null)
     {
         CustomizedMessageBox.Show("null", "", null, Icons.Info);
     }
     else
     {
         CustomizedMessageBox.Show("not null", "", null, Icons.Info);
     }
     if (TypesUtility.GetTypeFromString(System.Drawing.KnownColor.Aqua.GetType().ToString()) == null)
     {
         CustomizedMessageBox.Show("null", "", null, Icons.Info);
     }
     else
     {
         CustomizedMessageBox.Show("not null", "", null, Icons.Info);
     }
 }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public void RunSingleStep(BaseProcess process)
        ///
        /// \brief Executes the single step operation.
        ///
        /// \brief #### Algorithm.
        ///
        /// \brief #### Usage Notes.
        ///
        /// \author Main
        /// \date 24/01/2017
        ///
        /// \param process The process.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public void RunSingleStep(BaseProcess process, bool alreadyRunning = true)
        {
            if (runningProcesses.Exists(p => p == process))
            {
                if (process.or[bp.ork.MessageQ].Count == 0)
                {
                    CustomizedMessageBox.Show("The process : " + process.ToString() + " does not have a waiting message", "Running Window Message", null, Icons.Error);
                    return;
                }
            }
            else
            {
                runningProcesses.Add(process);
            }
            network.or[bn.ork.SingleStepStatus] = true;
            processesInStep = new List <BaseProcess>()
            {
                process
            };
            Run(alreadyRunning);
        }
Exemplo n.º 20
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn private SelectResult EndSelectionForDebug(string absPath, string file)
        ///
        /// \brief Ends selection for debug.
        ///
        /// \par Description.
        ///      Check for select debug file - the file must exist
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 10/12/2017
        ///
        /// \param absPath  (string) - Full pathname of the abs file.
        /// \param file     (string) - The file.
        ///
        /// \return A SelectResult.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        private SelectResult EndSelectionForDebug(string absPath, string file)
        {
            if (!File.Exists(absPath + file))
            {
                string selectedAction = CustomizedMessageBox.Show(new List <string> {
                    "The file dose not exist",
                    "Select Cancel to cancel the selection",
                    "Select Quit to quit the dialog"
                },
                                                                  "Select File Dialog Message",
                                                                  new List <string> {
                    "Cancel", "Quit"
                },
                                                                  Icons.Question);
                return((SelectResult)TypesUtility.GetKeyFromString(typeof(SelectResult), selectedAction));
            }
            else
            {
                return(SelectResult.Debug);
            }
        }
Exemplo n.º 21
0
 private SelectResult EndSelectionForNew(string absPath, string file)
 {
     if (File.Exists(absPath + file))
     {
         string selectedAction = CustomizedMessageBox.Show(new List <string> {
             "The file already exist",
             "Select Save to override",
             "Select Cancel to cancel the selection",
             "Select Quit to quit the dialog"
         },
                                                           "Select Docs Dialog Message",
                                                           new List <string> {
             "Save", "Cancel", "Quit"
         },
                                                           Icons.Question);
         return((SelectResult)TypesUtility.GetKeyFromString(typeof(SelectResult), selectedAction));
     }
     else
     {
         return(SelectResult.Save);
     }
 }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public static bool ReplaceFile(string sourceFileName, string destFileName)
        ///
        /// \brief Replace file.
        ///
        /// \par Description.
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 10/12/2017
        ///
        /// \param sourceFileName  (string) - Filename of the source file.
        /// \param destFileName    (string) - Filename of the destination file.
        ///
        /// \return True if it succeeds, false if it fails.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static bool ReplaceFile(string sourceFileName, string destFileName)
        {
            sourceFileName = System.IO.Path.GetFullPath(sourceFileName);
            destFileName   = System.IO.Path.GetFullPath(destFileName);

            //Delete the destination file
            if (File.Exists(destFileName))
            {
                while (true)
                {
                    try
                    {
                        File.Delete(destFileName);
                        break;
                    }
                    catch (Exception e)
                    {
                        string result = CustomizedMessageBox.FileMsgErr("Error while deleting destination file",
                                                                        Path.GetFileName(destFileName),
                                                                        Path.GetDirectoryName(destFileName),
                                                                        e.Message,
                                                                        "FilesAndAlgorithmUtilities",
                                                                        new List <string> {
                            "Retry", "Cancel"
                        });

                        if (result == "Cancel")
                        {
                            return(false);
                        }
                    }
                }
            }


            //Copy the source file to the destination file
            File.Copy(sourceFileName, destFileName, true);
            return(true);
        }
Exemplo n.º 23
0
        /**********************************************************************************************//**
        * Replace value in attribute.
        *
        * \author  Ilan Hindy
        * \date    29/09/2016
        *
        **************************************************************************************************/

        private void ReplaceValueInAttribute()
        {
            if (ListBox_Elements.SelectedIndex == -1)
            {
                CustomizedMessageBox.Show("No selected item", "List Input Message", Icons.Error);
                return;
            }
            string    newValueString;
            Attribute attribute = ((List <Attribute>)list)[ListBox_Elements.SelectedIndex];

            if (!ComboBox_Replace_SelectValue.IsVisible)
            {
                newValueString = TextBox_Replace_AddValue.Text;
            }
            else
            {
                newValueString = (string)ComboBox_Replace_SelectValue.SelectedItem;
            }
            Type attributeType = attribute.Value.GetType();

            if (attributeType.IsPrimitive || attributeType.Equals(typeof(string)) || attributeType.IsEnum)
            {
                bool    converted;
                dynamic newValue = TypesUtility.ConvertValueFromString(attributeType, newValueString, out converted);
                if (!converted)
                {
                    CustomizedMessageBox.Show("The value of new value string: " + newValueString + " cannot be assigned to the attribute type: ", attributeType.ToString(), Icons.Error);
                }
                else
                {
                    attribute.Value = newValue;
                }
            }
            else
            {
                CustomizedMessageBox.Show("Attributes from types NetworkElement and List cannot be replaced they can only be removed and added ", "List Input Message", Icons.Error);
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public void CreateCodeFile()
        ///
        /// \brief Creates code file.
        ///
        /// \par Description.
        ///      The main method for creating the code file
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 18/03/2018
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public void CreateCodeFile()
        {
            InitSyntaxHighlight();

            // The header of the file
            string fileText = eol + "using System.Collections.Generic;";

            fileText += eol + "using DistributedAlgorithms;";
            fileText += eol + "using DistributedAlgorithms.Algorithms.Base.Base;";

            // The NetworkElement partial class
            if (!CreateNetworkElementText(ref fileText))
            {
                CustomizedMessageBox.Show("Base algorithm code building cancelled by the user", "BaseAlgorithmAccess", null);
                return;
            }

            // The base algorithm partial class
            NetworkElement[] networkElements = { new BaseMessage(), new BaseNetwork(), new BaseProcess(), new BaseChannel() };
            classNames[0] = "Message";
            string[] enumClasses = { "bm", "bn", "bp", "bc" };

            fileText += eol + @"namespace DistributedAlgorithms.Algorithms." + "Base" + "." + "Base" + eol + "{";
            for (classIdx = 0; classIdx < classNames.Count; classIdx++)
            {
                networkElements[classIdx].Init(0);
                if (!CreateBaseClassText(ref fileText, networkElements[classIdx], enumClasses[classIdx]))
                {
                    CustomizedMessageBox.Show("Base algorithm code building cancelled by the user", "BaseAlgorithmAccess", null);
                    return;
                }
            }
            fileText     += eol + "}";
            classNames[0] = "Process";
            File.WriteAllText(ClassFactory.GenerateAlgorithmPath("Base", "Base") + "\\" + "Base" + "DefsAndInits" + ".cs", fileText);
            CustomizedMessageBox.Show("Base algorithm code building finished", "BaseAlgorithmAccess", null, Icons.Success);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn private void Button_UpdateNetworkElement_Click(object sender, RoutedEventArgs e)
        ///
        /// \brief Event handler. Called by Button_UpdateNetworkElement for click events.
        ///
        /// \par Description.
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 04/07/2017
        ///
        /// \param sender (object) - Source of the event.
        /// \param e      (RoutedEventArgs) - Routed event information.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        private void Button_UpdateNetworkElement_Click(object sender, RoutedEventArgs e)
        {
            UpdateNetworkElement();
            CustomizedMessageBox.Show("Update Network Element Ended", "Element Input Window Message", Icons.Success);
            elementWasChanged = true;
        }
Exemplo n.º 26
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public static string Show(List<Control> controls = null, string title = "", List<Button> buttonsList = null, Icons imageIcon = Icons.Info, bool sizeToContent)
        ///
        /// \brief Shows.
        ///
        /// \par Description.
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 10/12/2017
        ///
        /// \param controls      (Optional)  (List&lt;Control&gt;) - The controls.
        /// \param title         (Optional)  (string) - The title.
        /// \param buttonsList   (Optional)  (List&lt;Button&gt;) - List of buttons.
        /// \param imageIcon     (Optional)  (Icons) - The image icon.
        /// \param sizeToContent  (bool) - true to size to content.
        ///
        /// \return A string.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static string Show(List <Control> controls, string title, List <Button> buttonsList, Icons imageIcon, bool sizeToContent)
        {
            if (controls == null)
            {
                controls = new List <Control>();
            }
            if (controls.Count == 0)
            {
                controls.Add(SetLabel(""));
            }
            if (buttonsList == null)
            {
                buttonsList = new List <Button>();
                buttonsList.Add(SetButton("OK"));
            }

            CustomizedMessageBox messageBox = new CustomizedMessageBox();

            if (!sizeToContent)
            {
                messageBox.MaxWidth = 500;
            }

            messageBox.Title = title;

            //Image
            Image image = SetImage(imageIcon);

            messageBox.panImage.Children.Add(image);

            //Controls
            string fullMessage = "";

            foreach (Control control in controls)
            {
                messageBox.panText.Children.Add(control);
                if (control is TextBox)
                {
                    fullMessage += ((TextBox)control).Text + "\n";
                }
                else if (control is SyntaxHighlight)
                {
                    messageBox.MaxWidth = 1200;
                    fullMessage        += ((SyntaxHighlight)control).Text;
                }
            }

            //Buttons
            int insertIdx = 0;

            foreach (Button button in buttonsList)
            {
                messageBox.panButtons.ColumnDefinitions.Add(new ColumnDefinition());
                messageBox.panButtons.Children.Add(button);
                Grid.SetColumn(button, insertIdx);
                Grid.SetRow(button, 0);
                button.Click += new RoutedEventHandler(messageBox.Button_Click);
                insertIdx++;
            }

            MessageRouter.AddEditOperation(title, fullMessage, imageIcon, new Font("Calibbri", 12, FontStyles.Normal, FontWeights.Normal, new Thickness(0), HorizontalAlignment.Left, Brushes.Black, null, TextWrapping.NoWrap));
            messageBox.ShowDialog();
            MessageRouter.AddEditOperationResult(messageBox.Result, new Font("Calibbri", 12, FontStyles.Normal, FontWeights.Normal, new Thickness(0), HorizontalAlignment.Left, Brushes.Black, null, TextWrapping.NoWrap));
            return(messageBox.Result);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn private void Button_ResetToInit_Click(object sender, RoutedEventArgs e)
        ///
        /// \brief Event handler. Called by Button_ResetToInit for click events.
        ///
        /// \par Description.
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 04/07/2017
        ///
        /// \param sender (object) - Source of the event.
        /// \param e      (RoutedEventArgs) - Routed event information.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        private void Button_ResetToInit_Click(object sender, RoutedEventArgs e)
        {
            ResetToInit();
            CustomizedMessageBox.Show("Reset To Init Ended", "Element Input Window Message", Icons.Success);
            elementWasChanged = true;
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn private void Button_ResetToSaved_Click(object sender, RoutedEventArgs e)
        ///
        /// \brief Event handler. Called by Button_ResetToSaved for click events.
        ///
        /// \par Description.
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 04/07/2017
        ///
        /// \param sender (object) - Source of the event.
        /// \param e      (RoutedEventArgs) - Routed event information.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        private void Button_ResetToSaved_Click(object sender, RoutedEventArgs e)
        {
            ResetToExisting();
            CustomizedMessageBox.Show("Reset To Saved Ended", "Element Input Window Message", Icons.Success);
        }
Exemplo n.º 29
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn private void Button_Select_Click(object sender, RoutedEventArgs e)
        ///
        /// \brief Event handler. Called by Button_Select for click events.
        ///
        /// \par Description.
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 29/08/2017
        ///
        /// \param sender  (object) - Source of the event.
        /// \param e       (RoutedEventArgs) - Routed event information.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        private void Button_Select_Click(object sender, RoutedEventArgs e)
        {
            // If the source and the target are not equal generate a message that the user code
            // will be overridden
            List <string> algorithms      = TypesUtility.GetAlgorithms();
            string        targetAlgorithm = Selection_TargetSubject.GetSelection().selectionText + "." + Selection_TargetAlgorithm.GetSelection().selectionText;
            string        sourceAlgorithm = Selection_SourceSubject.GetSelection().selectionText + "." + Selection_SourceAlgorithm.GetSelection().selectionText;

            if (algorithms.Any(a => a == targetAlgorithm))
            {
                newAlgorithm = false;
                if (sourceAlgorithm == targetAlgorithm)
                {
                    string messageResult = CustomizedMessageBox.Show(new List <string> {
                        "The algorithm already exist",
                        "Your code files Should not be re-generated",
                        "Select Replace to regenerate the user code files (and delete your implementation)",
                        "Select OK to replace only the automatically generated code file",
                        "Select Cancel to replace the selection"
                    },
                                                                     "SourceTargetAlgorithmsSelect Message",
                                                                     new List <string> {
                        "Replace", "OK", "Cancel"
                    },
                                                                     Icons.Question);
                    switch (messageResult)
                    {
                    case "Replace":
                        replaceUserCodeFiles = true;
                        break;

                    case "OK":
                        replaceUserCodeFiles = false;
                        break;

                    case "Cancel":
                        return;
                    }
                }
                else
                {
                    string messageResult = CustomizedMessageBox.Show(new List <string> {
                        "The algorithm already exist",
                        "You selected another algorithm as your source algorithm",
                        "Select Replace to replace the code files of the existing algorithm (Backup will be produced)",
                        "Select OK to replace only the auto generated code file",
                        "Select Cancel to replace the selection"
                    },
                                                                     "SourceTargetAlgorithmsSelect Message",
                                                                     new List <string> {
                        "Replace", "OK", "Cancel"
                    },
                                                                     Icons.Question);
                    switch (messageResult)
                    {
                    case "Replace":
                        replaceUserCodeFiles = true;
                        break;

                    case "OK":
                        replaceUserCodeFiles = false;
                        break;

                    case "Cancel":
                        return;
                    }
                }
            }
            else
            {
                newAlgorithm         = true;
                replaceUserCodeFiles = true;
            }

            selectResults = new List <SelectResults>();
            selectResults.Add(Selection_SourceSubject.GetSelection());
            selectResults.Add(Selection_SourceAlgorithm.GetSelection());
            selectResults.Add(Selection_TargetSubject.GetSelection());
            selectResults.Add(Selection_TargetAlgorithm.GetSelection());
            result = SelectResult.Select;
            Close();
        }