public static BackupRestore Find(string Root, string Product, string Id)
 {
     var Result = default(BackupRestore);
     var Dir = Path.Combine(Root, BackupDirectory);
     var FullId = GetFullId(Product, Id);
     if (Directory.Exists(Dir))
     {
         var DirList = new List<DirectoryTag>();
         foreach (var DateItem in Directory.GetDirectories(Dir))
         {
             DateTime date;
             var DateName = new DirectoryInfo(DateItem).Name;
             if (DateTime.TryParseExact(DateName, DateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out date))
             {
                 foreach (var VersionItem in Directory.GetDirectories(DateItem))
                 {
                     var VersionName = new DirectoryInfo(VersionItem).Name;
                     if (VersionName.StartsWith(FullId, StringComparison.InvariantCultureIgnoreCase))
                     {
                         Version BckpVersion;
                         var StrVersion = VersionName.Substring(FullId.Length);
                         if (Version.TryParse(StrVersion, out BckpVersion))
                             DirList.Add(new DirectoryTag { Name = VersionItem, Date = date, Version = BckpVersion });
                     }
                 }
             }
         }
         var ByVersion = from i in DirList where i.Version == (from v in DirList select v.Version).Max() select i;
         var ByDate = from i in ByVersion where i.Date == (from v in ByVersion select v.Date).Max() select i;
         var SrcTag = ByDate.First();
         Result = new BackupRestore { Id = Id, Root = GetComponentRoot(SrcTag, Id), BackupFile = Path.Combine(SrcTag.Name, AppZip), BackupMainConfigFile = GetMainConfig(SrcTag) };
     }
     return Result;
 }
Exemple #2
0
 public static string ResolveProcessorArchitecture(string runtimePath)
 {
     var runtimeFullName = new DirectoryInfo(runtimePath).Name;
     var runtimeName = runtimeFullName.Substring(0, runtimeFullName.IndexOf('.'));
     var arch = runtimeName.Substring(runtimeName.LastIndexOf('-') + 1);
     return arch;
 }
Exemple #3
0
 //删除指定日期之前的日志
 public static void DelLogFile(string tag, DateTime dt)
 {
     //if ((DateTime.Now - dt).Days < 3)
     //{
     //    throw new Exception("不允许删除三天之内的日志");
     //}
     //else
     {
         if (string.IsNullOrWhiteSpace(tag))
         {
             string[] logPaths = Directory.GetDirectories(GetFilePath(BASE_FILEPATH));
             foreach (string logPath in logPaths)
             {
                 string pathName = new DirectoryInfo(logPath).Name;
                 DateTime dtHas = new DateTime(int.Parse(pathName.Substring(0, 4)), int.Parse(pathName.Substring(4, 2)), int.Parse(pathName.Substring(6, 2)));
                 if (dtHas <= dt)
                 {
                     try
                     {
                         Directory.Delete(logPath, true);
                     }
                     catch
                     {
                     }
                 }
             }
         }
         else
         {
             string[] logs = Directory.GetFiles(GetFilePath(BASE_FILEPATH), tag + "*.csv", SearchOption.AllDirectories);
             foreach (string log in logs)
             {
                 DateTime _dt = GetFileNameDateTime(log);
                 if (_dt <= dt)
                 {
                     bool success = false;
                     try
                     {
                         File.Delete(log);
                         success = true;
                     }
                     catch { success = false; }
                 }
             }
         }
     }
 }
Exemple #4
0
        public string GetIncludeFileVirtualPath(string includeVirtualPath)
        {
            //string result = includeVirtualPath;

            //if (includeVirtualPath.StartsWith("/"))
            //{
            //    result = "~" + includeVirtualPath;
            //}

            if (includeVirtualPath.StartsWith("~/"))
                return UrlUtil.ConvertDots(includeVirtualPath);

            if (includeVirtualPath.StartsWith("/"))
                return UrlUtil.ConvertDots("~" + includeVirtualPath);


            string temp = IOUtil.JoinPath(Path.GetDirectoryName(this.FilePath), includeVirtualPath);

            if (m_BaseFile != null && File.Exists(temp) == false)
            {
                temp = IOUtil.JoinPath(Path.GetDirectoryName(m_BaseFile.FilePath), includeVirtualPath);
            }

            temp = new DirectoryInfo(temp).FullName;

            temp = temp.Substring(Globals.ApplicationPath.Length);

            return UrlUtil.JoinUrl("~/", temp);

            //return result;
        }
Exemple #5
0
        /// <summary>
        /// Writes the REST file for a given type
        /// </summary>
        /// <param name="rootFolder"></param>
        /// <param name="type"></param>
        private void WriteRESTFile( string rootFolder, Type type )
        {
            string pluralizedName = pls.Pluralize( type.Name );

            string baseName = new DirectoryInfo( rootFolder ).Name;
            if ( baseName.EndsWith( ".Rest", StringComparison.OrdinalIgnoreCase ) )
            {
                baseName = baseName.Substring( 0, baseName.Length - 5 );
            }

            string restNamespace = type.Namespace;
            if ( restNamespace.StartsWith( baseName + ".", true, null ) )
            {
                restNamespace = baseName + ".Rest" + restNamespace.Substring( baseName.Length );
            }
            else
            {
                restNamespace = ".Rest." + restNamespace;
            }

            restNamespace = restNamespace.Replace( ".Model", ".Controllers" );

            var sb = new StringBuilder();

            sb.AppendLine( "//------------------------------------------------------------------------------" );
            sb.AppendLine( "// <auto-generated>" );
            sb.AppendLine( "//     This code was generated by the Rock.CodeGeneration project" );
            sb.AppendLine( "//     Changes to this file will be lost when the code is regenerated." );
            sb.AppendLine( "// </auto-generated>" );
            sb.AppendLine( "//------------------------------------------------------------------------------" );
            sb.AppendLine( "// <copyright>" );
            sb.AppendLine( "// Copyright 2013 by the Spark Development Network" );
            sb.AppendLine( "//" );
            sb.AppendLine( "// Licensed under the Apache License, Version 2.0 (the \"License\");" );
            sb.AppendLine( "// you may not use this file except in compliance with the License." );
            sb.AppendLine( "// You may obtain a copy of the License at" );
            sb.AppendLine( "//" );
            sb.AppendLine( "// http://www.apache.org/licenses/LICENSE-2.0" );
            sb.AppendLine( "//" );
            sb.AppendLine( "// Unless required by applicable law or agreed to in writing, software" );
            sb.AppendLine( "// distributed under the License is distributed on an \"AS IS\" BASIS," );
            sb.AppendLine( "// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied." );
            sb.AppendLine( "// See the License for the specific language governing permissions and" );
            sb.AppendLine( "// limitations under the License." );
            sb.AppendLine( "// </copyright>" );
            sb.AppendLine( "//" );
            sb.AppendLine( "" );

            sb.AppendFormat( "using {0};" + Environment.NewLine, type.Namespace );
            sb.AppendLine( "" );

            sb.AppendFormat( "namespace {0}" + Environment.NewLine, restNamespace );
            sb.AppendLine( "{" );
            sb.AppendLine( "    /// <summary>" );
            sb.AppendFormat( "    /// {0} REST API" + Environment.NewLine, pluralizedName );
            sb.AppendLine( "    /// </summary>" );
            sb.AppendFormat( "    public partial class {0}Controller : Rock.Rest.ApiController<{1}.{2}>" + Environment.NewLine, pluralizedName, type.Namespace, type.Name );
            sb.AppendLine( "    {" );
            sb.AppendFormat( "        public {0}Controller() : base( new {1}.{2}Service( new Rock.Data.RockContext() ) ) {{ }} " + Environment.NewLine, pluralizedName, type.Namespace, type.Name );
            sb.AppendLine( "    }" );
            sb.AppendLine( "}" );

            var file = new FileInfo( Path.Combine( NamespaceFolder( rootFolder, restNamespace ).FullName, "CodeGenerated", pluralizedName + "Controller.cs" ) );
            WriteFile( file, sb );
        }
Exemple #6
0
        /// <summary>
        /// Writes the REST file for a given type
        /// </summary>
        /// <param name="rootFolder"></param>
        /// <param name="type"></param>
        private void WriteRESTFile( string rootFolder, Type type )
        {
            string pluralizedName = pls.Pluralize( type.Name );

            string baseName = new DirectoryInfo( rootFolder ).Name;
            if ( baseName.EndsWith( ".Rest", StringComparison.OrdinalIgnoreCase ) )
            {
                baseName = baseName.Substring( 0, baseName.Length - 5 );
            }

            string restNamespace = type.Namespace;
            if ( restNamespace.StartsWith( baseName + ".", true, null ) )
            {
                restNamespace = baseName + ".Rest" + restNamespace.Substring( baseName.Length );
            }
            else
            {
                restNamespace = ".Rest." + restNamespace;
            }

            restNamespace = restNamespace.Replace( ".Model", ".Controllers" );

            var properties = GetEntityProperties( type );

            var sb = new StringBuilder();

            sb.AppendLine( "//------------------------------------------------------------------------------" );
            sb.AppendLine( "// <auto-generated>" );
            sb.AppendLine( "//     This code was generated by the Rock.CodeGeneration project" );
            sb.AppendLine( "//     Changes to this file will be lost when the code is regenerated." );
            sb.AppendLine( "// </auto-generated>" );
            sb.AppendLine( "//------------------------------------------------------------------------------" );
            sb.AppendLine( "//" );
            sb.AppendLine( "// THIS WORK IS LICENSED UNDER A CREATIVE COMMONS ATTRIBUTION-NONCOMMERCIAL-" );
            sb.AppendLine( "// SHAREALIKE 3.0 UNPORTED LICENSE:" );
            sb.AppendLine( "// http://creativecommons.org/licenses/by-nc-sa/3.0/" );
            sb.AppendLine( "//" );
            sb.AppendLine( "" );

            sb.AppendFormat( "using {0};" + Environment.NewLine, type.Namespace );
            sb.AppendLine( "" );

            sb.AppendFormat( "namespace {0}" + Environment.NewLine, restNamespace );
            sb.AppendLine( "{" );
            sb.AppendLine( "    /// <summary>" );
            sb.AppendFormat( "    /// {0} REST API" + Environment.NewLine, pluralizedName );
            sb.AppendLine( "    /// </summary>" );
            sb.AppendFormat( "    public partial class {0}Controller : Rock.Rest.ApiController<{1}.{2}, {1}.{2}Dto>" + Environment.NewLine, pluralizedName, type.Namespace, type.Name );
            sb.AppendLine( "    {" );
            sb.AppendFormat( "        public {0}Controller() : base( new {1}.{2}Service() ) {{ }} " + Environment.NewLine, pluralizedName, type.Namespace, type.Name );
            sb.AppendLine( "    }" );
            sb.AppendLine( "}" );

            var file = new FileInfo( Path.Combine( NamespaceFolder( rootFolder, restNamespace ).FullName, "CodeGenerated", pluralizedName + "Controller.cs" ) );
            WriteFile( file, sb );
        }
Exemple #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            // Create an instance of the open file dialog box.
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            // Set filter options and filter index.
            openFileDialog1.Filter = "CSV Files (.csv)|*.csv|All Files (*.*)|*.*";
            openFileDialog1.FilterIndex = 1;

            // Call the ShowDialog method to show the dialog box.
            DialogResult userClickedOK = openFileDialog1.ShowDialog();

             // Process input if the user clicked OK.
            if (userClickedOK == DialogResult.OK)
            {
                btnReadData.Enabled = true;
                InputFileName = openFileDialog1.FileName;
                TBInputFile.Text = InputFileName;
                OutputFileName = new DirectoryInfo(InputFileName).Parent.Parent.Name;

                OutputFileName = new DirectoryInfo(InputFileName).Parent.Parent.FullName +"\\"+ OutputFileName + ".txt";
                TBOutputFile.Text = OutputFileName;
                MarkerFileName = OutputFileName.Substring(0, OutputFileName.Length - 4) + "-markers.txt";
                InterviewFileName = OutputFileName.Substring(0, OutputFileName.Length - 4) + "-events.txt";

                lbStatus.Text = @"Ready";
                lbStatus.ForeColor = Color.Green;
                lbStatus.Refresh();

                if(File.Exists(MarkerFileName)) //Ask if the previous files need to be deleted or you want to abort the operation.
                {
                    DialogResult dialogResult = MessageBox.Show("Shimmerview Files for this Participant already exist. Do you want to delete the previous files and create new ones? Make sure you backup any previous interview information.", "Duplicate files", MessageBoxButtons.YesNo);
                    if (dialogResult == DialogResult.Yes)
                    {
                        string[] filePaths = Directory.GetFiles(new DirectoryInfo(InputFileName).Parent.Parent.FullName);
                        foreach (string filePath in filePaths)
                        File.Delete(filePath);
                        lbStatus.Text = @"Previous Files Deleted";
                        lbStatus.ForeColor = Color.Red;
                        lbStatus.Refresh();
                    }
                    else if (dialogResult == DialogResult.No)
                    {
                        lbStatus.Text = @"Check Files in folder and restart MarkerParser";
                        lbStatus.ForeColor = Color.Red;
                        lbStatus.Refresh();
                        btnReadData.Enabled = false;
                    }
                }

            }
        }