Пример #1
0
        private void AddDrives(byte a = 0)
        {
            var drives = from drive in DriveInfo.GetDrives()
                         select new Element {
                Name = drive.Name, isElement = IsElement.IsDrive
            };

            switch (a)
            {
            case 0:
                LeftPath.Clear();
                RightPath.Clear();
                LeftList.ItemsSource  = drives;
                RightList.ItemsSource = drives;
                break;

            case 1:
                LeftPath.Clear();
                LeftList.ItemsSource = drives;
                break;

            case 2:
                RightPath.Clear();
                RightList.ItemsSource = drives;
                break;
            }
        }
        private void ValidateRightSide()
        {
            Type?leftType = LeftPath?.GetPropertyType();

            if (PredicateType == ProfileRightSideType.Dynamic)
            {
                if (RightPath == null || !RightPath.IsValid)
                {
                    return;
                }

                Type rightSideType = RightPath.GetPropertyType() !;
                if (leftType != null && !leftType.IsCastableFrom(rightSideType))
                {
                    UpdateRightSideDynamic(null);
                }
            }
            else
            {
                if (RightStaticValue != null && (leftType == null || leftType.IsCastableFrom(RightStaticValue.GetType())))
                {
                    UpdateRightSideStatic(RightStaticValue);
                }
                else
                {
                    UpdateRightSideStatic(null);
                }
            }
        }
Пример #3
0
        private void ValidateRightSide()
        {
            if (Operator == null)
            {
                return;
            }

            if (PredicateType == ProfileRightSideType.Dynamic)
            {
                if (RightPath == null || !RightPath.IsValid)
                {
                    return;
                }

                Type rightSideType = RightPath.GetPropertyType() !;
                if (!Operator.SupportsType(rightSideType, ConditionParameterSide.Right))
                {
                    UpdateRightSideDynamic(null);
                }
            }
            else
            {
                if (RightStaticValue == null)
                {
                    return;
                }

                if (!Operator.SupportsType(RightStaticValue.GetType(), ConditionParameterSide.Right))
                {
                    UpdateRightSideStatic(null);
                }
            }
        }
        private void SetStaticValue(object?staticValue)
        {
            RightPath?.Dispose();
            RightPath = null;

            // If the left side is empty simply apply the value, any validation will wait
            if (LeftPath == null || !LeftPath.IsValid)
            {
                RightStaticValue = staticValue;
                return;
            }

            // If the left path is valid we can expect a type
            Type leftSideType = LeftPath.GetPropertyType() !;

            // If not null ensure the types match and if not, convert it
            if (staticValue != null && staticValue.GetType() == leftSideType)
            {
                RightStaticValue = staticValue;
            }
            else if (staticValue != null)
            {
                RightStaticValue = Convert.ChangeType(staticValue, leftSideType);
            }
            // If null create a default instance for value types or simply make it null for reference types
            else if (leftSideType.IsValueType)
            {
                RightStaticValue = Activator.CreateInstance(leftSideType);
            }
            else
            {
                RightStaticValue = null;
            }
        }
Пример #5
0
        /// <inheritdoc />
        public override bool Evaluate()
        {
            if (Operator == null || LeftPath == null || !LeftPath.IsValid)
            {
                return(false);
            }

            // If the operator does not support a right side, immediately evaluate with null
            if (Operator.RightSideType == null)
            {
                return(Operator.InternalEvaluate(LeftPath.GetValue(), null));
            }

            // Compare with a static value
            if (PredicateType == ProfileRightSideType.Static)
            {
                object?leftSideValue = LeftPath.GetValue();
                if (leftSideValue != null && leftSideValue.GetType().IsValueType&& RightStaticValue == null)
                {
                    return(false);
                }

                return(Operator.InternalEvaluate(leftSideValue, RightStaticValue));
            }

            if (RightPath == null || !RightPath.IsValid)
            {
                return(false);
            }

            // Compare with dynamic values
            return(Operator.InternalEvaluate(LeftPath.GetValue(), RightPath.GetValue()));
        }
        /// <inheritdoc />
        public override bool Evaluate()
        {
            if (Operator == null || LeftPath == null || !LeftPath.IsValid)
            {
                return(false);
            }

            // Compare with a static value
            if (PredicateType == ProfileRightSideType.Static)
            {
                object?leftSideValue = LeftPath.GetValue();
                if (leftSideValue != null && leftSideValue.GetType().IsValueType&& RightStaticValue == null)
                {
                    return(false);
                }

                return(Operator.Evaluate(leftSideValue, RightStaticValue));
            }

            if (RightPath == null || !RightPath.IsValid)
            {
                return(false);
            }

            // Compare with dynamic values
            return(Operator.Evaluate(LeftPath.GetValue(), RightPath.GetValue()));
        }
        /// <summary>
        ///     Updates the right side of the predicate, makes the predicate static and re-compiles the expression
        /// </summary>
        /// <param name="staticValue">The right side value to use</param>
        public void UpdateRightSideStatic(object?staticValue)
        {
            PredicateType = ProfileRightSideType.Static;
            RightPath?.Dispose();
            RightPath = null;

            SetStaticValue(staticValue);
        }
Пример #8
0
 new public string ToString()
 {
     return(String.Format("\nLeftPath: {0}\nRightPath: {1}\nLeftLine: {2}\nRightLine: {3}\nRefs: {4}",
                          (LeftPath?.ToString() ?? "null"),
                          (RightPath?.ToString() ?? "null"),
                          (LeftLine?.ToString() ?? "null"),
                          (RightLine?.ToString() ?? "null"),
                          Refs.ToString()));
 }
Пример #9
0
        /// <inheritdoc />
        protected override void Dispose(bool disposing)
        {
            ConditionOperatorStore.ConditionOperatorAdded   -= ConditionOperatorStoreOnConditionOperatorAdded;
            ConditionOperatorStore.ConditionOperatorRemoved -= ConditionOperatorStoreOnConditionOperatorRemoved;

            LeftPath?.Dispose();
            RightPath?.Dispose();

            base.Dispose(disposing);
        }
Пример #10
0
        private void UpdateFiles()
        {
            try
            {
                if (LeftPath.ToString() != "")
                {
                    DirectoryInfo   directoryInfo  = new DirectoryInfo(LeftPath.ToString());
                    DirectoryInfo[] subdirectories = directoryInfo.GetDirectories();

                    FileInfo[] files = directoryInfo.GetFiles();

                    var nameofdirectories = from dir in subdirectories
                                            select new Element {
                        Name = dir.Name, isElement = IsElement.IsDirectory, Date = dir.CreationTime.ToShortDateString()
                    };
                    var nameoffiles = from file in files
                                      select new Element {
                        Name = file.Name, isElement = IsElement.IsFile, Date = file.CreationTime.ToShortDateString()
                    };

                    var names = nameofdirectories.Union(nameoffiles);
                    Dispatcher.BeginInvoke((ThreadStart) delegate()
                    {
                        LeftList.ItemsSource = names;
                    });
                }

                if (RightPath.ToString() != "")
                {
                    DirectoryInfo   directoryInfo  = new DirectoryInfo(RightPath.ToString());
                    DirectoryInfo[] subdirectories = directoryInfo.GetDirectories();
                    FileInfo[]      files          = directoryInfo.GetFiles();

                    var nameofdirectories = from dir in subdirectories
                                            select new Element {
                        Name = dir.Name, isElement = IsElement.IsDirectory, Date = dir.CreationTime.ToShortDateString()
                    };
                    var nameoffiles = from file in files
                                      select new Element {
                        Name = file.Name, isElement = IsElement.IsFile, Date = file.CreationTime.ToShortDateString()
                    };

                    var names = nameofdirectories.Union(nameoffiles);
                    Dispatcher.BeginInvoke((ThreadStart) delegate()
                    {
                        RightList.ItemsSource = names;
                    });
                }
            }
            catch (System.UnauthorizedAccessException exc)
            {
                MessageBox.Show(exc.Message);
            }
        }
        /// <summary>
        ///     Updates the right side of the predicate using a path and makes the predicate dynamic
        /// </summary>
        /// <param name="path">The path pointing to the right side value</param>
        public void UpdateRightSideDynamic(DataModelPath?path)
        {
            if (path != null && !path.IsValid)
            {
                throw new ArtemisCoreException("Cannot update right side of predicate to an invalid path");
            }

            RightPath?.Dispose();
            RightPath = path != null ? new DataModelPath(path) : null;

            PredicateType = ProfileRightSideType.Dynamic;
        }
Пример #12
0
        /// <summary>
        ///     Updates the right side of the predicate, makes the predicate dynamic and re-compiles the expression
        /// </summary>
        /// <param name="path">The path pointing to the right side value inside the data model</param>
        public void UpdateRightSideDynamic(DataModelPath?path)
        {
            if (path != null && !path.IsValid)
            {
                throw new ArtemisCoreException("Cannot update right side of predicate to an invalid path");
            }
            if (Operator != null && path != null && !Operator.SupportsType(path.GetPropertyType() !, ConditionParameterSide.Right))
            {
                throw new ArtemisCoreException($"Selected operator does not support right side of type {path.GetPropertyType()!.Name}");
            }

            RightPath?.Dispose();
            RightPath = path != null ? new DataModelPath(path) : null;

            PredicateType = ProfileRightSideType.Dynamic;
        }
        internal override void Save()
        {
            Entity.PredicateType = (int)PredicateType;

            LeftPath?.Save();
            Entity.LeftPath = LeftPath?.Entity;
            RightPath?.Save();
            Entity.RightPath = RightPath?.Entity;

            Entity.RightStaticValue = JsonConvert.SerializeObject(RightStaticValue);

            if (Operator != null)
            {
                Entity.OperatorPluginGuid = Operator.PluginInfo.Guid;
                Entity.OperatorType       = Operator.GetType().Name;
            }
        }
        public void InjectBall()
        {
            if (IsEndPoint)
            {
                HasBall = true;
                return;
            }

            if (OpenPath == Direction.Left)
            {
                OpenPath = Direction.Right;
                LeftPath.InjectBall();
            }
            else
            {
                OpenPath = Direction.Left;
                RightPath.InjectBall();
            }
        }
Пример #15
0
        /// <summary>
        ///     Updates the right side of the predicate, makes the predicate static and re-compiles the expression
        /// </summary>
        /// <param name="staticValue">The right side value to use</param>
        public void UpdateRightSideStatic(object?staticValue)
        {
            PredicateType = ProfileRightSideType.Static;
            RightPath?.Dispose();
            RightPath = null;

            // If the operator is null simply apply the value, any validation will wait
            if (Operator == null)
            {
                RightStaticValue = staticValue;
                return;
            }

            // If the operator does not support a right side, always set it to null
            if (Operator.RightSideType == null)
            {
                RightStaticValue = null;
                return;
            }

            // If not null ensure the types match and if not, convert it
            Type?preferredType = GetPreferredRightSideType();

            if (staticValue != null && staticValue.GetType() == preferredType || preferredType == null)
            {
                RightStaticValue = staticValue;
            }
            else if (staticValue != null)
            {
                RightStaticValue = Convert.ChangeType(staticValue, preferredType);
            }
            // If null create a default instance for value types or simply make it null for reference types
            else if (preferredType.IsValueType)
            {
                RightStaticValue = Activator.CreateInstance(preferredType);
            }
            else
            {
                RightStaticValue = null;
            }
        }
Пример #16
0
        internal override void Save()
        {
            // Don't save an invalid state
            if (LeftPath != null && !LeftPath.IsValid || RightPath != null && !RightPath.IsValid)
            {
                return;
            }

            Entity.PredicateType = (int)PredicateType;

            LeftPath?.Save();
            Entity.LeftPath = LeftPath?.Entity;
            RightPath?.Save();
            Entity.RightPath = RightPath?.Entity;

            Entity.RightStaticValue = CoreJson.SerializeObject(RightStaticValue);

            if (Operator?.Plugin != null)
            {
                Entity.OperatorPluginGuid = Operator.Plugin.Guid;
                Entity.OperatorType       = Operator.GetType().Name;
            }
        }
        internal override bool EvaluateObject(object target)
        {
            if (Operator == null || LeftPath == null || !LeftPath.IsValid)
            {
                return(false);
            }

            // Compare with a static value
            if (PredicateType == ProfileRightSideType.Static)
            {
                object?leftSideValue = GetListPathValue(LeftPath, target);
                if (leftSideValue != null && leftSideValue.GetType().IsValueType&& RightStaticValue == null)
                {
                    return(false);
                }

                return(Operator.Evaluate(leftSideValue, RightStaticValue));
            }

            if (RightPath == null || !RightPath.IsValid)
            {
                return(false);
            }

            // Compare with dynamic values
            if (PredicateType == ProfileRightSideType.Dynamic)
            {
                // If the path targets a property inside the list, evaluate on the list path value instead of the right path value
                if (RightPath.Target is ListPredicateWrapperDataModel)
                {
                    return(Operator.Evaluate(GetListPathValue(LeftPath, target), GetListPathValue(RightPath, target)));
                }
                return(Operator.Evaluate(GetListPathValue(LeftPath, target), RightPath.GetValue()));
            }

            return(false);
        }
        private void Rename(object sender, RoutedEventArgs e)
        {
            Element element;
            string  path;

            if (LeftList.SelectedItem != null && LeftList.SelectedItems.Count == 1)
            {
                element = (Element)LeftList.SelectedItem;
                path    = LeftPath.ToString();
            }
            else if (RightList.SelectedItem != null && RightList.SelectedItems.Count == 1)
            {
                element = (Element)RightList.SelectedItem;
                path    = RightPath.ToString();
            }
            else
            {
                MessageBox.Show("Для переименования должен быть выбран 1 элемент");
                return;
            }
            if (element.isElement == IsElement.IsDrive)
            {
                MessageBox.Show("Разделы диска или носители нельзя переименовывать");
            }
            if (element.isElement == IsElement.IsDirectory)
            {
                DirectoryInfo directory    = new DirectoryInfo(path + element.Name);
                RenameWindow  renameWindow = new RenameWindow();
                renameWindow.ShowDialog();
                if (IsExistValue)
                {
                    if (renameWindow.TextBoxForName.Text != "")
                    {
                        try
                        {
                            directory.MoveTo(path + "\\" + renameWindow.TextBoxForName.Text);
                        }
                        catch (IOException exc)
                        {
                            MessageBox.Show(exc.Message);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Значение не введено");
                    }
                    IsExistValue = false;
                }
            }
            if (element.isElement == IsElement.IsFile)
            {
                FileInfo     file         = new FileInfo(path + element.Name);
                RenameWindow renameWindow = new RenameWindow();
                renameWindow.TextBoxForName.Text = file.Extension;
                renameWindow.ShowDialog();
                if (IsExistValue)
                {
                    if (renameWindow.TextBoxForName.Text != file.Extension)
                    {
                        try
                        {
                            file.MoveTo(path + "\\" + renameWindow.TextBoxForName.Text);
                        }
                        catch (IOException exc)
                        {
                            MessageBox.Show(exc.Message);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Значение не введено");
                    }
                }
            }
            UpdateFiles();
        }
Пример #19
0
        private void ChangePlace(bool delete, Element element, bool IsLeft)
        {
            try
            {
                string newpath, oldpath;
                string name = element.Name;
                if (IsLeft)
                {
                    if (RightPath.ToString() == "")
                    {
                        throw new Exception("Неверный путь");
                    }
                    oldpath = LeftPath.ToString();
                    newpath = RightPath.ToString() + name;
                }
                else
                {
                    if (LeftPath.ToString() == "")
                    {
                        throw new Exception("Неверный путь");
                    }
                    oldpath = RightPath.ToString();
                    newpath = LeftPath.ToString() + name;
                }
                if (element.isElement == IsElement.IsDirectory)
                {
                    if (!new DirectoryInfo(newpath).Exists)
                    {
                        DirectoryInfo newdirect = new DirectoryInfo(newpath);
                        newdirect.Create();

                        GetSubDir(new DirectoryInfo(oldpath + name), newpath, delete);
                        try
                        {
                            if (delete)
                            {
                                Directory.Delete(oldpath + name, true);
                            }
                        }
                        catch (IOException exc)
                        {
                            MessageBox.Show(exc.Message);
                        }
                    }
                }
                else if (element.isElement == IsElement.IsFile)
                {
                    if (delete)
                    {
                        try
                        {
                            File.Move(oldpath + name, newpath);
                        }
                        catch (IOException exc)
                        {
                            MessageBox.Show(exc.Message);
                        }
                    }
                    else
                    {
                        try
                        {
                            File.Copy(oldpath + name, newpath, false);
                        }
                        catch (IOException exc)
                        {
                            MessageBox.Show(exc.Message);
                        }
                        catch (UnauthorizedAccessException exc)
                        {
                            MessageBox.Show(exc.Message);
                        }
                    }
                }
                UpdateFiles();
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }
        }
Пример #20
0
        private async void Delete_Click(object sender, RoutedEventArgs e)
        {
            IsWorked = true;
            string path;

            if (LeftList.SelectedItems.Count > 0 && LeftPath.Length > 0)
            {
                await Task.Run(() =>
                {
                    Element[] elements;
                    GetNewCollection(out elements, true);
                    path = LeftPath.ToString();
                    foreach (Element element in elements)
                    {
                        Delete(element, path);
                    }
                });
            }
            else if (RightList.SelectedItems.Count > 0 && RightPath.Length > 0)
            {
                await Task.Run(() =>
                {
                    path = RightPath.ToString();
                    Element[] elements;
                    GetNewCollection(out elements, false);
                    foreach (Element element in elements)
                    {
                        Delete(element, path);
                    }
                });
            }
            else
            {
                if (LeftPath.Length == 0 && RightPath.Length == 0 && (LeftList.SelectedItems.Count > 0 || RightList.SelectedItems.Count > 0))
                {
                    MessageBox.Show("Диск не подлежит удалению");
                }
                else
                {
                    MessageBox.Show("Не выбран элемент для удаления");
                }
                IsWorked = false;
                return;
            }
            void Delete(Element elementfordel, String pathfordel)
            {
                if (elementfordel.isElement == IsElement.IsDirectory)
                {
                    try
                    {
                        Directory.Delete(pathfordel + elementfordel.Name, true);
                    }
                    catch (IOException exc)
                    {
                        MessageBox.Show(exc.Message);
                    }
                    catch (UnauthorizedAccessException exc)
                    {
                        MessageBox.Show(exc.Message);
                    }
                }
                else
                {
                    try
                    {
                        File.Delete(pathfordel + elementfordel.Name);
                    }
                    catch (Exception exc)
                    {
                        MessageBox.Show(exc.Message);
                    }
                }
                UpdateFiles();
            }

            LeftList.SelectedIndex  = -1;
            RightList.SelectedIndex = -1;
            IsWorked = false;
        }
        //private void Encode(object sender, RoutedEventArgs e)
        //{
        //    Element element;
        //    string path;
        //    if (LeftList.SelectedItem != null && LeftList.SelectedItems.Count == 1)
        //    {
        //        element = (Element)LeftList.SelectedItem;
        //        path = LeftPath.ToString();
        //    }
        //    else if (RightList.SelectedItem != null && RightList.SelectedItems.Count == 1)
        //    {
        //        element = (Element)RightList.SelectedItem;
        //        path = RightPath.ToString();
        //    }
        //    else
        //    {
        //        MessageBox.Show("Закодировать можно только 1 текстовый документ");
        //        return;
        //    }
        //    if(element.isElement == IsElement.IsFile)
        //    {
        //        FileInfo file = new FileInfo(path + "//" + element.Name);
        //        if(file.Extension == ".txt" || file.Extension == ".docx" || file.Extension == ".doc")
        //        {
        //            try
        //            {
        //                using (StreamReader reader = new StreamReader(File.Open(path + "//" + element.Name, FileMode.Open),Encoding.Default))
        //                {
        //                    using (StreamWriter writer = new StreamWriter(File.Open(path + "//" + "EncodingFile.docx", FileMode.CreateNew), Encoding.Default))
        //                    {
        //                        string temp;
        //                        StringBuilder stringBuilder = new StringBuilder(100);
        //                        while ((temp = reader.ReadLine()) != null)
        //                        {

        //                            for (int count = 0; count < temp.Length; count++)
        //                            {
        //                                stringBuilder.Append((char)((char)(temp[count]) + 5));
        //                            }
        //                            writer.WriteLine(stringBuilder.ToString());
        //                            stringBuilder.Clear();
        //                        }
        //                    }
        //                }
        //            }
        //            catch (Exception exc)
        //            {
        //                MessageBox.Show(exc.Message);
        //            }
        //            UpdateFiles();
        //        }
        //        else
        //        {
        //            MessageBox.Show("Документе не имеет требуемое расширение txt, docx или doc");
        //        }
        //    }
        //    else
        //    {
        //        MessageBox.Show("Документе должен быть файлом с расширением txt, docx или doc");
        //    }
        //}
        //private void Decode(object sender, RoutedEventArgs e)
        //{
        //    Element element;
        //    string path;
        //    if (LeftList.SelectedItem != null && LeftList.SelectedItems.Count == 1)
        //    {
        //        element = (Element)LeftList.SelectedItem;
        //        path = LeftPath.ToString();
        //    }
        //    else if (RightList.SelectedItem != null && RightList.SelectedItems.Count == 1)
        //    {
        //        element = (Element)RightList.SelectedItem;
        //        path = RightPath.ToString();
        //    }
        //    else
        //    {
        //        MessageBox.Show("Раскодировать можно только 1 текстовый документ");
        //        return;
        //    }
        //    if (element.isElement == IsElement.IsFile)
        //    {
        //        FileInfo file = new FileInfo(path + "//" + element.Name);
        //        if (file.Extension == ".txt" || file.Extension == ".docx" || file.Extension == ".doc")
        //        {
        //            try
        //            {
        //                using (StreamReader reader = new StreamReader(File.Open(path + "//" + element.Name, FileMode.Open), Encoding.Default))
        //                {
        //                    using (StreamWriter writer = new StreamWriter(File.Open(path + "//" + "DecodingFile.docx", FileMode.CreateNew), Encoding.Default))
        //                    {
        //                        string temp;
        //                        StringBuilder stringBuilder = new StringBuilder(100);
        //                        while ((temp = reader.ReadLine()) != null)
        //                        {

        //                            for (int count = 0; count < temp.Length; count++)
        //                            {
        //                                stringBuilder.Append((char)((char)(temp[count]) - 5));
        //                            }
        //                            writer.WriteLine(stringBuilder.ToString());
        //                            stringBuilder.Clear();
        //                        }
        //                    }
        //                }
        //            }
        //            catch (Exception exc)
        //            {
        //                MessageBox.Show(exc.Message);
        //            }

        //            UpdateFiles();
        //        }
        //        else
        //        {
        //            MessageBox.Show("Документе не имеет требуемое расширение txt, docx или doc");
        //        }
        //    }
        //    else
        //    {
        //        MessageBox.Show("Документе должен быть файлом с расширением txt, docx или doc");
        //    }
        //}

        private void Create(object sender, RoutedEventArgs e)
        {
            string   path     = "";
            MenuItem menuItem = (MenuItem)sender;

            if (menuItem.Parent.GetValue(NameProperty).ToString() == "CreateMenuLeft")
            {
                path = LeftPath.ToString();
            }
            else if (menuItem.Parent.GetValue(NameProperty).ToString() == "CreateMenuRight")
            {
                path = RightPath.ToString();
            }

            if (path != "")
            {
                RenameWindow window = new RenameWindow();
                string       name   = ((MenuItem)sender).Header.ToString();
                window.TextBoxForName.Text = name;
                window.button.Content      = "Создать";
                window.ShowDialog();
                if (IsExistValue)
                {
                    if (name == "новый каталог")
                    {
                        DirectoryInfo directory = new DirectoryInfo(path + window.TextBoxForName.Text);
                        if (!directory.Exists)
                        {
                            try
                            {
                                directory.Create();
                            }
                            catch (System.UnauthorizedAccessException exc)
                            {
                                MessageBox.Show(exc.Message);
                            }
                        }
                        else
                        {
                            MessageBox.Show("Каталог с таким именем уже существует");
                        }
                    }
                    else
                    {
                        FileInfo file = new FileInfo(path + window.TextBoxForName.Text);

                        if (!file.Exists)
                        {
                            try
                            {
                                file.Create();
                            }
                            catch (System.UnauthorizedAccessException exc)
                            {
                                MessageBox.Show(exc.Message);
                            }
                        }
                        else
                        {
                            MessageBox.Show("Данный элемент уже существует");
                        }
                    }
                    IsExistValue = false;
                    UpdateFiles();
                }
            }
            else
            {
                MessageBox.Show("Елемент должен быть создан в разделе диска либо в запоминающем устройстве");
            }
        }