Ejemplo n.º 1
0
        private void BeforeQueryStatus(object sender, EventArgs e)
        {
            var button = (OleMenuCommand)sender;
            var files  = ProjectHelpers.GetSelectedItemPaths();

            button.Visible = false;

            if (files.Count() != 1)
            {
                return;
            }

            string file = files.First();

            if (!BundleService.IsSupported(file))
            {
                return;
            }

            string fileName = Path.GetFileName(file);
            string ext      = Path.GetExtension(fileName).ToUpperInvariant();
            string minFile;
            bool   hasMinFile = FileHelpers.HasMinFile(file, out minFile);

            button.Visible = !fileName.Contains(".min.") && !hasMinFile;
        }
Ejemplo n.º 2
0
        private void Execute(object sender, EventArgs e)
        {
            var question = $"This will generate {GULP_FILE_NAME} and install the npm packages needed (it will take a minute or two).\r\nNo files will be deleted.\r\n\r\nDo you wish to continue?";
            var answer   = MessageBox.Show(question, Vsix.Name, MessageBoxButton.OKCancel, MessageBoxImage.Question);

            if (answer == MessageBoxResult.Cancel)
            {
                return;
            }

            var project = ProjectHelpers.GetActiveProject();
            var root    = project.GetRootFolder();

            var bundleConfigFile = Path.Combine(root, Constants.CONFIG_FILENAME);

            StripCommentsFromJsonFile(bundleConfigFile);

            var packageFile = Path.Combine(root, "package.json");
            var gulpFile    = Path.Combine(root, GULP_FILE_NAME);

            CreateFileAndIncludeInProject(project, packageFile);
            CreateFileAndIncludeInProject(project, gulpFile);

            BundlerMinifierPackage._dte.StatusBar.Text = "Installing node modules...";
            InstallNodeModules(Dispatcher.CurrentDispatcher, root, "del", "gulp", "gulp-concat", "gulp-cssmin", "gulp-htmlmin", "gulp-uglify", "merge-stream");
            BundleService.ToggleOutputProduction(project.GetConfigFile(), false);
        }
Ejemplo n.º 3
0
            public ServicesHolder(IReadOnlyList <IServices> services)
            {
                for (int i = 0; i < services.Count; i++)
                {
                    // Put in here services
                    // Can be more optimized than that, but I don't have time
                    if (sceneService == null)
                    {
                        sceneService = services[i] as SceneManagementService;
                    }

                    if (jsonConverter == null)
                    {
                        jsonConverter = services[i] as IConverter;
                    }

                    if (webLoader == null)
                    {
                        webLoader = services[i] as URLLoader;
                    }

                    if (bundleService == null)
                    {
                        bundleService = services[i] as BundleService;
                    }
                }
            }
Ejemplo n.º 4
0
        private void BeforeQueryStatus(object sender, EventArgs e)
        {
            var button = (OleMenuCommand)sender;
            var items  = ProjectHelpers.GetSelectedItems();

            button.Visible = false;

            if (items.Count() != 1)
            {
                return;
            }

            var item = items.First();

            if (item == null || item.ContainingProject == null || item.Properties == null)
            {
                return;
            }

            var sourceFile = item.Properties.Item("FullPath").Value.ToString();

            if (!BundleService.IsSupported(sourceFile))
            {
                return;
            }

            string configFile = item.ContainingProject.GetConfigFile();

            _bundles = BundleService.IsOutputConfigered(configFile, sourceFile);

            button.Visible = _bundles.Any();
        }
Ejemplo n.º 5
0
        /// <summary>Starts the file system watcher on the project root folder if it isn't already running.</summary>
        public void EnsureProjectIsActive(Project project)
        {
            if (project == null || _listeners.ContainsKey(project))
            {
                return;
            }

            var config = project.GetConfigFile();

            if (!BundleService.IsOutputProduced(config))
            {
                return;
            }

            try
            {
                if (!string.IsNullOrEmpty(config) && File.Exists(config))
                {
                    var fsw = new FileSystemWatcher(project.GetRootFolder());

                    fsw.Changed += FileChanged;
                    fsw.Renamed += FileChanged;

                    fsw.IncludeSubdirectories = true;
                    fsw.NotifyFilter          = NotifyFilters.Size | NotifyFilters.CreationTime | NotifyFilters.FileName;
                    fsw.EnableRaisingEvents   = true;

                    _listeners.TryAdd(project, fsw);
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }
        }
Ejemplo n.º 6
0
        private void UpdateSelectedBundle(object sender, EventArgs e)
        {
            try
            {
                var file = ProjectHelpers.GetSelectedItemPaths().FirstOrDefault();

                if (string.IsNullOrEmpty(file)) // Project
                {
                    var project = ProjectHelpers.GetActiveProject();

                    if (project != null)
                    {
                        file = project.GetConfigFile();
                    }
                }

                if (!string.IsNullOrEmpty(file))
                {
                    BundleService.Process(file);
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }
        }
Ejemplo n.º 7
0
 private void DocumentSaved(object sender, TextDocumentFileActionEventArgs e)
 {
     if (e.FileActionType == FileActionTypes.ContentSavedToDisk)
     {
         BundleService.Process(e.FilePath);
     }
 }
        private void DocumentSaved(object sender, TextDocumentFileActionEventArgs e)
        {
            if (e.FileActionType == FileActionTypes.ContentSavedToDisk)
            {
                var item = BundlerMinifierPackage._dte.Solution.FindProjectItem(e.FilePath);

                if (item != null && item.ContainingProject != null)
                {
                    string configFile = item.ContainingProject.GetConfigFile();

                    ErrorList.CleanErrors(e.FilePath);

                    if (File.Exists(configFile))
                    {
                        BundleService.SourceFileChanged(configFile, e.FilePath);
                    }

                    string minFile;

                    if (FileHelpers.HasMinFile(e.FilePath, out minFile))
                    {
                        BundleService.MinifyFile(e.FilePath);
                    }
                }
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 加载bundle
        /// </summary>
        /// <param name="path">bundle路径</param>
        /// <param name="complete"></param>
        public void LoadBundle(string path, Action <string, bool> complete)
        {
            BundlePackInfo p = GetPackInfo(path);

            if (p == null)
            {
                if (complete != null)
                {
                    complete(path, false);
                }

                return;
            }

            StartCoroutine(BundleService.GetInstance().LoadAsync(p, delegate(BundleRef bundle)
            {
                if (bundle != null && complete != null)
                {
                    complete(bundle.Path, true);
                }
            }, delegate(BundlePackInfo packInfo, string error) {
                if (packInfo != null && complete != null)
                {
                    complete(packInfo.Path, false);
                }
            }, null));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 加载常驻bundle
        /// </summary>
        /// <param name="complete"></param>
        /// <param name="progress"></param>
        /// <returns></returns>
        public IEnumerator LoadResidentBundles(Action complete = null, BundleBatchLoadingDelegate progress = null)
        {
            ResPackConfig config = ResService.GetInstance().PackConfig;

            if (config == null)
            {
                JW.Common.Log.LogE("In LoadResidentBundles(), but ResPackConfig is null.");

                if (complete != null)
                {
                    complete();
                }

                yield break;
            }

            JWObjList <BundlePackInfo> bundleList = new JWObjList <BundlePackInfo>();

            for (int i = 0; i < config.PackInfo.Count; i++)
            {
                BundlePackInfo p = config.PackInfo[i] as BundlePackInfo;
                if (p != null && p.Life == EBundleLife.Resident)
                {
                    bundleList.Add(p);
                }
            }

            yield return(StartCoroutine(BundleService.GetInstance().BatchLoadAsync(bundleList, complete, progress)));
        }
Ejemplo n.º 11
0
        void TimerElapsed(object state)
        {
            try
            {
                var items = _queue.Where(i => i.Value.Timestamp < DateTime.Now.AddMilliseconds(-250));

                foreach (var item in items)
                {
                    BundleService.SourceFileChanged(item.Value.ConfigFile, item.Key);
                }

                foreach (var item in _queue)
                {
                    QueueItem old;
                    if (item.Value.Timestamp < DateTime.Now.AddMilliseconds(-250))
                    {
                        _queue.TryRemove(item.Key, out old);
                    }
                }

                foreach (var fsw in _listeners.Values)
                {
                    fsw.EnableRaisingEvents = true;
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }
        }
Ejemplo n.º 12
0
        private void BeforeQueryStatus(object sender, EventArgs e)
        {
            var button = (OleMenuCommand)sender;
            var files  = ProjectHelpers.GetSelectedItemPaths();

            button.Visible = false;

            int count = files.Count();

            if (count == 0) // Project
            {
                var project = ProjectHelpers.GetActiveProject();

                if (project == null)
                {
                    return;
                }

                string config = project.GetConfigFile();

                if (!string.IsNullOrEmpty(config) && File.Exists(config))
                {
                    button.Visible = true;
                    button.Enabled = button.Visible && BundleService.IsOutputProduced(config);
                }
            }
            else
            {
                button.Visible = files.Count() == 1 && Path.GetFileName(files.First()) == Constants.CONFIG_FILENAME;
                button.Enabled = button.Visible && BundleService.IsOutputProduced(files.First());
            }
        }
Ejemplo n.º 13
0
        public void RunLocalTest()
        {
            LocalBundleStore localStore = new LocalBundleStore();

            for (int i = 0; i < inputBundleIds.Length; i++)
            {
                string bundleId = inputBundleIds[i];
                Assert.IsFalse(localStore.HasReference(bundleId));
                string bundlePath = Path.Combine(Test1.TestDataParentPath, inputBundlePaths[i]);
                localStore.PutReference(bundleId, bundlePath);
                Assert.IsTrue(localStore.HasReference(bundleId));
                var bundleRef = localStore.GetReference(bundleId);
                Assert.IsNotNull(bundleRef.Value);
            }

            BundleStore store = localStore.GetStore();

            Assert.IsNotNull(store);

            string bundleSvcPath = Path.Combine(_context.TestRunDirectory, @"RunLocalTestBundles");

            Directory.CreateDirectory(bundleSvcPath);
            BundleService bundleSvc = new BundleService(store, bundleSvcPath, false);

            var runId    = inputBundleIds[2];
            var outputId = runId.Substring(0, runId.Length - Path.GetExtension(runId).Length) + @"/output.zip";

            Assert.AreEqual(outputId, outputBundleIds[0]);
            Assert.IsFalse(bundleSvc.Has(outputId));

            Run.executeIt(bundleSvc, runId, LocalDiagnostics.get());

            Assert.IsTrue(bundleSvc.Has(outputId));
            Assert.IsTrue(localStore.HasReference(outputId));
            var outputRef = localStore.GetReference(outputId);

            Assert.IsTrue(outputRef.Value.IsZipBundle);

            var outputBundle = bundleSvc.Get(outputId);

            Assert.IsNotNull(outputBundle);
            var scorepath = Path.Combine(outputBundle.AbsolutePath, @"scores.txt");

            Assert.IsTrue(File.Exists(scorepath));
            string[] lines = File.ReadAllLines(scorepath);
            Assert.AreEqual(1, lines.Length);
            string[] line1Parts = lines[0].Split(':');
            Assert.AreEqual(2, line1Parts.Length);
            Assert.AreEqual("Difference", line1Parts[0].Trim());
            Assert.AreEqual("0.041593", line1Parts[1].Trim());

            var stdoutPath = Path.Combine(bundleSvcPath, @"competition1\submission1\run\stdout.txt");

            Assert.IsTrue(File.Exists(scorepath));
            var stderrPath = Path.Combine(bundleSvcPath, @"competition1\submission1\run\stderr.txt");

            Assert.IsTrue(File.Exists(scorepath));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// unload bundle
        /// </summary>
        /// <param name="path">bundle路径</param>
        public void UnloadBundle(string path, bool immediately = false)
        {
            BundlePackInfo packInfo = GetPackInfo(path);

            if (packInfo != null)
            {
                BundleService.GetInstance().Unload(packInfo, immediately);
            }
        }
Ejemplo n.º 15
0
        private void AddBundle(object sender, EventArgs e)
        {
            var item = ProjectHelpers.GetSelectedItems().FirstOrDefault();

            if (item == null || item.ContainingProject == null)
            {
                return;
            }

            string folder              = item.ContainingProject.GetRootFolder();
            string configFile          = Path.Combine(folder, Constants.CONFIG_FILENAME);
            IEnumerable <string> files = ProjectHelpers.GetSelectedItemPaths().Select(f => BundlerMinifier.FileHelpers.MakeRelative(configFile, f));
            string inputFile           = item.Properties.Item("FullPath").Value.ToString();
            string outputFile          = inputFile;

            if (files.Count() > 1)
            {
                outputFile = GetOutputFileName(inputFile, Path.GetExtension(files.First()));
            }
            else
            {
                // Reminify file
                var bundles = BundleFileProcessor.IsFileConfigured(configFile, inputFile);

                if (bundles.Any())
                {
                    BundleService.SourceFileChanged(configFile, inputFile);
                    Telemetry.TrackEvent("VS recompile config");
                    return;
                }
            }

            if (string.IsNullOrEmpty(outputFile))
            {
                return;
            }

            BundlerMinifierPackage._dte.StatusBar.Progress(true, "Creating bundle", 0, 2);

            string relativeOutputFile = BundlerMinifier.FileHelpers.MakeRelative(configFile, outputFile);
            Bundle bundle             = CreateBundleFile(files, relativeOutputFile);

            BundleHandler.AddBundle(configFile, bundle);

            BundlerMinifierPackage._dte.StatusBar.Progress(true, "Creating bundle", 1, 2);

            item.ContainingProject.AddFileToProject(configFile, "None");
            BundlerMinifierPackage._dte.StatusBar.Progress(true, "Creating bundle", 2, 2);

            BundleService.Process(configFile);
            BundlerMinifierPackage._dte.StatusBar.Progress(false, "Creating bundle");
            BundlerMinifierPackage._dte.StatusBar.Text = "Bundle created";

            Telemetry.TrackEvent("VS create bundle");
        }
Ejemplo n.º 16
0
        private void BeforeQueryStatus(object sender, EventArgs e)
        {
            var button = (OleMenuCommand)sender;

            button.Enabled = button.Visible = false;

            var files     = ProjectHelpers.GetSelectedItemPaths();
            var supported = BundleFileProcessor.IsSupported(files.ToArray());

            if (supported)
            {
                if (files.Count() == 1)
                {
                    var sourceFile = files.First();
                    var project    = BundlerMinifierPackage._dte.Solution.FindProjectItem(sourceFile)?.ContainingProject;
                    var configFile = project.GetConfigFile();

                    var  bundles   = BundleService.IsOutputConfigered(configFile, sourceFile);
                    bool isMinFile = Path.GetFileName(sourceFile).Contains(".min.");

                    if (!bundles.Any() && !isMinFile)
                    {
                        var minFileName = FileHelpers.GetMinFileName(sourceFile, bundles.FirstOrDefault <Bundle>().MinFileName);

                        bundles = BundleService.IsOutputConfigered(configFile, minFileName);
                    }

                    if (bundles.Any())
                    {
                        if (isMinFile)
                        {
                            button.Text = Resources.Text.ButtonReMinify;
                        }
                        else
                        {
                            button.Text = Resources.Text.ButtonReBundle;
                        }
                    }
                    else if (BundleFileProcessor.IsFileConfigured(configFile, sourceFile).Any())
                    {
                        supported = false;
                    }
                    else if (!isMinFile)
                    {
                        button.Text = Resources.Text.ButtonMinify;
                    }
                }
                else
                {
                    button.Text = Resources.Text.ButtonBundle;
                }

                button.Visible = button.Enabled = supported;
            }
        }
Ejemplo n.º 17
0
        public void LoadBundleSync(JWObjList <string> resourceList)
        {
            JWObjList <BundlePackInfo> bundles = GetBundleList(resourceList);

            if (bundles == null || bundles.Count == 0)
            {
                return;
            }

            BundleService.GetInstance().LoadSync(bundles[0]);
        }
Ejemplo n.º 18
0
        private void DocumentSaved(object sender, TextDocumentFileActionEventArgs e)
        {
            if (!BundlerMinifierPackage.Options.ReRunOnSave)
            {
                return;
            }

            if (e.FileActionType == FileActionTypes.ContentSavedToDisk)
            {
                BundleService.Process(e.FilePath);
            }
        }
Ejemplo n.º 19
0
        private void Execute(object sender, EventArgs e)
        {
            var button     = (OleMenuCommand)sender;
            var project    = ProjectHelpers.GetActiveProject();
            var configFile = project?.GetConfigFile();

            if (!string.IsNullOrEmpty(configFile))
            {
                BundleService.ToggleOutputProduction(configFile, !button.Checked);
                ProjectEventCommand.Instance.EnsureProjectIsActive(project);
            }
        }
Ejemplo n.º 20
0
        private void DocumentSaved(object sender, TextDocumentFileActionEventArgs e)
        {
            if (ProjectEventCommand.Instance != null)
            {
                var project = BundlerMinifierPackage._dte.Solution?.FindProjectItem(e.FilePath)?.ContainingProject;
                ProjectEventCommand.Instance.EnsureProjectIsActive(project);
            }

            if (e.FileActionType == FileActionTypes.ContentSavedToDisk)
            {
                BundleService.Process(e.FilePath);
            }
        }
Ejemplo n.º 21
0
        private void UpdateSelectedBundle(object sender, EventArgs e)
        {
            var projects = ProjectHelpers.GetAllProjects();

            foreach (Project project in projects)
            {
                string config = project.GetConfigFile();

                if (!string.IsNullOrEmpty(config))
                {
                    BundleService.Process(config);
                }
            }
        }
Ejemplo n.º 22
0
        public void GetGoldBundle_Fail()
        {
            var answer = new AnswerModel()
            {
                Age = 17,
                Student = false,
                Income = 50000
            };
            var bundleService = new BundleService();

            var result = bundleService.GetRecommendedBundle(answer);

            Assert.True(result.Success && result.Bundle.Id == 1 && result.Products.Count == 1);
        }
Ejemplo n.º 23
0
        public void GetJuniorBundle_Fail()
        {
            var answer = new AnswerModel()
            {
                Age = 18,
                Student = false,
                Income = 0
            };
            var bundleService = new BundleService();

            var result = bundleService.GetRecommendedBundle(answer);

            Assert.True(result.Success == false);
        }
Ejemplo n.º 24
0
        public void GetStudentBundle_Ok()
        {
            var answer = new AnswerModel()
            {
                Age = 18,
                Student = true,
                Income = 0
            };
            var bundleService = new BundleService();

            var result = bundleService.GetRecommendedBundle(answer);

            Assert.True(result.Success && result.Bundle.Id == 2 && result.Products.Count == 3);
        }
Ejemplo n.º 25
0
        public void GetClassicPlusBundle_Ok()
        {
            var answer = new AnswerModel()
            {
                Age = 18,
                Student = false,
                Income = 12001
            };
            var bundleService = new BundleService();

            var result = bundleService.GetRecommendedBundle(answer);

            Assert.True(result.Success && result.Bundle.Id == 4 && result.Products.Count == 3);
        }
Ejemplo n.º 26
0
        private void UpdateSelectedBundle(object sender, EventArgs e)
        {
            var projects = ProjectHelpers.GetAllProjects();

            foreach (Project project in projects)
            {
                string folder  = Path.GetDirectoryName(project.GetRootFolder());
                var    configs = GetFiles(folder, Constants.CONFIG_FILENAME);

                foreach (string config in configs)
                {
                    if (!string.IsNullOrEmpty(config))
                    {
                        BundleService.Process(config);
                    }
                }
            }
        }
Ejemplo n.º 27
0
 /// <summary>
 /// 初始化公共层
 /// </summary>
 /// <param name="initialize">初始化//反初始化</param>
 public static void InitCommon(bool initialize)
 {
     if (initialize)
     {
         //统一随机数
         UnityEngine.Random.InitState((int)DateTime.Now.Ticks);
         //开启日志
         Log.GetInstance();
         BundleService.GetInstance();
         ResService.GetInstance();
         //全局
         DG.Tweening.DOTween.Init(true, true, DG.Tweening.LogBehaviour.ErrorsOnly);
     }
     else
     {
         ResService.DestroyInstance();
         BundleService.DestroyInstance();
     }
 }
Ejemplo n.º 28
0
        /// 游戏更新检查后后启动
        public void StartAfterUpdate(Action <bool> allCompletedCallback)
        {
            _allCompletedCallback = allCompletedCallback;
#if USE_PACK_RES
            if (ResService.GetInstance().PackConfig == null)
            {
                JW.Common.Log.LogE("Preloader.StartAfterUpdate : resource initialize failed");
                return;
            }
            //
            _bundleFiles   = BundleMediator.GetInstance().GetPreloadBundles();
            _bundleLoading = false;

            string filename = "main_shaders.ab";
            _shaderBundle = BundleService.GetInstance().GetBundle(filename);
            if (_shaderBundle == null)
            {
                JW.Common.Log.LogE("Preloader.StartAfterUpdate : failed to get shader bundle");
            }

            ResPackInfo pi = ResService.GetInstance().PackConfig.GetPackInfo(filename);
            if (pi == null)
            {
                _shaderFilename = new JWArrayList <string>(0);
            }
            else
            {
                _shaderFilename = new JWArrayList <string>(pi.Resources.Count);
                for (int i = 0; i < pi.Resources.Count; i++)
                {
                    _shaderFilename.Add(pi.Resources[i].Path);
                }
            }
#else
            _bundleFiles    = new JWObjList <string>(0);
            _shaderBundle   = null;
            _shaderFilename = new JWArrayList <string>(0);
#endif

            //真正的开始预加载协成
            StartCoroutine(PreloadCoroutine());
        }
Ejemplo n.º 29
0
        private void UpdateSelectedBundle(object sender, EventArgs e)
        {
            var file = ProjectHelpers.GetSelectedItemPaths().FirstOrDefault();

            if (string.IsNullOrEmpty(file)) // Project
            {
                var project = ProjectHelpers.GetActiveProject();

                if (project != null)
                {
                    file = project.GetConfigFile();
                }
            }

            if (!string.IsNullOrEmpty(file))
            {
                BundleService.Process(file);
                Telemetry.TrackEvent("VS update bundle");
            }
        }
Ejemplo n.º 30
0
        private void AddBundle(object sender, EventArgs e)
        {
            var item = ProjectHelpers.GetSelectedItems().FirstOrDefault();

            if (item == null || item.ContainingProject == null)
            {
                return;
            }

            string folder              = item.ContainingProject.GetRootFolder();
            string configFile          = Path.Combine(folder, Constants.FILENAME);
            IEnumerable <string> files = ProjectHelpers.GetSelectedItemPaths().Select(f => MakeRelative(configFile, f));
            string inputFile           = item.Properties.Item("FullPath").Value.ToString();
            string outputFile          = GetOutputFileName(inputFile, Path.GetExtension(files.First()));

            if (string.IsNullOrEmpty(outputFile))
            {
                return;
            }

            BundlerMinifierPackage._dte.StatusBar.Progress(true, "Creating bundle", 0, 3);

            string relativeOutputFile = MakeRelative(configFile, outputFile);
            Bundle bundle             = CreateBundleFile(files, relativeOutputFile);

            BundleHandler bundler = new BundleHandler();

            bundler.AddBundle(configFile, bundle);

            BundlerMinifierPackage._dte.StatusBar.Progress(true, "Creating bundle", 1, 3);

            item.ContainingProject.AddFileToProject(configFile, "None");
            BundlerMinifierPackage._dte.StatusBar.Progress(true, "Creating bundle", 2, 3);

            BundlerMinifierPackage._dte.ItemOperations.OpenFile(configFile);
            BundlerMinifierPackage._dte.StatusBar.Progress(true, "Creating bundle", 3, 3);

            BundleService.Process(configFile);
            BundlerMinifierPackage._dte.StatusBar.Progress(false, "Creating bundle");
            BundlerMinifierPackage._dte.StatusBar.Text = "Bundle created";
        }
Ejemplo n.º 31
0
        public void RunAzureTest()
        {
            var connectionInfo = ConfigurationManager.AppSettings[AzureConnectionStringKey];
            var containerName = ConfigurationManager.AppSettings[AzureContainerName];
            var account = CloudStorageAccount.Parse(ConfigurationManager.AppSettings[AzureConnectionStringKey]);
            var container = account.CreateCloudBlobClient().GetContainerReference(containerName);
            if (connectionInfo.StartsWith("UseDevelopmentStorage=true"))
            {
                container.CreateIfNotExists();
            }
            Assert.IsTrue(container.Exists());

            // Clean the container
            var bundleIds = new List<string>();
            bundleIds.AddRange(inputBundleIds);
            bundleIds.AddRange(outputBundleIds);
            DeleteBlobsIfExists(container, bundleIds);

            string azureStorePath = Path.Combine(_context.TestRunDirectory, @"RunAzureTestBlobs");
            Directory.CreateDirectory(azureStorePath);
            AzureBundleStore azureStore = new AzureBundleStore(container, azureStorePath);
            for (int i = 0; i < inputBundleIds.Length; i++)
            {
                string bundleId = inputBundleIds[i];
                Assert.IsFalse(azureStore.HasReference(bundleId));
                string bundlePath = Path.Combine(Test1.TestDataParentPath, inputBundlePaths[i]);
                azureStore.PutReference(bundleId, bundlePath);
                Assert.IsTrue(azureStore.HasReference(bundleId));
                var bundleRef = azureStore.GetReference(bundleId);
                Assert.IsNotNull(bundleRef.Value);
            }

            BundleStore store = azureStore.GetStore();
            Assert.IsNotNull(store);

            string bundleSvcPath = Path.Combine(_context.TestRunDirectory, @"RunAzureTestBundles");
            Directory.CreateDirectory(bundleSvcPath);
            BundleService bundleSvc = new BundleService(store, bundleSvcPath, true);

            var runId = inputBundleIds[2];
            var outputId = outputBundleIds[0];
            Assert.IsFalse(bundleSvc.Has(outputId));

            Run.executeIt(bundleSvc, runId, AzureDiagnostics.get(container));

            Assert.IsTrue(bundleSvc.Has(outputId));
            Assert.IsTrue(azureStore.HasReference(outputId));
            var outputRef = azureStore.GetReference(outputId);
            Assert.IsTrue(outputRef.Value.IsZipBundle);
            var blobOutput = container.GetBlockBlobReference(outputId);
            Assert.IsTrue(blobOutput.Exists());

            var outputBundle = bundleSvc.Get(outputId);
            Assert.IsNotNull(outputBundle);
            var scorepath = Path.Combine(outputBundle.AbsolutePath, @"scores.txt");
            Assert.IsTrue(File.Exists(scorepath));
            string[] lines = File.ReadAllLines(scorepath);
            Assert.AreEqual(1, lines.Length);
            string[] line1Parts = lines[0].Split(':');
            Assert.AreEqual(2, line1Parts.Length);
            Assert.AreEqual("Difference", line1Parts[0].Trim());
            Assert.AreEqual("0.041593", line1Parts[1].Trim());

            var stdoutId = outputBundleIds[1];
            var blobStdout = container.GetBlockBlobReference(stdoutId);
            Assert.IsTrue(blobStdout.Exists());
            var stderrId = outputBundleIds[2];
            var blobStderr = container.GetBlockBlobReference(stderrId);
            Assert.IsFalse(blobStderr.Exists()); // does not exist because nothing was written to std error

            DeleteBlobsIfExists(container, bundleIds);
        }
Ejemplo n.º 32
0
        public void RunLocalTest()
        {
            LocalBundleStore localStore = new LocalBundleStore();
            for (int i = 0; i < inputBundleIds.Length; i++)
            {
                string bundleId = inputBundleIds[i];
                Assert.IsFalse(localStore.HasReference(bundleId));
                string bundlePath = Path.Combine(Test1.TestDataParentPath, inputBundlePaths[i]);
                localStore.PutReference(bundleId, bundlePath);
                Assert.IsTrue(localStore.HasReference(bundleId));
                var bundleRef = localStore.GetReference(bundleId);
                Assert.IsNotNull(bundleRef.Value);
            }

            BundleStore store = localStore.GetStore();
            Assert.IsNotNull(store);

            string bundleSvcPath = Path.Combine(_context.TestRunDirectory, @"RunLocalTestBundles");
            Directory.CreateDirectory(bundleSvcPath);
            BundleService bundleSvc = new BundleService(store, bundleSvcPath, false);

            var runId = inputBundleIds[2];
            var outputId = runId.Substring(0, runId.Length - Path.GetExtension(runId).Length) + @"/output.zip";
            Assert.AreEqual(outputId, outputBundleIds[0]);
            Assert.IsFalse(bundleSvc.Has(outputId));

            Run.executeIt(bundleSvc, runId, LocalDiagnostics.get());

            Assert.IsTrue(bundleSvc.Has(outputId));
            Assert.IsTrue(localStore.HasReference(outputId));
            var outputRef = localStore.GetReference(outputId);
            Assert.IsTrue(outputRef.Value.IsZipBundle);

            var outputBundle = bundleSvc.Get(outputId);
            Assert.IsNotNull(outputBundle);
            var scorepath = Path.Combine(outputBundle.AbsolutePath, @"scores.txt");
            Assert.IsTrue(File.Exists(scorepath));
            string[] lines = File.ReadAllLines(scorepath);
            Assert.AreEqual(1, lines.Length);
            string[] line1Parts = lines[0].Split(':');
            Assert.AreEqual(2, line1Parts.Length);
            Assert.AreEqual("Difference", line1Parts[0].Trim());
            Assert.AreEqual("0.041593", line1Parts[1].Trim());

            var stdoutPath = Path.Combine(bundleSvcPath, @"competition1\submission1\run\stdout.txt");
            Assert.IsTrue(File.Exists(scorepath));
            var stderrPath = Path.Combine(bundleSvcPath, @"competition1\submission1\run\stderr.txt");
            Assert.IsTrue(File.Exists(scorepath));
        }