TSVCEO.CloudPrint.Proxy.CloudPrintProxy.Start C# (CSharp) Method

Start() public method

public Start ( bool useXMPP ) : void
useXMPP bool
return void
        public void Start(bool useXMPP)
        {
            lock (UpdateLock)
            {
                ThrowIfDisposed();

                if (Config.OAuthRefreshToken != null && Config.OAuthCodeAccepted)
                {
                    if (OAuthTicket == null)
                    {
                        OAuthTicket = new OAuthTicket(Config.OAuthRefreshToken, Config.OAuthClientID, Config.OAuthClientSecret, Config.OAuthRedirectURI);
                    }

                    if (PrintQueueUpdateTimer == null)
                    {
                        PrintQueueUpdateTimer = new Timer((obj) => { lock (UpdateLock) { PollUpdatePrintQueues(); } }, null, TimeSpan.Zero, PrintQueueUpdateInterval);
                    }

                    if (XMPP == null && PrintJobUpdateTimer == null)
                    {
                        PrintJobUpdateTimer = new Timer((obj) => PollUpdateCloudPrintJobs(), null, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(30));

                        if (useXMPP)
                        {
                            RunXMPP();
                        }
                    }

                    Logger.Log(LogLevel.Info, "Cloud Print Proxy started");
                }
                else
                {
                    throw new InvalidOperationException("Need to register and accept proxy before it can be started");
                }
            }
        }

Usage Example

        protected override void OnStart(string[] args)
        {
            this.Stopped.Reset();
            Logger.Log(LogLevel.Info, "Starting service");
            PrintProcessor = new WindowsPrintJobProcessor();

            PrintProxy = new CloudPrintProxy(PrintProcessor, (p) => Stop());

            InfoServer = new CloudPrintInfoServer(Config.UserAuthHttpPort, PrintProxy);
            InfoServer.Start();

            if (PrintProxy.IsRegistered)
            {
                PrintProxy.Start(true);
            }
            Logger.Log(LogLevel.Info, "Service started");
        }