Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=frugal-mono-tools.git;a=commitdiff;h=c2c048fc6577135835a63322623465f229c7cb74
commit c2c048fc6577135835a63322623465f229c7cb74 Author: bouleetbil <bouleet...@frogdev.info> Date: Sun Aug 29 14:15:38 2010 +0200 *fixes service *create new project for start a service as well diff --git a/Packages.mdproj b/Packages.mdproj index 79b004a..08fa599 100644 --- a/Packages.mdproj +++ b/Packages.mdproj @@ -1 +1,22 @@ -<?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <ItemType>PackagingProject</ItemType> <ProductVersion>8.0.50727</ProductVersion> <SchemaVersion>2.0</SchemaVersion> <ProjectGuid>{8CC36C0E-5E0E-4B46-A124-2CE460C48FF7}</ProjectGuid> <Packages> <Packages xmlns=""> <Package name="frugal-mono-tools-0.1"> <Builder TargetDirectory="releases" DefaultConfiguration="Release" ctype="TarballDeployTarget"> <RootEntry path="frugal-mono-tools\frugal-mono-tools.csproj" /> </Builder> </Package> </Packages> </Packages> </PropertyGroup> </Project> \ No newline at end of file +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <ItemType>PackagingProject</ItemType> + <ProductVersion>8.0.50727</ProductVersion> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{8CC36C0E-5E0E-4B46-A124-2CE460C48FF7}</ProjectGuid> + <Packages> + <Packages> + <Package name="frugal-mono-tools-0.1"> + <Builder TargetDirectory="releases" DefaultConfiguration="Release" ctype="TarballDeployTarget"> + <ChildEntries> + <SolutionItemReference path="frugal-mono-tools\frugal-mono-tools.csproj" /> + <SolutionItemReference path="Service\Service.csproj" /> + </ChildEntries> + <RootEntry path="frugal-mono-tools.sln" id=":root:" /> + </Builder> + </Package> + </Packages> + </Packages> + </PropertyGroup> +</Project> \ No newline at end of file diff --git a/Service/AssemblyInfo.cs b/Service/AssemblyInfo.cs new file mode 100644 index 0000000..fe6768f --- /dev/null +++ b/Service/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("Service")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/Service/Main.cs b/Service/Main.cs new file mode 100644 index 0000000..d640465 --- /dev/null +++ b/Service/Main.cs @@ -0,0 +1,65 @@ +using System; +using System.Diagnostics; +using System.Timers; + +namespace Service +{ + class MainClass + { + public static void Main (string[] args) + { + Outils.Excecute("pacman-g2"," -Sy",true); + System.ServiceProcess.ServiceBase[] servicesToRun; + servicesToRun = new System.ServiceProcess.ServiceBase[] { new Service()}; + System.ServiceProcess.ServiceBase.Run(servicesToRun); + string strPID = "/tmp/fwmono"; + int pid = Mono.Unix.UnixProcess.GetCurrentProcessId(); + System.IO.File.Delete(strPID); + System.IO.StreamWriter FilePid = new System.IO.StreamWriter(strPID); + FilePid.WriteLine("PID="+pid.ToString()); + FilePid.Close(); + } + } + public static class Outils + { + public static Boolean Excecute(String Commande,string Arguments,bool wait) + { + System.Diagnostics.Process proc = new System.Diagnostics.Process(); + proc.EnableRaisingEvents=false; + proc.StartInfo.FileName = Commande; + proc.StartInfo.Arguments = Arguments; + proc.StartInfo.RedirectStandardError = true; + //proc.StartInfo.RedirectStandardInput = true; + proc.StartInfo.RedirectStandardOutput = true; + proc.StartInfo.UseShellExecute = false; + if (!proc.Start()) return false; + if (wait) proc.WaitForExit(); + return true; + } + + } + public class Service : System.ServiceProcess.ServiceBase + { + System.Timers.Timer aTimer; + + public Service () + { + + } + protected override void OnStart(string[] args) + { + //update packages bdd + aTimer = new System.Timers.Timer(); + aTimer.Elapsed+=new ElapsedEventHandler(UpdateBDD); + // Set the Interval to 1 hour. + aTimer.Interval=3600000; + aTimer.Enabled=true; + } + private static void UpdateBDD(object source, ElapsedEventArgs e) + { + //Console.WriteLine("update pacman-g2 bdd"); + Outils.Excecute("pacman-g2"," -Sy",true); + } + } +} + diff --git a/Service/Service.csproj b/Service/Service.csproj new file mode 100644 index 0000000..3c6e36d --- /dev/null +++ b/Service/Service.csproj @@ -0,0 +1 @@ +<?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ProductVersion>8.0.50727</ProductVersion> <SchemaVersion>2.0</SchemaVersion> <ProjectGuid>{EFA0F4E7-CCFD-4DE2-A28D-C5D75FE55C43}</ProjectGuid> <OutputType>Exe</OutputType> <RootNamespace>Service</RootNamespace> <AssemblyName>ServiceMonoFrugal</AssemblyName> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>bin\Debug</OutputPath> <DefineConstants>DEBUG</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> <Externalconsole>true</Externalconsole> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>none</DebugType> <Optimize>false</Optimize> <OutputPath>bin\Release</OutputPath> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> <Externalconsole>true</Externalconsole> </PropertyGroup> <ItemGroup> <Reference Include="System" /> <Reference Include="System.ServiceProcess" /> <Reference Include="Mono.Posix" /> </ItemGroup> <ItemGroup> <Compile Include="Main.cs" /> <Compile Include="AssemblyInfo.cs" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <ProjectExtensions> <MonoDevelop> <Properties InternalTargetFrameworkVersion="3.5" xmlns=""> <Deployment.LinuxDeployData scriptName="ServiceMonoFrugal" /> </Properties> </MonoDevelop> </ProjectExtensions> </Project> \ No newline at end of file diff --git a/frugal-mono-tools.sln b/frugal-mono-tools.sln index a5d5b49..95eb0d0 100644 --- a/frugal-mono-tools.sln +++ b/frugal-mono-tools.sln @@ -5,6 +5,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "frugal-mono-tools", "frugal EndProject Project("{9344bdbb-3e7f-41fc-a0dd-8665d75ee146}") = "Packages", "Packages.mdproj", "{8CC36C0E-5E0E-4B46-A124-2CE460C48FF7}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Service", "Service\Service.csproj", "{EFA0F4E7-CCFD-4DE2-A28D-C5D75FE55C43}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x86 = Debug|x86 @@ -21,6 +23,12 @@ Global {E1F59443-629D-4EB7-A6AA-6ED8821FE6D6}.Release|Any CPU.Build.0 = Release|Any CPU {E1F59443-629D-4EB7-A6AA-6ED8821FE6D6}.Release|x86.ActiveCfg = Release|x86 {E1F59443-629D-4EB7-A6AA-6ED8821FE6D6}.Release|x86.Build.0 = Release|x86 + {EFA0F4E7-CCFD-4DE2-A28D-C5D75FE55C43}.Debug|x86.ActiveCfg = Debug|Any CPU + {EFA0F4E7-CCFD-4DE2-A28D-C5D75FE55C43}.Debug|x86.Build.0 = Debug|Any CPU + {EFA0F4E7-CCFD-4DE2-A28D-C5D75FE55C43}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EFA0F4E7-CCFD-4DE2-A28D-C5D75FE55C43}.Release|Any CPU.Build.0 = Release|Any CPU + {EFA0F4E7-CCFD-4DE2-A28D-C5D75FE55C43}.Release|x86.ActiveCfg = Release|Any CPU + {EFA0F4E7-CCFD-4DE2-A28D-C5D75FE55C43}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution StartupItem = frugal-mono-tools\frugal-mono-tools.csproj diff --git a/frugal-mono-tools/Main.cs b/frugal-mono-tools/Main.cs index ba4ad6b..1940b5e 100644 --- a/frugal-mono-tools/Main.cs +++ b/frugal-mono-tools/Main.cs @@ -16,8 +16,14 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; +using System.Collections; +using System.ComponentModel; +using System.Diagnostics; +using System.ServiceProcess; +using System.IO; +using System.Threading; using System.Timers; -using Gtk; + namespace frugalmonotools { @@ -26,13 +32,6 @@ namespace frugalmonotools //pacman-g2 initialise public static PacmanG2 pacmanG2 = new PacmanG2(); - public static IconSummaryBody notif= new IconSummaryBody(); - - private static void UpdateBDD(object source, ElapsedEventArgs e) - { - Console.WriteLine("update pacman-g2 bdd"); - Outils.Excecute("pacman-g2"," -Sy",false); - } private static void checkUpdate(object source, ElapsedEventArgs e) { Console.WriteLine("check update packages."); @@ -40,7 +39,8 @@ namespace frugalmonotools } private static void check() { - + IconSummaryBody notif= new IconSummaryBody(); + if (Update.CheckUpdate()) { if(Debug.ModeDebug) @@ -57,37 +57,23 @@ namespace frugalmonotools public static void Main (string[] args) { System.Timers.Timer aTimer; - Application.Init (); if(args.Length==0) { + Gtk.Application.Init(); check(); MainWindow win = new MainWindow (); win.Show (); - Application.Run (); + Gtk.Application.Run (); } else { + Console.WriteLine(args[0]); switch(args[0]) - { - case "--daemon": - Console.WriteLine("Daemon mode"); - if (Mono.Unix.Native.Syscall.getuid()!=0) - { - Console.Write("Daemon should be started with root user"); - System.Environment.Exit(0); - } - //update packages bdd - aTimer = new System.Timers.Timer(); - aTimer.Elapsed+=new ElapsedEventHandler(UpdateBDD); - // Set the Interval to 1 hour. - aTimer.Interval=3600000; - aTimer.Enabled=true; - Application.Run (); - break; - + { case "--update": //check if an update is avalaible //started with X session + Gtk.Application.Init(); Console.WriteLine("check update packages."); check(); aTimer = new System.Timers.Timer(); @@ -95,7 +81,7 @@ namespace frugalmonotools // Set the Interval to 1 hour. aTimer.Interval=3600000; aTimer.Enabled=true; - Application.Run (); + Gtk.Application.Run (); break; default: diff --git a/frugal-mono-tools/frugal-mono-tools.csproj b/frugal-mono-tools/frugal-mono-tools.csproj index 166b2b6..ba30bd7 100644 --- a/frugal-mono-tools/frugal-mono-tools.csproj +++ b/frugal-mono-tools/frugal-mono-tools.csproj @@ -48,6 +48,7 @@ <Reference Include="Mono.Posix" /> <Reference Include="webkit-sharp, Version=1.1.15.0, Culture=neutral, PublicKeyToken=eaa1d335d2e19745" /> <Reference Include="notify-sharp, Version=0.4.0.0, Culture=neutral, PublicKeyToken=2df29c54e245917a" /> + <Reference Include="System.ServiceProcess" /> </ItemGroup> <ItemGroup> <EmbeddedResource Include="gtk-gui\gui.stetic"> _______________________________________________ Frugalware-git mailing list Frugalware-git@frugalware.org http://frugalware.org/mailman/listinfo/frugalware-git