Click here to Skip to main content
15,897,371 members
Articles / Programming Languages / C#

User-driven applications

Rate me:
Please Sign up or sign in to vote.
4.88/5 (24 votes)
10 Apr 2010CPOL136 min read 33.1K   5   78  
User-driven applications are the programs in which full control is given to the users. Designers of such programs are responsible only for developing an instrument for solving some task, but they do not enforce users to work with this instrument according with a predefined scenario.
using System;
using System .Collections .Generic;
using System .Drawing;
using System .Windows .Forms;
using Microsoft .Win32;

using MoveGraphLibrary;

namespace UserDrivenApplications
{
    public class AreaOnScreen
    {
        int version = 605;
        long id;
        MSPlot msplot;
        List<FunctionDesigned> funcs = new List<FunctionDesigned> ();

        // -------------------------------------------------
        public AreaOnScreen (MSPlot plot, List<FunctionDesigned> functions)
        {
            id = Auxi_Common .UniqueID;
            msplot = plot;
            funcs = functions;
        }
        // -------------------------------------------------        ID
        public long ID
        {
            get { return (id); }
            set { id = value; }
        }
        // -------------------------------------------------        Plot
        public MSPlot Plot
        {
            get { return (msplot); }
        }
        // -------------------------------------------------        FunctionInArea
        public bool FunctionInArea (long idFunc)
        {
            for (int i = 0; i < funcs .Count; i++)
            {
                if (idFunc == funcs [i] .ID)
                {
                    return (true);
                }
            }
            return (false);
        }
        // -------------------------------------------------        Draw
        public void Draw (Graphics grfx)
        {
            msplot .Draw (grfx);
            DrawPlots (grfx);
        }
        // -------------------------------------------------        DrawPlots
        public void DrawPlots (Graphics grfx)
        {
            for (int i = 0; i < funcs .Count; i++)
            {
                funcs [i] .Draw (grfx, msplot, i);
            }
        }
        //  -------------------------------------------------        SaveAreaIntoFunctions
        public void SaveAreaIntoFunctions ()
        {
            if (funcs .Count == 1)
            {
                funcs [0] .MSPlot = msplot;
            }
        }
        // -------------------------------------------------        CloseTuningForms
        public void CloseTuningForms ()
        {
            msplot .CloseTuningForms ();
        }

        const string nameMain = "Area_";
        // -------------------------------------------------        IntoRegistry
        public void IntoRegistry (RegistryKey regkey, string strAdd)
        {
            try
            {
                string [] strs = new string [3 + funcs .Count * 2];
                strs [0] = version .ToString ();
                strs [1] = id .ToString ();
                strs [2] = funcs .Count .ToString ();
                int k0 = 3;
                for (int i = 0; i < funcs .Count; i++)
                {
                    strs [k0 + i * 2] = ((int) (funcs [i] .Origin)) .ToString ();
                    strs [k0 + i * 2 + 1] = funcs [i] .ID .ToString ();
                }
                regkey .SetValue (nameMain + strAdd, strs, RegistryValueKind .MultiString);
                msplot .IntoRegistry (regkey, strAdd);
            }
            catch
            {
            }
            finally
            {
            }
        }
        // -------------------------------------------------        FromRegistry
        public static AreaOnScreen FromRegistry (Form form, RegistryKey regkey, string strAdd,
                                                 List<FunctionDesigned> funcsPredef, List<FunctionDesigned> funcsNew)
        {
            try
            {
                string [] strs = (string []) regkey .GetValue (nameMain + strAdd);
                if (form == null ||
                    strs == null || strs .Length < 5 ||
                    Convert .ToInt32 (strs [0]) != 605 ||   // version
                    funcsPredef == null || funcsNew == null || (funcsPredef .Count + funcsNew .Count == 0))
                {
                    return (null);
                }
                List<FunctionDesigned> funcsCheck;
                List<FunctionDesigned> funs = new List<FunctionDesigned> ();
                int nFunc = Convert .ToInt32 (strs [2]);
                int k0 = 3;
                for (int i = 0; i < nFunc; i++)
                {
                    FuncAuthor origin = (FuncAuthor) Convert .ToInt32 (strs [k0 + i * 2]);
                    long idRead = Convert .ToInt64 (strs [k0 + i * 2 + 1]);
                    if (origin == FuncAuthor .Developer)
                    {
                        funcsCheck = funcsPredef;
                    }
                    else
                    {
                        funcsCheck = funcsNew;
                    }
                    for (int j = 0; j < funcsCheck .Count; j++)
                    {
                        if (funcsCheck [j] .ID == idRead)
                        {
                            funs .Add (funcsCheck [j]);
                            break;
                        }
                    }
                }
                if (funs .Count <= 0)
                {
                    return (null);
                }
                MSPlot plot = MSPlot .FromRegistry (form, regkey, strAdd);
                if (plot == null)
                {
                    return (null);
                }
                AreaOnScreen area = new AreaOnScreen (plot, funs);
                if (area != null)
                {
                    area .ID = Convert .ToInt64 (strs [1]);
                }
                return (area);
            }
            catch
            {
                return (null);
            }
            finally
            {
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions