/// <summary>
        /// Adds a new item to the navigation panel given the module (navigationPanelItemName) and module group ().
        /// Note, if either module or module group does not exist then an exception is thrown.
        /// </summary>
        /// <param name="navigationPanelItemName"></param>
        /// <param name="navigationListName"></param>
        /// <param name="moduleGroupItem"></param>
        public void AddNavigationListItem(string navigationPanelItemName, string navigationListName, ModuleGroupItem moduleGroupItem)
        {
            if (moduleGroupItem == null)
            {
                throw new ArgumentNullException(nameof(moduleGroupItem));
            }

            var navigationPanelItem = NavigationPanelItems.FirstOrDefault(
                npi => npi.NavigationPanelItemName.Equals(navigationPanelItemName, StringComparison.Ordinal));

            var navigationList = navigationPanelItem.NavigationList.FirstOrDefault(
                nl => nl.NavigationListName.Equals(navigationListName, StringComparison.Ordinal));

            var navigationListItem = new NavigationListItem
            {
                ItemName      = moduleGroupItem.ModuleGroupItemName,
                ImageLocation = moduleGroupItem.ModuleGroupItemImagePath
            };

            OnRegisterNavigation(navigationListItem);

            navigationList.NavigationListItems.Add(navigationListItem);

            var navigationSettings = new NavigationSettings
            {
                Title = moduleGroupItem.TargetViewTitle,
                View  = moduleGroupItem.TargetView
            };

            string navigationKey = $"{navigationPanelItem.NavigationPanelItemName}.{navigationList.NavigationListName}.{navigationListItem.ItemName}";

            navigationListItem.Tag = navigationKey;
            NavigationSettingsList.Add(navigationKey, navigationSettings);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a sophisticated Gizmos drawer for the current state of the surface.
        /// </summary>
        /// <param name="settings">The navigation settings of the system.</param>
        /// <returns>A sophisticated Gizmos drawer for the current state of the surface.</returns>
        public ISurfaceDrawer CreateAdvancedDrawer(NavigationSettings settings)
        {
            var centers = new List <Vector3> [NavigationSettings.AreasCount];
            var edges   = new HashSet <Edge> [NavigationSettings.AreasCount];

            for (int i = 0; i < NavigationSettings.AreasCount; i++)
            {
                centers[i] = new List <Vector3>();
                edges[i]   = new HashSet <Edge>();
            }

            foreach (var face in faces.Values)
            {
                int areaIndex = AreaMaskToIndex(face.AreaMask);
                edges[areaIndex].Add(face.ab);
                edges[areaIndex].Add(face.bc);
                edges[areaIndex].Add(face.ca);
                centers[areaIndex].Add(face.CalculateCenter());
            }

            var subDrawers = new List <GizmosSurfaceDrawer>();

            for (int i = 0; i < NavigationSettings.AreasCount; i++)
            {
                if (centers[i].Count > 0)
                {
                    var color     = settings.GetAreaSettings(i).Color;
                    var subDrawer = new GizmosSurfaceDrawer(color,
                                                            edges[i].ToArray(), centers[i].ToArray());
                    subDrawers.Add(subDrawer);
                }
            }

            return(new CompositeSurfaceDrawer(subDrawers.ToArray()));
        }
Exemplo n.º 3
0
            //void ApproachTarget

            /// <summary>
            /// Attempts to approach the target until it gets within range
            /// </summary>
            IEnumerator ApproachTargetRoutine(Transform target, float speed, float acceleration, float stoppingDistance, float angle)
            {
                // Store, then set the new settings
                var navSettings = new NavigationSettings(this.navigation);

                navSettings.Set(speed, acceleration, stoppingDistance);

                //Trace.Script("Will now approach " + target.name + " up until " + stoppingDistance + " units at " + speed + " speed!", this);
                this.OnMovementStarted();

                // While we are not within range of the target, keep making paths to it
                while (Vector3.Distance(transform.position, target.position) > stoppingDistance)
                {
                    //Trace.Script("Current distance = " + dist);
                    this.MoveTo(target.transform.position);

                    yield return(new WaitForFixedUpdate());
                }

                //Trace.Script("Approached " + target.name, this);

                // Now that we are in range of the target, let's revert to the old settings and stop moving
                this.navigation.isStopped = true;
                navSettings.Revert();
                this.steeringRoutine = null;

                this.OnMovementEnded();
            }
Exemplo n.º 4
0
        /// <summary>
        /// Adds a new item to the navigation panel given the module (navigationPanelItemName) and module group ().
        /// Note, if either module or module group does not exist then an exception is thrown.
        /// </summary>
        /// <param name="navigationPanelItemName"></param>
        /// <param name="navigationListName"></param>
        /// <param name="moduleGroupItem"></param>
        public void AddNavigationListItem(string navigationPanelItemName, string navigationListName, ModuleGroupItem moduleGroupItem)
        {
            var navigationPanelItem = navigationPanel.NavigationPanelItems.FirstOrDefault(
                npi => npi.NavigationPanelItemName.Equals(navigationPanelItemName));

            var navigationList = navigationPanelItem.NavigationList.FirstOrDefault(
                nl => nl.NavigationListName.Equals(navigationListName));

            var navigationListItems = new NavigationListItem
            {
                ItemName      = moduleGroupItem.ModuleGroupItemName,
                ImageLocation = moduleGroupItem.ModuleGroupItemImagePath
            };

            navigationListItems.ItemClicked += GroupListItemItemClicked;
            navigationList.NavigationListItems.Add(navigationListItems);

            var navigationSettings = new NavigationSettings
            {
                Title = moduleGroupItem.TargetViewTitle,
                View  = moduleGroupItem.TargetView
            };

            string navigationKey = String.Format("{0}.{1}.{2}",
                                                 navigationPanelItem.NavigationPanelItemName,
                                                 navigationList.NavigationListName,
                                                 navigationListItems.ItemName);

            navigationListItems.Tag = navigationKey;
            navigationSettingsList.Add(navigationKey, navigationSettings);
        }
        /// <summary>
        /// Creates the navigation controller.
        /// </summary>
        public void CreateNavigationController()
        {
            // Ceate a new navigation settings object
            navigationSettings = new NavigationSettings();

            // Create an instance of the controller
            navigationController = new NavigationController(navigationWindow, MainNavigation_Click, navigationSettings);
        }
Exemplo n.º 6
0
        private void OnWizardNavigationEvent(NavigationSettings settings)
        {
            var context     = wizardContainer.Resolve <IWizardContext>();
            var currentStep = context.Where(s => s.IsCurrent == true).FirstOrDefault();

            if (settings.Step == null)
            {
                if (currentStep != null)
                {
                    int currentStepIndex = currentStep.Index;

                    if (settings.MoveForward)
                    {
                        if (currentStepIndex >= context.StepsCount || !currentStep.IsComplete)
                        {
                            return;
                        }
                    }

                    if (!settings.MoveForward && currentStepIndex <= 0)
                    {
                        return;
                    }

                    if (settings.MoveForward)
                    {
                        currentStepIndex   += 1;
                        context.CurrentStep = currentStepIndex;
                    }
                    else
                    {
                        currentStepIndex   -= 1;
                        context.CurrentStep = currentStepIndex;
                    }

                    var step = context.Where(s => s.Index == currentStepIndex).FirstOrDefault();
                    if (step != null)
                    {
                        SwitchStepView(currentStep, step, context);
                    }
                }
            }
            else
            {
                var nextStep = settings.Step;

                var allStepsBeforeNext = context.Where(s => s.Index < nextStep.Index);

                var allStepsBeforeNextCompleted = allStepsBeforeNext.All(s => s.IsComplete);

                if (!allStepsBeforeNextCompleted && nextStep.Index > currentStep.Index)
                {
                    return;
                }

                SwitchStepView(currentStep, nextStep, context);
            }
        }
        /// <summary>
        /// Called by the system when a building process is joined.
        /// </summary>
        /// <param name="layers">The layer available in the system.</param>
        /// <param name="settings">The settings of the system.</param>
        public void OnBuildingProcesJoin(NavigationSurface[] layers, NavigationSettings settings)
        {
            if (logBuildingProcess)
            {
                Debug.Log("BuildingProcess finished after ~" +
                          (Time.timeSinceLevelLoad - buildingProcessStartTime));
            }

            UpdateGizmosDrawer(layers, settings);
        }
Exemplo n.º 8
0
 public void RegisterService(Type serviceType, object instance)
 {
     RegisterSingleton(serviceType, instance);
     if (instance is MySettings)
     {
         RegisterSingleton((instance as MySettings).mpaSettings);
         var navSettings = new NavigationSettings((instance as MySettings).mpaSettings);
         RegisterSingleton(navSettings);
         //(instance as MySettings).mpaSettings;
     }
 }
Exemplo n.º 9
0
        private void OpenDocument(object param)
        {
            var navigationSettings = new NavigationSettings()
            {
                View  = "ExampleDocumentNavigationView",
                Title = DocumentTitle,
                Data  = DocumentParameter
            };

            PublishDocument(navigationSettings);
        }
Exemplo n.º 10
0
        public void RegisterService(Type serviceType, object instance)
        {
            RegisterSingleton(serviceType, instance);

            if (serviceType == typeof(MySettings))
            {
                var settings    = (MySettings)instance;
                var navSettings = new NavigationSettings(settings.MPASettings, settings.TalkServiceSettings);
                RegisterSingleton(settings.MPASettings);
                RegisterSingleton(settings.TalkServiceSettings);
                RegisterSingleton(navSettings);
            }
        }
Exemplo n.º 11
0
        void CreateNavigationLink(string postName)
        {
            Post post = _postRepository.GetByTitle(postName);

            DynamicNavigationItem item = new DynamicNavigationItem
            {
                NavigationType = DynamicNavigationType.Post,
                PostId         = post.Id,
                Id             = Guid.NewGuid()
            };

            NavigationSettings.Add(item);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Adds a new module to the navigation view. Called by the <see cref="ModuleNavigator"/>.
        /// </summary>
        /// <param name="moduleSettings">Module settings.</param>
        public void AddModule(ModuleSettings moduleSettings)
        {
            if (moduleSettings == null)
            {
                throw new ArgumentNullException(nameof(moduleSettings));
            }

            var navigationPanelItem = new NavigationPanelItem
            {
                NavigationPanelItemName = moduleSettings.ModuleName,
                ImageLocation           = moduleSettings.ModuleImagePath
            };

            foreach (ModuleGroup moduleGroup in moduleSettings.ModuleGroups)
            {
                var navigationList = new NavigationList {
                    NavigationListName = moduleGroup.ModuleGroupName
                };

                foreach (ModuleGroupItem moduleGroupItem in moduleGroup.ModuleGroupItems)
                {
                    var navigationListItem = new NavigationListItem
                    {
                        ItemName      = moduleGroupItem.ModuleGroupItemName,
                        ImageLocation = moduleGroupItem.ModuleGroupItemImagePath
                    };

                    OnRegisterNavigation(navigationListItem);

                    navigationList.NavigationListItems.Add(navigationListItem);

                    var navigationSettings = new NavigationSettings
                    {
                        Title = moduleGroupItem.TargetViewTitle,
                        View  = moduleGroupItem.TargetView
                    };

                    string navigationKey = $"{navigationPanelItem.NavigationPanelItemName}.{navigationList.NavigationListName}.{navigationListItem.ItemName}";

                    navigationListItem.Tag = navigationKey;
                    NavigationSettingsList.Add(navigationKey, navigationSettings);
                }

                navigationPanelItem.NavigationList.Add(navigationList);
            }

            NavigationPanelItems.Add(navigationPanelItem);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Called to publish a new document. Calls the <see cref="Publish"/>
        /// event which is handled on the <see cref="ViewBase"/>.
        /// </summary>
        /// <param name="navigationSettings">Navigation settings for the new document.</param>
        protected void PublishDocument(NavigationSettings navigationSettings)
        {
            var publish = Publish;

            if (publish != null)
            {
                var navigationTarget = new NavigationTarget(navigationId, Title);
                if (navigationHistory.Count > 0)
                {
                    navigationTarget.AppendNavigationHistory(navigationHistory.Select(t => t.Target).ToArray());
                }

                navigationSettings.NavigationHistory = navigationTarget.NavigationHistory;
                publish(this, navigationSettings);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Adds a new module to the navigation view. Called by the <see cref="ModuleNavigator"/>.
        /// </summary>
        /// <param name="moduleSettings">Module settings.</param>
        public void AddModule(ModuleSettings moduleSettings)
        {
            var navigationPanelItem = new NavigationPanelItem
            {
                NavigationPanelItemName = moduleSettings.ModuleName,
                ImageLocation           = moduleSettings.ModuleImagePath
            };

            foreach (ModuleGroup moduleGroup in moduleSettings.ModuleGroups)
            {
                var navigationList = new NavigationList {
                    NavigationListName = moduleGroup.ModuleGroupName
                };

                foreach (ModuleGroupItem moduleGroupItem in moduleGroup.ModuleGroupItems)
                {
                    var navigationListItem = new NavigationListItem
                    {
                        ItemName      = moduleGroupItem.ModuleGroupItemName,
                        ImageLocation = moduleGroupItem.ModuleGroupItemImagePath
                    };

                    OnRegisterNavigation(navigationListItem);

                    navigationList.NavigationListItems.Add(navigationListItem);

                    var navigationSettings = new NavigationSettings
                    {
                        Title = moduleGroupItem.TargetViewTitle,
                        View  = moduleGroupItem.TargetView
                    };

                    string navigationKey = string.Format("{0}.{1}.{2}",
                                                         navigationPanelItem.NavigationPanelItemName,
                                                         navigationList.NavigationListName,
                                                         navigationListItem.ItemName);

                    navigationListItem.Tag = navigationKey;
                    NavigationSettingsList.Add(navigationKey, navigationSettings);
                }

                navigationPanelItem.NavigationList.Add(navigationList);
            }

            NavigationPanelItems.Add(navigationPanelItem);
        }
Exemplo n.º 15
0
            //protected void FollowPath(Vector3[] points, float speed, float acceleration, float stoppingDistance)
            //{
            //  if (CurrentRoutine != null) StopCoroutine(CurrentRoutine);
            //  CurrentRoutine = FollowPathRoutine(points, speed, acceleration, stoppingDistance);
            //  StartCoroutine(CurrentRoutine);
            //}

            /// <summary>
            /// Moves this agent through a list of points.
            /// </summary>
            protected IEnumerator FollowPathRoutine(Vector3[] points, float speed, float acceleration, float stoppingDistance)
            {
                // Store, then set the new settings
                var navSettings = new NavigationSettings(this.navigation);

                navSettings.Set(speed, acceleration, stoppingDistance);

                this.OnMovementStarted();

                // Create a new line renderer to draw this path
                //PathDisplay pathDisplay;
                //if (this.IsDebugging)
                //{
                //  pathDisplay = new PathDisplay(this.gameObject, points, Color.red, Color.blue);
                //}

                IEnumerator drawRoutine = null;

                if (this.debug)
                {
                    drawRoutine = DrawPathRoutine(points, Color.red, Color.yellow);
                    StartCoroutine(drawRoutine);
                }

                // Now travel the path
                foreach (var point in points)
                {
                    Trace.Script("Moving to next point: " + point, this);
                    while (Vector3.Distance(transform.position, point) > stoppingDistance)
                    {
                        this.navigation.SetDestination(point);
                        yield return(new WaitForFixedUpdate());
                    }
                }

                Trace.Script("Finished the path!");
                if (this.debug)
                {
                    StopCoroutine(drawRoutine);
                }


                this.OnMovementEnded();
                this.navigation.isStopped = true;
                navSettings.Revert();
            }
 /// <summary>
 /// Updates the drawing component.
 /// </summary>
 /// <param name="layers">The layer available in the system.</param>
 /// <param name="settings">The settings of the system.</param>
 public void UpdateGizmosDrawer(NavigationSurface[] layers, NavigationSettings settings)
 {
     if (drawSurface && drawSurfaceLayerIndex >= 0 && drawSurfaceLayerIndex < layers.Length)
     {
         if (drawSurfaceMinimized)
         {
             surfaceDrawer = layers[drawSurfaceLayerIndex].CreateMinimalDrawer();
         }
         else
         {
             surfaceDrawer = layers[drawSurfaceLayerIndex].CreateAdvancedDrawer(settings);
         }
     }
     else
     {
         surfaceDrawer = null;
     }
 }
Exemplo n.º 17
0
        public EditManager(IDefinitionManager definitions, IPersister persister, IVersionManager versioner,
                           ISecurityManager securityManager, IPluginFinder pluginFinder, NavigationSettings settings,
                           IEditUrlManager urls, StateChanger changer, EditableHierarchyBuilder interfaceBuilder, EditSection config)
        {
            this.definitions      = definitions;
            this.persister        = persister;
            this.versioner        = versioner;
            this.securityManager  = securityManager;
            this.pluginFinder     = pluginFinder;
            this.urls             = urls;
            this.stateChanger     = changer;
            this.interfaceBuilder = interfaceBuilder;
            this.settings         = settings;

            EditTheme               = config.EditTheme;
            EnableVersioning        = config.Versions.Enabled;
            MaximumNumberOfVersions = config.Versions.MaximumPerItem;
            uploadFolders           = new List <string>(config.UploadFolders.Folders);
        }
Exemplo n.º 18
0
        public void DeleteCategory(string categoryName)
        {
            if (String.IsNullOrEmpty(categoryName))
            {
                throw new ArgumentOutOfRangeException("categoryName");
            }

            Category category = GetCategory(categoryName);

            Post.DestroyDeletedPostCascadingForCategory(category.Id);
            Category.Destroy(Category.Columns.Id, category.Id);
            NavigationSettings settings = NavigationSettings.Get();

            DynamicNavigationItem item = settings.Items.Find(dni => dni.CategoryId == category.Id);

            if (item != null)
            {
                NavigationSettings.Remove(item.Id);
            }
            CategoryController.Reset();
        }
        /// <summary>
        /// Moves this agent through a list of points.
        /// </summary>
        protected IEnumerator FollowPathRoutine(Vector3[] points, float speed, float acceleration, float stoppingDistance)
        {
            // Store, then set the new settings
            var navSettings = new NavigationSettings(this.navigation);

            navSettings.Set(speed, acceleration, stoppingDistance);

            this.OnAgentMovementStarted();

            IEnumerator drawRoutine = null;

            if (this.debug)
            {
                drawRoutine = DrawPathRoutine(points, Color.red, Color.yellow);
                StartCoroutine(drawRoutine);
            }

            // Now travel the path
            foreach (var point in points)
            {
                StratusDebug.Log("Moving to next point: " + point, this);
                while (Vector3.Distance(transform.position, point) > stoppingDistance)
                {
                    this.navigation.SetDestination(point);
                    yield return(new WaitForFixedUpdate());
                }
            }

            StratusDebug.Log("Finished the path!");
            if (this.debug)
            {
                StopCoroutine(drawRoutine);
            }


            this.OnAgentMovementEnded();
            this.navigation.isStopped = true;
            navSettings.Revert();
        }
Exemplo n.º 20
0
        void CreateNavigationLink <TPlugin>() where TPlugin : GraffitiEvent, IPluginConfigurationProvider, new()
        {
            TPlugin  plugin   = PluginHelper.GetPluginWithCurrentSettings <TPlugin>();
            Category category = _categoryRepository.GetCategory(plugin.CategoryName);

            // Dynamic navigation items for categories are automatically created if the dynamic navigation items are empty.
            NavigationSettings settings = NavigationSettings.Get();

            if (settings.SafeItems().Exists(dni => dni.NavigationType == DynamicNavigationType.Category && dni.CategoryId == category.Id))
            {
                // The dynamic navigation item already exists.
                return;
            }

            DynamicNavigationItem item = new DynamicNavigationItem
            {
                NavigationType = DynamicNavigationType.Category,
                CategoryId     = category.Id,
                Id             = Guid.NewGuid()
            };

            NavigationSettings.Add(item);
        }
Exemplo n.º 21
0
 public NLDIServiceAgent(NLDISettings settings, NavigationSettings navsettings)
 {
     this.NLDIsettings       = settings;
     this.Navigationsettings = navsettings;
 }
Exemplo n.º 22
0
    protected void Page_Load(object sender, EventArgs e)
    {
        LiHyperLink.SetNameToCompare(Context, "presentation");

        NavigationSettings settings = NavigationSettings.Get();
        CategoryCollection cc       = new CategoryController().GetTopLevelCachedCategories();

        foreach (Category c in cc)
        {
            bool found = false;
            foreach (DynamicNavigationItem di in settings.SafeItems())
            {
                if (di.NavigationType == DynamicNavigationType.Category && di.CategoryId == c.Id)
                {
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                the_Categories.Items.Add(new ListItem(c.Name, "Category-" + c.UniqueId));
            }
        }


        Query q = Post.CreateQuery();

        q.AndWhere(Post.Columns.CategoryId, CategoryController.UnCategorizedId);
        q.AndWhere(Post.Columns.IsDeleted, false);
        q.AndWhere(Post.Columns.Status, 1);

        PostCollection pc = new PostCollection();

        pc.LoadAndCloseReader(q.ExecuteReader());

        foreach (Post p in pc)
        {
            bool found = false;
            foreach (DynamicNavigationItem di in settings.SafeItems())
            {
                if (di.NavigationType == DynamicNavigationType.Post && di.PostId == p.Id)
                {
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                the_Posts.Items.Add(new ListItem(p.Title, "Post-" + p.UniqueId));
            }
        }

        // 0 - Title, 1 - Type, 2 - LID
        string itemFormat =
            "<div style=\"border: solid 1px #999; padding: 4px;\"><strong>{0} ({1})</strong><div style=\"text-align:right;\"><a title=\"Delete Link\" href=\"javascript:void();\" onclick=\"remove_Link( &#39;{1}&#39;,&#39;{0}&#39;, &#39;{2}&#39;); return false;\">Delete</a></div></div>";

        foreach (DynamicNavigationItem dni in settings.SafeItems())
        {
            lbar.Items.Add(
                new OrderedListItem(string.Format(itemFormat, dni.Name, dni.NavigationType.ToString(), dni.Id),
                                    dni.Name, dni.NavigationType.ToString() + "-" + dni.Id.ToString()));
        }
    }
Exemplo n.º 23
0
        public void ProcessRequest(HttpContext context)
        {
            if (context.Request.RequestType != "POST" || !context.Request.IsAuthenticated)
            {
                return;
            }

            IGraffitiUser user = GraffitiUsers.Current;

            if (user == null)
            {
                return;
            }

            if (!RolePermissionManager.CanViewControlPanel(user))
            {
                return;
            }

            context.Response.ContentType = "text/plain";


            switch (context.Request.QueryString["command"])
            {
            case "deleteComment":

                Comment c = new Comment(context.Request.Form["commentid"]);

                if (RolePermissionManager.GetPermissions(c.Post.CategoryId, GraffitiUsers.Current).Publish)
                {
                    Comment.Delete(context.Request.Form["commentid"]);
                    context.Response.Write("success");
                }

                break;

            case "deleteCommentWithStatus":

                Comment c1 = new Comment(context.Request.Form["commentid"]);

                if (RolePermissionManager.GetPermissions(c1.Post.CategoryId, GraffitiUsers.Current).Publish)
                {
                    Comment.Delete(context.Request.Form["commentid"]);
                    context.Response.Write("The comment was deleted. <a href=\"javascript:void(0);\" onclick=\"Comments.unDelete('" +
                                           new Urls().AdminAjax + "'," + context.Request.Form["commentid"] +
                                           "); return false;\">Undo?</a>");
                }
                break;

            case "unDelete":
                Comment c2 = new Comment(context.Request.Form["commentid"]);

                if (RolePermissionManager.GetPermissions(c2.Post.CategoryId, GraffitiUsers.Current).Publish)
                {
                    Comment comment = new Comment(context.Request.Form["commentid"]);
                    comment.IsDeleted = false;
                    comment.Save();
                    context.Response.Write("The comment was un-deleted. You may need to refresh the page to see it");
                }
                break;

            case "approve":
                Comment c3 = new Comment(context.Request.Form["commentid"]);

                if (RolePermissionManager.GetPermissions(c3.Post.CategoryId, GraffitiUsers.Current).Publish)
                {
                    Comment cmt = new Comment(context.Request.Form["commentid"]);
                    cmt.IsDeleted   = false;
                    cmt.IsPublished = true;
                    cmt.Save();
                    context.Response.Write("The comment was un-deleted and/or approved. You may need to refresh the page to see it");
                }
                break;

            case "deletePost":
                try
                {
                    Post postToDelete = new Post(context.Request.Form["postid"]);

                    Permission perm = RolePermissionManager.GetPermissions(postToDelete.CategoryId, user);

                    if (GraffitiUsers.IsAdmin(user) || perm.Publish)
                    {
                        postToDelete.IsDeleted = true;
                        postToDelete.Save(user.Name, DateTime.Now);

                        //Post.Delete(context.Request.Form["postid"]);
                        //ZCache.RemoveByPattern("Posts-");
                        //ZCache.RemoveCache("Post-" + context.Request.Form["postid"]);
                        context.Response.Write("The post was deleted. <a href=\"javascript:void(0);\" onclick=\"Posts.unDeletePost('" +
                                               new Urls().AdminAjax + "'," + context.Request.Form["postid"] +
                                               "); return false;\">Undo?</a>");
                    }
                }
                catch (Exception ex)
                {
                    context.Response.Write(ex.Message);
                }
                break;

            case "unDeletePost":
                Post p = new Post(context.Request.Form["postid"]);
                p.IsDeleted = false;
                p.Save();
                //ZCache.RemoveByPattern("Posts-");
                //ZCache.RemoveCache("Post-" + context.Request.Form["postid"]);
                //context.Response.Write("The post was un-deleted. You may need to fresh the page to see it");
                break;

            case "permanentDeletePost":
                Post tempPost = new Post(context.Request.Form["postid"]);
                Post.DestroyDeletedPost(tempPost.Id);
                context.Response.Write(tempPost.Title);
                break;

            case "createdWidget":
                string widgetID    = context.Request.Form["id"];
                var    the_widgets = Widgets.GetAvailableWidgets();
                Widget widget      = null;
                foreach (WidgetDescription wia in the_widgets)
                {
                    if (wia.UniqueId == widgetID)
                    {
                        widget = Widgets.Create(wia.WidgetType);
                        break;
                    }
                }

                context.Response.Write(widget.Id.ToString());

                break;

            case "updateWidgetsOrder":

                try
                {
                    string listID = context.Request.Form["id"];
                    string list   = "&" + context.Request.Form["list"];

                    Widgets.ReOrder(listID, list);

                    //StreamWriter sw = new StreamWriter(context.Server.MapPath("~/widgets.txt"), true);
                    //sw.WriteLine(DateTime.Now);
                    //sw.WriteLine();
                    //sw.WriteLine(context.Request.Form["left"]);
                    //sw.WriteLine(context.Request.Form["right"]);
                    //sw.WriteLine(context.Request.Form["queue"]);
                    //sw.WriteLine();
                    //sw.Close();

                    context.Response.Write("Saved!");
                }
                catch (Exception ex)
                {
                    context.Response.Write(ex.Message);
                }
                break;

            case "deleteWidget":

                string deleteID = context.Request.Form["id"];
                Widgets.Delete(deleteID);
                context.Response.Write("The widget was removed!");

                break;

            case "createTextLink":
                DynamicNavigationItem di = new DynamicNavigationItem();
                di.NavigationType = DynamicNavigationType.Link;
                di.Text           = context.Request.Form["text"];
                di.Href           = context.Request.Form["href"];
                di.Id             = Guid.NewGuid();
                NavigationSettings.Add(di);
                context.Response.Write(di.Id);

                break;

            case "deleteTextLink":
                Guid g = new Guid(context.Request.Form["id"]);
                NavigationSettings.Remove(g);
                context.Response.Write("Success");
                break;

            case "reOrderNavigation":
                try
                {
                    string navItems = "&" + context.Request.Form["navItems"];
                    NavigationSettings.ReOrder(navItems);
                    context.Response.Write("Success");
                }
                catch (Exception ex)
                {
                    context.Response.Write(ex.Message);
                }
                break;

            case "addNavigationItem":


                try
                {
                    if (context.Request.Form["type"] == "Post")
                    {
                        Post navPost = Post.FetchByColumn(Post.Columns.UniqueId, new Guid(context.Request.Form["id"]));
                        DynamicNavigationItem item = new DynamicNavigationItem();
                        item.PostId         = navPost.Id;
                        item.Id             = navPost.UniqueId;
                        item.NavigationType = DynamicNavigationType.Post;
                        NavigationSettings.Add(item);
                        context.Response.Write("Success");
                    }
                    else if (context.Request.Form["type"] == "Category")
                    {
                        Category navCategory       = Category.FetchByColumn(Category.Columns.UniqueId, new Guid(context.Request.Form["id"]));
                        DynamicNavigationItem item = new DynamicNavigationItem();
                        item.CategoryId     = navCategory.Id;
                        item.Id             = navCategory.UniqueId;
                        item.NavigationType = DynamicNavigationType.Category;
                        NavigationSettings.Add(item);
                        context.Response.Write("Success");
                    }
                }
                catch (Exception exp)
                {
                    context.Response.Write(exp.Message);
                }

                break;

            case "reOrderPosts":
                try
                {
                    var   posts = new Dictionary <int, Post>();
                    Query query = Post.CreateQuery();
                    query.AndWhere(Post.Columns.CategoryId, int.Parse(context.Request.QueryString["id"]));
                    foreach (Post post in PostCollection.FetchByQuery(query))
                    {
                        posts[post.Id] = post;
                    }

                    string postOrder   = context.Request.Form["posts"];
                    int    orderNumber = 1;
                    foreach (string sId in postOrder.Split('&'))
                    {
                        Post post = null;
                        posts.TryGetValue(int.Parse(sId), out post);
                        if (post != null && post.SortOrder != orderNumber)
                        {
                            post.SortOrder = orderNumber;
                            post.Save();
                        }

                        orderNumber++;
                    }

                    context.Response.Write("Success");
                }
                catch (Exception ex)
                {
                    context.Response.Write(ex.Message);
                }
                break;

            case "reOrderHomePosts":
                try
                {
                    var   posts = new Dictionary <int, Post>();
                    Query query = Post.CreateQuery();
                    query.AndWhere(Post.Columns.IsHome, true);
                    foreach (Post post in PostCollection.FetchByQuery(query))
                    {
                        posts[post.Id] = post;
                    }

                    string postOrder   = context.Request.Form["posts"];
                    int    orderNumber = 1;
                    foreach (string sId in postOrder.Split('&'))
                    {
                        Post post = null;
                        posts.TryGetValue(int.Parse(sId), out post);
                        if (post != null && post.HomeSortOrder != orderNumber)
                        {
                            post.HomeSortOrder = orderNumber;
                            post.Save();
                        }

                        orderNumber++;
                    }

                    context.Response.Write("Success");
                }
                catch (Exception ex)
                {
                    context.Response.Write(ex.Message);
                }
                break;

            case "categoryForm":

                int selectedCategory = int.Parse(context.Request.QueryString["category"] ?? "-1");
                int postId           = int.Parse(context.Request.QueryString["post"] ?? "-1");
                NameValueCollection nvcCustomFields;
                if (postId > 0)
                {
                    nvcCustomFields = new Post(postId).CustomFields();
                }
                else
                {
                    nvcCustomFields = new NameValueCollection();
                }

                CustomFormSettings cfs = CustomFormSettings.Get(selectedCategory);

                if (cfs.HasFields)
                {
                    foreach (CustomField cf in cfs.Fields)
                    {
                        if (context.Request.Form[cf.Id.ToString()] != null)
                        {
                            nvcCustomFields[cf.Name] = context.Request.Form[cf.Id.ToString()];
                        }
                    }

                    context.Response.Write(cfs.GetHtmlForm(nvcCustomFields, (postId < 1)));
                }
                else
                {
                    context.Response.Write("");
                }

                break;

            case "toggleEventStatus":

                try
                {
                    EventDetails ed = Events.GetEvent(context.Request.QueryString["t"]);
                    ed.Enabled = !ed.Enabled;

                    if (ed.Enabled)
                    {
                        ed.Event.EventEnabled();
                    }
                    else
                    {
                        ed.Event.EventDisabled();
                    }

                    Events.Save(ed);

                    context.Response.Write(ed.Enabled ? "Enabled" : "Disabled");
                }
                catch (Exception ex)
                {
                    context.Response.Write(ex.Message);
                }
                break;

            case "buildMainFeed":
                try
                {
                    FileInfo mainFeedFileInfo = new FileInfo(HttpContext.Current.Server.MapPath("~/Feed/Default.aspx"));

                    if (!mainFeedFileInfo.Directory.Exists)
                    {
                        mainFeedFileInfo.Directory.Create();
                    }

                    using (StreamWriter sw = new StreamWriter(mainFeedFileInfo.FullName, false))
                    {
                        sw.WriteLine("<%@ Page Language=\"C#\" Inherits=\"Graffiti.Core.RSS\" %>");
                        sw.Close();
                    }

                    context.Response.Write("Success");
                }
                catch (Exception ex)
                {
                    context.Response.Write(ex.Message);
                    return;
                }

                break;

            case "removeFeedData":
                try
                {
                    FeedManager.RemoveFeedData();
                    context.Response.Write("Success");
                }
                catch (Exception ex)
                {
                    context.Response.Write(ex.Message);
                }
                break;

            case "buildCategoryPages":

                try
                {
                    CategoryCollection cc = new CategoryController().GetCachedCategories();
                    foreach (Category cat in cc)
                    {
                        cat.WritePages();
                    }


                    context.Response.Write("Success");
                }
                catch (Exception ex)
                {
                    context.Response.Write(ex.Message);
                    return;
                }

                break;

            case "buildPages":

                try
                {
                    Query q = Post.CreateQuery();
                    q.PageIndex = Int32.Parse(context.Request.Form["p"]);
                    q.PageSize  = 20;
                    q.OrderByDesc(Post.Columns.Id);

                    PostCollection pc = PostCollection.FetchByQuery(q);
                    if (pc.Count > 0)
                    {
                        foreach (Post postToWrite in pc)
                        {
                            postToWrite.WritePages();
                            foreach (string tagName in Util.ConvertStringToList(postToWrite.TagList))
                            {
                                if (!string.IsNullOrEmpty(tagName))
                                {
                                    Tag.WritePage(tagName);
                                }
                            }
                        }

                        context.Response.Write("Next");
                    }
                    else
                    {
                        context.Response.Write("Success");
                    }
                }
                catch (Exception ex)
                {
                    context.Response.Write(ex.Message);
                    return;
                }


                break;

            case "importPosts":

                try
                {
                    Post newPost = new Post();
                    newPost.Title = HttpContext.Current.Server.HtmlDecode(context.Request.Form["subject"]);

                    string postName = HttpContext.Current.Server.HtmlDecode(context.Request.Form["name"]);

                    PostCollection pc = new PostCollection();

                    if (!String.IsNullOrEmpty(postName))
                    {
                        Query q = Post.CreateQuery();
                        q.AndWhere(Post.Columns.Name, Util.CleanForUrl(postName));
                        pc.LoadAndCloseReader(q.ExecuteReader());
                    }

                    if (pc.Count > 0)
                    {
                        newPost.Name   = "[RENAME ME - " + Guid.NewGuid().ToString().Substring(0, 7) + "]";
                        newPost.Status = (int)PostStatus.Draft;
                    }
                    else if (String.IsNullOrEmpty(postName))
                    {
                        newPost.Name   = "[RENAME ME - " + Guid.NewGuid().ToString().Substring(0, 7) + "]";
                        newPost.Status = (int)PostStatus.Draft;
                    }
                    else
                    {
                        newPost.Name   = postName;
                        newPost.Status = (int)PostStatus.Publish;
                    }

                    if (String.IsNullOrEmpty(newPost.Title))
                    {
                        newPost.Title = newPost.Name;
                    }


                    newPost.PostBody       = HttpContext.Current.Server.HtmlDecode(context.Request.Form["body"]);
                    newPost.CreatedOn      = Convert.ToDateTime(context.Request.Form["createdon"]);
                    newPost.CreatedBy      = context.Request.Form["author"];
                    newPost.ModifiedBy     = context.Request.Form["author"];
                    newPost.TagList        = context.Request.Form["tags"];
                    newPost.ContentType    = "text/html";
                    newPost.CategoryId     = Convert.ToInt32(context.Request.Form["category"]);
                    newPost.UserName       = context.Request.Form["author"];
                    newPost.EnableComments = true;
                    newPost.Published      = Convert.ToDateTime(context.Request.Form["createdon"]);
                    newPost.IsPublished    = Convert.ToBoolean(context.Request.Form["published"]);

                    // this was causing too many posts to be in draft status.
                    // updated text on migrator to flag users to just move their content/binary directory
                    // into graffiti's root
                    //if (context.Request.Form["method"] == "dasBlog")
                    //{
                    //    if (newPost.Body.ToLower().Contains("/content/binary/"))
                    //        newPost.Status = (int)PostStatus.Draft;
                    //}

                    newPost.Save(GraffitiUsers.Current.Name);

                    int postid = Convert.ToInt32(context.Request.Form["postid"]);

                    IMigrateFrom temp = null;

                    switch (context.Request.Form["method"])
                    {
                    case "CS2007Database":

                        CS2007Database db = new CS2007Database();
                        temp = db;

                        break;

                    case "Wordpress":

                        Wordpress wp = new Wordpress();
                        temp = wp;

                        break;

                    case "BlogML":

                        BlogML bml = new BlogML();
                        temp = bml;

                        break;

                    case "CS21Database":
                        CS21Database csDb = new CS21Database();
                        temp = csDb;

                        break;

                    case "dasBlog":
                        dasBlog dasb = new dasBlog();
                        temp = dasb;

                        break;
                    }

                    var comments = temp.GetComments(postid);

                    foreach (MigratorComment cmnt in comments)
                    {
                        Comment ct = new Comment();
                        ct.PostId         = newPost.Id;
                        ct.Body           = cmnt.Body;
                        ct.Published      = cmnt.PublishedOn;
                        ct.IPAddress      = cmnt.IPAddress;
                        ct.WebSite        = cmnt.WebSite;
                        ct.Email          = string.IsNullOrEmpty(cmnt.Email) ? "" : cmnt.Email;
                        ct.Name           = string.IsNullOrEmpty(cmnt.UserName) ? "" : cmnt.UserName;
                        ct.IsPublished    = cmnt.IsPublished;
                        ct.IsTrackback    = cmnt.IsTrackback;
                        ct.SpamScore      = cmnt.SpamScore;
                        ct.DontSendEmail  = true;
                        ct.DontChangeUser = true;

                        ct.Save();

                        Comment ctemp = new Comment(ct.Id);
                        ctemp.DontSendEmail  = true;
                        ctemp.DontChangeUser = true;
                        ctemp.Body           = HttpContext.Current.Server.HtmlDecode(ctemp.Body);
                        ctemp.Save();
                    }

                    if (newPost.Status == (int)PostStatus.Publish)
                    {
                        context.Response.Write("Success" + context.Request.Form["panel"]);
                    }
                    else
                    {
                        context.Response.Write("Warning" + context.Request.Form["panel"]);
                    }
                }
                catch (Exception ex)
                {
                    context.Response.Write(context.Request.Form["panel"] + ":" + ex.Message);
                }

                break;

            case "saveHomeSortStatus":

                SiteSettings siteSettings = SiteSettings.Get();
                siteSettings.UseCustomHomeList = bool.Parse(context.Request.Form["ic"]);
                siteSettings.Save();
                context.Response.Write("Success");

                break;

            case "checkCategoryPermission":

                try
                {
                    int        catID          = Int32.Parse(context.Request.QueryString["category"]);
                    string     permissionName = context.Request.QueryString["permission"];
                    Permission perm           = RolePermissionManager.GetPermissions(catID, user);

                    bool permissionResult = false;
                    switch (permissionName)
                    {
                    case "Publish":
                        permissionResult = perm.Publish;
                        break;

                    case "Read":
                        permissionResult = perm.Read;
                        break;

                    case "Edit":
                        permissionResult = perm.Edit;
                        break;
                    }

                    context.Response.Write(permissionResult.ToString().ToLower());
                }
                catch (Exception ex)
                {
                    context.Response.Write(ex.Message);
                }
                break;
            }
        }
 public NavigationServiceAgent(NavigationSettings settings)
 {
     this.settings = settings;
 }
 public StationsController(IGageStatsAgent agent, IOptions <NLDISettings> nldisettings, IOptions <NavigationSettings> navsettings) : base()
 {
     NLDIsettings       = nldisettings.Value;
     Navigationsettings = navsettings.Value;
     this.agent         = agent;
 }
Exemplo n.º 26
0
 /// <summary>
 /// Handles the Publish event raised by the view model to open a new document.
 /// </summary>
 /// <param name="sender">The view model.</param>
 /// <param name="e">Navigation settings.</param>
 protected void Publish(object sender, NavigationSettings e)
 {
     ViewContext.NavigationManager.NavigateDocumentRegion(e);
 }
Exemplo n.º 27
0
    protected void lbDelete_Command(object sender, CommandEventArgs args)
    {
        int      id = Convert.ToInt32(args.CommandArgument);
        Category c  = new Category(id);

        if (c.HasChildren)
        {
            Message.Text = "You cannot delete this category because it has child categories.";
            Message.Type = StatusType.Error;
            return;
        }

        var postCounts = Post.GetPostCounts(id, null);

        if (postCounts != null && postCounts.Count > 0)
        {
            int totalPosts = 0;
            foreach (PostCount p in postCounts)
            {
                totalPosts += p.Count;
            }

            if (totalPosts == 1)
            {
                Message.Text  = "You cannot delete this category because it is in use by " + totalPosts + " post.";
                Message.Text += " <a href=\"" + ResolveUrl("~/graffiti-admin/posts/?category=") + id +
                                "\">Click here</a> to change this post to another category or delete it.";
                Message.Type = StatusType.Error;
            }
            else
            {
                Message.Text  = "You cannot delete this category because it is in use by " + totalPosts + " posts.";
                Message.Text += " <a href=\"" + ResolveUrl("~/graffiti-admin/posts/?category=") + id +
                                "\">Click here</a> to change these posts to another category or delete them.";
                Message.Type = StatusType.Error;
            }
            return;
        }

        try
        {
            // destroy any deleted posts in this category
            Post.DestroyDeletedPostCascadingForCategory(id);

            Category.Destroy(Category.Columns.Id, id);

            NavigationSettings    navSettings = NavigationSettings.Get();
            DynamicNavigationItem item        = navSettings.Items == null
                                                             ? null
                                                             : navSettings.Items.Find(
                delegate(DynamicNavigationItem itm) { return(itm.CategoryId == id); });

            if (item != null)
            {
                NavigationSettings.Remove(item.Id);
            }

            CategoryController.Reset();
            GetCategories();

            Message.Text = "The category " + c.Name + " was deleted.";
        }
        catch (Exception ex)
        {
            Message.Text = ex.Message;
            Message.Type = StatusType.Error;
        }
    }