public void TestGetTemplate()
        {
            var service = new TemplatesService(new TemplatesStubDao());
            var actual  = service.GetTemplate(new Guid("11111111-1111-1111-1111-111111111112"));

            Assert.NotNull(actual);
        }
Esempio n. 2
0
        public void InitView(long idTemplate, long idVersion)
        {
            dtoSelectorContext context = GetContext();

            View.ContainerContext  = context;
            View.ContentIdTemplate = idTemplate;
            View.ContentIdVersion  = idVersion;
            if (UserContext.isAnonymous)
            {
                View.DisplaySessionTimeout();
            }
            else
            {
                if (HasPermission(context))
                {
                    InitializeView(idTemplate, idVersion, context);
                }
                else if (context.ObjectOwner != null)
                {
                    View.DisplayNoPermission(context.IdCommunity, context.IdModule, context.ModuleCode);
                }
                else
                {
                    View.DisplayNoPermission(context.IdCommunity, TemplatesService.ServiceModuleID(), context.ModuleCode);
                }
            }
        }
        public void TestGetTemplate_OnlySingleChoiceM2O_Template()
        {
            var service  = new TemplatesService(new TemplatesStubDao());
            var template = service.GetTemplate(new Guid("11111111-1111-1111-1111-111111111113"));

            Assert.Single(template.Body);
        }
        public IEnumerable <string> Get()
        {
            var ts = new TemplatesService();
            var k  = ts.Save();

            return(new string[] { "value1", "value2" });
        }
Esempio n. 5
0
        public void TestCopyOverwrite()
        {
            TemplatesService ts = new TemplatesService(storage);

            ts.Start();
            ITeamTemplatesProvider teamtemplateprovider = ts.TeamTemplateProvider;
            LMTeam teamB = LMTeam.DefaultTemplate(5);

            teamB.Name          = "B";
            teamB.TeamName      = "Template B";
            teamB.FormationStr  = "1-4";
            teamB.List [0].Name = "Paco";
            teamtemplateprovider.Save(teamB);
            LMTeam teamA = new LMTeam();

            teamA.Name         = "A";
            teamA.TeamName     = "Template A";
            teamA.FormationStr = "1-4-3-3";
            teamtemplateprovider.Save(teamA);

            LMTeam auxdelete = teamA;

            teamtemplateprovider.Copy(teamB, "A");
            teamtemplateprovider.Delete(auxdelete);
            teamA = teamtemplateprovider.Templates [0] as LMTeam;

            Assert.AreEqual(4, teamtemplateprovider.Templates.Count);
            Assert.AreEqual("A", teamA.Name);
            Assert.AreEqual("Template B", teamA.TeamName);
            Assert.AreEqual(teamB.List.Count, teamA.List.Count);
            Assert.AreEqual("1-4", teamA.FormationStr);
            Assert.AreEqual("Paco", teamA.List [0].Name);
        }
        public void TestGetTemplate_M2O_HasHeader()
        {
            var service  = new TemplatesService(new TemplatesStubDao());
            var template = service.GetTemplate(new Guid("11111111-1111-1111-1111-111111111113"));

            Assert.NotEmpty(template.Headers);
        }
Esempio n. 7
0
 public ActionResult GetTemplatets()
 {
     return(Json(new
     {
         templates = TemplatesService.GetAll()
     }, JsonRequestBehavior.AllowGet));
 }
Esempio n. 8
0
        public void TestSystemTemplates()
        {
            FileStorage fs = new FileStorage(
                Path.Combine(Path.GetTempPath(), "TestTemplatesService"));
            TemplatesService ts = new TemplatesService(fs);

            // Start service
            ts.Start();
            ICategoriesTemplatesProvider ctp = ts.CategoriesTemplateProvider;

            // We must have at least one template provider called 'Default'
            Dashboard dash = ctp.Load("Default dashboard");

            Assert.AreNotSame(dash, null);

            // Test we dont have a template
            bool found = ctp.Exists("NonExistingTemplate");

            Assert.AreEqual(found, false);

            // Test saving the default template
            dash.Name = "NewDefault";
            ctp.Save(dash);

            // Test loading a template from a file
            Dashboard newDefault = ctp.Load("NewDefault");

            Assert.AreEqual(newDefault.Name, "NewDefault");
        }
Esempio n. 9
0
        public void TestSystemTemplates()
        {
            FileStorage fs = new FileStorage (
                                 Path.Combine (Path.GetTempPath (), "TestTemplatesService"));
            TemplatesService ts = new TemplatesService (fs);
            // Start service
            ts.Start ();
            ICategoriesTemplatesProvider ctp = ts.CategoriesTemplateProvider;

            // We must have at least one template provider called 'Default'
            Dashboard dash = ctp.Load ("Default dashboard");
            Assert.AreNotSame (dash, null);

            // Test we dont have a template
            bool found = ctp.Exists ("NonExistingTemplate");
            Assert.AreEqual (found, false);

            // Test saving the default template
            dash.Name = "NewDefault";
            ctp.Save (dash);

            // Test loading a template from a file
            Dashboard newDefault = ctp.Load ("NewDefault");
            Assert.AreEqual (newDefault.Name, "NewDefault");
        }
Esempio n. 10
0
        public void TestGetTemplate_M2O_HasHeaderTextField()
        {
            var       service  = new TemplatesService(new TemplatesStubDao());
            var       template = service.GetTemplate(new Guid("11111111-1111-1111-1111-111111111113"));
            DataField text     = template.Headers[0];

            Assert.Equal(text.Id, new Guid("36004a67-4c36-4457-a30f-617ca9e0c838"));
        }
Esempio n. 11
0
        public void TestGetTemplate_SingleChoiceWeightedIdM2O_Template()
        {
            var           service  = new TemplatesService(new TemplatesStubDao());
            var           template = service.GetTemplate(new Guid("11111111-1111-1111-1111-111111111113"));
            QuestionField question = template.Body[0];

            Assert.Equal(question.Id, new Guid("5f4df704-8201-4e4f-94c2-4409da82bdb9"));
        }
Esempio n. 12
0
        public void TestUpdateTemplate_Throws_ItemNotFoundException()
        {
            var service  = new TemplatesService(new TemplatesErrorStubDao());
            var expected = new Template {
                Id = Guid.NewGuid(), Name = "Updated name"
            };

            Assert.Throws <ItemNotFoundServiceException>(() => { service.UpdateTemplate(expected); });
        }
Esempio n. 13
0
 public TemplatesController(IOptions <JwtIssuerOptions> jwtOptions, IOptions <AppSettings> appSettings)
 {
     _appSettings        = appSettings;
     _jwtOptions         = jwtOptions.Value;
     _serializerSettings = new JsonSerializerSettings
     {
         Formatting = Formatting.Indented
     };
     _templatesService = new TemplatesService(appSettings.Value);
 }
Esempio n. 14
0
        public void TestPostTemplates()
        {
            var expected = new Template()
            {
                Name = "New EvaluationTemplate"
            };

            var service = new TemplatesService(new TemplatesStubDao());
            var actual  = service.CreateTemplate(expected);

            Assert.True(expected.Name == actual.Name);
        }
        private GCTemplate GetTemplate(int templateId, Dictionary <int, GCTemplate> templatesDictionary)
        {
            GCTemplate gcTemplate;

            templatesDictionary.TryGetValue(templateId, out gcTemplate);
            if (gcTemplate == null)
            {
                gcTemplate = TemplatesService.GetSingleTemplate(templateId.ToString()).Data;
                templatesDictionary.Add(templateId, gcTemplate);
            }

            return(gcTemplate);
        }
Esempio n. 16
0
        public void TestUpdateTemplate_Succesful_Update()
        {
            var service       = new TemplatesService(new TemplatesStubDao());
            var stubTemplates = service.GetTemplates();
            var actual        = stubTemplates[0];
            var expected      = new Template {
                Id = actual.Id, Name = "Updated name"
            };

            service.UpdateTemplate(expected);

            Assert.Equal(expected.Name, actual.Name);
        }
Esempio n. 17
0
        public void TestRemoveNonExistingTemplate_Throws_ItemNotFoundException_Message()
        {
            var expected = "Unable to find a template with id f480b496-2356-402b-9fdc-a1893cc64e16";

            try
            {
                var service = new TemplatesService(new TemplatesStubDao());
                service.DeleteTemplate(Guid.Parse("f480b496-2356-402b-9fdc-a1893cc64e16"));
            }
            catch (Exception e)
            {
                Assert.Equal(expected, e.Message);
            }
        }
Esempio n. 18
0
        public void TestUpdateTemplate_ItemNotFoundException_Message()
        {
            var service  = new TemplatesService(new TemplatesErrorStubDao());
            var expected = new Template {
                Id = Guid.NewGuid(), Name = "Updated name"
            };
            var origMessage = $"Couldn't find template with id {expected.Id}";

            try
            {
                service.UpdateTemplate(expected);
            }
            catch (Exception e)
            {
                Assert.Equal(e.Message, origMessage);
            }
        }
Esempio n. 19
0
        public void Go()
        {
            var model = new
            {
                Id    = 10,
                Name  = "Name1",
                Items = new List <string> {
                    "Item1", "Item2", "Item3", "Item4", "Item5"
                }
            };

            var templateService = new TemplatesService(new FileSystemService(), new RazorTemplateEngine());

            var result = templateService.Parse("first", model);

            Console.Write(result);
        }
Esempio n. 20
0
 /// <summary>
 /// Initializes all the services offered by the current version of
 /// this API.
 /// </summary>
 /// <see cref="IdentityService"/>
 /// <see cref="HttpService"/>
 /// <see cref="OAuth2Service"/>
 private void InitializeServices()
 {
     Http              = new HttpService(RestClientWrapper.RestClient, new RequestBuilder());
     Accounts          = new AccountsService(this);
     Certificates      = new CertificatesService(this);
     Contacts          = new ContactsService(this);
     Domains           = new DomainsService(this);
     Identity          = new IdentityService(this);
     OAuth             = new OAuth2Service(Http);
     Registrar         = new RegistrarService(this);
     Services          = new ServicesService(this);
     Tlds              = new TldsService(this);
     Templates         = new TemplatesService(this);
     VanityNameServers = new VanityNameServersService(this);
     Webhooks          = new WebhooksService(this);
     Zones             = new ZonesService(this);
 }
Esempio n. 21
0
        public void TemplatesProvider_CopyStaticTemplate_CopyIsNotStatic()
        {
            // Arrange
            TemplatesService ts = new TemplatesService(storage);

            ts.Start();
            ICategoriesTemplatesProvider ctp = ts.CategoriesTemplateProvider;
            Dashboard dash = ctp.Templates [0];

            // Action
            ctp.Copy(dash, "NEW");

            // Assert
            Assert.IsTrue(dash.Static);
            Dashboard dash2 = ctp.Templates.Where(t => t.Name == "NEW").First();

            Assert.IsFalse(dash2.Static);
        }
Esempio n. 22
0
        public MockDnsimpleClient(string fixture)
        {
            Fixture   = fixture;
            UserAgent = "Testing user agent";

            Accounts          = new AccountsService(this);
            Certificates      = new CertificatesService(this);
            Contacts          = new ContactsService(this);
            Domains           = new DomainsService(this);
            Http              = new MockHttpService("v2", Fixture, BaseUrl);
            Identity          = new IdentityService(this);
            OAuth             = new OAuth2Service(Http);
            Registrar         = new RegistrarService(this);
            Services          = new ServicesService(this);
            Tlds              = new TldsService(this);
            Templates         = new TemplatesService(this);
            VanityNameServers = new VanityNameServersService(this);
            Webhooks          = new WebhooksService(this);
            Zones             = new ZonesService(this);
        }
Esempio n. 23
0
        public void TestSystemTemplates()
        {
            TemplatesService ts = new TemplatesService(storage);

            // Start service
            ts.Start();
            ICategoriesTemplatesProvider ctp = ts.CategoriesTemplateProvider;
            // We must have at least one template provider called 'Default'
            Dashboard dash = ctp.Templates [0];

            Assert.IsNotNull(dash);
            // Test we dont have a template
            Assert.IsFalse(ctp.Exists("NonExistingTemplate"));

            ITeamTemplatesProvider ttp = ts.TeamTemplateProvider;

            Assert.AreEqual(2, ttp.Templates.Count);
            // Test we dont have a template
            Assert.IsFalse(ctp.Exists("NonExistingTemplate"));
        }
        public IHttpActionResult RecordQuery(string key)
        {
            TemplatesService service = new TemplatesService();

            try
            {
                var query         = service.GetEntity(key);
                var packageEntity = query.PackageResult();
                return(Json(packageEntity));
            }
            catch (Exception)
            {
                PackageResultEntity <object> packageResultEntity = new PackageResultEntity <object>()
                {
                    list = null,
                    msg  = "failed"
                };
                return(Json(packageResultEntity));
            }
        }
        public IHttpActionResult RecordPagination(Pagination pagination)
        {
            TemplatesService service = new TemplatesService();

            try
            {
                var query         = service.RecordPagination(pagination);
                var packageEntity = query.PackageEntityPaginations(pagination);
                return(Json(packageEntity));
            }
            catch (Exception)
            {
                PackageResultEntity <object> packageResultEntity = new PackageResultEntity <object>()
                {
                    list = null,
                    msg  = "failed"
                };
                return(Json(packageResultEntity));
            }
        }
Esempio n. 26
0
        public static void StartServices(IGUIToolkit guiToolkit, IMultimediaToolkit multimediaToolkit)
        {
            ProjectsManager projectsManager;

            /* Start TemplatesService */
            ts = new TemplatesService(Config.configDirectory);
            Core.mainWindow.TemplatesService = ts;

            /* Start DB services */
            db = new DataBase(Path.Combine(Config.DBDir(),Constants.DB_FILE));

            /* Start the events manager */
            eManager = new EventsManager(guiToolkit);

            /* Start the hotkeys manager */
            hkManager = new HotKeysManager(guiToolkit.MainWindow);
            hkManager.newMarkEvent += eManager.OnNewTag;

            /* Start the rendering jobs manager */
            videoRenderer = new RenderingJobsManager(multimediaToolkit, guiToolkit);

            /* Start Game Units manager */
            guManager = new GameUnitsManager(mainWindow, mainWindow.Player);

            /* Start playlists manager */
            plManager = new PlaylistManager(guiToolkit, videoRenderer);

            projectsManager = new ProjectsManager(guiToolkit, multimediaToolkit);
            projectsManager.OpenedProjectChanged += OnOpenedProjectChanged;
        }
        private List <GCTemplate> GetTemplates(string projectId)
        {
            TemplatesEntity templates = TemplatesService.GetTemplates(projectId);

            return(templates.Data);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="itemId"></param>
        /// <param name="models"></param>
        /// <param name="language"></param>
        /// <returns></returns>
        public List <ItemResultModel> UpdateItems(string itemId, List <UpdateListIds> models, string language)
        {
            var model = new List <ItemResultModel>();

            var gcItems = new Dictionary <GCItem, string>();

            foreach (var item in models)
            {
                GCItem gcItem = ItemsService.GetSingleItem(item.GCId).Data;
                gcItems.Add(gcItem, item.CMSId);
            }

            //var templates = MappingRepository.GetMappings();
            var templatesDictionary = new Dictionary <int, GCTemplate>();

            foreach (var item in gcItems)
            {
                GCItem gcItem            = item.Key;      //gc item
                string cmsId             = item.Value;    // corresponding cms id
                var    itemResponseModel = new ItemResultModel
                {
                    IsImportSuccessful = true,
                    ImportMessage      = "Update Successful"
                };
                if (!string.IsNullOrEmpty(GcAccountSettings.GatherContentUrl))
                {
                    itemResponseModel.GcLink = string.Concat(GcAccountSettings.GatherContentUrl, "/item/", gcItem.Id);
                }
                itemResponseModel.GcItem = new GcItemModel
                {
                    Id    = gcItem.Id.ToString(),
                    Title = gcItem.Name
                };

                itemResponseModel.Status = new GcStatusModel
                {
                    Color = gcItem.Status.Data.Color,
                    Name  = gcItem.Status.Data.Name,
                };

                GCTemplate gcTemplate;
                int        templateId = gcItem.TemplateId.Value;
                templatesDictionary.TryGetValue(templateId, out gcTemplate);
                if (gcTemplate == null)
                {
                    gcTemplate = TemplatesService.GetSingleTemplate(templateId.ToString()).Data;
                    templatesDictionary.Add(templateId, gcTemplate);
                }

                itemResponseModel.GcTemplate = new GcTemplateModel
                {
                    Id   = gcTemplate.Id.ToString(),
                    Name = gcTemplate.Name
                };
                string cmsLink = ItemsRepository.GetCmsItemLink(HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Host, cmsId);
                itemResponseModel.CmsLink = cmsLink;
                itemResponseModel.CmsId   = cmsId;

                //MappingResultModel cmsItem;
                //TryMapItem(gcItem, gcTemplate, templates, out cmsItem);
                //result.Add(cmsItem);
                List <Element> gcFields = gcItem.Config.SelectMany(i => i.Elements).ToList();

                //var templateMapping = templates.First(x => x.GcTemplate.GcTemplateId == gcItem.TemplateId.ToString());

                var templateMapping = MappingRepository.GetMappingByItemId(cmsId, language);
                if (templateMapping != null)                 // template found, now map fields here
                {
                    var gcContentIdField = templateMapping.FieldMappings.FirstOrDefault(fieldMapping => fieldMapping.CmsField.TemplateField.FieldName == "GC Content Id");
                    if (gcContentIdField != null)
                    {
                        templateMapping.FieldMappings.Remove(gcContentIdField);
                    }

                    var files = new List <File>();
                    if (gcItem.Config.SelectMany(config => config.Elements).Any(element => element.Type == "files"))
                    {
                        foreach (var file in ItemsService.GetItemFiles(gcItem.Id.ToString()).Data)
                        {
                            files.Add(new File
                            {
                                FileName    = file.FileName,
                                Url         = file.Url,
                                FieldId     = file.Field,
                                UpdatedDate = file.Updated,
                                FileId      = file.Id
                            });
                        }
                    }

                    bool fieldError = CheckFieldError(templateMapping, gcFields, files, itemResponseModel);

                    if (!fieldError)
                    {
                        var cmsContentIdField = new FieldMapping
                        {
                            CmsField = new CmsField
                            {
                                TemplateField = new CmsTemplateField {
                                    FieldName = "GC Content Id"
                                },
                                Value = gcItem.Id.ToString()
                            }
                        };
                        templateMapping.FieldMappings.Add(cmsContentIdField);

                        var cmsItem = new CmsItem
                        {
                            Template = templateMapping.CmsTemplate,
                            Title    = gcItem.Name,
                            Fields   = templateMapping.FieldMappings.Select(x => x.CmsField).ToList(),
                            Language = language,
                            Id       = cmsId
                        };

                        var fieldMappings = templateMapping.FieldMappings;

                        // one CMS text field can be mapped to several GC fields
                        // in this case we concatenate their texts and put into one CMS field
                        foreach (IGrouping <string, FieldMapping> fields in fieldMappings.GroupBy(f => f.CmsField.TemplateField.FieldName))
                        {
                            FieldMapping field = fields.First();
                            if (field.GcField != null)
                            {
                                switch (field.GcField.Type)
                                {
                                case "choice_radio":
                                case "choice_checkbox":
                                {
                                    ItemsRepository.MapChoice(cmsItem, field.CmsField);
                                }
                                break;

                                case "files":
                                {
                                    ItemsRepository.ResolveAttachmentMapping(cmsItem, field.CmsField);
                                }
                                break;

                                default:
                                {
                                    if (field.CmsField.TemplateField.FieldType == "Datetime" || field.CmsField.TemplateField.FieldType == "Date")
                                    {
                                        ItemsRepository.MapDateTime(cmsItem, field.CmsField);
                                    }
                                    else
                                    {
                                        if (fields.Count() > 1)
                                        {
                                            field.CmsField.Value = string.Join("\r\n", fields.Select(f => f.CmsField.Value.ToString()));
                                        }

                                        ItemsRepository.MapText(cmsItem, field.CmsField);
                                    }
                                }
                                break;
                                }
                            }
                        }

                        var cmsSyncDateField = new CmsField
                        {
                            TemplateField = new CmsTemplateField {
                                FieldName = "Last Sync Date"
                            },
                            Value = DateTime.UtcNow.ToString("yyyyMMddTHHmmss")
                        };

                        ItemsRepository.MapText(cmsItem, cmsSyncDateField);
                    }
                }
                else
                {
                    //no template mapping, set error message
                    itemResponseModel.ImportMessage      = "Update failed: Template not mapped";
                    itemResponseModel.IsImportSuccessful = false;
                }
                model.Add(itemResponseModel);
            }

            return(model);
        }
        private List <ItemResultModel> Import(string itemId, List <ImportItemModel> items, string projectId, string statusId, string language)
        {
            var model = new List <ItemResultModel>();

            //get all paths
            var fullGcPaths          = GetItemsMap(projectId, items.Select(x => x.Id));
            var pathItemsToBeRemoved = new List <int>();

            Dictionary <string, List <ItemEntity> > shortPaths = new Dictionary <string, List <ItemEntity> >();

            if (fullGcPaths.Count() > 1)
            {
                var firstPath = fullGcPaths.First();
                foreach (var path in firstPath.Value)
                {
                    //if all paths start with same item and this item is not selected
                    if (fullGcPaths.Select(x => x.Value).All(x => x.First().Data.Id == path.Data.Id) && !items.Select(x => x.Id).Contains(path.Data.Id.ToString()))
                    {
                        pathItemsToBeRemoved.Add(path.Data.Id);
                    }
                }
            }

            foreach (var item in fullGcPaths)
            {
                List <ItemEntity> itemsToAdd = new List <ItemEntity>();

                foreach (var gcPathItem in item.Value)
                {
                    if (!pathItemsToBeRemoved.Contains(gcPathItem.Data.Id))
                    {
                        itemsToAdd.Add(gcPathItem);
                    }
                }
                shortPaths.Add(item.Key, itemsToAdd);
            }

            var sorted = shortPaths.OrderBy(x => x.Value.Count).ThenBy(x => x.Value.First().Data.Name);            //sort to start from shortest and alphabetically asc

            foreach (var path in sorted)
            {
                var itemResponseModel = new ItemResultModel
                {
                    IsImportSuccessful = true,
                    ImportMessage      = "Import Successful"
                };

                var gcItem = path.Value.Last();                                            //this is the item we selected to import
                var item   = items.FirstOrDefault(x => x.Id == gcItem.Data.Id.ToString()); //item coming from UI; selected mapping and other info

                if (gcItem != null && gcItem.Data != null && gcItem.Data.TemplateId != null)
                {
                    if (!string.IsNullOrEmpty(GcAccountSettings.GatherContentUrl))
                    {
                        itemResponseModel.GcLink = string.Concat(GcAccountSettings.GatherContentUrl, "/item/", gcItem.Data.Id);
                    }
                    itemResponseModel.GcItem = new GcItemModel
                    {
                        Id    = gcItem.Data.Id.ToString(),
                        Title = gcItem.Data.Name
                    };

                    itemResponseModel.Status = new GcStatusModel
                    {
                        Color = gcItem.Data.Status.Data.Color,
                        Name  = gcItem.Data.Status.Data.Name,
                    };

                    var gcTemplate = TemplatesService.GetSingleTemplate(gcItem.Data.TemplateId.ToString());
                    itemResponseModel.GcTemplate = new GcTemplateModel
                    {
                        Id   = gcTemplate.Data.Id.ToString(),
                        Name = gcTemplate.Data.Name
                    };

                    //element that corresponds to item in CMS that holds mappings
                    TemplateMapping templateMapping = MappingRepository.GetMappingById(item.SelectedMappingId);

                    List <Element> gcFields = gcItem.Data.Config.SelectMany(i => i.Elements).ToList();

                    if (templateMapping != null)                     // template found, now map fields here
                    {
                        var files = new List <File>();
                        if (gcItem.Data.Config.SelectMany(config => config.Elements).Select(element => element.Type).Contains("files"))
                        {
                            foreach (var file in ItemsService.GetItemFiles(gcItem.Data.Id.ToString()).Data)
                            {
                                files.Add(new File
                                {
                                    FileName    = file.FileName,
                                    Url         = file.Url,
                                    FieldId     = file.Field,
                                    UpdatedDate = file.Updated
                                });
                            }
                        }

                        bool fieldError = CheckFieldError(templateMapping, gcFields, files, itemResponseModel);

                        if (!fieldError)
                        {
                            var cmsContentIdField = new FieldMapping
                            {
                                CmsField = new CmsField
                                {
                                    TemplateField = new CmsTemplateField {
                                        FieldName = "GC Content Id"
                                    },
                                    Value = gcItem.Data.Id.ToString()
                                }
                            };
                            templateMapping.FieldMappings.Add(cmsContentIdField);

                            var cmsItem = new CmsItem
                            {
                                Template = templateMapping.CmsTemplate,
                                Title    = gcItem.Data.Name,
                                Fields   = templateMapping.FieldMappings.Select(x => x.CmsField).ToList(),
                                Language = language
                            };

                            var gcPath = string.Join("/", path.Value.Select(x => x.Data.Name));

                            var parentId = itemId;

                            bool alreadyMappedItemInPath = false;
                            //for each mapping which is fact GC Item => Sitecore/Umbraco item - get GC Path and run through its each item
                            for (int i = 0; i < path.Value.Count; i++)
                            {
                                //for each path item check if it exists already in CMS and if yes - skip; otherwise - add not mapped item
                                if (i == path.Value.Count - 1)
                                {
                                    //if we at the last item in the path - import mapped item
                                    if (ItemsRepository.IfMappedItemExists(parentId, cmsItem, templateMapping.MappingId, gcPath))
                                    {
                                        cmsItem.Id = ItemsRepository.AddNewVersion(parentId, cmsItem, templateMapping.MappingId, gcPath);
                                    }
                                    else
                                    {
                                        cmsItem.Id = ItemsRepository.CreateMappedItem(parentId, cmsItem, templateMapping.MappingId, gcPath);
                                    }
                                    parentId = cmsItem.Id;

                                    var fieldMappings = templateMapping.FieldMappings;

                                    // one CMS text field can be mapped to several GC fields
                                    // in this case we concatenate their texts and put into one CMS field
                                    foreach (IGrouping <string, FieldMapping> fields in fieldMappings.GroupBy(f => f.CmsField.TemplateField.FieldName))
                                    {
                                        var fieldMappingsAdditionals = fields
                                                                       .Where(f => f.CmsFieldAdditionalMapping != null &&
                                                                              f.CmsFieldAdditionalMapping.Any()).ToList()
                                                                       .SelectMany(f => f.CmsFieldAdditionalMapping).ToList();

                                        FieldMapping field = fields.First();
                                        if (field.GcField != null)
                                        {
                                            foreach (var fieldMappingsAdditional in fieldMappingsAdditionals)
                                            {
                                                fieldMappingsAdditional.Value   = field.CmsField.Value;
                                                fieldMappingsAdditional.Files   = field.CmsField.Files;
                                                fieldMappingsAdditional.Options = field.CmsField.Options;
                                            }

                                            switch (field.GcField.Type)
                                            {
                                            case "choice_radio":
                                            case "choice_checkbox":
                                            {
                                                ItemsRepository.MapChoice(cmsItem, field.CmsField);
                                                foreach (var fieldMappingsAdditional in fieldMappingsAdditionals)
                                                {
                                                    ItemsRepository.MapChoice(cmsItem, fieldMappingsAdditional);
                                                }
                                            }
                                            break;

                                            case "files":
                                            {
                                                ItemsRepository.ResolveAttachmentMapping(cmsItem, field.CmsField);
                                                foreach (var fieldMappingsAdditional in fieldMappingsAdditionals)
                                                {
                                                    ItemsRepository.ResolveAttachmentMapping(cmsItem, fieldMappingsAdditional);
                                                }
                                            }
                                            break;

                                            default:
                                            {
                                                if (field.CmsField.TemplateField.FieldType == "Datetime" || field.CmsField.TemplateField.FieldType == "Date")
                                                {
                                                    ItemsRepository.MapDateTime(cmsItem, field.CmsField);
                                                    foreach (var fieldMappingsAdditional in fieldMappingsAdditionals)
                                                    {
                                                        ItemsRepository.MapDateTime(cmsItem, fieldMappingsAdditional);
                                                    }
                                                }
                                                else
                                                {
                                                    if (fields.Count() > 1)
                                                    {
                                                        var newValue = string.Join("\r\n", fields.Select(f => f.CmsField.Value.ToString()));
                                                        field.CmsField.Value = newValue;
                                                        fieldMappingsAdditionals.ForEach(f => f.Value = newValue);
                                                    }

                                                    ItemsRepository.MapText(cmsItem, field.CmsField);
                                                    foreach (var fieldMappingsAdditional in fieldMappingsAdditionals)
                                                    {
                                                        ItemsRepository.MapText(cmsItem, fieldMappingsAdditional);
                                                    }
                                                }
                                            }
                                            break;
                                            }
                                        }
                                    }

                                    //Publish Parent Image Folder with SubItems?

                                    string parentMediaFolder = SimpleMediaRepository.publishParentMediaFolder;
                                    ItemsRepository.PublishItems(parentMediaFolder, isMediaFolder: true);
                                    ItemsRepository.PublishItems(cmsItem.Id, isContentItem: true);


                                    //set CMS link after we got out CMS Id
                                    var cmsLink = ItemsRepository.GetCmsItemLink(HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Host, cmsItem.Id);
                                    itemResponseModel.CmsLink = cmsLink;
                                    itemResponseModel.CmsId   = cmsItem.Id;

                                    if (!string.IsNullOrEmpty(statusId))
                                    {
                                        var status = PostNewItemStatus(gcItem.Data.Id.ToString(), statusId, projectId);
                                        itemResponseModel.Status.Color = status.Color;
                                        itemResponseModel.Status.Name  = status.Name;
                                    }
                                }
                                else
                                {
                                    var currentCmsItem = new CmsItem
                                    {
                                        Title    = path.Value[i].Data.Name,
                                        Language = language
                                    };
                                    //if we are not at the selected item, somewhere in the middle
                                    //1. если замапленный айтем существует (такое же название и такой же gc path?), то тогда выставляем alreadyMappedItemInPath = тру
                                    //и пропускаем всякое создание, сеттим только парент id
                                    //2. иначе если есть незамапленный айтем:
                                    // - alreadyMappedItemInPath == true = - скипуем создание, выставляем его как парент айди
                                    // - alreadyMappedItemInPath == false, - скипуем всё, парент айди не меняем
                                    //3. айтема никакого нет
                                    // - alreadyMappedItemInPath == true = - создаём незамапленный айтем, выставляем его как парент айди
                                    // - alreadyMappedItemInPath == false, - скипуем всё, парент айди не меняем
                                    if (ItemsRepository.IfMappedItemExists(parentId, currentCmsItem))
                                    {
                                        //cmsItem.Id = ItemsRepository.CreateNotMappedItem(parentId, notMappedCmsItem);
                                        //parentId = cmsItem.Id;
                                        alreadyMappedItemInPath = true;
                                        parentId = ItemsRepository.GetItemId(parentId, currentCmsItem);
                                    }
                                    else if (ItemsRepository.IfNotMappedItemExists(parentId, currentCmsItem))
                                    {
                                        if (alreadyMappedItemInPath)
                                        {
                                            parentId = ItemsRepository.GetItemId(parentId, currentCmsItem);
                                        }
                                    }
                                    else
                                    {
                                        if (alreadyMappedItemInPath)
                                        {
                                            parentId = ItemsRepository.CreateNotMappedItem(parentId, currentCmsItem);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        //no template mapping, set error message
                        itemResponseModel.ImportMessage      = "Import failed: Template not mapped";
                        itemResponseModel.IsImportSuccessful = false;
                    }
                }
                model.Add(itemResponseModel);
            }

            return(model);
        }
Esempio n. 30
0
		public static void RegisterServices (IGUIToolkit guiToolkit, IMultimediaToolkit multimediaToolkit)
		{
			App.Current.DependencyRegistry.Register<IStorageManager, CouchbaseManagerLongoMatch> (1);
			App.Current.DependencyRegistry.Register<IFileStorage, LMFileStorage> (1);
			App.Current.MultimediaToolkit = multimediaToolkit;
			App.Current.GUIToolkit = guiToolkit;
			App.Current.EventsBroker = new EventsBroker ();
			App.Current.EventsBroker.Subscribe<QuitApplicationEvent> (HandleQuitApplicationEvent);

			/* Start DB services */
			dbManager = new DataBaseManager ();
			RegisterService (dbManager);

			ts = new TemplatesService ();
			RegisterService (ts);

			/* Start the rendering jobs manager */
			jobsManagerVM = new JobsManagerVM {
				Model = new RangeObservableCollection<Job> ()
			};
			App.Current.JobsManager = jobsManagerVM;
			RenderingJobsController jobsController = new RenderingJobsController (jobsManagerVM);
			RegisterService (jobsController);

			projectsManager = new ProjectsManager ();
			RegisterService (projectsManager);

			/* State the tools manager */
			toolsManager = new ToolsManager ();
			RegisterService (toolsManager);
			ProjectsImporter = toolsManager;

			/* Start the events manager */
			eManager = new EventsManager ();
			RegisterService (eManager);

			RegisterService (new CoreEventsManager ());

			/* Start the hotkeys manager */
			hkManager = new HotKeysManager ();
			RegisterService (hkManager);

			/* Start playlists hotkeys manager */
			plManager = new PlaylistManager ();
			RegisterService (plManager);
		}
 public TemplatesController(TemplatesService templateService, ApplicationUserManager userManager) : base(userManager)
 {
     _templatesService = templateService;
 }
        public void TestCopyOverwrite()
        {
            TemplatesService ts = new TemplatesService (storage);
            ts.Start ();
            ITeamTemplatesProvider teamtemplateprovider = ts.TeamTemplateProvider;
            SportsTeam teamB = SportsTeam.DefaultTemplate (5);
            teamB.Name = "B";
            teamB.TeamName = "Template B";
            teamB.FormationStr = "1-4";
            teamB.List [0].Name = "Paco";
            teamtemplateprovider.Save (teamB);
            SportsTeam teamA = new SportsTeam ();
            teamA.Name = "A";
            teamA.TeamName = "Template A";
            teamA.FormationStr = "1-4-3-3";
            teamtemplateprovider.Save (teamA);

            SportsTeam auxdelete = teamA;
            teamtemplateprovider.Copy (teamB, "A");
            teamtemplateprovider.Delete (auxdelete);
            teamA = teamtemplateprovider.Templates [0];

            Assert.AreEqual (4, teamtemplateprovider.Templates.Count);
            Assert.AreEqual ("A", teamA.Name);
            Assert.AreEqual ("Template B", teamA.TeamName);
            Assert.AreEqual (teamB.List.Count, teamA.List.Count);
            Assert.AreEqual ("1-4", teamA.FormationStr);
            Assert.AreEqual ("Paco", teamA.List [0].Name);
        }
Esempio n. 33
0
 public ActionResult GetTemplate(string id)
 {
     return(Json(TemplatesService.GetBy(id), JsonRequestBehavior.AllowGet));
 }
        public void TestSystemTemplates()
        {
            TemplatesService ts = new TemplatesService (storage);
            // Start service
            ts.Start ();
            ICategoriesTemplatesProvider ctp = ts.CategoriesTemplateProvider;
            // We must have at least one template provider called 'Default'
            Dashboard dash = ctp.Templates [0];
            Assert.IsNotNull (dash);
            // Test we dont have a template
            Assert.IsFalse (ctp.Exists ("NonExistingTemplate"));

            ITeamTemplatesProvider ttp = ts.TeamTemplateProvider;
            Assert.AreEqual (2, ttp.Templates.Count);
            // Test we dont have a template
            Assert.IsFalse (ctp.Exists ("NonExistingTemplate"));
        }
Esempio n. 35
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="itemId"></param>
        /// <param name="models"></param>
        /// <param name="language"></param>
        /// <returns></returns>
        public List <ItemResultModel> UpdateItems(string itemId, List <UpdateListIds> models, string language)
        {
            var model = new List <ItemResultModel>();

            var gcItems = new Dictionary <GCItem, string>();

            foreach (var item in models)
            {
                GCItem gcItem = ItemsService.GetSingleItem(item.GCId).Data;
                gcItems.Add(gcItem, item.CMSId);
            }

            var templates           = MappingRepository.GetMappings();
            var templatesDictionary = new Dictionary <int, GCTemplate>();

            foreach (var item in gcItems)
            {
                var gcItem            = item.Key;   //gc item
                var cmsId             = item.Value; // corresponding cms id
                var itemResponseModel = new ItemResultModel
                {
                    IsImportSuccessful = true,
                    ImportMessage      = "Update Successful"
                };
                if (!string.IsNullOrEmpty(GcAccountSettings.GatherContentUrl))
                {
                    itemResponseModel.GcLink = string.Concat(GcAccountSettings.GatherContentUrl, "/item/", gcItem.Id);
                }
                itemResponseModel.GcItem = new GcItemModel
                {
                    Id    = gcItem.Id.ToString(),
                    Title = gcItem.Name
                };

                itemResponseModel.Status = new GcStatusModel
                {
                    Color = gcItem.Status.Data.Color,
                    Name  = gcItem.Status.Data.Name,
                };

                GCTemplate gcTemplate;
                var        templateId = gcItem.TemplateId.Value;
                templatesDictionary.TryGetValue(templateId, out gcTemplate);
                if (gcTemplate == null)
                {
                    gcTemplate = TemplatesService.GetSingleTemplate(templateId.ToString()).Data;
                    templatesDictionary.Add(templateId, gcTemplate);
                }

                itemResponseModel.GcTemplate = new GcTemplateModel
                {
                    Id   = gcTemplate.Id.ToString(),
                    Name = gcTemplate.Name
                };
                var cmsLink = ItemsRepository.GetCmsItemLink(HttpContext.Current.Request.Url.Host, cmsId);
                itemResponseModel.CmsLink = cmsLink;

                //MappingResultModel cmsItem;
                //TryMapItem(gcItem, gcTemplate, templates, out cmsItem);
                //result.Add(cmsItem);
                List <Element> gcFields = gcItem.Config.SelectMany(i => i.Elements).ToList();

                var templateMapping = templates.FirstOrDefault(x => x.GcTemplate.GcTemplateId == gcItem.TemplateId.ToString());
                if (templateMapping != null) // template found, now map fields here
                {
                    var gcContentIdField = templateMapping.FieldMappings.FirstOrDefault(fieldMapping => fieldMapping.CmsField.TemplateField.FieldName == "GC Content Id");
                    if (gcContentIdField != null)
                    {
                        templateMapping.FieldMappings.Remove(gcContentIdField);
                    }


                    var files = new List <File>();
                    if (
                        gcItem.Config.SelectMany(config => config.Elements)
                        .Select(element => element.Type)
                        .Contains("files"))
                    {
                        foreach (var file in ItemsService.GetItemFiles(gcItem.Id.ToString()).Data)
                        {
                            files.Add(new File
                            {
                                FileName    = file.FileName,
                                Url         = file.Url,
                                FieldId     = file.Field,
                                UpdatedDate = file.Updated
                            });
                        }
                    }

                    bool fieldError = false;

                    var groupedFields = templateMapping.FieldMappings.GroupBy(i => i.CmsField);

                    foreach (var grouping in groupedFields)
                    {
                        CmsField cmsField = grouping.Key;

                        var gcFieldIds    = grouping.Select(i => i.GcField.Id);
                        var gcFieldsToMap = grouping.Select(i => i.GcField);

                        IEnumerable <Element> gcFieldsForMapping =
                            gcFields.Where(i => gcFieldIds.Contains(i.Name)).ToList();

                        var gcField = gcFieldsForMapping.FirstOrDefault();

                        if (gcField != null)
                        {
                            var value   = GetValue(gcFieldsForMapping);
                            var options = GetOptions(gcFieldsForMapping);

                            cmsField.Files   = files.Where(x => x.FieldId == gcField.Name).ToList();
                            cmsField.Value   = value;
                            cmsField.Options = options;

                            //update GC fields' type
                            foreach (var field in gcFieldsToMap)
                            {
                                field.Type = gcField.Type;
                            }
                        }
                        else
                        {
                            //if field error, set error message
                            itemResponseModel.ImportMessage      = "Update failed: Template fields mismatch";
                            itemResponseModel.IsImportSuccessful = false;
                            fieldError = true;
                            break;
                        }
                    }

                    if (!fieldError)
                    {
                        var cmsContentIdField = new FieldMapping
                        {
                            CmsField = new CmsField
                            {
                                TemplateField = new CmsTemplateField {
                                    FieldName = "GC Content Id"
                                },
                                Value = gcItem.Id.ToString()
                            }
                        };
                        templateMapping.FieldMappings.Add(cmsContentIdField);

                        var cmsItem = new CmsItem
                        {
                            Template = templateMapping.CmsTemplate,
                            Title    = gcItem.Name,
                            Fields   = templateMapping.FieldMappings.Select(x => x.CmsField).ToList(),
                            Language = language,
                            Id       = cmsId
                        };

                        var fields = templateMapping.FieldMappings;
                        try
                        {
                            foreach (var field in fields)
                            {
                                if (field.GcField != null)
                                {
                                    switch (field.GcField.Type)
                                    {
                                    case "choice_radio":
                                    case "choice_checkbox":
                                    {
                                        ItemsRepository.MapChoice(cmsItem, field.CmsField);
                                    }
                                    break;

                                    case "files":
                                    {
                                        ItemsRepository.MapFile(cmsItem, field.CmsField);
                                    }
                                    break;

                                    default:
                                    {
                                        ItemsRepository.MapText(cmsItem, field.CmsField);
                                    }
                                    break;
                                    }
                                }
                            }
                        }
                        catch (KeyNotFoundException ex)
                        {
                            itemResponseModel.ImportMessage      = "Update failed: Some fields has been deleted from CMS Template";
                            itemResponseModel.IsImportSuccessful = false;
                            model.Add(itemResponseModel);
                            break;
                        }

                        //ItemsRepository.UpdateItem(new CmsItem
                        //{


                        //});
                    }
                }
                else
                {
                    //no template mapping, set error message
                    itemResponseModel.ImportMessage      = "Update failed: Template not mapped";
                    itemResponseModel.IsImportSuccessful = false;
                }
                model.Add(itemResponseModel);
            }

            return(model);
        }