Esempio n. 1
0
        internal static IProjectStore CreateProjectStore(DocumentReference documentReference, IServiceProvider serviceProvider, IEnumerable <ProjectCreator> creatorChainOfResponsibility)
        {
            string message;
            string invalidStoreBadPath = null;

            if (!documentReference.IsValidPathFormat)
            {
                invalidStoreBadPath = StringTable.InvalidStoreBadPath;
            }
            else if (!PathHelper.FileOrDirectoryExists(documentReference.Path))
            {
                invalidStoreBadPath = StringTable.InvalidStoreMissingPath;
            }
            if (!string.IsNullOrEmpty(invalidStoreBadPath))
            {
                return(InvalidProjectStore.CreateInstance(documentReference, invalidStoreBadPath, serviceProvider));
            }
            Exception     exception1   = null;
            IProjectStore projectStore = ProjectStoreHelper.CreateProjectStore(documentReference, serviceProvider, creatorChainOfResponsibility, (Action action, Action <Exception> exceptionAction) => {
                bool flag;
                try
                {
                    action();
                    flag = true;
                }
                catch (Exception exception)
                {
                    exceptionAction(exception);
                    flag = false;
                }
                return(flag);
            }, (Exception e) => exception1 = e);

            if (projectStore != null)
            {
                return(projectStore);
            }
            DocumentReference documentReference1 = documentReference;

            if (exception1 == null)
            {
                message = null;
            }
            else
            {
                message = exception1.Message;
            }
            return(InvalidProjectStore.CreateInstance(documentReference1, message, serviceProvider));
        }
Esempio n. 2
0
        protected INamedProject InitializeProject(IProjectStore projectStore)
        {
            INamedProject namedProject;
            INamedProject unlicensedProject = null;

            try
            {
                IProjectType projectTypeForProject = this.Services.ProjectTypeManager().GetProjectTypeForProject(projectStore);
                if (projectTypeForProject != null)
                {
                    IProjectCreateError projectCreateError = projectTypeForProject.CanCreateProject(projectStore);
                    if (projectCreateError != null)
                    {
                        projectTypeForProject = this.Services.ProjectTypeManager().UnknownProjectType;
                    }
                    if (projectTypeForProject is UnknownProjectType && SolutionBase.IsReloadPromptEnabled())
                    {
                        InvalidProjectStore invalidProjectStore = projectStore as InvalidProjectStore;
                        if (invalidProjectStore == null || string.IsNullOrEmpty(invalidProjectStore.InvalidStateDescription))
                        {
                            this.PromptWithUnsupportedProjectDetails(projectStore, projectCreateError);
                        }
                        else
                        {
                            IMessageDisplayService messageDisplayService = this.Services.MessageDisplayService();
                            ErrorArgs   errorArg         = new ErrorArgs();
                            CultureInfo currentUICulture = CultureInfo.CurrentUICulture;
                            string      unsupportedProjectWithDescription = StringTable.UnsupportedProjectWithDescription;
                            object[]    displayName = new object[] { projectStore.DocumentReference.DisplayName, invalidProjectStore.InvalidStateDescription };
                            errorArg.Message      = string.Format(currentUICulture, unsupportedProjectWithDescription, displayName);
                            errorArg.AutomationId = "OpenProjectErrorDialog";
                            messageDisplayService.ShowError(errorArg);
                        }
                    }
                    LicenseState licenseState = LicensingHelper.IsProjectLicensed(projectStore, this.serviceProvider);
                    if (!licenseState.IsExpired)
                    {
                        if (!licenseState.FullyLicensed)
                        {
                            LicensingHelper.UnlicensedProjectLoadAttempted();
                        }
                        unlicensedProject = projectTypeForProject.CreateProject(projectStore, this.GetCodeDocumentTypeFromProject(projectStore), this.serviceProvider);
                    }
                    else
                    {
                        LicensingHelper.UnlicensedProjectLoadAttempted();
                        unlicensedProject = new UnlicensedProject(projectStore, this.serviceProvider);
                    }
                    return(unlicensedProject);
                }
                else
                {
                    namedProject = null;
                }
            }
            catch (Exception exception)
            {
                if (unlicensedProject != null)
                {
                    projectStore.Dispose();
                    unlicensedProject.Dispose();
                    unlicensedProject = null;
                }
                throw;
            }
            return(namedProject);
        }