private string InstallPluginForFlow(byte[] zipFileContent, string flowId, string modifiedById,
                                            bool validateAgainstDbVersion, out string pluginFolderPath)
        {
            string parentFolderPath = GetPluginRootFolderForFlow(flowId);
            string tempDirPath      =
                Path.Combine(parentFolderPath, INSTALLING_DIRECTORY_PREFIX + Guid.NewGuid().ToString());

            try
            {
                // Extract files to installing directory
                _compressionHelper.UncompressDirectory(zipFileContent, tempDirPath);

                // Locate a valid base plugin and version #
                ICollection <SimpleDataService> implementers =
                    GetDataServiceImplementersInDirectory(tempDirPath, false);

                SimpleDataService primaryImplementer = GetPrimaryImplementer(implementers);
                if (primaryImplementer == null)
                {
                    throw new FileNotFoundException("A valid plugin implementer was not found in the zip file");
                }

                string installFolderPath = Path.Combine(parentFolderPath, primaryImplementer.Version.ToString());

                // Check that the incoming version is greater than any existing installed version
                VersionInfo curVersion;
                string      rtnPath = GetPluginSubFolderWithHighestVersion(flowId, out curVersion);

                if (validateAgainstDbVersion && (_pluginDao != null))
                {
                    PluginItem pluginItem = _pluginDao.GetHighestVersionPlugin(flowId);
                    if (pluginItem != null)
                    {
                        if (curVersion != null)
                        {
                            if (pluginItem.BinaryVersion > curVersion)
                            {
                                curVersion = pluginItem.BinaryVersion;
                            }
                        }
                        else
                        {
                            curVersion = pluginItem.BinaryVersion;
                        }
                    }
                }

                if (curVersion != null)
                {
                    if (primaryImplementer.Version < curVersion)
                    {
                        throw new InvalidOperationException(string.Format("A plugin with a newer version \"{0}\" is already installed for the flow \"{1}\"",
                                                                          curVersion.ToString(), _flowDao.GetDataFlowNameById(flowId)));
                    }
                }

                if ((_pluginDao != null) && !string.IsNullOrEmpty(modifiedById))
                {
                    PluginItem pluginItem = new PluginItem();
                    pluginItem.FlowId        = flowId;
                    pluginItem.BinaryVersion = primaryImplementer.Version;
                    pluginItem.ModifiedById  = modifiedById;
                    ITransactionOperations transactionTemplate = _pluginDao.GetTransactionTemplate();
                    transactionTemplate.Execute(delegate
                    {
                        _pluginDao.SavePlugin(pluginItem, zipFileContent);
                        // Rename the plugin directory with the version name
                        MoveInstalledPluginDirectory(tempDirPath, installFolderPath);
                        return(null);
                    });
                }
                else
                {
                    // Rename the plugin directory with the version name
                    MoveInstalledPluginDirectory(tempDirPath, installFolderPath);
                }

                pluginFolderPath = installFolderPath;
                return(string.Format("Successfully installed the plugin: \"{0}\"", primaryImplementer.ToString()));
            }
            catch (Exception)
            {
                FileUtils.SafeDeleteDirectory(tempDirPath);
                throw;
            }
        }