protected DateTime HandleDateField(Sitecore.Data.Items.Item article)
        {
            Sitecore.Data.Fields.DateField dateField = article.Fields[this.DateField];
            Sitecore.Diagnostics.Assert.IsNotNull(dateField, this.DateField);
            DateTime result = dateField.DateTime;

            if (String.IsNullOrEmpty(dateField.InnerField.Value))
            {
                using (new Sitecore.Data.Items.EditContext(article, true, false))
                {
                    dateField.Value = Sitecore.DateUtil.IsoNow;
                    result          = Sitecore.DateUtil.IsoDateToDateTime(dateField.InnerField.Value);
                }
            }

            string sort = "-" + dateField.Value.Substring(4).Replace("T", String.Empty);

            if (article[Sitecore.FieldIDs.Sortorder] != sort)
            {
                using (new Sitecore.Data.Items.EditContext(article, true, true))
                {
                    article[Sitecore.FieldIDs.Sortorder] = sort;
                }
            }

            return(result);
        }
Example #2
0
        public static DateTime GetDate(this Sitecore.Data.Items.Item item, string field)
        {
            Sitecore.Data.Fields.DateField dateField = item.Fields[field];
            if (dateField != null)
            {
                return(dateField.DateTime);
            }

            return(DateTime.MinValue);
        }
        public override void Process(
            Sitecore.Publishing.Pipelines.PublishItem.PublishItemContext context)
        {
            string name = typeof(
                Sitecore.Sharedsource.Publishing.Pipelines.PublishItem.BeforePerformAction).ToString();

            foreach (Sitecore.Pipelines.PipelineMessage message
                     in context.GetMessages())
            {
                if (message.Text.StartsWith(name))
                {
                    Sitecore.Diagnostics.Log.Info(
                        this + " : " + message.Text, this);
                }
            }

            Sitecore.Diagnostics.Log.Info(
                this + " : Result after publishing : " + context.Result.Operation,
                this);
            Sitecore.Links.UrlOptions opt =
                context.CustomData["whatever"] as Sitecore.Links.UrlOptions;

            if (opt != null)
            {
                Sitecore.Diagnostics.Log.Info(
                    this + " : " + opt + " came through the pipeline.",
                    this);
            }

            if (context.VersionToPublish == null)
            {
                return;
            }

            Sitecore.Data.Fields.DateField lastPublished =
                context.VersionToPublish.Fields["LastPublished"];

            if (lastPublished == null)
            {
                return;
            }

            using (new Sitecore.Data.Items.EditContext(
                       context.VersionToPublish, false /*updateStatistics*/, false /*silent*/))
            {
                lastPublished.Value = Sitecore.DateUtil.IsoNow;
            }
        }
        protected override Sitecore.Data.Validators.ValidatorResult Evaluate()
        {
            Sitecore.Data.Items.Item item = this.GetItem();
            string firstFieldName         = Sitecore.StringUtil.GetString(this.Parameters["FirstFieldName"], "StartDate");
            string lastFieldName          = Sitecore.StringUtil.GetString(this.Parameters["LastFieldName"], "EndDate");

            Sitecore.Data.Fields.DateField first = item.Fields[firstFieldName];
            Sitecore.Data.Fields.DateField last  = item.Fields[lastFieldName];

            if (first == null)
            {
                this.Text = firstFieldName + " does not exist.";
                return(Sitecore.Data.Validators.ValidatorResult.Warning);
            }

            if (last == null)
            {
                this.Text = lastFieldName + " does not exist.";
                return(Sitecore.Data.Validators.ValidatorResult.Warning);
            }

            if (item.Template.StandardValues != null && item.Template.StandardValues.ID == item.ID)
            {
                return(Sitecore.Data.Validators.ValidatorResult.Valid);
            }

            if (DateTime.Compare(first.DateTime, last.DateTime) >= 0)
            {
                string firstTitle = Sitecore.StringUtil.GetString(first.InnerField.Title, first.InnerField.Name);
                string lastTitle  = Sitecore.StringUtil.GetString(last.InnerField.Title, last.InnerField.Name);
                this.Text = String.Format("{0} must be greater than {1}.", firstTitle, lastTitle);
                return(Sitecore.Data.Validators.ValidatorResult.Error);
            }

            return(Sitecore.Data.Validators.ValidatorResult.Valid);
        }
Example #5
0
        public bool CreateModule(ModuleItem moduleItem)
        {
            Sitecore.Diagnostics.Assert.ArgumentNotNull(moduleItem, "Module Item");

            using (new Sitecore.SecurityModel.SecurityDisabler())
            {
                Sitecore.Data.Database master = Database.GetDatabase(MasterDatabase);
                Sitecore.Diagnostics.Assert.ArgumentNotNull(master, "Master Database");

                TemplateItem template = master.GetTemplate(IDs.TemplateId);
                Sitecore.Diagnostics.Assert.ArgumentNotNull(template, "Module Templete");

                Item parentItem = master.GetItem(IDs.ModuleFolderId);
                Sitecore.Diagnostics.Assert.ArgumentNotNull(parentItem, "Module Parent Folder");

                string itemName = Sitecore.Data.Items.ItemUtil.ProposeValidItemName($"{moduleItem.Title}-{moduleItem.Author}", "Module Item");

                using (new Sitecore.SecurityModel.SecurityDisabler())
                {
                    try
                    {
                        Item newItem = parentItem.Add(itemName, template);

                        if (newItem != null)
                        {
                            newItem.Editing.BeginEdit();

                            newItem.Fields[IDs.Fields.GitHubURL].Value                    = moduleItem.GitHubURL;
                            newItem.Fields[IDs.Fields.DocumentationURL].Value             = moduleItem.DocumentationURL;
                            newItem.Fields[IDs.Fields.Title].Value                        = moduleItem.Title;
                            newItem.Fields[IDs.Fields.Summary].Value                      = moduleItem.Summary;
                            newItem.Fields[IDs.Fields.Author].Value                       = moduleItem.Author;
                            newItem.Fields[IDs.Fields.TestedAgainstSitecoreVersion].Value = moduleItem.TestedAgainstSitecoreVersion;
                            newItem.Fields[IDs.Fields.ProductLine].Value                  = moduleItem.ProductLine;

                            Sitecore.Data.Fields.DateField releaseDateField = newItem.Fields[IDs.Fields.ReleaseDate];
                            releaseDateField.Value = DateUtil.ToIsoDate(moduleItem.ReleaseDate);

                            Sitecore.Data.Fields.DateField lastCommitDateField = newItem.Fields[IDs.Fields.LastCommitDate];
                            lastCommitDateField.Value = DateUtil.ToIsoDate(moduleItem.LastCommitDate);

                            newItem.Fields[IDs.Fields.Stars].Value         = moduleItem.Stars.ToString();
                            newItem.Fields[IDs.Fields.DownloadCount].Value = moduleItem.DownloadCount.ToString();


                            newItem.Editing.EndEdit();

                            TagItem(newItem);
                            PublishItem(newItem);
                            return(true);
                        }
                    }
                    catch (System.Exception ex)
                    {
                        Sitecore.Diagnostics.Log.Error($"Could not create new item {itemName}", ex, this);
                        // newItem.Editing.CancelEdit();
                    }
                }

                return(false);
            }
        }
Example #6
0
        public List <Models.StationInformationDTO> /*stationInformation_AllType*/ GetAllStationInformation()
        {
            //  stationInformation_AllType allType = new stationInformation_AllType();
            //allType.stationInformation_All = new List<Models.StationInformation>();
            List <Models.StationInformationDTO> allType = new List <Models.StationInformationDTO>();
            //Database master = Sitecore.Configuration.Factory.GetDatabase("master");
            Database DB = Sitecore.Context.Database;

            Sitecore.Data.Items.Item stationInfo_Item = DB.GetItem("/sitecore/content/Home/iMap/Configuration/Station Information/");
            foreach (Sitecore.Data.Items.Item child in stationInfo_Item.Children)
            {
                Sitecore.Data.Fields.Field temp = child.Fields[Templates.StationInformation.StationName];

                StationInformationDTO stationInfoAll = new StationInformationDTO();
                stationInfoAll.stationName = child.Fields[Templates.StationInformation.StationName].ToString();
                stationInfoAll.CRSCode     = child.Fields[Templates.StationInformation.CRSCode].ToString();
                if (child.Fields[Templates.StationInformation.StationAddress].ToString() != null || child.Fields[Templates.StationInformation.StationAddress].ToString() != "")
                {
                    stationInfoAll.stationAddress = child.Fields[Templates.StationInformation.StationAddress].ToString();
                }
                stationInfoAll.stationAddress = child.Fields[Templates.StationInformation.StationAddress].ToString();
                stationInfoAll.xPos           = child.Fields[Templates.StationInformation.XPox].ToString();
                stationInfoAll.yPox           = child.Fields[Templates.StationInformation.YPos].ToString();
                stationInfoAll.status         = child.Fields[Templates.StationInformation.StationStatus].ToString();
                //stationInfoAll.startDate = child.Fields[Templates.StationInformation.ValidFrom];//.Value.ToString();
                //stationInfoAll.endDate = child.Fields[Templates.StationInformation.ValidTo];//.Value.ToString();
                //station status

                Sitecore.Data.Fields.DateField startDate = child.Fields[Templates.StationInformation.ValidFrom];
                Sitecore.Data.Fields.DateField endDate   = child.Fields[Templates.StationInformation.ValidTo];

                if (stationInfoAll.status == null || stationInfoAll.status == "" || StatusValid(endDate.DateTime) || startValid(startDate.DateTime))
                {
                    //default status
                    //stationInfo.statusIcon = null;
                    //stationInfo.statusTitle = null;
                    //stationInfo.statusMessage = null;
                }
                else
                {
                    Sitecore.Data.Items.Item stationStatusDetails = DB.GetItem("/sitecore/content/Home/iMap/Configuration/Station Status/" + stationInfoAll.status);
                    //stationInfoAll.statusIcon = stationStatusDetails.Fields[Templates.StationStatus.StationStatusIcon];
                    Sitecore.Data.Fields.ImageField statusIcon = stationStatusDetails.Fields[Templates.StationStatus.StationStatusIcon];
                    stationInfoAll.imageURL = Sitecore.Resources.Media.MediaManager.GetMediaUrl(statusIcon.MediaItem);

                    //stationInfoAll.statusTitle = stationStatusDetails.Fields[Templates.StationStatus.StationStatusTitle].Value;
                    //stationInfoAll.statusMessage = stationStatusDetails.Fields[Templates.StationStatus.StationStatusDetails].Value.Replace("startDate", stationInfoAll.startDate.ToString());
                    //stationInfoAll.statusMessage = stationInfoAll.statusMessage.Replace("endDate", stationInfoAll.endDate.ToString());

                    //Legends legendInfoAll = new Legends();
                    //legendInfoAll.icon = stationStatusDetails.Fields[Templates.LegendInformation.LegendIcon];
                    //legendInfoAll.imageURL = Sitecore.Resources.Media.MediaManager.GetMediaUrl(legendInfoAll.icon.MediaItem);
                    //legendInfoAll.subtitle = child.Fields[Templates.LegendInformation.LegendSubtitle].ToString();



                    //stationInfoAll.statusTitle = stationStatusDetails.Fields[Templates.StationStatus.StationStatusTitle].ToString();
                    //stationInfoAll.statusMessage = stationStatusDetails.Fields[Templates.StationStatus.StationStatusDetails].ToString();
                }
                allType.Add(stationInfoAll);
            }

            return(allType);
        }
Example #7
0
        //[HttpPost]
        //public ActionResult StationInformation()
        //{
        //    stationInformation_AllType modelFull = GetAllStationInformation();
        //    return Json(modelFull);
        //}
        //public List<Models.StationInformation> /*stationInformation_AllType*/ GetAllStationInformation()
        //{
        //    //  stationInformation_AllType allType = new stationInformation_AllType();
        //    //allType.stationInformation_All = new List<Models.StationInformation>();
        //    List<Models.StationInformation> allType = new List<Models.StationInformation>();
        //    //Database master = Sitecore.Configuration.Factory.GetDatabase("master");
        //    Database DB = Sitecore.Context.Database;
        //    Sitecore.Data.Items.Item stationInfo_Item = DB.GetItem("/sitecore/content/Home/iMap/Configuration/Station Information/");
        //    foreach (Sitecore.Data.Items.Item child in stationInfo_Item.Children)
        //    {

        //        Sitecore.Data.Fields.Field temp = child.Fields[Templates.StationInformation.StationName];

        //        StationInformation stationInfoAll = new StationInformation();
        //        stationInfoAll.stationName = child.Fields[Templates.StationInformation.StationName].ToString();
        //        stationInfoAll.CRSCode = child.Fields[Templates.StationInformation.CRSCode].ToString();
        //        //stationInfoAll.stationAddress = child.Fields[Templates.StationInformation.StationAddress].ToString();
        //        stationInfoAll.xPos = child.Fields[Templates.StationInformation.XPox].ToString();
        //        stationInfoAll.yPox = child.Fields[Templates.StationInformation.YPos].ToString();
        //        stationInfoAll.status = child.Fields[Templates.StationInformation.StationStatus].ToString();
        //        //stationInfoAll.startDate = child.Fields[Templates.StationInformation.ValidFrom];//.Value.ToString();
        //        //stationInfoAll.endDate = child.Fields[Templates.StationInformation.ValidTo];//.Value.ToString();
        //        //station status
        //        if (stationInfoAll.status == null || stationInfoAll.status == "")
        //        {
        //            //default status
        //            //stationInfoAll.statusIcon = "";
        //            //stationInfo.statusTitle = null;
        //            //stationInfo.statusMessage = null;
        //        }
        //        else
        //        {
        //            Sitecore.Data.Items.Item stationStatusDetails = DB.GetItem("/sitecore/content/Home/iMap/Configuration/Station Status/" + stationInfoAll.status);
        //            //stationInfoAll.statusIcon = stationStatusDetails.Fields[Templates.StationStatus.StationStatusIcon];
        //            Sitecore.Data.Fields.ImageField statusIcon = stationStatusDetails.Fields[Templates.StationStatus.StationStatusIcon];
        //            stationInfoAll.imageURL = Sitecore.Resources.Media.MediaManager.GetMediaUrl(statusIcon.MediaItem);

        //            //stationInfoAll.statusTitle = stationStatusDetails.Fields[Templates.StationStatus.StationStatusTitle].Value;
        //            //stationInfoAll.statusMessage = stationStatusDetails.Fields[Templates.StationStatus.StationStatusDetails].Value.Replace("startDate", stationInfoAll.startDate.ToString());
        //            //stationInfoAll.statusMessage = stationInfoAll.statusMessage.Replace("endDate", stationInfoAll.endDate.ToString());

        //            //Legends legendInfoAll = new Legends();
        //            //legendInfoAll.icon = stationStatusDetails.Fields[Templates.LegendInformation.LegendIcon];
        //            //legendInfoAll.imageURL = Sitecore.Resources.Media.MediaManager.GetMediaUrl(legendInfoAll.icon.MediaItem);
        //            //legendInfoAll.subtitle = child.Fields[Templates.LegendInformation.LegendSubtitle].ToString();



        //            //stationInfoAll.statusTitle = stationStatusDetails.Fields[Templates.StationStatus.StationStatusTitle].ToString();
        //            //stationInfoAll.statusMessage = stationStatusDetails.Fields[Templates.StationStatus.StationStatusDetails].ToString();

        //        }
        //        allType.Add(stationInfoAll);
        //    }

        //    return allType;
        //}

        public StationInformation GetStationInformation(string city)
        {
            StationInformation stationInfo = new StationInformation();
            //Database master = Sitecore.Configuration.Factory.GetDatabase("master");
            Database DB = Sitecore.Context.Database;

            Sitecore.Data.Items.Item stationInfo_Item = DB.GetItem("/sitecore/content/Home/iMap/Configuration/Station Information/" + city);
            if (stationInfo_Item != null)
            {
                stationInfo.stationName = stationInfo_Item.Fields[Templates.StationInformation.StationName].ToString();
                stationInfo.CRSCode     = stationInfo_Item.Fields[Templates.StationInformation.CRSCode].ToString();
                if (stationInfo_Item.Fields[Templates.StationInformation.StationAddress].ToString() != null || stationInfo_Item.Fields[Templates.StationInformation.StationAddress].ToString() != "")
                {
                    stationInfo.stationAddress = stationInfo_Item.Fields[Templates.StationInformation.StationAddress].ToString();
                }

                stationInfo.xPos   = stationInfo_Item.Fields[Templates.StationInformation.XPox].ToString();
                stationInfo.yPox   = stationInfo_Item.Fields[Templates.StationInformation.YPos].ToString();
                stationInfo.status = stationInfo_Item.Fields[Templates.StationInformation.StationStatus].ToString();
                //stationInfo.startDate = stationInfo_Item.Fields[Templates.StationInformation.ValidFrom];//.ToString();
                //stationInfo.endDate = stationInfo_Item.Fields[Templates.StationInformation.ValidTo];//.Value.ToString();
                Sitecore.Data.Fields.DateField startDate = stationInfo_Item.Fields[Templates.StationInformation.ValidFrom]; //.ToString();
                Sitecore.Data.Fields.DateField endDate   = stationInfo_Item.Fields[Templates.StationInformation.ValidTo];   //.Value.ToString();


                //station status
                if (stationInfo.status == null || stationInfo.status == "" || (StatusValid(endDate.DateTime) || startValid(startDate.DateTime)))
                {
                    //default status
                    //stationInfo.statusIcon = null;
                    //stationInfo.statusTitle = null;
                    //stationInfo.statusMessage = null;
                }
                else
                {
                    Sitecore.Data.Items.Item stationStatusDetails = DB.GetItem("/sitecore/content/Home/iMap/Configuration/Station Status/" + stationInfo.status);
                    //stationInfo.statusIcon = stationStatusDetails.Fields[Templates.StationStatus.StationStatusIcon];
                    Sitecore.Data.Fields.ImageField statusIcon = stationStatusDetails.Fields[Templates.StationStatus.StationStatusIcon];
                    if (statusIcon.MediaItem != null)
                    {
                        stationInfo.imageURL = Sitecore.Resources.Media.MediaManager.GetMediaUrl(statusIcon.MediaItem);
                    }

                    stationInfo.statusTitle = stationStatusDetails.Fields[Templates.StationStatus.StationStatusTitle].ToString();

                    stationInfo.statusMessage = stationStatusDetails.Fields[Templates.StationStatus.StationStatusDetails].ToString();
                    stationInfo.statusMessage = stationStatusDetails.Fields[Templates.StationStatus.StationStatusDetails].Value.Replace("startDate", startDate.ToString());
                    stationInfo.statusMessage = stationInfo.statusMessage.Replace("endDate", endDate.ToString());

                    //Sitecore.Data.Items.Item stationStatusDetails = DB.GetItem("/sitecore/content/Home/iMap/Configuration/Station Status/" + stationInfo.status);
                    //stationInfo.statusIcon = stationStatusDetails.Fields[Templates.StationStatus.StationStatusIcon];
                    //stationInfo.imageURL = Sitecore.Resources.Media.MediaManager.GetMediaUrl(stationInfo.statusIcon.MediaItem);
                    //stationInfo.statusIcon = stationStatusDetails.Fields[Templates.StationStatus.StationStatusIcon];
                    //stationInfo.statusTitle = stationStatusDetails.Fields[Templates.StationStatus.StationStatusTitle].Value;
                    //stationInfo.statusMessage = stationStatusDetails.Fields[Templates.StationStatus.StationStatusDetails].Value.Replace("startDate", stationInfo.startDate.ToString());
                    //stationInfo.statusMessage = stationInfo.statusMessage.Replace("endDate", stationInfo.endDate.ToString());
                }
            }

            return(stationInfo);
        }
        //public void PublishAuthorProfile(Item dataItem)
        //{
        //    // Match Created By field
        //    string createdBy = dataItem.Statistics.CreatedBy.Replace("\\", "");
        //    Item getUserProfileItem = BlogSettings.AuthorProfileLibrary.Axes.GetDescendants().Where(c => c.Name.Equals(createdBy)).FirstOrDefault();
        //    Item itemInWeb = targetDb.GetItem(getUserProfileItem.ID);
        //    if (getUserProfileItem != null && (itemInWeb == null || getUserProfileItem.Statistics.Revision != itemInWeb.Statistics.Revision))
        //    {
        //        Sitecore.Publishing.PublishOptions publishOptions = new Sitecore.Publishing.PublishOptions(masterDb,
        //            targetDb,
        //            Sitecore.Publishing.PublishMode.SingleItem,
        //            getUserProfileItem.Language,
        //            System.DateTime.Now);

        //        Sitecore.Publishing.Publisher publisher = new Sitecore.Publishing.Publisher(publishOptions);
        //        publisher.Options.RootItem = getUserProfileItem;
        //        publisher.Options.Deep = false;
        //        publisher.Options.PublishRelatedItems = true;
        //        publisher.Publish();
        //    }
        //}

        public void PublishPostItem(Item dataItem)
        {
            Item item = dataItem;

            // Add new version / Update Workflow / Keep inital created date for RSS Feed Sort
            using (new Sitecore.SecurityModel.SecurityDisabler())
            {
                if (Sitecore.Data.Database.GetDatabase("web").GetItem(item.ID) != null)
                {
                    Sitecore.Workflows.IWorkflow     workflow    = item.Database.WorkflowProvider.GetWorkflow(item);
                    Sitecore.Workflows.WorkflowState newState    = workflow.GetStates().FirstOrDefault(state => state.FinalState == true);
                    Sitecore.Data.Fields.DateField   pubDateTime = item.Fields["pubDate"];

                    string originalAuthor = dataItem.Fields["__Created by"].Value;

                    item = dataItem.Versions.AddVersion();
                    item.Editing.BeginEdit();
                    item.Fields["__Workflow state"].Value = newState.StateID.ToString();
                    item.Fields["__Created"].Value        = pubDateTime.Value;
                    item.Fields["__Created by"].Value     = originalAuthor;
                    item.Locking.Unlock();
                    item.Editing.EndEdit();
                }
            }

            //// Clearing master db cache
            //ClearCaches.ClearDatabaseCache(masterDb, item);

            // Author Profile - Republish
            if (BlogSettings.AuthorProfileLibrary != null)
            {
                PublihsingMethod(BlogSettings.AuthorProfileLibrary, Sitecore.Publishing.PublishMode.SingleItem, true, true);
            }

            // Media Library - Smart Publish
            Item imageLibrary = masterDb.GetItem(BlogSettings.ImageLibrary);

            if (imageLibrary != null)
            {
                PublihsingMethod(imageLibrary, Sitecore.Publishing.PublishMode.Smart, true);
            }

            // Tag Repository - Smart Publish
            if (BlogSettings.TagRepository != null)
            {
                PublihsingMethod(BlogSettings.TagRepository, Sitecore.Publishing.PublishMode.Smart, true);
            }

            // Post - Republish
            if (item != null)
            {
                PublihsingMethod(item, Sitecore.Publishing.PublishMode.SingleItem, false);
            }

            //// Clearing web db cache
            //ClearCaches.ClearDatabaseCache(targetDb, item);

            // Refresh the new post for search index web
            if (Sitecore.Data.Database.GetDatabase("web").GetItem(item.ID) != null)
            {
                var tempItem = (SitecoreIndexableItem)Sitecore.Data.Database.GetDatabase("web").GetItem(item.ID);
                // Replace master with web
                string searchIndexWeb = BlogSettings.SearchIndexName.Replace("master", "web");
                Sitecore.ContentSearch.ContentSearchManager.GetIndex(searchIndexWeb).Refresh(tempItem);
                Sitecore.Diagnostics.Log.Audit("Search Indexing: " + searchIndexWeb, this);
            }
        }