def submit_payload(self, process):
        o = self.operation
        
        if o == 'new_metadata':
            # unique payload parameters
            payload = {
                'project_name'                  : self.project_name,
                'api_name'                      : self.params.get('metadata_name', None),
                'metadata_type'                 : self.params.get('metadata_type', None),
                'apex_trigger_object_api_name'  : self.params.get('object_api_name', None),
                'apex_class_type'               : self.params.get('apex_class_type', None),
                'github_template'               : self.params.get('github_template', None)
            }
            workspace = util.get_project_settings().get("workspace")
            if workspace != None:
                payload['workspace'] = util.get_project_settings().get("workspace")
            else:
                payload['workspace'] = os.path.dirname(util.mm_project_directory())
        else:
            payload = {}
            
            if o != 'new_project' and o != 'new_project_from_existing_directory':
                payload['project_name'] = self.project_name
                workspace = util.get_project_settings().get("workspace")
                if workspace != None:
                    payload['workspace'] = util.get_project_settings().get("workspace")
                else:
                    payload['workspace'] = os.path.dirname(util.mm_project_directory())
        
            #open type
            if o == 'open_sfdc_url':
                payload['type'] = self.params.get('type', 'edit')
            
            if o == 'run_apex_script':
                payload['script_name'] = self.params.get('script_name', None)
                payload['return_log'] = False

            ##catch all
            if self.params != None:
                for key in self.params:
                    if key not in payload:
                        payload[key] = self.params[key]
                
        #debug('>>>>>> ',payload)    

        if type(payload) is dict:
            payload = json.dumps(payload)  
        debug(payload)  
        try:
            process.stdin.write(payload)
        except:
            process.stdin.write(payload.encode('utf-8'))
        process.stdin.close()
    def run(self):
        if self.use_mm_panel:
            if sys.version_info >= (3, 0):
                self.calculate_process_region()
            PanelThreadProgress(self)

        #last_thread = ThreadTracker.get_last_added(self.window)
        ThreadTracker.add(self)

        port_number = self.settings.get('mm_app_server_port', '56248')
        ####### ---> new
        if util.is_mm_project() and self.operation != 'new-project' and self.operation != 'open-settings':
            url = 'http://localhost:'+str(port_number)+'/execute?command='+self.operation+'&async=1&pid='+util.get_project_settings()['id']
        else:
            url = 'http://localhost:'+str(port_number)+'/execute?command='+self.operation+'&async=1'
        debug(url)

        try:
            if self.body != None:
                body = json.dumps(self.body).encode('utf8')
                debug('posting to MavensMate:')
                debug(body)
                req = urllib.request.Request(url, data=body, headers={'Content-Type': 'application/json', 'MavensMate-Editor-Agent': 'sublime'})
                response = urllib.request.urlopen(req)
            else:
                response = urllib.request.urlopen(url)

            debug('response from MavensMate')
            debug(response)

            mm_response = json.loads(response.read().decode('utf-8'))

            request_id = mm_response['id']
            status = mm_response['status']
            result = None
            while status == 'pending':
                url = 'http://localhost:'+str(port_number)+'/status?id='+request_id
                # url = 'http://localhost:'+str(port_number)+'/execute/'+request_id # this is the new call, but we don't need to use it for a while (until users are fully migrated to 0.0.11+)
                req = urllib.request.Request(url, headers={'MavensMate-Editor-Agent': 'sublime'})

                response = urllib.request.urlopen(url)
                response_body = response.read().decode('utf-8')
                status_response = json.loads(response_body)
                if 'status' in status_response and status_response['status'] == 'pending':
                    time.sleep(0.5)
                else:
                    result = status_response
                    status = 'done'

        except urllib.error.HTTPError as e:
            debug('urllib.error.HTTPError')
            result = e.read().decode('utf-8')
            debug(result)
            result = str(result)
            response_body = { 'error': 'Request to the local MavensMate server failed. '+str(result) }
            status = 'done'
        except urllib.error.URLError as e:
            debug('urllib.error.URLError')
            result = 'Error contacting local MavensMate server: '+str(e)
            response_body = { 'error': 'Request to the local MavensMate server failed, please ensure MavensMate Desktop is installed and running. For more information, please visit https://github.com/joeferraro/MavensMate/tree/master/docs' }
            status = 'done'
        except Exception as e:
            debug('Exception')
            result = 'Error contacting local MavensMate server: '+str(e)
            response_body = { 'error': 'Request to the local MavensMate server failed. '+str(e) }
            status = 'done'


        debug(result)
        self.result = response_body

        self.calculate_process_region()

        ThreadTracker.remove(self)
    def submit_payload(self, process):
        o = self.operation
        
        if o == 'new_metadata':
            # unique payload parameters
            payload = {
                'project_name'                  : self.project_name,
                'api_name'                      : self.params.get('metadata_name', None),
                'metadata_type'                 : self.params.get('metadata_type', None),
                'apex_trigger_object_api_name'  : self.params.get('object_api_name', None),
                'apex_class_type'               : self.params.get('apex_class_type', None),
                'github_template'               : self.params.get('github_template', None)
            }
            workspace = util.get_project_settings().get("workspace")
            if workspace != None:
                payload['workspace'] = util.get_project_settings().get("workspace")
            else:
                payload['workspace'] = os.path.dirname(util.mm_project_directory())
        elif o == 'new_project_from_existing_directory':
            # no project name
            payload = self.params
        else:

            params = {
                'selected': [
                    'unit_test',
                    'deploy'
                ],
                'files': [
                    'compile',
                    'synchronize',
                    'refresh',
                    'refresh_properties',
                    'open_sfdc_url',
                    'delete'
                ],
                'directories': [
                    'refresh',
                    'synchronize',
                    'refresh_properties'
                ],
                'type': [
                    'open_sfdc_url'
                ]
            }

            # common parameters
            if o == 'new_apex_overlay' or o == 'delete_apex_overlay':
                payload = self.params
            else:
                payload = {}

            if o != 'new_project' and o != 'new_project_from_existing_directory':
                payload['project_name'] = self.project_name
                workspace = util.get_project_settings().get("workspace")
                if workspace != None:
                    payload['workspace'] = util.get_project_settings().get("workspace")
                else:
                    payload['workspace'] = os.path.dirname(util.mm_project_directory())

            #selected files
            if o in params['files']:
                payload['files'] = self.params.get('files', [])
            #directories
            if o in params['directories']: 
                payload['directories'] = self.params.get('directories', [])
            #selected metadata
            if o in params['selected']:
                if self.params != None:
                    payload['selected'] = self.params.get('selected', [])
            #open type
            if o in params['type']:
                payload['type'] = self.params.get('type', 'edit')
            
            if self.params != None and 'action' in self.params:
                payload['action'] = self.params.get('action', None)

            if self.params != None and 'metadata_types' in self.params:
                payload['metadata_types'] = self.params.get('metadata_types', None)

            if self.params != None and 'classes' in self.params:
                payload['classes'] = self.params.get('classes', None)

            if o == 'run_apex_script':
                payload['script_name'] = self.params.get('script_name', None)
                payload['return_log'] = False

        #print('>>>>>> ',payload)    

        if type(payload) is dict:
            payload = json.dumps(payload)  
        print(payload)  
        try:
            process.stdin.write(payload)
        except:
            process.stdin.write(payload.encode('utf-8'))
        process.stdin.close()
    def run(self):
        if self.use_mm_panel:
            if sys.version_info >= (3, 0):
                self.calculate_process_region()
            PanelThreadProgress(self)

        #last_thread = ThreadTracker.get_last_added(self.window)
        ThreadTracker.add(self)

        port_number = self.settings.get('mm_app_server_port', '56248')
        ####### ---> new
        if util.is_mm_project():
            url = 'http://localhost:'+str(port_number)+'/execute?command='+self.operation+'&async=1&pid='+util.get_project_settings()['id']
        else:
            url = 'http://localhost:'+str(port_number)+'/execute?command='+self.operation+'&async=1'
        debug(url)

        try:
            if self.body != None:
                body = json.dumps(self.body).encode('utf8')
                debug('posting to MavensMate:')
                debug(body)
                req = urllib.request.Request(url, data=body, headers={'Content-Type': 'application/json', 'MavensMate-Editor-Agent': 'sublime'})
                response = urllib.request.urlopen(req)
            else:
                response = urllib.request.urlopen(url)

            debug('response from MavensMate')
            debug(response)

            mm_response = json.loads(response.read().decode('utf-8'))

            request_id = mm_response['id']
            status = mm_response['status']
            result = None
            while status == 'pending':
                url = 'http://localhost:'+str(port_number)+'/status?id='+request_id
                req = urllib.request.Request(url, headers={'MavensMate-Editor-Agent': 'sublime'})

                response = urllib.request.urlopen(url)
                response_body = response.read().decode('utf-8')
                status_response = json.loads(response_body)
                if 'status' in status_response and status_response['status'] == 'pending':
                    time.sleep(0.5)
                else:
                    result = status_response
                    status = 'done'

        except urllib.error.HTTPError as e:
            debug('urllib.error.HTTPError')
            result = e.read().decode('utf-8')
            debug(result)
            result = str(result)
            response_body = { 'error': 'Request to the local MavensMate server failed. '+str(result) }
            status = 'done'
        except urllib.error.URLError as e:
            debug('urllib.error.URLError')
            result = 'Error contacting MavensMate server: '+str(e)
            response_body = { 'error': 'Request to the local MavensMate server failed. please ensure the MavensMate app is running.' }
            status = 'done'
        except Exception as e:
            debug('Exception')
            result = 'Error contacting MavensMate server: '+str(e)
            response_body = { 'error': 'Request to the local MavensMate server failed. '+str(e) }
            status = 'done'


        debug(result)
        self.result = response_body

        self.calculate_process_region()

        ThreadTracker.remove(self)