Esempio n. 1
0
        private static void CheckAndUpdateScriptFile(IVuGenScript script)
        {
            Logger.InfoFormat("Checking the script '{0}'...", script.FileName);

            var extraFiles      = script.GetExtraFiles();
            var isDllReferenced = extraFiles
                                  .Any(item => string.Equals(item.FileName, DllName, StringComparison.OrdinalIgnoreCase));

            if (isDllReferenced)
            {
                Logger.InfoFormat("The library '{0}' is referenced; no update is needed.", DllName);
                return;
            }

            Logger.InfoFormat("The library '{0}' is NOT referenced; updating and reopening the script.", DllName);

            var dllFilePath         = Path.Combine(Path.GetDirectoryName(script.FileName).EnsureNotNull(), DllName);
            var extraFileScriptItem = script.GenerateManuallyExtraFileScriptItem(dllFilePath);

            script.AddExtraFile(extraFileScriptItem);
            script.Save(true);

            #region Work-around: VuGen UI does not reflect the changes unless the project is reloaded

            ProjectService.CloseSolution();
            ProjectService.LoadSolutionOrProject(script.FileName);

            #endregion

            ////Logger.InfoFormat("Checking script file '{0}'", scriptFilePath);
            ////using (var scriptStream = File.Open(scriptFilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.Read))
            ////{
            ////    var scriptIni = new IniFile();
            ////    scriptIni.Load(scriptStream);

            ////    var section = scriptIni[DllSectionName];
            ////    if (section.Contains(DllName) && section[DllName] == string.Empty)
            ////    {
            ////        Logger.InfoFormat("No need to update script file '{0}'", scriptFilePath);
            ////        return;
            ////    }

            ////    section[DllName] = string.Empty;

            ////    var backupScriptFilePath = scriptFilePath + BackupExtension;
            ////    Logger.InfoFormat(
            ////        "Creating backup file '{0}' of script file '{1}'",
            ////        backupScriptFilePath,
            ////        scriptFilePath);
            ////    File.Copy(scriptFilePath, backupScriptFilePath, true);

            ////    Logger.InfoFormat("Updating script file '{0}'", scriptFilePath);
            ////    scriptStream.SetLength(0);
            ////    scriptIni.Save(scriptStream);
            ////}
        }
        private static void AddTransactionNames(IVuGenScript script, string usrFileName = null)
        {
            try
            {
                if (script == null)
                {
                    return;
                }
                List <IExtraFileScriptItem> extraFiles          = script.GetExtraFiles();
                IExtraFileScriptItem        dynamicTransacrions = null;
                foreach (IExtraFileScriptItem extraFile in extraFiles)
                {
                    if (extraFile.FileName == "dynamic_transactions.txt") //This is not configurable. This is the file name!
                    {
                        dynamicTransacrions = extraFile;
                        break;
                    }
                }

                if (dynamicTransacrions == null)
                {
                    return;
                }

                string            fileContent      = File.ReadAllText(dynamicTransacrions.FullFileName);
                string[]          transactionNames = fileContent.Split(new String[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                IScriptDataObject scriptData       = script.GenerateDataObject() as IScriptDataObject;
                if (scriptData == null)
                {
                    return;
                }
                List <String> transactionsList = scriptData.SpecialSteps.Transactions;
                transactionsList.AddRange(transactionNames);
                IniUsrFile usr;
                if (usrFileName != null)
                {
                    usr = new IniUsrFile(usrFileName);
                }
                else
                {
                    usr = new IniUsrFile(script.FileName);
                }
                usr.WriteTransactions(transactionsList);
                usr.Save();
            }
            catch
            {
                //Don't want to have adverse influence on the regular usage of VuGen. If this fails it does so silently.
            }
        }
        private static void AddTransactionNames(IVuGenScript script, string usrFileName=null)
        {
            try
              {
            if (script == null) return;
            List<IExtraFileScriptItem> extraFiles = script.GetExtraFiles();
            IExtraFileScriptItem dynamicTransacrions = null;
            foreach (IExtraFileScriptItem extraFile in extraFiles)
            {
              if (extraFile.FileName == "dynamic_transactions.txt") //This is not configurable. This is the file name!
              {
            dynamicTransacrions = extraFile;
            break;
              }
            }

            if (dynamicTransacrions == null) return;

            string fileContent = File.ReadAllText(dynamicTransacrions.FullFileName);
            string[] transactionNames = fileContent.Split(new String[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            IScriptDataObject scriptData = script.GenerateDataObject() as IScriptDataObject;
            if (scriptData == null) return;
            List<String> transactionsList = scriptData.SpecialSteps.Transactions;
            transactionsList.AddRange(transactionNames);
            IniUsrFile usr;
            if (usrFileName != null)
            {
              usr = new IniUsrFile(usrFileName);
            }
            else
            {
              usr = new IniUsrFile(script.FileName);
            }
            usr.WriteTransactions(transactionsList);
            usr.Save();
              }
              catch
              {
            //Don't want to have adverse influence on the regular usage of VuGen. If this fails it does so silently.
              }
        }