Esempio n. 1
0
        public void loadProfile(string profileName)
        {
            try
            {
                _currProfile = _settings.SyncProfiles.Profiles.Single(p => p.SyncProfileName == profileName);

                _storage = new SyncStorage(_currProfile.StorageConnectionString, _currProfile.StorageContainerName, _currProfile.UIPath);
                if (_storage.ErrorMessage != null)
                {
                    MessageBox.Show("The selected profile wasn't loaded due to an error initializing storage. Please check the profile and confirm your connection string.\n\rDetails: " + _storage.ErrorMessage, "Storage Profile Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                _storage.FileActivityMessage += FileActivityMessageAsync;

                txtUIFolder.Text     = (_currProfile.SyncStorageBool) ? _currProfile.UIPath : "N/A";
                txtPolicyFolder.Text = (_currProfile.SyncPolicyBool) ? _currProfile.PolicyPath : "N/A";
                btnStart.Enabled     = true;
            }
            catch (Exception ex)
            {
                btnStart.Enabled = false;
                Logging.WriteToAppLog(ex.Message, EventLogEntryType.Error, ex);
                MessageBox.Show("An error occured trying to initialize the storage profile. Please check the connection string for the storage account of the selected profile.", "Error Connecting", MessageBoxButtons.OK);
            }
        }
Esempio n. 2
0
        private async void PolicyWatcher_Changed(object sender, FileSystemEventArgs e)
        {
            if (_inQueue.Contains(e.FullPath))
            {
                return;
            }

            _inQueue.Add(e.FullPath, null);

            FileAttributes file = File.GetAttributes(e.FullPath);

            if (file.HasFlag(FileAttributes.Directory))
            {
                _inQueue.Remove(e.FullPath);
                return;
            }

            await Task.Factory.StartNew(async() =>
            {
                try
                {
                    var fileStream = SyncStorage.OpenShared(e.FullPath);
                    string content;
                    using (StreamReader reader = new StreamReader(fileStream))
                    {
                        content = reader.ReadToEnd();
                    }

                    var doc = new XmlDocument();

                    doc.LoadXml(content);
                    var id = doc.SelectSingleNode("/*/@PolicyId").Value;
                    _policy.RefreshToken(_auth.Token);
                    string res = null;
                    res        = await _policy.UpsertAsync(id, content);
                    File.SetAttributes(e.FullPath, FileAttributes.Normal);
                }
                catch (XmlException ex)
                {
                    Logging.WriteToAppLog("Error parsing XML while uploading policy", EventLogEntryType.Error, ex);
                    var msg = String.Format("An error occured parsing your XML policy update: {0}. Additional details may be availabe in the Windows event log for details.", ex.Message);
                    if (_settings.ShowMessageBoxOnError)
                    {
                        MessageBox.Show(msg, "Error Parsing XML", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception ex)
                {
                    Logging.WriteToAppLog("Error uploading policy", EventLogEntryType.Error, ex);
                    if (_settings.ShowMessageBoxOnError)
                    {
                        MessageBox.Show("Something went wrong while uploading your policy update. Please check the Windows event log for details.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                finally
                {
                    _inQueue.Remove(e.FullPath);
                }
            }, TaskCreationOptions.LongRunning);
        }
Esempio n. 3
0
        private static void Connect()
        {
            if (_settings.Hostname == null)
            {
                Console.Write("Enter Hostname: ");
                _settings.Hostname = Console.ReadLine();
            }

            if (_settings.Username == null)
            {
                Console.Write("Enter Username: "******"Enter Password: "******"Connection established!");
            }
        }
Esempio n. 4
0
 private void Application_ApplicationExit(object sender, EventArgs e)
 {
     try
     {
         _storage = null;
         _logger.Dispose();
         _logger = null;
     }
     catch { }
 }
 protected ComplexSyncTest()
 {
     storage = new SyncStorage();
     storage.Clear().Wait();
 }
Esempio n. 6
0
        private static bool ParseSync(string[] args)
        {
            if (args.Contains("connect"))
            {
                _settings = new SyncSettings();

                if (!args.Contains("-n"))
                {
                    SyncStorage.LoadSettings(_settings);
                }

                Connect();

                return(true);
            }

            if (_sync != null && _sync.IsConnected)
            {
                if (args.Contains("disconnect"))
                {
                    Disconnect();

                    Log("Session disconnected!");

                    return(true);
                }

                if (args.Contains("execute") | args.Contains("exec") | args.Contains("->"))
                {
                    return(ParseArguments(args, (x) =>
                    {
                        var result = _sync.Execute(x);

                        Log(string.Format(result.IsSuccess ? string.Format("({0}>\"{1}\")", _settings.Hostname, (result.Output != null ? result.Output : ""))
                            : "Execution Failed: \"{0}\"", result.ErrorOutput), result.IsSuccess ? SyncLog.LogType.Info : SyncLog.LogType.Error);
                    }));
                }

                if (args.Contains("sync"))
                {
                    return(ParseArguments(args, (x) =>
                    {
                        if (x.Length == 3)
                        {
                            WinSCP.SynchronizationResult result = null;

                            if (x.Contains("--local"))
                            {
                                result = _sync.Synchronize(WinSCP.SynchronizationMode.Local, x[1], x[2], x.Length == 4 ? x[3] : "");
                            }

                            if (x.Contains("--remote"))
                            {
                            }

                            if (x.Contains("--both"))
                            {
                            }


                            PrintResults(result);
                        }
                        else
                        {
                            Log("Command: \"sync -l\" has missing parameters!", SyncLog.LogType.Error);
                        }
                    }));
                }
            }

            return(false);
        }