static void Main()
        {
            //// {D19F100E-113F-4751-820C-FD5AF8D17A55}

            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            string strLoc = Assembly.GetExecutingAssembly().Location;
            FileSystemInfo fileInfo = new FileInfo(strLoc);
            string sExeName = fileInfo.Name;
            bool bCreatedNew;

            if (false == LanguageTranslator.SetLanguage(System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName))
                LanguageTranslator.SetLanguage("en");

            mutex = new Mutex(true, "Global\\" + sExeName, out bCreatedNew);
            if (bCreatedNew)
                mutex.ReleaseMutex();
            else
            {
                BasicInfo.LoadRegistryValues();
                if (BasicInfo.SyncDirPath.Trim().Length != 0)
                {
                    string argument = BasicInfo.SyncDirPath;
                    System.Diagnostics.Process.Start(argument);
                }

                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Create the events tables since they weren't here last time.
            // The tables are only created if they don't already exist so
            // it is safe to make this call every time to be sure they exist.
            DbHandler dbHandler = new DbHandler();
            dbHandler.CreatedNewDatabase();
            dbHandler.CreateEventsTable();
            dbHandler.CreateIssueTable();

            // Clear any local events since the code will search for any local
            // changes and create events for them.
            dbHandler.ClearLocalEvents();

            dbHandler = null;

            frmLogin loginForm = new frmLogin();
            bool showLogin = loginForm.showLogin;

            if (showLogin)
            {
                Application.Run(loginForm);
            }
            else
            {
                loginForm.Login();
                Application.Run();
            }
        }
        public frmIssues(CloudService mezeoFileCloud, frmSyncManager manager)
        {
            InitializeComponent();
            syncmanager = manager;
            dbHandler = new DbHandler();
            ClearInfoLabels();

            cMezeoFileCloud = mezeoFileCloud;
        }
 /// <summary>
 /// Wrapper function to return a connection to the database.  This way if the database must
 /// be manipulated in some way and the connections reset, the code doesn't have to worry
 /// about the member variable only having been initialized in the constructor and crashing
 /// under certain conditions.
 /// </summary>
 /// <returns></returns>
 private static DbHandler GetDbHandler()
 {
     if (dbHandler == null)
     {
         dbHandler = new DbHandler();
         dbHandler.OpenConnection();
     }
     return dbHandler;
 }
 public OfflineWatcher(DbHandler dbHandler)
 {
     this.dbHandler = dbHandler;
 }
        public frmSyncManager(CloudService mezeoFileCloud, LoginDetails loginDetails, NotificationManager notificationManager)
        {
            InitializeComponent();

            cMezeoFileCloud = mezeoFileCloud;

            cMezeoFileCloud.fileCloud.downloadStoppedEvent += new MezeoFileCloud.FileDownloadStoppedEvent(cMezeoFileCloud_downloadStoppedEvent);

            cMezeoFileCloud.fileCloud.uploadStoppedEvent += new MezeoFileCloud.FileUploadStoppedEvent(cMezeoFileCloud_uploadStoppedEvent);

            cLoginDetails = loginDetails;
            cnotificationManager = notificationManager;

            LoadResources();

            watcher = new Watcher(BasicInfo.SyncDirPath);
            EventQueue.WatchCompletedEvent += new EventQueue.WatchCompleted(queue_WatchCompletedEvent);
            CheckForIllegalCrossThreadCalls = false;

            watcher.StartMonitor();
            dbHandler = new DbHandler();
            dbHandler.OpenConnection();

            frmIssuesFound = new frmIssues(mezeoFileCloud, this);
            offlineWatcher = new OfflineWatcher(dbHandler);

            myDelegate = new MezeoFileSupport.CallbackIncrementProgress(this.CallbackSyncProgress);
            ContinueRunningDelegate = new MezeoFileSupport.CallbackContinueRunning(this.CallbackContinueRun);
        }
        private bool PopulateNQEvents()
        {
            int newEvents = 0;
            int eventsToDelete = 0;
            int nStatusCode = 0;
            NQDetails[] pNQDetails = null;

            if (IsSyncPaused() || (cLoginDetails == null))
                return false;

            if (this.InvokeRequired)
            {
                this.Invoke((MethodInvoker)delegate
                {
                    this.lblStatusL1.Text = LanguageTranslator.GetValue("SyncManagerCheckingServer");
                    this.lblStatusL3.Text = "";
                    ShowNextSyncLabel(false);

                    lblStatusL1.Refresh();
                    lblStatusL3.Refresh();
                    label1.Refresh();
                });
            }
            else
            {
                this.lblStatusL1.Text = LanguageTranslator.GetValue("SyncManagerCheckingServer");
                this.lblStatusL3.Text = "";
                ShowNextSyncLabel(false);

                lblStatusL1.Refresh();
                lblStatusL3.Refresh();
                label1.Refresh();
            }

            NQLengthResult nqLengthRes = cMezeoFileCloud.NQGetLength(BasicInfo.ServiceUrl + cLoginDetails.szNQParentUri, BasicInfo.GetQueueName(), ref nStatusCode);
            if (nStatusCode == ResponseCode.LOGINFAILED1 || nStatusCode == ResponseCode.LOGINFAILED2)
            {
                this.Hide();
                frmParent.ShowLoginAgainFromSyncMgr();
                return false;
            }

            // Look to see if we are offline.  A negative value is a socket error such as
            // 'cannot connect to server (-1)' or 'cannot resolve address (-2)'.Z
            if (nStatusCode < 0)
            {
                SetCanNotTalkToServer(true);
                return false;
            }

            // If there is no dbHandler object for some reason, create one.
            if (null == dbHandler)
            {
                dbHandler = new DbHandler();
                dbHandler.OpenConnection();
            }

            // Grab some events from the notification queue if any exist.
            pNQDetails = cMezeoFileCloud.NQGetData(BasicInfo.ServiceUrl + cLoginDetails.szNQParentUri, BasicInfo.GetQueueName(), 10, ref nStatusCode);
            if (nStatusCode == ResponseCode.NQGETDATA)
            {
                if (pNQDetails != null)
                {
                    foreach (NQDetails nq in pNQDetails)
                    {
                        if (nq.StrObjectType != "UNSUPPORTED_TYPE")
                        {
                            // Populate the queue with any we got.
                            dbHandler.AddNQEvent(nq);
                            newEvents++;
                        }
                        eventsToDelete++;
                    }
                    cMezeoFileCloud.NQDeleteValue(BasicInfo.ServiceUrl + cLoginDetails.szNQParentUri, BasicInfo.GetQueueName(), eventsToDelete, ref nStatusCode);
                    messageMax = (int)dbHandler.GetJobCount();
                }
            }

            return (newEvents > 0);
        }
 private void LoginSuccessTask()
 {
     DbHandler dbHandler = new DbHandler();
       if (!bwCheckServerStatus.IsBusy)
         bwCheckServerStatus.RunWorkerAsync();
         //syncManager.EnableSyncManager();
       syncManager.SetCanNotTalkToServer(false);
         if (BasicInfo.IsInitialSync)
         {
             syncManager.InitializeSync();
         }
         else
         {
             syncManager.SetUpSync();
             syncManager.SetUpSyncNowNotification();
             if (dbHandler.GetInitialSyncEventCount() == 0)
                 syncManager.ProcessOfflineEvents();
             else if (dbHandler.GetInitialSyncEventCount() > 0)
                 syncManager.SyncNow();
         }
 }
        private void CheckAndCreateSyncDirectory()
        {
            DbHandler dbHandler = new DbHandler();
            bool isDbCreateNew = false;

            bool isDirectoryExists = false;
            if (BasicInfo.SyncDirPath.Trim().Length != 0)
                isDirectoryExists = System.IO.Directory.Exists(BasicInfo.SyncDirPath);
            string dirName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + AboutBox.AssemblyTitle;

            //Modified code to fixed issue # 1417 Checking first is directory exists or not
            if (!isDirectoryExists)
            {
                if (showLogin == false && !isDirectoryExists)
                {
                    DialogResult checkDir;

                    string message = LanguageTranslator.GetValue("ExpectedLocation") + Environment.NewLine + BasicInfo.SyncDirPath + ". " + Environment.NewLine + Environment.NewLine + LanguageTranslator.GetValue("FolderMoved") + Environment.NewLine + Environment.NewLine + LanguageTranslator.GetValue("ClickNoExit") + Environment.NewLine + Environment.NewLine + LanguageTranslator.GetValue("ClickYesRestore");
                    string caption = LanguageTranslator.GetValue("CaptionFileMissingDialog");

                    MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                    MessageBoxDefaultButton defaultbutton = MessageBoxDefaultButton.Button2;

                    checkDir = MessageBox.Show(message, caption,
                       buttons, MessageBoxIcon.None, defaultbutton);

                    if (checkDir == DialogResult.Yes)
                    {
                        System.IO.Directory.CreateDirectory(dirName);

                        //Adding Code to change folder icon
                        folderIcon(dirName);

                        BasicInfo.IsInitialSync = true;
                        BasicInfo.SyncDirPath = dirName;
                        dbHandler.DeleteDb();
                        dbHandler.CreatedNewDatabase();
                        dbHandler.OpenConnection();
                    }
                    else
                    {
                        System.Environment.Exit(0);
                    }
                }
                else
                {
                    isDbCreateNew = dbHandler.CreatedNewDatabase();
                    if (!isDirectoryExists)
                    {
                        System.IO.Directory.CreateDirectory(dirName);

                        //Adding Code to change folder icon
                        folderIcon(dirName);
                     }
                    BasicInfo.IsInitialSync = true;
                    // Always set the BasicInfo.SyncDirPath value.
                    BasicInfo.SyncDirPath = dirName;
                }
            }
            else
            {
                //if directory exits checking whether we have new database or not
                isDbCreateNew = dbHandler.CreatedNewDatabase();
                BasicInfo.AutoSync = true;
                BasicInfo.SyncDirPath = dirName;
            }

            System.IO.Directory.SetCurrentDirectory(BasicInfo.SyncDirPath);
        }