Exemplo n.º 1
0
        /// <summary>
        /// Retrieves the top-level information about the specified poll.  First it tries to get it from CFSysInfo, but if it's not
        /// present then it queries the file itself for the data, and populates CFSysInfo to save this extra step the next time.
        /// </summary>
        /// <param name="filename"></param>          // This is the full pathname
        /// <param name="revision"></param>
        /// <param name="pollSummary"></param>
        /// <param name="reviewData"></param>
        /// <param name="questionCount"></param>
        /// <param name="respondentCount"></param>
        public void GetPollDetails(string filename, out int revision, out string pollSummary, out bool reviewData, out int questionCount, out int respondentCount)
        {
            string basename = Tools.StripPathAndExtension(filename);

            // Assign default values to out parameters
            pollSummary     = "";
            revision        = 0;
            reviewData      = true;
            questionCount   = 0;
            respondentCount = 0; // Note: Not used by Templates, only Active Polls

            // See if we're starting a new poll, and thus looking at templates
            if (OpenMode == SelectFileMode.RunPoll && NewPoll)
            {
                _TemplateSummary templateSummary = CFSysInfo.Data.Summaries.Templates.Find_Template(basename);
                if (templateSummary != null)
                {
                    revision      = templateSummary.Revision;
                    pollSummary   = templateSummary.PollSummary;
                    questionCount = templateSummary.NumQuestions;
                }
                else // Not in Summaries yet so get directly from the poll itself and then store this info in Summaries
                {
                    Cursor.Current = Cursors.WaitCursor;
                    string pollGuid     = "";
                    string lastEditGuid = "";
                    Tools.GetPollOverview(filename, out revision, out pollSummary, out questionCount, out pollGuid, out lastEditGuid);
                    templateSummary = new _TemplateSummary(basename, revision, pollSummary, questionCount, pollGuid, lastEditGuid);
                    CFSysInfo.Data.Summaries.Templates.Add(templateSummary);
                }
            }

            else // Either Resuming an existing poll (in Data) or Reviewing a poll (in Data)
            {
                _ActivePollSummary activePollSummary = CFSysInfo.Data.Summaries.ActivePolls.Find_PollSummary(basename);

                if (activePollSummary != null)
                {
                    pollSummary     = activePollSummary.PollSummary;
                    revision        = activePollSummary.Revision;
                    reviewData      = activePollSummary.ReviewData;
                    questionCount   = activePollSummary.NumQuestions;
                    respondentCount = activePollSummary.NumResponses;
                }
                else // Not in Summaries yet so get directly from the poll itself and then store this info in Summaries
                {
                    Cursor.Current = Cursors.WaitCursor;
                    Tools.GetPollOverview(filename, out revision, out pollSummary, out reviewData, out questionCount, out respondentCount);
                    activePollSummary = new _ActivePollSummary(basename, revision, pollSummary, reviewData, questionCount, respondentCount);
                    CFSysInfo.Data.Summaries.ActivePolls.Add(activePollSummary);
                }
            }
        }
        } // End of "Main"

        private static void InitializeSysInfo()
        {
            // First find out where this EXE is located
            SysInfo.Data.Paths.App = Tools.EnsureFullPath(Application.StartupPath);

            // FYI: The following line is an alternative to "Application.StartupPath"
            //SysInfo.Data.Paths.App = Tools.EnsureFullPath(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase));

            // Necessary so that the various support folders appear in a more easily accessible location for the developer
            OnlyRunInDebug();              // Special code, only run while in Debug mode

            string appPath = SysInfo.Data.Paths.App;

            // See if we can retrieve the rest of the SysInfo data from disk
            Tools.OpenData(appPath + "SysInfo.xml", SysInfo.Data);

            // The master copy of much of the 'Admin' info resides in the embedded 'ProductInfo.xml'.
            // We will load this data and then copy it into the 'SysInfo' object.
            DataSet dataSet = Tools.GetProductInfo();

            DataTable table = dataSet.Tables["Admin"];

            if (table != null)
            {
                SysInfo.Data.Admin.AppName       = table.Rows[0]["AppName"].ToString();
                SysInfo.Data.Admin.AppFilename   = table.Rows[0]["AppFilename"].ToString();
                SysInfo.Data.Admin.AppExtension  = Tools.EnsurePrefix(table.Rows[0]["AppExtension"].ToString(), ".").ToLower();
                SysInfo.Data.Admin.ProductID     = (DataObjects.Constants.ProductID)Enum.Parse(typeof(DataObjects.Constants.ProductID), table.Rows[0]["ProductID"].ToString(), true);
                SysInfo.Data.Admin.CompanyName   = table.Rows[0]["CompanyName"].ToString();
                SysInfo.Data.Admin.RegKeyName    = table.Rows[0]["RegKeyName"].ToString();
                SysInfo.Data.Admin.OperatingMode = (DataObjects.Constants.OpMode)Enum.Parse(typeof(DataObjects.Constants.OpMode), table.Rows[0]["OperatingMode"].ToString(), true); // 1 - Standard     0 - Viewer Mode

                // "ExpiryDate" may or may not be present
                if (table.Columns["ExpiryDate"] != null)
                {
                    string expiryDate = table.Rows[0]["ExpiryDate"].ToString();
                    if (expiryDate != "")
                    {
                        SysInfo.Data.Admin.ExpiryDate = Tools.GetDateFromString(expiryDate);
                    }
                }
            }


            // Now that we have the AppName, we can find the location of the Data Files.  Note: At first, the Data folder existed underneath
            // of the app's folder in Program Files.  But this is old school, so we're now going to default it to the correct place in My Documents.
            if (SysInfo.Data.Paths.Data == "")
            {
                //SysInfo.Data.Paths.Data = Tools.EnsureDirectoryExists(SysInfo.Data.Paths.App + @"Data\");   // Old location
                string dataAppPath = Tools.EnsureFullPath(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData).ToString());
                dataAppPath += SysInfo.Data.Admin.AppName;
                Tools.EnsureDirectoryExists(dataAppPath);
                dataAppPath += @"\Data";
                Tools.EnsureDirectoryExists(dataAppPath);
                SysInfo.Data.Paths.Data = dataAppPath + @"\";
            }

            // Always need to set the following values, all of which are not written out to disk
            string dataPath = SysInfo.Data.Paths.Data;

            SysInfo.Data.Paths.Incoming  = Tools.EnsureDirectoryExists(dataPath + @"Incoming\", true);
            SysInfo.Data.Paths.Templates = Tools.EnsureDirectoryExists(dataPath + @"Templates\", true);
            SysInfo.Data.Paths.Archive   = Tools.EnsureDirectoryExists(dataPath + @"Archive\", true);

            SysInfo.Data.Paths.Help       = Tools.EnsureDirectoryExists(appPath + @"Help\");
            SysInfo.Data.Paths.MobileCabs = Tools.EnsureDirectoryExists(appPath + @"MobileCabs\");

            SysInfo.Data.Paths.CurrentData        = SysInfo.Data.Paths.Data;
            SysInfo.Data.Admin.DataTransferActive = false; // Default value
            SysInfo.Data.Paths.Temp = Tools.EnsureDirectoryExists(System.IO.Path.GetTempPath() + SysInfo.Data.Admin.AppName + @"\");

            // Populate the Product Version Number too
            SysInfo.Data.Admin.VersionNumber = Assembly.GetExecutingAssembly().GetName().Version.ToString();

            // Check if the GUID needs to be created.  Generally this should only happen the VERY first time the app is run.
            if (SysInfo.Data.Admin.Guid == null || SysInfo.Data.Admin.Guid == "")
            {
                System.Guid guid = System.Guid.NewGuid();
                SysInfo.Data.Admin.Guid = guid.ToString();
            }


            // Ensure that the [Poll] Summaries section of SysInfo is up to date

            // First remove any summary records that no longer have a corresponding template file
            if (SysInfo.Data.Summaries.Templates.Count > 0)
            {
                for (int i = SysInfo.Data.Summaries.Templates.Count - 1; i >= 0; i--)
                {
                    _TemplateSummary summary = SysInfo.Data.Summaries.Templates[i];
                    if (!File.Exists(SysInfo.Data.Paths.Templates + summary.Filename + Tools.GetAppExt()))
                    {
                        SysInfo.Data.Summaries.Templates.Remove(summary);
                    }
                }
            }

            // Now add any new summary records that haven't yet been created for existing template files
            string[] templateFiles = Directory.GetFiles(SysInfo.Data.Paths.Templates, Tools.GetAppFilter());
            foreach (string fullFilename in templateFiles)
            {
                string baseName = Tools.StripPathAndExtension(fullFilename);

                if (!SysInfo.Data.Summaries.Templates.ContainsFilename(baseName))
                {
                    string pollSummary   = "";
                    int    revision      = 0;
                    int    questionCount = 0;
                    string pollGuid      = "";
                    string lastEditGuid  = "";

                    Tools.GetPollOverview(fullFilename, out revision, out pollSummary, out questionCount, out pollGuid, out lastEditGuid);

                    //_TemplateSummary summary = new _TemplateSummary(SysInfo.Data.Summaries.Templates);
                    _TemplateSummary summary = new _TemplateSummary();
                    summary.Filename     = baseName;
                    summary.PollSummary  = pollSummary;
                    summary.Revision     = revision;
                    summary.NumQuestions = questionCount;
                    summary.PollGuid     = pollGuid;
                    summary.LastEditGuid = lastEditGuid;

                    SysInfo.Data.Summaries.Templates.Add(summary);
                }
            }
        }