Exemplo n.º 1
0
        private void SchedulePropertyToXml(string filePath, PropertiesSystem prop)
        {
            try
            {
                XElement scheduleXml = new XElement("Properties");
                try
                {
                    XElement sysXml = new XElement("System");
                    sysXml.Add(new XElement("UpdateEnable", prop.UpdateEnable ? "1" : "0"));
                    sysXml.Add(new XElement("UpdateDrvieType", prop.UpdateDrvieType.ToString()));
                    sysXml.Add(new XElement("UpdateFtpUri", prop.UpdateFtpUri));
                    sysXml.Add(new XElement("UpdateFtpUser", prop.UpdateFtpUser));
                    sysXml.Add(new XElement("UpdateFtpPw", prop.UpdateFtpPw));
                    sysXml.Add(new XElement("UpdateDiskUri", prop.UpdateDiskUri));

                    scheduleXml.Add(sysXml);
                }
                catch (Exception ex)
                {
                    SystemLog.Output(SystemLog.MSG_TYPE.Err, "Property Setting", "Save: {0}", ex.Message);
                }

                XDocument doc = new XDocument(new XDeclaration("1.0", "UTF-8", null), scheduleXml);
                doc.Save(filePath);
            }
            catch (Exception ex)
            {
                SystemLog.Output(SystemLog.MSG_TYPE.Err, "Property Setting", "Save: {0}", ex.Message);
            }
        }
Exemplo n.º 2
0
        public void Load()
        {
            string dirPath  = AppDomain.CurrentDomain.BaseDirectory + "Config";
            string fileName = dirPath + "\\RCloudProperty.xml";

            System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileName);
            if (fileInfo.Exists)
            {
                m_properties = XmlToScheduleProperty(fileName);
            }
        }
Exemplo n.º 3
0
        public PropertiesSetting()
        {
            string dirPath = AppDomain.CurrentDomain.BaseDirectory + "Config";

            System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(dirPath);
            if (dir.Exists == false)
            {
                dir.Create();
            }
            string fileName = dirPath + "\\RCloudProperty.xml";

            System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileName);
            if (fileInfo.Exists)
            {
                m_properties = XmlToScheduleProperty(fileName);
            }
        }
Exemplo n.º 4
0
        private PropertiesSystem XmlToScheduleProperty(string filePath)
        {
            PropertiesSystem property = new PropertiesSystem();

            try
            {
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(filePath);
                XmlElement  element = xmldoc.DocumentElement;
                XmlNodeList nodes   = element.ChildNodes;
                foreach (XmlNode node in nodes)
                {
                    try
                    {
                        if (node.Name != "System")
                        {
                            continue;
                        }

                        if (node.SelectSingleNode("UpdateEnable") != null)
                        {
                            property.UpdateEnable = node["UpdateEnable"].InnerText == "1" ? true : false;
                        }

                        if (node.SelectSingleNode("UpdateDrvieType") != null)
                        {
                            if (node["UpdateDrvieType"].InnerText == DriveType.FTP.ToString())
                            {
                                property.UpdateDrvieType = DriveType.FTP;
                            }
                            else// if (str == DriveType.Disk.ToString())
                            {
                                property.UpdateDrvieType = DriveType.Disk;
                            }
                        }
                        if (node.SelectSingleNode("UpdateFtpUri") != null)
                        {
                            property.UpdateFtpUri = node["UpdateFtpUri"].InnerText;
                        }
                        if (node.SelectSingleNode("UpdateFtpUser") != null)
                        {
                            property.UpdateFtpUser = node["UpdateFtpUser"].InnerText;
                        }
                        if (node.SelectSingleNode("UpdateFtpPw") != null)
                        {
                            property.UpdateFtpPw = node["UpdateFtpPw"].InnerText;
                        }
                        if (node.SelectSingleNode("UpdateDiskUri") != null)
                        {
                            property.UpdateDiskUri = node["UpdateDiskUri"].InnerText;
                        }
                    }
                    catch (Exception ex)
                    {
                        SystemLog.Output(SystemLog.MSG_TYPE.Err, "Property Setting", "Load: {0}", ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                SystemLog.Output(SystemLog.MSG_TYPE.Err, "Property Setting", "Load: {0}", ex.Message);
            }
            return(property);
        }
Exemplo n.º 5
0
        private void OnReceiveUpdateMe(EventBroker.EventID id, EventBroker.EventParam param)
        {
            if (param == null || m_disableProgramUpdate)
            {
                return;
            }
            try
            {
                PropertiesSystem prop = PropertiesSetting.DefaultSetting.Property;
                if (prop == null)
                {
                    SystemLog.Output(SystemLog.MSG_TYPE.Err, "RCloud Auto update", "ProperiesSystem null");
                    return;
                }
                if (prop.UpdateEnable)
                {
                    IFileService server = null;
                    try
                    {
                        if (prop.UpdateDrvieType == DriveType.FTP)
                        {
                            server = new ServiceFtp(prop.UpdateFtpUser, prop.UpdateFtpPw, 5000, prop.UpdateFtpUri);
                        }
                        else
                        {
                            server = new ServiceDisk(prop.UpdateDiskUri);
                        }
                    }
                    catch (Exception ex)
                    {
                        SystemLog.Output(SystemLog.MSG_TYPE.Err, "RCloud Auto update", "Connection Server fail, " + ex.Message);
                        return;
                    }
                    List <FileInfo> info = null;
                    try
                    {
                        info = server.GetFileList(null, "zip");
                        if (info == null)
                        {
                            return;
                        }
                    }
                    catch (Exception ex)
                    {
                        SystemLog.Output(SystemLog.MSG_TYPE.Err, "RCloud Auto update", "Get File List fail, " + ex.Message);
                        return;
                    }
                    try
                    {
                        foreach (FileInfo fo in info)
                        {
                            string str = fo.Name.ToUpper();
                            if (fo.Name == null)
                            {
                                continue;
                            }
                            if (str.IndexOf("RCLOUD ") == 0)
                            {
                                string[] strArray = str.Split(' ');
                                if (strArray.Length == 2)
                                {
                                    string[] verArray = strArray[1].Split('.');
                                    if (verArray.Length == 3)
                                    {
                                        try
                                        {
                                            int     major = Convert.ToInt32(verArray[0]);
                                            int     minor = Convert.ToInt32(verArray[1]);
                                            int     build = Convert.ToInt32(verArray[2]);
                                            Version ver   = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
                                            if (major != ver.Major || minor != ver.Minor || build != ver.Build)
                                            {
                                                string currentPath = AppDomain.CurrentDomain.BaseDirectory;
                                                SystemLog.Output(SystemLog.MSG_TYPE.Nor, "RCloud Auto update", "Update Start");
                                                int indexRemove = currentPath.LastIndexOf(@"\");
                                                if (indexRemove > 1 && (indexRemove + 1) >= currentPath.Length)
                                                {
                                                    currentPath = currentPath.Substring(0, indexRemove);
                                                }

                                                string tempPath = currentPath + "\\UpdateTemp";
                                                if (UpdateMeDownload(server, fo, tempPath) == true)
                                                {
                                                    UpdateMeFileChange(currentPath, tempPath);
                                                }
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            SystemLog.Output(SystemLog.MSG_TYPE.Err, "RCloud Auto update", "file update check fail, " + ex.Message);
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                    }catch (Exception ex)
                    {
                        SystemLog.Output(SystemLog.MSG_TYPE.Err, "RCloud Auto update", "iterator, " + ex.Message);
                    }
                }
            }catch (Exception ex)
            {
                SystemLog.Output(SystemLog.MSG_TYPE.Err, "RCloud Auto update", "Error, " + ex.Message);
            }
        }