Пример #1
0
        public void AutomaticSetTempLocation()
        {
            // TODO Check if creation of dir is allowed
            // Exception if it is not

            // TODO check if this path is set in app configuration
            // if it is - get it from app configuration and check if it is OK
            // if it is - set it for this object and return

            bool needToCreate = true;

            if (UseAppSettings)
            {
                // Configuration conf = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                if (ConfigurationManager.AppSettings[pathParameterName] != null)
                {
                    if (Directory.Exists(ConfigurationManager.AppSettings[pathParameterName]))
                    {
                        this.SetTempLocation(ConfigurationManager.AppSettings[pathParameterName]);
                        needToCreate = false;
                    }
                    else
                    {
                        CreateTempDirectory(ConfigurationManager.AppSettings[pathParameterName], "");
                        needToCreate = false;
                    }
                }
            }
            if (needToCreate)
            {
                string userTempPath = Path.GetTempPath();
                string baseForTemp  = "";
                if (WfdbLocalFilesManager.IsWfdbPathCorrect(userTempPath))
                {
                    baseForTemp = userTempPath;
                }
                else
                {
                    baseForTemp = Path.GetPathRoot(System.Reflection.Assembly.GetExecutingAssembly().Location);
                }
                {
                    string[] dirs =
                        Directory.GetDirectories(baseForTemp);
                    if (!dirs.Contains <string>(Path.Combine(baseForTemp, this.defaultTempName)))
                    {
                        try
                        {
                            CreateTempDirectory(baseForTemp, defaultTempName);
                        }
                        catch
                        {
                            throw;
                        }
                    }
                    else
                    {
                        bool   done     = false;
                        int    i        = 0;
                        string tempName = defaultTempName;
                        string p        = "";
                        do
                        {
                            p = Path.Combine(baseForTemp, defaultTempName + i);
                            if (!dirs.Contains <string>(p))
                            {
                                try
                                {
                                    CreateTempDirectory(baseForTemp, tempName + i);
                                }
                                catch
                                {
                                    throw;
                                }
                                done = true;
                                break;
                            }
                            i++;
                        }while (!done);
                    }
                }
            }
            this.wfdbLocalFilesManager.SetLocationAsFirst(this.tempDirectoryPath);
        }