/// <summary>
        /// Creates an Backup instance which manages the backup process
        /// </summary>
        /// <param name="filename">The filename of the file the backup will be saved to</param>
        /// <param name="includeApk">Whether the associated apk file of an app should be saved</param>
        /// <param name="includeObb">Whether to backup the associated apk expansion file of the app</param>
        /// <param name="includeInternal">Whether to include sd card contents</param>
        /// <param name="backupAll">Whether to backup all applications</param>
        /// <param name="includeSystemApps">Whether to include system apps too</param>
        /// <param name="packages">Optionally the list of packages to backup (Note: backupAll has to be false)</param>
        /// <param name="interval">The interval in which to check for changes</param>
        /// <returns>An object handling the Backup process</returns>
        public Backup PrepareBackup(string filename, bool includeApk, bool includeObb, bool includeInternal, bool backupAll, bool includeSystemApps, List<string> packages = null, CheckInterval interval = CheckInterval.Middle)
        {
            //Build cmd string
            string command = "backup -f \"" + filename + "\" ";

            if (includeApk) command += "-apk ";
            else command += "-noapk ";

            if (includeObb) command += "-obb ";
            else command += "-noobb";

            if (includeInternal) command += "-shared ";
            else command += "-noshared ";

            if (backupAll) command += "-all ";

            if (includeSystemApps) command += "-system";
            else command += "-nosystem";

            if (packages != null && !backupAll)
            {
                foreach (string packagename in packages)
                {
                    command += " " + packagename;
                }
            }

            //Create object
            Backup backup = new Backup(command, mSerialNo, filename, (int) interval);

            return backup;
        }
Example #2
0
        private void Window_Closed(object sender, EventArgs e)
        {
            XmlConfigUtil util = new XmlConfigUtil("config.xml");

            util.Write(BattleNetPath, "BattleNetPath");
            util.Write(HearthbuddyPath, "HearthbuddyPath");
            util.Write(BNHSInterval.ToString(), "BNHSInterval");
            util.Write(HSHBInterval.ToString(), "HSHBInterval");
            util.Write(CheckInterval.ToString(), "CheckInterval");

            util.Write(StartTime.Hour.ToString(), "StartTime");
            util.Write(EndTime.Hour.ToString(), "EndTime");

            string logDirectory = Path.Combine(this.BaseDirectory, "Logs");

            if (!Directory.Exists(logDirectory)) //防止目录不存在报错
            {
                Directory.CreateDirectory(logDirectory);
            }
            string logPath = Path.Combine(logDirectory, $"HearthbuddyHelper_{DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss")}.log");

            using (StreamWriter sw = new StreamWriter(logPath, true, System.Text.Encoding.UTF8))
            {
                sw.Write(LogTextBox.Text);
            }

            Environment.Exit(0);
        }
Example #3
0
        public void SaveToXML(XmlDocument doc, IDTSInfoEvents infoEvents)
        {
            var data = doc.CreateElement("WaitForSignalData");

            data.SetAttribute("CheckInterval", CheckInterval.ToString());
            data.SetAttribute("SignalVariable", SignalVariable);
            doc.AppendChild(data);
        }
        /// <summary>
        /// Does the backup directly and blocks the thread until finish
        /// </summary>
        /// <param name="filename">The filename of the file the backup will be saved to</param>
        /// <param name="includeApk">Whether the associated apk file of an app should be saved</param>
        /// <param name="includeObb">Whether to backup the associated apk expansion file of the app</param>
        /// <param name="includeInternal">Whether to include sd card contents</param>
        /// <param name="backupAll">Whether to backup all applications</param>
        /// <param name="includeSystemApps">Whether to include system apps too</param>
        /// <param name="packages">Optionally the list of packages to backup (Note: backupAll has to be false)</param>
        /// <param name="interval">The interval in which to check for changes</param>
        public void DoBackup(string filename, bool includeApk, bool includeObb, bool includeInternal, bool backupAll, bool includeSystemApps, List<string> packages = null, CheckInterval interval = CheckInterval.Middle)
        {
            //Create instance of backup
            Backup backup = this.PrepareBackup(filename, includeApk, includeObb, includeObb, backupAll, includeSystemApps, packages, interval);

            //Block until it finished
            EventWaitHandle waiter = new ManualResetEvent(false);
            backup.OnBackupCompleted += ((object sender, Backup.OnBackupCompletedArgs Eventargs) => waiter.Set());
            backup.Start();
            waiter.WaitOne();
            backup.Dispose();
        }
Example #5
0
        /// <summary>
        /// Serializes the WaitForFile settings into XML
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="infoEvents"></param>
        void IDTSComponentPersist.SaveToXML(System.Xml.XmlDocument doc, IDTSInfoEvents infoEvents)
        {
            XmlElement data = doc.CreateElement("WaitForFilesData");

            doc.AppendChild(data);

            data.SetAttribute("checkType", CheckType.ToString());
            data.SetAttribute("existenceType", ExistenceType.ToString());
            data.SetAttribute("checkTimeoutInterval", CheckTimeoutInterval.ToString());
            data.SetAttribute("checkTimeoutTime", checkTimeoutTime.ToString());
            data.SetAttribute("checkInterval", CheckInterval.ToString());
            data.SetAttribute("timeoutNextDayIfTimePassed", TimeoutNextDayIfTimePassed.ToString());

            XmlElement filesNode = doc.CreateElement("checkFiles");

            data.AppendChild(filesNode);

            foreach (string file in files)
            {
                XmlElement fileNode = doc.CreateElement("file");
                fileNode.SetAttribute("name", file);
                filesNode.AppendChild(fileNode);
            }
        }
        /// <summary>
        /// This action is used to add a new External monitor. 
        /// </summary>
        /// <param name="type">type of the test</param>
        /// <param name="name">the name of the test</param>
        /// <param name="url">url of the test</param>
        /// <param name="interval">check interval(min)</param>
        /// <param name="tag">tag of the test</param>
        /// <param name="detailedTestType">specifies the request method. Used for HTTP and HTTPS. Default value is GET. </param>
        /// <param name="timeout">test timeout in ms. Default value is 10000</param>
        /// <param name="overSSL">if true, requests will be sent via SSL. Can be set for FTP, UDP, TCP, SMTP, IMAP, POP test types.</param>
        /// <param name="postData">data to send during POST request, e.g m_U=asd&m_P=asd</param>
        /// <param name="contentMatchFlag">set to true if there is string to match in response text otherwise false.</param>
        /// <param name="contentMatchString">text to match in the response</param>
        /// <param name="testParams">additional test parameters 
        /// TODO: http://monitis.com/api/api.html#addExternalMonitor - create type for MySQL and DNS?</param>
        /// <param name="uptimeSLA">min allowed uptime(%)</param>
        /// <param name="responseSLA">max allowed response time in seconds</param>
        /// <param name="basicAuthUser">userName for authentication</param>
        /// <param name="basicAuthPass">password for authentication</param>
        /// <param name="output">Output type - JSON or XML</param>
        /// <param name="validation">HMACSHA1 for checksum validation or token for authToken validation</param>
        /// <param name="locationIds">comma separated ids of the locations to add test for</param>
        /// <returns>Add ExternalMonitor Response</returns>
        public AddExternalMonitorResponse AddMonitor(
            TestType type,
            string name,
            string url,
            CheckInterval interval,
            string tag,
            int[] locationIds,
            DetailedTestType detailedTestType = DetailedTestType.GET,
            int timeout = 10000,
            bool? overSSL = null,
            string postData = null,
            bool? contentMatchFlag = null,
            string contentMatchString = null,
            Dictionary<string, string> testParams = null,
            int? uptimeSLA = null,
            int? responseSLA = null,
            string basicAuthUser = null,
            string basicAuthPass = null,
            OutputType? output = null,
            Validation? validation = null)
        {
            OutputType outputType = GetOutput(output);
            var parameters = new Dictionary<string, object>();
            parameters.Add(Params.name, name);
            parameters.Add(Params.tag, tag);
            parameters.Add(Params.locationIds, String.Join(",", locationIds));
            parameters.Add(Params.url, url);
            parameters.Add(Params.type, type);
            parameters.Add(Params.interval, (int) interval); /*minutes - int value*/
            AddIfNotNull(parameters, Params.contentMatchString, contentMatchString);
            AddIfNotNull(parameters, Params.contentMatchFlag, Helper.BoolToInt(contentMatchFlag));
            AddIfNotNull(parameters, Params.basicAuthUser, basicAuthUser);
            AddIfNotNull(parameters, Params.basicAuthPass, basicAuthPass);
            AddIfNotNull(parameters, Params.postData, postData);
            if (null != testParams && testParams.Count > 0)
            {
                string testParamsString = Helper.MapToURLString(testParams);
                AddIfNotNull(parameters, Params.@params, testParamsString);
            }
            parameters.Add(Params.detailedTestType, (int) detailedTestType);
            AddIfNotNull(parameters, Params.timeout, timeout);
            AddIfNotNull(parameters, Params.uptimeSLA, uptimeSLA);
            AddIfNotNull(parameters, Params.responseSLA, responseSLA);
            AddIfNotNull(parameters, Params.overSSL, Helper.BoolToInt(overSSL));

            RestResponse response = MakePostRequest(ExternalMonitorAction.addExternalMonitor, parameters,
                                                    output: outputType, validation: validation);
            Helper.CheckStatus(response, output: outputType);
            var addExternalMonitorResponse = new AddExternalMonitorResponse();

            //Fill information from response to struct
            Int32.TryParse(Helper.GetValueOfKey(response, Params.isTestNew, outputType),
                           out addExternalMonitorResponse.isTestNew);
            Int32.TryParse(Helper.GetValueOfKey(response, Params.testId, outputType),
                           out addExternalMonitorResponse.testId);
            DateTime.TryParse(Helper.GetValueOfKey(response, Params.startDate, outputType),
                              out addExternalMonitorResponse.startDate);
            return addExternalMonitorResponse;
        }
Example #7
0
        /// <summary>
        /// Creates an Backup instance which manages the backup process
        /// </summary>
        /// <param name="filename">The filename of the file the backup will be saved to</param>
        /// <param name="includeApk">Whether the associated apk file of an app should be saved</param>
        /// <param name="includeObb">Whether to backup the associated apk expansion file of the app</param>
        /// <param name="includeInternal">Whether to include sd card contents</param>
        /// <param name="backupAll">Whether to backup all applications</param>
        /// <param name="includeSystemApps">Whether to include system apps too</param>
        /// <param name="packages">Optionally the list of packages to backup (Note: backupAll has to be false)</param>
        /// <param name="interval">The interval in which to check for changes</param>
        /// <returns>An object handling the Backup process</returns>
        public Backup PrepareBackup(string filename, bool includeApk, bool includeObb, bool includeInternal, bool backupAll, bool includeSystemApps, List <string> packages = null, CheckInterval interval = CheckInterval.Middle)
        {
            //Build cmd string
            string command = "backup -f \"" + filename + "\" ";

            if (includeApk)
            {
                command += "-apk ";
            }
            else
            {
                command += "-noapk ";
            }

            if (includeObb)
            {
                command += "-obb ";
            }
            else
            {
                command += "-noobb";
            }

            if (includeInternal)
            {
                command += "-shared ";
            }
            else
            {
                command += "-noshared ";
            }

            if (backupAll)
            {
                command += "-all ";
            }

            if (includeSystemApps)
            {
                command += "-system";
            }
            else
            {
                command += "-nosystem";
            }

            if (packages != null && !backupAll)
            {
                foreach (string packagename in packages)
                {
                    command += " " + packagename;
                }
            }

            //Create object
            Backup backup = new Backup(command, mSerialNo, filename, (int)interval);

            return(backup);
        }
Example #8
0
        /// <summary>
        /// Does the backup directly and blocks the thread until finish
        /// </summary>
        /// <param name="filename">The filename of the file the backup will be saved to</param>
        /// <param name="includeApk">Whether the associated apk file of an app should be saved</param>
        /// <param name="includeObb">Whether to backup the associated apk expansion file of the app</param>
        /// <param name="includeInternal">Whether to include sd card contents</param>
        /// <param name="backupAll">Whether to backup all applications</param>
        /// <param name="includeSystemApps">Whether to include system apps too</param>
        /// <param name="packages">Optionally the list of packages to backup (Note: backupAll has to be false)</param>
        /// <param name="interval">The interval in which to check for changes</param>
        public void DoBackup(string filename, bool includeApk, bool includeObb, bool includeInternal, bool backupAll, bool includeSystemApps, List <string> packages = null, CheckInterval interval = CheckInterval.Middle)
        {
            //Create instance of backup
            Backup backup = this.PrepareBackup(filename, includeApk, includeObb, includeObb, backupAll, includeSystemApps, packages, interval);

            //Block until it finished
            EventWaitHandle waiter = new ManualResetEvent(false);

            backup.OnBackupCompleted += ((object sender, Backup.OnBackupCompletedArgs Eventargs) => waiter.Set());
            backup.Start();
            waiter.WaitOne();
            backup.Dispose();
        }
Example #9
0
        /// <summary>
        /// This action is used to add a new External monitor.
        /// </summary>
        /// <param name="type">type of the test</param>
        /// <param name="name">the name of the test</param>
        /// <param name="url">url of the test</param>
        /// <param name="interval">check interval(min)</param>
        /// <param name="tag">tag of the test</param>
        /// <param name="detailedTestType">specifies the request method. Used for HTTP and HTTPS. Default value is GET. </param>
        /// <param name="timeout">test timeout in ms. Default value is 10000</param>
        /// <param name="overSSL">if true, requests will be sent via SSL. Can be set for FTP, UDP, TCP, SMTP, IMAP, POP test types.</param>
        /// <param name="postData">data to send during POST request, e.g m_U=asd&m_P=asd</param>
        /// <param name="contentMatchFlag">set to true if there is string to match in response text otherwise false.</param>
        /// <param name="contentMatchString">text to match in the response</param>
        /// <param name="testParams">additional test parameters
        /// TODO: http://monitis.com/api/api.html#addExternalMonitor - create type for MySQL and DNS?</param>
        /// <param name="uptimeSLA">min allowed uptime(%)</param>
        /// <param name="responseSLA">max allowed response time in seconds</param>
        /// <param name="basicAuthUser">userName for authentication</param>
        /// <param name="basicAuthPass">password for authentication</param>
        /// <param name="output">Output type - JSON or XML</param>
        /// <param name="validation">HMACSHA1 for checksum validation or token for authToken validation</param>
        /// <param name="locationIds">comma separated ids of the locations to add test for</param>
        /// <returns>Add ExternalMonitor Response</returns>
        public AddExternalMonitorResponse AddMonitor(
            TestType type,
            string name,
            string url,
            CheckInterval interval,
            string tag,
            int[] locationIds,
            DetailedTestType detailedTestType = DetailedTestType.GET,
            int timeout               = 10000,
            bool?overSSL              = null,
            string postData           = null,
            bool?contentMatchFlag     = null,
            string contentMatchString = null,
            Dictionary <string, string> testParams = null,
            int?uptimeSLA         = null,
            int?responseSLA       = null,
            string basicAuthUser  = null,
            string basicAuthPass  = null,
            OutputType?output     = null,
            Validation?validation = null)
        {
            OutputType outputType = GetOutput(output);
            var        parameters = new Dictionary <string, object>();

            parameters.Add(Params.name, name);
            parameters.Add(Params.tag, tag);
            parameters.Add(Params.locationIds, String.Join(",", locationIds));
            parameters.Add(Params.url, url);
            parameters.Add(Params.type, type);
            parameters.Add(Params.interval, (int)interval);  /*minutes - int value*/
            AddIfNotNull(parameters, Params.contentMatchString, contentMatchString);
            AddIfNotNull(parameters, Params.contentMatchFlag, Helper.BoolToInt(contentMatchFlag));
            AddIfNotNull(parameters, Params.basicAuthUser, basicAuthUser);
            AddIfNotNull(parameters, Params.basicAuthPass, basicAuthPass);
            AddIfNotNull(parameters, Params.postData, postData);
            if (null != testParams && testParams.Count > 0)
            {
                string testParamsString = Helper.MapToURLString(testParams);
                AddIfNotNull(parameters, Params.@params, testParamsString);
            }
            parameters.Add(Params.detailedTestType, (int)detailedTestType);
            AddIfNotNull(parameters, Params.timeout, timeout);
            AddIfNotNull(parameters, Params.uptimeSLA, uptimeSLA);
            AddIfNotNull(parameters, Params.responseSLA, responseSLA);
            AddIfNotNull(parameters, Params.overSSL, Helper.BoolToInt(overSSL));

            RestResponse response = MakePostRequest(ExternalMonitorAction.addExternalMonitor, parameters,
                                                    output: outputType, validation: validation);

            Helper.CheckStatus(response, output: outputType);
            var addExternalMonitorResponse = new AddExternalMonitorResponse();

            //Fill information from response to struct
            Int32.TryParse(Helper.GetValueOfKey(response, Params.isTestNew, outputType),
                           out addExternalMonitorResponse.isTestNew);
            Int32.TryParse(Helper.GetValueOfKey(response, Params.testId, outputType),
                           out addExternalMonitorResponse.testId);
            DateTime.TryParse(Helper.GetValueOfKey(response, Params.startDate, outputType),
                              out addExternalMonitorResponse.startDate);
            return(addExternalMonitorResponse);
        }
        public XmlDocument ExportConfigurationToXml()
        {
            string xemailNS = "http://www.siprod.net/namespaces/XEMail/ClientConfig";
            string emptyNS  = string.Empty;

            XmlDocument doc  = new XmlDocument();
            XmlNode     root = doc.CreateNode(XmlNodeType.Element, "XEMailClientConfig", xemailNS);

            doc.AppendChild(root);

            XmlNode clientNode = doc.CreateNode(XmlNodeType.Element, "ClientConfig", xemailNS);

            root.AppendChild(clientNode);
            GenerateChildNode(clientNode, xemailNS, "AutoCheckEnabled", AutoCheckEnabled.ToString(), ref doc);
            GenerateChildNode(clientNode, xemailNS, "CheckInterval", CheckInterval.ToString(), ref doc);
            GenerateChildNode(clientNode, xemailNS, "WebserviceUrl", WebserviceUrl, ref doc);

            XmlNode netProxyNode = doc.CreateNode(XmlNodeType.Element, "NetworkProxy", xemailNS);

            clientNode.AppendChild(netProxyNode);
            GenerateChildNode(netProxyNode, xemailNS, "Enabled", networkProxy.Enabled.ToString(), ref doc);
            GenerateChildNode(netProxyNode, xemailNS, "Url", networkProxy.Url, ref doc);
            GenerateChildNode(netProxyNode, xemailNS, "Port", networkProxy.Port.ToString(), ref doc);
            GenerateChildNode(netProxyNode, xemailNS, "User", networkProxy.User, ref doc);
            GenerateChildNode(netProxyNode, xemailNS, "Password", EncryptedDataHelper.ConvertToNumbersString(MachineBasedRijndaelEncryptor.Encrypt(networkProxy.Password)), ref doc);
            GenerateChildNode(netProxyNode, xemailNS, "Domain", networkProxy.Domain, ref doc);

            XmlNode accountsNode = doc.CreateNode(XmlNodeType.Element, "Accounts", xemailNS);

            clientNode.AppendChild(accountsNode);
            XmlNode accountNode;

            foreach (string key in accounts.Keys)
            {
                XEMailAccount account = accounts[key];
                accountNode = doc.CreateNode(XmlNodeType.Element, "Account", xemailNS);

                GenerateChildNode(accountNode, xemailNS, "AccountName", account.AccountName, ref doc);
                GenerateChildNode(accountNode, xemailNS, "UseSameCredentials", account.UseSameCredentialsToSend.ToString(), ref doc);

                XmlNode incomingServerNode = doc.CreateNode(XmlNodeType.Element, "IncomingServer", xemailNS);
                accountNode.AppendChild(incomingServerNode);
                GenerateChildNode(incomingServerNode, xemailNS, "ServerEnabled", account.IncomingServer.ServerEnabled.ToString(), ref doc);
                GenerateChildNode(incomingServerNode, xemailNS, "ServerProtocol", account.IncomingServer.ServerProtocol.ToString(), ref doc);
                GenerateChildNode(incomingServerNode, xemailNS, "ServerName", account.IncomingServer.ServerName, ref doc);
                GenerateChildNode(incomingServerNode, xemailNS, "ServerPort", account.IncomingServer.ServerPort.ToString(), ref doc);
                GenerateChildNode(incomingServerNode, xemailNS, "UserName", account.IncomingServer.Username, ref doc);
                GenerateChildNode(incomingServerNode, xemailNS, "UserPassword", EncryptedDataHelper.ConvertToNumbersString(MachineBasedRijndaelEncryptor.Encrypt(account.IncomingServer.UserPassword)), ref doc);
                GenerateChildNode(incomingServerNode, xemailNS, "SslEnabled", account.IncomingServer.SslEnabled.ToString(), ref doc);

                XmlNode outgoingServerNode = doc.CreateNode(XmlNodeType.Element, "OutgoingServer", xemailNS);
                accountNode.AppendChild(outgoingServerNode);
                GenerateChildNode(outgoingServerNode, xemailNS, "ServerEnabled", account.OutgoingServer.ServerEnabled.ToString(), ref doc);
                GenerateChildNode(outgoingServerNode, xemailNS, "ServerProtocol", account.OutgoingServer.ServerProtocol.ToString(), ref doc);
                GenerateChildNode(outgoingServerNode, xemailNS, "ServerName", account.OutgoingServer.ServerName, ref doc);
                GenerateChildNode(outgoingServerNode, xemailNS, "ServerPort", account.OutgoingServer.ServerPort.ToString(), ref doc);
                GenerateChildNode(outgoingServerNode, xemailNS, "UserName", account.OutgoingServer.Username, ref doc);
                GenerateChildNode(outgoingServerNode, xemailNS, "UserPassword", EncryptedDataHelper.ConvertToNumbersString(MachineBasedRijndaelEncryptor.Encrypt(account.OutgoingServer.UserPassword)), ref doc);
                GenerateChildNode(outgoingServerNode, xemailNS, "SslEnabled", account.OutgoingServer.SslEnabled.ToString(), ref doc);

                accountsNode.AppendChild(accountNode);
            }

            clientNode.AppendChild(accountsNode);

            return(doc);
        }