Example #1
0
 private void RadDiagnostics_ExceptionOccurred(object sender, ExceptionOccurredEventArgs e)
 {
     //e.Cancel = true; setting Cancel to true will prevent the message box from displaying.
     // add any custom code here, like reporting to a custom web service
     //SendDiagnosticsToWebService((sender as RadDiagnostics).DiagnosticInfo);
 }
        protected virtual void OnExceptionOccurred(ExceptionCatcher sender, ExceptionOccurredEventArgs e)
        {
            var handler = ExceptionOccurred;

            handler?.Invoke(sender, e);
        }
Example #3
0
        public int[] Operate(string[] files, string destination, bool copy, IntPtr handle)
        {
            if (string.IsNullOrEmpty(destination))
            {
                throw new Exception("コピー/移動先が空です。");
            }

            var completedFileIndices = new List <int>();

            try
            {
                completedFileIndices.Capacity = files.Length;
            }
            catch
            {
                throw;
            }

            try
            {
                var operation      = (copy ? new FileOperationFunction(FileOperation.Copy) : new FileOperationFunction(FileOperation.Move));
                var destAndTargets = new Dictionary <string, List <FileItem> >();

                for (int i = 0; i < files.Length; ++i)
                {
                    string fileName = files[i];
                    string source   = fileName;
                    string destRoot = destination;

                    if (!Uri.TryCreate(destRoot, UriKind.Absolute, out Uri uri))
                    {
                        DirectoryInfo directory;

                        try
                        {
                            directory = new DirectoryInfo(Path.GetDirectoryName(fileName));
                        }
                        catch
                        {
                            throw new Exception("ファイル名不正\r\n" + fileName);
                        }

                        if (destRoot.StartsWith(Path.DirectorySeparatorChar.ToString()) ||
                            destRoot.StartsWith(Path.PathSeparator.ToString()))
                        {
                            string root = directory.Root.FullName;

                            if (destRoot.Length < 2)
                            {
                                destRoot = root;
                            }
                            else
                            {
                                try
                                {
                                    destRoot = Path.Combine(root, destRoot.Substring(1));
                                }
                                catch
                                {
                                    throw new Exception("コピー/移動先が不正です。\r\n" + fileName);
                                }
                            }
                        }
                        else
                        {
                            bool current;
                            bool parent;

                            do
                            {
                                current = IsCurrent(destRoot);

                                if (current)
                                {
                                    parent = false;

                                    if (destRoot.Length < 3)
                                    {
                                        throw new Exception("コピー/移動先が不正です。\r\n" + fileName);
                                    }

                                    destRoot = destRoot.Substring(2);
                                    continue;
                                }

                                parent = IsParent(destRoot);

                                if (parent)
                                {
                                    if (destRoot.Length < 4)
                                    {
                                        throw new Exception("コピー/移動先が不正です。\r\n" + fileName);
                                    }

                                    destRoot = destRoot.Substring(3);
                                }
                            }while (current || parent);
                        }
                    }

                    if (!(destRoot.EndsWith(directorySeparatorString)))
                    {
                        destRoot += Path.DirectorySeparatorChar;
                    }

                    string dest = source;
                    dest = dest.Replace("\\\\", directorySeparatorString);
                    dest = dest.Replace(volumeSeparatorString, string.Empty);
                    dest = destRoot + dest;
                    int index = dest.LastIndexOf(directorySeparatorString);

                    if (index < 0)
                    {
                        throw new Exception("コピー先作成不可\r\n" + dest);
                    }

                    dest = dest.Substring(0, index);

                    if (!(destAndTargets.TryGetValue(dest, out List <FileItem> value)))
                    {
                        value = new List <FileItem>
                        {
                            new FileItem(source, i)
                        };

                        destAndTargets.Add(dest, value);
                    }
                    else
                    {
                        value.Add(new FileItem(source, i));
                    }
                }

                foreach (string key in destAndTargets.Keys)
                {
                    try
                    {
                        if (!(destAndTargets.TryGetValue(key, out List <FileItem> files_)))
                        {
                            continue;
                        }

                        var directoryInfo = new DirectoryInfo(key);

                        if (!(directoryInfo.Exists))
                        {
                            directoryInfo.Create();
                        }

                        var fileNames = new string[files_.Count];

                        for (int i = 0; i < fileNames.Length; ++i)
                        {
                            fileNames[i] = files_[i].FileName;
                        }

                        if (operation(fileNames, key, handle))
                        {
                            foreach (FileItem item in files_)
                            {
                                completedFileIndices.Add(item.Index);
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        var eventArgs = new ExceptionOccurredEventArgs(exception, true);
                        ExceptionOccurred(this, eventArgs);

                        if (!eventArgs.Continue)
                        {
                            break;
                        }
                    }
                }
            }
            catch
            {
                throw;
            }

            return(completedFileIndices.ToArray());
        }
Example #4
0
 private void SimplifierFB_ExceptionOccurred(object sender, ExceptionOccurredEventArgs e)
 {
     ClearOutputs();
     MessageBox.Show(e.Exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
 }
Example #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void Diagnostics_ExceptionOccurred(object sender, ExceptionOccurredEventArgs e)
 {
     Diagnostics.ReportHandledException(e.Exception);
 }
Example #6
0
 private void RadDiagnostics_ExceptionOccurred(object sender, ExceptionOccurredEventArgs e)
 {
     //e.Cancel = true; setting Cancel to true will prevent the message box from displaying.
 }