Beispiel #1
0
        public static AppInstance GetMatchingInstanceByUrl(string requestUrl)
        {
            var instanceList = GetAppInstances(SpManager.GetRealm());

            if (instanceList == null)
            {
                return(null);
            }

            var matchedInstances = instanceList
                                   .Where(instance => !String.IsNullOrWhiteSpace(instance.ServiceURL) &&
                                          requestUrl.IndexOf(instance.ServiceURL, StringComparison.InvariantCultureIgnoreCase) == 0)
                                   .OrderByDescending(instance => instance.ServiceURL.Length);

            if (!matchedInstances.Any())
            {
                return(null);
            }

            var matchedInstance = matchedInstances.First();

            matchedInstance.InitializeCredentials();

            return(matchedInstance);
        }
Beispiel #2
0
        public async Task <ActionResult> GetTemplateInfo(string templateName)
        {
            if (String.IsNullOrWhiteSpace(templateName))
            {
                return(new ObjectResult <string>(null));
            }

            try
            {
                var template = await TemplateManager.GetTemplateRecord(SpManager.GetRealm(), templateName);

                if (template == null)
                {
                    return(new ObjectResult <string>(null));
                }

                var templateInfo = new
                {
                    instanceId = template.CurrentInstanceId
                };

                return(new ObjectResult <object>(templateInfo));
            }
            catch (Exception ex)
            {
                return(new ObjectResult <ErrorModel>(ErrorModel.FromException(ex)));
            }
        }
Beispiel #3
0
 private static string GetUserKey()
 {
     return(SpManager.GetRealm());
 }
Beispiel #4
0
        public async Task <ActionResult> TemplateDefinition(string libraryUrl = null, string xsnUrl = null, string templateName = null, bool includeTemplateXml = false, string instanceId = null)
        {
            try
            {
                using (var clientContext = GetSharePointContext())
                {
                    var userKey = SpManager.GetRealm();

                    if (xsnUrl != null)
                    {
                        var redirectTemplateName = await SQLTemplateStorageManager.FindRedirectTemplateName(userKey, xsnUrl);

                        if (redirectTemplateName != null)
                        {
                            templateName = redirectTemplateName;
                            xsnUrl       = null;
                        }
                    }

                    var manifest = await TemplateManager.ManifestWithProperties(clientContext, libraryUrl, xsnUrl, templateName, StorageContext, instanceId);

                    if (manifest == null)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
                    }

                    var template = new TemplateDefinition
                    {
                        TemplateName = templateName,
                        XsnUrl       = xsnUrl,
                        LibraryUrl   = libraryUrl
                    };

                    template.Files.Add(manifest.FormFile);

                    if (!String.IsNullOrWhiteSpace(templateName))
                    {
                        template.InitializeInstanceId(manifest);
                    }

                    var tasks = GetContentList(manifest, includeTemplateXml)
                                .Select(item => GetTemplateFileOrFail(clientContext, libraryUrl, xsnUrl, templateName, template.InstanceId, item, StorageContext))
                                .ToList();

                    while (tasks.Count > 0)
                    {
                        var task = await Task.WhenAny(tasks);

                        tasks.Remove(task);

                        template.Files.Add(await task);
                    }

                    await CheckAndUpdateOpenCountAsync(templateName, userKey);

                    CheckAndAddExpiryHeader(instanceId);

                    return(new ObjectResult <TemplateDefinition>(template));
                }
            }
            catch (Exception e)
            {
                return(new ObjectResult <ErrorModel>(ErrorModel.FromException(e)));
            }
        }