Ejemplo n.º 1
0
        private static void AddFileToQueue(FileObject fileObject)
        {
            var file = new UploadQueue
            {
                FileID           = fileObject.FileId,
                OriginalFileName = fileObject.FileName,
                FileLocation     = fileObject.Uri,
                ContentType      = "application/zip", //TODO: I should try and actually figure out what the ContentType is.
                ContentSize      = fileObject.FileSize,
                UserKey          = "61e8b5db-d076-44c3-914d-05e37cef4abd",
                UserIP           = "0.0.0.0",
                UploadedDate     = DateTime.Now,
                Processing       = false
            };

            UploadQueueController.AddItemToQueue(file);
        }
Ejemplo n.º 2
0
        public override void Run()
        {
            // This is a sample worker implementation. Replace with your logic.
            //Trace.WriteLine("EVSWorker entry point called", "Information");

            while (true)
            {
                Thread.Sleep(5 * 1000);
                //Trace.WriteLine("Working", "Information");

                var itemToProcess = UploadQueueController.GetAndLockItemForProcessing();

                if (itemToProcess != null)
                {
                    Process(itemToProcess);
                }
                else
                {
                    CleanTemp();
                }
            }
        }
Ejemplo n.º 3
0
        private static void Process(UploadQueue itemToProcess)
        {
            var p     = new Package();
            var error = false;

            try
            {
                //Trace.WriteLine("Found an item to process", "Information");
                Messages.LogMessage(itemToProcess, MessageList.Start);

                //move the file to local server storage
                var tempFile = FileHelpers.MoveBlobToTempStorage(itemToProcess.FileLocation);

                Messages.LogMessage(itemToProcess, MessageList.LocalStorage);

                //build a new 'package' object
                p.Path = tempFile;
                if (p.Messages == null)
                {
                    p.Messages = new List <VerificationMessage>();
                }

                //unzip the package
                var fz = new FastZip();

                var shortpath = Environment.GetEnvironmentVariable("ShortRootPath") ?? Path.GetTempPath();

                var tempPath = Path.Combine(shortpath, Guid.NewGuid().ToString());

                //Trace.WriteLine("Package location: " + tempPath);

                Directory.CreateDirectory(tempPath);
                p.ExtractedPath = tempPath;

                try
                {
                    using (var stm = new FileStream(p.Path, FileMode.Open))
                    {
                        fz.ExtractZip(stm, tempPath, FastZip.Overwrite.Always, null, null, null, true, true);
                    }
                }
                catch (Exception exc)
                {
                    error = true;
                    Trace.TraceError("Error while extracting file.");
                    Trace.TraceError(exc.Message);

                    if (exc.InnerException != null)
                    {
                        Trace.TraceError(exc.InnerException.Message);
                    }

                    p.Messages.Add(new VerificationMessage
                    {
                        Message     = "Problem encountered while attempting to extract uploaded file.",
                        MessageId   = new Guid("9ac011fa-08dd-4e26-91ba-0af7d5daf482"),
                        MessageType = MessageTypes.SystemError,
                        Rule        = "Extraction"
                    });

                    goto Cleanup;
                }

                Messages.LogMessage(itemToProcess, MessageList.UnZipped);

                Messages.LogMessage(itemToProcess, MessageList.Processing);

                p.Messages.AddRange(new PackageExists().ApplyRule(p));
                p.Messages.AddRange(new MinPackageSize().ApplyRule(p));
                p.Messages.AddRange(new ManifestFileExists().ApplyRule(p));
                p.Messages.AddRange(new ManifestIsXML().ApplyRule(p));

                foreach (var manifest in p.DNNManifests)
                {
                    p.Messages.AddRange(new CorrectTypeAndVersion().ApplyRule(p, manifest));

                    switch (manifest.ManifestType)
                    {
                    case ManifestTypes.Package:
                        p.Messages.AddRange(new PackageNodeAndChildren().ApplyRule(p, manifest));
                        p.Messages.AddRange(new PackageOwner().ApplyRule(p, manifest));
                        p.Messages.AddRange(new AssemblyNode().ApplyRule(p, manifest));
                        p.Messages.AddRange(new AuthenticationSystemNode().ApplyRule(p, manifest));
                        p.Messages.AddRange(new DashboardControlNode().ApplyRule(p, manifest));
                        p.Messages.AddRange(new CleanupNode().ApplyRule(p, manifest));
                        p.Messages.AddRange(new ConfigNode().ApplyRule(p, manifest));
                        p.Messages.AddRange(new FileNode().ApplyRule(p, manifest));
                        p.Messages.AddRange(new ModuleNode().ApplyRule(p, manifest));
                        p.Messages.AddRange(new SkinNode().ApplyRule(p, manifest));
                        p.Messages.AddRange(new SkinObjectNode().ApplyRule(p, manifest));
                        p.Messages.AddRange(new ContainerNode().ApplyRule(p, manifest));
                        p.Messages.AddRange(new CoreLanguageNode().ApplyRule(p, manifest));
                        p.Messages.AddRange(new ExtensionLanguageNode().ApplyRule(p, manifest));
                        p.Messages.AddRange(new ResourceFileNode().ApplyRule(p, manifest));
                        p.Messages.AddRange(new ScriptNode().ApplyRule(p, manifest));
                        p.Messages.AddRange(new WidgetNode().ApplyRule(p, manifest));
                        break;

                    case ManifestTypes.Module:
                        p.Messages.AddRange(new FolderNodeAndChildren().ApplyRule(p, manifest));
                        p.Messages.AddRange(new FileNode().ApplyRule(p, manifest));
                        p.Messages.AddRange(new ModuleNode().ApplyRule(p, manifest));
                        p.Messages.AddRange(new ProcessScripts().ApplyRule(p, manifest));
                        break;
                    }

                    Messages.LogMessage(itemToProcess, MessageList.TwoWayFileChecker);
                    //Trace.WriteLine("Running two-way file checker.", "Information");
                    p.Messages.AddRange(new TwoWayFileChecker().ApplyRule(p, manifest));

                    Messages.LogMessage(itemToProcess, MessageList.AssemblyChecker);
                    //Trace.WriteLine("Running assembly checker.", "Information");
                    const string assemblyInfoFile = @"collection.xml";
                    p.MinDotNetVersion     = ProcessAssembly.GetMinDotNetFramework(p.Assemblies).VersionName;
                    p.MinDotNetNukeVersion = ProcessAssembly.GetMinDotNetNukeVersion(p.Assemblies, assemblyInfoFile).Name;

                    Messages.LogMessage(itemToProcess, MessageList.SQLChecker);
                    //Trace.WriteLine("Running SQL scanner.", "Information");
                    p.Messages.AddRange(new SQLTestRunner().ApplyRule(p, manifest));
                }

                p.Messages.AddRange(new FileEncodingChecker().ApplyRule(p));
                p.Messages.AddRange(new DependencyChecker().ApplyRule(p));

                Messages.LogMessage(itemToProcess, MessageList.BuildingOutput);

                //Let's process the SQL output if there is any.
                if (p.SQLOutputPath != null)
                {
                    var tempPathForZip = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
                    Directory.CreateDirectory(tempPathForZip);
                    var filename       = itemToProcess.FileID + ".zip";
                    var destination    = tempPathForZip + "\\" + filename;
                    var zipInputStream = File.Create(destination);

                    using (zipInputStream)
                    {
                        fz.CreateZip(zipInputStream, p.SQLOutputPath, true, "", "");
                    }

                    var zipStream = File.Open(destination, FileMode.Open);

                    using (zipStream)
                    {
                        var storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue(Constants.ConfigurationSectionKey));
                        var blobClient     = storageAccount.CreateCloudBlobClient();
                        var container      = blobClient.GetContainerReference(Constants.ContainerNameScripts);
                        container.CreateIfNotExists();
                        var file = container.GetBlockBlobReference(filename);
                        file.UploadFromStream(zipStream);
                    }

                    try
                    {
                        File.Delete(destination);
                    }
                    catch (Exception exc)
                    {
                        error = true;
                        Trace.TraceError("Error while deleting temp SQL output files.");
                        Trace.TraceError(exc.Message);

                        if (exc.InnerException != null)
                        {
                            Trace.TraceError(exc.InnerException.Message);
                        }
                    }
                }

                //clean up
Cleanup:
                try
                {
                    File.Delete(tempFile);            //remove the temp file from the server.
                    DeleteDirectory(p.ExtractedPath); //remove the extracted folder from the server.

                    if (p.SQLOutputPath != null)
                    {
                        DeleteDirectory(p.SQLOutputPath);
                    }
                }
                catch (Exception exc)
                {
                    error = true;
                    Trace.TraceError("Error while deleting temp files.");
                    Trace.TraceError(exc.Message);

                    if (exc.InnerException != null)
                    {
                        Trace.TraceError(exc.InnerException.Message);
                    }
                }
            }
            catch (Exception exc)
            {
                error = true;
                Trace.TraceError("Error while processing extension.");
                Trace.TraceError(exc.Message);
                Trace.TraceError(exc.StackTrace);

                if (exc.InnerException != null)
                {
                    Trace.TraceError(exc.InnerException.Message);
                }
            }
            finally
            {
                UploadQueueController.RemoveItemFromQueue(itemToProcess); //remove the item from the queue.

                if (itemToProcess.UserKey != "44eb5af6-2205-488e-9985-f7204c268820")
                {
                    FileHelpers.RemoveBlob(itemToProcess.FileLocation); //this will remove the file from blob storage.
                }

                var extension = new Extension(itemToProcess);

                ExtensionController.AddExtension(extension);

                ProcessResults(p, extension.ExtensionID, error);

                //report to the status service that this file has finished processing.
                Messages.LogMessage(itemToProcess, MessageList.Finish);
            }
        }