コード例 #1
0
        private void MatterResults_SelectedIndexChanged(object sender, EventArgs e)
        {
            Common.Models.Matters.Matter matter = (Common.Models.Matters.Matter)MatterResults.SelectedItem;
            Task task;

            ProgressBarForm.Show();

            Globals.ThisAddIn.ActiveMatter = matter;

            task = new Task(() =>
            {
                Common.Net.Response <List <Common.Models.Forms.Form> > resp;

                resp = CommManager.ListFormsForMatter(matter.Id.Value);

                if (Extensions.DynamicPropertyExists(resp.Package, "Error"))
                {
                    if (Globals.ThisAddIn.CanLog)
                    {
                        LogManager.GetCurrentClassLogger().Error("Error: " + resp.Error);
                    }
                    MessageBox.Show("Error: " + resp.Error, "Error");
                }
                else
                {
                    FormResults.Invoke(new MethodInvoker(delegate
                    {
                        FormResults.DataSource    = resp.Package;
                        FormResults.DisplayMember = "Title";
                        FormResults.ValueMember   = "Id";

                        ProgressBarForm.Hide();
                        FormResults.Enabled = true;
                        Select.Enabled      = true;
                    }));
                }
            });

            task.Start();
        }
コード例 #2
0
        private static Dictionary <string, List <PreviewMatch> > PreviewRenameGlobalMacros(Regex regex, List <TabInfo> tabs, List <string> files)
        {
            ProgressBarForm pf = (files.Count > 100) ? new ProgressBarForm(Form.ActiveForm, files.Count, "Идет поиск совпадений в файлах проекта...") : null;
            Dictionary <string, List <PreviewMatch> > preview = new Dictionary <string, List <PreviewMatch> >(); // file => mathes

            foreach (var file in files)
            {
                if (pf != null)
                {
                    pf.IncProgress();
                }
                if (TextEditor.CheckTabs(file, tabs))
                {
                    continue;                                   // next file
                }
                string textContent = System.IO.File.ReadAllText(file);
                MatchesCollect(ref preview, regex, file, textContent);
            }
            if (pf != null)
            {
                pf.Dispose();
            }
            return(preview);
        }
コード例 #3
0
        private static void RenameGlobalMacros(Macro macros, string newName, TabInfo cTab, List <TabInfo> tabs, int diff)
        {
            Regex s_regex = new Regex(@"\b" + macros.token + @"\b", RegexOptions.None);

            // preview renamed macros open scripts
            Dictionary <string, List <PreviewMatch> > matchTabs = PreviewRenameGlobalMacros(s_regex, tabs);  // file => mathes

            List <string> files = Directory.GetFiles(Settings.solutionProjectFolder, "*.ssl", SearchOption.AllDirectories).ToList();

            files.AddRange(Directory.GetFiles(Settings.solutionProjectFolder, "*.h", SearchOption.AllDirectories).ToList());

            // preview renamed macros open scripts
            Dictionary <string, List <PreviewMatch> > matchFiles = PreviewRenameGlobalMacros(s_regex, tabs, files);

            // выбор совпадений
            var previewForm = new PreviewRename(macros.defname, macros.defname.Replace(macros.token, newName));

            previewForm.BuildTreeMatches(matchTabs, matchFiles);

            matchTabs.Clear();
            matchFiles.Clear();

            if (previewForm.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            previewForm.GetSelectedMatches(ref matchTabs, ref matchFiles);
            previewForm.Dispose();

            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            int isAdjustSpaces = diff;

            cTab.DisableParseAndStatusChange = true;

            int replaceLen = macros.token.Length;

            foreach (var tabMatches in matchTabs)
            {
                TabInfo tab           = null;
                int     replace_count = 0;
                foreach (var matches in tabMatches.Value)
                {
                    tab = matches.tab;
                    Match match  = matches.match;
                    int   offset = (diff * replace_count) + match.Index;
                    tab.textEditor.Document.Replace(offset, replaceLen, newName);
                    replace_count++;
                }
                if (tab != null)
                {
                    var document = tab.textEditor.Document;
                    if (isAdjustSpaces != 0 && string.Equals(tab.filepath, macros.fdeclared, StringComparison.OrdinalIgnoreCase))
                    {
                        DefineMacroAdjustSpaces(macros, document, diff);
                        isAdjustSpaces = 0;
                    }
                    document.UndoStack.ClearAll();
                    tab.SaveInternal(document.TextContent, tab.textEditor.Encoding); // сохранить изменения в файл
                }
            }

            if (matchFiles.Count == 0)
            {
                cTab.DisableParseAndStatusChange = false;
                return;
            }
            // замена в файлах проекта
            ProgressBarForm pf = (matchFiles.Count > 100) ? new ProgressBarForm(Form.ActiveForm, matchFiles.Count, "Идет замена в файлах проекта...") : null;

            int total = 0;

            foreach (var fileMatches in matchFiles)
            {
                string textContent = System.IO.File.ReadAllText(fileMatches.Key);
                total += fileMatches.Value.Count;

                int replace_count = 0;
                foreach (var matches in fileMatches.Value)
                {
                    int offset = (diff * replace_count) + matches.match.Index;
                    textContent = textContent.Remove(offset, matches.match.Length);
                    textContent = textContent.Insert(offset, newName);
                    replace_count++;
                }
                if (isAdjustSpaces != 0 && string.Equals(fileMatches.Key, macros.fdeclared, StringComparison.OrdinalIgnoreCase))
                {
                    DefineMacroAdjustSpaces(macros, newName, ref textContent, diff);
                    isAdjustSpaces = 0;
                }
                if (replace_count > 0)
                {
                    File.WriteAllText(fileMatches.Key, textContent, (Settings.saveScriptUTF8) ? new UTF8Encoding(false) : Encoding.Default);
                }
                if (pf != null)
                {
                    pf.IncProgress();
                }
            }
            if (pf != null)
            {
                pf.Dispose();
            }

            //MessageBox.Show(String.Format("Произведено переименование {0} макросов, в {1} файлах.", total, previewFiles.Count));
            cTab.DisableParseAndStatusChange = false;
        }
コード例 #4
0
        public void DownloadModule(Module module)
        {
            try
            {
                string userModDir      = Path.Combine(Program.BaseDirectoryExternal, "user_mods");
                var    installedModule = GetInstalledModule(module);
                //If module is installed remove it
                if (installedModule != null)
                {
                    foreach (var file in installedModule.InstalledFiles)
                    {
                        try
                        {
                            if (file.EndsWith("\\"))
                            {
                                Directory.Delete(Path.Combine(userModDir, file), true);
                            }
                            else
                            {
                                File.Delete(Path.Combine(userModDir, file));
                            }
                        }
                        catch { }
                    }

                    InstalledItems.Remove(installedModule);
                    installedModule = null;
                }
                switch (module.ModType)
                {
                case ModuleType.hmod:
                {
                    string fileLocation = Path.Combine(userModDir, module.Path.Substring(module.Path.LastIndexOf('/') + 1));

                    if (!ProgressBarForm.DownloadFile(module.Path, fileLocation))
                    {
                        throw new Exception("Cannot download file: " + module.Path);
                    }
                    installedModule = module.CreateInstalledItem();
                    installedModule.InstalledFiles.Add(module.Path.Substring(module.Path.LastIndexOf('/') + 1));
                    InstalledItems.Add(installedModule);
                }
                break;

                case ModuleType.compressedFile:
                    var tempFileName = Path.GetTempFileName();
                    if (!ProgressBarForm.DownloadFile(module.Path, tempFileName))
                    {
                        throw new Exception("Cannot download file: " + module.Path);
                    }
                    using (var extractor = ArchiveFactory.Open(tempFileName))
                    {
                        installedModule = module.CreateInstalledItem();
                        foreach (var file in extractor.Entries)
                        {
                            int index = file.Key.IndexOf('/');
                            if (index != -1)
                            {
                                var folder = file.Key.Substring(0, index + 1);
                                if (!installedModule.InstalledFiles.Contains(folder))
                                {
                                    installedModule.InstalledFiles.Add(folder);
                                    var localFolder = Path.Combine(userModDir, folder);
                                    if (Directory.Exists(localFolder))
                                    {
                                        Directory.Delete(localFolder, true);
                                    }
                                }
                            }
                            else if (!file.IsDirectory)
                            {
                                installedModule.InstalledFiles.Add(file.Key);
                            }
                        }
                        extractor.WriteToDirectory(userModDir, new SharpCompress.Common.ExtractionOptions()
                        {
                            ExtractFullPath = true, Overwrite = true
                        });
                        InstalledItems.Add(installedModule);
                    }
                    File.Delete(tempFileName);
                    break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Critical error: " + ex.Message + ex.StackTrace, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            SaveConfig();
        }
コード例 #5
0
        public void DownloadModule(Module module)
        {
            try
            {
                string userModDir      = Path.Combine(Program.BaseDirectoryExternal, "user_mods");
                var    installedModule = GetInstalledModule(module);
                //If module is installed remove it
                if (installedModule != null)
                {
                    foreach (var file in installedModule.InstalledFiles)
                    {
                        try
                        {
                            if (file.EndsWith("\\"))
                            {
                                Directory.Delete(Path.Combine(userModDir, file), true);
                            }
                            else
                            {
                                File.Delete(Path.Combine(userModDir, file));
                            }
                        }
                        catch { }
                    }

                    InstalledItems.Remove(installedModule);
                    installedModule = null;
                }
                switch (module.ModType)
                {
                case ModuleType.hmod:
                {
                    string fileLocation = Path.Combine(userModDir, module.Path.Substring(module.Path.LastIndexOf('/') + 1));

                    if (!ProgressBarForm.DownloadFile(module.Path, fileLocation))
                    {
                        throw new Exception("Cannot download file: " + module.Path);
                    }
                    installedModule = module.CreateInstalledItem();
                    installedModule.InstalledFiles.Add(module.Path.Substring(module.Path.LastIndexOf('/') + 1));
                    InstalledItems.Add(installedModule);
                }
                break;

                case ModuleType.compressedFile:
                    SevenZipExtractor.SetLibraryPath(Path.Combine(Program.BaseDirectoryInternal, IntPtr.Size == 8 ? @"tools\7z64.dll" : @"tools\7z.dll"));
                    var tempFileName = Path.GetTempFileName();
                    if (!ProgressBarForm.DownloadFile(module.Path, tempFileName))
                    {
                        throw new Exception("Cannot download file: " + module.Path);
                    }
                    using (var szExtractor = new SevenZipExtractor(tempFileName))
                    {
                        installedModule = module.CreateInstalledItem();
                        var data = szExtractor.ArchiveFileData;
                        foreach (var file in data)
                        {
                            int index = file.FileName.IndexOf('\\');
                            if (index != -1)
                            {
                                var folder = file.FileName.Substring(0, index + 1);
                                if (!installedModule.InstalledFiles.Contains(folder))
                                {
                                    installedModule.InstalledFiles.Add(folder);
                                    var localFolder = Path.Combine(userModDir, folder);
                                    if (Directory.Exists(localFolder))
                                    {
                                        Directory.Delete(localFolder, true);
                                    }
                                }
                            }
                            else if (!file.IsDirectory)
                            {
                                installedModule.InstalledFiles.Add(file.FileName);
                            }
                        }
                        szExtractor.ExtractArchive(userModDir);
                        InstalledItems.Add(installedModule);
                    }
                    File.Delete(tempFileName);
                    break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Critical error: " + ex.Message + ex.StackTrace, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            SaveConfig();
        }
コード例 #6
0
        public static void Calculate(IList<IActivity> activities, List<CalculatedFieldsRow> filter, bool testRun)
        {
            if ((activities != null) && (activities.Count > 0))
            {
                var progressBarForm = new ProgressBarForm();
                progressBarForm.Text = Resources.StringResources.ProgressFormTitle;

                progressBarForm.Show();

                object result;

                int actualActivity = 0;

                try
                {
                    SmoothingBackup();

                    foreach (IActivity activity in activities)
                    {
                        if (testRun)
                        {
                            progressBarForm.ProgressBarLabelText = "Testing calculation of fields for activity " + ++actualActivity +
                                                                   "/30";
                            progressBarForm.ProgressBarValue += 1000000 / 30;
                        }
                        else
                        {
                            progressBarForm.ProgressBarLabelText = "Calculating fields for activity " + ++actualActivity +
                                                                   "/" + activities.Count.ToString();
                            progressBarForm.ProgressBarValue += 1000000 / activities.Count;
                        }

                        virtualFields.Clear();

                        foreach (var virtualFieldsRow in GlobalSettings.virtualFieldsRows)
                        {
                            SmoothingSetTemporary(virtualFieldsRow);

                            if (virtualFieldsRow.Condition != "")
                            {
                                var conditionResult = Evaluate(virtualFieldsRow.Condition, activity, "", virtualFieldsRow);

                                if (conditionResult != null && conditionResult.ToString() == "True")
                                {
                                    result = Evaluate(
                                        virtualFieldsRow.CalculatedExpression,
                                        activity,
                                        virtualFieldsRow.Condition,
                                        virtualFieldsRow);

                                    if (result == "")
                                    {
                                        result = "NaN";
                                    }
                                }
                                else
                                {
                                    result = "NaN";
                                }
                            }
                            else
                            {
                                result = Evaluate(virtualFieldsRow.CalculatedExpression, activity, "", virtualFieldsRow);
                            }

                            //throw new Exception(result.ToString());

                            if (result != null)
                            {
                                virtualFields.Add(virtualFieldsRow.CustomField.ToUpper(), result);
                            }

                            SmoothingSetDefault();
                        }

                        ICustomDataFieldObjectType type =
                            CustomDataFieldDefinitions.StandardObjectType(typeof(IActivity));

                        foreach (ICustomDataFieldDefinition definition in CalculatedFields.GetLogBook().CustomDataFieldDefinitions)
                        {
                            if (progressBarForm.Cancelled || (testRun && actualActivity >= 30))
                            {
                                SmoothingSetDefault();
                                progressBarForm.Close();
                                break;
                            }

                            if ((filter != null && filter.Exists((o) => (o.CustomField == definition.Name))) || filter == null)
                            {
                                if (definition.ObjectType == type &&
                                    GlobalSettings.calculatedFieldsRows.Exists(
                                        (o) => (o.CustomField == definition.Name && o.Active == "Y")))
                                {
                                    var allCalculatedFieldsRow = GlobalSettings.calculatedFieldsRows.Where((o) => o.CustomField == definition.Name);

                                    foreach (var calculatedFieldsRow in allCalculatedFieldsRow)
                                    {
                                        SmoothingSetTemporary(calculatedFieldsRow);

                                        if (calculatedFieldsRow.Condition != "")
                                        {
                                            var conditionResult = Evaluate(calculatedFieldsRow.Condition, activity, "", calculatedFieldsRow);

                                            if (conditionResult != null && conditionResult.ToString() == "True")
                                            {
                                                result = Evaluate(
                                                    calculatedFieldsRow.CalculatedExpression,
                                                    activity,
                                                    calculatedFieldsRow.Condition,
                                                    calculatedFieldsRow);
                                            }
                                            else
                                            {
                                                result = null;
                                            }
                                        }
                                        else
                                        {
                                            result = Evaluate(
                                                calculatedFieldsRow.CalculatedExpression, activity, "", calculatedFieldsRow);
                                        }

                                        if (result != null && !testRun)
                                        {
                                            if (definition.DataType.Id ==
                                                CustomDataFieldDefinitions.StandardDataTypes.NumberDataTypeId)
                                            {
                                                activity.SetCustomDataValue(definition, Double.Parse(result.ToString()));
                                            }
                                            else if (definition.DataType.Id ==
                                                     CustomDataFieldDefinitions.StandardDataTypes.TextDataTypeId)
                                            {
                                                activity.SetCustomDataValue(definition, result.ToString());
                                            }
                                            else if (definition.DataType.Id ==
                                                     CustomDataFieldDefinitions.StandardDataTypes.TimeSpanDataTypeId)
                                            {
                                                double seconds = double.Parse(result.ToString());
                                                activity.SetCustomDataValue(
                                                    definition,
                                                    new TimeSpan(
                                                        (int)(seconds / 3600),
                                                        (int)((seconds % 3600) / 60),
                                                        (int)(seconds % 60)));
                                            }
                                        }

                                        SmoothingSetDefault();
                                    }
                                }
                            }

                            Application.DoEvents();
                        }

                        virtualFields.Clear();

                        if (progressBarForm.Cancelled || (testRun && actualActivity >= 30))
                        {
                            SmoothingSetDefault();
                            progressBarForm.Close();
                            break;
                        }
                    }
                }
                catch (Exception)
                {
                    SmoothingSetDefault();
                    progressBarForm.Close();

                    throw;
                }

                SmoothingSetDefault();
                progressBarForm.Close();
            }
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: randolphb1/MyTestRepo
        /// <summary>
        /// The main worker thread
        /// </summary>
        /// <param name="options">A CMyOptions object</param>
        public static void ThreadFunc(Object options)
        {
            CMyOptions opts = (CMyOptions) options;
            SuperFileFinderDriver ffd = new SuperFileFinderDriver();
            List<String> availableDrives = ffd.GetDrives( opts.fOptionLocalDrivesOnly );
            List<String> drives = new List<String>();
            DateTime start = DateTime.Now;

            if ( opts.aOptionDrives.Count > 0 )
            {
                String str;

                foreach ( String o in opts.aOptionDrives )
                {
                    str = o;

                    if ( o == "." )
                    {
                        str = ffd.GetCurrentDirectory();

                        if ( !str.EndsWith( "\\" ) )
                        {
                            str += "\\";
                        }
                    }

                    foreach ( String d in availableDrives )
                    {
                        if ( str.ToUpper().Contains( d.ToUpper() ) )
                        {
                            try
                            {
                                System.IO.DirectoryInfo di = new System.IO.DirectoryInfo( str );

                                if ( di.Exists )
                                {
                                    drives.Add( str );
                                }
                            }
                            catch ( SecurityException se )
                            {
                                Console.Error.WriteLine( se.ToString() );
                            }

                            break;
                        }
                    }
                }
            }
            else
            {
                drives = availableDrives;
            }

            if ( drives.Count > 0 )
            {
                int folder_count = 0;

                if ( opts.fJustFilenames == false )
                {
                    Console.WriteLine( "Searching for filenames containing [{0}] on drive{1} {2}",
                                        String.Join( " | ", opts.myArgs.ToArray() ).ToUpper(),
                                        drives.Count > 1 ? "s" : "",
                                        String.Join( ",", drives.ToArray() ).ToUpper() );
                }

                pbf = new ProgressBarForm();
                pbf.Show( 1000 );
                pbs = new ProgressBarSink( pbf );

                foreach ( String driveLetter in drives )
                {
                    folder_count += ffd.GetFoldersCount( driveLetter, pbs );
                }

                pbf.SetMax( folder_count );
                pbf.SetValue( 0 );

                foreach ( String driveLetter in drives )
                {
                    ffd.FindFolders( driveLetter, opts.myArgs, opts.fJustFilenames, pbs );
                }

                pbf.Hide();
            }
            else
            {
                Console.Error.WriteLine( "ERROR: Specified drives or folders do not exist- {0}",
                                         String.Join( ", ", opts.aOptionDrives.ToArray() ).ToUpper() );
            }

            if ( opts.fJustFilenames == false )
            {
                DateTime end = DateTime.Now;
                TimeSpan diff = end - start;
                Console.WriteLine( "{0} files found\nExecution time: {1}", ffd.Count, diff );
            }
        }
コード例 #8
0
    private void mCANoeProgProgressChangedInternal(object sender, EventArgs e)
    {
        ProgressBarForm frm = new ProgressBarForm();

        frm.DoSomething(value);
    }
コード例 #9
0
 public RowInsertCounter(ProgressBarForm form)
 {
     this.form = form;
 }