private void CreateVertices(Graph p_graph, GraphInformation p_graphInfo)
        {
            List <VertexItem> verticesInfo = null;
            int        i  = 0;
            VertexItem vi = null;

            verticesInfo = p_graphInfo.VertexCollection;
            for (i = 0; i < verticesInfo.Count; i++)
            {
                vi = verticesInfo[i];
                try
                {
                    p_graph.AddVertex(vi.Name);
                }
                catch (ArgumentException)
                {
                    throw new VertexInfoEmptyNameException(
                              string.Format(CultureInfo.InvariantCulture,
                                            "Vertex [#{0}] without name found",
                                            i + 1));
                }
                catch (InvalidOperationException)
                {
                    throw new VertexInfoDuplicationException(
                              string.Format(CultureInfo.InvariantCulture,
                                            "Vertices with the same name found; {0}", vi.Name));
                }
            }
        }
        public Graph Deserialize(string p_graphInformationFile)
        {
            Graph            rv    = null;
            GraphInformation gInfo = null;

            if (string.IsNullOrEmpty(p_graphInformationFile))
            {
                throw new ArgumentException("Graph information file path can not be null or empty", "p_graphInformationFile");
            }
            else if (!File.Exists(p_graphInformationFile))
            {
                throw new FileNotFoundException("Graph information file " +
                                                p_graphInformationFile +
                                                " does not exist");
            }

            XmlSerializer serializer = new XmlSerializer(typeof(GraphInformation));

            using (StreamReader reader = new StreamReader(p_graphInformationFile))
            {
                gInfo = (GraphInformation)serializer.Deserialize(reader);
            }

            rv = new Graph();

            rv.Name        = gInfo.Name;
            rv.Description = gInfo.Description;

            CreateVertices(rv, gInfo);
            RouteEdges(rv, gInfo);
            LoadApproximationsTable(rv, gInfo);

            return(rv);
        }
        /// <summary>
        /// Returns a BinaryReport of the diagram save in the given path/file
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        private BinaryReport GetReport(string filePath)
        {
            BinaryReport  report  = new BinaryReport();
            BinaryCapsule capsule = LoadCapsule(filePath);

            if (capsule != null)
            {
                report.Thumbnail = capsule.Thumbnail;
                GraphInformation info = capsule.Abstract.GraphInformation;
                report.Author       = info.Author;
                report.CreationDate = info.CreationDate;
                report.Description  = info.Description;
                report.FileSize     = new System.IO.FileInfo(filePath).Length;
                report.Path         = filePath;
                report.Subject      = info.Subject;
                report.Title        = info.Title;
                if (OnReport != null)
                {
                    OnReport(report, OutputInfoLevels.Info);
                }
                return(report);
            }
            else
            {
                return(null);
            }
        }
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="info"></param>
 public GraphInformationType(GraphInformation info)
 {
     this.mAuthor       = info.Author;
     this.mCreationDate = info.CreationDate;
     this.mDescription  = info.Description;
     this.mSubject      = info.Subject;
     this.mTitle        = info.Title;
 }
Exemple #5
0
 /// <summary>
 /// Loads the data of the graph information into the textboxes
 /// </summary>
 /// <param name="info"></param>
 private void LoadData(GraphInformation info)
 {
     author.Text       = info.Author;
     description.Text  = info.Description;
     title.Text        = info.Title;
     subject.Text      = info.Subject;
     creationdate.Text = info.CreationDate;
 }
        /// <summary>
        /// Returns this type as a GraphInformation object.
        /// </summary>
        /// <remarks>Used at deserialization</remarks>
        /// <returns></returns>
        public GraphInformation ToGraphInformation()
        {
            GraphInformation gi = new GraphInformation();

            gi.Author       = this.Author;
            gi.CreationDate = this.mCreationDate;
            gi.Description  = this.mDescription;
            gi.Subject      = this.mSubject;
            gi.Title        = this.mTitle;
            return(gi);
        }
        private void RouteEdges(Graph p_graph, GraphInformation p_graphInfo)
        {
            List <VertexItem> verticesInfo = null;
            int             i          = 0;
            VertexItem      vi         = null;
            Vertex          srcV       = null;
            Vertex          targetV    = null;
            List <EdgeItem> vEdgesInfo = null;
            int             j          = 0;
            double          weight     = 0;

            verticesInfo = p_graphInfo.VertexCollection;
            for (i = 0; i < verticesInfo.Count; i++)
            {
                vi   = verticesInfo[i];
                srcV = p_graph.Vertices[vi.Name] as Vertex;

                vEdgesInfo = vi.EdgeCollection;
                for (j = 0; j < vEdgesInfo.Count; j++)
                {
                    string targetName = vEdgesInfo[j].Target;
                    try
                    {
                        targetV = string.IsNullOrEmpty(targetName) ? null : p_graph.Vertices[targetName] as Vertex;
                        weight  = Convert.ToDouble(vEdgesInfo[j].Weight);
                        p_graph.AddEdge(srcV, targetV, weight);
                    }
                    catch (KeyNotFoundException)
                    {
                        throw new EdgeInfoEndNotExistsException(
                                  string.Format(CultureInfo.InvariantCulture,
                                                "Route edge from {0} failed, end vertex {1} does not exist.",
                                                vi.Name, targetV));
                    }
                    catch (InvalidOperationException)
                    {
                        throw new EdgeInfoEndDuplicationException(
                                  string.Format(CultureInfo.InvariantCulture,
                                                "Route edge from {0} failed, duplicate route to end vertex {1}.",
                                                vi.Name, targetName));
                    }
                    catch (FormatException)
                    {
                        throw new FormatException(
                                  string.Format(CultureInfo.InvariantCulture,
                                                "Weight [{0}] data for edge {1} ==> {2} is not a number in a valid format.",
                                                vEdgesInfo[j].Weight, vi.Name, targetName));
                    }
                }
            }
        }
        private void LoadApproximationsTable(Graph p_graph, GraphInformation p_graphInfo)
        {
            Approximations           approxs            = null;
            List <ApproximationItem> approximationsInfo = null;
            int i = 0;
            ApproximationItem ai      = null;
            Vertex            srcV    = null;
            Vertex            targetV = null;

            approxs            = new Approximations();
            approximationsInfo = p_graphInfo.ApproximationCollection;

            for (i = 0; i < approximationsInfo.Count; i++)
            {
                ai = approximationsInfo[i];

                try
                {
                    srcV    = p_graph.Vertices[ai.Source] as Vertex;
                    targetV = p_graph.Vertices[ai.Target] as Vertex;
                }
                catch (KeyNotFoundException)
                {
                    throw new EdgeInfoEndNotExistsException(
                              string.Format(CultureInfo.InvariantCulture,
                                            "Vertex for {0} ==> {1} approximation does not exist.",
                                            ai.Source, ai.Target));
                }
                try
                {
                    double approxVal = Convert.ToDouble(ai.aproximation);
                    approxs.SetH(srcV, targetV, approxVal);
                }
                catch (FormatException)
                {
                    throw new FormatException(
                              string.Format(CultureInfo.InvariantCulture,
                                            "Approximation [{0}] value for edge {1} ==> {2} is not a number in a valid format.",
                                            ai.aproximation, ai.Source, ai.Target));
                }
            }

            p_graph.Approximations = approxs;
        }
Exemple #9
0
 /// <summary>
 /// Required method for Designer support - do not modify
 /// the contents of this method with the code editor.
 /// </summary>
 private void InitializeComponent()
 {
     System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(GraphPropertiesDialog));
     this.surroundPanel = new System.Windows.Forms.Panel();
     this.upperPanel    = new System.Windows.Forms.Panel();
     this.xpCaption1    = new Netron.Neon.XPCaption();
     this.lowerPanel    = new System.Windows.Forms.Panel();
     this.Cancel        = new System.Windows.Forms.Button();
     this.OK            = new System.Windows.Forms.Button();
     this.graphProps1   = new Netron.GraphLib.UI.GraphProps();
     this.surroundPanel.SuspendLayout();
     this.upperPanel.SuspendLayout();
     this.lowerPanel.SuspendLayout();
     this.SuspendLayout();
     //
     // surroundPanel
     //
     this.surroundPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
     this.surroundPanel.Controls.Add(this.upperPanel);
     this.surroundPanel.Controls.Add(this.lowerPanel);
     this.surroundPanel.Dock      = System.Windows.Forms.DockStyle.Fill;
     this.surroundPanel.ForeColor = System.Drawing.Color.SlateGray;
     this.surroundPanel.Location  = new System.Drawing.Point(0, 0);
     this.surroundPanel.Name      = "surroundPanel";
     this.surroundPanel.Size      = new System.Drawing.Size(504, 360);
     this.surroundPanel.TabIndex  = 0;
     //
     // upperPanel
     //
     this.upperPanel.Controls.Add(this.graphProps1);
     this.upperPanel.Controls.Add(this.xpCaption1);
     this.upperPanel.Dock     = System.Windows.Forms.DockStyle.Fill;
     this.upperPanel.Location = new System.Drawing.Point(0, 0);
     this.upperPanel.Name     = "upperPanel";
     this.upperPanel.Size     = new System.Drawing.Size(502, 318);
     this.upperPanel.TabIndex = 3;
     //
     // xpCaption1
     //
     this.xpCaption1.Dock     = System.Windows.Forms.DockStyle.Top;
     this.xpCaption1.Font     = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Bold);
     this.xpCaption1.Location = new System.Drawing.Point(0, 0);
     this.xpCaption1.Name     = "xpCaption1";
     this.xpCaption1.Size     = new System.Drawing.Size(502, 20);
     this.xpCaption1.TabIndex = 0;
     this.xpCaption1.Text     = "Graph properties";
     //
     // lowerPanel
     //
     this.lowerPanel.Controls.Add(this.Cancel);
     this.lowerPanel.Controls.Add(this.OK);
     this.lowerPanel.Dock     = System.Windows.Forms.DockStyle.Bottom;
     this.lowerPanel.Location = new System.Drawing.Point(0, 318);
     this.lowerPanel.Name     = "lowerPanel";
     this.lowerPanel.Size     = new System.Drawing.Size(502, 40);
     this.lowerPanel.TabIndex = 2;
     //
     // Cancel
     //
     this.Cancel.Anchor    = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
     this.Cancel.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
     this.Cancel.Location  = new System.Drawing.Point(328, 8);
     this.Cancel.Name      = "Cancel";
     this.Cancel.TabIndex  = 1;
     this.Cancel.Text      = "Cancel";
     this.Cancel.Click    += new System.EventHandler(this.Cancel_Click);
     //
     // OK
     //
     this.OK.Anchor    = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
     this.OK.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
     this.OK.Location  = new System.Drawing.Point(408, 8);
     this.OK.Name      = "OK";
     this.OK.TabIndex  = 0;
     this.OK.Text      = "OK";
     this.OK.Click    += new System.EventHandler(this.OK_Click);
     //
     // graphProps1
     //
     this.graphProps1.BackColor        = System.Drawing.Color.White;
     this.graphProps1.Dock             = System.Windows.Forms.DockStyle.Fill;
     this.graphProps1.Font             = new System.Drawing.Font("Verdana", 8.25F);
     this.graphProps1.ForeColor        = System.Drawing.Color.DimGray;
     this.graphProps1.GraphInformation = ((Netron.GraphLib.GraphInformation)(resources.GetObject("graphProps1.GraphInformation")));
     this.graphProps1.Location         = new System.Drawing.Point(0, 20);
     this.graphProps1.Name             = "graphProps1";
     this.graphProps1.Size             = new System.Drawing.Size(502, 298);
     this.graphProps1.TabIndex         = 1;
     //
     // GraphPropertiesDialog
     //
     this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
     this.BackColor         = System.Drawing.Color.White;
     this.ClientSize        = new System.Drawing.Size(504, 360);
     this.Controls.Add(this.surroundPanel);
     this.Font            = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
     this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
     this.KeyPreview      = true;
     this.Name            = "GraphPropertiesDialog";
     this.ShowInTaskbar   = false;
     this.StartPosition   = System.Windows.Forms.FormStartPosition.CenterParent;
     this.Text            = "GraphPropertiesDialog";
     this.surroundPanel.ResumeLayout(false);
     this.upperPanel.ResumeLayout(false);
     this.lowerPanel.ResumeLayout(false);
     this.ResumeLayout(false);
 }
Exemple #10
0
 public GraphPropertiesDialog(GraphInformation info)
 {
     InitializeComponent();
     graphProps1.GraphInformation = info;
 }
        /// <summary>
        /// Saves an HTML version of the diagram to the given file
        /// </summary>
        /// <param name="filePath">a path</param>
        public void SaveAs(string filePath)
        {
            CreateDirAndFiles(filePath);

            StreamWriter sw = null;

            try
            {
                GraphInformation info     = mSite.Abstract.GraphInformation;
                Stream           stream   = Assembly.GetExecutingAssembly().GetManifestResourceStream("Netron.GraphLib.Resources.DefaultHTML.htm");
                StreamReader     reader   = new StreamReader(stream, System.Text.Encoding.ASCII);
                string           template = reader.ReadToEnd();

                stream.Close();

                stream = null;

                sw = new StreamWriter(filePath);

                if (info.Title == string.Empty)
                {
                    template = template.Replace("$title$", "A Netron diagram");
                }
                else
                {
                    template = template.Replace("$title$", info.Title);
                }

                if (info.Description == string.Empty)
                {
                    template = template.Replace("$description$", "Not set");
                }
                else
                {
                    template = template.Replace("$description$", info.Description);
                }

                if (info.Author == string.Empty)
                {
                    template = template.Replace("$author$", "Not set");
                }
                else
                {
                    template = template.Replace("$author$", info.Author);
                }

                if (info.Subject == string.Empty)
                {
                    template = template.Replace("$subject$", "Not set");
                }
                else
                {
                    template = template.Replace("$subject$", info.Subject);
                }

                template = template.Replace("$creationdate$", info.CreationDate);

                if (mSite.FileName == string.Empty)
                {
                    template = template.Replace("$filepath$", "Unsaved diagram");
                }
                else
                {
                    template = template.Replace("$filepath$", mSite.FileName);
                }

                string imagename = Path.ChangeExtension(Path.GetFileName(filePath), "jpg");

                mSite.SaveImage(Path.GetDirectoryName(filePath) + "\\images\\" + imagename, true);


                template = template.Replace("$imagepath$", "images\\" + imagename);

                template = template.Replace("$urlmap$", GetURLMap());


                sw.Write(template);
                sw.Close();
            }
            catch (Exception exc)
            {
                mSite.OutputInfo(exc.Message, OutputInfoLevels.Exception);
                if (sw != null)
                {
                    sw.Close();
                }
            }
        }
        protected void Page_PreRender(object sender, EventArgs e)
        {
            GraphInformation.HasReportTypeChanged = GeneralParams.ReportTypeControl.HasReportTypeChanged;


            if (GraphInformation.RefreshData || GraphInformation.UsingCachedGraphingData)
            {
                FutureTrendDataType futureTrendDataType;
                Enum.TryParse(GeneralParams.ReportTypeControl.SelectedForecastType.SelectedValue, out futureTrendDataType);

                var constrained = futureTrendDataType == FutureTrendDataType.Constrained ? true : false;

                var refreshDataFromDatabase = false;

                if (constrained && SavedConstrainedSeriesData == null)
                {
                    refreshDataFromDatabase = true;
                }

                if (!constrained && SavedUnconstrainedSeriesData == null)
                {
                    refreshDataFromDatabase = true;
                }

                if (GraphInformation.HaveDatesChanged || GraphInformation.HaveDynamicParametersChanged)
                {
                    refreshDataFromDatabase      = true;
                    SavedConstrainedSeriesData   = null;
                    SavedUnconstrainedSeriesData = null;
                }

                if (refreshDataFromDatabase || GraphInformation.RefreshData)
                {
                    var seriesData = BenchMarkDataAccess.GetBenchMarkGraphingData(GeneralParams.SelectedParameters, constrained);

                    if (constrained)
                    {
                        SavedConstrainedSeriesData = seriesData;
                    }
                    else
                    {
                        SavedUnconstrainedSeriesData = seriesData;
                    }

                    GraphInformation.SeriesData = seriesData;
                    GraphInformation.DataDate   = ParameterDataAccess.GetLastDateFromCmsForecast();
                    GraphInformation.UsingCachedGraphingData = false;
                }
                else
                {
                    GraphInformation.UsingCachedGraphingData = true;
                    GraphInformation.SeriesData = constrained
                                  ? SavedConstrainedSeriesData
                                  : SavedUnconstrainedSeriesData;
                }

                GraphInformation.TitleAdditional = string.Format("{0}",
                                                                 GeneralParams.ReportTypeControl.SelectedForecastType.SelectedItem.Text);

                GraphInformation.CalculateYEntriesCount();
                GraphInformation.RefreshData = false;

                this.SetPreviousDates(GeneralParams);

                GraphInformation.HaveDynamicParametersChanged = false;
            }
        }
        protected void Page_PreRender(object sender, EventArgs e)
        {
            //If this page is being being loaded but we have parameters from a previous visit
            if (!IsPostBack && GraphInformation.SelectedParameters[ParameterNames.Country].Length != 0)
            {
                SetQuickNavigationMenu();
            }

            //Don't allow drilldown past Pool
            if (GraphInformation.ReportParameters.First(p => p.Name == ParameterNames.Pool).SelectedValue != "")
            {
                GraphInformation.AllowDrillDown = false;
            }


            if (GraphInformation.RefreshData || GraphInformation.CheckIfCachedDataCanBeUsed)
            {
                SetQuickNavigationMenu();

                var topicId    = int.Parse(GeneralParams.ReportTypeControl.SelectedTopic.Value);
                var scenarioId = int.Parse(GeneralParams.ReportTypeControl.SelectedScenario.SelectedValue);

                if (topicId > 2)
                {
                    GraphInformation.LabelFormat            = "0%";
                    GraphInformation.DataPointsYAxisTooltip = "#VALY{0%}";
                    GraphInformation.YAxisNumberFormat      = "0%";
                }
                else
                {
                    GraphInformation.LabelFormat            = "#,##0";
                    GraphInformation.DataPointsYAxisTooltip = "#VALY{0,0}";
                    GraphInformation.YAxisNumberFormat      = "#,##0";
                }

                if (SiteComparisonGraphData[CurrentKey] == null || GraphInformation.RefreshData)
                {
                    //SiteComparisonGraphData[CurrentKey] = new SiteComparisonLogic(new SiteComparisonRepository()).GetData(GeneralParams.SelectedParameters, topicId, scenarioId);
                    SiteComparisonGraphData[CurrentKey] =
                        SiteComparisonDataAccess.GetSiteComparisonData(GeneralParams.SelectedParameters, topicId,
                                                                       scenarioId);
                    GraphInformation.DataDate = ParameterDataAccess.GetLastDateFromCmsForecast();
                }
                else
                {
                    GraphInformation.UsingCachedGraphingData = true;
                }

                GraphInformation.SeriesData = SiteComparisonGraphData[CurrentKey];

                if (string.IsNullOrEmpty(GraphInformation.TitleDate))
                {
                    GraphInformation.ShowLabelSeriesNames.Add(GraphInformation.SeriesData.First().SeriesName);
                }

                GraphInformation.TitleDate       = string.Format("{0} - {1}", GeneralParams.SelectedParameters[ParameterNames.FromDate], GeneralParams.SelectedParameters[ParameterNames.ToDate]);
                GraphInformation.TitleAdditional = string.Format("{0}", GeneralParams.ReportTypeControl.SelectedTopic.Text);

                GraphInformation.CalculateYEntriesCount();

                this.SetPreviousDates(GeneralParams);

                GraphInformation.RefreshData = false;
            }
        }
Exemple #14
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="info"></param>
 public GraphProps(GraphInformation info) : this()
 {
     this.info = info;
     LoadData(info);
 }
		/// <summary>
		/// Returns this type as a GraphInformation object.
		/// </summary>
		/// <remarks>Used at deserialization</remarks>
		/// <returns></returns>
		public GraphInformation ToGraphInformation()
		{
			GraphInformation gi = new GraphInformation();
			gi.Author = this.Author;
			gi.CreationDate = this.mCreationDate;
			gi.Description =this.mDescription;
			gi.Subject = this.mSubject;
			gi.Title = this.mTitle;
			return gi;
		}
		/// <summary>
		/// Default constructor
		/// </summary>
		/// <param name="info"></param>		
		public GraphInformationType(GraphInformation info)
		{
			this.mAuthor = info.Author;
			this.mCreationDate = info.CreationDate;
			this.mDescription = info.Description;
			this.mSubject = info.Subject;
			this.mTitle = info.Title;			
		}
Exemple #17
0
 /// <summary>
 /// Constructor
 /// </summary>
 public GraphProps()
 {
     InitializeComponent();
     info = new GraphInformation();
 }