/// <summary>
        /// <para>Will create a file lock like this: {rootPath}/{site extension id}/install.lock</para>
        /// <para>e.g 'D:\home\site\siteextension\filecounter\install.lock'</para>
        /// </summary>
        public static SiteExtensionInstallationLock CreateLock(string rootPath, string id)
        {
            string lockFilePath     = Path.Combine(rootPath, id, LockNameSuffix);
            var    installationLock = new SiteExtensionInstallationLock(lockFilePath);

            installationLock.InitializeAsyncLocks();
            return(installationLock);
        }
Esempio n. 2
0
        private async Task <SiteExtensionInfo> InstallExtensionCore(string id, SiteExtensionInfo requestInfo, ITracer tracer)
        {
            var version          = requestInfo.Version;
            var feedUrl          = requestInfo.FeedUrl;
            var type             = requestInfo.Type;
            var installationArgs = requestInfo.InstallationArgs;
            var packageUri       = requestInfo.PackageUri;

            try
            {
                using (tracer.Step("Installing '{0}' version '{1}' from '{2}'", id, version, StringUtils.ObfuscatePath(!string.IsNullOrEmpty(packageUri) ? packageUri : feedUrl)))
                {
                    var installationLock = SiteExtensionInstallationLock.CreateLock(_environment.SiteExtensionSettingsPath, id, enableAsync: true);
                    // hold on to lock till action complete (success or fail)
                    return(await installationLock.LockOperationAsync <SiteExtensionInfo>(async() =>
                    {
                        return await TryInstallExtension(id, requestInfo, tracer);
                    }, "Installing SiteExtension", TimeSpan.Zero));
                }
            }
            catch (Exception ex)
            {
                _analytics.UnexpectedException(
                    ex,
                    method: "PUT",
                    path: string.Format(CultureInfo.InvariantCulture, "/api/siteextensions/{0}", id),
                    result: Constants.SiteExtensionProvisioningStateFailed,
                    message: string.Format(CultureInfo.InvariantCulture, "{{\"version\": {0}, \"feed_url\": {1}}}", version, feedUrl),
                    trace: false);

                // handle unexpected exception
                tracer.TraceError(ex);

                var info = new SiteExtensionInfo();
                info.Id = id;

                SiteExtensionStatus armStatus = new SiteExtensionStatus(_environment.SiteExtensionSettingsPath, id, tracer);
                armStatus.Operation         = Constants.SiteExtensionOperationInstall;
                armStatus.ProvisioningState = Constants.SiteExtensionProvisioningStateFailed;
                armStatus.Status            = HttpStatusCode.BadRequest;
                armStatus.FillSiteExtensionInfo(info);
                tracer.Trace("Update arm settings for {0} installation. Status: {1}", id, armStatus.Status);
                return(info);
            }
        }
Esempio n. 3
0
        // <inheritdoc />
        public async Task <SiteExtensionInfo> InstallExtension(string id, string version, string feedUrl, SiteExtensionInfo.SiteExtensionType type, ITracer tracer)
        {
            try
            {
                var installationLock = SiteExtensionInstallationLock.CreateLock(_environment.SiteExtensionSettingsPath, id, enableAsync: true);
                // hold on to lock till action complete (success or fail)
                return(await installationLock.LockOperationAsync <SiteExtensionInfo>(async() =>
                {
                    return await TryInstallExtension(id, version, feedUrl, type, tracer);
                }, TimeSpan.Zero));
            }
            catch (Exception ex)
            {
                _analytics.UnexpectedException(
                    ex,
                    method: "PUT",
                    path: string.Format(CultureInfo.InvariantCulture, "/api/siteextensions/{0}", id),
                    result: Constants.SiteExtensionProvisioningStateFailed,
                    message: string.Format(CultureInfo.InvariantCulture, "{{\"version\": {0}, \"feed_url\": {1}}}", version, feedUrl),
                    trace: false);

                // handle unexpected exception
                tracer.TraceError(ex);

                var info = new SiteExtensionInfo();
                info.Id = id;

                SiteExtensionStatus armStatus = new SiteExtensionStatus(_environment.SiteExtensionSettingsPath, id, tracer);
                armStatus.Operation         = Constants.SiteExtensionOperationInstall;
                armStatus.ProvisioningState = Constants.SiteExtensionProvisioningStateFailed;
                armStatus.Status            = HttpStatusCode.BadRequest;
                armStatus.FillSiteExtensionInfo(info);
                tracer.Trace("Update arm settings for {0} installation. Status: {1}", id, armStatus.Status);
                return(info);
            }
        }