Ejemplo n.º 1
0
 public void StartUpdating()
 {
     if (m_configDTO == null)
     {
         if (m_onError != null)
         {
             m_onError.Invoke(new Exception("Init config file error!"));
         }
     }
     else
     {
         foreach (var obj in m_configDTO.OfficeHelperConfig)
         {
             ConfigUpdaterConfigDTO dto  = obj as ConfigUpdaterConfigDTO;
             UpdateTask             task = new UpdateTask(dto);
             task.UpdateFinished += (isSuccess) =>
             {
                 if (this.m_onTaskFinished != null)
                 {
                     m_onTaskFinished.Invoke(task.Name, isSuccess);
                 }
             };
             task.OnError += (e) =>
             {
                 if (this.m_onError != null)
                 {
                     m_onError.Invoke(e);
                 }
             };
             task.Invoke();
         }
     }
 }
Ejemplo n.º 2
0
 public UpdateTask(ConfigUpdaterConfigDTO updateConfig, Encoding configEncoding) : this(updateConfig)
 {
     if (configEncoding != null)
     {
         this.ConfigEncoding = configEncoding;
     }
     else
     {
         m_onError.Invoke(new Exception("ConfigEncoding can not be empty!"));
     }
 }
Ejemplo n.º 3
0
        public UpdateTask(ConfigUpdaterConfigDTO updateConfig)
        {
            if (updateConfig != null)
            {
                if (File.Exists(updateConfig.ConfigFilePath))
                {
                    this.Name = updateConfig.Name;
                    this.MatchingText = updateConfig.MatchingText;
                    this.MatchingRegex = updateConfig.MatchingRegex;
                    this.ConfigFilePath = updateConfig.ConfigFilePath;
                    this.ReplaceText = updateConfig.ReplaceText;
                    this.ReplaceJavaScriptContent = updateConfig.ReplaceJavaScriptContent;
                    this.RestartProcessName = updateConfig.RestartProcessName;
                    this.RestartServiceName = updateConfig.RestartServiceName;
                    if (string.IsNullOrWhiteSpace(MatchingRegex) && string.IsNullOrWhiteSpace(MatchingText))
                    {
                        if (m_onError != null)
                        {
                            m_onError.Invoke(new Exception("Can not matching condition!"));
                        }
                    }
                    if (string.IsNullOrWhiteSpace(ReplaceText) && string.IsNullOrWhiteSpace(ReplaceJavaScriptContent))
                    {
                        if (m_onError != null)
                        {
                            m_onError.Invoke(new Exception("Can not replace condition!"));
                        }
                    }
                }
                else
                {
                    if (m_onError != null)
                    {
                        m_onError.Invoke(new Exception($"Can not find file({this.ConfigFilePath})!"));
                    }
                }
            }
            else
            {
                m_onError.Invoke(new Exception("UpdateConfig can not be empty!"));
            }

        }